# cx-language
**Repository Path**: cxlang-offcial/cx-language
## Basic Information
- **Project Name**: cx-language
- **Description**: Self-hosting statically-typed language · Python VM + NASM native backend · try/catch · generics · concurrency
- **Primary Language**: Python
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2026-05-24
- **Last Updated**: 2026-06-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# CX Language




**A self-hosting, statically-typed systems programming language.**
**Dual backend: Python VM + x86-64 NASM native.**
---
## Quick Look
```cx
func Int main() {
var x = 42;
var name = "CX";
print("Hello, " + name + "!");
print(x);
if (x > 10) {
print("x is big");
}
var i = 0;
while (i < 5) {
i++;
}
var arr = [1, 2, 3, 4, 5];
arr[0] = 99;
try {
var z = 10 / 0;
} catch (e) {
print("Caught: " + e);
}
return 0;
}
```
---
## Features
| Category | Details |
|----------|---------|
| **Types** | `Int` `Str` `Bool` `Float` arrays `T[]` structs Dict/Map enum |
| **Control** | `if`/`elif`/`else` `switch`/`case` `for`(;;) `for-in` `while` `do-while` break continue |
| **Operators** | arithmetic `+ - * / %` bitwise `& | ^ ~ << >>` comparison `== != < > <= >=` logical `&& || !` ternary `? :` |
| **Functions** | named · lambda: `func(Int x) { return x+1; }` · default params · generic: `func[T]` |
| **Error** | `try` / `catch` |
| **Concurrency** | `go func()` — thread spawning |
| **Expressions** | type inference · array literals `[1,2,3]` · `arr[idx]=val` · constant folding · `++` `--` |
| **Backends** | Python VM (interactive) + x86-64 NASM native (no runtime dependency) |
| **Self-hosting** | `cxc.cx` compiles itself → MD5 verified |
| **Packages** | `import pkgname;` · `cx init/install/list` |
## Standard Library
```
io: out() outln() in() print() — auto-convert + newline
str: len() substr() split() contains() upper() lower()
reverse() trim() starts_with() ends_with() replace()
math: abs() pow() min() max() random() sqrt() floor() ceil()
sin() cos() log() exp()
types: Int() Str() Float()
fs: read() write() exists() delete() listdir()
time: now() sleep()
dict: new() set() get() has() keys() del()
json: parse() stringify()
regex: match()
http: get() post()
gfx: open() color() line() rect() circle() text() refresh()...
```
## Toolchain
```
cx — launcher menu cx repl — interactive REPL
cx run — compile & run (VM) cx build — compile to native exe
cx test — run test suite cx fmt — code formatter
cx init — create package cx install — install package
cx list — list packages cx gui — GUI editor
```
## Quick Start
```bash
# Run a .cx file
python cx.py run examples/demo.cx
# Compile to native (requires NASM + MinGW-GCC)
python cx.py build examples/demo.cx
# Interactive shell
python cx.py repl
# GUI editor
python cx.py gui
```
## Requirements
- Python 3.8+
- For native compilation: NASM + MinGW-GCC (Windows) or equivalent
## Specifications
| Metric | Value |
|--------|-------|
| Frontend | 1,300 lines (hand-written lexer + recursive descent parser + bytecode compiler) |
| Runtime | 650 lines (VirtualMachine with try/catch, generics, threading) |
| ASM Backend | 900 lines (NASM codegen) + 280 lines (C runtime) |
| Self-hosting | 2,100 lines of CX (cxc.cx — compiler written in CX itself) |
| **Total** | **~8,000 lines of Python + ~2,100 lines of CX** |
| License | MIT |
## Author
**Fanhua In Depressive Disorder**