mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
wasm_interp: implement local.get, local.set, and local.tee
This commit is contained in:
parent
987fcf616e
commit
ff63831fd1
3 changed files with 83 additions and 11 deletions
|
@ -14,7 +14,7 @@ pub struct ExecutionState<'a> {
|
|||
memory: Vec<'a, u8>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
call_stack: CallStack<'a>,
|
||||
pub call_stack: CallStack<'a>,
|
||||
|
||||
pub value_stack: ValueStack<'a>,
|
||||
program_counter: usize,
|
||||
|
@ -31,6 +31,10 @@ impl<'a> ExecutionState<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch_immediate_u32(&mut self, module: &WasmModule<'a>) -> u32 {
|
||||
u32::parse((), &module.code.bytes, &mut self.program_counter).unwrap()
|
||||
}
|
||||
|
||||
pub fn execute_next_instruction(&mut self, module: &WasmModule<'a>) {
|
||||
use OpCode::*;
|
||||
|
||||
|
@ -82,13 +86,19 @@ impl<'a> ExecutionState<'a> {
|
|||
todo!("{:?}", op_code);
|
||||
}
|
||||
GETLOCAL => {
|
||||
todo!("{:?}", op_code);
|
||||
let index = self.fetch_immediate_u32(module);
|
||||
let value = self.call_stack.get_local(index);
|
||||
self.value_stack.push(value);
|
||||
}
|
||||
SETLOCAL => {
|
||||
todo!("{:?}", op_code);
|
||||
let index = self.fetch_immediate_u32(module);
|
||||
let value = self.value_stack.pop();
|
||||
self.call_stack.set_local(index, value);
|
||||
}
|
||||
TEELOCAL => {
|
||||
todo!("{:?}", op_code);
|
||||
let index = self.fetch_immediate_u32(module);
|
||||
let value = self.value_stack.peek();
|
||||
self.call_stack.set_local(index, value);
|
||||
}
|
||||
GETGLOBAL => {
|
||||
todo!("{:?}", op_code);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue