LATERALUS

A programming language that spirals outward — from simple ideas to profound compositions.

v2.4.0 1,976 tests passing Python 3.10+ Zero Dependencies

What Is Lateralus?

Lateralus is a proprietary programming language (v2.4.0) created by bad-antics. It combines pipeline-driven data flow, algebraic data types, Hindley-Milner type inference, and built-in scientific/crypto engines into a language built for scientists, security researchers, and software engineers.

It ships two tightly-coupled languages and a full compiler / VM stack:

ExtensionLanguagePurpose
.ltlLateralus ScriptHigh-level: pipelines, ADTs, pattern matching, async/await, generics
.ltasmLateralus AssemblyLow-level register+stack assembly targeting the LTasm VM

Repository Layout

DirectoryWhat Lives Here
lateralus_lang/Core Python implementation — compiler, lexer, parser, IR, type system, VM, codegen, engines, tooling
lateralus_lang/codegen/7 backends: Python, C99, JavaScript, WASM, bytecode, IR, binary
lateralus_lang/vm/Stack-based VM, assembler, disassembler, 102 opcodes
lateralus_lang/errors/Error types, DNA fingerprinting, error bridge
lateralus_lang/markup/LTLML markup parser + HTML/ANSI renderers
stdlib/59 standard library modules written in .ltl
examples/38 example programs (.ltl + .ltasm)
tests/43 test files, 1,976 tests (pytest)
docs/Language spec, tutorial, cookbook, papers, blog — all in .ltlml
bootstrap/Self-hosting compiler sources (Lateralus-in-Lateralus, toward v2.0)
vscode-lateralus/VS Code / VSCodium extension (syntax, LSP, snippets, icons)
lateralus-os/LateralusOS — bare-metal x86_64 OS with GUI desktop
scripts/Build / test / health-check utilities

Compiler Pipeline

Source (.ltl)
    
      Lexer  (lexer.py)          Token stream
    
      Parser (parser.py)         AST  (ast_nodes.py — 106 node types)
    
      SemanticAnalyzer (ir.py)   IRModule (three-address code) + errors
    
    ├──▶ BytecodeGenerator        .ltbc bytecode  VM execution
    ├──▶ PythonTranspiler         .py   (Python 3.10+)
    ├──▶ CTranspiler              .c    (hosted or freestanding C99)
    ├──▶ JSTranspiler             .js   (ES2022+)
    └──▶ WASMTranspiler           .wat  (WebAssembly Text)

Source (.ltasm)
    
      Assembler (two-pass)       .ltbc bytecode  VM execution

The Compiler class in compiler.py orchestrates everything. The Target enum selects: BYTECODE, PYTHON, C, ASM, or CHECK (type-check only).

Key Modules

Lexer — lateralus_lang/lexer.py

Tokenizes .ltl and .ltasm source into a stream of Token objects. 559 lines; token kinds defined in the TK enum.

Parser — lateralus_lang/parser.py

Recursive-descent parser, 1,756 lines. Produces a Program AST node containing imports + body statements.

Expression precedence chain:

pipeline → logical → comparison → bitwise → shift → additive
→ multiplicative → power → unary → postfix → primary

v1.5 additions: _parse_pattern(), _parse_type_match_expr() for match-as-expression.

AST — lateralus_lang/ast_nodes.py

949 lines, 106 node types organized as Stmt and Expr subtrees. Every node carries a Span.

Node (base)
├── Program
├── Module
├── Stmt
│   ├── FnDecl / AsyncFnDecl
│   ├── LetDecl
│   ├── ReturnStmt
│   ├── IfStmt / MatchStmt
│   ├── WhileStmt / ForStmt / LoopStmt
│   ├── TryStmt  (try / recover / ensure)
│   ├── ImportStmt
│   ├── ExprStmt
│   └── BlockStmt
└── Expr
    ├── Literal  (int, float, str, bool, nil)
    ├── Ident, BinOp, UnaryOp
    ├── CallExpr, IndexExpr, FieldExpr
    ├── LambdaExpr, ListExpr, MapExpr
    ├── AwaitExpr, CastExpr
    ├── TypeMatchExpr      (v1.5)
    ├── ResultExpr          (v1.5)
    └── OptionExpr          (v1.5)

