Skip to main content

Module module

Module module 

Source
Expand description

Module system — (require "path.tlisp").

Evaluates another .tlisp file in the current interpreter, exposing its top-level (define …) forms as globals in the caller. Relative paths resolve against the directory of the current file being evaluated (or cwd if there isn’t one — e.g. from a REPL).

The require cache canonicalizes paths before storing so that (require "./util.tlisp") and (require "../scripts/util.tlisp") from sibling files converge on the same entry — no double-eval.

Implementation note: because tatara-lisp-eval does not expose an “eval a new form inside my interpreter” from the FFI layer, we install require as a macro-like native fn that READS + EXPANDS the target file but hands the forms back to the caller as a list the caller will then have to splice. To keep this ergonomic we wrap the top-level require behavior behind the install_require_with API (called from main.rs), which takes the interpreter by pointer and re-enters eval_program.

Functions§

install
Install (require PATH) on the given interpreter. Because require has to re-enter evaluation on the same interpreter, we capture an Arc<Mutex<Interpreter>> (or equivalent) via a closure — but since Interpreter<H> is not Send+Sync, we instead install a stub here and let main.rs override it with the real function after the interpreter is constructed.
plan_require
Utility for main.rs: take a (require PATH) string, resolve + canonicalize, return None if already required (caller should no-op), or the canonical path otherwise.
read_forms
Convenience wrapper: given an already-resolved path, read + parse it and return the spanned forms, ready for the caller to eval_program.
resolve_require_path
Resolve a (require) target string into an absolute canonical path. Relative paths resolve against the directory of ctx.current_file, or cwd if that’s unset. Absolute paths pass through unchanged.