ALB MoonScript backend
The ALB MoonScript backend — ALBM — compiles AdaLogic BASIC into MoonScript, the whitespace-significant, arrow-functioned superset that compiles down to Lua. The chain is three languages deep: .alb → .moon → moonc → .lua → Lua 5.4 + the alb_sdl3 bridge — and the remarkable part is that nothing is lost on the way down.
Why a second translation?
Because MoonScript is already a translation layer. The emitted .moon isn't the destination — moonc compiles it to Lua 5.4 at build time, so the backend inherits everything the Lua backend is: the same albVas virtual address space, the same Dumptruck GC grid, the same Prolog rule engine, the same alb_sdl3.dll bridge, the same MODE NO CONSOLE overlay switch — all documented on the sibling page.
What MoonScript adds is on the writer's side: it makes the generated source shorter, cleaner, and more idiomatic than raw Lua — which matters when the "generated file" is also the deliverable. A hand-checkable artifact, not just an intermediate.
The dialect, worn well
The emitter doesn't write "Lua with different keywords" — it writes real MoonScript:
albEnsureSDL = () ->
ok, mod = pcall(require, "alb_sdl3")
ALB_FATAL("ALBM requires alb_sdl3.dll…") if not ok
albSDL = mod
albSDL.init()
PURE = (num, den) -> return albPurePack(ALB_num(num), ALB_num(den or 1))
export ALB_new_array = (n, fill) ->
(args) ->arrow functions everywhere —ALB_NN_ACT = (code, value) ->,albEnsureTextRow = (row) ->— the runtime is a library of lambdas, notfunction … endscaffoldingexportdeclarations —export ALB_new_array,export ALB_band,export ALB_shl— MoonScript's module-style top-level names- Postfix conditionals —
ALB_FATAL(err) if not ok,r + p if aa == 1 and bb == 1— guards read after the action, the way MoonScript intends ALB_EXPORTS = ALB_EXPORTS or {}— the foreign-export table, initialized idempotentlyALB_NOTIFY_KNOWS_CHANGE(pred, a1, …)— KNOWS updates notify watchers: the logic runtime's change-notification, expressed as a one-line arrow
Even the sized-integer shims come out as readable MoonScript — ALB_band isn't a builtin call; it's the same repeated-halving algorithm the Lua twin uses (a = math.floor(a / 2)), written in the dialect's terser clothing.
The pipeline
albm emits .moon; --build assembles the full kit in moon_<name>/: the .moon file, moonc itself, SDL3.dll, and a run.bat that does moonc game.moon && lua game.lua. --run executes it in place. The runtime is stock Lua 5.4 — not LuaJIT — because alb_sdl3.dll is a standard Lua C-module and doesn't need the JIT's FFI.
Under the hood
Emit_Native_MoonScript (~8,300 lines, SPARK-annotated) declares itself the Lua twin openly — the spec comment reads "feature surface mirrors Emit_Native_Lua" — and it does: same Compile_To_File(Root, Output_Filename) AST-walker, same Set_No_Console_Overlay hook, same runtime rebuilt table-by-table, emitted in the dialect instead of raw Lua. albm.adb drives flags, moonc staging, and the run script.
The difference is purely surface, and that is precisely the point: ALB doesn't target runtimes, it targets languages — and MoonScript is proof the whole stack can wear a second dialect and lose nothing.
See also
- ALB Lua backend — the canonical twin: shared runtime,
alb_sdl3bridge, and the full feature list this page defers to - AdaLogic BASIC — the language
- ALB TypeScript backend · ALB FASM backend · ALB C backend · ALB .NET backend · ALB Ada backend · ALB NASM backend · ALB FASM16 backend
References
- ALB Handbook — alb-lang.org/handbook — the language reference for all backends.
- ALB Technology page — alb-lang.org/technology — the sixteen-backend matrix.
- ALB source — github.com/rockyoliver454/AdaLogic-BASIC-ALB-Programming-Language — the emitter sources are Apache 2.0.