展示 HN:Axis – 一种具有 Python 语法的系统编程语言
Show HN: Axis – A systems programming language with Python syntax

原始链接: https://github.com/AGDNoob/axis-lang

## AXIS:一种系统编程语言 AXIS 是一种新的、极简的系统编程语言,旨在提供 C 级别的性能,同时具有类似 Python 的语法。它直接编译为 x86-64 机器码,*无需*依赖外部链接器、汇编器或运行时库——从而产生小型、高效的可执行文件(约 4KB + 代码大小)。目前,它仅支持 Linux x86-64。 其关键原则包括零成本抽象、对系统资源的显式控制、与汇编代码的直接映射,以及对简单性的关注——目标是在一周内学会。AXIS 具有显式类型、默认的不可变变量和硬件原生整数类型(i8-i64, u8-u64)。 编译过程包括词法分析、语法分析、语义分析、代码生成和汇编,所有这些都由 Python 脚本处理。尽管仍处于早期开发阶段(MVP),AXIS 支持基本的控制流、算术运算、比较和函数调用。它优先考虑可预测的性能和通过系统调用进行直接系统访问。 AXIS 是一个实验性项目,正在进行中的开发重点是扩展功能、优化和平台支持。欢迎贡献!

## Axis:一种新的系统编程语言 AGDNoob推出了Axis,一种新的系统编程语言,作为编译器设计学习项目而构建。它直接编译为x86-64机器码,*不*使用LLVM或运行时,旨在实现零依赖和类似Python的可读性。目前仅支持Linux,代码量约为1500行Python,所有测试程序均可运行并可通过单个命令安装。 然而,初步反馈指出该语言的语法目前类似于Rust,尽管作者意图使其具有类似Python的特性。人们对嵌套`while`循环的潜在限制表示担忧,因为x86汇编中的寄存器分配可能存在挑战。 作者承认Axis的语法类似于Rust,并且实现基于缩进的语法很复杂,因此为了简化,在本初版本中选择了花括号。他们正在寻求对设计和方法的反馈,并愿意探索使Axis与Zig等现有语言区分开来的特性。该项目优先考虑一个最小的核心语言,并有可能在后期添加更高级的功能。
相关文章

原文

Version Platform License

A minimalist system programming language with Python-like syntax and C-level performance.

AXIS compiles directly to x86-64 machine code without requiring external linkers, assemblers, or runtime libraries.

⚠️ Platform Requirements: Linux x86-64 only (Ubuntu, Debian, Fedora, Arch, etc.)


One-Line Install (Recommended)

curl -fsSL https://raw.githubusercontent.com/AGDNoob/axis-lang/main/installer/standalone_install.sh | bash

This will:

  • ✅ Install AXIS compiler to ~/.local/bin
  • ✅ Set up the axis command
  • ✅ Optionally install VS Code extension
  • ✅ Configure your PATH automatically
# Clone repository
git clone https://github.com/AGDNoob/axis-lang
cd axis-lang

# Install
cd installer
./install.sh --user
# Write your first program
cat > hello.axis << 'EOF'
fn main() -> i32 {
    return 42;
}
EOF

# Compile to executable
axis build hello.axis -o hello --elf

# Run
./hello
echo $?  # Output: 42

AXIS follows four core principles:

  1. Zero-Cost Abstractions – You only pay for what you use
  2. Explicit Control – Stack, memory, and OS interactions are visible
  3. Direct Mapping – Source code maps predictably to assembly
  4. No Magic – No hidden allocations, no garbage collector, no virtual machine
  • Learnable in ≤1 week – Small, focused language
  • Immediately productive – Build real programs from day one
  • Predictable performance – Performance ceiling = C/C++
  • Systems access – Direct syscalls, full OS integration

AXIS provides hardware-native integer types with explicit sizing:

// Signed integers
i8      // -128 to 127
i16     // -32,768 to 32,767
i32     // -2,147,483,648 to 2,147,483,647
i64     // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

// Unsigned integers
u8      // 0 to 255
u16     // 0 to 65,535
u32     // 0 to 4,294,967,295
u64     // 0 to 18,446,744,073,709,551,615

// Other types
bool    // 0 or 1 (u8)
ptr     // 64-bit pointer

Type safety: All variables must be explicitly typed. No implicit conversions.

// Immutable by default
let x: i32 = 10;

// Mutable variables
let mut y: i32 = 20;
y = y + 5;  // OK

// Initialization is optional
let z: i32;  // Uninitialized (use with care)
// Basic function
fn add(a: i32, b: i32) -> i32 {
    return a + b;
}

// No return value
fn print_something() {
    // ...
}

// Entry point (must return i32)
fn main() -> i32 {
    return 0;
}

