Overview

The standard library is the set of modules shipped with tape. Import one by its bare name:

tape
import io from "io";
import collections from "collections";

tape finds them in stdlib/ next to the tape binary (or in ./stdlib, or any -I path). They’re ordinary tape modules: you can read their source.

Modules

ModuleWhat it’s for
arenaBump allocation over memory you own, for t0 and up: over, alloc, mark, release
ioConsole output and input, streams, buffering, IoError: println, read_line, BufWriter
fsFiles and directories: read_file, write_file, open, read_dir, mkdir_all, metadata
bitsBit counting, rotation, byte swapping, little- and big-endian loads and stores
asciiByte classification (is_digit, is_space, …), case mapping, digit values
bytesByte views without allocating: copy, fill, eq, index_of, trim, split, lines, cut
cstrNUL-terminated C strings at the C boundary: as_view, from_view, free
strBuilding strings: join, repeat, replace, case, padding, Builder
fmtNumber formatting beyond "{x}": hex, binary, fixed decimals, byte sizes
pathFile paths as text: join, dirname, basename, ext, normalize
mathInteger helpers and floating-point functions for f64 and f32: rounding, roots, trigonometry, exp/log, pow
affine2D transforms (CSS’s matrix(a, b, c, d, e, f)): translate, scale, rotate, skew, compose, invert, apply
wordsWord lookup tables: a fixed list of words becomes an enum and a lookup built at compile time (gen_lookup)
convNumbers to text and back, exactly: parse_i64, parse_f64, parse_f32, fmt_i64, fmt_f64, fmt_f32
memHeap memory: alloc (*u8 or MemError), alloc_or_trap, realloc, free, heap arenas, raw byte operations; live_allocs to check for leaks
utf8UTF-8 text: decode, encode, validate, count, chars
hashNon-cryptographic hashes: fnv1a_64, wyhash, crc32, hash_i64
cryptoCryptography in constant time: SHA-256/384/512, HMAC, HKDF, ChaCha20-Poly1305, AES-GCM, X25519, P-256, signature checks, a CSPRNG
x509X.509 certificates for TLS: a strict DER reader, parse, host name matching, a trust store, verify_chain
ca_rootstape’s bundled root certificates (Mozilla’s CA set), the same on every platform: load, certs, COUNT
tlsA TLS 1.3 client as a sans-I/O engine: you move the bytes, it does the protocol; certificate checks through x509, ALPN, KeyUpdate, leaf pinning
collectionsContainers for any element type: Vec, Map and Set (integer, string or custom keys), Deque, Heap, BitSet; Vec_i64, Map_string_i64 and others ready to use
sortSorting and binary search for slices of any type: sort_i64, sort_string, binary_search_i64, generators for your own types and orders
randSeedable random numbers: xoshiro256, pcg32, range_i64, next_f64, shuffle and choice
osArguments, environment, exit, working directory, platform, entropy: args, env, PLATFORM
jsonJSON: parse to a Value tree, accessors, stringify compact or indented, errors with line and column, a streaming Tokenizer, gen_codec for your structs
serialMark a struct once for every serialization format: @serial.skip, @serial.rename, @serial.explicit
hotHot reload’s safe point: hot.poll() swaps edited components in during a tape run --hot
vmScripts inside your program: contexts that decide what a script may use, host modules it calls, instances run a time slice at a time, errors as data
regexRegular expressions in linear time: compile, find, captures, matches, split, replace_all
encodingbase64, base64url, hex and percent-encoding, both ways, as strings or into your buffer
mimeEmail: parse a message into parts, headers, addresses, attachments and text; compose one with draft
charsetText in other encodings as UTF-8: windows-1252, ISO-8859, KOI8, Shift_JIS, GBK, Big5, EUC-KR, UTF-16, UTF-7, IMAP mailbox names: lookup, decode
timeMeasuring and sleeping, dates, the user’s time zone, ISO 8601 and mail dates: now, sleep, utc_now, local_now, parse_rfc5322, format, relative, brief
processStarting programs with exact arguments, output to files, a pipe into stdin, timeouts, kill, exit status: command, spawn, wait_timeout
pipeByte streams between programs on one machine: listen, accept and connect with timeouts, read_line
desktopOther programs’ windows and the screens: find, wait_for, place, set_topmost, close, screens (Windows)
netTCP and UDP sockets, name resolution, connect_host with Happy Eyeballs, poll, TCP streams as io streams, TLS connections and trust sets
httpAn HTTP client over http and https: get, request, headers, opt-in redirects, timeouts and limits, parse_url; a Client that keeps connections and runs many requests at once (get_all, start, wait), over HTTP/2 where the server offers it
h2, hpackHTTP/2 underneath http: the client side of a connection as a state machine over bytes, and its header compression
cliCommand lines from a declarative spec: parse, flag, value, positional, usage, message
logLeveled log lines with timestamps: info, warn, set_level, TAPE_LOG, sinks
colorBuilding and mixing colors: rgb, channels, lighten, darken, lerp, brightness
gfxDrawing on a pixel surface: rectangles, shapes, text, blits, clipping, pixels and checksums
imagePNG, JPEG, WebP, BMP, HV3 and HV4 bytes to surfaces (WebP decoded only) and back: decode, encode
text, font, fillTrueType text on pixels: font.open, text.draw, text.measure; the outline filler underneath
audioSound output: clips played once (play, load), streams written as you make samples (open, write_i16, drain), decode_wav
wavWAV files read without allocating: info, decode_into your buffer
uiComponent trees in a window (run) or offscreen (headless): layout, painting, input, testing
widgetsReady-made components: Label, Button, TextInput, Checkbox, Slider, Image, …
themeThe look of the widgets: light, dark, set at run time; the palette as #style constants
tween, easingValues over time: tweens through points with a curve per leg (from_f64, to, step, retarget), the easing curves, animating a component (ui.animated, ui.animate)
gpuThe GPU on every platform (Metal on macOS, OpenGL 4.3 on Windows and Linux): a window or offscreen device, buffers, textures, render and compute pipelines from #shader stages, passes, reading results back
glOpenGL: a window with a GL context (open, poll, present), shaders and programs with the driver’s log as an error (program, compute), check, debug messages, the GL functions under their Khronos names
localeThe active locale for @t strings: set, get, from LANG/LC_ALL, available

