Rul (.rl) — A 128-Bit Binary Programming Language for AI Agents What is Rul in Plain English? Languages like C, Go, and Rust were built for humans typing text at a keyboard. When an AI agent writes Rust or C today, it outputs thousands of characters of text, and the compiler (rustc or LLVM) spends seconds parsing that text, checking memory rules, and searching for loop optimizations. Rul (.rl) removes the human text…
Rul (.rl) — A 128-Bit Binary Programming Language for AI Agents
What is Rul in Plain English?
Languages like C, Go, and Rust were built for humans typing text at a keyboard. When an AI agent writes Rust or C today, it outputs thousands of characters of text, and the compiler (rustc or LLVM) spends seconds parsing that text, checking memory rules, and searching for loop optimizations.
Rul (.rl) removes the human text layer. Instead of writing text source files, an AI agent emits a compact list of fixed 16-byte (128-bit) binary instructions. Every 16-byte instruction carries three pieces of information up front:
The operation (such as add, compare, filter, or reduce).
How to run it on the CPU (a 1-byte schedule hint selecting single-core SIMD or multi-core execution).
A memory safety tag (a version number and bounds index proving the memory access is valid).
Because the AI provides the CPU schedule and safety tags inside each instruction, the Rul compiler does not need to guess or run slow optimization passes:
Fast safety checks: Rul verifies memory ownership, array bounds, the termination policy, and I/O permissions in a single forward pass (~5.8 nanoseconds per instruction, or under 60 microseconds for 10,000 instructions).
Microsecond native compilation: Rul compiles verified .rl programs directly into standalone Linux x86_64 executables (628 to 1,037 bytes) in ~6.4 microseconds, without LLVM or an external linker.
Easy for humans to inspect: Humans never need to write .rl by hand, but can inspect any program at any time using rul decompile (readable text view) or rul trace (which prints the exact min, max, sum, and NaN count at every step).
30-Second Quickstart
Install the standalone rul binary and create, verify, compile, run, and trace a .rl program in 30 seconds (no Cargo.toml or rustc required to run .rl projects):
# 1. Install the standalone rul toolchain
curl -fsSL https://raw.githubusercontent.com/rul-lang/rul/main/install.sh | sh
# 2. Create a sample Rul project (rul.toml, src/main.rls, data/arena_0.bin)
rul new my-ai-pipeline && cd my-ai-pipeline
# 3. Verify in microseconds, compile a standalone ~880-byte Linux ELF64 binary, and run
rul check
rul run
# 4. Inspect the exact min/max/sum/NaN output at every step (#0..#6)
rul trace
How Rul Achieves Safety, Runtime Speed, and Microsecond Compilation Together
Traditional languages force a trade-off between memory safety, runtime speed, and compile time because the compiler has to infer what the human programmer meant. Rul avoids that trade-off through four simple mechanisms:
No Text Parsing (0% Syntax Errors):
AI agents emit 16-byte binary instructions directly (or assemble flat .rls listings in ~8.8 microseconds).
A 7-step pipeline over 10 million numbers is 192 bytes in .rl and compiles into a standalone 817-byte Linux ELF64 binary.
Versioned Memory Buffers Instead of a Slow Borrow Checker:
Every memory buffer (Arena) starts at version 1.
Multiple instructions can read version 1 at the same time (ReadLease).
If an instruction modifies a mutable buffer in place (AffineConsume), it consumes version 1 and advances the buffer to version 2. Any later instruction that still tries to read or write version 1 is rejected immediately.
This gives AI-generated code Rust-grade protection against use-after-free and aliasing bugs in a single linear scan (5.78 ns/instruction).
Compile-Time Bounds Proofs and Hardware Capability Bits:
Operations on matching array lengths need zero runtime bounds checks. Sub-slices (ArenaSlice) and indirect lookups (Gather) reference a 16-byte ProofEntry table checked at load time.
The 64-byte file header includes a CapabilityMask bitfield. When set to 0x0 (CAP_NONE), instructions that perform external I/O are rejected before the program can run.
Cache-Friendly Columnar Memory and Single-Byte Schedule Tuning:
Data is stored in 64-byte-aligned columnar arrays (Structure-of-Arrays) so CPU vector registers only load the fields they actually use.
Changing a single byte (ScheduleHint) switches execution from single-core SIMD (pol=simd) to all CPU cores (pol=multicore) without rewriting the algorithm.
Benchmark (10,000,000f64 Elements = 80 MB Array)
Workload: Filter elements > 1000.0, square matching values, and sum to a scalar.
Implementation
Execution Mode
Median Latency
Effective Logical Bandwidth
Speedup vs. C 8-Acc (1-Core)
Speedup vs. Legacy AoS
[A] Imperative AoS + Vec::collect()
1-Core AoS + Heap
70.66 ms
1.13 GB/s
0.10x
1.00x
[B] Idiomatic Rust SoA (filter().map().sum())
1-Core SoA Iterator
19.12 ms
4.18 GB/s
0.38x
3.70x
[C] Hand-Written C/Rust 8-Accumulator SoA
1-Core 8-Lane Unrolled
7.32 ms
10.92 GB/s
1.00x (Baseline)
9.65x
[D] Rul (.rl) Tier 2 Fused SIMD
1-Core L1-Tile SIMD (SimdStream)
5.91 ms
13.53 GB/s
1.24x (1-Core vs. 1-Core)
11.95x
[E] Rul (.rl) Tier 2 MultiCore
All Cores (MultiCore 1-Byte Hint)
3.19 ms
25.04 GB/s
2.29x (Schedule Mutation)
22.12x
[F] Rul (.rl) Tier 2 MultiCore + ZoneMap
All Cores + O(1) Tile Skipping
1.55 ms
51.53 GB/s
4.72x (With Block Min/Max)
45.51x
Notes on the numbers above:
[C] vs. [D] (1.24x) is the strict single-core comparison on the exact same 80 MB array.
[E] (2.29x) changes only the 1-byte ScheduleHint from pol=simd (0x11) to pol=multicore (0x12), parallelizing 1,024-element L1 tiles across cores.
[F] (4.72x / 51.53 GB/s logical bandwidth) adds block min/max metadata (ArenaZoneMap) on partitioned data so cold 1,024-element tiles that cannot match the filter are skipped in O(1) without reading them from RAM.
On deep arithmetic pipelines (BM-HORNER-50, a 50-step Horner polynomial with 104 SSA nodes over 10,000,000 f64 elements), the linear-scan YMM register allocator in src/aot.rs compiles a 3,872-byteELF64 binary in ~20.4 us and executes in 106.58 ms, matching hand-written 8-accumulator C/Rust (107.96 ms).
Why .rl Does Not Become an Unmaintainable Black Box
A common question is: “If humans do not write .rl code, how do teams debug or maintain a system over time?”
Humans Define the Boundaries; AI Agents Regenerate the Binary:
Human engineers define the input/output schemas (ArenaDescriptor), hardware permissions (CapabilityMask), and output assertions (AssertContract).
Because verifying and compiling a .rl module takes microseconds, you never patch old AI-generated code. When requirements change, the AI regenerates the .rl module and verifies it from scratch.
Scheduling is Separate from Logic:
In C or Rust, adding SIMD intrinsics, cache tiling, and multi-threading tangles hardware tuning with business logic.
In Rul, the operation (opcode, in_a, in_b), the CPU schedule (schedule_hint), and the safety tags (proof_idx, token_op) sit in separate fields of each 16-byte instruction. Running rul autotune updates only the schedule byte.
At any time, engineers can run rul decompile to view the readable .rls listing or rul trace to inspect min, max, sum, NaN/Inf counts, and sample values at every instruction node #0..#N-1.
Where Rul is Today and Roadmap to v1.0
We intentionally restricted v0.1 through v0.4.0 to array and vector dataflow pipelines (29 opcodes at the v0.4.0 release) to prove the 16-byte binary instruction format, single-pass O(N) verifier, and zero-LLVM native ELF64 compiler on real hardware first.
Milestone 1 (v0.5.0 — Turing-Complete Core) and Milestone 2 (v0.6.0 — Ownership Across Joins, Linking & Rul Standard Library) are now shipped across a 68-opcode 128-bit ISA: structured control flow (Block, Loop, If, Else, End, Br, BrIf, BrTable), typed scalar locals, CAP_DIVERGE termination policy, I64/U8 bitwise & checked arithmetic, statically named, typestate-tracked growable regions (RegionLease, RegionEndLease, RegionMove, RegionDrop) with frame-rule FuncRegionEffect footprints and ArenaVersionTrieO(N + A) multi-arena joins, CAP_NONEStaticCostSummary + rul check --json, Section 5a read-only const_data segments (ConstDataLen, ConstDataLoad), typed CallIndirect, Section 5b link_meta separate verification & verified module linking (rul link), and a zero-new-opcode Rul standard library (stdlib/vec.rls, stdlib/string.rls, stdlib/hashmap.rls). All five v0.5 exit programs (Brainf*ck, fib, quicksort, sieve, sha256 at 1.13x–1.98x vs rustc -O) and all three linked v0.6 exit programs (JSON parser, in-memory KV store, and wc/grep at 1.55x–1.69x vs rustc -O, <= 2.0x gate, ~31 ns/nodeO(N) AOT codegen) pass Tier 0 == ELF64 AOT == rustc -O byte-for-byte.
We are executing a six-milestone roadmap (see ROADMAP.md) to expand Rul from a columnar compute engine into a general-purpose systems language capable of replacing Rust and Go for AI-generated software. Each milestone is defined by programs that must run identically in Tier 0 and as native binaries:
Integer and byte arithmetic, declared growable memory regions with runtime bounds checks, byte input and output, a function table with recursion guarded by host-independent call-depth and stack limits, and single-pass scalar register allocation. Exit programs passing Tier 0 == ELF64 AOT (1.13x–1.98x vs rustc -O): a Brainf*ck interpreter written in Rul, recursive fib, quicksort, a prime sieve, and sha256.
Milestone 2 (v0.6 — Shipped): Ownership Across Joins, Linking & Standard Library
Statically named, typestate-tracked region ownership and leases with frame-rule footprints across branches, loops, and calls in O(N), ArenaVersionTrieO(N + A) multi-arena joins, CAP_NONEStaticCostSummary + rul check --json, Section 5a read-only const_data segments, dense BrTable and typed CallIndirect, Section 5b link_meta + rul link verified module linking with zero silent capability escalation, and stdlib/ (Vec, String + RFC 3629 utf8_validate, HashMap) written in Rul with zero new opcodes. Linked exit programs passing Tier 0 == ELF64 AOT == rustc -O (1.55x–1.69x vs rustc -O): zero-GC json_parser, kv_store, and wc_grep.
Milestone 3 (v0.7): Capability-Gated Linux I/O & Columnar Bridge
File, clock, and network syscalls gated by fine-grained CapabilityMask bits, and a region-as-arena view so general programs call the columnar SIMD engine.
Share-nothing worker tasks and typed channels that transfer region ownership across cores, with an HTTP key-value server benchmarked against Go and Rust.
Milestone 5 (v0.9): C ABI FFI & AI Synthesis Benchmark
CAP_FFI-gated calls into C libraries, verifier diagnostics with repair hints, and a measured first-shot code generation benchmark.
Milestone 6 (v1.0): AArch64 Backend, Formal Proofs & Format Freeze
A second zero-LLVM native backend, continuous differential fuzzing, Kani proofs for the verifier, and the frozen .rlv1.0 format.
64-byte RulHeader (including Section 5a const_data and Section 5b link_meta lengths), 16-byte ArenaDescriptor table, 16-byte ProofEntry table (12 rule kinds), and 16-byte NodeFrame instructions across 68 opcodes (30 columnar dataflow opcodes, 30 v0.5 Turing-complete core opcodes, and 8 v0.6 ownership, constant-data, and dispatch opcodes).
Lossless .rls <-> .rl assembler and decompiler (assemble_rls, program_to_rls) including data seg, br_table, call_table, and module export/import directives.
Tier 0 (execute_tier0_interpreter): Reference interpreter and golden oracle (including structured control flow, regions, constant segments, BrTable, CallIndirect, and explicit heap-stack function calls).
Separately verifiable, zero-new-opcode Rul library modules (stdlib/vec.rls, stdlib/string.rls with RFC 3629 str::utf8_validate, and stdlib/hashmap.rls with 64-bit FNV-1a open addressing and tombstones) linked cleanly via rul link.
In-memory stdio JSON-RPC 2.0 MCP server (rul-mcp) providing 6 tools for AI agents: rul_assemble_and_verify, rul_test_differential, rul_autotune_schedule, rul_compile_standalone, rul_trace, and rul_cas_intrinsics.
Collision-safe 64-bit FNV-1a content-addressed store (RulCasStore) with I64/U8 kernels (sort, hash_join, group_by, simd_scan_byte, fnv1a_hash) and zero-panic #[repr(C)] embedding functions under #![forbid(unsafe_code)].
Toolchain Commands
# Install from prebuilt release tarball or source
curl -fsSL https://raw.githubusercontent.com/rul-lang/rul/main/install.sh | sh
# Or build and install with Cargo
cargo install --git https://github.com/rul-lang/rul --bins --force
# CLI workflow
rul new my-ai-pipeline
cd my-ai-pipeline
rul check # Run single-pass O(N) static verifier + StaticCostSummary (--json supported)
rul link a.rls b.rls -o app.rl # Verify and deterministically link modular .rl/.rls units
rul build # Assemble .rls -> build/main.rl and emit standalone ELF64 binary
rul run # Execute Tier 2 / Tier 0 + ELF64 AOT with differential verification
rul trace # Print per-node min/max/sum/NaN inspection table
rul autotune # Sweep ScheduleHint policies and pick fastest schedule
# Run the full 10-pipeline differential and AOT benchmark suite
rul-bench
# Run the MCP server for AI agents
rul-mcp
# Run all unit, verifier, differential, and AOT tests
cargo test
Documentation
ROADMAP.md: Six-Milestone Technical Roadmap from the v0.4 Columnar Engine through v0.5 Turing-Complete Core and v0.6 Ownership/Linking/Stdlib to the v1.0 General-Purpose Systems Language.
评论