Documentation/Reference

Initialized buffers, bulk I/O and allocation

On this page

Plain fallible calls are automatically checked; inline TRY in the API tables is accepted compatibility syntax, not a requirement.

Public ByteBuffer/StringBuilder and stream APIs build on these initialized storage contracts. Compiler boundary/layouts .

List capacity and editing

The self-hosted compiler provides these generic functions for every implemented copyable list element type:

Operation Result and checked failures
TRY Reserve(BYREF items,capacity) Ensures capacity, returns 0; IndexError for negative/unrepresentable capacity
TRY Resize(BYREF items,length,fill) Returns new length; shrinks with destruction or grows with independent copies of fill
TRY Truncate(BYREF items,length) Shrink only, returns length; destroys removed values
TRY CopyWithin(BYREF items,source,destination,count) Returns count; checked initialized ranges; overlap has snapshot semantics

Reserve never changes LEN and never exposes spare storage for reading or writing. Resize requires an explicit initialized fill value, including for records and nested collections. Invalid ranges are checked before mutation. Allocation failure remains fatal. CopyWithin has snapshot semantics, so overlapping owned values remain independent. The packed BYTE overload uses bounded memmove without an intermediate allocation. Extend and Concat remain the existing bulk append/copy APIs.

Inherited streams

Operation Contract
TRY WriteAll(text AS STRING) Writes all UTF-8 bytes to stdout; returns byte count; FAILS IoError
TRY WriteAll(bytes AS LIST OF INTEGER) Validates every element in 0..255 before output, writes all, returns count; FAILS IoError
TRY ReadInto(BYREF bytes,start,count) Reads stdin into initialized slots only, returns number read or 0 at EOF; FAILS IoError, IndexError

WriteAll retries interrupted operations and loops over short writes; an error can follow partial external output. ReadInto retries interruption and returns a successful short read without waiting to fill the range. The current platform primitive reads up to 8,192 bytes per call. It preserves LEN and untouched elements. Zero-length reads return zero. Invalid byte-list output returns IoError code 22 before writing; OS failures retain positive errno codes. These dedicated operations do not transfer ownership of the inherited streams.

Stdin(), Stdout() and Stderr() return owned File duplicates (FAILS IoError) for normal file and buffered APIs. Cleanup closes the duplicate while preserving the original. Their underlying I/O position is shared; coordinate buffered read-ahead with other consumers. Standard-stream rules and examples .

The compiler now writes its entire executable through bulk WriteAll, avoiding one syscall per image byte. Packed LIST OF BYTE buffers are now supported by WriteAll/ReadInto alongside the compatibility LIST OF INTEGER APIs. ReadInto on packed bytes reads directly into initialized storage; integer buffers use the bounded conversion chunk. The compiler uses a packed code buffer. See unsigned values and layout .

From the BASIL documentation. View source ↗

Find your way around BASIL

Type to search the manual.