Code Monkey home page Code Monkey logo

chum's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.