wasm_interp: implement local.get, local.set, and local.tee

This commit is contained in:
Brian Carroll 2022-11-21 23:29:08 +00:00
parent 987fcf616e
commit ff63831fd1
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
3 changed files with 83 additions and 11 deletions

View file

@ -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);