❄️ Tinsel AoC DSL

CLI, Debugger & Web Inspector Reference

This page documents all command-line subcommands, flags, environment variables, the interactive REPL, the terminal debugger (tdb), and the live browser-based Web Inspector IDE.


1. CLI Command Synopsis

bash
tinsel [command] [flags...] [arguments...]
Command Usage Description
run tinsel run [--no-opt|-O0] [--debug[=addr]|--debug-brk[=addr]] [--cover*] <file.tin|dir/> [args...] Compiles and executes one or more scripts or a directory
(default) tinsel <file.tin|dir/> [args...] Shorthand for tinsel run when the target path exists
debug tinsel debug [--addr=host:port|-p port] [--cli] [--run|--no-brk] [--opt|-O] <file.tin> Launches the Web Inspector IDE or terminal debugger (tdb)
compile tinsel compile [--no-opt|-O0] <file.tin> Compiles a script and prints its bytecode disassembly
check tinsel check <file.tin|dir/>... Statically parses and compiles files/directories without executing
eval, -e tinsel eval "<code-string>" Compiles and evaluates an inline Tinsel snippet
test tinsel test [--cover*] [file.tin|dir/...] Discovers and runs test_*.tin / *_test.tin suites (default: tests/)
play, playground tinsel play [--addr=host:port|-p port] [--docs=dir] Starts the interactive Web Playground & Documentation server (default: 127.0.0.1:8080)
doc, docs tinsel doc [output-dir] Generates the static HTML documentation, playground.html, and search index (default: docs/html)
vscode tinsel vscode [--dir=<ext-dir>] [--vsix=<out.vsix>] Packages and installs the VS Code / Cursor / Antigravity .tin extension
(none) tinsel Starts the interactive multi-line REPL
help, --help tinsel help Prints CLI usage information

2. Running, Checking & Testing Scripts

Single-File & Batch Execution (run)

  • Single Script with CLI Arguments: Arguments after <file.tin> populate the global args: [string] array:
    bash
    ./bin/tinsel run examples/aoc2025/day01.tin inputs/day01.txt
    
  • Directory & Multi-File Batch Execution: Pass a directory or shell glob to run multiple scripts sequentially:
    bash
    ./bin/tinsel examples/aoc2025/
    ./bin/tinsel examples/aoc2023_*.tin
    

Static Verification (check) & Test Suites (test)

  • tinsel check validates syntax, variable mutability (let vs. let mut), and pattern compilation across files or directories without executing code:
    bash
    ./bin/tinsel check examples/ tests/ stdlib/
    
  • tinsel test runs all test scripts in tests/ (or specified paths) and reports timing per file:
    bash
    ./bin/tinsel test
    ./bin/tinsel test tests/test_struct.tin
    

Code Coverage Analysis (--cover)

