Skip to content
V8V88V8V88Public

About

XE: A fast, indentation-based programming language that compiles to standalone native binaries via Rust.

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Repository files navigation

XE Programming Language

The XE Programming Language

A fast, indentation-based programming language compiling to standalone native machine code via Rust.

Website • Documentation • Getting Started • Changelog • Issues

Latest Release CI Status License Documentation


What is XE?

XE is an expressive, indentation-based programming language built for developers who want the clean readability of Python with the execution speed and standalone binary output of native code.

XE compiles source files to Rust and builds them with rustc and LLVM into standalone native executables.

# Quick look at XE syntax
fun fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)

fun main():
    limit = 10
    print("Fibonacci sequence up to", limit)
    
    for i in range(limit + 1):
        print(f"fib({i}) = {fibonacci(i)}")

main()

Key Features

  • Native Performance: Compiles to native machine code via Rust; no interpreter.
  • Pythonic Syntax and Semantics: Indentation-based blocks, Python-style scoping, shared lists and maps, f-strings, comprehensions, unpacking, conditional expressions, default and keyword arguments, try/catch, lambda, slicing and +=.
  • Structs with Methods: Records with default field values and methods; method calls on known structs compile to direct native calls.
  • Type Inference: Numbers, text and booleans with known types, including function parameters and return values, compile to native f64, String and bool.
  • Multi-File Modules: Namespaced imports (import geometry, geometry.area(...)) and from helpers import format_name.
  • Batteries Included: Built-ins for text, lists, maps, math, files and command-line arguments.
  • Rich Diagnostics: Compiler and runtime errors show the file, line and source line.
  • Built-in CLI: One tool for running (with a build cache), compiling, installing and self-updating.

Installation

Quick Install (Linux / macOS / FreeBSD)

curl -fsSL https://xe-lang.vercel.app/install.sh | bash

To install to a custom directory:

XE_INSTALL_DIR="$HOME/bin" curl -fsSL https://xe-lang.vercel.app/install.sh | bash

Build from Source

Prerequisites: Rust toolchain (rustc & cargo 1.70+).

git clone https://github.com/V8V88V8V88/XE.git
cd XE
cargo build --release

# Install binary to ~/.local/bin
./target/release/xe install

Quick Start

Command Description
xe run <file.xe> Compile and execute an XE program immediately
xe compile <file.xe> -o <binary> Build an optimized standalone native binary
xe compile <file.xe> Emit generated Rust source code to stdout
xe update Check for and install the latest compiler release
xe --version Display compiler version
# Run a single file
xe run examples/hello.xe

# Compile to an optimized binary
xe compile examples/adventure.xe -o adventure
./adventure

# Run a multi-module program
xe run examples/modules/main.xe

Architecture & Pipeline

graph LR
    Source[".xe Source"] --> Lexer["Lexer\n(Tokens)"]
    Lexer --> Parser["Parser\n(AST)"]
    Parser --> Semantic["Semantic Analyzer\n(Type & Scope Checking)"]
    Semantic --> IR["Typed IR\n(Hybrid Inference)"]
    IR --> Codegen["Rust Code Generator"]
    Codegen --> Rustc["rustc Backend\n(Native Machine Code)"]
    Rustc --> Binary["Standalone Binary"]
Loading
  1. Lexer (lexer.rs): Scans tokens, indentation levels, and source spans.
  2. Parser (parser.rs): Validates grammar and builds the Abstract Syntax Tree (AST).
  3. Compiler Linker (compiler.rs): Resolves module dependency graphs and resolves names across modules.
  4. Semantic Analyzer (semantic.rs): Checks names, scopes and types, and infers native types for function parameters and return values.
  5. Codegen (codegen.rs): Generates Rust code on top of the runtime in runtime/prelude.rs. Built-in functions are defined once in builtins.rs.
  6. Backend (rustc): Compiles generated Rust directly to native platform binaries.

Language Overview

Variables & Data Types

name = "XE"           # Text (String)
version = 0.1         # Number (f64)
is_fast = true        # Boolean (bool)
items = [1, 2, 3, 4]  # List (shared, like Python)
user = {"name": "Ada"} # Map
nothing = none        # None

Control Flow

score = 85
count = 3

# If / Elif / Else
if score >= 90:
    print("Grade: A")
elif score >= 80:
    print("Grade: B")
else:
    print("Grade: C")

# For Loops (Lists & Strings)
for item in [10, 20, 30]:
    print(item)

for ch in "XE":
    print(ch)

# While & Repeat Loops
while count > 0:
    count = count - 1

repeat 5 times:
    print("Hello!")

Functions & Modules

# File: math_utils.xe
fun square(x):
    return x * x

# File: main.xe
from math_utils import square

print("5 squared is", square(5))

Structs, f-strings & Comprehensions

struct Point:
    x
    y = 0

    fun scaled(self, k = 2):
        return Point(self.x * k, self.y * k)

p = Point(3, y = 4).scaled()
print(f"p = ({p.x}, {p.y})")

squares = [n * n for n in range(5) if n > 0]
low, high = min(squares), max(squares)
print("big" if high > 10 else "small", low, high)

for i, word in enumerate(["xe", "lang"]):
    print(i, word.upper())

Performance Benchmark

A reproducible benchmark comparing XE with CPython on a recursive Fibonacci workload:

python3 examples/benchmark.py

On a recursive fib(32), XE runs about 15 times faster than CPython (0.013 s vs 0.21 s on the author's machine), because the inferred native types turn it into plain f64 Rust code.


Testing

# Run the full automated test suite
cargo test

# Run linter checks
cargo clippy --all-targets --all-features

To view or build the documentation locally:

cd docs
npm install
npm run docs:dev

Roadmap

  • Multi-file module dependency resolver & linker
  • Type inference with native types for parameters and return values
  • Python-style scoping, global, and shared values
  • Compiler and runtime errors with source locations
  • First-class functions and lambda expressions
  • Standard library: text, lists, maps, math, files, arguments
  • User-defined structs / records
  • try / catch error handling
  • f-strings, comprehensions, unpacking, default and keyword arguments
  • Struct methods
  • Language Server Protocol (LSP) and VS Code Extension

License

This project is licensed under the GPL-3.0-or-later license. See the LICENSE file for details.

About

XE: A fast, indentation-based programming language that compiles to standalone native binaries via Rust.

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages