Runtime API
The runtime library provides some definitions as APIs to be used in the backend. This section includes which functions are provided as APIs and their documentation. If you want to see how they are declared in the backend, see the API documentation.
Globals
static mut argc: int
Assigned by entry point.
static mut argv: **byte
Assigned by entry point.
static mut envp: **byte
Assigned by entry point.
Functions
fn ptrToStr(p: *unsafe): str
Returns pointer in string form.
fn boolToStr(b: bool): str
Returns boolean in string form.
fn i64ToStr(x: i64): str
Returns x in decimal string format.
fn u64ToStr(mut x: u64): str
Returns x in decimal string format.
fn f64ToStr(mut f: f64): str
Returns x in decimal string format.
fn writeStdout(mut buf: []byte): int
Writes to stdout. Returns written byte count if success, -1
otherwise.
fn writeStderr(mut buf: []byte): int
Writes to stderr. Returns written byte count if success, -1
otherwise.
fn readStdin(mut buf: []byte): int
Reads from stdin. Returns readed byte count if success, -1
otherwise.
fn ptrEqual(a: *unsafe, b: *unsafe): bool
Reports whether pointer allocations are points to same address.
fn _RCNew(): _RCPtr
Returns new initialized ready-to-use reference counting data allocation pointer.
unsafe fn _RCLoad(p: _RCPtr): _RCType
Reads reference counting data. Passing nil pointer is not safe.
Implemented with no thread-safety by default. If thread-safety necessary, compiler will update implementation implicitly. See memory model of concurrency.
unsafe fn _RCLoadAtomic(p: _RCPtr): _RCType
Same as _RCLoad
but have thread-safe implementation.
unsafe fn _RCAdd(mut p: _RCPtr)
Adds strong reference to reference pointer. Passing nil pointer is not safe.
Implemented with no thread-safety by default. If thread-safety necessary, compiler will update implementation implicitly. See memory model of concurrency.
unsafe fn _RCAddAtomic(mut p: _RCPtr)
Same as _RCAdd
but have thread-safe implementation.
unsafe fn _RCDrop(mut p: _RCPtr): bool
Drops strong reference from reference pointer. Passing nil pointer is not safe. Reports wheter allocation still alive.
Implemented with no thread-safety by default. If thread-safety necessary, compiler will update implementation implicitly. See memory model of concurrency.
unsafe fn _RCDropAtomic(mut p: _RCPtr): bool
Same as _RCDrop
but have thread-safe implementation.
unsafe fn _RCFree(p: _RCPtr)
Deallocates reference counting data allocation.
unsafe fn panic1(m: *byte, n: int)
The built-in panic call.
fn compareStr(&a: str, &b: str): int
See strings::{Compare}
function for documentation.
fn bytesToStr(bytes: []byte): str
Converts []byte
to str
.
fn runesToStr(runes: []rune): str
Converts []rune
to str
.
fn strToRunes(s: str): []rune
Converts str
to []rune
.
fn strToBytes(s: str): []byte
Converts str
to []byte
.
fn strFromByte(b: byte): str
Converts byte
to str
.
fn strFromRune(r: rune): str
Converts rune
to str
.
unsafe fn runeStep(s: *byte, n: int, mut r: *rune, mut outLen: *int)
Designed for []rune(s)
iterations. Takes pointer to string withl length and sets output pointers by first rune of string. Passing nil pointer for any parameter is not safe except r
.
unsafe fn coSpawn(func: *unsafe, args: *unsafe)
A low level API function for threads. It doesn't provide much abstraction. It just creates and detaches a thread using API. Reports whether the thread created successfully. The created thread is a native-thread. The func
parameter should point to the valid function for operating system thread API. The args
parameter may be nil and should point to the argument data.