Skip to content

AtomiJD/jdBasic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

274 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jdBasic — A Persistent Experimental BASIC Environment

jdBasic is a modern BASIC interpreter built around a custom bytecode virtual machine with APL-style array programming, hot-reloadable code, a persistent REPL workspace, and first-class graphics, GUI, audio, networking, and AI integration.

It combines the immediacy of classic BASIC with powerful built-in capabilities and a "stay in the session" philosophy — no constant restarts, no rebuild loops, just think and run.

Reduce friction between thinking and running code.

🎥 Train jdBasic is on YouTube — 14 video lessons covering everything from PRINT to native compilation, all auto-generated and voiced by jdBasic itself. Watch the playlist →

You can:

  • explore ideas in a powerful interactive REPL
  • save and restore entire sessions with SAVEWS / LOADWS
  • write vectorized data pipelines using APL-inspired array operators
  • prototype graphics, games, and tools with SDL3 + Dear ImGui
  • talk to local LLMs (llama.cpp) and run ONNX models inline
  • build automation tools, REST clients, and serial-device controllers
  • extend the language with native modules

Try jdBasic in your browser

jdbasic.org/live — no installation required.


Watch the lessons

The Train jdBasic YouTube series walks through the language from "Hello, World" to native compilation — 14 episodes, 5–10 minutes each, with auto-generated chapters and code-on-screen as it happens.

▶️ Full playlist on YouTube

# Lesson Topic
01 Hello jdBasic PRINT, DIM, basic types
02 If and For IF/ELSE, FOR/NEXT, FizzBuzz
03 Arrays Vector ops, broadcasting, reductions
04 Strings Slice, search, SPLIT
05 Functions and SUBs FUNC, SUB, recursion
06 Maps Key-value data
07 INPUT and DO Loops User-driven programs
08 File I/O TXTWRITER, TXTREADER$
09 Graphics SCREEN, shapes, colours
10 Modules EXPORT, IMPORT, code reuse
11 REPL Workflow PRETTY, LINT, SAVEWS
12 Higher-Order Functions SELECT, FILTER, REDUCE, lambdas
13 HTTP and JSON Talk to the web
14 Native Compilation Compile to .exe with jdbasic -c

The entire production pipeline — voice synthesis, screen recording, FFmpeg compositing, even the YouTube uploads — is itself a jdBasic program. See jdb/tv/ if you want to fork the rig.


What's inside (v2)

This is the v2 rewrite. Compared to the original tree-walking interpreter, jdBasic now ships with:

  • A bytecode compiler + virtual machine with inline caches, opcode fusion, and a fast intrusive‑refcount value type
  • APL-style vectorizationSIN, COS, +, *, scatter/gather, IOTA, REDUCE, SCAN, FILTER, SELECT all operate over arrays in a single op
  • SDL3 graphics with letterboxed logical presentation, TOGGLE_FULLSCREEN, and a streaming-texture batch plotter (GFX.PLOT_POINTS_TEX) that can push 70k coloured pixels per frame at 30+ FPS from pure BASIC
  • Dear ImGui integration for instant-mode tools and debuggers
  • llama.cpp for local LLM inference (CPU + optional CUDA)
  • ONNX Runtime for classical ML inference
  • HTTP/HTTPS client (OpenSSL), COM automation (Windows), Serial I/O for embedded
  • Reactive variables (-> operator) with automatic dependency propagation
  • Hot reload of source files without losing the workspace
  • DAP debug adapter so you can step through BASIC code from VS Code
  • A persistent REPL workspace that survives restarts via SAVEWS/LOADWS
  • An MCP server (jdbasic --mcp) that exposes the persistent VM to LLM agents like Claude Code, Cursor, or Cline — see doc/MCP.md

The original v1 codebase is preserved on the legacy-v1 branch and the v1-legacy tag for archival and bugfixes.


Language tour

1. Reactive variables

DIM BaseValue AS INTEGER = 10
DIM Multiplier AS INTEGER = 5