v1.5 pattern nodes: WildcardPattern, LiteralPattern, BindingPattern, TypePattern, EnumVariantPattern, TuplePattern, ListPattern, OrPattern.

Type System — lateralus_lang/type_system.py

871 lines. Hindley-Milner inference with Robinson unification.

ComponentDescription
TypeKind enumINT, FLOAT, STR, BOOL, NIL, LIST, MAP, TUPLE, FUNCTION, STRUCT, ENUM, GENERIC, ANY
occurs_check()Prevents infinite recursive types
unify()Robinson unification with 10 cases
substitute()Recursive substitution application
solve()Drains constraint queue, returns error list
infer_pattern()Infers bindings for all 8 pattern kinds

IR — lateralus_lang/ir.py

Three-address intermediate representation. SemanticAnalyzer walks the AST and emits IRInstr objects into an IRModule. Feeds bytecode generation and powers type/error checking.

Codegen Backends — lateralus_lang/codegen/

BackendFileLinesNotes
Bytecodebytecode.py316IR → LTasm; two-pass with back-patching
Pythonpython.py1,457AST → Python 3.10+; reference transpiler
C99c.py1,030Hosted (libc) or freestanding (bare-metal); powers LateralusOS
JavaScriptjavascript.py484AST → ES2022+
WASMwasm.py485IR → WAT format

Virtual Machine — lateralus_lang/vm/

FileDescription
opcodes.py102 opcode enum; registers r0–r15, sp, pc, flags (Z/C/N/O)
assembler.pyTwo-pass .ltasm → bytecode; sections, directives, labels
vm.pyStack-based executor; call frames, error stack, coroutine support
disassembler.pyBytecode → readable assembly; round-trip verified

Built-in Engines

🔬 Science Engine

CODATA constants, RK4 ODE solvers, FFT, statistics, linear systems

⚙️ Math Engine

Arbitrary-precision, complex numbers, polynomials, integration, number theory

🔒 Crypto Engine

SHA-256/512, BLAKE2b, AES-256-GCM, HMAC, PBKDF2, Fernet

🔎 Pattern Engine

Pattern matching engine for expression evaluation

📊 Query Engine

Data query engine for structured data processing

📡 Reactive Engine

Reactive streams and event-driven programming

CLI Commands

All commands are available as lateralus <cmd>, ltlc <cmd>, or python -m lateralus_lang <cmd>.

CommandDescription
run <file.ltl>Execute a program
py <file> -o out.pyTranspile → Python
c <file> -o out.cTranspile → C99 (add --freestanding for bare-metal)
js <file> -o out.jsTranspile → JavaScript (ES2020)
wasm <file> -o out.watCompile → WebAssembly text format
check <file>Type-check only
replInteractive REPL (--enhanced for :save/:doc/:profile)
asm <file.ltasm>Assemble → bytecode
disasm <file.ltlc>Disassemble bytecode binary
ast <file>Dump AST (--json for JSON output)
ir <file>Dump three-address IR
test <file>Run @test functions
bench <file>Benchmark compilation pipeline
profile <file>Profile execution with timing
doc <file.ltlml>Render markup (--html for HTML)
fmt <file>Format code
lint <file>Lint code (21+ rules)
cleanRemove build artifacts
infoToolchain info

Language Features by Version