Pure and capability modules

A pure module only computes: it has no effect besides its return values and the memory you hand it (allocating memory is allowed). A capability module touches the outside world: the console, the clock, files, processes, the network, windows.

PureCapability
bits, ascii, cstr, str, fmt, path, mem, math, affine, words, collections, sort, rand, color, arena, utf8, hash, crypto, x509, ca_roots, tls, hpack, h2, conv, bytes, cli, json, serial, regex, encoding, charset, mime, gfx, image, font, fill, text, theme, easing, tween, wavio, fs, os, time, process, pipe, desktop, net, http, log, ui, widgets, locale, audio, gl, gpu, hot, vm

A pure module never imports a capability module, so code that uses only pure modules can’t do I/O. A host that embeds tape can rely on that.

Conventions

  • Text is passed as []const u8. A string or a literal is accepted wherever a []const u8 is expected (see Strings as byte views). A C string goes through cstr.as_view(p) first.
  • Errors are enum values returned as T or SomeError, each with a description, so "{err}" reads well. A module that passes on other modules’ errors wraps them in a tagged union (http.HttpError, net.SecureError), whose desc() reads the same way.
  • Generated containers come from @tape generators: the common ones are ready (collections.Vec_i64, collections.Map_string_i64); for others call collections.gen_vec(Person) once and use Vec_Person. You don’t import the modules the generated code uses. A container owns copies of its elements and is itself a managed value: it is freed when its variable goes out of scope and copied by assignment (see collections and Ownership).

Testing

Modules carry their tests in a #test region. tape test stdlib/cstr.tape runs them in the VM and as native code and checks that both agree; see tape test.