wasmpascal v0.4.0: Ternaries, Xonix, and more
01-09-2026
The compiler keeps growing
A week ago I released Flight Leader for wasmpascal. There's still so much to do on my list, but I managed to carve out some time over the weekend to tick some things off the list.
Today, wasmpascal hits v0.4.0. This release is contains new language features, another arcade game port (Xonix clone), touch support for mobile devices, a completely modular standalone export pipeline, and a better test harness that now runs smoke tests in headless Chrome.
Here is what is new since the last update.
1. Ternary Expressions
In standard Pascal, if you wanted to assign a value based on a condition, you had to write out a full
if ... then ... else statement block:
if n <= 1 then
FibRec := n
else
FibRec := FibRec(n - 1) + FibRec(n - 2);
I decided wasmpascal needed ternary expressions. Because I'm lazy...
Now you can write if cond then a else b directly in expression position:
FibRec := if n <= 1 then n else FibRec(n - 1) + FibRec(n - 2);
This isn't just for numbers either. The ternary operator in wasmpascal supports:
- Scalars & numerics: Integers, Reals, Booleans, characters, enums, and subranges (with proper numeric promotion when mixing types).
- Strings: Both dynamic heap strings and fixed
String[n]buffers via scratch pairs. - Proper short-circuiting: Only the selected branch is evaluated, so side-effects in the unused branch are never executed.
- Nesting & expressions: Multi-level nesting without mandatory parentheses, usable directly inside array indexers, for-loop bounds, write arguments, and case selectors.
I went through several existing examples in the repository (fibonacci.pas,
shapes.pas,
flightleader.pas, flsim.pas, basic_canvas.pas) and cleaned them
up with ternaries.
It makes code just a little bit less verbose, in my opinion.
2. A classic DOS game: Xonix
I shamelessly cloned the classic Xonix (xonix.pas, over 1,000 lines of
Pascal) in wasmpascal running on the batchiness canvas ABI.
If you remember Xonix or Qix from the arcade/DOS days, the objective is simple: guide your marker across the water to build land and enclose the bouncing balls. Claim at least 75% of the playing field to advance to the next level. Each new level adds another ball to dodge.
The flood-fill algorithm in xonix.pas has a neat trick: it floods from the position of
the bouncing balls outward
into open sea. Any water reachable by an enemy stays water; any water unreachable by any enemy is
converted to land.
This guarantees an enclosed ball keeps its own pocket open and the fill algorithm can never accidentally
crush a ball!
3. Touch & Mobile Controls
Wasmpascal canvas games now support touch events! The batchiness canvas runtime and games
like
breakout_graphics.pas now detect touch dragging, letting you steer the paddle or interact
with canvas
demos directly on your phone or tablet.
4. Modular Standalone Web App Exports
When wasmpascal v0.3.0 introduced standalone web app exports (downloading a project as a ready-to-host
.zip
or a single self-contained .html), it shipped a monolithic ~850-line runtime.
In v0.4.0, the export engine has been completely re-architected into lightweight, modular building blocks:
runtime-core.js: The universal WebAssembly bootloader and export ABI detector.runtime-batchiness.js: The batched 2D canvas bridge and Web Audio synthesizer (included only if your app usesbatchiness).runtime-canvas.js: The direct pixel-buffer canvas runtime (included only forbasic_canvasprograms).runtime-console.js: The Turbo Pascal character screen, color palettes, Delay sleep worker, and input handlers.runtime-pascaldom.js: The DOM and Canvas 2D bridge.
Your exported web apps now only bundle the runtime modules they actually need. Furthermore, standalone
console programs
now support both full SharedArrayBuffer worker input bars (when served with cross-origin
isolation headers)
and fallback prompt() dialogs on plain static hosts.
5. Automated Smoke Testing
As a compiler grows, making sure you didn't break an existing feature or example is quite tricky.
v0.4.0 adds a unified ./test.sh test runner with:
- Example Smoke Suite (
examples_smoke_test.js): A headless Chrome test runner that automatically compiles, boots, and verifies all 39 examples in the dropdown menu. - Golden Output Drift Protection: Verifies that deterministic console examples match checked-in golden snapshots byte-for-byte, preventing formatting regressions.
- Consistency & Docs Checks: Verifies version flags, query strings, and documentation counts across the entire codebase.
Try it out!
Everything is live right now at https://wasmpascal.com/.
Select xonix.pas or ternary.pas from the
dropdown, hit Run,
and have some fun with Pascal in your browser!
Return to the blog index