mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DEV: simple expressions don't leave their values on the stack.
This commit is contained in:
parent
f1180dbc5f
commit
45819f5406
@ -584,7 +584,7 @@ macro_rules! assert_parse_cases {
|
||||
let env = Rc::new(RefCell::new(Environment::new(Vec::new(), Vec::new())));
|
||||
let mut vm = VM::new(ops.clone(), env);
|
||||
vm.run().unwrap();
|
||||
assert_eq!(vm.pop().unwrap().0, Rc::new(case.1));
|
||||
assert_eq!(vm.last.unwrap().0, Rc::new(case.1));
|
||||
}
|
||||
};
|
||||
|
||||
@ -769,7 +769,7 @@ fn simple_trace() {
|
||||
let env = Rc::new(RefCell::new(Environment::new(Vec::new(), Vec::new())));
|
||||
let mut vm = VM::new(ops.clone(), env);
|
||||
vm.run().unwrap();
|
||||
assert_eq!(vm.pop().unwrap().0, Rc::new(P(Int(2))));
|
||||
assert_eq!(vm.last.unwrap().0, Rc::new(P(Int(2))));
|
||||
let err_out = &vm.env.borrow().stderr;
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(err_out).to_owned(),
|
||||
|
@ -55,7 +55,11 @@ impl AST {
|
||||
fn translate_stmts(stmts: Vec<Statement>, mut ops: &mut PositionMap, root: &Path) {
|
||||
for stmt in stmts {
|
||||
match stmt {
|
||||
Statement::Expression(expr) => Self::translate_expr(expr, &mut ops, root),
|
||||
Statement::Expression(expr) => {
|
||||
let expr_pos = expr.pos().clone();
|
||||
Self::translate_expr(expr, &mut ops, root);
|
||||
ops.push(Op::Pop, expr_pos);
|
||||
}
|
||||
Statement::Assert(_, _) => {
|
||||
unimplemented!("Assert statements are not implmented yet")
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ where
|
||||
runtime: runtime::Builtins,
|
||||
ops: OpPointer,
|
||||
pub env: Rc<RefCell<Environment<O, E>>>,
|
||||
pub last: Option<(Rc<Value>, Position)>,
|
||||
}
|
||||
|
||||
impl<'a, O, E> VM<O, E>
|
||||
@ -56,6 +57,7 @@ where
|
||||
runtime: runtime::Builtins::new(),
|
||||
ops: ops,
|
||||
env: env,
|
||||
last: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,6 +68,7 @@ where
|
||||
runtime: self.runtime.clone(),
|
||||
ops: self.ops.clone(),
|
||||
env: self.env.clone(),
|
||||
last: self.last,
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +138,7 @@ where
|
||||
return Ok(());
|
||||
}
|
||||
Op::Pop => {
|
||||
self.pop()?;
|
||||
self.last = Some(self.pop()?);
|
||||
}
|
||||
Op::Typ => self.op_typ()?,
|
||||
Op::Runtime(h) => self.op_runtime(h, pos)?,
|
||||
|
Loading…
x
Reference in New Issue
Block a user