Moving the compiler

Marble: ink dropped ring by ring on water, each drop moving all the ink already there and losing none of it. It is 47 lines.
The compiler was written in Dart because Dart is what my work has been built in for the last few years. It was the obvious place to start, and the plan was to leave it there until the language stopped changing.
That plan has changed.
What changed it
I asked how I would actually write Nilo, day to day. The answer was a text editor on one side and the live page on the other. And I had to be honest: I only really write code when the editor understands the language. Words that complete. Errors under the line as I type. Without that I do not sit down and write, I put it off.
So for all the talk of coding by hand, I have not written a full piece in Nilo by hand yet. That is the biggest hole in the project, and an editor is what fills it.
I want two things:
- Nilo understood by the editors I already use.
- An editor of its own in the browser, with the code beside the art, that works on a phone.
Both need the compiler to run in new places. Inside an editor, answering between keystrokes. Inside a web page. And if anyone else is ever to use it, on their machine, without a morning spent installing things.
Why Go
I want the compiler to be fast and I want it to travel. Go gives one program file with nothing to install beside it. It can be built for every kind of computer from one machine. Editors can launch it. It can be built to run in a page.
It will not be much faster. The Dart program is already quick, and the slow part of a full build is the search for the smallest output, which is slow in any language. The gain is where it can go.
The order
- Finish the words that are in progress: curves, gradients, groups.
- Stop adding to the language.
- Rewrite the compiler in Go, as a single job.
- Carry on with the language from there.
- Then the editor support, then the editor.
Doing it now is cheaper than doing it later. Every new feature added in Dart is one more thing to carry across.
How I will know it worked
This is where the byte comparison earns its keep. The new compiler has to produce the same 180 builds as the old one, byte for byte, and pass the same 470 checks. Not close. The same.
A rewrite is normally an act of faith. This one can be proven, and the old compiler stays until it is.
What could go wrong
- Numbers. The two languages print them in slightly different ways, and every number in a shipped file has to come out identical.
- Order. Go deliberately shuffles the order of some of its collections, so a careless port would give a different file each time it ran. For work that goes on chain, that is not acceptable.
- Time. My guess is a few days. I do not trust the guess.
The editor waits until this is done. I would sooner build it once, on the compiler it will live on.
The piece at the top
The image at the top comes from this token, built for the svg target: 0x8f08377b97472a3cb9f41813ddd04f149af6ce2e2185bb059b8a7ae890012652
// marble: ink dropped ring by ring on water, each drop pushing out all the ink already there
plate(1920, 2400)
use colour v2
random layout, ink
let deep = [#1b2a4e, #5a1a1f, #12403f, #2a1c16][ink.int(0 ..< 4)]
let water = #f1ebe0
kind drop { at: vec, size: num, tint: color, edge: num }
let drops = drop[]
// where p ends up once every drop from the one given on has pushed it outward
fn carry(p: vec, from: int): vec {
var q = p
for d in drops[from ..< drops.len] {
let away = q - d.at
q = d.at + away * sqrt(1 + pow(d.size / len(away), 2)) // moved out by just the drop's area
}
return q
}
// places near a focus, fed in turn: a ring of ink, a shade paler or darker each time, then clear water
let focus = vec(layout.float(760 ..< 1160), layout.float(950 ..< 1450))
let places = vec[]
for k in 0 ..< layout.int(6 ..< 14) {
places.add(focus + polar(layout.float(0 ..< TAU), layout.float(0 ..< 420)))
}
let width = layout.float(85 ..< 125) / sqrt(places.len) // more places, narrower rings
for round in 0 ..< 26 {
for at in places {
if ink.chance(0.4) { continue }
let tint = colour.mix(deep, toward: water, amount: ink.float(0 ..< 0.35))
drops.add(drop(at, size: width * ink.float(0.5 ..< 1.3), tint: tint, edge: 1.2))
drops.add(drop(at, size: width * ink.float(0.6 ..< 1.8), tint: water, edge: 0))
}
}
// then the water is turned about an eddy near the focus: the nearer a point, the further it turns
let eddy = focus + polar(layout.float(0 ..< TAU), 400), spin = layout.float(-3 ..< 3)
fn stir(p: vec): vec {
let away = p - eddy
return eddy + polar(atan2(away.y, away.x) + spin * exp(-len(away) / 500), len(away))
}
background(water)
for k in 0 ..< drops.len {
let rim = vec[]
for j in 0 ..< 360 {
let start = drops[k].at + polar(TAU * j / 360, drops[k].size)
rim.add(stir(carry(start, from: k + 1)))
}
polygon(rim, fill: drops[k].tint, stroke: colour.darken(deep, amount: 0.3), width: drops[k].edge)
}