An open API service indexing awesome lists of open source software.

https://github.com/webcien/u-lang

U is a Modern, Safe, and Lightweight systems programming language
https://github.com/webcien/u-lang

programming-language

Last synced: 8 days ago
JSON representation

U is a Modern, Safe, and Lightweight systems programming language

Awesome Lists containing this project

README

          

# U Language

**Modern, Safe, and Lightweight Systems Programming Language**

[![Version](https://img.shields.io/badge/version-1.6.0-blue.svg)](https://github.com/webcien/u-lang/releases/tag/v1.6.0)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://github.com/webcien/u-lang)

---

## 🚀 What is U?

U is a **systems programming language** that combines the best features of modern languages while maintaining simplicity and performance. It offers:

- **Memory Safety** through a complete ownership system (like Rust, but simpler)
- **Native GUI** with a declarative DSL (like Flutter/SwiftUI)
- **Actor-based Concurrency** without data races (like Erlang/Pony)
- **Modern Package Manager** for ecosystem growth (like Cargo)
- **Full Generics Support** with monomorphization and trait bounds
- **IDE Integration** via Language Server Protocol (LSP) and VS Code extension
- **Cross-Platform** compilation to Linux, Windows, macOS, and WebAssembly

U compiles to **clean C code** and uses **Zig** as a cross-compilation backend, resulting in:
- ⚡ **Zero runtime overhead**
- 🎯 **Predictable performance**
- 📦 **Tiny binaries** (no runtime, no GC)
- 🌍 **True cross-platform** support

---

## ✨ Key Features

### 1. Complete Ownership System

U implements a **7-rule ownership system** that guarantees memory safety without garbage collection:

```u
// Explicit deep copies with .clone()
let s1 = "hello";
let s2 = s1.clone(); // s2 is independent

// Multiple immutable references
let v = Vec_new();
let r1 = &v; // Immutable borrow
let r2 = &v; // OK: Multiple immutable borrows allowed

// Compile-time error on use-after-move
let x = Vec_new();
let y = x; // x is moved
// let z = x; // ERROR: use of moved value
```

**No explicit lifetimes. No borrow checker complexity. Just simple, safe code.**

### 2. Declarative GUI DSL

Build native user interfaces with a clean, declarative syntax:

```u
ui my_app {
Container {
width: 600,
height: 400,
background: rgb(230, 240, 255),
child: Column {
children: [
Text { text: "Hello, U Language!", size: 24 },
Button {
text: "Click Me",
onClick: handle_click
},
TextField { placeholder: "Enter text..." }
]
}
}
}
```

**Compiles to Skia rendering calls. Runs on desktop and mobile.**

### 3. Actor-Based Concurrency

Safe, scalable concurrency without locks or data races:

```u
actor Counter {
let mut count: i32 = 0;

fn increment() {
count = count + 1;
}

fn get_count() -> i32 {
return count;
}
}

fn main() {
let counter = spawn Counter;
send counter.increment();
let result = await counter.get_count();
return 0;
}
```

**Micro-runtime of only 5.3 KB. Zero overhead message passing.**

### 4. Modern Package Manager

Manage dependencies with a Cargo-like package manager:

```bash
# Create a new package
ul init my-package

# Install dependencies
ul install u-std

# Build your project
ul build --release

# Publish to registry
ul publish
```

**Package manifest (`ul.toml`):**
```toml
[package]
name = "my-package"
version = "1.0.0"

[dependencies]
u-std = "1.0.0"
u-gui = { version = "1.3.0", features = ["skia"] }
```

### 5. Full Generics Support

Write generic code that works with any type:

```u
// Generic function with trait bound
fn print_clonable(value: T) {
let cloned = value.clone();
unsafe { printf("Cloned!\n"); }
}

// Generic struct
type Point {
x: T,
y: T,
}

fn main() {
let p1 = Point { x: 10, y: 20 };
let p2 = Point { x: 1.0, y: 2.0 };
print_clonable(p1);
}
```

**Monomorphization generates specialized code for each concrete type at compile time.**

### 6. IDE Integration (LSP + VS Code)

First-class editor support with the U Language Server:

```bash
# Install the Language Server
cd lsp
cargo build --release

# Install VS Code extension
cd editors/vscode
npm install
npm run compile
code --install-extension u-language-1.4.0.vsix
```

**Features:**
- ✅ Autocompletion
- ✅ Go to definition
- ✅ Hover information
- ✅ Real-time diagnostics
- ✅ Syntax highlighting

### 7. Cross-Platform Compilation

Compile to any platform from any platform using Zig:

```bash
# Compile for Linux
ul build --target x86_64-linux

# Compile for Windows
ul build --target x86_64-windows

# Compile for macOS
ul build --target x86_64-macos

# Compile for WebAssembly
ul build --target wasm32-wasi
```

---

## 📦 Installation

### Prerequisites

- **Rust** (for building the compiler)
- **Zig** (for cross-compilation)
- **Git**

### Build from Source

```bash
git clone https://github.com/webcien/u-lang.git
cd u-lang/compiler
cargo build --release
```

The compiler binary will be at `target/release/ul`.

### Add to PATH

```bash
export PATH="$PATH:/path/to/u-lang/compiler/target/release"
```

---

## 🎯 Quick Start

### Hello World

Create `hello.ul`:

```u
fn main() {
unsafe {
printf("Hello, U Language!\n");
}
return 0;
}

extern "C" {
fn printf(format: ptr, ...);
}
```

Compile and run:

```bash
ul build hello.ul
./hello
```

### GUI Application

Create `gui_app.ul`:

```u
ui my_window {
Container {
width: 400,
height: 300,
background: rgb(255, 255, 255),
child: Text {
text: "Hello, GUI!",
size: 24,
color: rgb(0, 0, 0)
}
}
}

fn main() {
unsafe {
skia_init();
let surface = skia_create_surface(400, 300);
let canvas = skia_get_canvas(surface);
render_ui_my_window(canvas);
skia_save_png(surface, "output.png");
}
return 0;
}
```

Compile:

```bash
ul build gui_app.ul
```

---

## 📚 Documentation

- **[Language Guide](docs/)** - Complete language reference
- **[Standard Library](stdlib/)** - API documentation
- **[ul.toml Specification](docs/UL_TOML_SPEC.md)** - Package manifest format
- **[Examples](examples/)** - Sample programs

---

## 🏗️ Project Structure

```
u-lang/
├── compiler/ # U Language compiler (Rust)
│ └── src/
│ ├── lexer.rs # Tokenization
│ ├── parser.rs # AST generation
│ ├── type_checker.rs # Type validation
│ ├── ownership_checker.rs # Ownership validation
│ ├── concurrency_checker.rs # Concurrency validation
│ ├── optimizer.rs # Code optimization
│ ├── package_manager.rs # Package management
│ └── codegen/
│ └── c.rs # C code generation
├── runtime/ # Runtime libraries (C)
│ ├── actor_runtime.c # Actor system (5.3 KB)
│ ├── event_loop_sdl2.c # Event loop
│ ├── layout.c # Flexbox layout
│ └── skia_real.c # Skia integration
├── stdlib/ # Standard library (U)
│ ├── clone.ul # Clone trait
│ ├── option.ul # Option
│ ├── result.ul # Result
│ ├── vec.ul # Vec
│ └── hashmap.ul # HashMap
├── examples/ # Example programs
├── docs/ # Documentation
└── tests/ # Test suite
```

---

## 🛠️ Tooling

### Compiler Commands

| Command | Description |
|:---|:---|
| `ul build ` | Compile a U source file |
| `ul build --release` | Compile with optimizations |
| `ul build --target ` | Cross-compile to target platform |
| `ul fmt ` | Format source code |
| `ul lint ` | Lint source code |

### Package Manager Commands

| Command | Description |
|:---|:---|
| `ul init ` | Create a new package |
| `ul install ` | Install a dependency |
| `ul publish` | Publish package to registry |
| `ul update` | Update dependencies |

---

## 🎨 Standard Library

U provides a modern standard library with common data structures:

| Type | Description | File |
|:---|:---|:---|
| `Option` | Optional value | `stdlib/option.ul` |
| `Result` | Error handling | `stdlib/result.ul` |
| `Vec` | Dynamic array | `stdlib/vec.ul` |
| `HashMap` | Hash map | `stdlib/hashmap.ul` |
| `Clone` | Deep copy trait | `stdlib/clone.ul` |

---

## 🌟 Why U?

### vs. Rust
- ✅ **Simpler ownership** (no explicit lifetimes)
- ✅ **Native GUI DSL** (no external frameworks)
- ✅ **Smaller learning curve**
- ❌ No borrow checker complexity

### vs. Go
- ✅ **No garbage collection** (predictable performance)
- ✅ **Memory safety** (ownership system)
- ✅ **Native GUI** (no web-based UI)
- ❌ Smaller ecosystem (for now)

### vs. Zig
- ✅ **Memory safety** (ownership system)
- ✅ **Actor concurrency** (safe by default)
- ✅ **GUI DSL** (declarative UI)
- ❌ Uses Zig as backend (dependency)

### vs. C/C++
- ✅ **Memory safety** (no segfaults, no use-after-free)
- ✅ **Modern syntax** (type inference, traits)
- ✅ **Package manager** (dependency management)
- ✅ **Same performance** (compiles to C)

---

## 📈 Roadmap

### ✅ v1.6 (Q3 2026) - COMPLETED
- ✅ Native Windows compiler
- ✅ GUI with Skia integration
- ✅ Macro system
- ✅ Automatic linking scripts

### v1.7 (Q4 2026)
- Interactive GUI (event loop)
- Compile-time execution
- Advanced pattern matching
- Module system improvements

### v2.0 (Q4 2026)
- Async/await over actors
- LLVM backend (optional)
- Garbage collection (optional)
- WebAssembly improvements

---

## 🤝 Contributing

Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

### Development Setup

```bash
git clone https://github.com/webcien/u-lang.git
cd u-lang/compiler
cargo build
cargo test
```

---

## 📜 License

U Language is licensed under the **MIT License**.

See [LICENSE](LICENSE) for details.

---

## 🙏 Acknowledgments

U Language draws inspiration from:
- **Rust** - Ownership system and safety
- **Go** - Simplicity and tooling
- **Zig** - Cross-compilation and C interop
- **Pony** - Actor-based concurrency
- **Flutter/SwiftUI** - Declarative UI

Special thanks to the open-source community.

---

## 📞 Contact

- **Repository:** https://github.com/webcien/u-lang
- **Issues:** https://github.com/webcien/u-lang/issues
- **Discussions:** https://github.com/webcien/u-lang/discussions

---

## 🚀 Get Started

```bash
# Clone the repository
git clone https://github.com/webcien/u-lang.git

# Build the compiler
cd u-lang/compiler
cargo build --release

# Try an example
cd ../examples
../compiler/target/release/ul build hello.ul
./hello
```

**Welcome to U Language! 🎉**

---

**Copyright © 2025 Webcien and U contributors**