mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DEV: Tuple and List values are translatable.
This commit is contained in:
parent
52a66bae8b
commit
422569c7b4
@ -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]
|
||||
|
@ -186,7 +186,7 @@ impl AST {
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_value(value: Value, ops: &mut Vec<Op>) {
|
||||
fn translate_value(value: Value, mut ops: &mut Vec<Op>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user