diff --git a/src/build/opcode/test.rs b/src/build/opcode/test.rs index 2ecc017..b6e439c 100644 --- a/src/build/opcode/test.rs +++ b/src/build/opcode/test.rs @@ -616,23 +616,13 @@ fn simple_let_statements() { #[test] fn dot_expressions() { - let mut ops = vec![ - Sym("foo".to_owned()), - InitList, - Val(Int(0)), - Element, - Val(Int(1)), - Element, - Val(Int(2)), - Element, - Bind, + assert_parse_cases![ + "let foo = [0,1,2]; foo.0;" => P(Int(0)), + "let foo = [0,1,2]; foo.2;" => P(Int(2)), + "let tpl = { foo = 1 }; tpl.foo;" => P(Int(1)), + "let tpl = { foo = { bar = 2 } }; tpl.foo.bar;" => P(Int(2)), + "let tpl = { foo = [ 3 ] }; tpl.foo.0;" => P(Int(3)), ]; - - let stmts = parse(OffsetStrIter::from(dbg!("foo.0;")), None).unwrap(); - ops.append(&mut translate::AST::translate(stmts)); - let ops = Rc::new(ops); - let mut vm = VM::new("foo.ucg", ops.clone()); - vm.run().unwrap(); } #[test] diff --git a/src/build/opcode/translate.rs b/src/build/opcode/translate.rs index f8bbdf1..559a8ca 100644 --- a/src/build/opcode/translate.rs +++ b/src/build/opcode/translate.rs @@ -186,7 +186,7 @@ impl AST { } } - fn translate_value(value: Value, ops: &mut Vec) { + fn translate_value(value: Value, mut ops: &mut Vec) { match value { Value::Int(i) => ops.push(Op::Val(Primitive::Int(i.val))), Value::Float(f) => ops.push(Op::Val(Primitive::Float(f.val))), @@ -196,8 +196,21 @@ impl AST { Value::Symbol(s) => { ops.push(Op::DeRef(s.val)); } - Value::Tuple(_flds) => unimplemented!("Select expression are not implmented yet"), - Value::List(_els) => unimplemented!("Select expression are not implmented yet"), + Value::Tuple(flds) => { + ops.push(Op::InitTuple); + for (k, v) in flds.val { + ops.push(Op::Sym(k.fragment)); + Self::translate_expr(v, &mut ops); + ops.push(Op::Field); + } + } + Value::List(els) => { + ops.push(Op::InitList); + for el in els.elems { + Self::translate_expr(el, &mut ops); + ops.push(Op::Element); + } + } } } }