nanolang

nanolang

A tiny experimental language designed to be targeted by coding LLMs

Stars: 526

Visit
 screenshot

NanoLang is a minimal, LLM-friendly programming language that transpiles to C for native performance. It features mandatory testing, unambiguous syntax, automatic memory management, LLM-powered autonomous optimization, dual notation for operators, static typing, C interop, and native performance. The language supports variables, functions with mandatory tests, control flow, structs, enums, generic types, and provides a clean, modern syntax optimized for both human readability and AI code generation.

README:

NanoLang

CI License Bootstrap

A minimal, LLM-friendly programming language with mandatory testing and unambiguous syntax.

NanoLang transpiles to C for native performance while providing a clean, modern syntax optimized for both human readability and AI code generation.

📖 Documentation

User Guide - Start here! Comprehensive tutorial with executable examples

Additional Resources:

Quick Start

# Clone and build
git clone https://github.com/jordanhubbard/nanolang.git
cd nanolang
make build

# Create hello.nano
cat > hello.nano << 'EOF'
fn greet(name: string) -> string {
    return (+ "Hello, " name)
}

shadow greet {
    assert (== (greet "World") "Hello, World")
}

fn main() -> int {
    (println (greet "World"))
    return 0
}

shadow main { assert true }
EOF

# Compile and run
./bin/nanoc hello.nano -o hello
./hello

BSD users: Use gmake instead of make.

Key Features

  • Automatic Memory Management (ARC) ⭐ - Zero-overhead reference counting, no manual free() calls (v2.3.0)
  • LLM-Powered Autonomous Optimization ⭐ - Continuous profiling and automatic optimization loop (v2.3.0)
  • Dual Notation - Both prefix (+ a b) and infix a + b operators supported
  • Mandatory Testing - Every function requires a shadow test block
  • Static Typing with type inference
  • C Interop - Easy FFI via modules
  • Native Performance - Transpiles to optimized C

Language Overview

# Variables (immutable by default)
let x: int = 42
let mut counter: int = 0

# Functions with mandatory tests
fn add(a: int, b: int) -> int {
    return (+ a b)
}

shadow add {
    assert (== (add 2 3) 5)
}

# Control flow
if (> x 0) {
    (println "positive")
}

# Structs and enums
struct Point { x: int, y: int }
enum Status { Pending = 0, Active = 1 }

# Generic types
let numbers: List<int> = (List_int_new)
(List_int_push numbers 42)

Building & Testing

make build          # Build compiler (bin/nanoc)
make test           # Run full test suite
make test-quick     # Quick language tests only
make examples       # Build all examples

Examples & Interactive Tools

Web Playground (recommended for learning):

./bin/nanoc examples/playground/playground_server.nano -o bin/playground
./bin/playground  # Open http://localhost:8080

Examples Browser (requires SDL2):

cd examples && make launcher

Individual examples:

./bin/nanoc examples/language/nl_fibonacci.nano -o fib && ./fib

See examples/README.md for the complete catalog including games (Snake, Asteroids, Checkers) and graphics demos.

Platform Support

Fully supported:

  • Ubuntu 22.04+ (x86_64, ARM64)
  • macOS 14+ (Apple Silicon)
  • FreeBSD

Windows: Use WSL2 with Ubuntu.

For LLM Training

NanoLang is designed for AI code generation:

  • MEMORY.md - LLM training reference with patterns and idioms
  • spec.json - Formal language specification

Contributing

See CONTRIBUTING.md for guidelines.

License

Apache License 2.0 - See LICENSE for details.

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for nanolang

Similar Open Source Tools

For similar tasks

For similar jobs