-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
- Loading branch information
1 parent
cff17ce
commit 67adf21
Showing
8 changed files
with
257 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,48 @@ | ||
use alloc::vec::Vec; | ||
use alloc::boxed::Box; | ||
use tinywasm_types::{ValType, WasmValue}; | ||
|
||
#[derive(Debug)] | ||
pub struct CallFrame { | ||
pub instr_ptr: usize, | ||
pub func_ptr: usize, | ||
|
||
pub local_addrs: Vec<usize>, | ||
pub locals: Box<[WasmValue]>, | ||
pub local_count: usize, | ||
} | ||
|
||
impl CallFrame { | ||
pub fn new<'a>( | ||
func_ptr: usize, | ||
params: &[WasmValue], | ||
local_types: impl Iterator<Item = &'a ValType>, | ||
) -> Self { | ||
let mut locals = params.to_vec(); | ||
locals.extend(local_types.map(|ty| WasmValue::default_for(*ty))); | ||
let locals = locals.into_boxed_slice(); | ||
|
||
Self { | ||
instr_ptr: 0, | ||
func_ptr, | ||
local_count: locals.len(), | ||
locals, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn set_local(&mut self, local_index: usize, value: WasmValue) { | ||
if local_index >= self.local_count { | ||
panic!("Invalid local index"); | ||
} | ||
|
||
self.locals[local_index] = value; | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn get_local(&self, local_index: usize) -> WasmValue { | ||
if local_index >= self.local_count { | ||
panic!("Invalid local index"); | ||
} | ||
|
||
self.locals[local_index] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.