Language Features

Marina is a strictly-typed subset of TypeScript, compiled ahead of time to LLVM IR. Programs use the .tsm extension and file names must be kebab-case.

Types & inference

TypeExample
Int8, Int16, Int32, Int64let a = 10 is Int32; let b: Int8 = -12
UInt8, UInt16, UInt32, UInt64let n: UInt8 = 255
Float32, Float64let x = 20.5 is Float64; let y: Float32 = 1.5
stringlet s = "hi"
boollet ok = true
Promise<T>return value of an async function
Array<T>let xs = [1, 2, 3]
interfacestructural data contracts
generic Ttype parameters on functions and classes

Annotations are available (let a: Int32 = 10, function f(x: Int8): void {}) and required for function parameters. There is no any.

Unsuffixed integer literals are Int32 when they fit, Int64 when they only fit in 64 bits, and UInt64 otherwise. A literal may be used as any integer or float type it fits in. Integer widths do not convert to each other, and signed does not convert to unsigned. Any integer widens to Float32 or Float64; Float32 widens to Float64. Arithmetic on two integers requires the same type (a literal adopts the other operand). If either operand is Float64 the result is Float64; a Float32 operand otherwise keeps the result Float32. Unary - is signed-only. String arithmetic is rejected — use template literals:

let a = 10              // Int32
let b = 20.5            // Float64
let result = a + b      // Float64 (a is widened)
let s: Int8 = -12
let w: Float32 = 1.5
let z = s + w           // Float32
console.log(`The result of ${a} + ${b} is ${result}`)

Aliases: i8/int8, i16/int16, i32/int/int32, i64/int64, u8/uint8 … u64/uint64, f32/float32, f64/float/float64/double.

Variables: let vs const

let declares a mutable variable; const declares an immutable one. Assigning to a const in any form (=, ++, --, +=, -=) is a compile-time error, and const declarations must be initialized. const freezes the binding, not the object — array contents can still be mutated through it.

Top-level variables are globals: they live for the whole program and are visible inside every function and lambda. Lambdas capture them by reference to the global — reads see the current value, and writes update the shared global.

Arrays

Typed lists with bounds-checked indexing (out-of-bounds panics at runtime) and reference counting. Element types are inferred, or taken from an annotation on an empty literal.

let xs = [1, 2, 3, 4, 5]          // Array<Int32>
xs.push(6); xs.pop(); xs.unshift(0); xs.splice(2, 1)
console.log(xs.length)

xs[0] = 10                          // index assignment
let strs: Array<string> = []
strs.push("hello"); strs.push("world")
console.log(strs.join("-"))          // hello-world

xs.forEach((item) => { console.log(item) })
let doubled = xs.map((item) => { return item * 2 })
let big = xs.filter((item) => { return item > 3 })
let sum = xs.reduce((acc, item) => { return acc + item }, 0)

Supported: push, pop, shift, unshift, splice, slice, concat, join, reverse, sort, length, plus the higher-order forEach / map / filter / reduce. Nested arrays work too.

Objects & classes

Objects are struct-of-fields values, ARC-managed. Two ways to get one:

Ghost classes — an object literal infers its shape at compile time. The checker mints an anonymous class from the literal; field types come from the values. No class definition needed, and the shape is still fully static:

let abc = {
    a: 5,          // Int32
    b: 6,          // Int32
    c: "Test"      // string
}
console.log(abc.a)   // 5
abc.b = 10           // field write

Accessing abc.d is a compile-time error. Declared classes define a named shape, instantiated with new. Fields and methods are public by default. private fields and methods are visible only inside the class's own methods and constructor:

class Point {
    public x: Float64
    private y: Float64
    label: string

    describe(): string {
        return `${this.label}`
    }
}
let origin = new Point()
origin.x = 0.0

With a class annotation on a let, an object literal must match the class field-for-field.

Generics

Functions and classes take type parameters, monomorphized at compile time — every distinct instantiation generates its own specialized copy, so generics cost nothing at runtime.

function pick<T>(a: T, b: T, takeFirst: bool): T {
    if takeFirst { return a }
    return b
}

class Box<T> { value: T, label: string }

let n = pick(10, 20, true)              // inferred: Int32
let box = new Box<Int32>()            // explicit type argument

Interfaces

