Comments (6)
That is very good idea actually!
Why?
Because result of invoking of a function might yield only two outcomes:
- return a result
- trap
However, the docs at the invoke_export
actually give a glimpse of a problem:
Returns `Err` if:
- there are no export with a given name or this export is not a function,
- given arguments doesn't match to function signature,
- trap occured at the execution time,
So in other words, today, we have invoke_index
that returns an wasmi::Error
which includes various variants that just can't happen in result of invoking a function.
from wasmi.
First step to implement this is in #29
from wasmi.
How does this look for a start?
instance
.export_by_name(func_name)?
.as_func()?
.with_externals(&mut NopExternals)
.with_args(&args)?
.invoke()
.ok()?;
export_by_name() -> Option<ExternVal>
and as_func() -> Option<&FuncRef>
already exist.
The rest could be implemented by adding the following to func.rs
:
impl FuncRef {
pub fn with_externals<'a, E: Externals>(
&'a self,
externals: &'a mut E,
) -> BoundExternalsFunc<'a, E> {
BoundExternalsFunc {
func_instance: self,
externals,
}
}
}
/// First step in chained function calling pattern.
pub struct BoundExternalsFunc<'a, E: Externals + 'a> {
func_instance: &'a FuncRef,
externals: &'a mut E,
}
impl<'a, E: Externals> BoundExternalsFunc<'a, E> {
pub fn with_args(self, args: &'a [RuntimeValue]) -> Option<BoundFunc<'a, E>> {
BoundFunc::new(self.func_instance, self.externals, args)
}
}
/// FuncRef with verified arguments.
pub struct BoundFunc<'a, E: Externals + 'a> {
func_instance: &'a FuncRef,
externals: &'a mut E,
args: &'a [RuntimeValue],
}
impl<'a, E: Externals> BoundFunc<'a, E> {
fn new(
func_instance: &'a FuncRef,
externals: &'a mut E,
args: &'a [RuntimeValue],
) -> Option<BoundFunc<'a, E>> {
check_function_args(func_instance.signature(), &args).ok()?;
Some(BoundFunc {
func_instance,
externals,
args,
})
}
pub fn invoke(&mut self) -> Result<Option<RuntimeValue>, Trap> {
FuncInstance::invoke(&self.func_instance, self.args, self.externals)
}
}
from wasmi.
I can submit a pr, just checking first to see if this is approach it useful.
from wasmi.
Hello, @bddap ! I'm very sorry for the delay and for that I missed your comment.
Yeah, it is a good start. But we can go beyond that. For example, there is a related problem with limits (#51). And we might want to add other configuration options.
Can you see an approach that can incorporate such changes?
from wasmi.
This issue is no longer relevant due to the fact that the current wasmi
version is using Wasmtime based API which mostly is pretty well designed already.
from wasmi.
Related Issues (20)
- Big performance regression between 0.31 and 0.32 HOT 7
- Optimization: Special handling for common shadow stack instruction sequences HOT 1
- Create C bindings for Wasmi
- Simplification: Rewrite `iNN.sub` with immediate to new `iNN.add` variant
- Restore CI benchmarks HOT 1
- Wasmi versions `0.32.0-beta.6` cannot run `ffmpeg.wasm` correctly HOT 20
- Update `wasmi_wasi` WASI implementing dependencies HOT 1
- Optimization: Fuse transitive copies HOT 1
- Add `--verbose` mode to Wasmi CLI HOT 2
- Add support for fully hibernate-able Wasm instances HOT 7
- Handle host function calls the same as other instructions in the Wasmi executor HOT 1
- Make it possible to debug and pretty print Wasmi bytecode
- Add Wasmi execution profiling HOT 1
- The URL in the project description is 404 HOT 1
- Optimize `Linker` setup
- Add customizable `wasmi::Engine` limits
- Reconsider proper fuel charging for lazily compiled functions
- Reduce `wasmi::Engine` memory consumption for storing function artifacts HOT 3
- Try to put the Wasmi engine internals into its own crate
- Wasmi v0.32 stable release preparations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmi.