Skip to main content

Module copyterm

Module copyterm 

Source
Expand description

Relocatable off-heap term copies.

One mechanism, three users: thrown error balls must survive the heap rewinding that backtracks to a catch frame; findall/3 must preserve each solution’s template instance across the rewind that discards the goal’s bindings; copy_term/2 is the user-facing form.

A TermBuf stores cells exactly like the heap, except pointer payloads are indices into the buffer itself. Copy and restore are both ITERATIVE (a long list is as deep as it is long — recursion would overflow the C stack) and memoized per source cell, which preserves variable sharing and keeps cyclic terms (legal without occurs check) from looping.

Structs§

TermBuf

Functions§

copy_to_buf
Copy root (a heap word) into a relocatable buffer.
restore_cells
Materialize a term whose cells use buffer-relative pointer payloads, rooted at root, onto the machine heap; returns the heap root. The slice-based core of restore_from_buf — also used by the fact-table to restore a non-immediate column from its read-only .rodata blob (those blobs are ground, so the TAG_REF arm never fires there).
restore_from_buf
Materialize a buffer back onto the machine heap; returns the root.