discussion
discussion copied to clipboard
Anyone compiling Forth VMs to WASM yet?
I just compiled a small-ish Forth VM to Web Assembly. It works (meaning, it can evalutate strings and perform character I/O), but it is hogging all of the resources on the main tab and is not usable in its current form. I suspect error on my part rather than a bug in the original VM source because it runs just fine on native Linux.
Has anyone worked with WASM yet? Anyone have any ideas where I went wrong on this one? Comments appreciated. Here's a reproducible use case: https://github.com/RickCarlino/WASM-Forth
I don't know web assembly, but looking over the code, my initial guess is that - when compiled to JavaScript - the variable "initialScript" is not properly null terminated.
You may want to either explicitly put a '\0' at the end or track how many bytes of the initial script have been read and see if that fixes it.
Here's hoping that's it. :)
Note: I like the way you did the BUILTIN macro.
Jeff M.
On Aug 21, 2017 18:35, "Rick Carlino" [email protected] wrote:
I just compiled a small-ish Forth VM to Web Assembly https://developer.mozilla.org/en-US/docs/WebAssembly. It works (meaning, it can evalutate strings and perform character I/O), but it is hogging all of the resources on the main tab and is not usable in its current form. I suspect error on my part rather than a bug in the original VM source because it runs just fine on native Linux.
Has anyone worked with WASM yet? Anyone have any ideas where I went wrong on this one? Comments appreciated. Here's a reproducible use case: https://github.com/RickCarlino/WASM-Forth
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ForthHub/discussion/issues/52, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtlwpImsezmUPYHBe1MaUPz3blZWHzSks5sahQ9gaJpZM4O98Wx .
@pipcet ported my Forth to asm.js. I think he did some work on wasm as well.
Rick, I try to generate WASM like jit compiler but two main dificult appear. First, WASM work with a stack data but only one parameter can be return, this is an artificial limitation, search multi value return in wasm forum, perhaps change in the future, if not, I need simulate the data stack. Return stack is not accesible but you can llive with this, simulate too. Other is the ausence of jmp or goto, I compile to x86 and not to hi-level lang, I need this for an eficient compile
This too looks v. interesting: https://github.com/stefano/wasm-forth