Finish up branch implementation
* while and unconditional loops are now supported fully * break and continue keywords for loop control * List::thunkify() has been broken into its own structure so it can be broken out further as necessary Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -42,10 +42,11 @@ pub enum Inst {
|
||||
Jump(usize),
|
||||
|
||||
/// Jump to a given address in the current function if the condition flag is true.
|
||||
///
|
||||
/// The condition flag may be set by an internal function.
|
||||
JumpTrue(usize),
|
||||
|
||||
/// Jump to a given address in the current function if the condition flag is false.
|
||||
JumpFalse(usize),
|
||||
|
||||
/// Calls a function with the supplied number of arguments.
|
||||
///
|
||||
/// The stack, from bottom to top, should contain the function followed by the arguments.
|
||||
@@ -83,6 +84,7 @@ impl Inst {
|
||||
Inst::CheckTruth => "CHECK_TRUTH",
|
||||
Inst::Jump(_) => "JUMP",
|
||||
Inst::JumpTrue(_) => "JUMP_TRUE",
|
||||
Inst::JumpFalse(_) => "JUMP_FALSE",
|
||||
Inst::Call(_) => "CALL",
|
||||
Inst::Index => "INDEX",
|
||||
Inst::Return => "RETURN",
|
||||
|
||||
@@ -267,7 +267,12 @@ impl<'c> Vm<'c> {
|
||||
next_pc = addr;
|
||||
}
|
||||
Inst::JumpTrue(addr) => {
|
||||
if self.condition {
|
||||
if !self.condition {
|
||||
next_pc = addr;
|
||||
}
|
||||
}
|
||||
Inst::JumpFalse(addr) => {
|
||||
if !self.condition {
|
||||
next_pc = addr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user