A compiler for a strongly typed variant of TypeScript, targeting LLVM for high-performance native code generation.
- LLVM@18 (
brew install llvm@18) - Rust (latest stable version)
- TypeScript (for testing)
To run specific tests in the tests directory, use the following command:
make bin testfile=./tests/<fileName>.ts
This command compiles the specified TypeScript file and runs the tests defined within it. Replace <fileName> with the name of the test file you want to execute.
- Strong Typing: No implicit type conversions, strict type checking at compile time
- TypeScript Syntax: Familiar syntax with stricter semantics
- Performance: LLVM backend for optimized native code generation
- Simplicity: Clean, understandable compiler architecture
- Distinct Types:
any,null, andundefinedas separate, well-defined types
π§ Early Development - Basic compiler infrastructure in progress
- Lexical analysis (tokenization)
- Parser (AST generation)
- Semantic analysis (type checking)
- LLVM IR code generation
- Basic operations (variable assignment, arithmetic)
Source Code (.ts) β Lexer β Parser β Semantic Analyzer β Code Generator β LLVM IR β Native Binary
- Lexer: Tokenizes TypeScript source code
- Parser: Builds Abstract Syntax Tree (AST)
- Semantic Analyzer: Type checking and symbol resolution
- Code Generator: Converts AST to LLVM IR
- LLVM Backend: Optimization and machine code generation
Unlike standard TypeScript, Draf enforces strict typing:
- No implicit type conversions
anyis a distinct type that requires explicit handlingnullandundefinedare separate types- All operations must be type-safe at compile time
// Variable declarations with explicit types let x: number = 42; let name: string = "hello"; let flag: boolean = true; // No implicit conversions - this would be a compile error // let result = x + name; // Error: Cannot add number and string // Explicit handling of nullable types let maybeValue: number | null = getValue(); if (maybeValue !== null) { let doubled = maybeValue * 2; // Safe to use after null check }
# Install Rust if not already installed curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Build the compiler cargo build --release # Run tests cargo test # Compile a TypeScript file ./target/release/draf input.ts -o output
- Rust: Systems programming language
- LLVM 17: Code generation and optimization
- inkwell: Rust bindings for LLVM
- logos: Fast lexical analysis
# Run in development mode cargo run -- input.ts # Run with debug output RUST_LOG=debug cargo run -- input.ts # Benchmark parser performance cargo bench
This is an experimental project exploring strongly typed compilation of TypeScript-like syntax. Contributions and ideas welcome!
MIT License - see LICENSE file for details.