Skip to content

A friendly WASM compiler for scheme (experimental).

License

Notifications You must be signed in to change notification settings

jochasinga/chum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chum 🚧

A friendly WASM compiler for scheme (experimental).

run

$ guile
> GNU Guile 3.0.9
> Copyright (C) 1995-2023 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> scheme@(guile-user)> (load "compiler.scm")
> scheme@(guile-user)> (compile-and-run '(primcall integer? 3))
>> #t
> scheme@(guile-user)> (compile-and-run '(primcall + 3 2))
>> int: 5

Instead of compiling to x86 Assembly, chum compiles to hand-rolled WAT program and gets executed by the runtime.

Running compile-to-wasm procedure will compile an expression to a corresponding WAT in modules/compiled.wat without compiling to WASM binary and running.

> scheme@(guile-user)> (load "compiler.scm")
> scheme@(guile-user)> (compile-to-wasm #\a)

To invoke the runtime, run compile-and-run:

> scheme@(guile-user)> (load "compiler.scm")
> scheme@(guile-user)> (compile-and-run #\a)
>> char: a

components

Does most of the work. Use tagged pointers to determine types such as fix-num, boolean, and character. Emit the source code in Webassembly Text Format (WAT) in modules/compiled.wat.

Rust runtime that links a bunch of WAT modules together, convert the tagged binaries into the corresponding types, and simply print them out.

Helper functions written in WAT.

movitation

I started coding from literature, thus writing computer code has been nothing short of writing a novel for computers. Writing a compiler for a programming language is one of my programming epitaphs I've always wanted the time to work on.

Lisp (and in effect, Scheme) is, in my opinion, the most expressive computer language humanity has ever created.

Moreover, the homoiconicity1 of Lisp makes it possible to skip the parsing process of a compiler.

This project is also overwhelmingly inspired by An Incremental Approach to Compiler Construction2 and Let's Build a Compiler Series3.

  1. I wish we could stop linking Wikipedia. It's at the point where it's just downright scaring learners away.
  2. An Incremental Approach to Compiler Construction, Abdulazia Ghuloum
  3. Let's Build a Compiler, Noah Zentzis

About

A friendly WASM compiler for scheme (experimental).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published