Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix some jit
  • Loading branch information
ShaharNaveh committed Mar 2, 2026
commit aad0560a5a698e23100b9f005f055240173b1883
45 changes: 23 additions & 22 deletions crates/jit/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {

Ok(())
}
Instruction::BuildTuple { size } => {
let elements = self.pop_multiple(size.get(arg) as usize);
Instruction::BuildTuple { count } => {
let elements = self.pop_multiple(count.get(arg) as usize);
self.stack.push(JitValue::Tuple(elements));
Ok(())
}
Instruction::Call { nargs } => {
let nargs = nargs.get(arg);
Instruction::Call { argc } => {
let nargs = argc.get(arg);

let mut args = Vec::new();
for _ in 0..nargs {
Expand Down Expand Up @@ -562,8 +562,8 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
_ => Err(JitCompileError::NotSupported),
}
}
Instruction::CompareOp { op, .. } => {
let op = op.get(arg);
Instruction::CompareOp { opname } => {
let op = opname.get(arg);
// the rhs is popped off first
let b = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
let a = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
Expand Down Expand Up @@ -627,9 +627,10 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
self.builder.ins().jump(target_block, &[]);
Ok(())
}
Instruction::LoadConst { idx } => {
let val = self
.prepare_const(bytecode.constants[idx.get(arg) as usize].borrow_constant())?;
Instruction::LoadConst { consti } => {
let val = self.prepare_const(
bytecode.constants[consti.get(arg) as usize].borrow_constant(),
)?;
self.stack.push(val);
Ok(())
}
Expand All @@ -639,8 +640,8 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
self.stack.push(JitValue::Int(val));
Ok(())
}
Instruction::LoadFast(idx) | Instruction::LoadFastBorrow(idx) => {
let local = self.variables[idx.get(arg) as usize]
Instruction::LoadFast { namei } | Instruction::LoadFastBorrow { namei } => {
let local = self.variables[namei.get(arg) as usize]
.as_ref()
.ok_or(JitCompileError::BadBytecode)?;
self.stack.push(JitValue::from_type_and_value(
Expand All @@ -649,9 +650,9 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
));
Ok(())
}
Instruction::LoadFastLoadFast { arg: packed }
| Instruction::LoadFastBorrowLoadFastBorrow { arg: packed } => {
let oparg = packed.get(arg);
Instruction::LoadFastLoadFast { var_num }
| Instruction::LoadFastBorrowLoadFastBorrow { var_nums: var_num } => {
let oparg = var_num.get(arg);
let idx1 = oparg >> 4;
let idx2 = oparg & 0xF;
for idx in [idx1, idx2] {
Expand All @@ -665,8 +666,8 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
}
Ok(())
}
Instruction::LoadGlobal(idx) => {
let oparg = idx.get(arg);
Instruction::LoadGlobal { namei } => {
let oparg = namei.get(arg);
let name = &bytecode.names[(oparg >> 1) as usize];

if name.as_ref() != bytecode.obj_name.as_ref() {
Expand Down Expand Up @@ -714,19 +715,19 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
self.stack.pop();
Ok(())
}
Instruction::Resume { arg: _resume_arg } => {
Instruction::Resume { .. } => {
// TODO: Implement the resume instruction
Ok(())
}
Instruction::ReturnValue => {
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
self.return_value(val)
}
Instruction::StoreFast(idx) => {
Instruction::StoreFast { namei } => {
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
self.store_variable(idx.get(arg), val)
self.store_variable(namei.get(arg), val)
}
Instruction::Swap { index } => {
Instruction::Swap { i: index } => {
let len = self.stack.len();
let i = len - 1;
let j = len - 1 - index.get(arg) as usize;
Expand Down Expand Up @@ -760,15 +761,15 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
_ => Err(JitCompileError::NotSupported),
}
}
Instruction::UnpackSequence { size } => {
Instruction::UnpackSequence { count } => {
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;

let elements = match val {
JitValue::Tuple(elements) => elements,
_ => return Err(JitCompileError::NotSupported),
};

if elements.len() != size.get(arg) as usize {
if elements.len() != count.get(arg) as usize {
return Err(JitCompileError::NotSupported);
}

Expand Down
Loading