Skip to content

pr0h0/bpl3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1,852 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BPL (Best Programming Language) v3

License

BPL is a statically-typed, compiled programming language that transpiles to LLVM IR. It combines the performance and control of systems languages with modern language features, making it ideal for performance-critical applications, systems programming, and educational purposes.

import [IO] from "std/io.bpl";

struct Point {
    x: int,
    y: int
}

frame main() ret int {
    local p: Point;
    p.x = 10;
    p.y = 20;
    IO.log("Hello from BPL!");
    return 0;
}

✨ Features

πŸš€ Performance First

  • LLVM Backend: Leverages LLVM's world-class optimization and code generation
  • Zero-Cost Abstractions: High-level features without runtime overhead
  • Manual Memory Management: Direct control over allocations for predictable performance
  • Native Compilation: Produces optimized machine code for your platform

πŸ”’ Type Safety

  • Strong Static Typing: Catch errors at compile-time before they become runtime bugs
  • Generics: Write reusable, type-safe code with full monomorphization
  • No Null Dereferences: Explicit null handling patterns
  • Type Inference: Less verbose where it matters, explicit where it helps

πŸ—οΈ Modern Language Features

  • Object-Oriented: Structs with methods, single and multiple inheritance
  • Module System: Organize code with imports and exports
  • Exception Handling: Try/catch blocks for robust error management
  • Pattern Matching: Type-safe conditional logic
  • Process execution: Execute shell commands, check status, and capture output with automatic injection protection
  • String Interpolation: Embed expressions in strings with `Hello ${name}`
  • Tuples: Multi-value types for clean APIs
  • Function Pointers: First-class functions

πŸ› οΈ Developer Experience

  • Clear Error Messages: Helpful compiler diagnostics with exact source-span underlines
  • Machine-Readable Diagnostics: JSON output for check, lint, and doctor with stable source ranges, source previews, and underline pointers for CI and editors
  • Enhanced Runtime Errors: Beautiful formatted error boxes with stack traces for null access, bounds checking, division by zero, and signed integer division overflow
  • Built-in Formatter: Automatic code formatting and format --check for CI gates
  • Watch Mode: Automatic recompilation on file changes for rapid development
  • Package Manager: Easy dependency management with bpl install
  • Cross-Platform: Compile for Linux, macOS, Windows, ARM, and more
  • VS Code Extension: Full language server with IntelliSense, go-to-definition, hover tooltips, clickable imports, and smart stdlib path completions
  • Incremental Compilation: Fast rebuilds with module caching

πŸ“¦ Installation

Build from Source

git clone https://github.com/pr0h0/bpl3.git
cd bpl3
./init.sh
bpl --version

Prerequisites

You'll need:

  1. Clang/LLVM (13+) - for compiling LLVM IR to native code
  2. Bun - for running the compiler

Linux (Ubuntu/Debian):

sudo apt-get install clang llvm lld
curl -fsSL https://bun.sh/install | bash

macOS:

brew install llvm lld
curl -fsSL https://bun.sh/install | bash

Windows: Download LLVM from releases.llvm.org or use WSL.

Verify Installation

bpl --version
echo 'extern printf(fmt: string, ...); frame main() ret int { printf("It works!\n"); return 0; }' > test.bpl
bpl run test.bpl

For detailed installation instructions, see the Installation Guide.

Release Verification

Before publishing a local build or npm tarball, run:

bun run release:check
bun run release:manifest

The release check builds and tests the standalone compiler, packed CLI, runtime artifacts, wasm runtime shims, shell completions, documentation, example configs, and VS Code extension. The manifest command writes dist/release-manifest.json with SHA-256 checksums for shipped artifacts. Release manifest usage errors, such as Unknown release manifest option: --unknown, Missing value for --out, or Missing value for --repo-root, exit with status 2 before running release manifest or npm pack work. Use bun tools/release_manifest.ts --help to print the release manifest helper usage without writing artifacts.

Helper CLI inline value forms are supported for automation that prefers single-token options:

bun run ci:triage -- --json --jobs-json=jobs.json --run=<run-id> --repo=owner/repo
bun tools/release_manifest.ts --out=dist/release-manifest.json --repo-root=.

