Skip to main content

Crate doge_runtime

Crate doge_runtime 

Source

Structs§

BoundMethodData
A method captured together with the receiver it was read off. Two bound methods are equal only when they name the same method on the very same instance (a.speak == a.speak, but not b.speak).
BowlHandle
The clonable half of a bowl: a sender plus a shared receiver over the same channel. Cloning a handle is how both sides of a pup boundary reach one channel — a bowl is deliberately shared, not copied. The channel carries Packed values, since every message crosses a thread boundary.
DogeError
A catchable runtime error: a category plus a precise, plain-English message.
FunctionData
A first-class function value: which compiled function it is (fn_id, matched by the generated call_function dispatcher), the name it prints and errors under, and the cells it captured from its enclosing scope. Two function values are equal only when they share both the definition and the captured cells.
OrderedMap
An insertion-ordered string→Value map.
PackedError
A DogeError flattened for the trip back from a pup to its fetcher: no Rc, so it is Send. Rebuilt into a real error (with its original raise site preserved, so oh no sees the same file/line) by PackedError::into_error.
Rc
A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
RefCell
A mutable memory location with dynamically checked borrow rules

Enums§

ErrorKind
The category of a runtime error. Each variant maps to a pls/oh no catchable failure a Doge program can hit.
PackMode
How a socket is treated when its containing value is packed.
Packed
An owned, Send mirror of a Value, holding no Rc so it can move to another thread. Built by pack_value, consumed by unpack_packed.
Value
A dynamically typed Doge value.

Functions§

