forked from wa-lang/wa
升级 wazero-1.0.1, 感谢 @codefromthecrypt 的补丁
https://github.com/wa-lang/wa/pull/44#issuecomment-1491343042
This commit is contained in:
parent
0b8bf8c6fe
commit
fa5f7bb98f
2
go.mod
2
go.mod
|
|
@ -5,6 +5,6 @@ module wa-lang.org/wa
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/tetratelabs/wazero v1.0.0-pre.4
|
||||
github.com/tetratelabs/wazero v1.0.1
|
||||
wa-lang.org/wabt-go v1.2.3
|
||||
)
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -1,4 +1,4 @@
|
|||
github.com/tetratelabs/wazero v1.0.0-pre.4 h1:RBJQT5OzmORkSp6MmZDWoFEr0zXjk4pmvMKAdeUnsaI=
|
||||
github.com/tetratelabs/wazero v1.0.0-pre.4/go.mod h1:u8wrFmpdrykiFK0DFPiFm5a4+0RzsdmXYVtijBKqUVo=
|
||||
github.com/tetratelabs/wazero v1.0.1 h1:xyWBoGyMjYekG3mEQ/W7xm9E05S89kJ/at696d/9yuc=
|
||||
github.com/tetratelabs/wazero v1.0.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
|
||||
wa-lang.org/wabt-go v1.2.3 h1:xwGW3+IrCMAPDx+ngQFx7vl0xBc1vuooRNql7i2yCiA=
|
||||
wa-lang.org/wabt-go v1.2.3/go.mod h1:v4fKY/p4oMiKwQ2S2aC/wOXvJ2bk2MgtLmwK0TKTNx0=
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ func ArduinoInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, err
|
|||
Export("getPinLED").
|
||||
NewFunctionBuilder().
|
||||
WithFunc(func(ctx context.Context, m api.Module, ptr, len uint32) {
|
||||
bytes, _ := m.Memory().Read(ctx, ptr, len)
|
||||
bytes, _ := m.Memory().Read(ptr, len)
|
||||
fmt.Printf("arduino.print(%q)\n", string(bytes))
|
||||
}).
|
||||
WithParameterNames("ptr", "len").
|
||||
Export("print").
|
||||
Instantiate(ctx, rt)
|
||||
Instantiate(ctx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ import (
|
|||
)
|
||||
|
||||
func ChromeInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error) {
|
||||
return rt.NewHostModuleBuilder(config.WaOS_chrome).Instantiate(ctx, rt)
|
||||
return rt.NewHostModuleBuilder(config.WaOS_chrome).Instantiate(ctx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func WasiInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error)
|
|||
// ----
|
||||
NewFunctionBuilder().
|
||||
WithFunc(func(ctx context.Context, m api.Module, pos, len uint32) {
|
||||
bytes, _ := m.Memory().Read(ctx, pos, len)
|
||||
bytes, _ := m.Memory().Read(pos, len)
|
||||
fmt.Print(string(bytes))
|
||||
}).
|
||||
WithParameterNames("pos", "len").
|
||||
|
|
@ -46,44 +46,58 @@ func WasiInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error)
|
|||
}).
|
||||
WithParameterNames("ch").
|
||||
Export("waPrintRune").
|
||||
Instantiate(ctx, rt)
|
||||
Instantiate(ctx)
|
||||
}
|
||||
|
||||
func wasi_fdWriteFn(ctx context.Context, mod api.Module, fd, iovs, iovsCount, resultSize uint32) wasi.Errno {
|
||||
// errno is neither uint16 nor an alias for parity with wasm.ValueType.
|
||||
type errno = uint32
|
||||
|
||||
const (
|
||||
// ErrnoSuccess No error occurred. System call completed successfully.
|
||||
errnoSuccess errno = 0
|
||||
|
||||
// errnoFault Bad address.
|
||||
errnoFault errno = 21
|
||||
|
||||
// errnoIo I/O error.
|
||||
errnoIo errno = 29
|
||||
)
|
||||
|
||||
func wasi_fdWriteFn(ctx context.Context, mod api.Module, fd, iovs, iovsCount, resultSize uint32) errno {
|
||||
var err error
|
||||
var nwritten uint32
|
||||
var writer = os.Stdout
|
||||
|
||||
for i := uint32(0); i < iovsCount; i++ {
|
||||
iov := iovs + i*8
|
||||
offset, ok := mod.Memory().ReadUint32Le(ctx, iov)
|
||||
offset, ok := mod.Memory().ReadUint32Le(iov)
|
||||
if !ok {
|
||||
return wasi.ErrnoFault
|
||||
return errnoFault
|
||||
}
|
||||
// Note: emscripten has been known to write zero length iovec. However,
|
||||
// it is not common in other compilers, so we don't optimize for it.
|
||||
l, ok := mod.Memory().ReadUint32Le(ctx, iov+4)
|
||||
l, ok := mod.Memory().ReadUint32Le(iov + 4)
|
||||
if !ok {
|
||||
return wasi.ErrnoFault
|
||||
return errnoFault
|
||||
}
|
||||
|
||||
var n int
|
||||
if writer == io.Discard { // special-case default
|
||||
n = int(l)
|
||||
} else {
|
||||
b, ok := mod.Memory().Read(ctx, offset, l)
|
||||
b, ok := mod.Memory().Read(offset, l)
|
||||
if !ok {
|
||||
return wasi.ErrnoFault
|
||||
return errnoFault
|
||||
}
|
||||
n, err = writer.Write(b)
|
||||
if err != nil {
|
||||
return wasi.ErrnoIo
|
||||
return errnoIo
|
||||
}
|
||||
}
|
||||
nwritten += uint32(n)
|
||||
}
|
||||
if !mod.Memory().WriteUint32Le(ctx, resultSize, nwritten) {
|
||||
return wasi.ErrnoFault
|
||||
if !mod.Memory().WriteUint32Le(resultSize, nwritten) {
|
||||
return errnoFault
|
||||
}
|
||||
return wasi.ErrnoSuccess
|
||||
return errnoSuccess
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue