darmie/zyntax
{ "createdAt": "2025-01-25T08:45:35Z", "defaultBranch": "main", "description": "Multi-Paradigm Compiler Infrastructure & Runtime Framework", "fullName": "darmie/zyntax", "homepage": "", "language": "Rust", "name": "zyntax", "pushedAt": "2025-11-25T14:33:03Z", "stargazersCount": 10, "topics": [ "aot-compilation", "bytecode", "bytecode-virtual-machine", "compiler", "jit", "jit-compiler", "runtime", "virtual-machine" ], "updatedAt": "2025-11-25T14:33:22Z", "url": "https://github.com/darmie/zyntax"}Zyntax: Multi-Paradigm Compiler Infrastructure
Section titled βZyntax: Multi-Paradigm Compiler InfrastructureβA high-performance, multi-paradigm compiler infrastructure with advanced type system features, tiered JIT compilation, and async/await runtime support.
[]!(./BACKLOG.md)
[
]!(./crates/zyn_parser/tests)
[
]!(./crates/zyn_parser/tests)
[
]!(LICENSE)
π― What is Zyntax?
Section titled βπ― What is Zyntax?βZyntax is a complete compiler infrastructure and runtime framework designed for building high-performance, memory-safe programming languages. It provides:
-
Complete Compilation Pipeline: TypedAST β HIR β Native Code
-
Tiered JIT Compilation: 3-tier optimization (Baseline β Standard β Optimized)
-
Advanced Type System: Generics, traits, lifetimes, dependent types
-
Async/Await Runtime: Zero-cost futures with complete executor infrastructure
-
Production-Ready stdlib: Vec, String, HashMap, Iterator (93/100 functions compile)
-
Multi-Backend: Cranelift JIT (fast) + LLVM AOT (optimized)
-
HIR Builder API: Type-safe, fluent interface for IR construction
Think of Zyntax as LLVM + Rustβs type system + V8βs tiered compilation - a complete foundation for building modern, high-performance programming languages.
π οΈ Zyntax CLI
Section titled βπ οΈ Zyntax CLIβThe Zyntax command-line interface provides a unified compilation toolchain with multiple input format support:
# Build the CLIcargo build --release
# Compile and run a programzyntax compile input.json -o myprogram --run
# Multiple input formats supportedzyntax compile program.zbc --format zbc -o outputzyntax compile source.zyn --format zyn -o output --jitCLI Features
Section titled βCLI Featuresβ- Dual-Format Support: Compile from JSON TypedAST or ZBC bytecode
- JIT Execution: Run programs directly with
--runflag - Multiple Backends: Choose Cranelift (fast) or LLVM (optimized)
- Format Auto-Detection: Automatically detects input format from file extension
- Rich Diagnostics: Clear error messages with source location tracking
Usage Examples
Section titled βUsage Examplesβ# Compile JSON TypedAST to executablezyntax compile program.json -o myapp
# Compile and run immediatelyzyntax compile program.json --run
# Compile ZBC bytecode formatzyntax compile program.zbc -o myapp
# Use specific backendzyntax compile program.json --backend llvm -o myappπ¦ ZBC Bytecode Format
Section titled βπ¦ ZBC Bytecode FormatβZBC (Zyntax ByteCode) is a portable, architecture-independent bytecode format designed for efficient serialization and distribution of compiled programs.
Key Features
Section titled βKey Featuresβ- Portable: Architecture-independent binary format
- Compact: Efficient binary encoding with compression
- Type-Preserving: Maintains full type information for verification
- Module-Based: Supports separate compilation and linking
- Version-Safe: Built-in format versioning for compatibility
Format Overview
Section titled βFormat Overviewβββββββββββββββββββββββββββββββββββββββββ ZBC File Header ββ - Magic number: 0x5A42_4300 ββ - Version: 1.0 ββ - Metadata section offset ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Type Definitions ββ - Structs, enums, traits ββ - Generic type parameters ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Function Definitions ββ - Signature with parameter types ββ - HIR instruction stream ββ - SSA value numbering ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Constant Pool ββ - String literals ββ - Numeric constants ββββββββββββββββββββββββββββββββββββββββUse Cases
Section titled βUse Casesβ- Distribution: Ship pre-compiled modules to users
- Caching: Cache compiled TypedAST for faster rebuilds
- Cross-Platform: Compile once, run on any Zyntax-supported platform
- Integration: Load modules from multiple source languages
See [Bytecode Format Specification]!(./docs/BYTECODE_FORMAT_SPEC.md) for complete details.
π Zyn Grammar Format
Section titled βπ Zyn Grammar FormatβZyn is Zyntaxβs domain-specific language for defining custom programming language frontends. It extends PEG (Parsing Expression Grammar) syntax with JSON-based semantic actions that construct TypedAST nodes directly from parsed syntax.
How Zyn Works with Zyntax
Section titled βHow Zyn Works with Zyntaxββββββββββββββββββββ βββββββββββββββββ ββββββββββββββββ βββββββββββββββββ Source Code β β β Zyn β β β TypedAST β β β Native ββ (your_lang.x) β β Grammar β β (JSON) β β Binary ββββββββββββββββββββ βββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β βββββββββββββββββ β Cranelift/ β β LLVM Backend β βββββββββββββββββZyn grammars define both syntax (what patterns to match) and semantics (what AST nodes to create). This enables:
- Custom Language Frontends: Define your own language syntax and compile to native code
- Runtime Grammar Loading: No Rust recompilation neededβload grammars dynamically
- Seamless Integration: Output TypedAST that flows through Zyntaxβs HIR and backend pipeline
- Interactive Development: Test grammar changes instantly with the built-in REPL
Quick Example
Section titled βQuick Exampleβ@language { name: "Calculator", version: "1.0", file_extensions: [".calc"], entry_point: "main",}
// Build a program: expression β return β function β programprogram = { SOI ~ expr ~ EOI } -> TypedProgram { "commands": [ { "define": "return_stmt", "args": { "value": "$1" }, "store": "ret" }, { "define": "function", "args": { "name": "main", "params": [], "body": "$ret" } }, { "define": "program", "args": { "declarations": ["$result"] } } ] }
// Binary expression with left-associative foldingexpr = { term ~ ((add_op | sub_op) ~ term)* } -> TypedExpression { "fold_binary": { "operand": "term", "operator": "add_op|sub_op" } }
// Integer literal: get text, parse, create AST nodenumber = @{ ASCII_DIGIT+ } -> TypedExpression { "get_text": true, "parse_int": true, "define": "int_literal", "args": { "value": "$result" } }
add_op = { "+" } -> String { "get_text": true }sub_op = { "-" } -> String { "get_text": true }WHITESPACE = _{ " " | "\t" | "\n" | "\r" }CLI Usage
Section titled βCLI Usageβ# Compile and run with grammarzyntax compile --source input.calc --grammar calc.zyn --format zyn --run
# Verbose mode shows compilation stepszyntax compile -v --source code.mylang --grammar mylang.zyn --format zyn -o output
# Interactive REPL modezyntax repl --grammar calc.zynInteractive REPL
Section titled βInteractive REPLβStart an interactive session to evaluate expressions on the fly:
$ zyntax repl --grammar examples/zpeg_test/calc.zynZyntax REPLGrammar: examples/zpeg_test/calc.zynβ Calculator grammar loaded (11 rules)
Calculator> 2 + 3 * 4[1] = 14Calculator> (10 + 5) * 2[2] = 30Calculator> :helpREPL Commands: :help, :h, :? Show this help message :quit, :q, :exit Exit the REPL :verbose, :v Toggle verbose mode :clear, :c Clear the screen :{ Start multi-line input (end with :})
Multi-line Input: - End a line with \ to continue on the next line - Lines with unclosed { automatically continue - Use :{ to start explicit multi-line mode, :} to execute - Press Ctrl+C to cancel multi-line inputCalculator> :quitGoodbye!Key Features
Section titled βKey Featuresβ| Feature | Description |
|---|---|
define | Create AST nodes with named arguments: "define": "int_literal", "args": { "value": 42 } |
commands | Sequential command execution with $result chaining |
store | Save intermediate results: "store": "myvar" β access as "$myvar" |
fold_binary | Left-associative binary operator folding |
get_text | Extract matched text content |
get_child | Access child nodes by index or name |
Available Node Types
Section titled βAvailable Node Typesβ- Literals:
int_literal,float_literal,string_literal,bool_literal,char_literal - Expressions:
variable,binary_op,unary_op,call_expr,method_call,field_access,index,array,struct_literal,cast,lambda - Statements:
let_stmt,assignment,return_stmt,if_stmt,while_stmt,for_stmt,break_stmt,continue_stmt,expression_stmt,block - Declarations:
function,param,program - Types:
primitive_type,pointer_type,array_type,named_type,function_type
See [Zyn Grammar Specification]!(./docs/ZYN_GRAMMAR_SPEC.md) for complete documentation.
π Frontend Integrations
Section titled βπ Frontend IntegrationsβZyntax supports multiple language frontends through its TypedAST intermediate representation. Create your own programming language or integrate existing ones:
β Zyn - Create Your Own Language
Section titled ββ Zyn - Create Your Own LanguageβDefine a custom language with Zyn grammar and compile to native code:
# Write your language grammar (mylang.zyn)# Then compile source files written in your languagezyntax compile --source program.mylang --grammar mylang.zyn --format zyn --run
# Or use interactive REPL to test your languagezyntax repl --grammar mylang.zynOutput Targets:
| Target | Description |
|---|---|
| TypedAST | JSON intermediate representation for tooling integration |
| Bytecode | Portable .zbc format for distribution and caching |
| JIT | Cranelift-powered just-in-time compilation |
| AOT | LLVM-based ahead-of-time native executables |
Status: β Production-ready - Full compilation pipeline with REPL support
β Haxe Integration (via Reflaxe)
Section titled ββ Haxe Integration (via Reflaxe)βCompile Haxe code to native executables using the [reflaxe.zyntax]!(./reflaxe.zyntax/README.md) backend:
# Install dependencieshaxelib install reflaxe 4.0.0-betahaxelib dev reflaxe.zyntax ./reflaxe.zyntax
# Compile Haxe to nativehaxe -lib reflaxe.zyntax -main Main -D zyntax-output=outzyntax compile out/*.json -o myprogram --runStatus: π§ In development - JSON AST generation complete, HIR conversion in progress
See [Haxe Integration Guide]!(./docs/HAXE_INTEGRATION.md) for details.
β HIR Builder API - Programmatic Code Generation
Section titled ββ HIR Builder API - Programmatic Code GenerationβBuild HIR modules directly from Rust code. Perfect for:
- Code generators that emit Zyntax IR from other tools
- DSL implementations that construct code at runtime
- Compiler backends for languages with existing parsers
- Testing and prototyping new language features
use zyntax_compiler::hir_builder::HirBuilder;use zyntax_typed_ast::arena::AstArena;
let mut arena = AstArena::new();let mut builder = HirBuilder::new("hello", &mut arena);
// fn main() -> i32 { return 42; }let i32_ty = builder.i32_type();let main_fn = builder.begin_function("main") .returns(i32_ty.clone()) .build();
builder.set_current_function(main_fn);let entry = builder.entry_block();builder.set_insert_point(entry);
let value = builder.const_i32(42);builder.ret(value);
let module = builder.finish();
// Compile to native code with JITlet mut backend = CraneliftBackend::new().unwrap();backend.compile_module(&module).unwrap();
// Execute!let fn_ptr = backend.get_function_ptr(main_fn).unwrap();let result = unsafe { let f: fn() -> i32 = std::mem::transmute(fn_ptr); f()};assert_eq!(result, 42);Status: β Production-ready - Full SSA-based IR construction with type system integration
π Other Integrations
Section titled βπ Other Integrationsβ- Whirlwind - Direct AST adapter (in progress)
- Custom JSON - Generate TypedAST JSON directly from any toolchain
π Quick Start
Section titled βπ Quick Startβ# Clone the repositorygit clone https://github.com/darmie/zyntax.gitcd zyntax
# Run testscargo test
# Run comprehensive end-to-end testscargo test --test end_to_end_comprehensivecargo test --test end_to_end_simple
# Build the compilercargo build --releaseποΈ Architecture
Section titled βποΈ Architectureβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Language Frontends ββ (Your language's parser β TypedAST) βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ β βΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Zyntax TypedAST Layer ββ β’ Multi-paradigm type checking (structural/nominal/gradual)ββ β’ Generics, traits, lifetimes, dependent types ββ β’ Advanced analysis (ownership, escape, lifetimes) ββ β’ Rich diagnostics with span tracking βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ β βΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ High-Level IR (HIR) + Lowering ββ β’ SSA-based intermediate representation ββ β’ Control flow graph (CFG) with dominance analysis ββ β’ Type-erased, platform-agnostic ββ β’ HIR Builder API for programmatic construction βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ β ββββββ΄βββββ βΌ βΌ βββββββββββββββββββ ββββββββββββββββββββ β Cranelift JIT β β LLVM AOT β β (Baseline/Fast) β β (Optimized) β ββββββββββ¬βββββββββ ββββββββββ¬ββββββββββ β β βββββββββ¬ββββββββββββ βΌ ββββββββββββββββββββββββ β Native Machine β β Code β ββββββββββββββββββββββββKey Components
Section titled βKey Componentsβπ¦ Crates:
typed_ast/- Multi-language typed AST with rich type systemcompiler/- HIR generation, lowering, backend code generation, and async runtimewhirlwind_adapter/- Whirlwind language integration
π¨ Key Features:
- Tiered Compilation: Hot code recompiles with better optimizations
- Zero-Cost Abstractions: Traits, generics, closures compile to native code
- Async/Await: Complete runtime with task scheduling and waker infrastructure
- Memory Safety: Ownership, borrowing, lifetimes enforced at compile time
π₯ Current Status
Section titled βπ₯ Current StatusβTest Results (98.6% Pass Rate)
Section titled βTest Results (98.6% Pass Rate)ββ
280/284 tests passingβ
All end-to-end comprehensive tests passing (9/9)β
All end-to-end simple tests passing (5/5)β
Standard library: 93/100 functions compile successfullyWhatβs Working
Section titled βWhatβs Workingββ Core Compiler Pipeline
Section titled ββ Core Compiler Pipelineβ- Complete TypedAST β HIR β Native code pipeline
- Full SSA construction with phi nodes
- Control flow graph analysis (dominators, post-dominators)
- Dead code elimination
β Type System
Section titled ββ Type Systemβ- Generics: Type parameters with bounds
fn foo<T: Clone>(x: T) - Traits: Interface definitions with associated types
- Lifetimes: Borrow checker with lifetime inference
- Dependent Types: Basic refinement types and indexed families
- Multi-paradigm: Structural, nominal, and gradual typing
β Language Features
Section titled ββ Language Featuresβ- Functions with parameters and returns
- Basic arithmetic (
+,-,*,/) - Function calls (including recursive)
- Local variables with stack allocation
- Pattern matching (basic)
- Async/await syntax and runtime
β Tiered JIT Compilation
Section titled ββ Tiered JIT Compilationβ- Tier 1: Cranelift baseline JIT (fast compilation)
- Tier 2: Cranelift optimized (moderate optimizations)
- Tier 3: LLVM JIT (aggressive optimizations for hot paths)
- Runtime profiling with atomic execution counters
- Hot-path detection and automatic recompilation
β Standard Library
Section titled ββ Standard LibraryβVec<T>- Dynamic array with push/pop/indexingString- UTF-8 string with manipulation methodsHashMap<K,V>- Hash table with insert/get/removeIterator- Lazy iterator trait with 50+ adapters
β Async Runtime
Section titled ββ Async Runtimeβ- Complete executor with task scheduling
- Waker infrastructure for efficient event-driven code
- Parameter capture in async state machines
- Integration with tiered JIT compilation
π Documentation
Section titled βπ Documentationβ- [Architecture Guide]!(docs/ARCHITECTURE.md) - Complete system architecture
- [HIR Builder Example]!(docs/HIR_BUILDER_EXAMPLE.md) - How to construct HIR programmatically
- [Async Runtime Design]!(docs/ASYNC_RUNTIME_DESIGN.md) - Async/await internals
- [Bytecode Spec]!(docs/BYTECODE_FORMAT_SPEC.md) - Bytecode serialization format
- [Backlog]!(BACKLOG.md) - Development roadmap and tasks
- [Production Status]!(PRODUCTION_READY_STATUS.md) - Detailed feature matrix
π― Use Cases
Section titled βπ― Use Casesβ1. Language Implementation
Section titled β1. Language ImplementationβBuild a new programming language by targeting Zyntax:
// Your language parserYourLanguage β TypedAST β HIR β Native CodeExample: Implement a Python-like language with JIT compilation and type inference.
2. Domain-Specific Languages (DSLs)
Section titled β2. Domain-Specific Languages (DSLs)βCreate high-performance DSLs for specific domains:
- Game scripting languages
- Data processing pipelines
- Configuration languages with validation
3. Cross-Language Interop
Section titled β3. Cross-Language InteropβUse Zyntax as a common compilation target:
Multiple Languages β TypedAST β Shared Runtime4. Research Platform
Section titled β4. Research PlatformβExperiment with advanced type system features:
- Effect systems
- Dependent types
- Linear types
- Algebraic effects
π§ Roadmap
Section titled βπ§ RoadmapβSee [BACKLOG.md]!(BACKLOG.md) for detailed tasks.
Q4 2025 (Current): Core Stabilization β COMPLETE
Section titled βQ4 2025 (Current): Core Stabilization β COMPLETEβ- β Zig parser with full control flow support (continue, break, while loops)
- β Fix SSA variable reads for unsealed blocks (continue statement bug)
- β Logical operators with short-circuit evaluation
- β Array types, indexing, and array index assignment
- β
String literals (lowered to global
*i8) - β 71/71 Zig E2E tests passing (100%)
- β Zig-style error handling (try/catch/orelse on error unions)
- β Pattern matching (if let, switch, Some/None/Ok/Err)
- β Generic functions with monomorphization
Q1 2026: Production Features
Section titled βQ1 2026: Production Featuresβ- π LLVM AOT backend completion
- π Haxe-style exception handling (throw/catch/finally with stack unwinding)
- π Complete I/O and networking standard library
- π String operations (needs stdlib integration via plugin system)
Q2 2026: Ecosystem & Integration
Section titled βQ2 2026: Ecosystem & Integrationβ- π Complete Reflaxe/Haxe integration
- π Run Haxe standard library through Zyntax
- π Performance benchmarking vs existing targets
- π 100% test pass rate
Q3 2026: Developer Experience
Section titled βQ3 2026: Developer Experienceβ- π Language Server Protocol (LSP) implementation
- π Package manager
- π Comprehensive documentation and tutorials
- π VSCode/IntelliJ integration
π€ Contributing
Section titled βπ€ ContributingβContributions are welcome! Hereβs how to get started:
- Pick a task from [BACKLOG.md]!(BACKLOG.md)
- Check documentation in [docs/]!(docs/)
- Run tests to understand the system:
cargo test - Implement incrementally with test coverage
- Submit a PR with clear description
Development Setup
Section titled βDevelopment Setupβ# Install Rust (1.70+)curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Clone and buildgit clone https://github.com/yourusername/zyntax.gitcd zyntaxcargo build
# Run testscargo test --workspace
# Run specific test suitescargo test --package zyntax_compilercargo test --test end_to_end_comprehensiveπ Performance
Section titled βπ PerformanceβCompilation Speed
Section titled βCompilation Speedβ- Baseline JIT (Cranelift): <1ms for small functions
- Optimized JIT (LLVM): 10-100ms for hot paths
- Tiered compilation: Amortizes optimization cost over runtime
Runtime Performance
Section titled βRuntime Performanceβ- Zero-cost abstractions: Generics and traits compile to direct calls
- Async overhead: ~100ns per await point
- Memory safety: No runtime overhead for ownership checks
Comparison (Estimated)
Section titled βComparison (Estimated)βLanguage/VM | Startup | Hot Code | Memory Safety---------------------|---------|----------|---------------Zyntax (Tier 1) | ~1ms | 2-3x C | Compile-timeZyntax (Tier 3) | ~50ms | ~C speed | Compile-timeV8 (JavaScript) | ~50ms | ~C speed | Runtime GCHotSpot (Java) | ~100ms | ~C speed | Runtime GCPyPy (Python) | ~200ms | 5-10x C | Runtime GCCPython (Python) | ~50ms | 50-100x C| Runtime GCNote: Benchmarks are preliminary. Real-world performance depends on workload.
π License
Section titled βπ LicenseβThis project is licensed under the Apache 2.0 License - see the [LICENSE]!(LICENSE) file for details.
π Acknowledgments
Section titled βπ Acknowledgmentsβ- Cranelift - Fast, secure code generator
- LLVM - Optimizing compiler infrastructure
- Rust - Type system inspiration and implementation language
- Haxe - Multi-target compilation model
- V8/HotSpot - Tiered compilation strategies
π Contact
Section titled βπ Contactβ- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with π¦ Rust | Powered by Cranelift & LLVM | Production-Ready Core