Skip to main content

basic-types

Basic Types​

types — Type Definitions​

Mapping of Nolang types to LLVM:

NolangLLVM
booli1
bytei8
chari32
i8/i16/i32/i64/i128i8/i16/i32/i64/i128
u8/u16/u32/u64/u128i8/i16/i32/i64/i128
f32float
f64double
str{*byte, i64, i64} (data, len, cap, heap-allocated)
txt{ [255 x i8], i8 } (fixed 256 bytes)

Composite types:

  • Variable-length array []t: underlying { t*, i64 } (data, len)
  • Fixed-length array [n]t: LLVM fixed-size array
  • String str: heap-allocated byte sequence {*byte, i64, i64} (data, len, cap), supports s[i], s[i..j], s + t
  • Fixed string txt: fixed 256-byte struct { [255]byte data, byte len }, 255 bytes data + 1 byte storing the byte length (0-255), no heap allocation, requires type annotation (t txt = 'abc'); t.len() returns the code point count (aligned with str, equal to t.count()), t.len-bytes() returns the byte count; indexing t[i] is code-point based for both read and write — reading returns the char at that code point (out of range yields -1), writing t[i] = c re-encodes c as UTF-8 and shifts the trailing bytes (appending when i equals the code-point count, dropping bytes beyond the 255-byte cap); raw byte-level access uses the paired t.byte(i) / t.set-byte(i, b). Note that str's s[i] = v stays a byte-level write, an intentional divergence from txt
  • Enum/Union: option tagged enum (ok t / nil / err str)
  • Struct: must be defined across multiple lines; fields are not comma-separated
  • Map: underlying linked-hash-map
  • Iterator: for iter.next() {} (interface method next() (ok bool))

option — Option Type​

option<t> tagged enum (tag=0=val, 1=nil, 2=err):

x ?t ; Declare option<t>
x = 42 ; Set to a value
x = nil ; Set to nil
x = err('msg') ; Set to an error

; match
x: {
val -> f(it)
nil ->
err -> g(it)
}

Style guide: When a function may fail or return an empty value, use the ?t option instead of (val, ok bool). ?t has three states: ok (has value), nil (empty/normal absence), err (error). The normal value is bound implicitly. For example, pop() returns ?i64 (nil = empty), read-line() returns ?str (nil = EOF, err = error), lookup() returns ?str (nil = not found). See the syntax documentation for details.