mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
wasm_interp: implement indirect_call
This commit is contained in:
parent
468be47da2
commit
c2fb626c17
3 changed files with 165 additions and 31 deletions
|
@ -194,7 +194,7 @@ pub fn update_section_size<T: SerialBuffer>(buffer: &mut T, header_indices: Sect
|
|||
*
|
||||
*******************************************************************/
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct Signature<'a> {
|
||||
pub param_types: Vec<'a, ValueType>,
|
||||
pub ret_type: Option<ValueType>,
|
||||
|
@ -1165,6 +1165,13 @@ pub struct ElementSegment<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ElementSegment<'a> {
|
||||
pub fn new(arena: &'a Bump) -> Self {
|
||||
ElementSegment {
|
||||
offset: ConstExpr::I32(0),
|
||||
fn_indices: Vec::new_in(arena),
|
||||
}
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
let variant_id = 1;
|
||||
let constexpr_opcode = 1;
|
||||
|
@ -1267,6 +1274,14 @@ impl<'a> ElementSection<'a> {
|
|||
pub fn is_empty(&self) -> bool {
|
||||
self.segments.iter().all(|seg| seg.fn_indices.is_empty())
|
||||
}
|
||||
|
||||
/// Look up a "function pointer" (element index) and return the function index.
|
||||
pub fn lookup(&self, element_index: u32) -> Option<u32> {
|
||||
self.segments.iter().find_map(|seg| {
|
||||
let adjusted_index = element_index as usize - seg.offset.unwrap_i32() as usize;
|
||||
seg.fn_indices.get(adjusted_index).copied()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parse<&'a Bump> for ElementSection<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue