aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFederico G. Schwindt <[email protected]>2021-03-15 11:41:37 +0000
committerGitHub <[email protected]>2021-03-15 12:41:37 +0100
commit303acf5ed6dd77eacd401795c4a9167d31a18172 (patch)
tree0340daf69ee75668e05a1634e8b030cb3b20e24f
parent7d1ce24be5c60525e14b25a29bc0833b454ab7d4 (diff)
downloadtinygo-303acf5ed6dd77eacd401795c4a9167d31a18172.tar.gz
tinygo-303acf5ed6dd77eacd401795c4a9167d31a18172.zip
Upgrade WASI version to wasi_snapshot_preview1 (#1691)
wasm: Upgrade WASI version to wasi_snapshot_preview1 Addresses #1647.
-rw-r--r--src/runtime/runtime_wasm.go2
-rw-r--r--src/runtime/runtime_wasm_wasi.go22
-rw-r--r--targets/wasm_exec.js4
3 files changed, 13 insertions, 15 deletions
diff --git a/src/runtime/runtime_wasm.go b/src/runtime/runtime_wasm.go
index fdea09505..f2acf9768 100644
--- a/src/runtime/runtime_wasm.go
+++ b/src/runtime/runtime_wasm.go
@@ -12,7 +12,7 @@ type __wasi_iovec_t struct {
bufLen uint
}
-//go:wasm-module wasi_unstable
+//go:wasm-module wasi_snapshot_preview1
//export fd_write
func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (errno uint)
diff --git a/src/runtime/runtime_wasm_wasi.go b/src/runtime/runtime_wasm_wasi.go
index 99a34ebb4..51cb75cff 100644
--- a/src/runtime/runtime_wasm_wasi.go
+++ b/src/runtime/runtime_wasm_wasi.go
@@ -35,7 +35,6 @@ var (
u: __wasi_subscription_u_t{
tag: __wasi_eventtype_t_clock,
u: __wasi_subscription_clock_t{
- userData: 0,
id: 0,
timeout: 0,
precision: timePrecisionNanoseconds,
@@ -48,23 +47,23 @@ var (
)
func sleepTicks(d timeUnit) {
- sleepTicksSubscription.u.u.timeout = int64(d)
+ sleepTicksSubscription.u.u.timeout = uint64(d)
poll_oneoff(&sleepTicksSubscription, &sleepTicksResult, 1, &sleepTicksNEvents)
}
func ticks() timeUnit {
- var nano int64
+ var nano uint64
clock_time_get(0, timePrecisionNanoseconds, &nano)
return timeUnit(nano)
}
// Implementations of wasi_unstable APIs
-//go:wasm-module wasi_unstable
+//go:wasm-module wasi_snapshot_preview1
//export clock_time_get
-func clock_time_get(clockid uint32, precision uint64, time *int64) (errno uint16)
+func clock_time_get(clockid uint32, precision uint64, time *uint64) (errno uint16)
-//go:wasm-module wasi_unstable
+//go:wasm-module wasi_snapshot_preview1
//export poll_oneoff
func poll_oneoff(in *__wasi_subscription_t, out *__wasi_event_t, nsubscriptions uint32, nevents *uint32) (errno uint16)
@@ -77,7 +76,7 @@ const (
)
type (
- // https://github.com/wasmerio/wasmer/blob/1.0.0-alpha3/lib/wasi/src/syscalls/types.rs#L584-L588
+ // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-subscription-record
__wasi_subscription_t struct {
userData uint64
u __wasi_subscription_u_t
@@ -90,18 +89,17 @@ type (
u __wasi_subscription_clock_t
}
- // https://github.com/wasmerio/wasmer/blob/1.0.0-alpha3/lib/wasi/src/syscalls/types.rs#L711-L718
+ // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-subscription_clock-record
__wasi_subscription_clock_t struct {
- userData uint64
id uint32
- timeout int64
- precision int64
+ timeout uint64
+ precision uint64
flags uint16
}
)
type (
- // https://github.com/wasmerio/wasmer/blob/1.0.0-alpha3/lib/wasi/src/syscalls/types.rs#L191-L198
+ // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-event-record
__wasi_event_t struct {
userData uint64
errno uint16
diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js
index eb153ed04..96ff7cfce 100644
--- a/targets/wasm_exec.js
+++ b/targets/wasm_exec.js
@@ -247,8 +247,8 @@
const timeOrigin = Date.now() - performance.now();
this.importObject = {
- wasi_unstable: {
- // https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-api.md#__wasi_fd_write
+ wasi_snapshot_preview1: {
+ // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_write
fd_write: function(fd, iovs_ptr, iovs_len, nwritten_ptr) {
let nwritten = 0;
if (fd == 1) {