Update examples

extensions
Volodymyr Shymanskyy 3 years ago
parent 76cec3cb4a
commit 8d71546dd0

@ -15,15 +15,12 @@ pip3 install dist/pywasm3-*.tar.gz
## Usage example
```py
import wasm3
import wasm3, base64
# WebAssembly binary
WASM = bytes.fromhex("""
00 61 73 6d 01 00 00 00 01 06 01 60 01 7e 01 7e
03 02 01 00 07 07 01 03 66 69 62 00 00 0a 1f 01
1d 00 20 00 42 02 54 04 40 20 00 0f 0b 20 00 42
02 7d 10 00 20 00 42 01 7d 10 00 7c 0f 0b
""")
WASM = base64.b64decode("AGFzbQEAAAABBgFgAX4"
"BfgMCAQAHBwEDZmliAAAKHwEdACAAQgJUBEAgAA"
"8LIABCAn0QACAAQgF9EAB8Dws=")
env = wasm3.Environment()
rt = env.new_runtime(1024)

@ -3,6 +3,31 @@
import wasm3
import base64, time, timeit
"""
Input module:
(module
(type (;0;) (func (param i64) (result i64)))
(func (;0;) (type 0) (param i64) (result i64)
local.get 0
i64.const 2
i64.lt_u
if ;; label = @1
local.get 0
return
end
local.get 0
i64.const 2
i64.sub
call 0
local.get 0
i64.const 1
i64.sub
call 0
i64.add
return)
(export "fib" (func 0)))
"""
# WebAssembly binary
WASM = base64.b64decode("""
AGFzbQEAAAABBgFgAX4BfgMCAQAHBwEDZmliAAAKHwEdACAAQgJUBEAgAA8LIABCAn0QACAAQgF9

@ -19,9 +19,6 @@ with open(wasm_fn, "rb") as f:
rt.load(mod)
mod.link_function("env", "clock_ms", "i()", clock_ms)
# Gas metering will only apply to metered (pre-instrumented) modules
mod.gasLimit = 200_000_000
wasm_run = rt.find_function("run")
print("Running CoreMark 1.0...")
@ -32,6 +29,3 @@ if res > 1:
else:
print("Error")
if mod.gasUsed:
print(f"Gas used: {mod.gasUsed}")

@ -0,0 +1,38 @@
#!/usr/bin/env python3
import wasm3
import os, time
scriptpath = os.path.dirname(os.path.realpath(__file__))
wasm_fn = os.path.join(scriptpath, "./wasm/coremark-metered.wasm")
print("Initializing Wasm3 engine...")
def clock_ms():
return int(round(time.time() * 1000))
env = wasm3.Environment()
rt = env.new_runtime(4096)
with open(wasm_fn, "rb") as f:
mod = env.parse_module(f.read())
rt.load(mod)
mod.link_function("env", "clock_ms", "i()", clock_ms)
# Gas metering will only apply to metered (pre-instrumented) modules
mod.gasLimit = 200_000_000
wasm_run = rt.find_function("run")
print("Running CoreMark 1.0...")
try:
res = wasm_run()
if res > 1:
print(f"Result: {res:.3f}")
else:
print("Error")
finally:
if mod.gasUsed:
print(f"Gas used: {mod.gasUsed}")

@ -3,9 +3,10 @@
# Author: Volodymyr Shymanskyy
# Usage:
# ./run-spec-test.py
# ./run-spec-test.py ./core/i32.json
# ./run-spec-test.py ./core/float_exprs.json --line 2070
# ./run-spec-test.py ./proposals/tail-call/*.json
# ./run-spec-test.py --spec=opam-1.1.1
# ./run-spec-test.py .spec-v1.1/core/i32.json
# ./run-spec-test.py .spec-v1.1/core/float_exprs.json --line 2070
# ./run-spec-test.py .spec-v1.1/proposals/tail-call/*.json
# ./run-spec-test.py --exec "../build-custom/wasm3 --repl"
#
# Running WASI version with different engines:

Loading…
Cancel
Save