Scala 3 Compiler Plugins embedded in browser with WASM

Hello,

We are currently building an educational tool where students can write Scala 3 code in a browser window to solve exercises but with some restrictions: for example, if we want students to implement data structures and algorithms by themselves and not import them straight away, we have made compiler plugins that detect such code. This already works if the student is working in their own IDE and submits the code to a compile and automatic grader server where the plugin actually resides.

Now, we want to implement this in a browser where the compiler immediately underlines the forbidden code. This already works in the IDE as the language server can show error messages from the compiler plugin even when just writing the code without compiling.

We would greatly appreciate suggestions for workflows around this issue. Thanks!

1 Like

Why use a compiler plugin and not Tasty Reader?

if you are adventurous you could fork GitHub - scalacenter/scastie: An interactive playground for Scala · GitHub

but you seem to be asking about WASM, are you already compiling code directly in the browser (rather than sending to the server)?

1 Like

I think a vscode in the browser with metal is better.

Hi again,

The goal here is to bring the entire Scala 3 compiler to clientside in the browser via WASM, so we don’t want to compile anything serverside. I suppose there must be some VM that can do this?

We have a prototype of that at GitHub - pgilliar/scala3-compiler-sjs at macro · GitHub . Hopefully we will be able to merge it in the coming month or two.

2 Likes

That is really interesting! Is it possible to implement a clientside compilation demo using that branch of sjs right now?

There is a client side compilation demo in that branch.

3 Likes

Excuse my reply again, can you point out where exactly it is in the branch?

1 Like

Thanks you! How would I build the compiler from source? We managed to get the index.html to render in browser but the compiler manifest of course could not be fetched.

There is a README in the “browser” branch:

you need to check out that branch and build in the root dir etc as written in the readme

1 Like

I built it locally on one of my ubuntu 24.04 boxes, but I could not get it to work as I did not know how to get my Firefox nor my Chromium browser to expose the wasm stuff. It says it compiles the pre-filled hello-world main, but then nothing happens.

Got it to work on chrome just fine! I used npm and npx to serve and the sbt command to build.

2 Likes

Great to know! I found the settings in chromium to enable webasm and it says it compiles but still no “Hello world” is printed for me. I’ll fiddle some more during the weekend if I get the time.