Clone this repository
For self-hosted knots, clone URLs may differ based on your setup.
Download tar.gz
Implement the dfasm macro system as designed in docs/design-plans/2026-02-28-dfasm-macros.md.
Grammar changes:
- Add macro definition (#name params |> { body }) and invocation syntax
- Add function call syntax ($func args |> outputs) with named outputs
- Require trailing colon on location directives (disambiguation)
- Add scoped references (#macro.&label, $func.&label)
- Add ${param} parameter reference syntax for const and edge positions
- Add variadic parameters (*args) and repetition blocks ($(body),*)
Pipeline:
- Lower: CST-to-IR for all new grammar rules, MacroDef/IRMacroCall/ParamRef
creation, token pasting pattern detection
- Expand: new pass between lower and resolve. Macro expansion with parameter
substitution, const expression evaluation, token pasting, variadic
repetition. Function call wiring with @ret return markers and per-call-site
context slots.
- Allocate: per-call-site context slot assignment via CallSite metadata
- Codegen: CTX_OVRD (ctx_mode=01) emission on cross-call-site edges
Built-in macro library: zero-param self-contained macros (dup, discard,
reduce_add) prepended to user source automatically.
Error handling: MACRO and CALL error categories with expansion stack
threading for precise error locations in nested macros.
Tests: 1034 passing (40 new macro/call tests + existing regression suite).
Macro system with IR-level expansion, static function call syntax
with @ret markers and auto-inserted free_ctx, trailing-colon
location directives, dot-notation scope resolution, and built-in
macro library. 8 implementation phases.
Design for adding env.timeout(1) between pipeline stages in PE, SM,
and network delivery. PE adopts process-per-token model for natural
pipelining. 3 implementation phases covering emu/, tests, and monitor.
6 phase files covering observability hooks, simulation backend, CLI REPL,
frontend-common extraction, web server, and monitor frontend. Includes
Playwright validation tasks in phases 4 and 6 to catch frontend integration
issues during execution.
feat(emu): add typed event system with PE/SM observability hooks
- Add emu/events.py with frozen event dataclasses (TokenReceived, Matched, Executed, Emitted, IRAMWritten, CellWritten, DeferredRead, DeferredSatisfied, ResultSent)
- Add on_event callback field to PEConfig and SMConfig
- Wire callbacks into PE and SM SimPy processes
- Wire callbacks through build_topology
- Export event types from emu package
feat(monitor): add simulation backend with state snapshot capture
- Promote asm.run_pipeline to public API
- Add monitor/snapshot.py with frozen StateSnapshot dataclasses (PESnapshot, SMSnapshot, SMCellSnapshot)
- Add monitor/commands.py with typed command/result protocol (LoadCmd, StepTickCmd, StepEventCmd, RunUntilCmd, InjectCmd, SendCmd, ResetCmd, StopCmd)
- Add monitor/backend.py SimulationBackend with threaded SimPy execution and command queue
- Export public API from monitor/__init__.py
feat(monitor): add CLI REPL for interactive simulation control
- Add monitor/formatting.py with ANSI colour helpers and NO_COLOUR flag for testing
- Add monitor/repl.py with cmd.Cmd-based REPL (load, step, stepe, run, send, inject, state, pe, sm, log, time, reset, quit)
- Add monitor/__main__.py CLI entry point with --cli/--web/--port flags
refactor: extract frontend-common shared TypeScript library from dfgraph
- Create frontend-common/ package with shared layout, style, export, and type modules
- Refactor dfgraph/frontend to import from @common/ alias
- Update build.mjs files with esbuild path aliases
- Both dfgraph and monitor frontends consume frontend-common as workspace dependency
feat(monitor): add FastAPI WebSocket server and graph JSON serialization
- Add monitor/graph_json.py with execution overlay (active/matched/executed/token_flow flags)
- Add monitor/server.py with FastAPI, bidirectional WebSocket, REST endpoints
- Add --web mode to CLI entry point
- Extend graph_loaded_json and graph_to_monitor_json with full state serialization
feat(monitor): add browser frontend with Cytoscape.js graph visualization
- Create monitor/frontend/ package with esbuild, TypeScript, Cytoscape.js
- Add TypeScript types matching server protocol (MonitorNode, MonitorEdge, SystemState, etc.)
- Add execution overlay styles (active, matched, executed, half-matched, token-flow)
- Add event log panel with component/type filtering
- Add state inspector panel with PE/SM tree view and node click matching store display
- Add WebSocket client with exponential backoff reconnection
- Add main.ts with graph rendering, execution state overlay, control handlers
- Add dark-themed three-panel HTML layout
docs: add human test plan for OR1 Monitor
fix(asm): generate SMConfigs for all declared SMs, not just those with data defs
generate_direct only created SMConfigs from @val data definitions, ignoring
the sm_count from @system pragma. Programs with SM operations but no @val
directives got zero SMConfigs, causing KeyError at runtime when PE tried
to route to a nonexistent SM.
Now ensures at least max(1, system.sm_count) SMConfigs are always created.
fix(monitor): sanitize float('inf') in JSON serialization for browser compatibility
Python's json.dumps serializes float('inf') as 'Infinity' which is not
valid JSON. The browser's JSON.parse would fail silently on monitor_update
messages when the simulation finished (next_time=inf). Convert non-finite
floats to null via _safe_time() helper.
fix(monitor): use 'presence' not 'pres' for SM cell state in frontend
The Python serializer uses 'presence' as the JSON key but the frontend
renderer was reading 'pres' (the dataclass field name from sm_mod.py),
resulting in 'undefined' in the cell display.
Interactive emulator interface with typed observability hooks in emu/,
shared simulation backend with command queue, CLI REPL, and web GUI
with dataflow graph execution overlay. Six implementation phases.