v1.0 — Genesis Complete
Core lexer/parser/AST, Python transpiler, bytecode VM, basic types (int, float, str, bool, nil), control flow, functions, closures, lambdas, pipelines (|>, |?), try/recover/ensure
v1.1 — Foundations Complete
Structs, enums (tuple/record/valued), type aliases, interfaces, impl blocks, generics <T>, decorators, yield/generators, spawn/concurrency, self, pub
v1.2 — Polyglot Bridge Complete
foreign blocks for Python/JS/R interop, VS Code extension, REPL, .ltasm assembler
v1.3 — Error Architecture Complete
throw, emit/event system, probe/introspection, measure/timing, TryExpr, error DNA fingerprinting
v1.4 — Mathematical Elegance Complete
List comprehensions, ternary, spread, guard/where clauses, |>=, ? propagation, math/crypto/science engines, LTLML markup, binary .ltlc format, 28 stdlib modules
v1.5 — ADT Edition Complete
Result::Ok/Result::Err, Option::Some/Option::None, match-as-expression (8 pattern types + guards), :: scope operator, HM type inference, C99 backend, LateralusOS, 1,158 tests
v2.0 — C Backend & OS Complete
C99 transpilation (hosted + freestanding), enum/trait/impl type system, async/await runtime, LateralusOS bare-metal x86_64 OS, 3 backends
v2.1 — IRC & DAP Complete
IRC chat server, Debug Adapter Protocol server, enhanced error reporting, LateralusOS GUI desktop
v2.2 — Ecosystem Complete
IRC chat server, LateralusOS v0.3 GUI with framebuffer rendering, 22 example programs, 700+ tests, fmt/csv/uuid/hash/base64 stdlib
v2.3 — JS/WASM Backends Complete
JavaScript (ES2020) and WebAssembly backends, Jupyter notebook kernel, 7 backends total, sort/set/event stdlib, 1,769 tests
v2.4 — VM Disassembler Current
VM disassembler (~300 lines, round-trip verified), 4 new CLI subcommands (bench, profile, disasm, clean), enhanced REPL (:save, :doc, :profile), 3 new optimizer passes, 7 new stdlib modules, 1,976 tests
v2.5 — Self-Hosting Bootstrap Planned
Lateralus compiler written in Lateralus; bootstrap from Python implementation

Standard Library — 59 Modules

Located in stdlib/, written entirely in .ltl:

algorithms.ltl

Sorting, searching, graph algorithms

async.ltl

Async/await utilities

collections.ltl

24 collection utilities

core.ltl

Core builtins and helpers

crypto.ltl

Hashing, HMAC, encoding

data.ltl

Data structures

datetime.ltl

Date/time types, formatting, durations

functional.ltl

compose, pipe, curry, memoize

graph.ltl

Graph data structures

http.ltl

HTTP client, Request/Response types

io.ltl

File I/O, paths, prompts

iter.ltl

Lazy iterators, map/filter/zip/chain

json.ltl

JSON parse / stringify

linalg.ltl

Linear algebra

math.ltl

Math functions and constants

matrix.ltl

Matrix operations

network.ltl

Networking utilities

numerics.ltl

Numerical methods, ODE solvers

optimize.ltl

Optimization algorithms

os.ltl

Process, environment, filesystem ops

random.ltl

Random number generation

regex.ltl

Regular expressions, Pattern type

result.ltl

Result/Option monadic operations

science.ltl

Scientific computing

signals.ltl

Signal processing

stats.ltl

Statistics and regression

strings.ltl

19 string functions

testing.ltl

Test framework utilities

time.ltl

Timestamps and durations

fmt.ltl

String formatting

csv.ltl

CSV parse / generate

uuid.ltl

UUID generation

hash.ltl

Hashing utilities

base64.ltl

Base64 encode / decode

sort.ltl

Sorting algorithms

set.ltl

Set data structure

event.ltl

Event system

heap.ltl

Heap / priority queue

deque.ltl

Double-ended queue

trie.ltl

Trie data structure

ini.ltl

INI file parser

lru.ltl

LRU cache

+ 15 more

arena, pool, color, logger, enum_utils, etc.

Testing

43 test files with 1,976 tests, all managed via pytest.

# Full suite
pytest tests/ -v --tb=short

# Specific areas
pytest tests/test_parser.py -v
pytest tests/test_type_system.py -v
pytest tests/test_v15_features.py -v
pytest tests/test_c_backend.py -v

# Health check
python scripts/health_check.py

# Master runner
python scripts/run_all_tests.py --suite all_new

Test File Coverage

Core Pipeline

test_lexer, test_parser, test_compiler, test_full_pipeline

Type System

test_type_system, test_v15_features

Backends

test_c_backend, test_javascript_transpiler

VM & Bytecode

test_vm, test_bytecode_format

Engines

test_math_engine, test_crypto_engine, test_science, test_engines, test_pattern_engine, test_query_engine

Tooling

test_formatter_linter, test_lsp_server, test_debugger, test_profiler, test_cli_extensions

Runtime

test_async_runtime, test_reactive, test_error_engine

Other

test_optimizer, test_source_map, test_notebook, test_markup, test_package_manager, test_v12_features

LateralusOS

A bare-metal operating system written in Lateralus (transpiled to freestanding C99) + x86_64 assembly. Located in lateralus-os/.

