Casts have arithmetic semantics, and under some build configurations
Rust will panic when encountering an arithmetic overflow.
Use a transmute instead since it's what we mean.
The previous code worked, but still I added a test for good measure.
* Refactor TryInto → FromRuntimeValue.
Replace `TryInto<T, E>` with `FromRuntimeValue`.
The main difference is that `FromRuntimeValue` is implemented for the concrete type of the value we create, rather than on `RuntimeValue`. This makes more sense to me and seems more clear.
The `try_into` method is now implemented on `RuntimeValue` itself.
And finally, `FromRuntimeValue` has been made public.
* Impl AsRef<[RuntimeValue]> for RuntimeArgs
This impl can be used as an escape hatch if the user wants to use the inner slice.
* Little doc fixes for RuntimeArgs.
Fixes#63
Fix is simple: all labels refered by the br_table instruction must have same value type (or NoResult in case if they don't have result). So we just take the default label and check other labels against it.
The bug was about instantiating a module with elements segment being out-of-bounds, however, it was with zero length. E.g.:
```
(module
(table 0 anyfunc)
(elem (i32.const 1))
)
```
In our impl there was no out-of-bounds, because there was no attempt to set any table entry.
This change adds early check for specifically this case.
Remove all old test fixtures that migrated in this repo from the parity-wasm.
Also, use .wast files instead of compiled .wasm. I believe this is more convenient than testing a .wasm file and having a corresponding .wast file, which might go out of sync.
These limits seems to be picked arbitrary, and I just made it arbitrary larger.
We need to reconsider these limits, ideally providing to user a way to customize the limits.
FWIW, When the last time I've tried to run gcc's torture testsuite with wasmi it also bumped into this limit.
Fixes#41.
* Initial implementation
* Not use grow as it is makes debug builds very slow
* Use Pages::BYTE_SIZE for LINEAR_MEMORY_PAGE_SIZE
* Tidy docs.
* Use memory_units from git.
* Get rid of Stack error
* Add UnexpectedSignature error and remove Value err
* Publish FuncInstance::invoke
* Rename Trap to TrapKind
* Replace Trap with struct. Enum is now TrapKind
* Fixes
* Update value.rs
* Avoid reversing parameter types iter.
* Add impl From<TrapKind> for Trap
* Remove redundant clone in prepare_function_args.
* Use .into() to convert TrapKind into Trap
* Introduce Trap struct.
* get_local can't fail.
* Add MemoryOutOfBounds trap.
* from_little_endian use slice instead of vec.
* MemoryAccessOutOfBounds for mem get and set.
* from_little_endian conversion can't fail.
* call_indirect traps.
* DivisionByZero and InvalidConversionToInt
* Use traps in value to convey an error
* select: int condition on stack top
* if: int condition on stack top
* Assert pops.
* Another protions of assert pops
* Introduce ValueStack
Also, hide FunctionContext and remove some stale code
* Traps in execution
* Make it compile.
* Check args before invoke.
* Document RuntimeArgs.
* Update host.rs
* Add rustdoc for Trap.