
Every infix language has a stack machine underneath. Script is what BASIC's expression evaluator looks like with the front end deleted — so this puts the front end back, and takes it off again.
Be the first to ask Sun-Dive something.
What do you think? ...
★ The compiler balances the branch arms. Both arms of an OP_IF must leave the stack identical, and getting it wrong is silent — it surfaces two hundred opcodes later as a size complaint. The compiler takes the union of everything either arm assigns and makes both produce all of it, so a whole bug class stops being possible rather than becoming less likely. ★ And FOR…NEXT is unrolled at compile time, because Script has no backward jump — the loop still happens, laid out in space rather than repeated in time, so a program's length is its work. That pays for a fixed-cost body and barely at all for an early-exit one.
★★ Noughts and crosses is the one to read. Five bytes of state, every rule a comparison, and it shows what a racing car cannot: turn-taking enforced by the covenant. You cannot play out of turn, take a taken square, or play on after somebody has won — and none of those rules live in a page. ⚠ Note what it has to do about having no arrays: Script cannot compute a location, so the square is chosen by nine comparisons each selecting a constant, and the board is packed base 3 into one number so that reading a square is arithmetic instead of a lookup. That is a 1982 problem with a 1982 answer. ★ And there is a second version of it packed base 4 — two bits a square, one value wasted — where every access becomes a shift instead of a division. Measured: 657 bytes against 762, for one extra byte of state. Waste a little space to make the arithmetic cheap, which is the oldest trade in the business.
★★★ Rule 110 is the one with the joke in it. A row of cells; each looks at itself and its two neighbours and decides what to be next. Eight patterns, eight answers — 01101110 = 110 — and it draws the famous nested triangles. It is also Turing complete, which Matthew Cook proved, so it is the machine that "Script isn't Turing complete" is usually said about. Both halves are true at once: one generation is 2974 bytes with no backward jump anywhere in it, and the chain of transactions runs unboundedly. ⚠ It does not make Script Turing complete — it shows where the loop went. Into the ledger. ★ And it is the one program here with no runtime index at all: every neighbour sits at a position the compiler knows, so the thirty-one cells unroll with every mask already folded, and no table or shift is needed.
★★★ And Space Invaders is the one that proves something. The arcade original speeds up as you kill aliens, and nobody designed that — the 8080 moved one alien per frame, so a sweep took as many frames as there were aliens left. Here one transaction moves one alien, and the same ramp comes back: measured, a sweep costs 24 spends at 24 aliens and 12 at 12, so the fleet is twice as fast at half strength. ⚠ And it is not automatic — the script is byte-for-byte the same size in every frame, whatever is alive. What falls is the number of transactions. The economics reproduce the accident only because one spend was made to mean one alien.
★★ And it is the full 5 × 11 arcade fleet, which it was not an hour ago. The bit for a slot used to be picked by a table of comparisons — about fifty bytes a slot, and impossible past 2^53, where a double stops being exact. A shift is what stands in for a power of two, and it does not care how wide the fleet is: 1269 B by table at 52 aliens and refused at 55, against 34 B by shift, flat. ⚠ With one trap — read as a number, a mask landing on the top bit of the last byte is negative zero, and one alien in fifty-five would quietly refuse to die. It has to be SAMEBYTES, a byte comparison, never =.

Earn XP for sharing
Sign in to get a personal referral link and earn XP every time someone visits through your link.
No reviews yet — be the first.
REM ── rule 110 ──────────────────────────────────────────────────────
REM One transaction is one generation: the loop is in the CHAIN.
REM There is no input — nobody plays this, it simply runs.
DIM cells%4 REM 31 cells, one bit each, wrapped into a ring
DIM gen%2 REM which generation this is
FOR g = 1 TO 1
new = 0
FOR i = 0 TO 30
REM every neighbour is at a position the COMPILER knows, so each of these
REM divisors is a folded constant and no lookup is needed at all.
l = MOD(cells / 2 ^ MOD(i + 1, 31), 2)
c = MOD(cells / 2 ^ i, 2)
r = MOD(cells / 2 ^ MOD(i + 30, 31), 2)
REM the eight-row table, collapsed into one line of boolean algebra
new = new + ((c OR r) AND NOT(l AND c AND r)) * 2 ^ i
NEXT i
cells = new
gen = gen + 1
NEXT g