Rubix-lang README

The project's README from github.com/tek-sys-hub/Rubix-lang. As one markdown file: README.md.

Rubix Programming Language (.ix)

Rubix Logo

Rubix .ix File Icon

The Ultra-Lightweight x86-64 Systems Programming Language
Zero C. Zero libc. Zero LLVM. A ~42 KB compiler building standalone native binaries in sub-milliseconds.

   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—
   โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•
   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ•”โ• 
   โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— 
   โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•—
   โ•šโ•โ•  โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•

A sovereign systems programming language whose entire compiler is written in 100% pure x86-64 assembly.
Zero libc. Zero C. Zero LLVM. Zero Virtual Machines. Zero bloated toolchains.
Produces standalone native executables for Linux ELF64 and Windows PE64.


โšก 10-Second Syntax Preview

struct Point {
    x: int,
    y: int
}

fn hypot_squared(p: Point): int {
    return p.x * p.x + p.y * p.y;
}

fn main() {
    print_str("Hello from Rubix!\n");

    let pt = Point { x: 3, y: 4 };
    let dist = hypot_squared(pt);
    print(dist); // Prints: 25

    let pi: float = 3.141592;
    print(pi * 2.0); // Native SSE2 float math

    return 0;
}

๐ŸŽฏ Why Rubix? (vs. C or Zig)

Why choose Rubix over industry standards like C, Zig, or Rust?

๐Ÿ“Š Verify the Benchmarks Yourself

You can verify the sub-millisecond compilation time and tiny binary footprint directly on your machine:

# 1. Verify the tiny compiler binary footprint:
ls -lh rubix_compiler
# (Unstripped: ~64 KB | Stripped: ~49 KB)

# 2. Benchmark compile time on a comprehensive program:
time ./rubix_compiler examples/large_system_test.ix /dev/null
# Output: real 0m0.001s (instant sub-millisecond execution)

๐Ÿ“„ The .ix File Format & Identity

Rubix .ix File Icon Every Rubix program is authored in the sovereign .ix file format. Designed for pure systems-level performance, .ix source files are converted directly to native machine code by rubix_compiler and orchestrated via the ./rubixc driver. The official .ix file badge reflects Rubix's sharp geometric lineage and uncompromising fidelity to native hardware.



โšก Highlights


๐Ÿ—๏ธ Compiler Architecture

                       +-----------------------------------+
                       |    Rubix Source Code (.ix)        |
                       +-----------------------------------+
                                         โ”‚
                                         โ–ผ
+---------------------------------------------------------------------------------+
|                                 rubix_compiler                                  |
|                                                                                 |
|  [Lexer (src/lexer.s)]                                                          |
|    โ€ข Tokenizer converting source buffers into structured 32-byte token records  |
|                                         โ”‚                                       |
|                                         โ–ผ                                       |
|  [Parser (src/parser.s)]                                                        |
|    โ€ข Recursive descent parser with Pratt-style operator precedence              |
|    โ€ข Handles scopes, statements, expressions, control flow, loops & imports     |
|                                         โ”‚                                       |
|                                         โ–ผ                                       |
|  [Symbol Table (src/symtab.s)]                                                  |
|    โ€ข Lexical block scoping (up to 64 depth) and stack offset calculation       |
|    โ€ข Variable redeclaration guards and symbol lookup                            |
|                                         โ”‚                                       |
|                                         โ–ผ                                       |
|  [Code Generator (src/codegen.s)]                                               |
|    โ€ข Emits native x86-64 GNU assembly (.intel_syntax noprefix)                  |
|    โ€ข Generates .rodata string literals & links embedded assembly runtime        |
+---------------------------------------------------------------------------------+
                                         โ”‚
                                         โ–ผ
                       +-----------------------------------+
                       |      x86-64 Assembly (.s)         |
                       +-----------------------------------+
                                         โ”‚  (as + ld)
                                         โ–ผ
                       +-----------------------------------+
                       |    Universal Native Executable    |
                       |  (Direct Syscalls / No C / No VM) |
                       +-----------------------------------+
                                         โ”‚
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ–ผ                       โ–ผ                       โ–ผ
           [Host: Linux]          [Host: Windows]          [Host: macOS]
           Direct Linux           Dynamic kernel32        Direct Darwin
             Syscalls            PEB Export Resolver         Syscalls

๐Ÿ“ Repository Layout

