Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax

Statements

End a binding, assignment, function call, or return statement with a semicolon (;). The closing brace ends an if or while statement. Newlines are whitespace, so a statement can span multiple lines, and a line can contain multiple statements.

A file can end with <- expression; to return the expression’s value to the host. A file without a return statement finishes without a value.

Comments

A line comment starts with // and runs to the end of the line or file. It can appear on its own line or after code.

Values

Oryn checks types before execution. A binding gets its type from its initializer, so count := 42; binds an integer and ready := count > 0; binds a boolean. An operation fails to compile if an operand has the wrong type. Both operands of && and || are checked, even when one would be skipped at runtime.

Integers

Oryn stores integers as signed 64-bit values. Integer literals are written in decimal, such as 42. Arithmetic can produce negative values.

Booleans

The boolean literals are true and false. You can bind them to names or use them directly as conditions.

Strings

Use double quotes for a string literal. A string can contain Unicode text, and // inside a string is literal text. String literals cannot contain line breaks, and escape sequences are unsupported.

message := "hello, 世界";

print(message);
<- message;

This file prints hello, 世界 and returns the string to the host.

Memory management

Oryn manages string memory automatically. A garbage collector can reclaim a string once it is no longer reachable from the program’s live values. Each execution has its own heap, which is released when execution ends.

Strings passed to native functions or returned to the host are copied into owned Rust values. An embedder can keep a returned value or clone a callback argument for use after execution.

Operators

Arithmetic

Addition (+)

left + right adds two integers and produces their sum.

Subtraction (-)

left - right subtracts the right integer from the left integer and produces their difference.

Multiplication (*)

left * right multiplies two integers and produces their product.

Division (/)

left / right divides the left integer by the right integer and produces their quotient, truncated toward zero. For example, 7 / 2 evaluates to 3, and (0 - 7) / 2 evaluates to -3. A zero divisor causes a division-by-zero error.

Grouping

Multiplication and division share a precedence level above addition and subtraction. Operators at the same precedence group from left to right, so 12 / 3 * 2 groups as (12 / 3) * 2. Parentheses can change the grouping.

print(1 - (2 + 3) + 7 / 2 * 4);

This file prints 8. The term 7 / 2 * 4 groups as (7 / 2) * 4, so the quotient is truncated to 3 before multiplication.

Overflow

If any arithmetic result falls outside the signed 64-bit integer range, evaluation fails with an integer overflow error.

Integer comparisons

OperatorTests whether the left integer is
>Greater than the right integer
>=Greater than or equal to the right integer
<Less than the right integer
<=Less than or equal to the right integer
==Equal to the right integer
!=Different from the right integer

Each comparison returns true or false.

Comparisons bind less tightly than arithmetic, so 2 + 3 == 5 compares (2 + 3) with 5. Write one comparison at a time. A chain such as 1 < 2 < 3 is a syntax error.

Boolean operators

!value flips a boolean. For example, !false evaluates to true. Applying ! to an integer causes a type error.

! binds more tightly than arithmetic and comparisons. To negate a comparison, wrap it in parentheses, as in !(score > 40).

left && right returns false immediately if left is false. left || right returns true immediately if left is true. Otherwise, the operator evaluates and returns right. Every operand that is evaluated must be a boolean.

Comparisons bind more tightly than &&, and && binds more tightly than ||. For example, ready || score >= 40 && score <= 100 checks whether ready is true or both comparisons are true.

Local bindings

Use name := expression; to declare an immutable binding.

base := 40;
factor := 3;

print(base + 2 * factor);

This file prints 46.

A binding is available after its initializer, so an initializer can refer to earlier bindings. Referencing an undefined name or declaring the same name twice is an error.

Names start with an ASCII letter or underscore and may also contain digits after the first character.

Mutable bindings

Use name :~ expression; to declare a mutable binding and name = expression; to assign a new value. The new value must have the type inferred from the initializer.

score :~ 38;

if score < 40 {
    score = score + 2;
}

print(score);

This file prints 40. A block can assign to a mutable binding in an enclosing scope. Function parameters are immutable.

Control flow

Conditionals

if condition { ... } runs its block when the condition evaluates to true. If the condition is false, Oryn runs the optional else block or continues after the statement. The condition must be a boolean.

score := 42;

if score >= 40 {
    print("Passed");
} else {
    print("Try again");
}

This file prints Passed. At file scope, a return inside a block exits the file. Bindings declared inside the block are visible only within that block and its nested blocks. A binding name must be distinct from any name already in scope.

While loops

while condition { ... } checks a boolean condition before each iteration. It runs the body while the condition is true and continues after the loop as soon as it is false. If it starts out false, the body never runs.

n :~ 1;
sum :~ 0;

while n <= 100 {
    sum = sum + n;
    n = n + 1;
}

print(sum);

This file prints 5050. Bindings declared in the body are local to that iteration. Assignments to mutable bindings in an enclosing scope persist into the next iteration.

Functions

Declare a function at file scope with a name, typed parameters, and a return type. The available type names are Int, Bool, and Str.

fib(n: Int) -> Int {
    if n <= 1 {
        <- n;
    }

    <- fib(n - 1) + fib(n - 2);
}

print(fib(30));

This file prints 832040. Top-level statements run in source order, and a function body runs when called. A call can refer to a function declared later in the file, or to the function currently running.

Each call gets its own parameters and local bindings. A function can call other functions in the file. Bindings declared outside the function are outside its scope.

The compiler checks argument counts and types. Every path through a function must return a value of its declared type using <- expression;. A return inside a function resumes its caller. At file scope, a return ends execution and gives the host a value.

A function call can be used as an expression or written as a statement with a semicolon. The statement form discards the returned value.

Output

Use print(value); to write a value followed by a newline. The CLI provides print by default and sends its output to stdout.

print(42);
<- 99;

oryn run prints 42. The value 99 is the file’s return value. Applications that embed Oryn choose which native functions to make available and where their output goes. Native function signatures specify how many arguments the function takes and which types it accepts. The compiler checks calls against those signatures. print accepts one value of any supported type.