fix test 23
This commit is contained in:
parent
919ea6c723
commit
30487cc232
|
@ -1948,7 +1948,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
fn define_recurse_ir(
|
fn define_recurse_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
ir_stack: &mut [Air],
|
ir_stack: &mut Vec<Air>,
|
||||||
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
||||||
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
||||||
mut recursion_func_map: IndexMap<FunctionAccessKey, ()>,
|
mut recursion_func_map: IndexMap<FunctionAccessKey, ()>,
|
||||||
|
@ -1960,7 +1960,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
for func_index in func_index_map.clone().iter() {
|
for func_index in func_index_map.clone().iter() {
|
||||||
let func = func_index.0;
|
let func = func_index.0;
|
||||||
|
|
||||||
let function_components = func_components.get(func).unwrap();
|
let function_components = func_components.get_mut(func).unwrap();
|
||||||
let mut function_ir = function_components.ir.clone();
|
let mut function_ir = function_components.ir.clone();
|
||||||
let mut skip = false;
|
let mut skip = false;
|
||||||
|
|
||||||
|
@ -2018,6 +2018,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
recursion_func_map.clone(),
|
recursion_func_map.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function_components.ir = function_ir;
|
||||||
|
|
||||||
//now unify
|
//now unify
|
||||||
for item in inner_func_components {
|
for item in inner_func_components {
|
||||||
if !func_components.contains_key(&item.0) {
|
if !func_components.contains_key(&item.0) {
|
||||||
|
@ -2038,7 +2040,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
fn process_define_ir(
|
fn process_define_ir(
|
||||||
&mut self,
|
&mut self,
|
||||||
ir_stack: &mut [Air],
|
ir_stack: &mut Vec<Air>,
|
||||||
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
func_components: &mut IndexMap<FunctionAccessKey, FuncComponents>,
|
||||||
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
func_index_map: &mut IndexMap<FunctionAccessKey, Vec<u64>>,
|
||||||
) {
|
) {
|
||||||
|
@ -2046,7 +2048,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
for (index, ir) in ir_stack.to_vec().iter().enumerate().rev() {
|
for (index, ir) in ir_stack.to_vec().iter().enumerate().rev() {
|
||||||
match ir {
|
match ir {
|
||||||
Air::Var {
|
Air::Var {
|
||||||
scope, constructor, ..
|
scope,
|
||||||
|
constructor,
|
||||||
|
name: temp_name,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
if let ValueConstructorVariant::ModuleFn {
|
if let ValueConstructorVariant::ModuleFn {
|
||||||
name,
|
name,
|
||||||
|
@ -2084,7 +2089,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (variant_name, mut func_ir) =
|
let (variant_name, func_ir) =
|
||||||
monomorphize(func_ir, generics_type_map, &constructor.tipo);
|
monomorphize(func_ir, generics_type_map, &constructor.tipo);
|
||||||
|
|
||||||
let function_key = FunctionAccessKey {
|
let function_key = FunctionAccessKey {
|
||||||
|
@ -2093,6 +2098,13 @@ impl<'a> CodeGenerator<'a> {
|
||||||
variant_name: variant_name.clone(),
|
variant_name: variant_name.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ir_stack[index] = Air::Var {
|
||||||
|
scope: scope.clone(),
|
||||||
|
constructor: constructor.clone(),
|
||||||
|
name: name.clone(),
|
||||||
|
variant_name: variant_name.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(scope_prev) = to_be_defined_map.get(&function_key) {
|
if let Some(scope_prev) = to_be_defined_map.get(&function_key) {
|
||||||
let new_scope = get_common_ancestor(scope, scope_prev);
|
let new_scope = get_common_ancestor(scope, scope_prev);
|
||||||
|
|
||||||
|
@ -2101,9 +2113,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
to_be_defined_map.insert(function_key.clone(), scope.to_vec());
|
to_be_defined_map.insert(function_key.clone(), scope.to_vec());
|
||||||
} else {
|
} else {
|
||||||
to_be_defined_map.insert(function_key.clone(), scope.to_vec());
|
to_be_defined_map.insert(function_key.clone(), scope.to_vec());
|
||||||
let mut func_calls = vec![];
|
let mut func_calls = HashMap::new();
|
||||||
|
|
||||||
for (index, ir) in func_ir.clone().into_iter().enumerate() {
|
for ir in func_ir.clone().into_iter() {
|
||||||
if let Air::Var {
|
if let Air::Var {
|
||||||
constructor:
|
constructor:
|
||||||
ValueConstructor {
|
ValueConstructor {
|
||||||
|
@ -2111,16 +2123,11 @@ impl<'a> CodeGenerator<'a> {
|
||||||
ValueConstructorVariant::ModuleFn {
|
ValueConstructorVariant::ModuleFn {
|
||||||
name: func_name,
|
name: func_name,
|
||||||
module,
|
module,
|
||||||
field_map,
|
|
||||||
arity,
|
|
||||||
location,
|
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
public,
|
|
||||||
tipo,
|
tipo,
|
||||||
|
..
|
||||||
},
|
},
|
||||||
scope,
|
|
||||||
name,
|
|
||||||
..
|
..
|
||||||
} = ir
|
} = ir
|
||||||
{
|
{
|
||||||
|
@ -2138,24 +2145,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let function = self.functions.get(¤t_func);
|
let function = self.functions.get(¤t_func);
|
||||||
if function_key.clone() == current_func_as_variant {
|
if function_key.clone() == current_func_as_variant {
|
||||||
func_ir[index] = Air::Var {
|
func_calls.insert(current_func_as_variant, ());
|
||||||
scope,
|
|
||||||
constructor: ValueConstructor {
|
|
||||||
public,
|
|
||||||
variant: ValueConstructorVariant::ModuleFn {
|
|
||||||
name: func_name,
|
|
||||||
field_map,
|
|
||||||
module,
|
|
||||||
arity,
|
|
||||||
location,
|
|
||||||
builtin: None,
|
|
||||||
},
|
|
||||||
tipo,
|
|
||||||
},
|
|
||||||
name,
|
|
||||||
variant_name: variant_name.clone(),
|
|
||||||
};
|
|
||||||
func_calls.push(current_func_as_variant);
|
|
||||||
} else if let (Some(function), Type::Fn { args, .. }) =
|
} else if let (Some(function), Type::Fn { args, .. }) =
|
||||||
(function, &*tipo)
|
(function, &*tipo)
|
||||||
{
|
{
|
||||||
|
@ -2168,16 +2158,19 @@ impl<'a> CodeGenerator<'a> {
|
||||||
for arg in args.iter() {
|
for arg in args.iter() {
|
||||||
get_variant_name(&mut new_name, arg);
|
get_variant_name(&mut new_name, arg);
|
||||||
}
|
}
|
||||||
func_calls.push(FunctionAccessKey {
|
func_calls.insert(
|
||||||
module_name: module,
|
FunctionAccessKey {
|
||||||
function_name: func_name,
|
module_name: module,
|
||||||
variant_name: new_name,
|
function_name: func_name,
|
||||||
});
|
variant_name: new_name,
|
||||||
|
},
|
||||||
|
(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
func_calls.push(current_func);
|
func_calls.insert(current_func, ());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
func_calls.push(current_func);
|
func_calls.insert(current_func, ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2194,30 +2187,19 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let recursive = if let Ok(index) =
|
|
||||||
func_calls.binary_search(&function_key)
|
let recursive = if func_calls.get(&function_key).is_some() {
|
||||||
{
|
func_calls.remove(&function_key);
|
||||||
func_calls.remove(index);
|
|
||||||
while let Ok(index) = func_calls.binary_search(&function_key) {
|
|
||||||
func_calls.remove(index);
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
ir_stack[index] = Air::Var {
|
|
||||||
scope: scope.clone(),
|
|
||||||
constructor: constructor.clone(),
|
|
||||||
name: name.clone(),
|
|
||||||
variant_name,
|
|
||||||
};
|
|
||||||
|
|
||||||
func_components.insert(
|
func_components.insert(
|
||||||
function_key,
|
function_key,
|
||||||
FuncComponents {
|
FuncComponents {
|
||||||
ir: func_ir,
|
ir: func_ir,
|
||||||
dependencies: func_calls,
|
dependencies: func_calls.keys().cloned().collect_vec(),
|
||||||
recursive,
|
recursive,
|
||||||
args,
|
args,
|
||||||
},
|
},
|
||||||
|
@ -2764,9 +2746,13 @@ impl<'a> CodeGenerator<'a> {
|
||||||
format!("{module_name}_{function_name}{variant_name}");
|
format!("{module_name}_{function_name}{variant_name}");
|
||||||
let name = format!("{function_name}{variant_name}");
|
let name = format!("{function_name}{variant_name}");
|
||||||
if text == name || text == name_module {
|
if text == name || text == name_module {
|
||||||
|
let mut term = self.uplc_code_gen(&mut ir.clone());
|
||||||
|
term = builder::constr_get_field(term);
|
||||||
|
term = builder::constr_fields_exposer(term);
|
||||||
|
|
||||||
let mut program: Program<Name> = Program {
|
let mut program: Program<Name> = Program {
|
||||||
version: (1, 0, 0),
|
version: (1, 0, 0),
|
||||||
term: self.uplc_code_gen(&mut ir.clone()),
|
term,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut interner = Interner::new();
|
let mut interner = Interner::new();
|
||||||
|
|
Loading…
Reference in New Issue