Malformed inline values remain status 2 usage errors before network or release work starts. ci:triage rejects --json=true and --jobs-json= before any GitHub API request; release_manifest rejects --pack-npm=true and --out= before writing manifests or running npm pack. test:ci rejects --json=true, --list=true, --dry-run=true, and --help=true before planning or running the CI-safe suite. Packed test:ci --list and test:ci --json planning does not require a source-checkout tests/ directory. release:cli-registry rejects --check=true and --write=true while keeping usage diagnostics on stderr. Focus those contracts with:

bun test tests/CiTriage.test.ts -t "inline option values|malformed inline option values"
bun test tests/ReleaseMetadata.test.ts -t "release manifest CLI reports usage errors|release manifest CLI accepts inline option values"
bun test tests/TestCiRunner.test.ts
bun test tests/JsonErrorCodeLists.test.ts

Packed npm helper scripts supported from installed packages:

npm run fuzz:repro -- --help
npm run fuzz -- --help
npm run fuzz:replay -- --help
npm run fuzz:promote -- --help
npm run ci:triage -- --help
npm run ci:triage -- --json --jobs-json jobs.json <run-id>

The packed fuzz, fuzz:replay, and fuzz:promote scripts validate usage in installed packages before delegating to source-tree fuzz helpers when a checkout is present. Fuzz helper usage diagnostics are status 2 failures before artifact discovery, campaign startup, replay, promotion, or source-checkout delegation. bun run fuzz:repro rejects flag values such as --json=true, empty artifact options such as --input=, and mixed positional and --input artifact paths. bun run fuzz rejects malformed boolean values such as --minimize maybe and empty required values such as --iterations=. Focus these contracts with:

bun test tests/FuzzArtifactRepro.test.ts -t "malformed CLI option values"
bun test tests/CompilerFuzzRunner.test.ts -t "fuzz package wrappers reject malformed option values"
bun test tests/ReleaseHelperSmoke.test.ts -t "exercises packed helper usage paths"

