DAFTGROK LUMEN · GUIDE▶ Open the playground

DaftGrok Lumen v0.1

Fox's event-and-colour language, by DaftLad Creations

File extension: .dgl. It really builds working little websites.

Lumen takes a small text program and compiles it into one standalone HTML file. Open that file in a modern browser: the interface, behaviour and selected runtime are inside it. There are no runtime packages or CDN dependencies.

This is an original experimental compiler, not a physical light computer. It borrows Fox's three design principles:

  1. React to events. Executable actions live inside when or on handlers. There is no for or while statement.
  2. Send values on colour channels. A pulse has a channel, a value and a target. Channels have independent queued deliveries.
  3. Take a small runtime. Audio, beat timing, lists, movement/collision, drawing, flash and the monitor are included only when needed.

Important: browser JavaScript is still single-threaded here. Independently queued channels are not CPU threads, simultaneous optical wavelengths or a new low-power chip. A timer still costs work, and a smaller HTML file is not a measurement of electrical energy.

Start without installing anything

Open playground/index.html. It is a single self-contained live playground:

The preview iframe is sandboxed with allow-scripts, without allow-same-origin. This is a prototype, not a security audit. Source is not uploaded, tracked or saved automatically.

Compile on the command line

Node.js 20 or newer is sufficient. No npm install is needed to compile.

node dglc.js examples/hello.dgl -o dist/hello.html
node dglc.js examples/dnb.dgl -o dist/dnb.html --monitor
node dglc.js examples/dnb.dgl -o dist/quiet.html --no-monitor
node dglc.js --version

The executable ./dglc.js works too. package.json also defines the dglc bin name for an optional local npm link; no global installation was performed.

Your first program

app "Hello, Fox"
channel mint = "#a8f6d1"
text title "Waiting for a little light" at 24, 36
button hello "Send a pulse" at 24, 100

when click hello:
  pulse mint "Hello from Lumen!" -> title

on mint:
  text target = value
  glow target 400

Clicking the button queues a mint-channel pulse. Its handler gets target ("title") and value ("Hello from Lumen!"). It updates the text and briefly glows the element. There is no application polling loop.

Use two spaces per indentation level, double-quoted strings, and # for comments outside strings. A block starts with :. String escapes follow JSON (\n, \", \\). Coordinates are CSS pixels. Commas separate coordinates and function arguments.

Program structure

Top-level declarations are app, monitor, state, channel, UI elements, when handlers and on handlers. Actions cannot run directly at the top level. Put start-up actions inside when load:.

States are initialised before UI creation. Element initialisation follows source order. All handlers are installed before load handlers run. Keep initial values simple; do not read an element before it exists.

State and small-number semantics

state count = 0
state label = "Ready"
state playing = true
state step: u8 = 0
state score: u16 = 0
state signed: i8 = -4
state level: f32 = 0.1

when click add:
  set count = count + 1

when change count:
  text title = "Count: " + value
Type Meaning
omitted / any Ordinary JavaScript value: number, string, boolean or null
number Ordinary JavaScript numeric convention; not a strict static type
u8 Truncate and wrap modulo 256: 255 + 1 becomes 0
u16 Truncate and wrap modulo 65,536
i8 Truncate and wrap to signed -128…127
f32 Round through Math.fround

These are value semantics, not a guarantee of one- or two-byte storage. The v0.1 runtime still stores JavaScript values. No memory or wattage reduction from these types has been measured. Use normal numbers if wraparound is not wanted.

A state-change handler is queued only if the cast new value differs according to Object.is. Inside a change handler, value is that event's new value; reading the state name gets its latest current value. Reactive cycles are stopped after 1,000 handler invocations in one event-loop turn, with an on-page error. That is a basic safety guard, not a complete resource sandbox.

UI declarations

text title "Hello" at 24, 30 color "#a8f6d1"
button add "Add one" at 24, 90
input name "Your name" at 24, 150 size 230, 44
box player at 100, 300 size 50, 16 color "#63d9f4"
canvas sky at 24, 210 size 330, 180
list tasks at 24, 200 size 330, 240

at, size and color are optional. Without positions, elements get a simple vertical default placement. Box defaults are 24 × 24; canvas defaults are 320 × 200. Other elements use browser sizing unless a size is provided. Layout uses absolute coordinates inside a centred, at-most-640-pixel app stage. This is not a full responsive layout engine: design for the viewport you need.

Use different names for states, channels and UI elements. target, value and key are reserved event values.

Events

