[fine] Assignments!

And new error capabilities!
This commit is contained in:
John Doty 2024-01-19 19:08:17 -08:00
parent 92cf840766
commit f20f5a5e03
12 changed files with 400 additions and 64 deletions

View file

@ -161,6 +161,15 @@ impl Frame {
}
}
fn store_argument(&mut self, i: usize, v: StackValue) -> Result<()> {
if i >= self.locals.len() {
Err(VMErrorCode::LocalOutOfRange(i))
} else {
self.args[i] = v;
Ok(())
}
}
fn pop_function(&mut self) -> Result<FuncValue> {
match self.pop_value()? {
StackValue::Function(f) => Ok(FuncValue::Function(f)),
@ -236,6 +245,11 @@ fn eval_one(
Instruction::Discard => {
f.pop_value()?;
}
Instruction::Dup => {
let v = f.pop_value()?;
f.push_value(v.clone());
f.push_value(v);
}
Instruction::FloatAdd => {
let x = f.pop_float()?;
let y = f.pop_float()?;
@ -300,6 +314,10 @@ fn eval_one(
Instruction::PushTrue => {
f.push_bool(true);
}
Instruction::StoreArgument(i) => {
let v = f.pop_value()?;
f.store_argument(i, v)?;
}
Instruction::StoreLocal(i) => {
let v = f.pop_value()?;
f.store_local(i, v)?;