Skip to content

Commit 72b1dc7

Browse files
committed
Use usize for CALL_INTRINSIC, since it takes a pointer as argument.
1 parent 6595598 commit 72b1dc7

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/interpreter/builtins/vm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,18 @@ pub fn inline_fn_push_with_u8(opcode: OpCode, arg: u8) -> InlineFunction {
163163
}})
164164
}
165165

166-
pub fn inline_fn_push_with_u64(opcode: OpCode, arg: u64) -> InlineFunction {
166+
pub fn inline_fn_push_with_usize(opcode: OpCode, arg: usize) -> InlineFunction {
167167
Rc::new(move |compiler, expression| {{
168168
let arguments = &compiler.implementation.expression_tree.children[expression];
169169
for arg in arguments { compiler.compile_expression(arg)? }
170170

171-
compiler.chunk.push_with_u64(opcode, arg);
171+
compiler.chunk.push_with_usize(opcode, arg);
172172
Ok(())
173173
}})
174174
}
175175

176176
pub fn inline_fn_push_intrinsic_call(arg: IntrinsicFunction) -> InlineFunction {
177-
inline_fn_push_with_u64(OpCode::CALL_INTRINSIC, unsafe { transmute(arg) })
177+
inline_fn_push_with_usize(OpCode::CALL_INTRINSIC, unsafe { transmute(arg) })
178178
}
179179

180180
pub unsafe fn to_str_ptr<A: ToString>(a: A) -> *mut () {

src/interpreter/chunks.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ impl Chunk {
5656
}
5757
}
5858

59+
pub fn push_with_usize(&mut self, code: OpCode, arg: usize) {
60+
// TODO Should be constexpr
61+
if size_of::<usize>() == size_of::<u64>() {
62+
self.push_with_u64(code, arg as u64);
63+
}
64+
else if size_of::<usize>() == size_of::<u32>() {
65+
self.push_with_u64(code, arg as u64);
66+
}
67+
else {
68+
panic!()
69+
}
70+
}
71+
5972
pub fn push_with_u128(&mut self, code: OpCode, arg: u128) {
6073
let len = self.code.len();
6174

src/interpreter/disassembler.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ pub fn disassemble_one(ip: *const u8) -> usize {
4040
print!("\t{:?}", *(ip.add(1) as *mut u32));
4141
return 1 + 4;
4242
}
43-
OpCode::LOAD64 | OpCode::CALL_INTRINSIC => {
43+
OpCode::LOAD64 => {
4444
print!("\t{:?}", *(ip.add(1) as *mut u64));
4545
return 1 + 8;
4646
}
47+
OpCode::CALL_INTRINSIC => {
48+
print!("\t{:?}", *(ip.add(1) as *mut usize));
49+
return 1 + size_of::<usize>();
50+
}
4751
OpCode::JUMP | OpCode::JUMP_IF_FALSE | OpCode::LOAD_LOCAL_32 | OpCode::STORE_LOCAL_32 => {
4852
print!("\t{:?}", *(ip.add(1) as *mut i32));
4953
return 1 + 4;

src/interpreter/vm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ impl VM {
9696
current_chunk = chunk;
9797
}
9898
OpCode::CALL_INTRINSIC => {
99-
// TODO Should be platform dependent int (32bit / 64bit)
100-
let fun_ptr_int = pop_ip!(u64);
101-
let fun: IntrinsicFunction = transmute(fun_ptr_int);
99+
let fun = pop_ip!(IntrinsicFunction);
102100
fun(self, &mut sp)?;
103101
}
104102
OpCode::LOAD0 => {

0 commit comments

Comments
 (0)