From 43ff66cd012784ed826501d2c442e50333053859 Mon Sep 17 00:00:00 2001 From: Kasey White Date: Sun, 18 Dec 2022 19:49:16 -0500 Subject: [PATCH] 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 --- crates/lang/src/builder.rs | 2 + crates/lang/src/tipo.rs | 6 ++- crates/lang/src/uplc.rs | 87 +++++++++++++++----------------------- 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/crates/lang/src/builder.rs b/crates/lang/src/builder.rs index bc85c899..1cb7ff46 100644 --- a/crates/lang/src/builder.rs +++ b/crates/lang/src/builder.rs @@ -846,6 +846,8 @@ pub fn get_variant_name(new_name: &mut String, t: &Arc) { "int".to_string() } else if t.is_bool() { "bool".to_string() + } else if t.is_bytearray() { + "bytearray".to_string() } else if t.is_map() { let mut full_type = "map".to_string(); let pair_type = &t.get_inner_types()[0]; diff --git a/crates/lang/src/tipo.rs b/crates/lang/src/tipo.rs index 48a10f74..bc87262d 100644 --- a/crates/lang/src/tipo.rs +++ b/crates/lang/src/tipo.rs @@ -223,7 +223,11 @@ impl Type { } else if matches!(self.get_uplc_type(), UplcType::Data) { match self { 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(), _ => unreachable!(), } diff --git a/crates/lang/src/uplc.rs b/crates/lang/src/uplc.rs index 6f36203d..689603d2 100644 --- a/crates/lang/src/uplc.rs +++ b/crates/lang/src/uplc.rs @@ -28,7 +28,10 @@ use crate::{ rearrange_clauses, ClauseProperties, DataTypeKey, FuncComponents, FunctionAccessKey, }, expr::TypedExpr, - tipo::{self, PatternConstructor, Type, TypeInfo, ValueConstructor, ValueConstructorVariant}, + tipo::{ + self, ModuleValueConstructor, PatternConstructor, Type, TypeInfo, ValueConstructor, + ValueConstructorVariant, + }, IdGenerator, }; @@ -437,8 +440,8 @@ impl<'a> CodeGenerator<'a> { tipo, .. } => match constructor { - tipo::ModuleValueConstructor::Record { .. } => todo!(), - tipo::ModuleValueConstructor::Fn { name, module, .. } => { + ModuleValueConstructor::Record { .. } => todo!(), + ModuleValueConstructor::Fn { name, module, .. } => { let func = self.functions.get(&FunctionAccessKey { module_name: module_name.clone(), function_name: name.clone(), @@ -449,7 +452,7 @@ impl<'a> CodeGenerator<'a> { ir_stack.push(Air::Var { scope, constructor: ValueConstructor::public( - func.return_type.clone(), + tipo.clone(), ValueConstructorVariant::ModuleFn { name: name.clone(), field_map: None, @@ -479,7 +482,7 @@ impl<'a> CodeGenerator<'a> { } } } - tipo::ModuleValueConstructor::Constant { literal, .. } => { + ModuleValueConstructor::Constant { literal, .. } => { constants_ir(literal, ir_stack, scope); } }, @@ -2332,7 +2335,6 @@ impl<'a> CodeGenerator<'a> { arg_stack.push(term); } - Air::Fn { params, .. } => { let mut term = arg_stack.pop().unwrap(); @@ -2890,59 +2892,36 @@ impl<'a> CodeGenerator<'a> { 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 { function: Term::Lambda { parameter_name: Name { - text: func_name, + text: func_name.clone(), unique: 0.into(), }, - body: term.into(), + body: Term::Apply { + function: Term::Lambda { + parameter_name: Name { + text: func_name.clone(), + unique: 0.into(), + }, + body: term.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(),