Hacker Newsnew | past | comments | ask | show | jobs | submit | soegaard's commentslogin

Yes. I am following the Scheme tradition of representing immediate values as tagged pointers. And (ref i31) is the obvious choice when using WebAssembly. I am happy you and the team added GC to WebAssembly.

Details on the representation.

https://github.com/soegaard/webracket/blob/main/compiler.rkt...

I am more or less only using the linear memory for the JavaScript FFI. FASL-encoded values are passed back and forth to JavaScript.


I wouldn't say compiling full Racket to WebAssembly is impossible. But I think the consensus is that one can't add a WebAssembly backend to the compiler in the same manner as the x86 and arm backends. These backends manipulate the stack in ways WebAssembly prohibits.

This forces an Racket implementation to make continuations explicit. And that will most likely mean a WebAssembly backend will be slower than the native backends.


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


Are there any architectural similarities or crossover with Hoot (Guile Scheme -> Wasm) or are you taking a completely different approach?

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.


> Adding continuation marks and delimited continuations require adding a CPS-pass.

Have you considered targeting the stack switching proposal?


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


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.


With stack-switching you won't (shouldn't?) need a CPS pass.

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


No, there is nothing in common with Whalesong.

Whalesong used the built-in bytecode compiler and compiled the bytecode to JavaScript. Reusing the bytecode compiler is in principle a good idea - but each time the bytecodes are changed, Whalesong needs to be updated.

And after the move to Chez Scheme as backend, the bytecode compiler is no longer a part of the main compilation path.


JVM languages always target bytecode because it’s much simpler and stable than Java as a language. It almost never changes and when it does it normally won’t break code generation since it’s only adding type system information, for example, as with records.

Is Racket bytecode different?


JVM bytecode is well specified. [0]

Racket is not [1]. It's just the internal representation that the compiler uses. Sort of like marshalling in Python.

[0] https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.ht...

[1] https://docs.racket-lang.org/raco/API_for_Making_Bytecode.ht...


> Is Racket bytecode different?

Changes to the bytecode representation were indeed rare also in Racket.

The Whalesong project was written as part of a dissertation - and when people graduate and get jobs, projects are often abandoned.


Nato - Article 2

The Parties will contribute toward the further development of peaceful and friendly international relations by strengthening their free institutions, by bringing about a better understanding of the principles upon which these institutions are founded, and by promoting conditions of stability and well-being. They will seek to eliminate conflict in their international economic policies and will encourage economic collaboration between any or all of them.


A wonderful video!


Thanks for helping my son learn it.


From the Idris 2 documentation:

    >> Can Idris 2 compile itself?
    > Yes, Idris 2 is implemented in Idris 2. By default, it targets Chez Scheme, 
    > so you can bootstrap from the generated Scheme code, as described in Section 
    > Getting Started.
Also, check this talk:

https://www.youtube.com/watch?v=h9YAOaBWuIk


well, i wouldn't call that beeing bootstrapped.

in this case the generated scheme code is just a strange form of executable file that happens to need ChezScheme to be executed.

i.e. an ELF64 idris2 linux binary vs. an idris2.scm file that needs ChezScheme to come alive.

as for Idris2 implemented in Idris2: well, yes, that's true for the current version of Idris2. but the first version of Idris2 was written in Idris1. and the first version of Idris1 was written in Haskell.


Go to racket-mode.com for the very nice Emacs-integration.


Geiser works well for Racket also.


I think, this is the best way of running the SICM programs.


Mock-up?


Typically "mock-up", like "wireframe", refers to a model of the user interface appearance, perhaps made with Figma or Photoshop, but I think noosphr is talking about a prototype of the functionality.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: