Skip to content

Commit 87eeba9

Browse files
committed
fix jit
1 parent 6f81e21 commit 87eeba9

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

crates/jit/src/instructions.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cranelift::prelude::*;
66
use num_traits::cast::ToPrimitive;
77
use rustpython_compiler_core::bytecode::{
88
self, BinaryOperator, BorrowedConstant, CodeObject, ComparisonOperator, Instruction,
9-
IntrinsicFunction1, Label, OpArg, OpArgState,
9+
IntrinsicFunction1, Label, OpArg, OpArgState, oparg,
1010
};
1111
use std::collections::HashMap;
1212

@@ -94,7 +94,10 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
9494
let params = compiler.builder.func.dfg.block_params(entry_block).to_vec();
9595
for (i, (ty, val)) in arg_types.iter().zip(params).enumerate() {
9696
compiler
97-
.store_variable(i as u32, JitValue::from_type_and_value(ty.clone(), val))
97+
.store_variable(
98+
(i as u32).into(),
99+
JitValue::from_type_and_value(ty.clone(), val),
100+
)
98101
.unwrap();
99102
}
100103
compiler
@@ -105,14 +108,10 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
105108
self.stack.drain(stack_len - count..).collect()
106109
}
107110

108-
fn store_variable(
109-
&mut self,
110-
idx: bytecode::NameIdx,
111-
val: JitValue,
112-
) -> Result<(), JitCompileError> {
111+
fn store_variable(&mut self, idx: oparg::VarNum, val: JitValue) -> Result<(), JitCompileError> {
113112
let builder = &mut self.builder;
114113
let ty = val.to_jit_type().ok_or(JitCompileError::NotSupported)?;
115-
let local = self.variables[idx as usize].get_or_insert_with(|| {
114+
let local = self.variables[idx].get_or_insert_with(|| {
116115
let var = builder.declare_var(ty.to_cranelift());
117116
Local {
118117
var,
@@ -649,7 +648,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
649648
Ok(())
650649
}
651650
Instruction::LoadFast { var_num } | Instruction::LoadFastBorrow { var_num } => {
652-
let local = self.variables[var_num.get(arg) as usize]
651+
let local = self.variables[var_num.get(arg)]
653652
.as_ref()
654653
.ok_or(JitCompileError::BadBytecode)?;
655654
self.stack.push(JitValue::from_type_and_value(

0 commit comments

Comments
 (0)