Handler When it runs Useful event values
when load: Once after UI and event setup No target/value
when click add: An element is clicked/tapped target is its element name
when key "ArrowLeft": Matching keydown outside inputs/textareas key
when change count: State value changes target, value
when change name: Input's native input event target, current string value
when change tasks: List is added to, completed or deleted from value is remaining row count
when every(50): Explicit repeated timer, milliseconds value is performance.now()
when beat(174): WebAudio-clock musical beat value is the 1-based beat count
on mint: A pulse arrives on that channel target, value

every(ms) accepts 16…2,147,483,647 ms. beat(bpm) accepts 20…400 BPM. Their expressions are evaluated when registering the handler, not continuously re-read. This version has no cancel/restart timer statement; closing/reloading the app ends it. A paused game can skip its update body while its explicit timer still ticks.

No polling syntax does not mean no periodic computation. every and beat intentionally schedule events. The runtime uses event listeners, microtasks, one-shot scheduling and animation completion/cleanup timers. There is no continuous requestAnimationFrame loop or setInterval. CSS/Web Animations run only when a flash/glow or a monitor pulse is created.

Colour channels

channel red = "#ff957f"

when click send:
  pulse red 42 -> title

on red:
  text target = "Received: " + value
  flash target 180

Omit the value to send null: pulse red -> title. Target must be a known element name, or the current handler's target. Receivers are queued as microtasks in send order. Each matching subscriber runs independently in registration order, on the same JavaScript event loop. Long synchronous handlers can delay other channels. Their colour is routing/monitor metadata, not light or a compressed physical numeric representation.

Actions and expressions

set count = count + 1
text title = "Count: " + count
value name = ""
move player to x(player) + 10, y(player)
paint player "#ff957f"
flash player 150
glow player 350
hide player
show player
append tasks "Try the next idea"
clear tasks
sound kick
sound hat
sound snare
sound beep 660

text writes plain text, not HTML. value writes an input's value; it does not synthesize an input event. Lists provide working complete/delete controls. Their data is in memory only; reload resets a to-do list.

Operators: + - * / %, == != < > <= >=, and or not (also && || !), parentheses. Equality compiles to strict equality. + follows normal number/string concatenation rules. Conditions support if and optional else with indented bodies.

Built-ins: - read(inputName) - x(element), y(element), width(element), height(element) - hits(boxA, boxB) for axis-aligned bounding-box collision - min(a,b), max(a,b), abs(a), floor(a), ceil(a), round(a) - random(low, high) — floating-point, not cryptographic; high is exclusive in normal operation - length(value), trim(value) — string conversion then operation

Canvas basics

canvas sky at 24, 80 size 330, 220

when load:
  draw sky clear("#09121c")
  draw sky rect(20, 30, 70, 40, "#a8f6d1")
  draw sky circle(160, 100, 20, "#63d9f4")
  draw sky line(10, 180, 300, 180, "#ff957f", 2)
  draw sky text("LUMEN", 20, 205, "#edf4f4", 16)

Shape arguments are rect(x,y,w,h,color?), circle(x,y,r,color?), line(x1,y1,x2,y2,color?,width?), text(value,x,y,color?,fontSize?), clear(color?). These are immediate Canvas 2D operations, not a retained scene graph.

Sound and the beat clock

WebAudio requires a gesture. Sound/beat programs get a small start-audio button; clicking it (or another app interaction) creates/resumes the audio context. No beat events run before that. The same button can mute sound while the clock continues.

beat schedules its next one-shot timeout from AudioContext.currentTime, with about 25 ms lookahead. Audio deadlines are preserved through asynchronous colour-channel pulses, so a sound is scheduled for its beat time rather than simply played whenever the handler happens to arrive. Drum synthesizers are original sine/noise generators, not downloaded samples.

Limits: DOM flashes can be early by the lookahead, browser timers/background tabs can jitter or skip late beats, and this is not a DAW, AudioWorklet sequencer or hard real-time system. Actual device timing/audio quality has not yet been browser-tested. The automated audio test uses a mock clock and checks scheduled timestamps, not sound from a speaker.

Pulse monitor

Add monitor on (or use the playground checkbox / CLI --monitor). It shows a coloured travelling dot and increments on handler dispatch. Load, UI, key, state, timer, beat and channel handlers have distinguishable colours. The counter is handler activity, not instructions, joules or watts. The monitor itself adds work and code; omit it for the smallest build.

Examples and current compiled sizes

Source What works Standalone HTML bytes
examples/hello.dgl Greeting, button and colour pulse 4,686
examples/counter.dgl Reactive click counter, reset, u8 wrap 5,209
examples/dnb.dgl 174 BPM quarter notes + 348 BPM hats, pads and monitor 9,862
examples/catch.dgl Falling-light catch game; keys and touch buttons 6,981
examples/todo.dgl Add, complete and delete tasks 5,178
examples/canvas.dgl Draw, pulse-created sparks and clear 5,583

