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
let mut argc: intAssigned by entry point.
let mut argv: **byteAssigned by entry point.
let mut envp: **byteAssigned by entry point.
Functions
fn ptrToStr(p: *unsafe): strReturns pointer in string form.
fn boolToStr(b: bool): strReturns boolean in string form.
fn i64ToStr(x: i64): strReturns x in decimal string format.
fn u64ToStr(mut x: u64): strReturns x in decimal string format.
fn f64ToStr(mut f: f64): strReturns x in decimal string format.
fn writeStdout(mut buf: []byte): intWrites to stdout. Returns written byte count if success, -1 otherwise.
fn writeStderr(mut buf: []byte): intWrites to stderr. Returns written byte count if success, -1 otherwise.
fn readStdin(mut buf: []byte): intReads from stdin. Returns read byte count if success, -1 otherwise.
fn ptrEqual(a: *unsafe, b: *unsafe): boolReports whether pointer allocations are points to same address.
fn _RCNew(): _RCPtrReturns new initialized ready-to-use reference counting data allocation pointer.
unsafe fn _RCLoad(p: _RCPtr): _RCTypeReads 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): _RCTypeSame 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): boolDrops strong reference from reference pointer. Passing nil pointer is not safe. Reports whether 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): boolSame 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.
unsafe fn panic1(m: *byte, n: int)The built-in panic call.
fn panicStr(m: str)Calls the panic1 function by m.
fn compareStr(&a: str, &b: str): intSee strings::{Compare} function for documentation.
fn bytesToStr(bytes: []byte): strConverts []byte to str.
fn runesToStr(runes: []rune): strConverts []rune to str.
fn strToRunes(s: str): []runeConverts str to []rune.
fn strToBytes(s: str): []byteConverts str to []byte.
fn strFromByte(b: byte): strConverts byte to str.
fn strFromRune(r: rune): strConverts 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. The thread data, should be fit into the threadData struct. So, the head fields of the thread data should be matched fields of the threadData.
fn runeCount(s: str): intReturns rune count of the string.
fn pseudoMalloc(n: i64, size: uint)Pseudo memory allocation, for allocation checking and documentation purposes. Any runtime allocation must be follow this implementation documentation. Pseudo allocates linear memory on the heap. The |n| is non-negative count of elements. The |size| is size in bytes of the single instance of a type which is will be allocated. Panics if |n*size > maxAlloc || n > max(int)|, also panics if allocation failed. Returns pointer to the allocation (pointer to the first cell if n>1). The allocated memory will not be initialized by default.
Calling this function, performs allocation size checking as described and panics if conditions are met.
unsafe fn strBytePtr(b: *byte, n: int): strReturns string based on b, the parameter b means first byte of string. The returned string uses n as length. Will not perform garbage collection.
unsafe fn sliceBytePtr(mut b: *byte, len: int, cap: int): []byteReturns slice based on b, the parameter b means first element of slice. Will not perform garbage collection.
fn strAsSlice(s: str): []byteEquals to sliceBytePtr(&s[0], len(s), len(s)) call. Returns nil slice for empty string.
fn sliceAsStr(b: []byte): strReturns byte slice as str. Equals to strBytePtr(&b[0], len(b)) call. Returns empty string if len(b) == 0.
fn zprint(s: str)The runtime implementation of the built-in print function.
fn zprintln(s: str)The runtime implementation of the built-in println function.
fn nan(): f64Equals to the math::NaN function.
fn inf(sign: int): f64Equals to the math::Inf function.