Skip to content
Library

Library

The standard library is the qdx source in std/. It is not built into the compiler: a program gets it by naming the files on the command line, as in std/*.qdx.

The tables list the functions meant to be called. The files also contain helper functions, and since every top-level name is shared across a program, those names are taken too.

Bytes

In std/bytes.qdx. Positions count from zero.

FunctionResultMeaning
byte(value: int)bytesOne byte with that value.
byte_at(b: bytes, index: int)intThe byte at index. Stops the program if index is outside b.
slice(b: bytes, start: int, end: int)bytesThe bytes from start up to, not including, end. Stops the program if the range is outside b.
concat(a: bytes, b: bytes)bytesa followed by b.
concat3, concat4, concat5bytesThe same for three, four and five pieces.
bytes_equal(a: bytes, b: bytes)boolWhether the two have the same length and content.
bytes_less(a: bytes, b: bytes)boolWhether a sorts before b, comparing byte by byte.
starts_at(text: bytes, part: bytes, at: int)boolWhether part appears in text at position at.
ends_with(text: bytes, ending: bytes)boolWhether text ends with ending.
contains(text: bytes, part: bytes)boolWhether part appears anywhere in text.
index_of_byte(text: bytes, wanted: int, from: int)intThe first position at or after from holding the byte wanted, or the length of text when there is none.
with_byte_replaced(text: bytes, old: int, new: int)bytesA copy with every byte old changed to new.
int_to_text(value: int)bytesThe number in decimal digits, with - in front if negative.
text_to_int(text: bytes)intThe number written in text as decimal digits. Stops the program on any other byte.
little_endian(count: int, value: int)bytesThe lowest count bytes of value, lowest first.

Lists of bytes

In std/list.qdx.

union bytes_list { bytes_nil(), bytes_cons(head: bytes, tail: bytes_list) }
FunctionResultMeaning
one_bytes(item: bytes)bytes_listA list with that single item.
bytes_count(items: bytes_list)intThe number of items.
appended(items: bytes_list, more: bytes_list)bytes_listitems followed by more.
reversed(items: bytes_list)bytes_listThe items in opposite order.
sorted(items: bytes_list)bytes_listThe items ordered by bytes_less.
joined(items: bytes_list, separator: bytes)bytesThe items in one run, with separator between each two.
same_bytes_lists(a: bytes_list, b: bytes_list)boolWhether both hold equal items in the same order.
lines(text: bytes)bytes_listtext split at each line end. A line end at the very end adds no empty item.

Input and output

In std/io.qdx.

FunctionResultMeaning
print(b: bytes)intWrites b to standard output. Returns 0.
put(value: int)intWrites one byte to standard output. Returns value.
panic(message: bytes)neverWrites message and a line end to standard error, then ends the program with status 1.
read_file(path: bytes)bytesThe whole content of a file. Stops the program if it cannot be opened.
write_file(path: bytes, content: bytes, mode: int)intReplaces the file at path with content, with the given permissions.
files_equal(a: bytes, b: bytes)boolWhether two files have the same content.
make_directory(path: bytes)intCreates a directory. Returns the kernel’s answer, which is negative if it already exists.
file_names(directory: bytes)bytes_listThe names in a directory, sorted, without . and ...

For mode, std/sys.qdx provides mode_plain() for an ordinary file and mode_executable() for a program.

Arguments and processes

In std/process.qdx.

FunctionResultMeaning
arg_count()intThe number of command-line arguments, counting the program’s own name.
arg(index: int)bytesThe argument at index. arg(0) is the program’s name. Stops the program if index is outside the arguments.
run_program(path: bytes, arguments: bytes_list, output_path: bytes, error_path: bytes)intRuns another program and waits for it. Returns its exit status, or 128 plus the signal number if a signal ended it.

run_program sends the other program’s standard output to the file output_path and its standard error to error_path. An empty path leaves that stream where it is.

System numbers

std/sys.qdx names the numbers the kernel uses: system call numbers such as sys_open(), flags such as open_read_only(), and sizes such as page_size() and word_size(). It also provides kernel_call(number, a, b, c), a system call with three arguments.