diff --git a/src/build/opcode/test.rs b/src/build/opcode/test.rs index 3a45866..2ecc017 100644 --- a/src/build/opcode/test.rs +++ b/src/build/opcode/test.rs @@ -606,6 +606,14 @@ fn simple_binary_expr() { ) } +#[test] +fn simple_let_statements() { + assert_parse_cases![ + "let foo = 1; foo;" => P(Int(1)), + "let foo = 1 + 1; foo;" => P(Int(2)), + ]; +} + #[test] fn dot_expressions() { let mut ops = vec![ diff --git a/src/build/opcode/translate.rs b/src/build/opcode/translate.rs index b120dd5..f8bbdf1 100644 --- a/src/build/opcode/translate.rs +++ b/src/build/opcode/translate.rs @@ -27,7 +27,12 @@ impl AST { Statement::Assert(_, _) => { unimplemented!("Assert statements are not implmented yet") } - Statement::Let(_) => unimplemented!("Let statements are not implmented yet"), + Statement::Let(def) => { + let binding = def.name.fragment; + ops.push(Op::Sym(binding)); + Self::translate_expr(def.value, &mut ops); + ops.push(Op::Bind); + } Statement::Output(_, _, _) => { unimplemented!("Out statements are not implmented yet") }