From eddd2022535e98027d3ef1428684c373b257f28e Mon Sep 17 00:00:00 2001 From: Kasey White Date: Thu, 15 Dec 2022 02:04:27 -0500 Subject: [PATCH] tests 1 through 10 pass now, add negate --- crates/lang/src/air.rs | 1 - crates/lang/src/builder.rs | 3 ++- crates/lang/src/uplc.rs | 28 ++++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/lang/src/air.rs b/crates/lang/src/air.rs index 9a8e8ee8..2a0b473f 100644 --- a/crates/lang/src/air.rs +++ b/crates/lang/src/air.rs @@ -216,7 +216,6 @@ pub enum Air { Negate { scope: Vec, - value: Box, }, TupleAccessor { diff --git a/crates/lang/src/builder.rs b/crates/lang/src/builder.rs index 522d2ea2..8a7b2654 100644 --- a/crates/lang/src/builder.rs +++ b/crates/lang/src/builder.rs @@ -747,7 +747,8 @@ pub fn match_ir_for_recursion( pub fn find_generics_to_replace(tipo: &mut Arc, generic_types: &HashMap>) { 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 { diff --git a/crates/lang/src/uplc.rs b/crates/lang/src/uplc.rs index 74a470ed..b01669c9 100644 --- a/crates/lang/src/uplc.rs +++ b/crates/lang/src/uplc.rs @@ -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();