Show HN: A tiny WASM compiler and runtime for demonstration purposes (luna-demo.vercel.app)
Hello, I'm building a WebAssembly compiler and documenting the process in the meantime.
This aims to be a tool for demonstration and education purpose. It doesn't aim to do fancy stuff nor to replace existing ones.
I'm building this to learn and to improve and hopefully it can be useful for others as well :)
From last time I've presented the idea, I've implemented more basic features on Luna and I've built a custom and tiny runtime for Luna! (documenting it of course).
Any feedback is really appreciated :)
22 comments
[ 4.5 ms ] story [ 53.6 ms ] threadIn particular I'm curious how feasible it is to create WASM polyfills for various languages. Imagine you have a nice C kernel that you want to wrap in various languages. In many cases you can use native extensions to wrap your C kernel through an FFI, and on the web you can use WASM in supported browsers. But what about cases where people can't use your native extension? Suppose they are using a browser that doesn't support WASM. It's nice to be able to offer a polyfill that at least works, even if it is slower.
The feasibility of this idea hinges on how easily you can write a conforming implementation of WASM in a bunch of different languages. But I don't know the WASM spec well enough to know how big of an undertaking this is.
this is also the reason why the "hello world" of WASM is a function adding two numbers - because there are no strings in WASM
https://webassembly.github.io/spec/core/syntax/types.html
https://github.com/WebAssembly/component-model
So arrays of numbers will work and have predictable performance from one wasm runtime to another.
Personally, I'd prefer to see wasm not repeat the same disasterous mistakes Java made.
[0]: https://news.ycombinator.com/item?id=33424354
Do you ever ask someone why they're doing a crossword puzzle? Playing a video game? Trying to get of an Escape Room?
No. But if someone say writes their own Lisp as an exercise, oh the vitriol from the pragmatists.
I've personally stopped answering that question.
https://github.com/thomscoder/luna/blob/009b20c9afd88d0a6572...
The list splitting here is currently un-necessary. Your example for users is
So you can just do something like However, this leaves me with questions. Why should we need to create/parse the AST each time we want to invoke a function? A wasmBinary can provide multiple functions. Creating the AST each time seems extremely wasteful, but also a bit confusing since I don't think it's necessary. My personal opinion is the function "startAeonRuntime" should be more something like "createAeonRuntime" that returns a partially parameterized version of invokeFunction that I can re-use over and over without it needing to create an AST each time. So something likeIn user code I have
Then in the library for the runtime the implementation looks like.