SultanC – 一种阿拉伯语优先的系统编程语言
SultanC – an Arabic-first systems programming language

原始链接: https://github.com/sultan-language/sultanc

SultanC 是一种自托管的原生系统编程语言,具备所有权与借用检查、代数数据类型、模式匹配、泛型、线程以及可互换的阿拉伯语/英语关键字。其编译器用 SultanC 编写,并验证字节级自托管(Stage3 == Stage4)。它可从 C、WebAssembly 或现有编译器引导启动,并可选 LLVM 后端。它使用自有链接器为多种操作系统/架构目标及 WebAssembly 生成原生二进制文件,在 Linux 或 FreeBSD 上无需 libc。该语言支持错误作为值、编译时求值和经验证的中间表示(MSIR)。其标准库涵盖文本/Unicode、集合、文件、网络、数据格式、压缩、加密和并发。诊断信息可为阿拉伯语或英语,包括 JSON 输出,且解释器运行相同的 MSIR 与标准库。采用 MIT 许可证。

SultanC 是一种以阿拉伯语为先的编译型系统编程语言,由 Madyan(supax)创建,灵感来自他童年时因仅英文材料而学习编程的困难。它为关键词、类型和标准库提供阿拉伯语名称,并提供英文等价形式,允许一键切换阿拉伯语和英语。编译器用 SultanC 本身编写,为 arm64 macOS 和 x86_64 Linux 生成原生代码,并包含 LLVM 后端用于交叉编译。浏览器游乐场通过 WebAssembly 在 Web Worker 中运行完整编译器,无需服务器通信。阿拉伯语标识符会规范化 tatweel 和 alef 变体,错误消息可提供阿拉伯语或英语。该项目旨在帮助阿拉伯语初学者在先不学习英语的情况下开始编程。社区反馈还提出了文化本地化语法,例如阿拉伯语引号和阿拉伯-印度数字。
相关文章

原文

SultanC is a native systems language with ownership-aware safety, algebraic data types, pattern matching and threads. Its keywords exist in Arabic and English as equal, interchangeable surfaces of the same syntax. The compiler is written in SultanC and compiles itself: every build passes a byte-for-byte self-host check (Stage3 == Stage4).


Englishالعربية
def main(): int {
    let x: int = 40;
    let y: int = 2;
    return x + y;
}
عرف الرئيسية(): عدد {
    دع س: عدد = 40;
    دع ص: عدد = 2;
    أرجع س + ص;
}

Same AST, same semantics, same diagnostics: only the keywords and identifiers change.

git clone https://github.com/sultan-language/sultanc.git && cd sultanc
./build.sh                          # C Stage0 -> Stage1 -> Stage2 (needs LLVM)
sudo cp build/sultanc /usr/local/bin/sultanc
Route Command Needs
C bootstrap (default) ./build.sh C compiler + LLVM
WebAssembly seed ./build.sh --bootstrap=wasm only a C compiler
Rebuild from an existing compiler ./build.sh --bootstrap=existing a built build/sultanc (about a minute)
With the LLVM backend inside ./build.sh --enable-llvm LLVM 19–23
Self-host check ./build.sh verify Stage3 == Stage4, byte for byte

macOS with Homebrew LLVM: export LLVM_CONFIG="$(brew --prefix llvm)/bin/llvm-config" before building. Windows: ./build.sh --bootstrap=c --enable-llvm --backend=llvm.

sultanc main.sn -o app && ./app
  • Ownership, borrowing and move checking, verified statically before code generation
  • Algebraic data types and pattern matching, with exhaustiveness checking
  • Generics and compile-time evaluation (وقت_الترجمة)
  • Errors as values: نتيجة results, ؟ propagation, إنهيار / panic
  • Threads and synchronization: spawn/join, atomics, Arc, Mutex, Condvar, Once, channels, with a compile-time check on what a thread may capture
  • Arabic and English as equal source surfaces, including every diagnostic
  • A verified intermediate representation (MSIR): every pass goes through a checker before reaching a backend
  • Native output: ELF, Mach-O, PE/COFF and WebAssembly, with the compiler's own linkers; no libc needed on Linux and FreeBSD
sultanc check main.sn                       # type-check only
sultanc run main.sn                         # run in the interpreter, no compilation
sultanc --backend=llvm main.sn -o app       # LLVM backend (O2)
sultanc --target=aarch64-linux-gnu main.sn  # cross-compile
sultanc --lang=en check main.sn             # English diagnostics (Arabic by default)
sultanc --diagnostic-format=json check main.sn
sultanc targets                             # list every target

The interpreter runs the same MSIR and the same standard library as the compiler, on Linux, macOS, Windows and FreeBSD.

Area Highlights
Text and formatting UTF-8 text, Unicode segmentation and normalization, std.fmt (Rust-style format strings, checked at compile time)
Collections vectors with capacity, maps, sets, sorting
Files and processes files, directories, links, file locks, streaming child processes, environment
Networking TCP, UDP, Unix sockets, DNS, TLS 1.3, HTTP/1.1 and HTTP/2 (client and server)
Data formats JSON, TOML, CSV, zip, tar
Compression gzip/deflate, zstd, xz/LZMA2
Crypto and hashing SHA-2, X25519, Ed25519, ChaCha20-Poly1305, AES-GCM, XXH64, CRC
Concurrency std.thread, std.sync (atomics, Arc, Mutex, RwLock, Condvar, Once, channels)

See std coverage for the full list, compared with Rust and Go.

OS Architectures
Linux x86_64, aarch64, riscv64, loongarch64, ppc64le, s390x, mips64el, sparcv9, i686, armv7
macOS arm64, x86_64
Windows x64, arm64
FreeBSD x86_64, aarch64, riscv64
Android x86_64, aarch64, armv7
WebAssembly WASI (wasm32); freestanding wasm32/wasm64

Native backends for x86_64 and arm64; every other target goes through LLVM. See targets.

Architecture & MSIR How source becomes native code
Kernel architecture Compiler internals
Bootstrap The C Stage0 and the WebAssembly seed
Safety flow Ownership and borrow checking
Type system Types, inference, generics, casts
Ownership and destruction Moves, drops, temporaries, capacity
Errors Results, ؟, panics, localized messages
Concurrency Threads, atomics, synchronization
Formatting std.fmt
Interpreter sultanc run
Platform dependencies What std needs from each OS
Arabic terminology Canonical Arabic compiler vocabulary
Examples · Tests examples/ and the test runner

Self-hosting on x86_64-linux and arm64-darwin, verified by byte-identical convergence across compiler generations, from the C Stage0 and from the WebAssembly seed. CI builds every route on Linux, macOS and Windows (x64 and arm64).

MIT License

联系我们 contact @ memedata.com