Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ impl Compiler {
// We cannot handle this exception type:
emit!(
self,
Instruction::JumpIfFalse {
Instruction::PopJumpIfFalse {
target: next_handler,
}
);
Expand Down Expand Up @@ -3117,7 +3117,7 @@ impl Compiler {
JumpOp::PopJumpIfFalse => {
emit!(
self,
Instruction::JumpIfFalse {
Instruction::PopJumpIfFalse {
target: pc.fail_pop[pops]
}
);
Expand Down Expand Up @@ -4398,14 +4398,14 @@ impl Compiler {
if condition {
emit!(
self,
Instruction::JumpIfTrue {
Instruction::PopJumpIfTrue {
target: target_block,
}
);
} else {
emit!(
self,
Instruction::JumpIfFalse {
Instruction::PopJumpIfFalse {
target: target_block,
}
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions compiler/core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ pub enum Instruction {
Swap {
index: Arg<u32>,
},
// ToBool,
ToBool,
Rotate2,
Rotate3,
Duplicate,
Expand All @@ -548,11 +548,11 @@ pub enum Instruction {
target: Arg<Label>,
},
/// Pop the top of the stack, and jump if this value is true.
JumpIfTrue {
PopJumpIfTrue {
target: Arg<Label>,
},
/// Pop the top of the stack, and jump if this value is false.
JumpIfFalse {
PopJumpIfFalse {
target: Arg<Label>,
},
/// Peek at the top of the stack, and jump if this value is true.
Expand Down Expand Up @@ -1255,8 +1255,8 @@ impl Instruction {
pub const fn label_arg(&self) -> Option<Arg<Label>> {
match self {
Jump { target: l }
| JumpIfTrue { target: l }
| JumpIfFalse { target: l }
| PopJumpIfTrue { target: l }
| PopJumpIfFalse { target: l }
| JumpIfTrueOrPop { target: l }
| JumpIfFalseOrPop { target: l }
| ForIter { target: l }
Expand Down Expand Up @@ -1330,7 +1330,7 @@ impl Instruction {
CopyItem { .. } => 1,
Pop => -1,
Swap { .. } => 0,
// ToBool => 0,
ToBool => 0,
Rotate2 | Rotate3 => 0,
Duplicate => 1,
Duplicate2 => 2,
Expand All @@ -1341,7 +1341,7 @@ impl Instruction {
Continue { .. } => 0,
Break { .. } => 0,
Jump { .. } => 0,
JumpIfTrue { .. } | JumpIfFalse { .. } => -1,
PopJumpIfTrue { .. } | PopJumpIfFalse { .. } => -1,
JumpIfTrueOrPop { .. } | JumpIfFalseOrPop { .. } => {
if jump {
0
Expand Down Expand Up @@ -1533,7 +1533,7 @@ impl Instruction {
CopyItem { index } => w!(CopyItem, index),
Pop => w!(Pop),
Swap { index } => w!(Swap, index),
// ToBool => w!(ToBool),
ToBool => w!(ToBool),
Rotate2 => w!(Rotate2),
Rotate3 => w!(Rotate3),
Duplicate => w!(Duplicate),
Expand All @@ -1546,8 +1546,8 @@ impl Instruction {
Continue { target } => w!(Continue, target),
Break { target } => w!(Break, target),
Jump { target } => w!(Jump, target),
JumpIfTrue { target } => w!(JumpIfTrue, target),
JumpIfFalse { target } => w!(JumpIfFalse, target),
PopJumpIfTrue { target } => w!(PopJumpIfTrue, target),
PopJumpIfFalse { target } => w!(PopJumpIfFalse, target),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
MakeFunction => w!(MakeFunction),
Expand Down
4 changes: 2 additions & 2 deletions jit/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
) -> Result<(), JitCompileError> {
match instruction {
Instruction::ExtendedArg => Ok(()),
Instruction::JumpIfFalse { target } => {
Instruction::PopJumpIfFalse { target } => {
let cond = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
let val = self.boolean_val(cond)?;
let then_block = self.get_or_create_block(target.get(arg));
Expand All @@ -288,7 +288,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {

Ok(())
}
Instruction::JumpIfTrue { target } => {
Instruction::PopJumpIfTrue { target } => {
let cond = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
let val = self.boolean_val(cond)?;
let then_block = self.get_or_create_block(target.get(arg));
Expand Down
21 changes: 17 additions & 4 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,12 @@ impl ExecutingFrame<'_> {
self.push_value(vm.ctx.new_int(len).into());
Ok(None)
}
bytecode::Instruction::ToBool => {
let obj = self.pop_value();
let bool_val = obj.try_to_bool(vm)?;
self.push_value(vm.ctx.new_bool(bool_val).into());
Ok(None)
}
bytecode::Instruction::CallIntrinsic1 { func } => {
let value = self.pop_value();
let result = self.call_intrinsic_1(func.get(arg), value, vm)?;
Expand Down Expand Up @@ -1227,9 +1233,11 @@ impl ExecutingFrame<'_> {
self.jump(target.get(arg));
Ok(None)
}
bytecode::Instruction::JumpIfTrue { target } => self.jump_if(vm, target.get(arg), true),
bytecode::Instruction::JumpIfFalse { target } => {
self.jump_if(vm, target.get(arg), false)
bytecode::Instruction::PopJumpIfTrue { target } => {
self.pop_jump_if(vm, target.get(arg), true)
}
bytecode::Instruction::PopJumpIfFalse { target } => {
self.pop_jump_if(vm, target.get(arg), false)
}
bytecode::Instruction::JumpIfTrueOrPop { target } => {
self.jump_if_or_pop(vm, target.get(arg), true)
Expand Down Expand Up @@ -1839,7 +1847,12 @@ impl ExecutingFrame<'_> {
}

#[inline]
fn jump_if(&mut self, vm: &VirtualMachine, target: bytecode::Label, flag: bool) -> FrameResult {
fn pop_jump_if(
&mut self,
vm: &VirtualMachine,
target: bytecode::Label,
flag: bool,
) -> FrameResult {
let obj = self.pop_value();
let value = obj.try_to_bool(vm)?;
if value == flag {
Expand Down
Loading