Puppy Scheme

A Scheme compiler targeting WebAssembly.

WASM GCNo runtime garbage collector — uses WebAssembly's built-in GC.
Tiny outputSingle-digit KB binaries. No bloated runtime linked in.
Self-hostingThe compiler compiles itself to WebAssembly.
R7RS librariesdefine-library and import with dead code elimination.

Usage

Compile a Scheme file to WebAssembly:

$ puppyc hello.scm -o hello.wasm
$ wasmtime -W gc hello.wasm

Target the browser or WASI:

$ puppyc app.scm --target web
$ puppyc app.scm --target wasi

The compiler itself is a WASM module. puppyc is a thin wrapper around puppyc.wasm, which can be run directly by any WASI-compatible runtime:

$ wasmtime -W gc puppyc.wasm -- hello.scm -o hello.wasm

Examples

Interactive counter

Compile Scheme to WebAssembly and build live components for the browser. This counter is server-rendered and hydrated on the client.

0
(define count 0)

(define (counter-view)
  (html (div (@ (class "counter"))
          (button (@ (on "click" "on_decrement")) "-")
          (span (@ (class "count")) ,(number->string count))
          (button (@ (on "click" "on_increment")) "+"))))

(define (handle-event handler)
  (cond ((equal? handler "on_decrement")
         (if (> count 0)
             (set! count (- count 1))))
        ((equal? handler "on_increment")
         (set! count (+ count 1)))))