A simple, powerful programming language with TypeScript-inspired syntax that compiles to native code via C transpilation.
Native performance • Rich tooling • Modern syntax • Zero-cost abstractions
# Build the compiler
cargo build
# Compile and run a Bolt program
./target/debug/bolt examples/hello.bolt -o hello
./out/debug/hello
# Run all example programs
./run_examples.sh
# Test the compiler
./run_tests.sh # Complete test suite (61 tests)✅ Core Language:
- Variables:
var(mutable) andval(immutable) with type inference - Types:
String,Integer,Boolwith automatic type detection - Arithmetic:
+,-,*,/,%with proper precedence - Comparisons:
==,!=,<,>,<=,>= - Boolean logic:
&&,||,!
✅ Control Flow:
- Conditionals:
if,else if,elsestatements - Loops:
for (item in collection)iteration - Advanced iteration:
for item in myArrayworks with Array[T] types - Condition loops:
for (condition)while-style iteration
✅ Functions:
- Function definitions:
fun name(params): ReturnType { ... } - Parameters and return values with type annotations
- Function calls with argument passing
✅ Data Structures:
- Custom types:
type TypeName = { field: Type } - Generic types:
type Array[T] = { data: ^T, length: Integer } - Struct literals:
TypeName { field: value } - Generic constructors:
Array[Integer] { data: &value, length: 1 } - Field access:
object.fieldwith proper type handling - Monomorphization: Automatic generation of type-specific C structs
✅ Module System:
- Selective imports:
import { print } from "bolt:stdio" - Namespace imports:
import math from "bolt:math" - Export functions:
export fun functionName() { ... }
✅ Standard Library:
bolt:stdio- Input/output functions (print,println)bolt:math- Mathematical functions (max,min,abs)bolt:array- Array manipulation functionsbolt:string- String processing functions
✅ Developer Experience:
- Full LSP (Language Server Protocol) support
- VS Code extension with syntax highlighting
- Hover documentation with
/** */comments - Auto-completion and real-time error detection
- Cross-editor support (VS Code, Neovim, etc.)
Get rich IDE support with syntax highlighting, hover docs, and auto-completion:
# Install the Bolt VS Code extension
./reinstall-extension.sh
# Restart VS Code and open any .bolt fileFeatures:
- 🎨 Syntax highlighting for Bolt code
- 📖 Hover documentation for functions and variables
- 💡 Intelligent auto-completion
- 🔍 Documentation comment support (
/** */) - 🚀 Real-time language server integration
The Bolt LSP server works with any LSP-compatible editor:
# Build the LSP server
cargo build --bin bolt-lsp
# Use the binary at: ~/.vscode/extensions/bolt-language-lsp-0.2.0/bin/bolt-lspSupported LSP features:
textDocument/hover- Rich hover informationtextDocument/completion- Context-aware completionstextDocument/didOpen/didChange- Document synchronization
./run_tests.sh # All tests, comprehensive validation# Debug build
./target/debug/bolt examples/hello.bolt -o hello
# Release build (optimized)
./target/debug/bolt examples/hello.bolt -o hello --release🎉 PRODUCTION READY - Comprehensive language with native C integration!
- 61/61 tests passing (perfect score, 100% success rate)
- All core language features fully implemented
- Native C integration - Inline C functions and external library support
- Advanced type system - Generics with angle brackets, pointers, monomorphization
- Rich standard library - File I/O, string processing, mathematics
- Full developer tooling - LSP server, VS Code extension
- Robust compilation pipeline - C transpilation with GCC backend
Compilation Pipeline:
Bolt Source (.bolt) → Lexer → Parser → AST → C Code Generator → GCC → Native Executable
Key Components:
src/lexer.rs- Tokenizes Bolt source codesrc/parser.rs- Builds AST from tokenssrc/ast.rs- Language constructs representationsrc/c_codegen.rs- Transpiles AST to C codesrc/main.rs- CLI interface and compilation pipelinesrc/module.rs- Import/export system
Hello World:
import { print } from "bolt:stdio"
print("Hello, World!")
Function with Documentation (LSP-Enabled):
import { print } from "bolt:stdio"
/**
* Calculates the factorial of a given number using recursion
* This demonstrates Bolt's documentation comment support
*
* Example usage:
* val result = factorial(5) // Returns 120
*/
fun factorial(n: Integer): Integer {
if n <= 1 {
return 1
} else {
return n * factorial(n - 1)
}
}
/** The user's name for personalization */
val userName: String = "Alice"
val result := factorial(5)
print("Factorial: " + toString(result))
Struct Example:
import { print } from "bolt:stdio"
import math from "bolt:math"
type Point = {
x: Integer,
y: Integer
}
fun distance(p1: Point, p2: Point): Integer {
val dx := p1.x - p2.x
val dy := p1.y - p2.y
return math.abs(dx) + math.abs(dy)
}
val origin := Point { x: 0, y: 0 }
val point := Point { x: 3, y: 4 }
val dist := distance(origin, point)
print(dist)
🆕 Generic Array[T] Example:
import { print } from "bolt:stdio"
type Array[T] = {
data: ^T,
length: Integer,
capacity: Integer
}
type Person = {
name: String,
age: Integer
}
/** Create an Array[Integer] with one element */
val number: Integer = 42
val numbers: Array[Integer] = Array[Integer] {
data: &number,
length: 1,
capacity: 10
}
/** Iterate over the generic array */
print("Array[Integer] iteration:")
for item in numbers {
print(item) // Prints: 42
}
/** Works with custom types too! */
val person: Person = Person { name: "Alice", age: 25 }
val people: Array[Person] = Array[Person] {
data: &person,
length: 1,
capacity: 5
}
print("Array[Person] iteration:")
for p in people {
val name := p.name
val age := p.age
print(name) // Prints: Alice
print(age) // Prints: 25
}
🔥 Monomorphization Magic: The compiler automatically generates optimized C structs:
// Array[Integer] becomes:
typedef struct {
int* data;
int length;
int capacity;
} Array_Integer;
// Array[Person] becomes:
typedef struct {
Person* data;
int length;
int capacity;
} Array_Person;We welcome contributions! Here's how to get started:
git clone https://github.com/YOUR_USERNAME/boltlang.git
cd boltlang
cargo build
./run_tests.sh # Make sure everything works- All new language features must include test cases in
tests/ - Run the full test suite before submitting PRs
- Follow existing code style and conventions
- Update documentation for user-facing changes
- Maintain backward compatibility with existing Bolt code
- Update the lexer (
src/lexer.rs) for new tokens - Extend the parser (
src/parser.rs) for new syntax - Add AST nodes (
src/ast.rs) if needed - Implement code generation (
src/c_codegen.rs) - Add LSP support (
src/lsp.rs) for new constructs - Write comprehensive tests in
tests/
See ROADMAP.md for the comprehensive development roadmap.
- Result<T, E> Code Generation: Complete implementation of Result type runtime behavior
- Pattern Matching Runtime: Full
matchstatement code generation with destructuring - Error Propagation: Complete
?operator code generation for early returns - Option Types: Implement nullable value handling with Some/None variants
- String Operations: Concatenation with
+, indexing, slicing - Collection Improvements: Dynamic arrays, hash maps, sets
- Advanced Types: Tuples, enums with associated data, type unions
- Functional Features: Function overloading, closures, higher-order functions
- Concurrency: Async/await, channels, actor model
- Ecosystem: Package manager, documentation generator, REPL
This project is licensed under the MIT License.
- Built with Rust for performance and memory safety
- TypeScript-inspired syntax for familiarity and clarity
- LSP integration for modern development experience
- C transpilation for fast native code generation
Ready to bolt into action? ⚡
/**
* Welcome to Bolt - where performance meets productivity!
*/
fun main() {
val message := "The future of programming starts here!"
print(message)
}
Built with ❤️ by the Bolt community