project 2.0/
โ”œโ”€โ”€ Makefile              # Compiler build automation
โ”œโ”€โ”€ rubixc                # User-friendly compiler & runner script
โ”œโ”€โ”€ test.sh               # Complete 14-test verification suite
โ”œโ”€โ”€ src/                  # 100% Pure x86-64 Assembly Source Code
โ”‚   โ”œโ”€โ”€ main.s            # Entry point (_start), command line parser, file pipeline
โ”‚   โ”œโ”€โ”€ constants.s       # Linux syscall numbers, token types, buffer capacity limits
โ”‚   โ”œโ”€โ”€ strings.s         # String length, compare, copy, and integer conversion routines
โ”‚   โ”œโ”€โ”€ io.s              # Raw kernel file I/O & Rust-style diagnostic error reporting
โ”‚   โ”œโ”€โ”€ lexer.s           # Tokenizer & scanner (keywords, identifiers, literals, operators)
โ”‚   โ”œโ”€โ”€ symtab.s          # Lexical scope stack, symbol table buffer, and stack offsets
โ”‚   โ”œโ”€โ”€ codegen.s         # Instruction emitters, rodata manager, and standard library runtime
โ”‚   โ””โ”€โ”€ parser.s          # Recursive-descent parser, operator precedence, and loop frames
โ””โ”€โ”€ examples/             # Test & Demonstration Programs
    โ”œโ”€โ”€ 01_hello.ix       # Hello World string literal output
    โ”œโ”€โ”€ 02_arithmetic.ix  # Expressions, operator precedence, and variables
    โ”œโ”€โ”€ 03_control_flow.ix# While loops, if-else chains, and reassignments
    โ”œโ”€โ”€ 04_functions.ix   # Multi-parameter functions and recursive Fibonacci
    โ”œโ”€โ”€ 05_prime_numbers.ix# Prime number sieve demonstrating nested logic
    โ”œโ”€โ”€ 06_arrays.ix      # Dynamic heap allocation, indexing, and array literals
    โ”œโ”€โ”€ 07_types_and_logic.ix # Booleans, chars, logical operators (&&, ||, !), optional types
    โ”œโ”€โ”€ 08_many_params.ix # Unbounded 8-parameter function caller/callee stack passing
    โ”œโ”€โ”€ 09_modules.ix     # Multi-file module import system
    โ”œโ”€โ”€ 10_safe_math.ix   # Hardware integer overflow detection trap
    โ”œโ”€โ”€ 11_for_loops.ix   # Complete for loops (break, continue, nesting, dynamic arrays)
    โ”œโ”€โ”€ 12_stdlib.ix      # Embedded stdlib (File I/O, string manipulation, math routines)
    โ”œโ”€โ”€ large_system_test.ix # 200-element Quicksort, 4x4 matrix multiplication, and multi-file math
    โ””โ”€โ”€ comprehensive_large_test.ix # Grand stress test: 1,000-element Sieve, binary search, prefix sums

๐Ÿ“– Language Syntax & Capabilities

1. Variables & Basic Types

Rubix is statically typed with 64-bit integer primitives (int, bool, char). Type annotations are optional:

let count = 10;                # Inferred 64-bit int
let flag: bool = true;         # Explicit bool
let symbol: char = 'R';        # Character literal

2. Operators & Safe Arithmetic

Supports full precedence: (), !, - (unary), *, /, %, +, -, <, <=, >, >=, ==, !=, &&, ||. All arithmetic operations detect hardware overflow and terminate safely:

let x = (10 + 5) * 2 - 4 / 2;  # Precedence respected
let valid = (x > 10) && (!flag || x < 100);

3. For & While Loops with break and continue

for loops support <init>; <cond>; <step>, empty clauses, nested loops with isolated stack frames, and control jumps:

for (let i = 0; i < 20; i = i + 1) {
    if (i >= 15) {
        break;      # Exits loop early
    }
    if (i % 2 == 0) {
        continue;   # Skips to step clause (i = i + 1)
    }
    print(i);       # Prints 1, 3, 5, 7, 9, 11, 13
}

4. Dynamic Heap Memory & Arrays

Direct interaction with the Linux memory manager via alloc and free (mmap/munmap):

# Dynamic array allocation
let size = 100;
let arr = alloc(size * 8);

for (let i = 0; i < size; i = i + 1) {
    arr[i] = i * i;
}
print(arr[9]);      # Prints 81
free(arr, size * 8);

# Array literal initialization
let primes = [2, 3, 5, 7, 11, 13, 17];
print(primes[4]);   # Prints 11

5. Functions & Unbounded Parameters

Functions adhere to the AMD64 System V ABI. When more than 6 arguments are supplied, additional arguments are seamlessly spilled and retrieved from the stack frame:

fn compute_sum(a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int): int {
    return a + b + c + d + e + f + g + h;
}

fn main(): int {
    let sum = compute_sum(1, 2, 3, 4, 5, 6, 7, 8);
    print(sum);      # Prints 36
    return 0;
}

6. Multi-File Module System

Split code across multiple files with automatic cycle prevention and deduplication:

import "examples/math_lib.ix";

fn main(): int {
    let result = compute_cube(5);
    print(result);   # Prints 125
    return 0;
}

7. Embedded Standard Library Reference

Every Rubix binary includes a built-in standard library with zero external runtime requirements:

Module Function Description
I/O print(val) Prints a 64-bit signed integer followed by a newline
print_str(expr) Prints a static or dynamic null-terminated string
print_char(c) Prints a single ASCII character
File I/O file_open(path, flags, mode) Calls Linux sys_open (syscall 2)
file_read(fd, buf, count) Calls Linux sys_read (syscall 0)
file_write(fd, buf, count) Calls Linux sys_write (syscall 1)
file_close(fd) Calls Linux sys_close (syscall 3)
Strings str_len(s) Returns length of null-terminated string
str_cmp(s1, s2) Compares strings (0 if equal)
str_copy(dst, src) Copies source string into destination buffer
str_cat(dst, src) Concatenates source onto destination buffer
puts(s) Writes null-terminated string to stdout
Math math_abs(x) Absolute value
math_min(a, b) Minimum of two integers
math_max(a, b) Maximum of two integers
math_pow(base, exp) Integer exponentiation ($base^{exp}$)
math_sqrt(n) Integer square root ($\lfloor\sqrt{n}\rfloor$)
Memory alloc(bytes) Allocates memory via sys_mmap (syscall 9)
free(ptr, bytes) Releases memory via sys_munmap (syscall 11)

8. Universal Multi-OS Architecture (Linux, Windows, macOS)

Rubix binaries break the operating system barrier by incorporating an adaptive native runtime:

[!NOTE] Platform & Cross-Compilation: Rubix natively targets both Linux ELF64 and Windows PE64 (.exe) platforms directly from GNU ld without external dependencies. The multi-OS entry vectors and Windows PEB resolver are verified on host systems.


๐Ÿ’Ž Advanced Systems Capabilities

1. Floating-Point Numbers (f64 / Double Precision) & Type System

Full IEEE-754 64-bit double-precision support with type-aware symbol table resolution, native SSE2 machine code emission (addsd, subsd, mulsd, divsd), and polymorphic print():

let pi: float = 3.141592;
let rad = 2.5;

// Native SSE2 arithmetic (+, -, *, /) and mixed int-float operations
let area = pi * rad * rad;
print(area); // 19.634950 (automatically dispatches to float formatting)

// Typed function parameters and return types
fn hypot(a: float, b: float): float {
    return a * a + b * b;
}

Built-in math routines (float_add, float_sub, float_mul, float_div, float_to_int, int_to_float, print_float) remain fully available for backwards compatibility.

2. Struct Declarations & Dynamic Instances

User-defined compound data structures with compile-time offset layout, heap instantiation, and member access/mutation:

struct Vector3 {
    x: int,
    y: int,
    z: int
}

fn main() {
    let v = Vector3 { x: 10, y: 20, z: 30 };
    print(v.x);
    v.z = v.x + v.y;
    print(v.z); // 30
    free(v, 24);
    return 0;
}

3. DWARF Debug Information (gdb / lldb)

The compiler generates native DWARF .file and .loc debug directives mapping machine instructions directly back to .ix source lines:

./rubixc -g examples/01_hello.ix -o hello_dbg
gdb ./hello_dbg
# (gdb) break 3
# (gdb) run
# Breakpoint 1, main () at examples/01_hello.ix:3

4. Cross-OS Compilation (Windows PE64)

Produce real 64-bit Windows console executables directly on Linux:

./rubixc -t windows examples/01_hello.ix -o hello.exe
file hello.exe
# hello.exe: PE32+ executable for MS Windows 5.02 (console), x86-64

5. Separate Compilation & Static Object Linking

Compile individual .ix files into ELF relocatable objects (.o) and link multiple units:

./rubixc -c module1.ix -o module1.o
./rubixc -c module2.ix -o module2.o
./rubixc module1.o module2.o -o my_app

๐Ÿ› ๏ธ Rich Diagnostic Error Reporting

Rubix produces clear, informative compile-time diagnostics pointing directly to the offending token:

Rubix Compiler Error: Expected expression
  --> line 4
   |
 4 |     let x = ;
   | ^

๐Ÿš€ Quickstart & Usage

Prerequisites

1. Build the Compiler (or Download Prebuilt)

make clean && make

Produces rubix_compiler (the standalone ~42 KB binary).

[!TIP] Prebuilt Binaries: If you don't want to build from source, standalone prebuilt binaries for Linux x86-64 are available on the GitHub Releases page.

2. Compile and Run a Program

Use the ./rubixc compiler driver:

# Compile and immediately run
./rubixc -r examples/15_floats.ix
./rubixc -r examples/16_structs.ix
./rubixc -r examples/17_native_floats.ix
./rubixc -r examples/18_compiler_fixes.ix

# Compile for Windows PE64
./rubixc -t windows examples/01_hello.ix -o hello.exe

# Compile with DWARF debug info
./rubixc -g examples/01_hello.ix -o hello_dbg

3. Run the Entire Test Suite

./test.sh

Executes all 19 test suites verifying the compiler build, arithmetic, control flow, functions, prime algorithms, dynamic arrays, modules, loops, standard library, floats, structs, native float SSE2 operators, Windows cross-linking, separate compilation, and compiler bug fixes.


๐Ÿ”„ Self-Hosting & Compiler Status


๐Ÿ“œ License

Created with precision in pure x86-64 Assembly. Free and open source under the MIT License.

Rubix-lang (tek-sys-hub/Rubix-lang)

Searching Databaseโ€ฆ

29 ยทGitHub

> A sovereign systems programming language whose entire compiler is written in 100% pure x86-64 assembly. > Zero libc. Zero C.

Size
0.9 MB
Stars
29
Updated
CommitOct 22
Age
4d
Commits ยท 90 Days