I Built a Scheme Compiler with AI in 4 Days

2 min read Original article ↗

Inspired seeing others quickly built near-production level things that would normally take months or years, I decided to do something that only I would care about: build a Scheme compiler to WASM. I call it Puppy Scheme.

And it happened way faster than I expected. This is a side project so I’m not exactly sure the total number of hours I spent; it was most of last weekend plus an hour or two a couple of weekday nights, but that’s really it.

One night before I went to bed I told Claude to “grind on performance” and when I woke up it had taken compilation time from 3½ minutes down to 11 seconds. Just incredible stuff.

The compiler is definitely still alpha quality but the number of features is impressive for how little time I spent on it. It has:

  • Support for 73% of R5RS and R7RS
  • Support for WASI 2 and the Component Model
  • Uses WASM GC
  • Pretty good dead-code elimination, creating small binaries
  • Self-hosting - Puppy compiles its own source code to puppyc.wasm
  • A wasmtime wrapper to create native binaries
  • A website I built that runs on Puppy wasm in Cloudflare Workers. See the code.

I also started working on a little component model that looks a little like this:

(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)))))

There’s probably more I built that I have already forgotten about. I run into bugs all the time so it’s probably not ready for anyone other than me to use, but I’ve managed to go pretty deep (if not wide) in just a few days of work. We’ve definitely entered a new world.

This is a side-project so I can’t promise too much and am not sure where I’ll take it from here, but if you’re interesting, puppy-scheme.org is where you can check it out.