The package intentionally excludes source-only files such as playground/examples/70-browser-wasm-showcase.json, tests/, fuzz/, and broad compiler sources. The playground browser wasm helper assets are local playground files, not npm package payload: playground/frontend/wasmHostAdapter.js and playground/frontend/browserWasmRuntime.js. The playground backend helper modules used by the local web server are also source-only: playground/backend/processRunner.ts, playground/backend/nativeExecution.ts, and playground/backend/wasmToolchain.ts, and playground/backend/runtimeFiles.ts. The narrow exception is compiler/common/PathSafety.ts, which is shipped because packed helper scripts share its symlink-safe path validation. Release metadata checks derive the helper inventory from package.json scripts so new bun tools/*.ts npm scripts must be shipped or fail with the referencing script name. Packed ci:triage smoke also validates timeout repro contracts for package tooling, package IR verification, and object symbol parsing:

BPL_PACKAGE_TOOL_TIMEOUT_MS=300000 bun test tests/PackageManager.test.ts
BPL_PACKAGE_IR_VERIFY_TIMEOUT_MS=30000 bun test tests/CLI.test.ts -t "package IR verification"
BPL_OBJECT_SYMBOL_TIMEOUT_MS=30000 bun test tests/ObjectFileParser.test.ts

It also validates representative JSON-code mapping repros from the packed helper path, including package archive validation and wasm linker diagnostics.

Packed ci:triage smoke also validates sanitizer runtime repro contracts:

bun run test:sanitizers
bun test tests/CompilerSanitizerRuntime.test.ts

Packed package/import diagnostic smoke validates that the installed npm CLI keeps package import JSON diagnostics machine-readable, including stable diagnostic codes such as BPL_PACKAGE_MANIFEST_MISSING. Reproduce that release slice locally with:

bun test tests/ReleaseMetadata.test.ts -t "packed package import diagnostic codes"
bun run release:smoke

πŸš€ Quick Start

Hello World

Create hello.bpl:

extern printf(fmt: string, ...);

frame main() ret int {
    printf("Hello, World!\n");
    return 0;
}

Compile and run:

bpl run hello.bpl

Or just compile:

bpl hello.bpl -o hello

Compile code without a file

You can compile snippets or piped input directly:

  • Compile a snippet from the command line:

    bpl -e 'frame main() ret int { return 0; }'
  • Compile from stdin (helpful with cat/pipes):

    cat examples/hello-world/main.bpl | bpl --stdin

--emit tokens|ast|formatted|llvm works with both -e and --stdin; diagnostics show <eval>/<stdin> in locations.

More Examples

Variables and Types:

extern printf(fmt: string, ...);

frame main() ret int {
    local x: int = 42;
    local name: string = "BPL";
    local pi: float = 3.14159;

    printf("%s: x = %d, pi = %f\n", name, x, pi);
    return 0;
}

Functions:

extern printf(fmt: string, ...);

frame add(a: int, b: int) ret int {
    return a + b;
}

frame main() ret int {
    local result: int = add(5, 3);
    printf("5 + 3 = %d\n", result);
    return 0;
}

Structs and Methods:

extern printf(fmt: string, ...);

struct Point {
    x: int,
    y: int,

    frame new(x: int, y: int) ret Point {
        local p: Point;
        p.x = x;
        p.y = y;
        return p;
    }

    frame print(this: Point) ret void {
        printf("Point(%d, %d)\n", this.x, this.y);
    }
}

frame main() ret int {
    local p: Point = Point.new(10, 20);
    p.print();
    return 0;
}

Generics:

extern printf(fmt: string, ...);

struct Box<T> {
    value: T,

    frame new(val: T) ret Box<T> {
        local b: Box<T>;
        b.value = val;
        return b;
    }
}

frame main() ret int {
    local intBox: Box<int> = Box<int>.new(42);
    local floatBox: Box<float> = Box<float>.new(3.14);

    printf("Int: %d, Float: %f\n", intBox.value, floatBox.value);
    return 0;
}

Using Standard Library:

import [Array] from "std/array.bpl";
import [IO] from "std/io.bpl";

frame main() ret int {
    local numbers: Array<int> = Array<int>.new(5);
    numbers.push(10);
    numbers.push(20);
    numbers.push(30);

    IO.log("Vector contents:");
    local i: int = 0;
    loop (i < numbers.len()) {
        IO.printIntLn(numbers.get(i));
        i = i + 1;
    }

    numbers.destroy();
    return 0;
}

For more examples, check out the examples directory or the Quick Start Guide.

πŸ“– Documentation

Comprehensive documentation is available in the docs/ directory:

Getting Started

Core Concepts

Advanced Topics

Reference

πŸ’» Command Line Interface

Quick Reference

# Compile and run a program
bpl run main.bpl

# Development mode with watch and auto-run
bpl dev main.bpl

# Build an executable
bpl build main.bpl -o myprogram

# Type check without code generation (fast)
bpl check main.bpl

# Create a new project
bpl new my-project

# Format code
bpl format main.bpl -w

# Clean build artifacts
bpl clean

Core Commands

bpl run <file> [args...]

Compile and execute a BPL program in one step:

# Run a program
bpl run main.bpl

# Pass arguments to the program
bpl run main.bpl arg1 arg2

# Run with optimization
bpl run main.bpl -O 2

# Run with timing statistics
bpl run main.bpl --time

bpl dev <file> [args...]

Development mode with automatic recompilation and execution:

# Watch and run on changes
bpl dev main.bpl

# Clear screen on each recompile
bpl dev main.bpl --clear

# Watch but only compile (don't run)
bpl dev main.bpl --no-run

bpl build <file>

Explicitly compile a program:

# Basic compilation (generates LLVM IR)
bpl build main.bpl

# Specify output filename
bpl build main.bpl -o myprogram

# Verbose output
bpl build main.bpl -v

# Enable incremental compilation
bpl build main.bpl --cache

bpl check <files...>

Fast type checking without code generation:

# Check a single file
bpl check main.bpl

# Check multiple files
bpl check src/*.bpl

# JSON output for tooling
bpl check main.bpl --json

bpl new <name>

Create a new BPL project with standard structure:

# Create new project
bpl new my-project
cd my-project
bpl run main.bpl

This creates:

  • bpl.json - Package manifest
  • main.bpl - Entry point with Hello World
  • lib/ - Local library directory
  • README.md - Project documentation
  • .gitignore - Git ignore rules

bpl clean

Remove build artifacts. In git repositories, tracked files are preserved even when they live in build/, dist/, or .bpl-cache/. --json reports each planned deletion as a file, directory, or symlink.

# Remove all build artifacts
bpl clean

# Dry run (show what would be deleted)
bpl clean --dry-run

# Verbose output
bpl clean -v

Compilation Options

Global Flags

These work with any command:

-v, --verbose          Enable verbose output
-q, --quiet            Suppress non-error output
-O <level>             Optimization level: 0, 1, 2, or 3
--debug, -d            Generate DWARF debug information
--time                 Show compilation time statistics
--cache                Enable incremental compilation
--color/--no-color     Force/disable colored output
--json                 Output in JSON format (for check command)

Emit Options

Control what the compiler outputs:

# Emit LLVM IR (default)
bpl build main.bpl --emit llvm

# Emit AST as JSON
bpl build main.bpl --emit ast

# Emit tokens
bpl build main.bpl --emit tokens

# Format source code
bpl format main.bpl

Cross-Compilation

Compile for different platforms and architectures:

# Cross-compile for ARM64 Linux
bpl build main.bpl --target aarch64-unknown-linux-gnu --march=armv8-a

# Cross-compile for Windows x64
bpl build main.bpl --target x86_64-pc-windows-gnu

# Cross-compile for macOS ARM64
bpl build main.bpl --target arm64-apple-darwin

# Specify sysroot for cross-compilation
bpl build main.bpl --target aarch64-unknown-linux-gnu --sysroot /opt/sysroots/aarch64

# Pass additional flags to clang
bpl build main.bpl --clang-flag=-O3 --clang-flag=-static

Supported target triples:

  • x86_64-pc-linux-gnu (Linux x64)
  • aarch64-unknown-linux-gnu (Linux ARM64)
  • arm64-apple-darwin (macOS ARM64)
  • x86_64-apple-darwin (macOS x64)
  • x86_64-pc-windows-gnu (Windows x64)

Code Formatting

# Format and print to stdout
bpl format main.bpl

# Format and write back to file
bpl format -w main.bpl

# Format multiple files
bpl format -w src/**/*.bpl

