[fine] More tests and also comparisons
This commit is contained in:
parent
55749af917
commit
7fb88ef199
5 changed files with 101 additions and 4 deletions
|
|
@ -95,6 +95,13 @@ impl Frame {
|
|||
}
|
||||
}
|
||||
|
||||
fn pop_string(&mut self) -> Result<Rc<str>> {
|
||||
match self.pop_value()? {
|
||||
StackValue::String(v) => Ok(v),
|
||||
v => Err(VMErrorCode::StackTypeMismatch(v, Type::String)),
|
||||
}
|
||||
}
|
||||
|
||||
fn push_value(&mut self, v: StackValue) {
|
||||
self.stack.push(v)
|
||||
}
|
||||
|
|
@ -237,10 +244,10 @@ fn eval_one(
|
|||
Instruction::FloatDivide => {
|
||||
let x = f.pop_float()?;
|
||||
let y = f.pop_float()?;
|
||||
if y == 0. {
|
||||
if x == 0. {
|
||||
return Err(VMErrorCode::DivideByZero);
|
||||
}
|
||||
f.push_float(x / y);
|
||||
f.push_float(y / x);
|
||||
}
|
||||
Instruction::FloatMultiply => {
|
||||
let x = f.pop_float()?;
|
||||
|
|
@ -250,7 +257,7 @@ fn eval_one(
|
|||
Instruction::FloatSubtract => {
|
||||
let x = f.pop_float()?;
|
||||
let y = f.pop_float()?;
|
||||
f.push_float(x - y);
|
||||
f.push_float(y - x);
|
||||
}
|
||||
Instruction::Jump(i) => {
|
||||
*index = i;
|
||||
|
|
@ -335,6 +342,30 @@ fn eval_one(
|
|||
}
|
||||
None => return Ok(Flow::Break),
|
||||
},
|
||||
Instruction::StringAdd => {
|
||||
let x = f.pop_string()?;
|
||||
let y = f.pop_string()?;
|
||||
|
||||
let mut new_string = x.to_string();
|
||||
new_string.push_str(&y);
|
||||
|
||||
f.push_string(new_string.into());
|
||||
}
|
||||
Instruction::CompareBool => {
|
||||
let x = f.pop_bool()?;
|
||||
let y = f.pop_bool()?;
|
||||
f.push_bool(x == y);
|
||||
}
|
||||
Instruction::CompareFloat => {
|
||||
let x = f.pop_float()?;
|
||||
let y = f.pop_float()?;
|
||||
f.push_bool(x == y);
|
||||
}
|
||||
Instruction::CompareString => {
|
||||
let x = f.pop_string()?;
|
||||
let y = f.pop_string()?;
|
||||
f.push_bool(x == y);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Flow::Continue)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue