soegaard
16 days ago
Hi All,
It's still early days for the WebRacket project.
Racket is a huge language, so be patient wrt features.
To keep motivation high I decided to implement a subset that can be used to built practical applications - and then extend the supported features from there. Hopefully, this strategy will also lead to some early adopters that can help me prioritize which features to add.
Some features are simply "more of the same". In this category falls more types of hash tables. Supporting bignums are also a matter of just doing it.
Other features require more work. I have already done some work on implementing modules in terms of linklets. When linklets/modules work, we can reuse the existing implementation of regular expressions.
Adding continuation marks and delimited continuations require adding a CPS-pass. This is certainly doable. Postponing it has been great though. Having a direct style compiler means the generated code follows the structure in the input source code. And that makes debugging easier. Now that bugs have become rarer, it makes sense to look at CPS.
Enjoy.
/Jens Axel
michaelsbradley
16 days ago
Are there any architectural similarities or crossover with Hoot (Guile Scheme -> Wasm) or are you taking a completely different approach?
soegaard
16 days ago
I am using a similar representation of immediates as Hoot and wasm_of_ocaml.
The representation is explained here:
https://github.com/soegaard/webracket/blob/main/compiler.rkt...
Internally the compiler uses a series of passes implemented using Nanopass.
(generate-code
(flatten-begin
(closure-conversion
(anormalize
(categorize-applications
(assignment-conversion
(α-rename
(explicit-case-lambda
(explicit-begin
(convert-quotations
(infer-names
(flatten-topbegin
(parse
(unexpand
(topexpand stx)))))))))))))))
The code generator is inspired by "Destination-driven Code Generation"
by Dybvig, Hieb and Butler. There are some differences however. The code
generator in the paper generates "flat" code (assembler) whereas I
generate nested Web Assembly instructions.This approach generates reasonable code without having to implement a register allocator. Also, I believe I saw a Wasm to Wasm compiler that improved register allocation (maybe it was a switch for wasm-tools?).
If (when?) WebRacket becomes a success, we can always switch out individual passes.
titzer
16 days ago
> Adding continuation marks and delimited continuations require adding a CPS-pass.
Have you considered targeting the stack switching proposal?
debugnik
16 days ago
Another idea, wasm_of_ocaml [1] compiles effects using either a CPS transform or the JS Promise integration proposal for Wasm [2].
[1]: https://github.com/ocsigen/js_of_ocaml/blob/1b1fcf7b06c12324... [2]: https://github.com/WebAssembly/js-promise-integration/blob/7...
soegaard
16 days ago
Maybe. My main problem is to get light-weight support for continuation marks.
If I need a CPS-pass for continuation marks, I might as well use it for continuations as well.
It would be great if it were possible to avoid a CPS-pass though.
titzer
16 days ago
With stack-switching you won't (shouldn't?) need a CPS pass.
soegaard
16 days ago
I need to study the stack-switching proposal in more detail.
However, I don't see an obvious way of attach and probe continuation marks to the continuations (including the current one).
I am not an expert in continuation marks, so I'll just link to this presentation by Matthew Flatt (which you probably already know).
https://github.com/WebAssembly/meetings/blob/main/stack/2021...