Package Management

# Initialize a new project
bpl init my-project

# Scaffold a new app project with machine-readable output
bpl new my-project --no-git --json

# Create a package tarball
bpl pack

# Install a package
bpl install package-name-1.0.0.tgz

# Install all dependencies from bpl.json
bpl install

# List installed packages
bpl list

# Uninstall a package
bpl uninstall package-name

See the Package Management Guide for details.

Shell Completion

BPL provides command-line completion for Bash and Zsh shells:

# Generate Bash completion script
bpl completion bash > ~/.local/share/bash-completion/completions/bpl

# Or add to your ~/.bashrc:
source <(bpl completion bash)

# Generate Zsh completion script
mkdir -p ~/.local/share/zsh/completions
bpl completion zsh > ~/.local/share/zsh/completions/_bpl

# Add to ~/.zshrc:
fpath=(~/.local/share/zsh/completions $fpath)

# Reload completions
rm -f ~/.zcompdump; compinit

After installation, you can use Tab to complete commands, flags, and file paths!

🌟 Language Highlights

Type System

BPL features a rich, safe type system:

  • Primitive types: int, float, bool, char
  • Composite types: pointers, arrays, tuples
  • User-defined types: structs with fields and methods
  • Generics: Type parameters for functions and structs
  • Type aliases: Create meaningful names for complex types
type UserID = int;
type Callback = Func<void>(int);
type Point3D = (float, float, float);

struct Result<T, E> {
    ok: T,
    err: E,
    is_ok: bool
}

Memory Management

Manual memory management with safety helpers:

extern malloc(size: i64) ret *void;
extern free(ptr: *void);

