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.
| Function | Result | Meaning |
|---|---|---|
byte(value: int) | bytes | One byte with that value. |
byte_at(b: bytes, index: int) | int | The byte at index. Stops the program if index is outside b. |
slice(b: bytes, start: int, end: int) | bytes | The bytes from start up to, not including, end. Stops the program if the range is outside b. |
concat(a: bytes, b: bytes) | bytes | a followed by b. |
concat3, concat4, concat5 | bytes | The same for three, four and five pieces. |
bytes_equal(a: bytes, b: bytes) | bool | Whether the two have the same length and content. |
bytes_less(a: bytes, b: bytes) | bool | Whether a sorts before b, comparing byte by byte. |
starts_at(text: bytes, part: bytes, at: int) | bool | Whether part appears in text at position at. |
ends_with(text: bytes, ending: bytes) | bool | Whether text ends with ending. |
contains(text: bytes, part: bytes) | bool | Whether part appears anywhere in text. |
index_of_byte(text: bytes, wanted: int, from: int) | int | The 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) | bytes | A copy with every byte old changed to new. |
int_to_text(value: int) | bytes | The number in decimal digits, with - in front if negative. |
text_to_int(text: bytes) | int | The number written in text as decimal digits. Stops the program on any other byte. |
little_endian(count: int, value: int) | bytes | The 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) }| Function | Result | Meaning |
|---|---|---|
one_bytes(item: bytes) | bytes_list | A list with that single item. |
bytes_count(items: bytes_list) | int | The number of items. |
appended(items: bytes_list, more: bytes_list) | bytes_list | items followed by more. |
reversed(items: bytes_list) | bytes_list | The items in opposite order. |
sorted(items: bytes_list) | bytes_list | The items ordered by bytes_less. |
joined(items: bytes_list, separator: bytes) | bytes | The items in one run, with separator between each two. |
same_bytes_lists(a: bytes_list, b: bytes_list) | bool | Whether both hold equal items in the same order. |
lines(text: bytes) | bytes_list | text split at each line end. A line end at the very end adds no empty item. |
Input and output
In std/io.qdx.
| Function | Result | Meaning |
|---|---|---|
print(b: bytes) | int | Writes b to standard output. Returns 0. |
put(value: int) | int | Writes one byte to standard output. Returns value. |
panic(message: bytes) | never | Writes message and a line end to standard error, then ends the program with status 1. |
read_file(path: bytes) | bytes | The whole content of a file. Stops the program if it cannot be opened. |
write_file(path: bytes, content: bytes, mode: int) | int | Replaces the file at path with content, with the given permissions. |
files_equal(a: bytes, b: bytes) | bool | Whether two files have the same content. |
make_directory(path: bytes) | int | Creates a directory. Returns the kernel’s answer, which is negative if it already exists. |
file_names(directory: bytes) | bytes_list | The 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.
| Function | Result | Meaning |
|---|---|---|
arg_count() | int | The number of command-line arguments, counting the program’s own name. |
arg(index: int) | bytes | The 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) | int | Runs 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.