Calling convention: System V AMD64 (Linux)

  • First 6 arguments: rdi, rsi, rdx, rcx, r8, r9
  • Return value: rax (or eax for i32)
fn abs(x: i32) -> i32 {
    if x < 0 {
        return -x;
    } else {
        return x;
    }
}

// Without else
fn positive_check(x: i32) -> bool {
    if x > 0 {
        return 1;
    }
    return 0;
}
fn count() -> i32 {
    let mut i: i32 = 0;
    
    while i < 10 {
        i = i + 1;
    }
    
    return i;  // 10
}
fn find_even() -> i32 {
    let mut i: i32 = 0;
    
    while i < 100 {
        i = i + 1;
        
        if i == 50 {
            break;  // Exit loop
        }
        
        if i < 10 {
            continue;  // Skip to next iteration
        }
    }
    
    return i;
}
let a: i32 = 10 + 5;   // Addition
let b: i32 = 10 - 5;   // Subtraction
let c: i32 = 10 * 5;   // Multiplication (MVP: not implemented)
let d: i32 = 10 / 5;   // Division (MVP: not implemented)
let e: i32 = -10;      // Negation
x == y    // Equal
x != y    // Not equal
x < y     // Less than
x <= y    // Less than or equal
x > y     // Greater than
x >= y    // Greater than or equal

All comparisons return bool (0 or 1).

x = y     // Simple assignment
x = x + 1 // Compound expression
// Decimal
let dec: i32 = 42;

// Hexadecimal
let hex: i32 = 0xFF;      // 255
let hex2: i32 = 0x1A2B;   // 6699

// Binary
let bin: i32 = 0b1010;    // 10
let bin2: i32 = 0b11111111; // 255

// Negative
let neg: i32 = -100;

// Underscores for readability (ignored)
let big: i32 = 1_000_000;
// Single-line comments only
// Multi-line comments: use multiple single-line comments

fn example() -> i32 {
    // This is a comment
    let x: i32 = 10;  // Inline comment
    return x;
}

┌─────────────────────┐
│  Source Code        │  .axis file
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  Lexer              │  tokenization_engine.py
│  (Tokenization)     │  → Token stream
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  Parser             │  syntactic_analyzer.py
│  (Syntax Analysis)  │  → Abstract Syntax Tree (AST)
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  Semantic Analyzer  │  semantic_analyzer.py
│  (Type Checking)    │  → Annotated AST
└──────────┬──────────┘  → Symbol table
           │              → Stack layout
           ▼
┌─────────────────────┐
│  Code Generator     │  code_generator.py
│  (x86-64)           │  → Assembly instructions
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  Assembler          │  tets.py
│  (Machine Code)     │  → Raw x86-64 machine code
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  ELF64 Generator    │  executable_format_generator.py
│  (Executable)       │  → Linux executable
└─────────────────────┘

No runtime library. AXIS executables contain only:

  1. ELF64 Header (64 bytes)
  2. Program Header (56 bytes)
  3. _start stub (16 bytes) – Calls main() and invokes exit syscall
  4. User code – Your compiled functions

Entry point:

_start:
    xor edi, edi        ; argc = 0
    call main           ; Call user's main()
    mov edi, eax        ; exit_code = main's return value
    mov eax, 60         ; syscall: exit
    syscall             ; exit(code)

Virtual address space:

  • Base: 0x400000 (4MB, Linux standard)
  • Code: 0x401000 (page-aligned at 4KB)
  • Stack: Grows downward from high addresses

Function frame:

[rbp+0]    = saved rbp
[rbp-4]    = first local variable (i32)
[rbp-8]    = second local variable
...

Stack size is computed at compile-time and 16-byte aligned.


Prerequisites:

  • Operating System: Linux x86-64 (Ubuntu, Debian, Fedora, Arch, openSUSE, etc.)
  • Python: 3.7 or higher
  • Not supported: Windows, macOS, ARM/ARM64
git clone https://github.com/AGDNoob/axis-lang
cd axis-lang

No additional dependencies required (Python 3.7+ only).

Generate ELF64 executable (Linux):

python compilation_pipeline.py program.axis -o program --elf
chmod +x program
./program

Generate raw machine code:

python compilation_pipeline.py program.axis -o program.bin

Verbose output (show assembly):

python compilation_pipeline.py program.axis -o program --elf -v

Hex dump only (no output file):

python compilation_pipeline.py program.axis

AXIS includes a VS Code extension for syntax highlighting.

Install:

# Extension is already installed in: axis-vscode/
# Reload VS Code (Ctrl+Shift+P → "Developer: Reload Window")

Features:

  • Syntax highlighting for .axis files
  • Auto-closing brackets
  • Line comments via Ctrl+/
  • Build task: Ctrl+Shift+B

fn main() -> i32 {
    return 42;
}
$ python compilation_pipeline.py hello.axis -o hello --elf
$ ./hello
$ echo $?
42
fn main() -> i32 {
    let x: i32 = 10;
    let y: i32 = 20;
    let z: i32 = x + y;
    return z;  // 30
}
fn factorial(n: i32) -> i32 {
    let mut result: i32 = 1;
    let mut i: i32 = 1;
    
    while i <= n {
        result = result * i;
        i = i + 1;
    }
    
    return result;
}

fn main() -> i32 {
    return factorial(5);  // 120
}
fn max(a: i32, b: i32) -> i32 {
    if a > b {
        return a;
    }
    return b;
}

fn clamp(x: i32, min: i32, max: i32) -> i32 {
    if x < min {
        return min;
    }
    if x > max {
        return max;
    }
    return x;
}
fn is_prime(n: i32) -> bool {
    if n <= 1 {
        return 0;
    }
    
    let mut i: i32 = 2;
    while i < n {
        // Note: modulo operator not implemented in MVP
        // This is pseudocode for demonstration
        i = i + 1;
    }
    
    return 1;
}

fn count_primes(limit: i32) -> i32 {
    let mut count: i32 = 0;
    let mut i: i32 = 2;
    
    while i < limit {
        if is_prime(i) == 1 {
            count = count + 1;
        }
        i = i + 1;
    }
    
    return count;
}

fn main() -> i32 {
    return count_primes(100);
}

Calling Convention (System V AMD64)

Arguments:

Position i32 Register i64 Register
1st edi rdi
2nd esi rsi
3rd edx rdx
4th ecx rcx
5th r8d r8
6th r9d r9
7+ Stack Stack

Return value: eax (i32) or rax (i64)

Preserved registers: rbx, rbp, r12-r15

Offset  | Size | Section
--------|------|-------------------
0x0000  | 64   | ELF Header
0x0040  | 56   | Program Header (PT_LOAD)
0x0078  | ...  | Padding (to 0x1000)
0x1000  | 16   | _start stub
0x1010  | ...  | User code

Entry point: 0x401000 (_start)

Currently implemented:

  • exit(code): rax=60, rdi=exit_code

Planned:

  • write(fd, buf, len): rax=1
  • read(fd, buf, len): rax=0

⚠️ Current Limitations (MVP)

  • ELF64 executable format
  • Stack-based local variables
  • Control flow (if/else, while, break, continue)
  • Arithmetic (+, -)
  • Comparisons (==, !=, <, >, <=, >=)
  • Function calls (basic)
  • Integer types (i8-i64, u8-u64)
  • Mutable/immutable variables
  • VS Code syntax highlighting

Phase 5: Essential Operations

Phase 7: Advanced Features

Phase 8: Standard Library

Phase 9: Developer Experience


Compilation:

  • ~100ms for small programs (< 100 lines)
  • No external tools required

Runtime:

  • Zero overhead – No runtime library
  • Direct syscalls – No libc indirection
  • Native machine code – Same performance as C/C++
  • Minimal binary size – ~4KB + code size

Comparison:

Metric AXIS C (gcc) Python
Startup time <1ms <1ms ~20ms
Binary size ~4KB ~15KB N/A
Runtime deps None libc CPython
Compilation ~100ms ~200ms N/A

🏛️ Project Structure

axis-lang/
├── tokenization_engine.py          # Lexer
├── syntactic_analyzer.py           # Parser + AST
├── semantic_analyzer.py            # Type checker + Symbol table
├── code_generator.py               # x86-64 code generator
├── executable_format_generator.py  # ELF64 writer
├── compilation_pipeline.py         # Main compiler driver
├── tets.py                         # Assembler backend
├── axis-vscode/                    # VS Code extension
│   ├── package.json
│   ├── language-configuration.json
│   └── syntaxes/
│       └── axis.tmLanguage.json
├── tests/                          # Test programs
│   ├── test_arithmetic.axis
│   ├── test_control_flow.axis
│   └── syntax_test.axis
├── .vscode/
│   └── tasks.json                  # Build tasks
└── README.md

AXIS is an experimental language project. Contributions welcome!

Areas of interest:

  • Standard library design
  • Optimization passes
  • Language Server Protocol
  • More architectures (ARM64, RISC-V)
  • Windows support (PE format)

MIT License


Recommended reading:

Similar projects:

  • Zig – Systems language with manual memory management
  • Odin – Simple, fast, modern alternative to C
  • V – Fast compilation, minimal dependencies

Built with precision. No runtime overhead. Pure machine code.

AXIS – Where Python meets the metal.

联系我们 contact @ memedata.com