interface declares a structural contract: any object — a ghost class (object literal) or a declared class — that has the interface's fields and public methods with matching types conforms to it, and extra fields are allowed. Method signatures look like TypeScript (name(params): Type, no body). Conformance is checked at compile time. Field access is resolved by name; a method call dispatches to the concrete class's method.

interface Point { x: Int32, y: Int32, name: string }
interface Named { name: string }
interface Titled { title(): string }

function describe(pt: Point): string {
    return `${pt.name}: ${pt.x}, ${pt.y}`
}

function show(t: Titled): string {
    return t.title()
}

let p = { x: 1, y: 2, name: "origin" }   // object literal conforms
let shapes: Array<Named> = [p, q, car]    // different concrete shapes

Inheritance & OOP

Classes support the TypeScript OOP surface: single inheritance (extends), interfaces (implements), abstract classes and methods, public/private/protected access, static members, get/set accessors and super. Overridden methods dispatch virtually on the runtime class id, so a base-typed array (Array<Shape>) runs the right subclass implementation.

abstract class Shape {
    protected originX: Float64        // subclass-visible
    static created: Int32             // class-level field

    constructor(originX: Float64) {
        this.originX = originX
        Shape.created = Shape.created + 1
    }

    abstract area(): Float64;         // no body: subclasses implement

    get origin(): string { return `(${this.originX}, 0)` }
}

class Circle extends Shape implements Describable {
    radius: Float64

    constructor(x: Float64, radius: Float64) {
        super(x)                      // base constructor call
        this.radius = radius
    }

    area(): Float64 { return 3.14 * this.radius * this.radius }

    override describe(): string {
        return `circle: ${super.describe()}`
    }
}

private members are usable only inside the defining class; protected also inside subclasses; everything else is a compile-time error. Statics (Shape.created) are inherited and stored as module globals. super.method() calls the base implementation directly; a subclass constructor must call super(...) when the base declares one. abstract classes cannot be instantiated.

Async / await

JS-style promises. Each async function compiles to an entry function plus a resume state machine — one basic block per continuation segment. await registers the frame with the runtime; when the promise resolves, the runtime resumes it on a worker thread. The program exits when the event loop reaches quiescence.

async function fetchData() {
    return new Promise((resolve) => {
        setTimeout(() => { resolve("Data fetched") }, 1000)
    })
}

async function main() {
    let data = await fetchData()
    console.log(data)
}

Control flow

if/else, while, C-style for, with ++, --, +=, -=. Loop conditions must be bool (no truthiness); the for init variable is scoped to the loop. Entry point: define main (sync or async).

Exceptions: try / catch / throw

throw raises an exception carrying a string message; try/catch handles anything raised inside it — including runtime panics (array index out of bounds, popping an empty array, fs/sql errors), which are catchable like in JavaScript. The catch binding is a string and is optional. Exceptions propagate across function calls to the nearest enclosing try; one that reaches the top of the program prints uncaught exception: ... (or marina runtime panic: ...) and exits with status 101. await is not allowed inside a try/catch block, and there is no finally.

let numbers = [1, 2, 3]

try {
    console.log(numbers[10])       // runtime panic: index out of bounds
} catch (err) {
    console.log(`caught: ${err}`)  // caught: array index 10 out of bounds (length 3)
}

try {
    throw "custom failure"
} catch {
    console.log("handled")
}

Under the hood this is a setjmp/longjmp handler stack in the runtime: each try pushes a frame, panics and throw longjmp into the innermost frame on the current thread (worker threads included), and uncaught exceptions abort with the usual message.

Standard libraries

Bring them in with a top-level import statement (import http). Full signatures and examples live on the standard library page.

ModuleWhat it provides
netraw TCP: net.connect(host, port) → Stream with write / read_all / close
httpclient (http.get/http.post), low-level http.listen server, and an express-style API: new http.Server, server.router, router.get/post, http.JsonValidator with chainable field validators
fsreadFile, writeFile, exists, readDir, mkdir, remove
cryptopure-C++ sha256, base64Encode/Decode, randomHex, uuid
sqlSQLite via prepared statements: new sql.Connection, sql.stmt`...` tagged templates, db.execute / db.query — values are always bound as parameters, never string-concatenated

How a program compiles

Lex & parse → strict type check → LLVM IR codegen (with ARC retain/release insertion and async state machines) → clang links libmarina_runtime.a into a native binary. The runtime exposes a stable C ABI (marina_retain, marina_release, marina_promise_create, marina_await, …) that the generated IR calls directly.