Work through all but constr case for expect_type_assign
TODO: constr case for expect_type_assign TODO: soft_cast opcode uplc codegen TODO: fix PairAccessor opcode uplc codegen
This commit is contained in:
parent
dd5badd884
commit
6ba9a312f0
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
Span, TraceLevel, Tracing, TypedArg, TypedClause, TypedDataType, TypedFunction,
|
Span, TraceLevel, Tracing, TypedArg, TypedClause, TypedDataType, TypedFunction,
|
||||||
TypedPattern, TypedValidator, UnOp,
|
TypedPattern, TypedValidator, UnOp,
|
||||||
},
|
},
|
||||||
builtins::{bool, byte_array, data, int, list, void, PRELUDE},
|
builtins::{bool, byte_array, data, int, list, pair, void, PRELUDE},
|
||||||
expr::TypedExpr,
|
expr::TypedExpr,
|
||||||
gen_uplc::{
|
gen_uplc::{
|
||||||
air::ExpectLevel,
|
air::ExpectLevel,
|
||||||
|
@ -975,17 +975,14 @@ impl<'a> CodeGenerator<'a> {
|
||||||
location,
|
location,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let name = format!(
|
let name = format!("__expected_bytes_span_{}_{}", location.start, location.end);
|
||||||
"__expected_bytes_span_{}_{}",
|
|
||||||
location.start, location.end
|
|
||||||
);
|
|
||||||
|
|
||||||
let expect = AirTree::binop(
|
let expect = AirTree::binop(
|
||||||
BinOp::Eq,
|
BinOp::Eq,
|
||||||
bool(),
|
bool(),
|
||||||
AirTree::byte_array(expected_bytes),
|
AirTree::byte_array(expected_bytes.clone()),
|
||||||
AirTree::local_var(&name, byte_string()),
|
AirTree::local_var(&name, byte_array()),
|
||||||
byte_string(),
|
byte_array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assign_casted_value(
|
assign_casted_value(
|
||||||
|
@ -1627,7 +1624,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
| UplcType::Bls12_381G2Element
|
| UplcType::Bls12_381G2Element
|
||||||
| UplcType::Bls12_381MlResult
|
| UplcType::Bls12_381MlResult
|
||||||
| UplcType::Data,
|
| UplcType::Data,
|
||||||
) => value,
|
) => then,
|
||||||
|
|
||||||
// Map type
|
// Map type
|
||||||
Some(UplcType::List(_)) if tipo.is_map() => {
|
Some(UplcType::List(_)) if tipo.is_map() => {
|
||||||
|
@ -1643,38 +1640,54 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let fst_name = format!("__pair_fst_span_{}_{}", location.start, location.end);
|
let fst_name = format!("__pair_fst_span_{}_{}", location.start, location.end);
|
||||||
let snd_name = format!("__pair_snd_span_{}_{}", location.start, location.end);
|
let snd_name = format!("__pair_snd_span_{}_{}", location.start, location.end);
|
||||||
|
|
||||||
let expect_fst = self.expect_type_assign(
|
|
||||||
&inner_pair_types[0],
|
|
||||||
AirTree::local_var(fst_name.clone(), inner_pair_types[0].clone()),
|
|
||||||
defined_data_types,
|
|
||||||
location,
|
|
||||||
otherwise.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let expect_snd = self.expect_type_assign(
|
let expect_snd = self.expect_type_assign(
|
||||||
&inner_pair_types[1],
|
&inner_pair_types[1],
|
||||||
AirTree::local_var(snd_name.clone(), inner_pair_types[1].clone()),
|
AirTree::local_var(snd_name.clone(), inner_pair_types[1].clone()),
|
||||||
defined_data_types,
|
defined_data_types,
|
||||||
location,
|
location,
|
||||||
|
then,
|
||||||
otherwise.clone(),
|
otherwise.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let anon_func_body = AirTree::pair_access(
|
let expect_fst = self.expect_type_assign(
|
||||||
|
&inner_pair_types[0],
|
||||||
|
AirTree::local_var(fst_name.clone(), inner_pair_types[0].clone()),
|
||||||
|
defined_data_types,
|
||||||
|
location,
|
||||||
|
expect_snd,
|
||||||
|
otherwise.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let unwrap_function = AirTree::anon_func(
|
||||||
|
vec!["__list".to_string(), "__curried_expect_on_list".to_string()],
|
||||||
|
AirTree::list_empty(
|
||||||
|
AirTree::local_var("__list", tipo.clone()),
|
||||||
|
then,
|
||||||
|
AirTree::let_assignment(
|
||||||
|
&pair_name,
|
||||||
|
AirTree::builtin(
|
||||||
|
DefaultFunction::HeadList,
|
||||||
|
pair(data(), data()),
|
||||||
|
vec![AirTree::local_var("__list", tipo.clone())],
|
||||||
|
),
|
||||||
|
AirTree::pair_access(
|
||||||
Some(fst_name),
|
Some(fst_name),
|
||||||
Some(snd_name),
|
Some(snd_name),
|
||||||
inner_list_type.clone(),
|
inner_list_type.clone(),
|
||||||
AirTree::local_var(&pair_name, inner_list_type.clone()),
|
AirTree::local_var(&pair_name, inner_list_type.clone()),
|
||||||
true,
|
true,
|
||||||
AirTree::let_assignment("_", expect_fst, expect_snd),
|
expect_fst,
|
||||||
otherwise.clone(),
|
otherwise.clone(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let unwrap_function = AirTree::anon_func(vec![pair_name], anon_func_body, false);
|
|
||||||
|
|
||||||
let function = self.code_gen_functions.get(EXPECT_ON_LIST);
|
let function = self.code_gen_functions.get(EXPECT_ON_LIST);
|
||||||
|
|
||||||
if function.is_none() {
|
if function.is_none() {
|
||||||
let expect_list_func = AirTree::expect_on_list();
|
let expect_list_func = AirTree::expect_on_list2();
|
||||||
self.code_gen_functions.insert(
|
self.code_gen_functions.insert(
|
||||||
EXPECT_ON_LIST.to_string(),
|
EXPECT_ON_LIST.to_string(),
|
||||||
CodeGenFunction::Function {
|
CodeGenFunction::Function {
|
||||||
|
@ -1771,7 +1784,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let list_name = format!("__list_span_{}_{}", location.start, location.end);
|
let list_name = format!("__list_span_{}_{}", location.start, location.end);
|
||||||
let item_name = format!("__item_span_{}_{}", location.start, location.end);
|
let item_name = format!("__item_span_{}_{}", location.start, location.end);
|
||||||
|
|
||||||
let g = AirTree::anon_func(
|
let unwrap_function = AirTree::anon_func(
|
||||||
vec!["__list".to_string(), "__curried_expect_on_list".to_string()],
|
vec!["__list".to_string(), "__curried_expect_on_list".to_string()],
|
||||||
AirTree::list_empty(
|
AirTree::list_empty(
|
||||||
AirTree::local_var("__list", tipo.clone()),
|
AirTree::local_var("__list", tipo.clone()),
|
||||||
|
@ -1783,21 +1796,15 @@ impl<'a> CodeGenerator<'a> {
|
||||||
data(),
|
data(),
|
||||||
vec![AirTree::local_var("__list", tipo.clone())],
|
vec![AirTree::local_var("__list", tipo.clone())],
|
||||||
),
|
),
|
||||||
AirTree::let_assignment(
|
AirTree::soft_cast_assignment(
|
||||||
&item_name,
|
&item_name,
|
||||||
|
inner_list_type.clone(),
|
||||||
|
AirTree::local_var(item_name, data()),
|
||||||
self.expect_type_assign(
|
self.expect_type_assign(
|
||||||
inner_list_type,
|
inner_list_type,
|
||||||
AirTree::cast_from_data(
|
AirTree::local_var(item_name, inner_list_type.clone()),
|
||||||
AirTree::local_var(item_name, data()),
|
|
||||||
inner_list_type.clone(),
|
|
||||||
otherwise.clone(),
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
defined_data_types,
|
defined_data_types,
|
||||||
location,
|
location,
|
||||||
AirTree::void(),
|
|
||||||
otherwise,
|
|
||||||
),
|
|
||||||
AirTree::call(
|
AirTree::call(
|
||||||
AirTree::local_var("__curried_expect_on_list", void()),
|
AirTree::local_var("__curried_expect_on_list", void()),
|
||||||
void(),
|
void(),
|
||||||
|
@ -1807,34 +1814,19 @@ impl<'a> CodeGenerator<'a> {
|
||||||
vec![AirTree::local_var("__list", tipo.clone())],
|
vec![AirTree::local_var("__list", tipo.clone())],
|
||||||
)],
|
)],
|
||||||
),
|
),
|
||||||
|
otherwise,
|
||||||
|
),
|
||||||
|
otherwise,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expect_item = self.expect_type_assign(
|
|
||||||
inner_list_type,
|
|
||||||
AirTree::cast_from_data(
|
|
||||||
AirTree::local_var(&item_name, data()),
|
|
||||||
inner_list_type.clone(),
|
|
||||||
otherwise.clone(),
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
defined_data_types,
|
|
||||||
location,
|
|
||||||
otherwise,
|
|
||||||
);
|
|
||||||
|
|
||||||
let anon_func_body = expect_item;
|
|
||||||
|
|
||||||
let unwrap_function =
|
|
||||||
AirTree::anon_func(vec![item_name], anon_func_body, false);
|
|
||||||
|
|
||||||
let function = self.code_gen_functions.get(EXPECT_ON_LIST);
|
let function = self.code_gen_functions.get(EXPECT_ON_LIST);
|
||||||
|
|
||||||
if function.is_none() {
|
if function.is_none() {
|
||||||
let expect_list_func = AirTree::expect_on_list();
|
let expect_list_func = AirTree::expect_on_list2();
|
||||||
self.code_gen_functions.insert(
|
self.code_gen_functions.insert(
|
||||||
EXPECT_ON_LIST.to_string(),
|
EXPECT_ON_LIST.to_string(),
|
||||||
CodeGenFunction::Function {
|
CodeGenFunction::Function {
|
||||||
|
@ -1890,19 +1882,21 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let fst_name = format!("__pair_fst_span_{}_{}", location.start, location.end);
|
let fst_name = format!("__pair_fst_span_{}_{}", location.start, location.end);
|
||||||
let snd_name = format!("__pair_snd_span_{}_{}", location.start, location.end);
|
let snd_name = format!("__pair_snd_span_{}_{}", location.start, location.end);
|
||||||
|
|
||||||
let expect_fst = self.expect_type_assign(
|
|
||||||
&tuple_inner_types[0],
|
|
||||||
AirTree::local_var(fst_name.clone(), tuple_inner_types[0].clone()),
|
|
||||||
defined_data_types,
|
|
||||||
location,
|
|
||||||
otherwise.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let expect_snd = self.expect_type_assign(
|
let expect_snd = self.expect_type_assign(
|
||||||
&tuple_inner_types[1],
|
&tuple_inner_types[1],
|
||||||
AirTree::local_var(snd_name.clone(), tuple_inner_types[1].clone()),
|
AirTree::local_var(snd_name.clone(), tuple_inner_types[1].clone()),
|
||||||
defined_data_types,
|
defined_data_types,
|
||||||
location,
|
location,
|
||||||
|
then,
|
||||||
|
otherwise.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let expect_fst = self.expect_type_assign(
|
||||||
|
&tuple_inner_types[0],
|
||||||
|
AirTree::local_var(fst_name.clone(), tuple_inner_types[0].clone()),
|
||||||
|
defined_data_types,
|
||||||
|
location,
|
||||||
|
expect_snd,
|
||||||
otherwise.clone(),
|
otherwise.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue