How to add a builtin or a method
Korrin's core vocabulary is a set of functions in the global scope (print,
range, str, …) plus methods on the built-in types str / list / map
(xs.push(v), text.trim()). The rule for which to add
(ADR 0016): a function constructs or
converts a value or does I/O; a method operates on its receiver.
Adding a function
- Implement it in
crates/korrin/src/builtins.rsagainst theNativeFnPtrsignature —fn(&mut Interpreter, &[Value], Span) -> Exec<Value>. - Add a row to the
BUILTINStable (name,Arity, function). - Document it as a
###heading in../spec/08-builtins.md§8.1 — the coverage test (crates/korrin/tests/builtins.rs) fails if you skip this, and fails again if the name and the table disagree. - Add or extend a golden test under
crates/korrin/tests/programs/. - Add a
CHANGELOG.mdentry.
Adding a method
- Implement it in
crates/korrin/src/interpreter/methods.rsagainst theNativeMethodFnsignature — the receiver arrives as&Value, separate from the argument slice. - Add a
method(...)row toSTR_METHODS,LIST_METHODS, orMAP_METHODS. TheAritycounts arguments after the receiver. - Document it in a table row in
../spec/08-builtins.md§8.2–8.4 as`type.name(args)`. The coverage test matches that form against the method tables both ways. - Add or extend a golden test and an interpreter unit test.
- Add a
CHANGELOG.mdentry.