How Sollang’s Stage2 compiler runs in the browser
Public postsEnglish
Meet Sollang through a working example and follow the v0.5 web preview from the editor through Stage2 and LLVM to a running WebAssembly program.
What is Sollang?
Sollang is a programming language I’m building to make the path of a value easy to follow. In "Hello" -> println, the string on the left goes to the print function on the right. In "Stage2" => language, the value gets the name language. Both lines let you start by reading the value.
The Sollang compiler turns .slg source files into LLVM IR, which can be used to build native programs for Windows and Linux or WebAssembly for a browser. This article follows the build labeled v0.5 Preview in the public playground. Read the Sollang project overview
What Stage2 means
I wrote Sollang’s first compiler in C#. I used it to build the compiler whose source was written in Sollang. That resulting compiler is Stage2. It can read and compile Sollang code itself. Writing a compiler in the language it compiles is called self-hosting. The playground loads the browser build of Stage2. See how the compiler is bootstrapped
What happens when you press Run
- Prepare the inputs. The playground reads the editor and selects the standard library sources needed for compilation. It passes both to Stage2.
- Generate LLVM IR. Stage2 is already running in the browser as WebAssembly. It analyzes the source and emits LLVM IR, an intermediate representation of the program.
- Build and run the program. LLVM tools running in the browser turn the IR into a WebAssembly module. The playground runs that module and displays the console output.
The WebAssembly loaded at the start is the compiler. The WebAssembly produced at the end is the program you wrote. Once the tools and standard library have downloaded, compilation and execution take place without sending the code from the editor to a compilation server. See the playground implementation
Change one line and run it again
Choose Hello and interpolation and run it. The first line of output is Hello from Sollang!. In "Sollang" => language, change the value to "Stage2".
main {
"Stage2" => language
"Hello from $language!" -> println
"Values flow from left to right." -> println
}
On the next run, $language takes the new value. I checked this output in the public playground.
Hello from Stage2!
Values flow from left to right.
The last -> println also shows exactly where the string goes. Open the Sollang playground

Comments: 0
Sign in to leave a comment.
No comments yet. Write the first one.