frame main() ret int {
    # Allocate
    local ptr: *int = cast<*int>(malloc(sizeof(int) * 10));

    # Use
    ptr[0] = 42;

    # Free
    free(cast<*void>(ptr));

    return 0;
}

Inheritance

Single and multiple inheritance supported:

struct Animal {
    name: string,
    frame speak() { printf("...\n"); }
}

struct Dog : Animal {
    breed: string,
    frame speak() { printf("Woof!\n"); }  # Override
}

struct Bird : Animal {
    wingspan: float
}

# Multiple inheritance
struct Platypus : Animal, Swimmer {
    # ...
}

Module System

Organize code across files:

# math.bpl
export add, multiply;

frame add(a: int, b: int) ret int {
    return a + b;
}

frame multiply(a: int, b: int) ret int {
    return a * b;
}
# main.bpl
import add, multiply from "./math.bpl";

frame main() ret int {
    local sum: int = add(5, 3);
    local product: int = multiply(5, 3);
    return 0;
}

πŸ”§ Standard Library

BPL includes a comprehensive standard library:

Module Description Example
std/io.bpl Input/output operations IO.log("Hello")
std/string.bpl String manipulation String.new("text")
std/array.bpl Dynamic arrays Array<int>.new(10)
std/map.bpl Hash maps Map<K, V>.new()
std/set.bpl Hash sets Set<T>.new()
std/fs.bpl File system ops FS.readFile(path)
std/math.bpl Math functions Math.sqrt(x)
std/time.bpl Time operations Time.now()
std/json.bpl JSON parsing JSON.parse<T>(str)
std/option.bpl Optional values Option<T>.Some(val)
std/result.bpl Error handling Result<T, E>

std/ and std\ imports are reserved for the configured standard library and do not fall back to packages or extra search paths when a normalized standard library module is missing.

See the Standard Library documentation for complete API reference.

πŸ“ Project Structure

bpl3/
β”œβ”€β”€ compiler/           # Compiler implementation
β”‚   β”œβ”€β”€ frontend/       # Lexer (Peggy) and parser
β”‚   β”œβ”€β”€ middleend/      # Type checker, module resolver, linker
β”‚   β”œβ”€β”€ backend/        # LLVM IR code generation
β”‚   β”‚   └── codegen/    # Generators for expressions, types, etc.
β”‚   β”œβ”€β”€ formatter/      # Code formatter
β”‚   β”œβ”€β”€ linter/         # Code linting
β”‚   β”œβ”€β”€ docs/           # Documentation generator
β”‚   └── common/         # Shared utilities
β”‚       β”œβ”€β”€ AST.ts      # AST definitions
β”‚       β”œβ”€β”€ CompilerError.ts # Error handling
β”‚       β”œβ”€β”€ Config.ts   # Centralized configuration
β”‚       β”œβ”€β”€ Logger.ts   # Structured logging
β”‚       └── ...         # Path resolution, source management
β”œβ”€β”€ cli/                # Command-line interface
β”‚   β”œβ”€β”€ index.ts        # CLI entry point
β”‚   β”œβ”€β”€ commands/       # Subcommand handlers
β”‚   └── completions/    # Shell completions
β”œβ”€β”€ docs/               # Comprehensive documentation
β”‚   β”œβ”€β”€ 01-introduction.md
β”‚   β”œβ”€β”€ 02-installation.md
β”‚   β”œβ”€β”€ 03-quick-start.md
β”‚   └── ...             # 70+ documentation files
β”œβ”€β”€ examples/           # 450+ examples and regression programs
β”‚   β”œβ”€β”€ hello-world/
β”‚   β”œβ”€β”€ fibonacci/
β”‚   β”œβ”€β”€ generics/
β”‚   β”œβ”€β”€ stdlib_*/       # Standard library examples
β”‚   └── ...
β”œβ”€β”€ grammar/            # PEG grammar definitions
β”‚   └── bpl.peggy       # Language grammar
β”œβ”€β”€ lib/                # Standard library
β”‚   β”œβ”€β”€ io.bpl          # Input/output
β”‚   β”œβ”€β”€ array.bpl       # Dynamic arrays
β”‚   β”œβ”€β”€ map.bpl         # Hash maps
β”‚   β”œβ”€β”€ string.bpl      # String utilities
β”‚   └── ...             # 50+ stdlib modules
β”œβ”€β”€ tests/              # Comprehensive test suite
β”‚   β”œβ”€β”€ Integration.test.ts
β”‚   β”œβ”€β”€ Parser.test.ts
β”‚   └── ...
β”œβ”€β”€ benchmark/          # Performance benchmarks
β”œβ”€β”€ vscode-ext/         # VS Code extension
β”œβ”€β”€ playground/         # Web playground (optional)
β”œβ”€β”€ index.ts            # Main entry point
β”œβ”€β”€ LANGUAGE_SPEC.md    # Language specification
└── README.md           # This file