User Applications → GUI Desktop → System Services → Shell
→ Kernel (scheduler, IPC, VFS, network) → Memory Manager
→ HAL (interrupts, timers, I/O) → Bootstrap (C + ASM) → Bare Metal
LayerContents
boot/Multiboot2 x86_64 long-mode bootstrap (NASM + C stubs)
kernel/Scheduler, IPC, VFS, cooperative task scheduler, memory manager (kmalloc bump allocator)
hal/PIC, PIT, interrupts, I/O ports
drivers/VGA text (80×25), PS/2 keyboard + mouse, serial port, PC speaker (PIT Ch2, melody queue)
fs/RAM filesystem (64 inodes, pre-populated /home, /etc, /tmp)
shell/ltlsh — 15+ commands (help, uname, uptime, free, cpuid, ls, cat, touch, mkdir, gui…)
gui/Double-buffered 1024×768 framebuffer, window manager, functional terminal (17 commands), animated wallpaper (Fibonacci spirals, stars), Alt+Tab switcher, window open/close/minimize animations, start menu, context menu, desktop icons, system monitor, Catppuccin Mocha theme
services/Mesh agent, crypto, system monitor
Build & Boot: cd lateralus-os && bash build_and_boot.sh --test
Kernel size: ~375 KB  |  ISO: ~13 MB  |  Build: 11-step pipeline, 11 .o files
Phase 3: Functional terminal (17 commands), RAM VFS, PC speaker audio, cooperative task scheduler, animated wallpaper (Fibonacci spirals, twinkling stars), window animations, Alt+Tab window switcher
Requires: nasm, gcc, ld, grub-mkrescue, qemu-system-x86_64

VS Code Extension

Located in vscode-lateralus/. Supports VS Code and VSCodium.

FeatureDetails
Syntax highlighting.ltl, .ltasm, .ltlml, .ltlcfg, .ltlnb
LSP clientSpawns lateralus_lang.lsp_server — diagnostics, completions, hover
Snippets17 snippets for v1.5 constructs (Result, Option, match, pipelines)
Icons6 custom SVG file icons for all Lateralus file types
# Install
make vscode-install

# Or use the workspace task:
# "Install Lateralus VS Code Extension"

Development Setup

# Requirements: Python 3.10+
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

# Verify installation
lateralus --version        # → LATERALUS 2.4.0
lateralus info             # Toolchain details

# Run all tests
pytest tests/ -v --tb=short

# Run a program
lateralus run examples/hello.ltl

# Interactive REPL
lateralus repl

# LateralusOS (additional requirements)
# nasm, gcc, ld, grub-mkrescue, xorriso, qemu-system-x86_64

Make Targets

TargetWhat It Does
make installpip install -e .
make testFull pytest suite
make test-c-backendC backend tests only
make lintLint stdlib with Lateralus linter
make formatFormat stdlib with Lateralus formatter
make checkType-check all examples
make docsBuild .ltlml → HTML
make vscode-installInstall VS Code extension
make replLaunch interactive REPL
make benchRun benchmarks
make healthRun health check script
make cleanRemove __pycache__, .pyc, build artifacts

Public API

from lateralus_lang import (
    # Compiler pipeline
    Compiler, CompileResult, Target,
    compile_file, compile_source,
    run_file, run_source,

    # Lexer / Parser
    lex, Token, TK, LexError,
    parse, ParseError,

    # Intermediate Representation
    analyze, IRModule,

    # Virtual Machine
    VM, Bytecode, assemble,

    # Code generation
    generate_bytecode, transpile_to_python,

    # REPL
    start_repl, REPL,

    # Error handling
    LTLError, ErrorContext, ErrorReporter, Severity,
    get_bridge, ErrorBridge,
)

Roadmap

VersionThemeStatus
v1.0 – v1.5Genesis → ADT Edition✅ Complete
v2.0 – v2.3C Backend, JS/WASM, IRC, Jupyter, OS✅ Complete
v2.4VM Disassembler, Enhanced REPL, Optimizer🟢 Current
v2.5Self-Hosting Bootstrap◯ Planned

Rules of Engagement

  1. No version ships with failing tests. Ever.
  2. Every feature gets at least 3 tests before merge.
  3. Backward compatibility is sacred — old .ltl files must always work.
  4. The Python transpiler is the reference implementation until v2.0.
  5. Versions follow semver within the 1.x series.