all tests pass besides todo in 13, couple changes
Use more cost efficient recurse Monomorphize needed to deal with function arg return types bytearray variant added for variant names
This commit is contained in:
parent
b6556e6739
commit
43ff66cd01
|
@ -846,6 +846,8 @@ pub fn get_variant_name(new_name: &mut String, t: &Arc<Type>) {
|
||||||
"int".to_string()
|
"int".to_string()
|
||||||
} else if t.is_bool() {
|
} else if t.is_bool() {
|
||||||
"bool".to_string()
|
"bool".to_string()
|
||||||
|
} else if t.is_bytearray() {
|
||||||
|
"bytearray".to_string()
|
||||||
} else if t.is_map() {
|
} else if t.is_map() {
|
||||||
let mut full_type = "map".to_string();
|
let mut full_type = "map".to_string();
|
||||||
let pair_type = &t.get_inner_types()[0];
|
let pair_type = &t.get_inner_types()[0];
|
||||||
|
|
|
@ -223,7 +223,11 @@ impl Type {
|
||||||
} else if matches!(self.get_uplc_type(), UplcType::Data) {
|
} else if matches!(self.get_uplc_type(), UplcType::Data) {
|
||||||
match self {
|
match self {
|
||||||
Type::App { args, .. } => args.clone(),
|
Type::App { args, .. } => args.clone(),
|
||||||
Type::Fn { args, .. } => args.clone(),
|
Type::Fn { args, ret } => {
|
||||||
|
let mut args = args.clone();
|
||||||
|
args.push(ret.clone());
|
||||||
|
args
|
||||||
|
}
|
||||||
Type::Var { tipo } => tipo.borrow().get_inner_type(),
|
Type::Var { tipo } => tipo.borrow().get_inner_type(),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,10 @@ use crate::{
|
||||||
rearrange_clauses, ClauseProperties, DataTypeKey, FuncComponents, FunctionAccessKey,
|
rearrange_clauses, ClauseProperties, DataTypeKey, FuncComponents, FunctionAccessKey,
|
||||||
},
|
},
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant},
|
tipo::{
|
||||||
|
self, ModuleValueConstructor, PatternConstructor, Type, TypeInfo, ValueConstructor,
|
||||||
|
ValueConstructorVariant,
|
||||||
|
},
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -437,8 +440,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
tipo,
|
tipo,
|
||||||
..
|
..
|
||||||
} => match constructor {
|
} => match constructor {
|
||||||
tipo::ModuleValueConstructor::Record { .. } => todo!(),
|
ModuleValueConstructor::Record { .. } => todo!(),
|
||||||
tipo::ModuleValueConstructor::Fn { name, module, .. } => {
|
ModuleValueConstructor::Fn { name, module, .. } => {
|
||||||
let func = self.functions.get(&FunctionAccessKey {
|
let func = self.functions.get(&FunctionAccessKey {
|
||||||
module_name: module_name.clone(),
|
module_name: module_name.clone(),
|
||||||
function_name: name.clone(),
|
function_name: name.clone(),
|
||||||
|
@ -449,7 +452,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
ir_stack.push(Air::Var {
|
ir_stack.push(Air::Var {
|
||||||
scope,
|
scope,
|
||||||
constructor: ValueConstructor::public(
|
constructor: ValueConstructor::public(
|
||||||
func.return_type.clone(),
|
tipo.clone(),
|
||||||
ValueConstructorVariant::ModuleFn {
|
ValueConstructorVariant::ModuleFn {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
field_map: None,
|
field_map: None,
|
||||||
|
@ -479,7 +482,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tipo::ModuleValueConstructor::Constant { literal, .. } => {
|
ModuleValueConstructor::Constant { literal, .. } => {
|
||||||
constants_ir(literal, ir_stack, scope);
|
constants_ir(literal, ir_stack, scope);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -2332,7 +2335,6 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
arg_stack.push(term);
|
arg_stack.push(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
Air::Fn { params, .. } => {
|
Air::Fn { params, .. } => {
|
||||||
let mut term = arg_stack.pop().unwrap();
|
let mut term = arg_stack.pop().unwrap();
|
||||||
|
|
||||||
|
@ -2890,61 +2892,38 @@ impl<'a> CodeGenerator<'a> {
|
||||||
body: func_body.into(),
|
body: func_body.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut boostrap_recurse = Term::Apply {
|
|
||||||
function: Term::Var(Name {
|
|
||||||
text: "__recurse".to_string(),
|
|
||||||
unique: 0.into(),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
argument: Term::Var(Name {
|
|
||||||
text: "__recurse".to_string(),
|
|
||||||
unique: 0.into(),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for param in params.iter() {
|
|
||||||
boostrap_recurse = Term::Apply {
|
|
||||||
function: boostrap_recurse.into(),
|
|
||||||
argument: Term::Var(Name {
|
|
||||||
text: param.clone(),
|
|
||||||
unique: 0.into(),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
func_body = Term::Apply {
|
|
||||||
function: Term::Lambda {
|
|
||||||
parameter_name: Name {
|
|
||||||
text: "__recurse".to_string(),
|
|
||||||
unique: 0.into(),
|
|
||||||
},
|
|
||||||
body: boostrap_recurse.into(),
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
argument: func_body.into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for param in params.iter().rev() {
|
|
||||||
func_body = Term::Lambda {
|
|
||||||
parameter_name: Name {
|
|
||||||
text: param.clone(),
|
|
||||||
unique: 0.into(),
|
|
||||||
},
|
|
||||||
body: func_body.into(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
term = Term::Apply {
|
term = Term::Apply {
|
||||||
function: Term::Lambda {
|
function: Term::Lambda {
|
||||||
parameter_name: Name {
|
parameter_name: Name {
|
||||||
text: func_name,
|
text: func_name.clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
},
|
||||||
|
body: Term::Apply {
|
||||||
|
function: Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: func_name.clone(),
|
||||||
unique: 0.into(),
|
unique: 0.into(),
|
||||||
},
|
},
|
||||||
body: term.into(),
|
body: term.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
|
argument: Term::Apply {
|
||||||
|
function: Term::Var(Name {
|
||||||
|
text: func_name.clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
argument: Term::Var(Name {
|
||||||
|
text: func_name,
|
||||||
|
unique: 0.into(),
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
argument: func_body.into(),
|
argument: func_body.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue