Standard library
Every module is a TryC source file of the standard library, written in TryC (with asminline for the syscalls and the SIMD paths). #include <libstd/name> makes it available; a module may include others, and including the same file twice is harmless. The pages in this section are generated from the sources: signatures, classes and constants are always current.
Linux and Windows
A program that uses the standard library compiles unchanged for Linux and for Windows: every module has the same functions, classes and constant names on both. What changes is underneath. A module that needs the operating system includes its back end with the macros the compiler predefines for the target:
#ifdef __unix__
#include <libstd/wrapper/linux/sysnet>
#else
#include <libstd/wrapper/windows/sysnet>
#endif
The two back ends define the same sys_* functions: on Linux they are system calls, on Windows calls to the Windows API (kernel32, ws2_32, bcrypt, user32, ...). The functions without the prefix are written once, above them, and are the same code on both. A constant whose number depends on the system, like a socket option, is defined in both back ends with the same name; the reference pages show the two values side by side.
When something exists on only one system, the other one gets the closest equivalent (TCP_USER_TIMEOUT is TCP_MAXRTMS on Windows). If it is only an optimisation, it does nothing there (TCP_DEFER_ACCEPT on Windows). If skipping it would change what the program does, it stays on one system and using it on the other is a compile error (SO_REUSEPORT, libstd/xlib). exit ends the whole process on both, threads started by a library (such as a Vulkan driver's) included.
Core
| Module | Contents |
|---|---|
| stdio | print, buffered input, fprint, raw read/write |
| string | length, search, slicing, strip, split/join, replace, line Reader |
| type | the conversions as does not do: narrowing integers, text to number, digits, hexadecimal |
| list | growable List of long |
| dict | hash tables: dict (int), sdict (str), vdict (typed), adict (boxed, nestable); iteration; peek/poke |
| json | parse and serialise JSON |
| math | sin/cos/sqrt, Vec3, 4×4 matrices |
| random | xorshift64* generator, entropy from the system |
| re | regular expressions: search, groups, findall, sub, compiled patterns |
| argparse | ArgParser: command-line options, flags, positionals, subcommands, --help; several parsers on one command line |
Operating system
| Module | Contents |
|---|---|
| file | open/close/stat, whole-file read, dup, flags and modes |
| os | argv, environment, cwd, uname, executable path, sysinfo |
| process | pids, fork/exec/wait, system, zombie reaping, clone |
| thread | thread_spawn, thread_join/thread_detach, cooperative stop |
| sync | atomics and futexes |
| net | TCP sockets, socket options |
| http | HTTP/1.1 server: routes, static files, middleware, cookies, shared sessions, worker processes with epoll |
| http/cookies | the cookies of a request and of its response: read, set, delete, safe defaults |
| http/session | sessions shared by all the workers: login and logout, expiry, recovery after a crash |
| time | clocks, timestamps, sleep, durations |
| window | a window on the screen and its close button (Xlib on Linux, user32 on Windows) |
| mem | memory syscall and mmap constants |
| macro | __unix__ and syscall numbers |
| cpuinfo | vendor, brand, features: cpuid on x86_64, ID registers on aarch64 |
Bindings to C libraries
| Module | Linux | Windows |
|---|---|---|
| sqlite3 | libsqlite3.so | winsqlite3.dll |
| mysql | libmariadb.so | libmariadb.dll (on PATH) |
| xlib | libX11.so.6, with events | — (use window) |
| vulkan, vulkan3d | libvulkan.so | vulkan-1.dll |
Conventions
- Functions named
sys_*are the back end: a system call on Linux, the Windows API on Windows, with the same signature on both. A negative return is an error (-errnoon Linux, a negated Windows error code on Windows); the functions without the prefix are the convenient layer above them. - Predicates return
1/0. - Lengths, indices and sizes are
longin the containers andintin most string functions; passn as longwhere a literal is needed. - Strings returned by a function are new arena allocations promoted to the caller's scope, unless the description says the function returns a pointer into its input (
lstrip,match_rest). - "Undefined on an empty list" and similar notes mean exactly that: no check is performed, the caller tests first.
- Every function has a docstring in the source (
/* ... */right after thedef), in Italian, with anargomenti:/return:section. The generated pages summarise it in English.