basic-types
Basic Types
types — Type Definitions
Mapping of Nolang types to LLVM:
| Nolang | LLVM |
|---|---|
bool | i1 |
byte | i8 |
char | i32 |
i8/i16/i32/i64/i128 | i8/i16/i32/i64/i128 |
u8/u16/u32/u64/u128 | i8/i16/i32/i64/i128 |
f32 | float |
f64 | double |
str | %str-long = { i32, i32, i8* } (u32 len, u32 cap, data; 16 bytes on 64-bit, heap-allocated) |
[]t | %vec = { i32, i32, i64 } (u32 len, u32 cap, ptrtoint data; 16 bytes on 64-bit, heap-allocated) |
[n]t | [n x t] (bare aggregate, elements inline; no len / cap descriptor) |
txt | { [255 x i8], i8 } (fixed 256 bytes) |
Both
strand[]tstore len / cap asu32internally but expose them asi64. The descriptor boundary widens reads (zext i32 -> i64) and narrows writes (trunc i64 -> i32); the signatures ofs.len-bytes(),s.len(),s.cap(),v.len()and the private_len/_cap/_set-len/_set-capbuiltins all stayi64. See Strings: internal layout and public API and Memory model: type layout.%vecdeliberately keeps itsdatafield asi64(aptrtoint-encoded pointer) unlike thei8*in%str-long, so the two descriptors no longer share a layout and must not begetelementptr-ed as if they did.txthas nocapfield, keeps its length in onei8(0-255), and does not adopt u32.
Composite types:
- Variable-length array
[]t: underlying%vec = { u32 len, u32 cap, i64 data }(16 bytes;cap == 0marks a borrowed view that owns nothing) - Fixed-length array
[n]t: LLVM fixed-size array[n x t], elements inline, no runtime descriptor;.lenis the compile-time constantnand there is nocap - String
str: heap-allocated byte sequence with descriptor{ u32 len, u32 cap, i8* data }(16 bytes on 64-bit); supportss[i],s[i..j],s + t. Length / capacity are exposed asi64(s.len-bytes()/s.cap()) and stored asu32internally - 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 withstr, equal tot.count()),t.len-bytes()returns the byte count; indexingt[i]reads by code point (returning thecharat that code point,-1when out of range); writingt[i] = chas been banned globally since 2026-11-12 (compile erroridxwrite) — it re-encodescas UTF-8 and shifts the trailing bytes, so the length changes as a side effect (appending wheniequals the code-point count, silently dropping bytes beyond 255); to grow uset.push(c char)/t.push-str(s)/t.push-txt(u), and to overwrite in place use place-matcht[i]: { ok -> it = c }; raw byte-level reads uset.byte(i)(returns?byte, nil when out of range); to assemble atxtbyte-wise, gather a[]byteand copy it in once withtxt.from-bytes(b)(anything past 255 bytes is truncated; the length is set from the actual byte count). The raw byte-level writertxt._set-bytehas been std-private since 2026-11-11 and is unreachable from user code.str'ss[i] = vwas banned globally on 2026-11-11 (compile erroridxwrite,with-capbases no longer exempt either) — all that is left on thestrside iss.fill(val byte), place-matchs[i]: { ok -> it = v }, and the growth pairs.push(c)/s.push-str(s) - Enum/Union:
optiontagged 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 methodnext() (ok bool))
option — Option Type
option<t> tagged enum (tag=0=val, 1=nil, 2=err):
#{fmt-skip}
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.msg())
}
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.