Introduction

Sun Programming Language

Sun is a general-purpose programming language designed particularly with the needs of robotics and AI in mind. It provides Rust-style memory safety while retaining a familiar syntax and classic concepts such as classes and interfaces. Sun optimizes for both performance and intelligibility for human programmers as well as AI coding agents. Sun additionally aims to improve software distribution in robotics applications by making it easier to package and distribute portable, systems-level software modules.

Design Goals

  • Fast: Systems-level performance without runtime overhead
  • Designed for Robotics: Robotics software typically involves dozens to hundreds of processes that run across one or more compute nodes and communicate over a DDS (opens in a new tab) using some kind of pub-sub middleware (e.g. ROS (opens in a new tab)). The standard message serialization format is protobuf, which Sun provides built-in support for. A custom DDS and middleware are on the roadmap.
  • Designed for AI: NumPy-like N-D matrices and linear algebra are provided in the standard library. Built-in support for hardware accelerators/GPUs using LLVM Offload is on the roadmap.
  • Memory safe: No undefined behavior via Rust-style borrow checking
  • Readable: Straightforward for humans (and AIs!) to read and understand
  • Unambiguous: Minimizes alternative syntaxes and hidden control flow such as operator and constructor overloading. No hidden memory allocation. Absolutely no macros!
  • Modular: Simple to package and distribute pre-compiled modules.
⚠️

These are goals and not claims about the language's current capabilities.

Hello World

Here's a minimal hello-world program:

hello.sun
using sun;
 
function main() void {
    println("Hello, Sun!");
}
 
manifest {
    moons: ["stdlib.moon"]
}

Run directly with JIT:

export SUN_PATH=/path/to/sun/build
sun hello.sun
Hello, Sun!

Or compile to a native executable:

sun -c -o hello hello.sun
./hello
Hello, Sun!

Installation

Ubuntu (Debian Package)

Download and install the latest dev build:

curl -LO https://github.com/namo-robotics/sun/releases/download/dev/sun_0.dev_amd64.deb
sudo apt install ./sun_0.dev_amd64.deb

Use apt rather than dpkg -i so the dependencies are pulled in: sun -c links through the system C compiler, so it needs gcc, libc6-dev and the libstdc++ development files. On releases without LLVM 20 in the archive, add apt.llvm.org (opens in a new tab) first so libllvm20 can be found.

To update, download and install the new package.

Uninstalling

To uninstall the Debian package:

sudo dpkg -r sun

Build from Source

# Clone the repository
git clone https://github.com/namo-robotics/sun.git
cd sun
./build.sh

Quick Start

Create a Sun program:

hello.sun
using sun;
 
function main() i32 {
    println("Hello, Sun!");
    return 0;
}
 
manifest {
    moons: ["stdlib.moon"]
}

JIT Execution

Set SUN_PATH to the directory containing stdlib.moon:

export SUN_PATH=/path/to/sun/build
sun hello.sun
Hello, Sun!

Compile to native executable

sun -c -o hello hello.sun
Compiling: hello.sun -> hello
Successfully compiled to: hello
./hello 
Hello, Sun!

Inspect generated LLVM IR

$ sun --emit-ir -c hello.sun 
Compiling: hello.sun -> hello
; LLVM IR (reachable from main):
define void @"$340e67ad$_sun_println"(%static_ptr_struct %s) {
entry:
  %s1 = alloca %static_ptr_struct, align 8
  store %static_ptr_struct %s, ptr %s1, align 8
  %s2 = load %static_ptr_struct, ptr %s1, align 8
  %str.data = extractvalue %static_ptr_struct %s2, 0
  call void @__sun_print_string(ptr %str.data)
  call void @__sun_print_newline()
  ret void
}
 
define internal void @__sun_print_newline() {
entry:
  %0 = alloca i8, align 1
  store i8 10, ptr %0, align 1
  %syscall_write = call i64 asm sideeffect "syscall", "={rax},{rax},{rdi},{rsi},{rdx},~{rcx},~{r11},~{memory}"(i64 1, i32 1, ptr %0, i64 1)
  ret void
}
 
define internal void @__sun_print_string(ptr %0) {
entry:
  %1 = alloca i64, align 8
  store i64 0, ptr %1, align 4
  br label %strlen_loop
 
strlen_loop:                                      ; preds = %strlen_loop, %entry
  %2 = load i64, ptr %1, align 4
  %3 = getelementptr i8, ptr %0, i64 %2
  %4 = load i8, ptr %3, align 1
  %5 = icmp eq i8 %4, 0
  %6 = add i64 %2, 1
  store i64 %6, ptr %1, align 4
  br i1 %5, label %write, label %strlen_loop
 
write:                                            ; preds = %strlen_loop
  %7 = load i64, ptr %1, align 4
  %8 = sub i64 %7, 1
  %syscall_write = call i64 asm sideeffect "syscall", "={rax},{rax},{rdi},{rsi},{rdx},~{rcx},~{r11},~{memory}"(i64 1, i32 1, ptr %0, i64 %8)
  ret void
}
 
define void @main() {
entry:
  call void @"$340e67ad$_sun_println"(%static_ptr_struct { ptr @str, i64 11 })
  ret void
}
 
Successfully compiled to: hello

Debug Mode

Use --debug to generate debugging artifacts in a <filename>_debug/ folder:

sun --debug hello.sun
Debug output folder: hello_debug/
  Generated: hello_debug/ast.dot
  Generated: hello_debug/scope_tree.html
  Generated: hello_debug/ir.ll
Hello, Sun!

This creates:

  • ast.dot — GraphViz visualization of the AST
  • ir.ll — Full LLVM IR output
  • scope_tree.html — HTML visualization of semantic scopes

Visualize the AST:

dot -Tpng hello_debug/ast.dot -o ast.png

Manifests

Sun programs declare their dependencies using a manifest block:

manifest {
    suns: ["utils.sun", "math.sun"]    // Source files to compile together
    moons: ["stdlib.moon"]              // Precompiled libraries to link
}

Paths are resolved relative to the source file, then via SUN_PATH.

Moons

Moons (.moon files) are precompiled library bundles containing compiled code and type information. Create a moon from an entry point with a manifest:

mylib.sun
public module mylib {
    public function helper() i32 { return 42; }
}
 
manifest {
    suns: ["utils.sun", "math.sun"]
}
sun --emit-moon -o mylib.moon mylib.sun

Sun is designed to work with Moon, a safety-critical package manager (coming soon) that will provide:

  • Exact matching: Dependencies are pinned to the exact hash of the binary and compiler version — every change is a breaking change
  • Verified builds: Reproducible compilation with cryptographic verification
  • Trusted sources: Security auditing based on verified, trustworthy package sources
  • Static bundling: No dynamic linkage — moons and binaries include all dependencies in a single file

Quick Links