Exact sizes and included helpers are generated in compiled_sizes.json. HTML sizes include the dark neon style and selected runtime, not browser memory, the compiler or the playground. The playground itself is a separate self-contained file (about 43 kB). No compression ratio or measured energy claim is made.

Compiler API and build

const Lumen = require('./compiler.js');
const tokens = Lumen.tokenize(source);
const ast = Lumen.parse(tokens);
const result = Lumen.generate(ast, {monitor: false});
// or: Lumen.compile(source, {monitor: true})
// result: html, js, ast, features, bytes, version

node build.js recompiles every example, writes the size manifest and rebuilds the single-file playground. compiler.js contains a real tokenizer, indentation-aware parser, expression precedence parser, AST validation/code generation, and feature-selected runtime helpers. SPEC.md is the compact syntax reference.

Testing

All 33 automated tests pass, and every example has also been checked in a real browser (Chrome engine, 16 Nov 2026): the playground, all six apps, error messages and the 174 BPM drum clock.

v0.1 limits

Nothing was deployed to daftladcreations.com, aimutants.co.uk or a public server.


DaftGrok Lumen 0.1 syntax reference

Source is UTF-8, .dgl, line-oriented, with exactly two spaces for each block indentation. Blank lines and # comments outside strings are ignored. Strings are double-quoted JSON string literals. Identifiers match [A-Za-z_][A-Za-z_0-9]*. Numbers are ordinary non-exponent decimal literals; negative values use unary minus.

Top level

app STRING
monitor on|off
state NAME [ : any|number|u8|u16|i8|f32 ] = EXPR
channel NAME = STRING
text|button|input NAME EXPR [at EXPR, EXPR] [size EXPR, EXPR] [color EXPR]
box|canvas|list NAME [at EXPR, EXPR] [size EXPR, EXPR] [color EXPR]
when load: BLOCK
when click NAME: BLOCK
when key STRING: BLOCK
when change NAME: BLOCK
when every(EXPR): BLOCK
when beat(EXPR): BLOCK
on CHANNEL: BLOCK

A block is newline, INDENT, one or more statements, DEDENT. UI, state and channel names must be unique. target, value, key are reserved event values. Channel and element references are compile-checked; dynamic target is resolved at runtime.

Handler statements

set STATE = EXPR
text ELEMENT = EXPR
value INPUT = EXPR
move ELEMENT to EXPR, EXPR
paint ELEMENT EXPR
flash|glow ELEMENT [EXPR]
show|hide ELEMENT
pulse CHANNEL [EXPR] -> ELEMENT
sound kick|hat|snare|beep [EXPR]
append LIST EXPR
clear LIST
draw CANVAS clear|rect|circle|line|text(ARGUMENTS)
if EXPR: BLOCK
[else: BLOCK]

An omitted pulse value is null. Flash/glow duration defaults to 150 ms and is clamped to 0…10,000 ms. An omitted beep pitch defaults to 440 Hz; other synthesizers use their own parameters.

Expressions

Literal strings, decimal numbers, true, false and null; state names; event values; parentheses; whitelisted function calls. No arbitrary JavaScript, property access, assignment expressions or user-defined functions.

Precedence, low to high: 1. or, || 2. and, && 3. ==, != (strict equality / inequality) 4. <, >, <=, >= 5. +, - 6. *, /, % 7. unary +, -, !, not

Functions: read(element); x/y/width/height(element); hits(element,element); min/max(a,b,...); abs/floor/ceil/round(a); random(low,high); length/trim(value).

Runtime contract

Declarations set up before events. Handler registration before load. DOM events dispatch synchronously through the runtime; state/channel deliveries queue microtasks. Multiple subscribers run in registration order. Channels share the same JS thread. Timer expressions evaluate at registration; every has a minimum 16 ms; beat accepts 20…400 BPM and starts only after WebAudio is resumed by a gesture.

No polling loop/for/while syntax. Explicit periodic timers remain periodic work. No continuous runtime RAF loop or setInterval. CSS/Web Animations are transient. Audio deadlines travel through colour-channel deliveries. A visible error stops handlers and periodic scheduling if a runtime exception or more than 1,000 handler calls in one event-loop turn is detected.

Compiler returns the AST, generated JavaScript, standalone HTML, included feature list and UTF-8 byte count. Runtime feature dependencies are selected from actual AST use, plus an optional monitor. General base styles remain shared. u8, u16, i8 and f32 specify casts, not a physical representation guarantee. Monitor counts handler dispatch, not energy.