go-interpreter / wagon

wagon, a WebAssembly-based Go interpreter, for Go.
BSD 3-Clause "New" or "Revised" License
902 stars 150 forks source link

Implement emscripten libc environment #163

Open sampaioletti opened 5 years ago

sampaioletti commented 5 years ago

Been playing with adding in some of the libc functions that compiling with emscripten requires, here is a working POC for discussion. Not pretty but I was trying to see how difficult it would be.

I have a few questions:

Not sure if i'm understanding how the init_expr should work. To get the code to work I had to modify the getGlobal case

https://github.com/sampaioletti/wagon/blob/1e71fcd3777b154c901701743ae3930e472e86fc/wasm/init_expr.go#L138

I have created a Global for __memory_base

https://github.com/sampaioletti/wagon/blob/1e71fcd3777b154c901701743ae3930e472e86fc/internal/emlibc/resolver.go#L61

and it is used from here.

https://github.com/sampaioletti/wagon/blob/1e71fcd3777b154c901701743ae3930e472e86fc/internal/emlibc/test/puts.wast#L4

without the modification the inti_expr stack is empty so it returns nil,nil which causes a panic

https://github.com/sampaioletti/wagon/blob/1e71fcd3777b154c901701743ae3930e472e86fc/wasm/init_expr.go#L157

Also a quick look at my internal/emlibc/resolver.go would be appreciated...just to see if i'm missing any important concepts..I'm relatively new to WASM so I'm having to learn as I go.

Thanks for the input.

codecov-io commented 5 years ago

Codecov Report

Merging #163 into master will decrease coverage by 0.02%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
- Coverage   69.54%   69.51%   -0.03%     
==========================================
  Files          43       43              
  Lines        5007     5009       +2     
==========================================
  Hits         3482     3482              
- Misses       1231     1233       +2     
  Partials      294      294
Impacted Files Coverage Δ
wasm/init_expr.go 35.29% <0%> (ø) :arrow_up:
cmd/wasm-run/main.go 24.24% <0%> (-0.76%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1e64ad3...1e71fcd. Read the comment docs.

sampaioletti commented 4 years ago

As i've been working through this I decided to try going a different route to learn how the emscripten internals work so I created a different project at github.com/sampaioletti/wagoja it basically uses goja to create a node like environment and ties it back to wagon so that the emscripten generated scripts will work

I was able to get it working over the weekend with a basic example. It was a nightmare (: but it is working for that limited case shown in the example folder and it definitely helped me understand what a emscripten libc implementation will need to look like.

That repo relies on another branch in my sampaioletti/wagon fork called 'wagoja' I made the changes required to make this work and started working on a few of the other things we've been discussing in there (like the module builder).

I'm going to play with wagoja (sorry i hate naming projects) and begin to start replacing it with functionality implemented in wagon.

Feel free to poke around if your interested...mostly hack work..but it took a lot of playing to get it to function correctly.