All Projects → mathetake → Gasm

mathetake / Gasm

Licence: mit
An Experimental Wasm Virtual Machine for Gophers

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gasm

Lam
🚀 a lightweight, universal actor-model vm for writing scalable and reliable applications that run natively and on WebAssembly
Stars: ✭ 176 (-59.73%)
Mutual labels:  wasm, virtual-machine
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (+12.13%)
Mutual labels:  wasm, virtual-machine
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (-93.14%)
Mutual labels:  virtual-machine, wasm
Esta
Interpreted language and bytecode VM of my own design written in Rust [Unmaintained]
Stars: ✭ 28 (-93.59%)
Mutual labels:  wasm, virtual-machine
Wasm3
🚀 The fastest WebAssembly interpreter, and the most universal runtime
Stars: ✭ 4,375 (+901.14%)
Mutual labels:  wasm, virtual-machine
Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+816.7%)
Mutual labels:  wasm
Ink
Parity's ink! to write smart contracts
Stars: ✭ 407 (-6.86%)
Mutual labels:  wasm
Simplify
Android virtual machine and deobfuscator
Stars: ✭ 3,865 (+784.44%)
Mutual labels:  virtual-machine
Vultr
🐧 Vultr CLI and API client library
Stars: ✭ 357 (-18.31%)
Mutual labels:  virtual-machine
Edge Sql
Cloudflare Workers providing a SQL API
Stars: ✭ 429 (-1.83%)
Mutual labels:  wasm
Wasm Bindgen
Facilitating high-level interactions between Wasm modules and JavaScript
Stars: ✭ 4,695 (+974.37%)
Mutual labels:  wasm
Bootstrapblazor
A set of enterprise-class UI components based on Bootstrap and Blazor
Stars: ✭ 403 (-7.78%)
Mutual labels:  wasm
Ffmpeg.wasm
FFmpeg for browser and node, powered by WebAssembly
Stars: ✭ 6,566 (+1402.52%)
Mutual labels:  wasm
Cc Oci Runtime
OCI (Open Containers Initiative) compatible runtime for Intel® Architecture
Stars: ✭ 418 (-4.35%)
Mutual labels:  virtual-machine
Lys
⚜︎ A language that compiles to WebAssembly
Stars: ✭ 375 (-14.19%)
Mutual labels:  wasm
Jwebassembly
Java bytecode to WebAssembly compiler
Stars: ✭ 426 (-2.52%)
Mutual labels:  wasm
Wac
WebAssembly interpreter in C
Stars: ✭ 372 (-14.87%)
Mutual labels:  wasm
Rustynes
👾 An NES emulator by Rust and WebAssembly
Stars: ✭ 399 (-8.7%)
Mutual labels:  wasm
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (-3.43%)
Mutual labels:  virtual-machine
Wee alloc
The Wasm-Enabled, Elfin Allocator
Stars: ✭ 399 (-8.7%)
Mutual labels:  wasm

gasm

CircleCI MIT License

A minimal implementation of v1 WASM spec compatible virtual machine purely written in go. The vm can be embedded in your go program without any dependency like cgo, and enables Gophers to write wasm host environments easily.

The vm should be used only for providing sandbox environments embedded in your Go program since we have not implemented validation of wasm binary.

The implementation is quite straightforward and I hope this code would be a good starting point for novices to learn WASM spec.

examples

Full examples can be found at: https://github.com/mathetake/gasm/tree/master/examples

call exported function from host

func Test_fibonacci(t *testing.T) {
	buf, _ := ioutil.ReadFile("wasm/fibonacci.wasm")
	mod, _ := wasm.DecodeModule(bytes.NewBuffer(buf))
	vm, _ := wasm.NewVM(mod, wasi.Modules)

	for _, c := range []struct {
		in, exp int32
	}{
		{in: 20, exp: 6765},
		{in: 10, exp: 55},
		{in: 5, exp: 5},
	} {
		ret, _, _ := vm.ExecExportedFunction("fib", uint64(c.in))
		require.Equal(t, c.exp, int32(ret[0]))
	}
}

call host function from WASM module


func Test_hostFunc(t *testing.T) {
	buf, _ := ioutil.ReadFile("wasm/host_func.wasm")
	mod, _ := wasm.DecodeModule(bytes.NewBuffer(buf))

	var cnt uint64  // to be incremented as hostFunc is called

	// host functions must be defined in the form of `Virtual Machine closure` generators
	// in order to access the VM state to get things done
	hostFunc := func(*wasm.VirtualMachine) reflect.Value {
		return reflect.ValueOf(func() {
			cnt++
		})
	}

	builder := hostfunc.NewModuleBuilderWith(wasi.Modules)
	builder.MustSetFunction("env", "host_func", hostFunc)
	vm, _ := wasm.NewVM(mod, builder.Done())

	for _, exp := range []uint64{5, 10, 15} {
		vm.ExecExportedFunction("call_host_func", exp)
		require.Equal(t, exp, cnt)
		cnt = 0
	}
}

🚧 WASI support 🚧

WebAssembly System Interface(WASI) will partly be supported in wasi package. Currently only fd_write is implemented and you can see it works in examples/panic example where the WASM module causes panic and the host prints the message through fd_write ABI.

references

https://webassembly.github.io/spec/core/index.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].