From 252be6e5fc6a5049ac29a5b87eae1d76965e7299 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Sat, 9 Mar 2024 15:10:11 -0500 Subject: [PATCH] better interpreter --- src/interp.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/interp.rs b/src/interp.rs index b329d3b..a66ac35 100644 --- a/src/interp.rs +++ b/src/interp.rs @@ -18,6 +18,7 @@ pub struct InterpContext { pub globals: PerEntity, pub fuel: u64, pub trace_handler: Option) -> bool + Send>>, + pub import_hander: Option InterpResult>> } type MultiVal = SmallVec<[ConstVal; 2]>; @@ -86,6 +87,7 @@ impl InterpContext { globals, fuel: u64::MAX, trace_handler: None, + import_hander: None, }) } @@ -312,10 +314,10 @@ impl InterpContext { } fn call_import(&mut self, name: &str, args: &[ConstVal]) -> InterpResult { - if let Some(ret) = wasi::call_wasi(&mut self.memories[Memory::from(0)], name, args) { - return ret; - } - panic!("Unknown import: {} with args: {:?}", name, args); + let mut r = self.import_hander.take().unwrap(); + let rs = r(self,name,args); + self.import_hander = Some(r); + return rs; } }