Add evaluating of simple maths
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
05c095ccfe
commit
d222573a3a
8 changed files with 543 additions and 4 deletions
|
|
@ -96,8 +96,9 @@ pub fn execute(vm: &VMInstructions, global_context: &Context) -> Result<String,
|
|||
scopes.insert_into_slot(*slot, value.clone());
|
||||
}
|
||||
Instruction::EmitFromSlot { slot } => {
|
||||
let value = scopes.get(slot).as_str().unwrap();
|
||||
output.push_str(value);
|
||||
let value = scopes.get(slot).try_to_string().unwrap();
|
||||
|
||||
output.push_str(&value);
|
||||
}
|
||||
Instruction::PushScope { inherit_parent: _ } => {
|
||||
scopes.push_scope();
|
||||
|
|
@ -186,6 +187,26 @@ pub fn execute(vm: &VMInstructions, global_context: &Context) -> Result<String,
|
|||
} => {
|
||||
scopes.insert_into_slot(*slot, value.clone());
|
||||
}
|
||||
Instruction::MathOperate {
|
||||
op,
|
||||
left_slot,
|
||||
right_slot,
|
||||
result_slot,
|
||||
} => {
|
||||
let left_value = scopes.get(left_slot);
|
||||
let right_value = scopes.get(right_slot);
|
||||
|
||||
let result = match op {
|
||||
crate::parser::TokenOperator::Plus => left_value.try_add(right_value),
|
||||
crate::parser::TokenOperator::Minus => left_value.try_sub(right_value),
|
||||
crate::parser::TokenOperator::Times => left_value.try_mul(right_value),
|
||||
crate::parser::TokenOperator::Divide => left_value.try_div(right_value),
|
||||
crate::parser::TokenOperator::And => left_value.try_and(right_value),
|
||||
crate::parser::TokenOperator::Or => left_value.try_or(right_value),
|
||||
};
|
||||
|
||||
scopes.insert_into_slot(*result_slot, result.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
ip += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue