Standard library

std

Types

type File = *cstd::s__IO_FILE
type UnixTime = uint64

Variables

const PATH_MAX: int = 4096
const MAX_UINT8: uint8 = 255
const MAX_UINT16: uint16 = 65535
const MAX_UINT32: uint32 = 4294967295
const MAX_UINT64: uint64 = 18446744073709551616
const MIN_INT8: int8 = -128
const MIN_INT16: int16 = -32768
const MIN_INT32: int32 = -2147483648
const MIN_INT64: int64 = ...
const MAX_INT8: int8 = 127
const MAX_INT16: int16 = 32767
const MAX_INT32: int32 = 2147483647
const MAX_INT64: int64 = 9223372036854775808
const SEEK_SET: int = 0
const SEEK_CUR: int = 1
const SEEK_END: int = 2

Functions

def stdin() -> File
def stdout() -> File
def stderr() -> File
def combine_hashes(hashes: uint64) -> uint64
def parse_int(str: String) -> int
def to_array(gen: &runtime::Generator(type T)) -> &[T]
def print(args: ) -> int
def error(args: ) -> int
def fprint(file: File, args: ) -> int
def fprint(file: File, str: Str) -> int
def abort(s: String)
def delete(v: type *T)
def delete(v: type [T])
def new(t: type T) -> *T
def concat(base: string, to_append: string)
def allocate(size: size_t) ->
def allocate(type T) -> *T
def allocate(type T, size: size_t) -> [T]
def zero_allocate(size: size_t) ->
def zero_allocate(type T) -> *T
def zero_allocate(type T, size: size_t) -> [T]
def allocate_ref(type T, size: size_t) -> &[T]
def reallocate(value: type *T, size: size_t) -> *T
def free(value: type [T])
def open(file_path: String, mode: String) -> File
def reopen(file_path: String, mode: String, file: File) -> File
def close(file: File) -> int
def read(file: File, buffer: type [T]) -> size_t
def read(file: File, buffer: type [T], size: size_t) -> size_t
def read(file: File, ptr: type *T) -> size_t
def read_str(file: File) -> Str
def flush(file: File)
def write(file: File, buffer: type [T]) -> size_t
def write(file: File, buffer: type [T], size: size_t) -> size_t
def write(file: File, ptr: type *T) -> size_t
def write(file: File, c: char) -> size_t
def write_str(file: File, str: String) -> size_t
def read_line(file: File, str: string)
def seek(file: File, offset: long, whence: int) -> int
def tell(file: File) -> long
def strlen(str: string) -> size_t
def max(a: double, b: double) -> double
def min(a: double, b: double) -> double
def memcopy(src: , dest: , size: size_t) ->
def system(command: String) -> int
def getenv(str: String) -> Str
def mkdir(path: String)
def dirname(file: String) -> Str
def basename(file: String) -> Str
def executable_file() -> Str
def absolute_path(pathname: String) -> Str
def tmpfolder(name: String) -> Str
def read_all(fh: File) -> Str
def read_all_pipe(pipe: File) -> Str
def read_remaining(file: File) -> Str
def timespec_to_unix(ts: linux::s_timespec) -> UnixTime
def modified_time(file: File) -> UnixTime
def print_stacktrace()

arena

Types

type Arena = struct {
    start: *Region
    end: *Region
    region_capacity: size_t
}

Functions

def make(capacity: size_t) -> &Arena
def allocate(arena: &Arena, type T) -> *T
def allocate(arena: &Arena, size: size_t) ->
def free(arena: &Arena)

getopt

Types

type Option = struct {
    kind: OptionKind
    data:
    longop: Str
    nargs: int
    shortop: char
    is_set: bool
    is_required: bool
    help: Str
    metavar: Str
}
type OptionParser = struct {
    options: &[Option]
    description: Str
}

Functions

def option(data: *&[Str], longop: Str, nargs: int) -> Option
def option(data: *bool, longop: Str) -> Option
def option(data: *Str, longop: Str) -> Option
def option(data: *&Vector(Str), longop: Str) -> Option
def option(data: *&Vector(&[Str]), longop: Str, nargs: int) -> Option
def set_required(option: Option) -> Option
def set_shortop(option: Option, shortop: char) -> Option
def set_help(option: Option, help: Str) -> Option
def set_metavar(option: Option, metavar: Str) -> Option
def make_parser(options: &[Option], description: Str) -> &OptionParser
def parse(option_parser: &OptionParser, args: [string]) -> bool

io

Variables

var stderr_orig: *s__IO_FILE = ...
var stdout_orig: *s__IO_FILE = ...
const NO_BLOCKING: int = 1
const _IONBF: int = 2

Functions

def redirect_stderr_to_file(file: String)
def redirect_stdout_to_file(file: String)
def restore_stderr()
def restore_stdout()
def pipe(mode: int) -> File, File
def is_a_tty(file: File) -> bool

json

Types

type Type = enum {
    NIL
    OBJECT
    ARRAY
    STRING
    NUMBER
    TRUE
    FALSE
    KEY
}
type Status = enum {
    JSON_NULL
    JSON_EMPTY
    JSON_OK
    JSON_ERROR
}
type Data = struct #union {
    number: double
    str: Str
    b: bool
}
type JsonTreeNode = struct {
    tpe: Type
    parent: *JsonTreeNode
    data: Data
    children: &Vector(JsonTreeNode)
}
type Json = struct {
    status: Status
    root: JsonTreeNode
}

Functions

def destruct(this: *JsonTreeNode)
def construct(copy: *JsonTreeNode, this: *JsonTreeNode)
def __eq__(this: &Json, other: &Json) -> bool
def __ne__(this: &Json, other: &Json) -> bool
def make_array() -> &Json
def make_object() -> &Json
def make_null() -> &Json
def push(tree: &Json, item: &Json)
def push(tree: &Json, item: double)
def push(tree: &Json, item: bool)
def push(tree: &Json, item: String)
def update(tree: &Json, key: String, item: &Json)
def update(tree: &Json, key: String, item: double)
def update(tree: &Json, key: String, item: bool)
def update(tree: &Json, key: String, item: String)
def length(tree: &Json) -> size_t
def has_item(tree: &Json, str: String) -> bool
def apply(tree: &Json, str: String) -> &Json
def has_item(tree: &Json, index: size_t) -> bool
def apply(tree: &Json, index: size_t) -> &Json
def as_bool(tree: &Json) -> bool
def as_int(tree: &Json) -> int
def as_double(tree: &Json) -> double
def as_string(tree: &Json) -> Str
def is_bool(tree: &Json) -> bool
def is_double(tree: &Json) -> bool
def is_string(tree: &Json) -> bool
def is_null(tree: &Json) -> bool
def is_object(tree: &Json) -> bool
def is_array(tree: &Json) -> bool
def serialize(obj: type *T) -> &Json
def deserialize(json: &Json, type T) -> Optional(T)
def to_string(tree: &Json) -> String
def destruct(self: *Json)
def parse(str: String) -> &Json

map

Types

type Entry(type K, type V) = struct {
    key: K
    value: V
    next: &Entry(K, V)
    l_prev: weak &Entry(K, V)
    l_next: weak &Entry(K, V)
}
type Map(type K, type V) = struct {
    size: size_t
    entries: [&Entry(K, V)]
    tail: weak &Entry(K, V)
    head: weak &Entry(K, V)
}
type SMap(type V) = Map(Str, V)

Functions

def construct(copy: *Map(type K, type V), this: *Map(K, V))
def destruct(map: *Map(type K, type V))
def hash(i: size_t) -> size_t
def make(type K, type V, size: size_t) -> &Map(K, V)
def make(type V, size: size_t) -> &SMap(V)
def make(type K, type V) -> &Map(K, V)
def make(type V) -> &SMap(V)
def get(map: &Map(type K, type V), key: K) -> Optional(V)
def get_or_default(map: &Map(type K, type V), key: K, default: V) -> V
def apply(map: &Map(type K, type V), key: K) -> V
def contains(map: &Map(type K, type V), key: K) -> bool
def update(map: &Map(type K, type V), key: K, value: V)
def put_all(this: &Map(type K, type V), other: &Map(K, V))
def remove(map: &Map(type K, type V), key: K)
def size(map: &Map(type K, type V)) -> size_t
def keys(map: &Map(type K, type V)) -> &[K]
def reverse_keys(map: &Map(type K, type V)) -> &[K]
def clear(map: &Map(type K, type V))

optional

Types

type Optional(type V) = struct {
    exists: bool
    value: V
}

Functions

def none(type V) -> Optional(V)
def some(value: type V) -> Optional(V)
def get(this: Optional(type T)) -> T
def get_or_default(this: Optional(type T), default: T) -> T

process

Types

type Process = struct {
    exit_code: int
    running: bool
    pid: int
    fd: long
}

Functions

def spawn(exe: String, args: &[String], stdin: File, stdout: File, stderr: File) -> Process
def wait(process: *Process, timeout: ulong)
def terminate(process: *Process)
def dispose(process: *Process)

set

Types

type Set(type T) = map::Map(T, )
type SSet = Set(Str)

Functions

def make(type T) -> &Set(T)
def make() -> &SSet
def make(vec: &Vector(type T)) -> &Set(T)
def __eq__(a: &Set(type T), b: &Set(T)) -> bool
def __ne__(a: &Set(type T), b: &Set(T)) -> bool
def add(set: &Set(type T), value: T)
def add_all(set: &Set(type T), other: &Set(T))
def copy(set: &Set(type T)) -> &Set(T)

shared

Types

type SymbolKind = enum {
    OBJECT
    FUNCTION
}
type Symbol = struct {
    kind: SymbolKind
    name: Str
    value:
}
type Library = struct {
    path: Str
    handle:
    symbols: &[Symbol]
}

Functions

def find_symbol(library: *Library, name: String) -> Optional(Symbol)
def load(path: String, init: bool) -> Library
def close(library: *Library, finalize: bool)

strings

Types

type Str = struct #union {
    long_str: LongString
    short_str: ShortString
}
type StringBuffer = struct {
    prev: &StringBuffer
    data: Str
    offset: size_t
}
type StringSlice = struct {
    parent: String
    data: *char
    offset: size_t
    count: size_t
}
type IString = interface {
    def length() -> size_t
    def apply(i: size_t) -> char
}
type String = &IString
type ToString = interface {
    def to_string() -> String
}

Functions

def length(s: [char]) -> size_t
def length(s: &[char]) -> size_t
def apply(s: &[char], i: size_t) -> char
def hash(str: Str) -> size_t
def to_bool(s: Str) -> bool
def is_short_str(s: *Str) -> bool
def get_internal_buffer(s: *Str) -> *char
def to_str(s: &string) -> Str
def to_str(s: string) -> Str
def to_str(len: size_t, value: *char) -> Str
def to_str(s: String) -> Str
def length(s: Str) -> size_t
def length(s: &Str) -> size_t
def apply(s: Str, i: size_t) -> char
def apply(s: &Str, i: size_t) -> char
def construct(copy: *Str, this: *Str)
def destruct(this: *Str)
def length(s: StringBuffer) -> size_t
def to_str(s: StringBuffer) -> Str
def to_buffer(s: String) -> StringBuffer
def to_buffer(s: Str) -> StringBuffer
def to_buffer(s: StringSlice) -> StringBuffer
def to_buffer(s: &string) -> StringBuffer
def to_buffer(s: string) -> StringBuffer
def __add__(s: StringBuffer, o: &ToString) -> StringBuffer
def __add__(s: StringBuffer, o: Str) -> StringBuffer
def __add__(s: StringBuffer, o: StringSlice) -> StringBuffer
def __add__(s: StringBuffer, o: String) -> StringBuffer
def __add__(s: StringBuffer, o: &string) -> StringBuffer
def __add__(s: StringBuffer, o: string) -> StringBuffer
def __add__(s: &ToString, o: StringBuffer) -> StringBuffer
def __add__(s: StringBuffer, o: StringBuffer) -> StringBuffer
def __iadd__(s: StringBuffer, o: &ToString) -> StringBuffer
def __iadd__(s: StringBuffer, o: Str) -> StringBuffer
def __iadd__(s: StringBuffer, o: StringSlice) -> StringBuffer
def __iadd__(s: StringBuffer, o: String) -> StringBuffer
def __iadd__(s: StringBuffer, o: &string) -> StringBuffer
def __iadd__(s: StringBuffer, o: string) -> StringBuffer
def __iadd__(s: StringBuffer, o: StringBuffer) -> StringBuffer
def to_string(s: StringBuffer) -> String
def to_string(s: string) -> String
def to_string(s: &string) -> String
def to_bool(s: StringSlice) -> bool
def length(s: StringSlice) -> size_t
def length(s: &StringSlice) -> size_t
def apply(s: StringSlice, i: size_t) -> char
def apply(s: &StringSlice, i: size_t) -> char
def to_str(s: StringSlice) -> Str
def __eq__(s1: IString, s2: IString) -> bool
def __eq__(s1: IString, s2: [char]) -> bool
def __eq__(s1: [char], s2: IString) -> bool
def __eq__(s1: [char], s2: [char]) -> bool
def __eq__(s1: Str, s2: Str) -> bool
def __ne__(s1: IString, s2: IString) -> bool
def __ne__(s1: IString, s2: [char]) -> bool
def __ne__(s1: [char], s2: IString) -> bool
def __ne__(s1: [char], s2: [char]) -> bool
def __ne__(s1: Str, s2: Str) -> bool
def cmp(s1: IString, s2: IString) -> int
def __lt__(s1: IString, s2: IString) -> bool
def __le__(s1: IString, s2: IString) -> bool
def __gt__(s1: IString, s2: IString) -> bool
def __ge__(s1: IString, s2: IString) -> bool
def to_slice(s: [char]) -> StringSlice
def to_slice(s: String) -> StringSlice
def to_slice(s: Str) -> StringSlice
def slice(s: [char], frm: size_t, to: size_t) -> StringSlice
def slice(s: Str, frm: size_t, to: size_t) -> StringSlice
def slice(s: String, frm: size_t, to: size_t) -> StringSlice
def to_array(s: String) -> &[char]
def chars(s: String) -> char
def to_string(sign: int, n: uint64) -> String
def to_string(a: &int64) -> String
def to_string(a: &int32) -> String
def to_string(a: &int16) -> String
def to_string(a: &int8) -> String
def to_string(a: &uint64) -> String
def to_string(a: &uint32) -> String
def to_string(a: &uint16) -> String
def to_string(a: &uint8) -> String
def to_string(a: &bool) -> String
def to_string(a: &char) -> String
def to_string(value: &float) -> String
def to_string(value: &double) -> String
def make_string(ptr: *char) -> Str
def remove(str: String, i: size_t) -> Str
def remove(str: String, start: size_t, count: size_t) -> Str
def insert(str: String, i: size_t, s: String) -> Str
def insert(str: String, i: size_t, c: char) -> Str
def substring(str: String, start: size_t, end: size_t) -> Str
def substring(str: String, start: size_t) -> Str
def index_of(str: String, substring: String, start: size_t) -> int64
def last_index_of(str: String, substring: String) -> int64
def ends_with(str: String, suffix: String) -> bool
def starts_with(str: String, pre: String) -> bool
def strip_margin(s: String) -> Str
def match(pattern: String, candidate: String) -> bool
def utf8_encode(code_point: uint64) -> Str
def int_to_hex_str(n: uint64, prefix: bool) -> Str
def iterate(str: String) -> char

vector

Types

type Vector(type T) = struct {
    length: size_t
    data: [T]
}

Functions

def destruct(this: *Vector(type T))
def construct(copy: *Vector(type T), this: *Vector(T))
def make(type T) -> &Vector(T)
def resize(vec: &Vector(type T), size: size_t)
def length(vec: &Vector(type T)) -> size_t
def get(vec: &Vector(type T), index: size_t) -> *T
def apply(vec: &Vector(type T), index: size_t) -> T
def update(vec: &Vector(type T), index: size_t, val: T)
def push(vec: &Vector(type T), elem: T)
def prepend(vec: &Vector(type T), elem: T)
def peek(vec: &Vector(type T)) -> T
def pop(vec: &Vector(type T)) -> T
def head(vec: &Vector(type T)) -> T
def head_vec(vec: &Vector(type T)) -> &Vector(T)
def tail(vec: &Vector(type T)) -> &Vector(T)
def copy(vec: &Vector(type T)) -> &Vector(T)
def insert(vec: &Vector(type T), index: size_t, elem: T)
def insert(vec: &Vector(type T), index: size_t, vec2: &Vector(T))
def add_all(vec: &Vector(type T), vec2: &Vector(T))
def remove(vec: &Vector(type T), index: size_t)
def iterate(vec: &Vector(type T)) -> T
def iterate_ref(vec: &Vector(type T)) -> *T
def to_array(vec: &Vector(type T)) -> &[T]

runtime

Types

type TestEnvironment = struct {
    out: () -> (&string)
    err: () -> (&string)
    assertion_handler: (bool, *char) -> ()
}
type Generator(type T) = struct {
    implementation: (&Generator(T)) -> (optional::Optional(T))
    context:
    free_context: () -> ()
    is_at_end: bool
}
type TypeKind = enum {
    BOOL
    WORD
    FLOAT
    STRUCT
    UNION
    ARRAY
    STATIC_ARRAY
    POINTER
    REFERENCE
    FUNCTION
    ENUM
    CHAR
    STRUCTURAL
    OPAQUE
    WEAK_REF
    TYPE
    VARIANT
    TUPLE
}
type Function = struct {
    name: string
    exported: bool
    module: string
    parameter_t: [*Type]
    return_t: [*Type]
}
type Type = struct {
    kind: TypeKind
    name: string
    unsig: bool
    length: size_t
    tpe: *Type
    size: size_t
    align: size_t
    fields: [Field]
    parameters: [*Type]
    returns: [*Type]
    enum_values: [EnumValue]
    module: string
    structural_members: [Function]
    type_members: [Function]
    id: int64
}
type EnumValue = struct {
    name: string
    value: int64
}
type Field = struct {
    name: string
    offset: size_t
    tpe: *Type
}
type Ref = struct {
    ref_count: *int64
    value:
    tpe: *Type
}

Functions

def destruct(this: *Generator(type T))
def next(generator: &Generator(type T)) -> optional::Optional(T)
def implements(A: *Type, B: *Type) -> bool
def ref_type(a: Ref) -> *Type
def equals(a: *Type, b: *Type) -> bool
def reference(tpe: *Type) -> *Type