checkpoint

This commit is contained in:
Kasey White 2022-12-10 00:42:38 -05:00 committed by KtorZ
parent 04c05f8d63
commit 3d3b3d7e10
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 133 additions and 11 deletions

View File

@ -143,7 +143,7 @@ impl Type {
if let Type::Tuple { elems } = &*args[0] { if let Type::Tuple { elems } = &*args[0] {
elems.len() == 2 elems.len() == 2
} else if let Type::Var { tipo } = &*args[0] { } else if let Type::Var { tipo } = &*args[0] {
matches!(tipo.borrow().get_uplc_type(), UplcType::Pair(_, _)) matches!(tipo.borrow().get_uplc_type(), Some(UplcType::Pair(_, _)))
} else { } else {
false false
} }
@ -388,10 +388,10 @@ impl TypeVar {
} }
} }
pub fn get_uplc_type(&self) -> UplcType { pub fn get_uplc_type(&self) -> Option<UplcType> {
match self { match dbg!(self) {
Self::Link { tipo } => tipo.get_uplc_type(), Self::Link { tipo } => Some(tipo.get_uplc_type()),
_ => unreachable!(), _ => None,
} }
} }
} }

View File

@ -101,8 +101,12 @@ impl<'a> CodeGenerator<'a> {
self.build_ir(&body, &mut ir_stack, scope); self.build_ir(&body, &mut ir_stack, scope);
print!("{ir_stack:#?}");
self.define_ir(&mut ir_stack); self.define_ir(&mut ir_stack);
print!("{ir_stack:#?}");
let mut term = self.uplc_code_gen(&mut ir_stack); let mut term = self.uplc_code_gen(&mut ir_stack);
if self.needs_field_access { if self.needs_field_access {
@ -129,6 +133,8 @@ impl<'a> CodeGenerator<'a> {
term, term,
}; };
println!("{}", program.to_pretty());
let mut interner = Interner::new(); let mut interner = Interner::new();
interner.program(&mut program); interner.program(&mut program);
@ -1877,6 +1883,7 @@ impl<'a> CodeGenerator<'a> {
DefaultFunction::EqualsData DefaultFunction::EqualsData
}; };
println!("Equals Binop");
let term = match name { let term = match name {
BinOp::And => Term::Apply { BinOp::And => Term::Apply {
function: Term::Apply { function: Term::Apply {
@ -1974,7 +1981,7 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term); arg_stack.push(term);
return; return;
} else if tipo.is_tuple() } else if tipo.is_tuple()
&& matches!(tipo.get_uplc_type(), UplcType::Pair(_, _)) && matches!(dbg!(tipo.clone()).get_uplc_type(), UplcType::Pair(_, _))
{ {
let term = Term::Apply { let term = Term::Apply {
function: Term::Apply { function: Term::Apply {
@ -2029,7 +2036,7 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term); arg_stack.push(term);
return; return;
} else if tipo.is_list() } else if tipo.is_list()
|| matches!(tipo.get_uplc_type(), UplcType::List(_)) || matches!(dbg!(tipo.clone()).get_uplc_type(), UplcType::List(_))
{ {
let term = Term::Apply { let term = Term::Apply {
function: Term::Apply { function: Term::Apply {
@ -2146,7 +2153,7 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term); arg_stack.push(term);
return; return;
} else if tipo.is_tuple() } else if tipo.is_tuple()
&& matches!(tipo.get_uplc_type(), UplcType::Pair(_, _)) && matches!(dbg!(tipo.clone()).get_uplc_type(), UplcType::Pair(_, _))
{ {
// let term = Term::Apply { // let term = Term::Apply {
// function: Term::Apply { // function: Term::Apply {
@ -2198,7 +2205,7 @@ impl<'a> CodeGenerator<'a> {
// return; // return;
todo!() todo!()
} else if tipo.is_list() } else if tipo.is_list()
|| matches!(tipo.get_uplc_type(), UplcType::List(_)) || matches!(dbg!(tipo).get_uplc_type(), UplcType::List(_))
{ {
let term = Term::Apply { let term = Term::Apply {
function: Term::Apply { function: Term::Apply {
@ -3270,8 +3277,65 @@ impl<'a> CodeGenerator<'a> {
params: depend_comp.args.clone(), params: depend_comp.args.clone(),
recursive: depend_comp.recursive, recursive: depend_comp.recursive,
}]; }];
let mut new_ir = depend_comp.ir.clone();
temp_ir.extend(depend_comp.ir.clone()); if depend_comp.recursive {
let mut insert_var_vec = vec![];
println!("FOund HERE");
for (index, air) in depend_comp.ir.clone().into_iter().enumerate().rev() {
if let Air::Var {
scope,
constructor,
name,
} = air
{
println!("found a var at index: {}", index);
if let ValueConstructorVariant::ModuleFn {
name: func_name,
module,
..
} = constructor.clone().variant
{
println!(
"Func Name: {func_name}, Dependency Name: {}",
dependency.function_name
);
println!(
"Module Name: {module}, Dependency Module: {}",
dependency.module_name
);
if func_name.clone() == dependency.function_name.clone()
&& module == dependency.module_name.clone()
{
insert_var_vec.push((
index,
Air::Var {
scope: scope.clone(),
constructor: constructor.clone(),
name: func_name.clone(),
},
));
}
}
}
}
for (index, ir) in insert_var_vec {
new_ir.insert(index, ir);
let current_call = new_ir[index - 1].clone();
match current_call {
Air::Call { scope, count } => {
new_ir[index - 1] = Air::Call {
scope,
count: count + 1,
}
}
_ => unreachable!(),
}
}
}
temp_ir.extend(new_ir);
temp_ir.append(&mut dep_ir); temp_ir.append(&mut dep_ir);
@ -3314,6 +3378,61 @@ impl<'a> CodeGenerator<'a> {
recursive: funt_comp.recursive, recursive: funt_comp.recursive,
}); });
// let mut insert_var_vec = vec![];
println!("FOund HERE");
// for (index, air) in depend_comp.ir.clone().into_iter().enumerate().rev() {
// if let Air::Var {
// scope,
// constructor,
// name,
// } = air
// {
// println!("found a var at index: {}", index);
// if let ValueConstructorVariant::ModuleFn {
// name: func_name,
// module,
// ..
// } = constructor.clone().variant
// {
// println!(
// "Func Name: {func_name}, Dependency Name: {}",
// dependency.function_name
// );
// println!(
// "Module Name: {module}, Dependency Module: {}",
// dependency.module_name
// );
// if func_name.clone() == dependency.function_name.clone()
// && module == dependency.module_name.clone()
// {
// insert_var_vec.push((
// index,
// Air::Var {
// scope: scope.clone(),
// constructor: constructor.clone(),
// name: func_name.clone(),
// },
// ));
// }
// }
// }
// }
// for (index, ir) in insert_var_vec {
// new_ir.insert(index, ir);
// let current_call = new_ir[index - 1].clone();
// match current_call {
// Air::Call { scope, count } => {
// new_ir[index - 1] = Air::Call {
// scope,
// count: count + 1,
// }
// }
// _ => unreachable!(),
// }
// }
full_func_ir.extend(funt_comp.ir.clone()); full_func_ir.extend(funt_comp.ir.clone());
for ir in full_func_ir.into_iter().rev() { for ir in full_func_ir.into_iter().rev() {
@ -3981,6 +4100,7 @@ fn convert_type_to_data(term: Term<Name>, field_type: &Arc<Type>) -> Term<Name>
.into(), .into(),
} }
} else if field_type.is_tuple() { } else if field_type.is_tuple() {
println!("Type to data");
match field_type.get_uplc_type() { match field_type.get_uplc_type() {
UplcType::List(_) => Term::Apply { UplcType::List(_) => Term::Apply {
function: DefaultFunction::ListData.into(), function: DefaultFunction::ListData.into(),

View File

@ -548,7 +548,9 @@ where
results.push(test_info); results.push(test_info);
} }
(Err(_), remaining_budget, _) => { (Err(e), remaining_budget, _) => {
println!("ERROR:\n{}", e);
let test_info = TestInfo { let test_info = TestInfo {
is_passing: false, is_passing: false,
test, test,