add
+ — Int+Int (arbitrary precision), Float/Decimal promotion, Str/Bytes/List concatenation, Error-as-message concatenation.
assert_error
Build the error a failing amaze <cond> raises. With a message (amaze cond, msg) the message value’s display form becomes the error text, mirroring bonk; without one it takes the default doge-flavored line.
attr_get
Read obj.name. A missing field is a catchable ErrorKind::AttrError; reading a field off a non-object is a catchable TypeError.
attr_get_or_bind
Read obj.name as a value, binding a method when there is no field of that name — the semantics of such f = a.speak. A field always wins over a method (fields appear on assignment). For a many instance, class_has_method tells whether the receiver’s class (or an ancestor) defines name; for a List/Dict, has_builtin_method decides. A name that is neither a field nor a method is the same catchable error a bare attr_get would raise.
attr_set
Write obj.name = value. A field appears the first time it is assigned; setting a field on a non-object is a catchable TypeError.
bark
bark x — print a value on its own line and evaluate to none, so bark can sit anywhere an expression is expected.
bitand
& — bitwise AND.
bitnot
~ — bitwise NOT (Int-only).
bitor
| — bitwise OR.
bitxor
^ — bitwise XOR.
bonk_error
Build the error a bonk <expr> raises. Re-raising a caught Error value (bonk err) preserves its type, message, and original location; any other value raises a Bonk whose message is the value’s display form, so bonk 5 reads 5 and bonk "much fail" reads much fail — the text bark prints.
builtin_method
Dispatch a method call on a List or Dict. recv is the receiver, name the method, args the already-evaluated arguments. A non-collection receiver, an unknown method, or a wrong argument count is a catchable error.
callee_function
Resolve a callee to the function it names. A class value calls the same way — its fn_id is a constructor arm — so both unwrap to their shared FunctionData. Calling anything else is a catchable TypeError, worded from the caller’s point of view.
cell_get
Read a captured cell, cloning the value out so the borrow ends here.
cell_set
Write a captured cell. Every writer shares the same cell, so the update is visible to every closure that captured it.
chase_run
chase.run(cmd, args, stdin) — run cmd with the Str args, feeding it the Str stdin (or nothing when stdin is none), and give back a Dict {"code": Int, "stdout": Str, "stderr": Str}. Failing to launch the program, or output that is not valid text, is a catchable IOError.
div
/ — always a Float for integers (5 / 2 == 2.5); exact for decimals (Decimal / DecimalDecimal). A Float/Decimal mix is a type error.
dson_emit
dson.emit(value) — a DSON document for value. Dict/List/Str/Int/Float/Bool/ none serialize; any other type, or a non-finite Float, is a catchable error.
dson_parse
dson.parse(text) — the value a DSON document denotes. Leading and trailing whitespace is ignored; anything after the top-level value is an error.
enter_call
Enter one call: fail (catchably) if the chain is already [RECURSION_LIMIT] deep, otherwise record the new depth. Pairs with exit_call.
env_args
env.args() — the script’s command-line arguments as a List of Str, excluding the program name. Empty when the script was given none.
env_get
env.get(name) — the value of environment variable name as a Str, or none when it is unset or not valid text.
eq
==.
error_field
Read a field off a caught Error value. A field other than type, message, file, or line is a catchable ErrorKind::AttrError.
error_value
The value bound by oh no err!: a structured Error carrying the caught error’s type, message, and location. A re-raised error keeps its embedded location; a fresh one takes the catch site’s file/line.
exit_call
Leave one call, undoing a matching enter_call.
fetch_append
fetch.append(path, text) — add text to the end of the file, creating it if needed. Returns none.
fetch_basename
fetch.basename(path) — the final /-separated component of path ("a/b/c.txt""c.txt"), or "" when the path ends in / (e.g. "/").
fetch_copy
fetch.copy(from, to) — copy the contents of file from to to, creating or replacing to. A missing from is a catchable IOError. Returns none.
fetch_delete
fetch.delete(path) — remove the file at path. A missing file is a catchable IOError. Returns none.
fetch_exists
fetch.exists(path) — whether a file or directory exists at path.
fetch_ext
fetch.ext(path) — the extension of the final component including the leading dot ("c.txt"".txt"), or "" when there is none. A leading dot on the component itself (".gitignore") is not an extension.
fetch_join
fetch.join(a, b) — join two path segments with /, Doge’s one canonical separator on every platform. If b is absolute (starts with /) it replaces a entirely; an empty a yields b unchanged.
fetch_list
fetch.list(path) — the names of the entries in directory path, sorted so the order is stable across runs. A missing path or one that is not a directory is a catchable IOError.
fetch_make_dir
fetch.make_dir(path) — create the directory at path, along with any missing parent directories. Doing this when the directory already exists is not an error. Returns none.
fetch_read
fetch.read(path) — the file’s whole contents as a Str. A missing file or one whose bytes are not valid text is a catchable IOError.
fetch_read_bytes
fetch.read_bytes(path) — the file’s whole contents as raw Bytes, for binary files that are not valid text. A missing file is a catchable IOError.
fetch_remove_dir
fetch.remove_dir(path) — remove the directory at path and everything inside it. A missing path is a catchable IOError. Returns none.
fetch_rename
fetch.rename(from, to) — move or rename the file or directory from to to, replacing to if it already exists. A missing from is a catchable IOError. Returns none.
fetch_stat
fetch.stat(path) — metadata about path as a Dict with size (Int bytes), modified (Float unix seconds, negative for a pre-epoch time), and is_dir (Bool). A missing path, or a platform that cannot report the modified time, is a catchable IOError.
fetch_write
fetch.write(path, text) — replace the file’s contents with text, creating it if needed. Returns none.
fetch_write_bytes
fetch.write_bytes(path, bytes) — replace the file’s contents with the raw bytes, creating it if needed. Returns none.
finish_pup
Pack a call’s outcome for the trip back from a pup to its fetcher: the return value is transferred (the pup is finishing, so a socket in the result moves home), and a raised error is flattened. A return value that cannot be packed becomes the fetched error.
floordiv
// — floor division. Int//Int yields an Int, Decimal//Decimal an exact integer-valued Decimal, any Float operand a floored Float.
function_arity_error
The error an indirect call raises when the argument count is wrong, worded like the compiler’s user-function arity message. max is None when the function is variadic.
ge
>=.
gib
gib() / gib("prompt") — read one line from standard input. An optional prompt, which must be a Str, is written without a trailing newline and flushed first. The returned Str has its trailing newline stripped; at end of input the result is none. A stdin read failure is a catchable IOError.
gt
>.
has_builtin_method
Whether a List or Dict has a built-in method named name — the gate a bound method read (such f = xs.append) checks before capturing the receiver. The method-name sets live beside each collection’s dispatch (list::LIST_METHODS, dict::DICT_METHODS), so binding and dispatch never disagree.
howl_accept
howl.accept(listener) — block until a client connects, then return the new connection. A non-listener socket is a catchable TypeError; a closed one is an IOError.
howl_close
howl.close(sock) — close a listener or connection now. Idempotent: closing an already-closed socket is fine. Returns none. Any later operation on it is a catchable IOError.
howl_connect
howl.connect(host, port) — open a TCP connection to host:port. A refused connection or unknown host is a catchable IOError.
howl_get
howl.get(url) — HTTP(S) GET. Returns a Dict {"status": Int, "body": Str}. A non-2xx response is returned like any other (its status and body); only a transport, TLS, or timeout failure is a catchable IOError.
howl_listen
howl.listen(host, port) — bind a TCP listener on host:port (port 0 lets the OS choose a free one, readable back with howl.port). A bind failure is a catchable IOError.
howl_port
howl.port(sock) — the local port a listener or connection is bound to. A closed socket is a catchable IOError.
howl_post
howl.post(url, body) — HTTP(S) POST of body as text/plain; charset=utf-8. Same return shape and error rule as howl_get.
howl_recv
howl.recv(conn, max_bytes) — read up to max_bytes bytes from a connection and return them as text, or none at end of input. Never splits a multi-byte character: an incomplete trailing sequence is held for the next read, and a call always yields at least one whole character (or none). max_bytes must be a positive Int. Genuinely invalid bytes are a catchable IOError.
howl_recv_line
howl.recv_line(conn) — read one line from a connection, without the trailing newline (a \r\n is trimmed too), or none at end of input. Invalid bytes are a catchable IOError.
howl_send
howl.send(conn, text) — write text as UTF-8 to a connection. Returns none. A broken pipe or a non-connection socket is a catchable error.
hunt_find
hunt.find(pat, text) — the first substring of text that matches pat, or none when there is no match.
hunt_find_all
hunt.find_all(pat, text) — a List of every non-overlapping match of pat in text, in order; an empty List when there is none.
hunt_groups
hunt.groups(pat, text) — the capture groups of the first match, group 0 (the whole match) first; a group that did not participate is none. none overall when pat does not match.
hunt_replace
hunt.replace(pat, text, repl) — every match of pat in text swapped for repl, where repl may reference capture groups as $1 or ${name}.
hunt_test
hunt.test(pat, text) — whether pat matches anywhere in text.
in_
needle in container. Python-style: a List tests element membership, a Dict tests key membership, a Str tests substring. Every other container type is a catchable type error. Matched by container variant (not a wildcard) so a new Value variant forces its own decision here.
index_get
container[index]. List by Int, Dict by Str key, Str by character index (never byte index — "héllo"[1] == "é").
index_set
container[index] = value. List and Dict are mutable in place; Str is immutable, so assigning into one is a catchable type error.
interp
String interpolation ("a {b} c") — join each part’s display form, the same text bark/str would show, into one Str. Always succeeds.
iter_value
The sequence a for loop walks: a List’s elements, a Str’s characters, or a Dict’s keys in insertion order, captured as an owned snapshot taken when the loop starts. Mutating the original value inside the loop body does not change what the loop visits. Any other value is a catchable type error.
json_emit
json.emit(value) — a compact JSON document (no insignificant whitespace) for value. Dict/List/Str/Int/Float/Bool/none serialize; any other type, or a non-finite Float (JSON has no NaN/infinity), is a catchable error.
json_parse
json.parse(text) — the value a JSON document denotes. Leading and trailing whitespace is ignored; anything after the top-level value is an error.
le
<=.
len
len(x) — character count for a Str, byte count for a Bytes, element count for a List or Dict. Anything else is a catchable type error.
lt
<.
method_arity_error
The error a method call raises when the argument count is wrong, worded like the compiler’s user-function arity message. max is None when the method is variadic.
mul
* — Int*Int (arbitrary precision) or Float/Decimal promotion.
nap_mono
nap.mono() — seconds from a fixed process origin, for measuring elapsed time. Only differences between two readings are meaningful; the origin itself is arbitrary. Monotonic, so it never jumps when the wall clock is adjusted.
nap_now
nap.now() — seconds since the Unix epoch (UTC), with sub-second precision. Never fails: a system clock set before the epoch reads back as a negative number rather than an error.
nap_parse
nap.parse(text) — unix seconds (as a Float) for an ISO-8601 UTC timestamp "YYYY-MM-DDTHH:MM:SSZ". The trailing Z is optional. Anything that is not a well-formed, in-range UTC timestamp is a catchable ValueError with a hint.
nap_rest
nap.rest(seconds) — block for seconds (Int or Float). A negative, non-finite, or absurdly large duration is a catchable ValueError rather than the panic Duration::from_secs_f64 would raise on such an input.
nap_stamp
nap.stamp(secs) — the ISO-8601 UTC string "YYYY-MM-DDTHH:MM:SSZ" for a unix timestamp (Int or Float seconds, truncated to a whole second toward negative infinity). A timestamp outside the representable Int range is a catchable ValueError.
ne
!=.
neg
Unary -.
nerd_abs
nerd.abs(x) — magnitude, keeping the argument’s own type. An Int stays an Int (and never overflows — it is arbitrary precision), a Float a Float, a Decimal a Decimal.
nerd_ceil
nerd.ceil(x) — round toward positive infinity, yielding an Int.
nerd_floor
nerd.floor(x) — round toward negative infinity, yielding an Int.
nerd_max
nerd.max(a, b) — the larger of two numbers, keeping the winner’s own type; a tie returns a.
nerd_min
nerd.min(a, b) — the smaller of two numbers, keeping the winner’s own type; a tie returns a. Compares exactly across Int/Decimal, via f64 once a Float is involved.
nerd_pow
nerd.pow(base, exponent) — the same rule as the ** operator: Int^Int (a non-negative exponent) stays an arbitrary-precision Int, Decimal^Int an exact Decimal, and any other numeric mix returns a Float.
nerd_round
nerd.round(x) — round half away from zero, yielding an Int.
nerd_sqrt
nerd.sqrt(x) — always a Float. A negative input is a catchable ValueError.
no_such_method
The error a method-call site raises when the receiver’s class has no such method. recv is an object at every real call site; the non-object branch is a defensive fallback that mirrors object_class_id.
not_
not — always succeeds, using Python truthiness.
not_in
needle not in container — the negation of in_, sharing its type rules so x not in xs and not (x in xs) always agree.
object_class_id
The class id of a method-call receiver, so the dispatcher can pick the right arm. Calling a method on a value that has no methods is a catchable AttrError.
pack_bowl
pack.bowl() — open a fresh, empty bowl (channel).
pack_drop
pack.drop(bowl, value) — send value into a bowl (transferring it, so a socket moves along). Returns none. A non-bowl handle is a catchable type error; a bowl whose every reader is gone is a catchable IOError rather than a silent loss.
pack_fetch
pack.fetch(pup) — wait for a pup to finish and return its function’s result, or re-raise (catchably) the error the pup hit, with the pup’s own file/line preserved. Fetching a pup twice, or a value that is not a pup, is a catchable error.
pack_snapshot
Snapshot a value for an ambient position (the globals a pup inherits), never failing: a value that cannot be packed — a Pup, or one nested too deep — simply arrives as none in the pup rather than blocking the spawn, since the pup likely never touches that binding.
pack_sniff
pack.sniff(bowl) — block until a value arrives in the bowl, then return it. A bowl that is empty and can never receive another value again (every writer is gone) is a catchable IOError rather than a forever-block. A non-bowl handle is a catchable type error.
pack_value
Deep-copy a value into its Send boundary form. A Pup cannot cross (a catchable type error), and a structure nested past [PACK_DEPTH_LIMIT] — which a self-referential value hits — is a catchable value error rather than an unbounded copy. mode decides only how a socket is treated.
pack_zoom
pack.zoom(f, args) — spawn f onto a new pup, called with the List args. The callee’s captures and the caller’s top-level variables are snapshotted in; each argument is transferred in. f must be callable and args must be a List, or it is a catchable type error. entry is the generated trampoline that rebuilds a world inside the pup and runs the call.
pow
** — exponentiation. Int raised to a non-negative Int stays an Int (arbitrary precision); a Decimal raised to a non-negative Int stays an exact Decimal; a negative exponent or any Float operand promotes to Float. 0 ** <negative> is a catchable division by zero, and an exponent too large to materialize is a catchable overflow.
range
range(start, end) — the Ints start, start+1, …, end-1 as an eager List. When end <= start the List is naturally empty. Both arguments must be Int; anything else is a catchable type error. A bound too large to be a machine index is a catchable value error (the List could never fit in memory anyway). The one-argument Doge form range(n) is compiled as range(0, n), so the runtime has one signature.
rem
% — modulo whose result takes the sign of the divisor (Python-style), so that a == (a // b) * b + (a % b) holds.
roll_choice
roll.choice(list) — one random element of a non-empty List. An empty List is a catchable ValueError.
roll_float
roll.float() — a uniform Float in 0.0 <= x < 1.0.
roll_int
roll.int(low, high) — a uniform Int in the inclusive range [low, high]. A low above high is a catchable ValueError, not an empty range.
roll_sample
roll.sample(list, k) — a new List of k distinct elements drawn from the List (by position, so duplicate values may appear if the List holds them). A k below zero or above the List’s length is a catchable ValueError.
roll_seed
roll.seed(n) — reseed this thread’s generator so the following draws repeat exactly on the next run. Returns none.
roll_shuffle
roll.shuffle(list) — a new List holding the same elements in random order. The argument is left untouched (module functions are pure; only list methods mutate in place).
set_script_args
Record the script’s command-line arguments. Called once at program startup (compiled main or the interpreter’s file runner); any later call is ignored, so the arguments a script sees are fixed for its whole run.
shl
<< — left shift. Int is arbitrary precision, so this never drops significant bits; only a negative or too-large shift count is a catchable error.
shr
>> — arithmetic (sign-preserving) right shift. A count larger than the value has bits saturates to the sign fill: 0 for a non-negative value, -1 for a negative one.
slice_get
container[start:end:step]. A List yields a new List and a Str a new Str (character-based); every other value is a catchable type error. Bounds clamp rather than erroring, matching Python.
spawn_pup
Spawn a job onto a fresh pup thread and hand back the pup value. The job produces the packed result (or error) the pup’s fetch will return. Shared by both engines: the compiler passes a generated trampoline, the interpreter a closure that runs a fresh interpreter. A thread the OS refuses to start is a catchable IOError.
strings_beeg
strings.beeg(s) — every letter uppercased.
strings_contains
strings.contains(s, needle) — whether needle occurs anywhere in s.
strings_join
strings.join(parts, sep) — the Strs in parts joined with sep. Every element of parts must be a Str.
strings_replace
strings.replace(s, from, to) — every occurrence of from in s swapped for to. Replacing an empty from is a catchable ValueError.
strings_smoll
strings.smoll(s) — every letter lowercased.
strings_split
strings.split(s, sep) — a List of the pieces of s between each sep. Empty pieces are kept ("a,,b" splits into three); splitting on an empty separator is a catchable ValueError.
strings_trim
strings.trim(s) — leading and trailing whitespace removed.
sub
- — Int-Int (arbitrary precision) or Float/Decimal promotion.
to_bytes
bytes(x) — raw bytes from a value. A Str is UTF-8 encoded; a List of Ints becomes those bytes, each of which must be in 0..=255 (a catchable ValueError otherwise); a Bytes is returned unchanged. Any other type is a catchable TypeError.
to_decimal
dec(x) — an exact Decimal. An Int converts exactly; a Bool to 0/1; a numeric Str parses exactly (dec("0.10")); a Float converts via its shortest decimal form, so dec(0.1) is exactly 0.1 and not the binary noise a raw cast would carry. A Decimal is returned unchanged. A non-numeric Str is a catchable ValueError; other types are a TypeError.
to_float
float(x) — Int and Bool widen to Float, Decimal rounds to the nearest Float, Float is unchanged, a numeric Str is parsed. A non-numeric Str is a catchable ValueError; other types are a TypeError.
to_int
int(x) — Int unchanged, Float and Decimal truncated toward zero, Bool to 0/1, a Str parsed as a whole number (of any size). A Str that isn’t a number is a catchable ValueError; other types are a TypeError.
to_str
str(x) — the value’s printed form as a Str. Always succeeds.
unpack_globals
Unpack a globals snapshot into the values a pup’s fresh Env fields take, in the order they were packed. Anything that is not a list snapshot yields no values, so the fields fall back to none.
unpack_packed
Rebuild a fresh Value from its boundary form on the receiving thread, with brand-new Rcs and cells — no sharing survives the trip, which is exactly the copy semantics a pup boundary promises.
unpack_value
Unpack v into the values a multiple-assignment binds: the same sequence a for loop walks (a List’s elements, a Str’s characters, or a Dict’s keys), split to fixed leading targets plus, when rest is set, a trailing collector that gathers every surplus value into a List. The returned Vec has exactly fixed elements without a collector, or fixed + 1 with one (its last element being the collector List). A non-iterable value or a length that cannot fill the targets is a catchable error, so pls/oh no can handle it.
values_equal
Structural, Python-style equality: 1 == 1.0, deep list/dict comparison, everything else across types is unequal.

Type Aliases§

Cell
A shared, mutable binding cell. Closures capture enclosing variables by sharing these: a such/param captured by a nested function becomes a Cell, so a reassignment on either side is visible to the other.
DogeResult
The result of any fallible runtime operation. Defaults to yielding a crate::Value since that is what almost every operator and builtin produces.
PupEntry
The signature of the generated trampoline a pup runs: build a fresh world from the globals snapshot, unpack the callee and its arguments, run the call, and pack the result (or the error) for the trip home. A plain fn pointer, so it is Send and can be handed to a spawned thread.