πŸ§ͺ Examples

The examples/ directory contains 450+ working examples and regression programs demonstrating language features and compiler edge cases:

Beginner Examples

  • hello-world/ - Your first program
  • assignment_variations/ - Variable declarations and assignment forms
  • float_operations/ - Floating-point arithmetic
  • control_flow_if_complex/ - Conditionals
  • loops/ - Loop constructs

Intermediate Examples

  • func_nested_calls/ - Function definitions and calls
  • structs/ - Custom data types
  • arrays/ - Array operations
  • pointers/ - Pointer manipulation
  • stdlib_string_extended/ - String handling

Advanced Examples

  • generics/ - Generic programming
  • generics_advanced/ - Complex generics
  • objects_inheritance/ - OOP patterns
  • multi_inheritance/ - Multiple inheritance
  • error_handling/ - Exception handling

Standard Library Examples

  • stdlib_demo/ - I/O, arrays, strings, and stdlib basics
  • stdlib_vec/ - Dynamic arrays
  • stdlib_map_set/ - Hash maps and sets
  • stdlib_json/ - JSON parsing
  • stdlib_fs/ - File system
  • stdlib_time/ - Time operations

Complete Applications

  • fibonacci/ - Fibonacci sequence
  • collatz/ - Collatz conjecture
  • recursive_algorithms/ - Recursion examples

Each example includes:

  • Source code (.bpl files)
  • Expected output (in test configurations)
  • Build and test scripts

Run any example:

cd examples/fibonacci
bpl run main.bpl

πŸ§‘β€πŸ’» Development

Work Tracking

Active BPL implementation work is tracked on the project-scoped BPL Agent Board. Use the board as the source of truth for task ownership, acceptance criteria, progress notes, review status, and time tracking. Keep repository artifacts in sync with the board: user-visible behavior changes should update CHANGELOG.md, docs should change with documented behavior, and completed work should include the relevant test or verification output in the board summary.

Do not commit Agent Board credentials, API keys, local environment files, or private endpoint details. Board updates should describe the work and evidence, not secrets.

Running Tests

# Run the default test suite
bun run test

# Run the CI-safe broad suite. This includes integration, playground, VS Code
# extension tests, and a generated CLI registry shim check, but leaves
# correctness corpora, long fuzz, sanitizer runtime, and full release smoke
# suites to dedicated scripts.
bun run test:ci
# Inspect the typed CI-safe runner plan without running it.
bun tools/test_ci.ts --list
bun tools/test_ci.ts --dry-run
bun tools/test_ci.ts --json
bun tools/test_ci.ts --help
# Unknown test_ci options and malformed flag values such as --json=true exit
# with status 2 on stderr while stdout stays empty. Packed --list/--json
# planning works even when the installed package has no tests/ directory.
# CI-safe unit discovery includes tests/CiTriage.test.ts, including offline
# jobs-json diagnostics. Focus that path directly when needed:
bun test tests/CiTriage.test.ts -t "unreadable and malformed jobs-json"
# Run the generated packed CLI registry shim check directly.
bun run release:cli-registry
bun tools/cli_json_registry_shim.ts --help
bun tools/cli_json_registry_shim.ts --write
# Malformed registry-shim flag values such as --check=true and --write=true
# exit with status 2 before checking or writing generated files.
# Limit integration/example concurrency. BPL_INTEGRATION_JOBS must be a
# positive integer; malformed values are ignored with a warning and the
# auto-detected integration job count is used.
BPL_INTEGRATION_JOBS=4 bun run test:ci
# Check the integration runner environment contract directly.
bun test tests/IntegrationRunner.test.ts

