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).
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.
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.
Value
A dynamically typed Doge value.

Functions§

add
+ — Int+Int (checked), Float promotion, Str concatenation, List 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.
div
/ — always returns a Float (5 / 2 == 2.5), per the sharp-edges table in docs/README.md.
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_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_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_write
fetch.write(path, text) — replace the file’s contents with text, creating it if needed. Returns none.
floordiv
// — floor division. Int//Int yields an Int (floored toward negative infinity, Python-style); any Float operand yields 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.
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.
le
<=.
len
len(x) — character count for a Str, 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 (checked) or Float promotion.
ne
!=.
neg
Unary -.
nerd_abs
nerd.abs(x) — magnitude. An Int stays an Int (and abs(i64::MIN) overflows catchably); a Float stays a Float.
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.
nerd_pow
nerd.pow(base, exponent) — Int^Int (non-negative exponent) stays an Int and overflows catchably; 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.
pow
** — exponentiation. Int raised to a non-negative Int stays an Int (checked, so it overflows catchably); a negative exponent or any Float operand promotes to Float. 0 ** <negative> is a catchable division by zero.
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. 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.
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. Losing significant bits (or a count of 64 or more) is a catchable overflow error, never a silent wraparound.
shr
>> — arithmetic right shift. A count of 64 or more saturates to 0 for a non-negative value and -1 for a negative one, matching the sign fill.
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.
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 (checked) or Float promotion.
to_float
float(x) — Int and Bool widen to 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 truncated toward zero, Bool to 0/1, a Str parsed as a whole number. 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_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.