Skip to content

Commit 5cb04fd

Browse files
committed
f
1 parent 80bcbb8 commit 5cb04fd

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

bindings/rust/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Drop for Instance {
4444
}
4545

4646
impl Module {
47-
fn instantiate(mut self) -> Option<Instance> {
47+
fn instantiate(self) -> Option<Instance> {
4848
// An instance was already created.
4949
if self.ptr.is_null() {
5050
return None;
@@ -61,6 +61,8 @@ impl Module {
6161
}
6262
}
6363

64+
/*
65+
Introduce nicer abstractions.
6466
enum Value {
6567
U32(u32),
6668
U64(u64),
@@ -73,10 +75,16 @@ enum Result {
7375
NoValue,
7476
Value(Value),
7577
}
78+
*/
79+
80+
pub type Value = sys::FizzyValue;
81+
82+
pub type ExecutionResult = sys::FizzyExecutionResult;
7683

7784
impl Instance {
78-
fn execute(&mut self, func_idx: u32, args: &[Value]) -> Result {
79-
Result::Trapped
85+
fn execute(&mut self, func_idx: u32, args: &[Value]) -> ExecutionResult {
86+
// FIXME: pass args
87+
unsafe { sys::fizzy_execute(self.ptr.as_ptr(), func_idx, std::ptr::null(), 0, 0) }
8088
}
8189
}
8290

@@ -115,4 +123,15 @@ mod tests {
115123
let instance = module.unwrap().instantiate();
116124
assert!(instance.is_some());
117125
}
126+
127+
#[test]
128+
fn execute_wasm() {
129+
let module = parse(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
130+
assert!(module.is_some());
131+
let instance = module.unwrap().instantiate();
132+
assert!(instance.is_some());
133+
let result = instance.unwrap().execute(0, &[]);
134+
assert!(result.trapped);
135+
assert!(!result.has_value);
136+
}
118137
}

0 commit comments

Comments
 (0)