# Build, pack, install, and smoke-test the release package. This also discovers
# package scripts that call tools/*.ts and verifies those helper files are in the
# packed npm tarball.
bun run release:smoke

# Run the focused packed-helper sweep without the full release package smoke.
bun test tests/ReleaseHelperSmoke.test.ts

# Summarize a GitHub Actions run and print local repro commands for failed steps.
bun run ci:triage -- https://github.com/pr0h0/bpl3/actions/runs/<run-id>
# Accepted locators are a numeric run id, a run URL, or a job URL.
bun run ci:triage -- <run-id>
bun run ci:triage -- https://github.com/pr0h0/bpl3/actions/runs/<run-id>/job/<job-id>
# Malformed run ids, malformed URLs, non-GitHub URLs, non-actions URLs, and
# invalid job ids fail as usage errors before any GitHub API request.
# For non-default repositories, --repo must be owner/name. Invalid values fail
# as usage errors before any GitHub API request.
# If a failed job prints "No focused local repro command matched this job",
# inspect the failed step logs and add a ci:triage mapping when the failure
# pattern is recurring.
# Print versioned JSON from a saved GitHub jobs API response without network.
bun run ci:triage -- --json --jobs-json jobs.json <run-id>
# Missing, malformed, or wrong-shape --jobs-json fixtures fail before any
# GitHub API request and name the fixture path in the usage error.
# Print CI triage usage without making a GitHub API request.
bun run ci:triage -- --help
# Wasm/toolchain failures include required-linker mode and doctor diagnostics.
bun index.ts doctor --json

# Run only the VS Code extension tests
bun run test:vscode-ext

# Run parser/typechecker/codegen tests that are safe on Windows runners.
# This validates documented target triples without native runtime execution.
bun run test:codegen-cross-platform

# Run compiler correctness and deterministic fuzz regression coverage
bun run test:correctness

# Run standalone/hosted WebAssembly runtime and toolchain contract coverage
bun run test:wasm
# CI sets BPL_REQUIRE_WASM_LD=1 so this fails instead of skipping when wasm-ld is missing.
BPL_REQUIRE_WASM_LD=1 bun run test:wasm

# Start the playground. The Run Wasm button compiles hosted wasm and executes it
# in the browser with JavaScript host imports.
cd playground && bun run start

# Run sanitizer-backed runtime checks. CI installs compiler-rt so this runs
# safe programs and checked failure paths under ASan/UBSan; local toolchains
# without sanitizer runtimes are detected.
bpl doctor sanitizer --json
bun run test:sanitizers
SANITIZER_RUNTIME_TEST_TIMEOUT_MS=30000 bun test tests/CompilerSanitizerRuntime.test.ts

# Run a short deterministic O0/O3 differential fuzz campaign. Differential
# inputs include successful programs and checked BPL runtime failures.
bun run fuzz:differential

# Validate saved active fuzz failures under tests/fuzz-failure-artifacts
bun run fuzz:validate-artifacts

# Print local replay/minimize/promote commands for downloaded scheduled fuzz artifacts
bun run fuzz:repro -- fuzz/crashes

# Save minimized fuzz artifacts while running a campaign
FUZZ_MINIMIZE=1 FUZZ_MINIMIZE_PASSES=8 bun run fuzz:differential

# Replay one artifact through parser, typechecker, codegen, runtime,
# O0/O3 differential, and sanitizer modes
bun run fuzz:replay -- --metadata fuzz/crashes/mismatch_seed-...json --mode parser,typecheck,codegen,runtime,differential,sanitizer

# Run specific test file
bun test tests/Integration.test.ts

# Run tests matching pattern
bun test -t "generics"

Type Checking

# Check TypeScript types
bun run check

Building the Compiler

# Build executable
bun run build

# Development mode (no build)
bun index.ts run examples/hello-world/main.bpl

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (bun test)
  5. Format code (bun run format)
  6. Commit (git commit -m 'Add amazing feature')
  7. Push (git push origin feature/amazing-feature)
  8. Open a Pull Request

