From 6162128427a2903272c4e3bb262e23fcdf30b04e Mon Sep 17 00:00:00 2001 From: Kasey White Date: Mon, 31 Oct 2022 01:35:14 -0400 Subject: [PATCH] add string comparison and int comparison --- crates/project/src/lib.rs | 116 ++++++++++++++++++++++++++-- examples/sample/src/sample.ak | 7 +- examples/sample/src/scripts/swap.ak | 17 +++- 3 files changed, 129 insertions(+), 11 deletions(-) diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index dc6ea3e3..ef5669ed 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -460,6 +460,8 @@ impl Project { interner.program(&mut program); + println!("{}", program.to_pretty()); + programs.push(program.try_into().unwrap()); } } @@ -484,7 +486,7 @@ impl Project { &ast::ModuleConstant, String>, >, ) { - match dbg!(body) { + match body { TypedExpr::Int { value, .. } => {} TypedExpr::String { value, .. } => {} TypedExpr::ByteArray { bytes, .. } => {} @@ -568,9 +570,44 @@ impl Project { name, left, right, - } => { - todo!() - } + } => match name { + ast::BinOp::And => todo!(), + ast::BinOp::Or => todo!(), + ast::BinOp::Eq => { + self.recurse_scope_level( + left, + scripts, + scope_level.clone(), + uplc_function_holder_lookup, + functions, + type_aliases, + data_types, + imports, + constants, + ); + self.recurse_scope_level( + right, + scripts, + scope_level, + uplc_function_holder_lookup, + functions, + type_aliases, + data_types, + imports, + constants, + ); + } + ast::BinOp::NotEq => todo!(), + ast::BinOp::LtInt => todo!(), + ast::BinOp::LtEqInt => todo!(), + ast::BinOp::GtEqInt => todo!(), + ast::BinOp::GtInt => todo!(), + ast::BinOp::AddInt => todo!(), + ast::BinOp::SubInt => todo!(), + ast::BinOp::MultInt => todo!(), + ast::BinOp::DivInt => todo!(), + ast::BinOp::ModInt => todo!(), + }, TypedExpr::Assignment { location, tipo, @@ -933,7 +970,76 @@ impl Project { left, right, } => { - todo!() + let left_term = self.recurse_code_gen( + left, + scripts, + scope_level.clone(), + uplc_function_holder, + uplc_function_holder_lookup, + functions, + type_aliases, + data_types, + imports, + constants, + ); + + let right_term = self.recurse_code_gen( + right, + scripts, + scope_level, + uplc_function_holder, + uplc_function_holder_lookup, + functions, + type_aliases, + data_types, + imports, + constants, + ); + + match name { + ast::BinOp::And => todo!(), + ast::BinOp::Or => todo!(), + ast::BinOp::Eq => match &*left.tipo() { + tipo::Type::App { + public, + module, + name, + args, + } => match name.as_str() { + "Int" => Term::Apply { + function: Term::Apply { + function: Term::Builtin(DefaultFunction::EqualsInteger).into(), + argument: left_term.into(), + } + .into(), + argument: right_term.into(), + }, + + "String" => Term::Apply { + function: Term::Apply { + function: Term::Builtin(DefaultFunction::EqualsString).into(), + argument: left_term.into(), + } + .into(), + argument: right_term.into(), + }, + + _ => todo!(), + }, + tipo::Type::Fn { args, ret } => todo!(), + tipo::Type::Var { tipo } => todo!(), + }, + ast::BinOp::NotEq => todo!(), + ast::BinOp::LtInt => todo!(), + ast::BinOp::LtEqInt => todo!(), + ast::BinOp::GtEqInt => todo!(), + ast::BinOp::GtInt => todo!(), + ast::BinOp::AddInt => todo!(), + ast::BinOp::SubInt => todo!(), + ast::BinOp::MultInt => todo!(), + ast::BinOp::DivInt => todo!(), + ast::BinOp::ModInt => todo!(), + } } TypedExpr::Assignment { location, diff --git a/examples/sample/src/sample.ak b/examples/sample/src/sample.ak index 8983ac74..7cfd74b9 100644 --- a/examples/sample/src/sample.ak +++ b/examples/sample/src/sample.ak @@ -6,7 +6,10 @@ pub type Datum { something: String, } -pub fn thing(a: Bool) { - a +pub fn eqInt(a: Int, b: Int) { + a == b } +pub fn eqString(a: String, b: String) { + a == b +} diff --git a/examples/sample/src/scripts/swap.ak b/examples/sample/src/scripts/swap.ak index b7221c63..0e02ac04 100644 --- a/examples/sample/src/scripts/swap.ak +++ b/examples/sample/src/scripts/swap.ak @@ -9,9 +9,18 @@ pub type Redeemer { pub fn spend(datum: sample.Datum, rdmr: Redeemer, ctx: spend.ScriptContext) -> Bool { - let a = True - let b = sample.thing(a) - let c = sample.thing(b) - c + let x = "x" + let a = "y" + let b = sample.eqString(x, a) + let c = 1 + let y = 1 + let d = sample.eqInt(y, c) + + if b { + c == 1 + } else{ + d + } + }