mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
wasm_interp: create a block for each function and get tests working again
This commit is contained in:
parent
caedb9060b
commit
d51beb073f
6 changed files with 390 additions and 376 deletions
|
@ -9,7 +9,7 @@ pub use instance::Instance;
|
|||
pub use wasi::{WasiDispatcher, WasiFile};
|
||||
|
||||
pub use roc_wasm_module::Value;
|
||||
use roc_wasm_module::{ValueType, WasmModule};
|
||||
use roc_wasm_module::ValueType;
|
||||
|
||||
pub trait ImportDispatcher {
|
||||
/// Dispatch a call from WebAssembly to your own code, based on module and function name.
|
||||
|
@ -100,22 +100,3 @@ impl From<(ValueType, ValueType)> for Error {
|
|||
Error::ValueStackType(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which function the program counter is in
|
||||
pub(crate) fn pc_to_fn_index(program_counter: usize, module: &WasmModule<'_>) -> usize {
|
||||
if module.code.function_offsets.is_empty() {
|
||||
0
|
||||
} else {
|
||||
// Find the first function that starts *after* the given program counter
|
||||
let next_internal_fn_index = module
|
||||
.code
|
||||
.function_offsets
|
||||
.iter()
|
||||
.position(|o| *o as usize > program_counter)
|
||||
.unwrap_or(module.code.function_offsets.len());
|
||||
// Go back 1
|
||||
let internal_fn_index = next_internal_fn_index - 1;
|
||||
// Adjust for imports, whose indices come before the code section
|
||||
module.import.imports.len() + internal_fn_index
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue