Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

  1. Implement it in crates/korrin/src/builtins.rs against the NativeFnPtr signature — fn(&mut Interpreter, &[Value], Span) -> Exec<Value>.
  2. Add a row to the BUILTINS table (name, Arity, function).
  3. 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.
  4. Add or extend a golden test under crates/korrin/tests/programs/.
  5. Add a CHANGELOG.md entry.

Adding a method

  1. Implement it in crates/korrin/src/interpreter/methods.rs against the NativeMethodFn signature — the receiver arrives as &Value, separate from the argument slice.
  2. Add a method(...) row to STR_METHODS, LIST_METHODS, or MAP_METHODS. The Arity counts arguments after the receiver.
  3. 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.
  4. Add or extend a golden test and an interpreter unit test.
  5. Add a CHANGELOG.md entry.