Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b2bd6c

Browse files
Merge pull request #1 from explodingcamera/imports
feat: host functions, rewrite linker
2 parents 7b456a5 + c0dd4bc commit 0b2bd6c

File tree

15 files changed

+431
-476
lines changed

15 files changed

+431
-476
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tinywasm/src/export.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
use alloc::boxed::Box;
2-
use tinywasm_types::{Export, ExternalKind};
31

4-
#[derive(Debug)]
5-
/// Exports of a module instance
6-
// TODO: Maybe use a BTreeMap instead?
7-
pub struct ExportInstance(pub(crate) Box<[Export]>);
8-
9-
impl ExportInstance {
10-
/// Get an export by name
11-
pub fn get(&self, name: &str, ty: ExternalKind) -> Option<&Export> {
12-
self.0.iter().find(|e| e.name == name.into() && e.kind == ty)
13-
}
14-
15-
pub(crate) fn get_untyped(&self, name: &str) -> Option<&Export> {
16-
self.0.iter().find(|e| e.name == name.into())
17-
}
18-
}

crates/tinywasm/src/func.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ impl FuncHandle {
5252
}
5353
}
5454

55-
let wasm_func = &func_inst.assert_wasm()?;
55+
let wasm_func = match &func_inst.func {
56+
crate::Function::Host(h) => {
57+
let func = h.func.clone();
58+
return (func)(store, params);
59+
}
60+
crate::Function::Wasm(ref f) => f,
61+
};
5662

5763
// 6. Let f be the dummy frame
5864
debug!("locals: {:?}", wasm_func.locals);
@@ -76,11 +82,7 @@ impl FuncHandle {
7682
let res = stack.values.last_n(result_m)?;
7783

7884
// The values are returned as the results of the invocation.
79-
Ok(res
80-
.iter()
81-
.zip(func_ty.results.iter())
82-
.map(|(v, ty)| v.attach_type(*ty))
83-
.collect())
85+
Ok(res.iter().zip(func_ty.results.iter()).map(|(v, ty)| v.attach_type(*ty)).collect())
8486
}
8587
}
8688

@@ -184,11 +186,8 @@ macro_rules! impl_from_wasm_value_tuple_single {
184186
fn from_wasm_value_tuple(values: Vec<WasmValue>) -> Result<Self> {
185187
#[allow(unused_variables, unused_mut)]
186188
let mut iter = values.into_iter();
187-
Ok($T::try_from(
188-
iter.next()
189-
.ok_or(Error::Other("Not enough values in WasmValue vector".to_string()))?,
190-
)
191-
.map_err(|_| Error::Other("Could not convert WasmValue to expected type".to_string()))?)
189+
$T::try_from(iter.next().ok_or(Error::Other("Not enough values in WasmValue vector".to_string()))?)
190+
.map_err(|_| Error::Other("Could not convert WasmValue to expected type".to_string()))
192191
}
193192
}
194193
};

0 commit comments

Comments
 (0)