Both tinsel run and tinsel test support line, function/method, and branch (if/else and match arm) coverage tracking across user scripts, imported local .tin modules, and optionally embedded std/* modules:

Flag Description
--cover Enable coverage tracking and print a per-file summary table (lines, functions, branches)
--cover-func Include a per-function and struct method breakdown table (Struct.method, call counts, line %)
--cover-show Print colorized source code in the terminal annotated with execution hit counts (142x) and partial-branch diagnostics
--cover-std Include embedded standard library (std/*) modules in the coverage report
--cover-html=<file.html> Generate a standalone interactive HTML coverage report with file tree, function breakdown, and filter pills
--cover-out=<file.info|.json> Export coverage profile in standard LCOV (.info/.lcov, including FNDA/DA/BRDA) or JSON (.json) format
bash
# Run test suite with per-function summary and standalone HTML report
./bin/tinsel test --cover --cover-func --cover-html=coverage.html

# Run a single script with annotated terminal source and LCOV export
./bin/tinsel run --cover-show --cover-out=coverage.info examples/aoc2025/day01.tin

Bytecode Disassembly (compile) & Web Playground (play)

Inspect the compiler's optimized bytecode (including constant folding and superinstructions) or pass --no-opt (-O0) to view unoptimized 1-to-1 bytecode:

bash
./bin/tinsel compile examples/aoc2023_day1.tin
./bin/tinsel compile --no-opt examples/aoc2023_day1.tin

Launch the interactive Tinsel Playground server to edit and execute code in your browser, test custom puzzle inputs (input.txt), browse bundled examples, compare -O vs -O0 bytecode side by side, and run code blocks inline across the HTML documentation:

bash
./bin/tinsel play
./bin/tinsel play -p 9000

Environment Variables & Exit Codes

  • TINSEL_PATH: Colon-separated list of directories (semicolon-separated on Windows) searched when resolving module imports.
  • TINSEL_DEBUG_ADDR: Default host:port (e.g. 127.0.0.1:4040) for the Web Debugger; when set during tinsel run, automatically attaches the live debug endpoint.
  • TINSEL_PLAY_ADDR: Default host:port (e.g. 127.0.0.1:8080) for tinsel play.
  • Exit Codes: 0 on success; 1 on syntax, compilation, runtime, or assertion error.

3. Live Web Inspector IDE & Debugger (tinsel debug)

Tinsel embeds a zero-dependency source-level and bytecode-level debugger with both a browser-based Web Inspector IDE and an interactive terminal CLI (tdb).

text
+-------------------------------+                  +-------------------------------+
|     Web Browser Inspector     |  SSE /api/events |     Embedded Debug Server     |
|    (http://127.0.0.1:4040)    | <--------------> |      (internal/debugger)      |
+-------------------------------+  REST /api/eval  +-------------------------------+
                                                              ^         ^
+-------------------------------+                             |         | DebugHook &
|    Terminal CLI Debugger      | ----------------------------+         | EvalInFrame
|   (tinsel debug --cli / tdb)  |                                       v
+-------------------------------+                  +-------------------------------+
                                                   |      Tinsel Bytecode VM       |
                                                   |         (internal/vm)         |
                                                   +-------------------------------+

Launching the Debugger

  1. Dedicated Debug Session (Paused on Line 1):
    bash
    ./bin/tinsel debug examples/aoc2024_day16.tin
    # Custom port or start running immediately until a breakpoint/dbg() is hit:
    ./bin/tinsel debug -p 8080 --run examples/aoc2024_day16.tin
    
  2. Attaching to a Normal tinsel run Job:
    bash
    ./bin/tinsel run --debug examples/aoc2024_day16.tin
    ./bin/tinsel run --debug-brk=127.0.0.1:4040 examples/aoc2024_day16.tin
    
Note

Optimization Mode in the Debugger: tinsel debug and tinsel run --debug default to unoptimized compilation (--no-opt) so every source line and local variable maps 1-to-1 during stepping and frame evaluation. Pass --opt (-O) if you explicitly want to step through optimized superinstructions.

Programmatic Breakpoints (dbg & breakpoint)

Call dbg(expr) or breakpoint() anywhere in your .tin code to pause when the debugger is attached. When running normally without a debugger, dbg(x) is a fast no-op that returns x unchanged:

tinsel
let total = dbg([10, 20, 30].sum())
assert(total == 60)

Web Inspector IDE Features

  • Stepping Controls: Continue (F8), Step Over (F10), Step Into (F11), Step Out (Shift+F11), Step Single Bytecode Instruction, Live Pause, and Restart.
  • Conditional Breakpoints: Click any line number in the gutter to toggle a breakpoint, or Shift+Click to attach a Tinsel condition expression (e.g. cost > 500 && pos == vec2(5, 5)).
  • 2D Grid & RangeSet Visualizers: Automatically renders grid variables as color-coded 2D boards and rangeset variables as interval badges.
  • Live Code Coverage Overlay (📊 Cov): Highlights executed (green), partial-branch (amber), and unexecuted (red) source lines in real time with execution hit counts (14x) in the gutter and a dedicated Coverage tab showing per-function call counts and line percentages.
  • Live Frame Evaluator: Evaluate arbitrary Tinsel expressions in the lexical scope of any paused call frame.

4. Terminal CLI Debugger (tdb)

Pass --cli to debug directly in your terminal (./bin/tinsel debug --cli <file.tin>):

Command Shorthand Description
continue c Resume execution until the next breakpoint or program exit
next n Step over to the next source line in the current frame
step s Step into a function call or advance to the next line
out o, finish Finish the current function frame and pause at the caller
stepi si Execute a single VM bytecode instruction
break [file:]<line> [cond] b Set a line breakpoint with an optional Tinsel condition
delete <id> / breakpoints d / bl Delete a breakpoint by ID or list all active breakpoints
backtrace bt, where Print the active call stack frames
vars v, locals Print current frame locals, captured upvalues, and module globals
print <expr> p, eval Evaluate <expr> in the currently selected call frame
watch [expr] w Add a watch expression or list current watches
list / disasm l / dis Print source lines or bytecode disassembly around the current IP
coverage [show|all] cov, cover Print live line/function/branch coverage summary (or annotated source with cov show)
restart / quit r / q Restart or exit the debugging session

5. Debugger HTTP REST & SSE API

External tools can integrate with the embedded debug server (internal/debugger/server.go):

Endpoint Method Payload / Description
/api/events GET Server-Sent Events (SSE) stream pushing StateSnapshot JSON on every state change
/api/state GET Current StateSnapshot (status, frames, globals, bytecode, watches, output)
/api/source?file=<path> GET Source content for the main script, imported .tin files, or embedded std/* modules
/api/action POST {"action": "continue" | "step_over" | "step_into" | "step_out" | "step_instruction" | "pause" | "restart"}
/api/breakpoint POST {"op": "toggle" | "add" | "remove" | "clear", "file": "...", "line": 10, "condition": "..."}
/api/watch POST {"op": "add" | "remove", "expr": "..."}
/api/eval POST {"expr": "...", "frameIdx": 0} — evaluates a Tinsel expression inside frame frameIdx