DIM Result AS REACT INTEGER
Result -> BaseValue * Multiplier

PRINT Result    ' 50

Multiplier = 10
PRINT Result    ' 100  — updated automatically

2. Vectorized array math (APL-style)

' Generate 10 numbers, keep > 5, multiply by 10
result = IOTA(10) |> FILTER(LAMBDA x -> x > 5, ?) |> SELECT(LAMBDA v -> v * 10, ?)
PRINT result    ' [60 70 80 90 100]
' All trig is vectorized — one call processes the whole array
DIM angles = IOTA(360) * (PI / 180)
DIM sines  = SIN(angles)
DIM cosines = COS(angles)

3. Immediate-mode GUI

SCREEN 800, 600, "My Tool"
DIM BgColor[4] = [0.2, 0.3, 0.3, 1.0]

DO
    CLS
    IF GUI.BEGIN("Control Panel", 50, 50, 300, 200) THEN
        GUI.TEXT "Welcome to jdBasic GUI"
        GUI.SEPARATOR()
        IF GUI.BUTTON("Click Me") THEN
            PRINT "Clicked at " + TIME$
        ENDIF
        GUI.COLOR("Background", BgColor)
    ENDIF
    GUI.END()
    SCREENFLIP
    SLEEP 16
LOOP UNTIL INKEY$() = "q"

4. High-performance graphics

The jdb/universe.jdb demo plots 70 000 coloured pixels per frame at 30+ FPS from pure BASIC, by combining vectorized inner loops with a single GPU upload via GFX.PLOT_POINTS_TEX.

build\jdBasic.exe jdb\universe.jdb

5. APL-style pipelines

Vectorized arithmetic + bitops let you push real workloads — physics, cellular automata, SAT, DSP — through whole-array operations instead of per-cell loops. See doc/APL_pipeline.md for a tutorial walking from "tight FOR loops" to "one line per update step" using the demos under bench/ and jdb/. Highlights:

  • jdb/life_demo.jdb — live Conway 200 × 150 at 60 FPS via an ONNX 3×3-conv backend
  • jdb/boids_apl.jdb — 5 000 particles at ~630 FPS, all-vector update
  • jdb/synth_apl.jdb — additive synthesis, 4 096 samples/frame in five vector ops
  • bench/life_bench.jdb / bench/mandelbrot_bench.jdb — when APL form wins (Conway, 4–13×) and when it loses (Mandelbrot, ~4×)

Numbers from the latest run: bench/Results.md.


Getting started

Run it

Build it from source

  • See doc/BUILD.md for the full build guide (prerequisites, third-party libraries, feature flags, packaging)

Learn the language

Tooling


Project layout

src/        — interpreter source (lexer, parser, compiler, VM, runtime modules)
jdb/        — example .jdb programs
doc/        — language reference and build guide
tests/      — regression suite (comprehensive_test.jdb + crash_test.jdb)
fonts/      — bundled TTF fonts
sfx/        — bundled sound effects
resources/  — icon, manifest, version info
syntaxes/   — editor syntax highlighting files
tools/      — auxiliary scripts
vscode_extension/ — VS Code extension (.vsix) and install instructions
libs/       — third-party libraries (not in git, see doc/BUILD.md)
build/      — compile output (not in git)
dist/       — packaged distribution (not in git)

Contributing

Contributions, bug reports, and feedback are welcome! Please make sure that the regression suite still passes after your changes — four test files cover the language, the native compiler, and the APL pipeline:

build\jdBasic.exe tests\comprehensive_test.jdb
build\jdBasic.exe tests\native_test.jdb
build\jdBasic.exe tests\test_apl_complete.jdb
build\jdBasic.exe tests\test_apl_pipelines.jdb

All four should report 0 failed (1139 tests total at the time of writing). For changes that touch the LLVM codegen, run each suite again through the compiler — build\jdBasic.exe -c tests\<suite>.jdb && tests\<suite>.exe — so both the interpreter and native paths stay green.


License

See LICENSE.txt.