d1160ca5d1ed170322e6a170fd685f81edd736d1
The self-hosted compiler crashed with SIGSEGV when processing files that generated >=256 parser diagnostics (e.g. truncated source files). The parser allocated a fixed-size diag buffer of 256 entries, but parserExpect, parserExpectIdentOrKeyword, and parserEmitDiag wrote into it without checking bounds. Once diagCount exceeded 256, writes overflowed into adjacent heap objects (Decl structs), corrupting their kind/childDecl2 fields and causing crashes during AST traversal. This fix adds bounds checks to all three sites so excess diagnostics are silently dropped rather than corrupting memory. The file size threshold (7037 vs 7062 bytes) was a red herring — it determined how many parser errors were generated before EOF. Closes: selfhost segfault on 250+ line files
Bux Programming Language
Status: Self-hosting phase —
buxc2(Bux compiler written in Bux) compiles.buxfiles to C. Bootstrap compiler (buxc, Nim) maintains backward compatibility.
Bux is a fast, compiled, strongly-typed systems programming language. The long-term goal is a self-hosted compiler with a minimal runtime, native x86-64 backend, and modern tooling.
Bux features a rich standard library (Map, String), modern error handling (Result, Option, and the ? operator), and a portable C transpiler backend that runs on Linux, macOS, and Windows.
Quick Start
# Build the bootstrap compiler (Nim)
make build
# Create a new project
bux new hello
cd hello
# Build and run
bux run
Syntax Preview
Hello World
import Std::Io::PrintLine;
func Main() -> int {
PrintLine("Hello, Bux!");
return 0;
}
Error Handling with ?
enum Result {
Ok(int),
Err(String)
}
func Divide(a: int, b: int) -> Result {
if b == 0 {
return Result_NewErr("division by zero");
}
return Result_NewOk(a / b);
}
func Compute() -> Result {
let x: int = Divide(10, 2)?; // auto-propagates Err
let y: int = Divide(x, 5)?;
return Result_NewOk(y);
}
Structs and Methods
struct Rectangle {
width: int;
height: int;
}
extend Rectangle {
func Area(self: Rectangle) -> int {
return self.width * self.height;
}
}
func Main() -> int {
let rect: Rectangle = Rectangle { width: 10, height: 5 };
PrintInt(rect.Area());
return 0;
}
Generics
func Max<T>(a: T, b: T) -> T {
if a > b {
return a;
}
return b;
}
func Main() -> int {
let m: int = Max<int>(10, 20);
PrintInt(m);
return 0;
}
Async/Await
import Std::Io::{PrintLine, PrintInt};
async func Compute() -> int {
PrintLine("Compute: step 1");
bux_async_yield();
PrintLine("Compute: step 2");
return 42;
}
func Main() -> int {
let h1 = spawn Compute();
let r1: int = h1.await as int;
PrintInt(r1);
return 0;
}
Hash Map
import Std::Map::{Map, Map_New, Map_Set, Map_Get};
func Main() -> int {
let m: Map = Map_New(16);
Map_Set(&m, "answer", 42);
PrintInt(Map_Get(&m, "answer"));
return 0;
}
Features
| Feature | Status |
|---|---|
| Types | Primitives, pointers, slices, tuples, structs, enums, unions |
| Generics | Generic functions (monomorphization) |
| Algebraic Enums | Enums with data (Result, Option) |
| Pattern Matching | match with guards |
| Methods | extend blocks for struct methods |
| Interfaces | interface + extend for trait-like behavior |
| Error Handling | Result<T,E>, Option<T>, and the ? operator |
| Standard Library | Io, Array, String, Map |
| Backend | C transpiler (bootstrap) → self-hosting target |
| Gradual Ownership | @[Checked] + &T/&mut T borrow checking |
| Async/Await | async func, spawn, .await with stackful coroutines |
| Concurrency | Task/Channel (pthread-based), bux_async_yield/spawn |
| CTFE | const func — compile-time function execution |
| Trait Bounds | func Max<T: Comparable>(a: T, b: T) -> T |
| Package Manager | bux add, bux install, bux.lock, path + git deps |
| Tooling | bux new, bux build, bux run, bux check |
Project Structure
bux/
├── src/ # Bootstrap compiler (Nim)
├── src_bux/ # Self-hosting compiler source (Bux)
├── _selfhost/ # Self-hosting build artifacts
├── stdlib/ # Standard library (.bux + .c runtime)
├── examples/ # Example programs
├── tests/ # Unit tests (Nim)
├── docs/ # Documentation
├── README.md
├── PLAN.md # Roadmap to self-hosting
└── Makefile
Build & Test
# Build bootstrap compiler (Nim)
make build
# Build self-hosted compiler (Bux → C → binary)
make selfhost
# Run all tests
make test
# Run example programs
make test-examples
# Clean build artifacts
make clean
Documentation
docs/LanguageRef.md— Language referencedocs/Stdlib.md— Standard library documentationdocs/BuildAndTest.md— Build and test guidePLAN.md— Roadmap to self-hosting
License
MIT
Languages
C
74.6%
Nim
23.4%
HTML
1.2%
Makefile
0.3%
Go
0.3%