Only 2 errors and todos left to finish

This commit is contained in:
microproofs 2024-07-29 14:45:54 -04:00 committed by Kasey
parent 6ba9a312f0
commit 0be5229f1c
3 changed files with 65 additions and 52 deletions

View File

@ -38,7 +38,7 @@ use crate::{
}, },
IdGenerator, IdGenerator,
}; };
use builder::unknown_data_to_type; use builder::{softcast_data_to_type_otherwise, unknown_data_to_type};
use indexmap::{IndexMap, IndexSet}; use indexmap::{IndexMap, IndexSet};
use itertools::Itertools; use itertools::Itertools;
use petgraph::{algo, Graph}; use petgraph::{algo, Graph};
@ -656,7 +656,10 @@ impl<'a> CodeGenerator<'a> {
kind: AssignmentKind::Expect { backpassing: () }, kind: AssignmentKind::Expect { backpassing: () },
remove_unused: false, remove_unused: false,
full_check: true, full_check: true,
otherwise: AirTree::local_var("acc_var", void()), otherwise: Some(AirTree::local_var(
"acc_var",
tipo.clone(),
)),
}, },
), ),
) )
@ -3216,17 +3219,17 @@ impl<'a> CodeGenerator<'a> {
let msg_func_name = msg.split_whitespace().join(""); let msg_func_name = msg.split_whitespace().join("");
if msg.is_empty() {
None
} else {
self.special_functions.insert_new_function( self.special_functions.insert_new_function(
msg_func_name.clone(), msg_func_name.clone(),
if msg.is_empty() { Term::Error.delayed_trace(Term::string(msg)).delay(),
Term::Error.delay()
} else {
Term::Error.delayed_trace(Term::string(msg)).delay()
},
void(), void(),
); );
self.special_functions.use_function_tree(msg_func_name) Some(self.special_functions.use_function_tree(msg_func_name))
}
}; };
let inner_then = self.assignment( let inner_then = self.assignment(
@ -4186,14 +4189,6 @@ impl<'a> CodeGenerator<'a> {
} }
fn gen_uplc(&mut self, ir: Air, arg_stack: &mut Vec<Term<Name>>) -> Option<Term<Name>> { fn gen_uplc(&mut self, ir: Air, arg_stack: &mut Vec<Term<Name>>) -> Option<Term<Name>> {
let convert_data_to_type = |term, tipo, otherwise| {
if otherwise == Term::Error.delay() {
builder::unknown_data_to_type(term, tipo)
} else {
builder::softcast_data_to_type_otherwise(term, tipo, otherwise)
}
};
match ir { match ir {
Air::Int { value } => Some(Term::integer(value.parse().unwrap())), Air::Int { value } => Some(Term::integer(value.parse().unwrap())),
Air::String { value } => Some(Term::string(value)), Air::String { value } => Some(Term::string(value)),
@ -4911,7 +4906,7 @@ impl<'a> CodeGenerator<'a> {
known_data_to_type(term, &tipo) known_data_to_type(term, &tipo)
}; };
if extract_constant(&term).is_some() { if extract_constant(&term.pierce_no_inlines()).is_some() {
let mut program: Program<Name> = Program { let mut program: Program<Name> = Program {
version: (1, 0, 0), version: (1, 0, 0),
term, term,
@ -5738,33 +5733,45 @@ impl<'a> CodeGenerator<'a> {
let list_id = self.id_gen.next(); let list_id = self.id_gen.next();
if let Some(name) = snd { if let Some(name) = snd {
term = term.lambda(name).apply(if is_expect { let value = Term::snd_pair().apply(Term::var(format!("__pair_{list_id}")));
convert_data_to_type( term = if is_expect {
Term::snd_pair().apply(Term::var(format!("__pair_{list_id}"))), if otherwise == Term::Error.delay() {
term.lambda(name)
.apply(unknown_data_to_type(value, &inner_types[1]))
} else {
softcast_data_to_type_otherwise(
value,
&name,
&inner_types[1], &inner_types[1],
term,
otherwise.clone(), otherwise.clone(),
) )
}
} else { } else {
known_data_to_type( term.lambda(name)
Term::snd_pair().apply(Term::var(format!("__pair_{list_id}"))), .apply(known_data_to_type(value, &inner_types[1]))
&inner_types[1], }
)
});
} }
if let Some(name) = fst { if let Some(name) = fst {
term = term.lambda(name).apply(if is_expect { let value = Term::fst_pair().apply(Term::var(format!("__pair_{list_id}")));
convert_data_to_type( term = if is_expect {
Term::fst_pair().apply(Term::var(format!("__pair_{list_id}"))), if otherwise == Term::Error.delay() {
term.lambda(name)
.apply(unknown_data_to_type(value, &inner_types[0]))
} else {
softcast_data_to_type_otherwise(
value,
&name,
&inner_types[0], &inner_types[0],
term,
otherwise, otherwise,
) )
}
} else { } else {
known_data_to_type( term.lambda(name)
Term::fst_pair().apply(Term::var(format!("__pair_{list_id}"))), .apply(known_data_to_type(value, &inner_types[0]))
&inner_types[0], }
)
})
} }
term = term.lambda(format!("__pair_{list_id}")).apply(value); term = term.lambda(format!("__pair_{list_id}")).apply(value);
@ -5807,6 +5814,13 @@ impl<'a> CodeGenerator<'a> {
Some(term) Some(term)
} }
Air::SoftCastLet { name, tipo } => {
let value = arg_stack.pop().unwrap();
let then = arg_stack.pop().unwrap();
let otherwise = arg_stack.pop().unwrap();
todo!()
}
} }
} }
} }

View File

@ -858,8 +858,8 @@ pub fn known_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
match uplc_type { match uplc_type {
Some(UplcType::Integer) => Term::un_i_data().apply(term), Some(UplcType::Integer) => Term::un_i_data().apply(term),
Some(UplcType::ByteString) => Term::un_b_data().apply(term), Some(UplcType::ByteString) => Term::un_b_data().apply(term),
Some(UplcType::Bool) => Term::less_than_integer() Some(UplcType::Bool) => Term::equals_integer()
.apply(Term::integer(0.into())) .apply(Term::integer(1.into()))
.apply(Term::fst_pair().apply(Term::unconstr_data().apply(term))), .apply(Term::fst_pair().apply(Term::unconstr_data().apply(term))),
Some(UplcType::String) => Term::decode_utf8().apply(Term::un_b_data().apply(term)), Some(UplcType::String) => Term::decode_utf8().apply(Term::un_b_data().apply(term)),
Some(UplcType::Unit) => Term::unit().lambda("_").apply(term), Some(UplcType::Unit) => Term::unit().lambda("_").apply(term),
@ -915,15 +915,14 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
Some(UplcType::Bool) => Term::snd_pair() Some(UplcType::Bool) => Term::snd_pair()
.apply(Term::var("__pair__")) .apply(Term::var("__pair__"))
.delayed_choose_list( .delayed_choose_list(
Term::equals_integer() Term::less_than_equals_integer()
.apply(Term::integer(1.into())) .apply(Term::integer(2.into()))
.apply(Term::fst_pair().apply(Term::var("__pair__"))) .apply(Term::fst_pair().apply(Term::var("__pair__")))
.delayed_if_then_else( .delayed_if_then_else(
Term::bool(true), Term::Error,
Term::equals_integer() Term::equals_integer()
.apply(Term::integer(0.into())) .apply(Term::integer(1.into()))
.apply(Term::fst_pair().apply(Term::var("__pair__"))) .apply(Term::fst_pair().apply(Term::var("__pair__"))),
.delayed_if_then_else(Term::bool(false), Term::Error),
), ),
Term::Error, Term::Error,
) )

View File

@ -988,7 +988,7 @@ impl Term<Name> {
} }
} }
fn pierce_no_inlines(&self) -> &Self { pub fn pierce_no_inlines(&self) -> &Self {
let mut term = self; let mut term = self;
while let Term::Lambda { while let Term::Lambda {