feat(tazjin/rlox): Implement simple conditionals
... basically just optional blocks (no else). Change-Id: If091c6b8fdeb6c13a5f3dd284d0a9a87f9f4228d Reviewed-on: https://cl.tvl.fyi/c/depot/+/3739 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
d57e43e161
commit
670662a360
4 changed files with 84 additions and 16 deletions
|
|
@ -201,8 +201,27 @@ impl VM {
|
|||
}
|
||||
|
||||
OpCode::OpSetLocal(local_idx) => {
|
||||
debug_assert!(self.stack.len() > local_idx.0, "stack is not currently large enough for local");
|
||||
self.stack[local_idx.0] = self.stack.last().unwrap().clone();
|
||||
debug_assert!(
|
||||
self.stack.len() > local_idx.0,
|
||||
"stack is not currently large enough for local"
|
||||
);
|
||||
self.stack[local_idx.0] =
|
||||
self.stack.last().unwrap().clone();
|
||||
}
|
||||
|
||||
OpCode::OpJumpPlaceholder(_) => {
|
||||
panic!("unpatched jump detected - this is a fatal compiler error!");
|
||||
}
|
||||
|
||||
OpCode::OpJumpIfFalse(offset) => {
|
||||
if self
|
||||
.stack
|
||||
.last()
|
||||
.expect("condition should leave a value on the stack")
|
||||
.is_falsey()
|
||||
{
|
||||
self.ip += offset.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue