From df939e20ce1ec61dd3288b170be527c295eb2584 Mon Sep 17 00:00:00 2001 From: microproofs Date: Wed, 12 Jun 2024 01:29:14 -0400 Subject: [PATCH] missed a Air Op Code and updated how we pass in otherwise for assignment --- crates/aiken-lang/src/gen_uplc.rs | 42 ++++++----------------- crates/aiken-lang/src/gen_uplc/builder.rs | 8 ----- crates/aiken-lang/src/gen_uplc/tree.rs | 17 ++++----- 3 files changed, 19 insertions(+), 48 deletions(-) diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index e021b02c..fbb78502 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -9,7 +9,7 @@ use self::{ modify_cyclic_calls, modify_self_calls, rearrange_list_clauses, AssignmentProperties, ClauseProperties, CodeGenSpecialFuncs, CycleFunctionNames, HoistableFunction, Variant, }, - tree::{AirMsg, AirTree, TreePath}, + tree::{AirTree, TreePath}, }; use crate::{ ast::{ @@ -17,7 +17,7 @@ use crate::{ Span, TraceLevel, Tracing, TypedArg, TypedClause, TypedDataType, TypedFunction, TypedPattern, TypedValidator, UnOp, }, - builtins::{bool, data, int, list, string, void}, + builtins::{bool, data, int, list, void}, expr::TypedExpr, gen_uplc::{ air::ExpectLevel, @@ -285,14 +285,11 @@ impl<'a> CodeGenerator<'a> { self.special_functions.insert_new_function( msg_func_name.clone(), - Term::string(msg), - string(), + Term::Error.delayed_trace(Term::string(msg)), + void(), ); - let msg_string = - AirTree::string(self.special_functions.use_function_string(msg_func_name)); - - AirTree::trace(msg_string, void(), AirTree::error(void(), false)) + self.special_functions.use_function_tree(msg_func_name) } }; @@ -1776,28 +1773,13 @@ impl<'a> CodeGenerator<'a> { // mutate code_gen_funcs and defined_data_types in this if branch if function.is_none() && defined_data_types.get(&data_type_name).is_none() { - let (msg_term, error_term) = match self.tracing { - TraceLevel::Silent => (None, AirTree::error(tipo.clone(), false)), - TraceLevel::Compact | TraceLevel::Verbose => { - let msg = AirMsg::LocalVar("__param_msg".to_string()); - ( - Some(msg.clone()), - AirTree::trace( - msg.to_air_tree(), - tipo.clone(), - AirTree::error(tipo.clone(), false), - ), - ) - } - }; - defined_data_types.insert(data_type_name.clone(), 1); let current_defined = defined_data_types.clone(); let mut diff_defined_types = vec![]; let constr_clauses = data_type.constructors.iter().enumerate().rfold( - error_term, + otherwise.clone(), |acc, (index, constr)| { let mut constr_args = vec![]; @@ -1836,8 +1818,8 @@ impl<'a> CodeGenerator<'a> { ), tipo.clone(), ), - msg_term.clone(), constr_then, + otherwise.clone(), ) } else { AirTree::fields_expose( @@ -3069,15 +3051,11 @@ impl<'a> CodeGenerator<'a> { self.special_functions.insert_new_function( msg_func_name.to_string(), - Term::string(msg), - string(), + Term::Error.delayed_trace(Term::string(msg)), + void(), ); - let msg_string = AirTree::string( - self.special_functions.use_function_string(msg_func_name), - ); - - AirTree::trace(msg_string, void(), AirTree::error(void(), false)) + self.special_functions.use_function_tree(msg_func_name) } }; diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index 763b0750..1ffb9365 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -233,14 +233,6 @@ impl CodeGenSpecialFuncs { } } - pub fn use_function_string(&mut self, func_name: String) -> String { - if !self.used_funcs.contains(&func_name) { - self.used_funcs.push(func_name.to_string()); - } - - func_name - } - pub fn use_function_tree(&mut self, func_name: String) -> AirTree { if !self.used_funcs.contains(&func_name) { self.used_funcs.push(func_name.to_string()); diff --git a/crates/aiken-lang/src/gen_uplc/tree.rs b/crates/aiken-lang/src/gen_uplc/tree.rs index c8aa3007..5e3b0dc7 100644 --- a/crates/aiken-lang/src/gen_uplc/tree.rs +++ b/crates/aiken-lang/src/gen_uplc/tree.rs @@ -215,8 +215,8 @@ pub enum AirTree { // Misc. FieldsEmpty { constr: Box, - msg: Option, then: Box, + otherwise: Box, }, ListEmpty { list: Box, @@ -960,11 +960,11 @@ impl AirTree { AirTree::NoOp { then: then.into() } } - pub fn fields_empty(constr: AirTree, msg: Option, then: AirTree) -> AirTree { + pub fn fields_empty(constr: AirTree, then: AirTree, otherwise: AirTree) -> AirTree { AirTree::FieldsEmpty { constr: constr.into(), - msg, then: then.into(), + otherwise: otherwise.into(), } } @@ -1284,15 +1284,16 @@ impl AirTree { otherwise.create_air_vec(air_vec); } } - AirTree::FieldsEmpty { constr, msg, then } => { + AirTree::FieldsEmpty { + constr, + then, + otherwise, + } => { air_vec.push(Air::FieldsEmpty); - if let Some(msg) = msg { - msg.to_air_tree().create_air_vec(air_vec); - } - constr.create_air_vec(air_vec); then.create_air_vec(air_vec); + otherwise.create_air_vec(air_vec); } AirTree::ListEmpty { list,