Skip to content

Commit 090720a

Browse files
committed
Fix jit
1 parent 1be79c9 commit 090720a

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

jit/src/instructions.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
5454
let params = compiler.builder.func.dfg.block_params(entry_block).to_vec();
5555
for (i, (ty, val)) in arg_types.iter().zip(params).enumerate() {
5656
compiler
57-
.store_variable(i, JitValue::new(val, ty.clone()))
57+
.store_variable(i as u32, JitValue::new(val, ty.clone()))
5858
.unwrap();
5959
}
6060
compiler
@@ -66,8 +66,8 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
6666
val: JitValue,
6767
) -> Result<(), JitCompileError> {
6868
let builder = &mut self.builder;
69-
let local = self.variables[idx].get_or_insert_with(|| {
70-
let var = Variable::new(idx);
69+
let local = self.variables[idx as usize].get_or_insert_with(|| {
70+
let var = Variable::new(idx as usize);
7171
let local = Local {
7272
var,
7373
ty: val.ty.clone(),
@@ -119,7 +119,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
119119
let label_targets = bytecode.label_targets();
120120

121121
for (offset, instruction) in bytecode.instructions.iter().enumerate() {
122-
let label = Label(offset);
122+
let label = Label(offset as u32);
123123
if label_targets.contains(&label) {
124124
let block = self.get_or_create_block(label);
125125

@@ -219,7 +219,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
219219
Ok(())
220220
}
221221
Instruction::LoadFast(idx) => {
222-
let local = self.variables[*idx]
222+
let local = self.variables[*idx as usize]
223223
.as_ref()
224224
.ok_or(JitCompileError::BadBytecode)?;
225225
self.stack.push(JitValue {
@@ -232,7 +232,9 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
232232
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
233233
self.store_variable(*idx, val)
234234
}
235-
Instruction::LoadConst { idx } => self.load_const(constants[*idx].borrow_constant()),
235+
Instruction::LoadConst { idx } => {
236+
self.load_const(constants[*idx as usize].borrow_constant())
237+
}
236238
Instruction::ReturnValue => {
237239
let val = self.stack.pop().ok_or(JitCompileError::BadBytecode)?;
238240
if let Some(ref ty) = self.sig.ret {

jit/tests/common.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ impl StackMachine {
7878
names: &[String],
7979
) -> bool {
8080
match instruction {
81-
Instruction::LoadConst { idx } => self.stack.push(constants[idx].clone().into()),
82-
Instruction::LoadNameAny(idx) => {
83-
self.stack.push(StackValue::String(names[idx].clone()))
81+
Instruction::LoadConst { idx } => {
82+
self.stack.push(constants[idx as usize].clone().into())
8483
}
84+
Instruction::LoadNameAny(idx) => self
85+
.stack
86+
.push(StackValue::String(names[idx as usize].clone())),
8587
Instruction::StoreLocal(idx) => {
8688
self.locals
87-
.insert(names[idx].clone(), self.stack.pop().unwrap());
89+
.insert(names[idx as usize].clone(), self.stack.pop().unwrap());
8890
}
8991
Instruction::StoreAttr { .. } => {
9092
// Do nothing except throw away the stack values
@@ -104,7 +106,7 @@ impl StackMachine {
104106
}
105107
self.stack.push(StackValue::Map(map));
106108
}
107-
Instruction::MakeFunction => {
109+
Instruction::MakeFunction(_flags) => {
108110
let name = if let Some(StackValue::String(name)) = self.stack.pop() {
109111
name
110112
} else {
@@ -134,7 +136,7 @@ impl StackMachine {
134136
let mut values = Vec::new();
135137

136138
// Pop all values from stack:
137-
values.extend(self.stack.drain(self.stack.len() - amount..));
139+
values.extend(self.stack.drain(self.stack.len() - amount as usize..));
138140

139141
// Push top of stack back first:
140142
self.stack.push(values.pop().unwrap());

0 commit comments

Comments
 (0)