tests 1 through 10 pass now, add negate

This commit is contained in:
Kasey White 2022-12-15 02:04:27 -05:00 committed by Lucas
parent 6e46e7562e
commit eddd202253
3 changed files with 28 additions and 4 deletions

View File

@ -216,7 +216,6 @@ pub enum Air {
Negate {
scope: Vec<u64>,
value: Box<Self>,
},
TupleAccessor {

View File

@ -747,7 +747,8 @@ pub fn match_ir_for_recursion(
pub fn find_generics_to_replace(tipo: &mut Arc<Type>, generic_types: &HashMap<u64, Arc<Type>>) {
if let Some(id) = tipo.get_generic() {
*tipo = generic_types.get(&id).unwrap().clone();
//If generic does not have a type we know of like a None in option then just use same type
*tipo = generic_types.get(&id).unwrap_or(tipo).clone();
} else if tipo.is_generic() {
match &**tipo {
Type::App {

View File

@ -484,7 +484,13 @@ impl<'a> CodeGenerator<'a> {
});
}
TypedExpr::RecordUpdate { .. } => todo!(),
TypedExpr::Negate { .. } => todo!(),
TypedExpr::Negate { value, .. } => {
ir_stack.push(Air::Negate {
scope: scope.clone(),
});
self.build_ir(value, ir_stack, scope);
}
TypedExpr::Tuple { elems, tipo, .. } => {
ir_stack.push(Air::Tuple {
scope: scope.clone(),
@ -3638,7 +3644,25 @@ impl<'a> CodeGenerator<'a> {
}
Air::Record { .. } => todo!(),
Air::RecordUpdate { .. } => todo!(),
Air::Negate { .. } => todo!(),
Air::Negate { .. } => {
let value = arg_stack.pop().unwrap();
let term = Term::Apply {
function: Term::Apply {
function: Term::Apply {
function: Term::Builtin(DefaultFunction::IfThenElse)
.force_wrap()
.into(),
argument: value.into(),
}
.into(),
argument: Term::Constant(UplcConstant::Bool(false)).into(),
}
.into(),
argument: Term::Constant(UplcConstant::Bool(true)).into(),
};
arg_stack.push(term);
}
Air::TupleAccessor { tipo, names, .. } => {
let value = arg_stack.pop().unwrap();
let mut term = arg_stack.pop().unwrap();