feat: change expect from data on constrs to take in a message term
This commit is contained in:
parent
43e84d7af7
commit
4fc65cc600
|
@ -1574,17 +1574,19 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let data_type_name = format!("__expect_{}_{}", data_type.name, data_type_variant);
|
let data_type_name = format!("__expect_{}_{}", data_type.name, data_type_variant);
|
||||||
let function = self.code_gen_functions.get(&data_type_name);
|
let function = self.code_gen_functions.get(&data_type_name);
|
||||||
|
|
||||||
let error_term = if self.tracing {
|
// mutate code_gen_funcs and defined_data_types in this if branch
|
||||||
AirTree::trace(
|
if function.is_none() && defined_data_types.get(&data_type_name).is_none() {
|
||||||
msg_func.clone(),
|
let (msg_term, error_term) = if self.tracing {
|
||||||
tipo.clone(),
|
let msg = AirTree::local_var("__param_msg", string());
|
||||||
AirTree::error(tipo.clone(), false),
|
|
||||||
|
(
|
||||||
|
msg.clone(),
|
||||||
|
AirTree::trace(msg, tipo.clone(), AirTree::error(tipo.clone(), false)),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
AirTree::error(tipo.clone(), false)
|
(msg_func.clone(), AirTree::error(tipo.clone(), false))
|
||||||
};
|
};
|
||||||
|
|
||||||
if function.is_none() && defined_data_types.get(&data_type_name).is_none() {
|
|
||||||
defined_data_types.insert(data_type_name.clone(), 1);
|
defined_data_types.insert(data_type_name.clone(), 1);
|
||||||
|
|
||||||
let current_defined = defined_data_types.clone();
|
let current_defined = defined_data_types.clone();
|
||||||
|
@ -1610,7 +1612,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
AirTree::local_var(&arg_name, arg_tipo.clone()),
|
AirTree::local_var(&arg_name, arg_tipo.clone()),
|
||||||
defined_data_types,
|
defined_data_types,
|
||||||
location,
|
location,
|
||||||
msg_func.clone(),
|
msg_term.clone(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1639,7 +1641,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
),
|
),
|
||||||
tipo.clone(),
|
tipo.clone(),
|
||||||
),
|
),
|
||||||
msg_func.clone(),
|
msg_term.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assigns.insert(0, empty);
|
assigns.insert(0, empty);
|
||||||
|
@ -1653,7 +1655,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
),
|
),
|
||||||
tipo.clone(),
|
tipo.clone(),
|
||||||
),
|
),
|
||||||
Some(msg_func.clone()),
|
Some(msg_term.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
assigns.insert(0, expose);
|
assigns.insert(0, expose);
|
||||||
|
@ -1700,9 +1702,16 @@ impl<'a> CodeGenerator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let code_gen_func = CodeGenFunction::Function {
|
let code_gen_func = if self.tracing {
|
||||||
|
CodeGenFunction::Function {
|
||||||
|
body: func_body,
|
||||||
|
params: vec!["__param_0".to_string(), "__param_msg".to_string()],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CodeGenFunction::Function {
|
||||||
body: func_body,
|
body: func_body,
|
||||||
params: vec!["__param_0".to_string()],
|
params: vec!["__param_0".to_string()],
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.code_gen_functions
|
self.code_gen_functions
|
||||||
|
@ -1713,18 +1722,35 @@ impl<'a> CodeGenerator<'a> {
|
||||||
defined_data_types.insert(data_type_name.to_string(), 1);
|
defined_data_types.insert(data_type_name.to_string(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.tracing {
|
||||||
|
let module_fn = ValueConstructorVariant::ModuleFn {
|
||||||
|
name: data_type_name.to_string(),
|
||||||
|
field_map: None,
|
||||||
|
module: "".to_string(),
|
||||||
|
arity: 2,
|
||||||
|
location,
|
||||||
|
builtin: None,
|
||||||
|
};
|
||||||
|
|
||||||
let func_var = AirTree::var(
|
let func_var = AirTree::var(
|
||||||
ValueConstructor::public(
|
ValueConstructor::public(tipo.clone(), module_fn),
|
||||||
tipo.clone(),
|
data_type_name,
|
||||||
ValueConstructorVariant::ModuleFn {
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
AirTree::call(func_var, void(), vec![value, msg_func])
|
||||||
|
} else {
|
||||||
|
let module_fn = ValueConstructorVariant::ModuleFn {
|
||||||
name: data_type_name.to_string(),
|
name: data_type_name.to_string(),
|
||||||
field_map: None,
|
field_map: None,
|
||||||
module: "".to_string(),
|
module: "".to_string(),
|
||||||
arity: 1,
|
arity: 1,
|
||||||
location: Span::empty(),
|
location,
|
||||||
builtin: None,
|
builtin: None,
|
||||||
},
|
};
|
||||||
),
|
|
||||||
|
let func_var = AirTree::var(
|
||||||
|
ValueConstructor::public(tipo.clone(), module_fn),
|
||||||
data_type_name,
|
data_type_name,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
@ -1732,6 +1758,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
AirTree::call(func_var, void(), vec![value])
|
AirTree::call(func_var, void(), vec![value])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_each_clause(
|
pub fn handle_each_clause(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use aiken_lang::{
|
use aiken_lang::ast::{Definition, Function, TypedFunction, TypedValidator};
|
||||||
ast::{Definition, Function, TypedFunction, TypedValidator},
|
|
||||||
gen_uplc::builder::{CONSTR_INDEX_MISMATCH, CONSTR_NOT_EMPTY, TOO_MANY_ITEMS},
|
|
||||||
};
|
|
||||||
use uplc::{
|
use uplc::{
|
||||||
ast::{Constant, Data, DeBruijn, Name, Program, Term, Type},
|
ast::{Constant, Data, DeBruijn, Name, Program, Term, Type},
|
||||||
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER},
|
builder::{CONSTR_FIELDS_EXPOSER, CONSTR_INDEX_EXPOSER},
|
||||||
|
|
Loading…
Reference in New Issue