Open a pull request after running the relevant tests and type checks.

πŸŽ“ Learning Resources

Documentation

Video Tutorials

Coming soon!

Community

  • GitHub Discussions - Ask questions, share projects
  • GitHub Issues - Report bugs, request features
  • Discord - Real-time chat (link coming soon)

🚦 Roadmap

Current Status: Beta

BPL is under active development. The compiler has 1,300+ tests across 140+ test files, plus hundreds of example and regression programs.

Build Status:

  • βœ… 1,300+ tests in the checked-in test suite
  • βœ… CI-safe suite includes integration tests, all playground examples, and VS Code extension tests
  • βœ… 0 ESLint errors/warnings
  • βœ… 0 TypeScript errors
  • βœ… 450+ checked-in examples and regression programs

Completed βœ…

  • Full LLVM IR backend
  • Static type system with generics
  • Structs with inheritance
  • Module system with imports/exports
  • Exception handling (try/catch)
  • Package manager
  • Code formatter
  • Cross-compilation support
  • Standard library (50+ modules)
  • VS Code extension
  • Comprehensive test suite (1,300+ tests)
  • Documentation (70+ pages)
  • Enum types with pattern matching
  • String interpolation
  • Lambda expressions
  • Tuple destructuring (including nested)
  • Operator overloading (24 operators)
  • Intrinsics (math, bit manipulation, memory)
  • WebAssembly target (freestanding wasm32 plus hosted runtime hooks)

In Progress 🚧

  • IDE integrations (beyond VS Code)
  • More stdlib modules (networking, threads)
  • Optimization passes

Planned πŸ“‹

  • Package registry
  • Incremental compilation improvements
  • Inline assembly improvements
  • C++ interop improvements
  • Self-hosting compiler

See TODO.md for detailed task list.

πŸ“Š Benchmarks

BPL produces C-class performance on the checked-in benchmark suite. Representative medians from a recent --language bpl,c --runs 5 run:

Benchmark BPL (-O3) C (clang -O3) Ratio
bit_twiddle 40.60ms 40.59ms 1.00x
fibonacci_recursive 289.29ms 317.60ms 0.91x
matrix_multiplication 16.56ms 17.06ms 0.97x
prime_sieve 18.33ms 21.17ms 0.87x

Run ./benchmark/run_all.sh --language bpl,c --runs 5 to refresh local numbers, or add --json > benchmark/latest-results.json to write ignored local JSON output.

πŸ” Comparison with Other Languages

Feature BPL C C++ Rust Go
Manual memory mgmt βœ… βœ… βœ… βœ…* ❌
Generics βœ… ❌ βœ… βœ… βœ…
Inheritance βœ… ❌ βœ… ❌ ❌
Exceptions βœ… ❌ βœ… ❌ βœ…
Module system βœ… ❌ ⚠️ βœ… βœ…
Package manager βœ… ❌ ⚠️ βœ… βœ…
Memory safety** ⚠️ ❌ ❌ βœ… βœ…
Learning curve ⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐
Compile speed ⚑⚑ ⚑⚑⚑ ⚑ ⚑ ⚑⚑⚑
Runtime performance ⚑⚑⚑ ⚑⚑⚑ ⚑⚑⚑ ⚑⚑⚑ ⚑⚑

*Rust uses ownership/borrowing instead of GC
**Planned for BPL

πŸ“ License

BPL is licensed under the Apache License 2.0.

See LICENSE for details.

πŸ‘€ Author

pr0h0

  • GitHub: @pr0h0
  • Email: contact via GitHub

πŸ™ Acknowledgments

  • LLVM Project - For the amazing compiler infrastructure
  • Bun - For the fast JavaScript runtime
  • Community Contributors - For bug reports and feature requests

πŸ“ž Support

Need help?

  1. Documentation - Check the docs/ directory
  2. Examples - Browse examples/
  3. Issues - Search or create a GitHub Issue
  4. Discussions - Join GitHub Discussions

πŸ”— Links


Happy Coding! πŸš€

BPL - Where performance meets modern language design