Overview

Language Overview

Sun uses a C-style syntax with explicit type annotations and modern features. Functions are declared with the function keyword, types follow variable names after a colon, and blocks are delimited by curly braces. The language prioritizes readability and unambiguity — there are no lossy implicit conversions (a number only widens on its own), no operator overloading, and no macros.

Identifier Naming

⚠️

Identifiers starting with _ (underscore) are reserved for compiler builtins and cannot be used for user-defined names.

function _helper() i32 { ... }  // ❌ ERROR: reserved identifier
var _count: i32 = 0;            // ❌ ERROR: reserved identifier
 
function helper() i32 { ... }   // ✓ OK
var count: i32 = 0;             // ✓ OK

Reserved Words

The following words are keywords and cannot be used as names for variables, functions, parameters, fields, classes, interfaces, enums, or modules. Using one where a name is expected is reported as 'partial' is a reserved word and cannot be used as an identifier.

GroupWords
Declarationsvar, const, function, lambda, class, packed_class, partial, interface, enum, implements, public, def, declare, extern
Modulesmanifest, module, using
Control flowif, else, match, for, while, break, continue, return
Errorstry, catch, throw
Literalstrue, false, null, this
Operatorsand, or, not
Typesi8, i16, i32, i64, u8, u16, u32, u64, f32, f64, bool, void, array, ref, ptr, raw_ptr, static_ptr
Otherspawn, unsafe

A few words only have meaning in one position and remain usable as names: in (in a for loop) and as (in an extern declaration).

var partial = 1;   // ❌ ERROR: 'partial' is a reserved word
var in: i32 = 5;   // ✓ OK: `in` is only a keyword inside `for (...)`

Primitive Types

Sun provides the following primitive types:

TypeDescription
i8, i16, i32, i64Signed integers
u8, u16, u32, u64Unsigned integers
f32, f64Floating-point numbers
boolBoolean (true or false)
voidNo return value

Variable Declaration

Variables are declared with var and require explicit type annotations:

var x: i32 = 42;
var name: static_ptr<u8> = "Sun";
var flag: bool = true;

A value that never changes is declared with const instead. It can be read, borrowed with const ref, and moved, but never assigned to or changed in place. See Constants.

const MAX_RETRIES: i32 = 3;
const greeting = String(alloc, "hello");

Comments

Sun supports single-line and block comments:

// This is a comment
var x: i32 = 42;  // Inline comment
 
/* Block comment,
   possibly spanning multiple lines */
var y: i32 = /* inline */ 7;

Block comments do not nest.