prep / wasmexec Goto Github PK
View Code? Open in Web Editor NEWImplementation of wasm_exec.js for Go Wasm runtimes
License: MIT License
Implementation of wasm_exec.js for Go Wasm runtimes
License: MIT License
Users can define their own "go" module function imports by defining a func
without a body in their source and a%_wasm.s
or %_js.s
file that uses the
CallImport
instruction.
The compiler chooses a naming prefix of "main.$funcName", if defined in the
main
package, or a fully-qualified based on the module, if elsewhere.
For example, given func logString(msg string)
and the below assembly:
#include "textflag.h"
TEXT ·logString(SB), NOSPLIT, $0
CallImport
RET
If the package was main
, the WebAssembly function name would be
"main.logString". If it was util
and your go.mod
module was
"github.com/user/me", the WebAssembly function name would be
"github.com/prep/user/me/util.logString"
You may want to add an example of this, so that you can see the impact
to the various runtimes. It is the same as the other "go".
Note that you will need to put this in a separate directory so you can
compile . or ./... and get the .s file. Also, the func
has to be called, or
the compiler will skip writing it!
Here's an example which would work the same way in user-code as go's
source tree
https://github.com/golang/go/blob/master/src/syscall/js/js.go#L569
https://github.com/golang/go/blob/master/src/syscall/js/js_js.s#L63-L65
I'm interested in implementing an external FS:
All the lines which are defined with errorCallback(ENOSYS)
would instead call into a FS interface (or if the interface is nil, return ENosys)
There are some confusing code in the source wasm_exec.js which is about forcing unsigned numbers. The memory offset and stack pointer should both be uint32 not int32 where possible.
This is the correct way to force unsigned in go. The javascript does it via sp >>>= 0;
which can be wholesale removed here as it has no effect, regardless of if the variable types are changed.
No matter if the flag
package is a direct dependency or transitive dependency, it will panic.
Minimum steps to reproduce it:
main.go
in https://github.com/prep/wasmexec/blob/main/examples/hello/main.go to:package main
import (
"os"
_ "flag"
)
func main() {
_, _ = os.Stdout.Write([]byte("Hello from Go!\n"))
}
GOOS=js GOARCH=wasm go build -o hello.wasm ./main.go
$ cd wasmtimexec/example
$ go build -o wasmtimeexec ./main.go
hello.wasm
:./wasmtimeexec ../../examples/hello/hello.wasm
It will produce the following error:
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
flag.init()
/usr/local/go/src/flag/flag.go:1047 +0x2f
It seems the problem is that: flag
pacakge try to run var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
and os.Args
is expected to hold the command-line arguments, starting with the program name.
It seems os.Args
is not correctly populated somehow.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.