Comment by soegaard

4 hours 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.