Bogdanp / racket-wasm

Wasm tooling in Racket.
BSD 3-Clause "New" or "Revised" License
40 stars 2 forks source link

Where do I get started? #1

Open cwebber opened 3 years ago

cwebber commented 3 years ago

I'd like to give this project a try but I don't quite know how to try anything yet... even a braindump might be nice :)

Bogdanp commented 3 years ago

This post shows how you can run a wasm-compiled Go program, but the gist of it is if you have a file called fib.wasm that exports a function of one argument called fib, you can run it with:

#lang racket

(require wasm/private/binary 
         wasm/private/vm)

(define m (call-with-input-file "fib.wasm" read-wasm))
(define v (make-vm m (hash)))
(define fib (vm-ref v "fib"))
(fib 8)

You can also take the WASM module and compile it into Racket code:


(require wasm/private/compiler)

(define-values (ns sexp init!)
 (compile-mod m (hash)))

(parameterize ([current-namespace ns])
  (eval (compile sexp))
  (init!)
  (namespace-require ''wasm)
  ((namespace-variable-value 'fib) 8))
nano-o commented 1 year ago

Could you please share the "go-runtime.rkt" file that you use in the blog post?

Bogdanp commented 1 year ago

Could you please share the "go-runtime.rkt" file that you use in the blog post?

It's easy to miss, but the blog post does link to go-runtime.rkt. Note that if you try to use it with a recent version of Go, you might have to make some changes. I believe I was using Go 1.15 or 1.16 when I wrote that.

nano-o commented 1 year ago

Okay, thanks! Sorry I missed it.

nano-o commented 1 year ago

@Bogdanp the repository seems to only contain tests for the validation code. Have you tested the interpreter in some way? Have you ever tried to validate it against the official WASM tests? I'm thinking of this: https://github.com/WebAssembly/spec/tree/w3c-1.0/test/core