X3 Language & Compiler
Relevant source files
The following files were used as context for generating this wiki page:
The X3 Language and Compiler system provides a specialized framework for developing and executing smart contracts across multiple execution domains, including X3Native, X3Evm, and X3Svm. It facilitates a full-stack build pipeline that transforms high-level source code into deterministic bytecode suitable for the X3 Virtual Machine (X3VM), ensuring cross-VM atomicity and consensus safety within the X3 Atomic Star ecosystem.
Sources: README.md:1-20, reports/prompt-runs/latest-full.md:10-25
Compiler Pipeline Architecture
The X3 compiler is structured as a multi-stage pipeline that handles everything from initial lexical analysis to final bytecode emission. It utilizes various intermediate representations (IR) to perform optimizations and semantic checks before generating executable code for the X3VM.
Compilation Stages
The following diagram illustrates the transformation flow from source code to executable bytecode:
The compilation pipeline transforms source code through multiple IR layers to ensure safety and optimization.
Sources: crates/x3-cli/x3-cli.cdx.json:80-160
Key Compiler Components
| Component | Responsibility | Relevant Crate |
|---|---|---|
| Lexer | Tokenizes raw source text into a stream of symbols. | x3-lexer |
| Parser | Generates an AST from the token stream. | x3-parser |
| Type Checker | Enforces the X3 type system and verifies type safety. | x3-typeck |
| Optimizer | Performs constant folding, dead code elimination (DCE), and peephole optimizations on MIR. | x3-opt |
| Backend | Lowers HIR into X3VM bytecode. | x3-backend |
| Verifier | Checks gas bounds, forbidden operations, and determinism. | x3-verifier |
Sources: crates/x3-cli/x3-cli.cdx.json:82-162
X3 Virtual Machine (X3VM) Integration
The compiler's final output is targeted at the x3-vm, which acts as the execution engine for the X3 Chain. The VM features a deterministic interpreter and a bytecode verifier to prevent non-deterministic execution paths that could lead to consensus failures.
VM Execution Flow
The interaction between the compiled bytecode and the VM environment:
The VM ensures that all bytecode meets strict safety criteria before execution begins.
Sources: crates/x3-cli/x3-cli.cdx.json:165-180, reports/prompt-runs/latest-full.md:70-85
Cross-VM and Instruction Logic (IXL)
A critical feature of the compiler is its support for the x3-ixl (Instruction eXecution Logic). This module handles the planning and interpretation of instructions that span different execution domains (EVM/SVM).
IXL Capabilities
- Instruction Types/Opcodes: Defines the fundamental operations for cross-VM interaction.
- Planner: Determines the sequence of execution steps for complex cross-domain operations.
- Rollback Semantics: Ensures atomic "all-or-nothing" execution across different VMs.
- Receipt Generation: Produces verifiable proof of execution for the X3 runtime.
Sources: reports/prompt-runs/latest-full.md:112-125
Build & Enforcement Guardrails
The X3 ecosystem enforces strict "No Stub" and "No Test Weakening" policies during the compilation and build process. Automated agents use a "Completion Scoreboard" to track the readiness of compiler subsystems.
Completion Standards
Subsystems are only considered complete if they meet the following criteria:
- Parser: Supports all new syntax and passes malformed input/fuzz tests.
- Emitter: Handles both basic transfer operations and complex cross-chain settlement.
- Verifier: Successfully checks all invariants and forbidden operation paths.
Sources: AGENTS.md:50-100, reports/prompt-runs/latest-full.md:40-60
Conclusion
The X3 Language & Compiler system is a high-integrity pipeline designed for cross-domain blockchain execution. By leveraging multi-stage IR transformations, a deterministic VM, and atomic instruction logic, it provides the necessary infrastructure for secure and interoperable smart contract execution within the X3 Chain.
Sources: README.md:25-40, reports/prompt-runs/latest-full.md:180-195