Skip to content
Shachar Shemesh edited this page Dec 23, 2018 · 2 revisions

Integer types

U (uppercase) followed by (bit) width for unsigned, S for signed. Sizes are 8, 16, 32, 64 and 128. Examples:

S32 is C's int on most modern platforms. U128 is C's unsigned long long.

Implicit conversion between types is only possible if the destination type can hold all values the source type can. As such, U8 is implicitly convertible to all other unsigned types, as well as S16 and higher, but not to S8, as the later cannot hold the numbers 128 through 255. Signed types cannot be implicitly converted to unsigned types regardless of width.

Integer literals are automatically the smallest size that may hold them. To allow implicit conversion between, e.g., 0 and S8, integer literals may be of special internal use only types. These are __U7, __U15, __U31, __U63 and __U127. Examples:

0 is of type __U7, and is thus implicitly convertible to all user accessible types. 128 is of type U8, as is 255. 256 is of type __U15.

Statements and Expressions

Expressions

An expression is any sequence of operations or values that result in a value. This is, pretty much, the same was expressions are defined in any other language.

Statements

Statements are expressions without a value. One way to turn an expression into a statement is to add a semicolon (;) at its end. Unlike other languages, expressions that evaluate to void may be treated as expressions even without a semicolon.

Code blocks

A code block is a series of statements followed by one optional expression, grouped between an opening curly brace ({) and a closing one (}). If the code block ends with an expression, the code block as a whole is considered to have the value of that expression, and the code block itself is an expression, and can be used anywhere an expression can.

Example:

3 + { someFunction(); 7 }

Is a legal expression that equals 10.

Functions

Functions are defined with the def keyword, followed by the function name, its arguments in parenthesis, an arrow operator (->) and the function's body inside curly braces:

def function(arg1 : S32, arg2 : U64) -> U8 {
    0
}

Clone this wiki locally