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.
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): 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.
fn runeCount(s: str): int
Returns 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): str
Returns 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): []byte
Returns slice based on b, the parameter b means first element of slice. Will not perform garbage collection.
fn strAsSlice(s: str): []byte
Equals to sliceBytePtr(&s[0], len(s), len(s)) call. Returns nil slice for empty string.
fn sliceAsStr(b: []byte): str
Returns byte slice as str. Equals to strBytePtr(&b[0], len(b)) call. Returns empty string if len(b) == 0.