x-lang

← Index

x/tool/compiled

Functions that have a compiled version: switched to interpreted before a state image is written and compiled again after one is loaded, with a list of which are compiled.

Class Compiled

A function that has a compiled version: its interpreted version, the function that compiles it, and the function that installs either. (Compiled make …) adds one to the list and compiles it; (Compiled report) prints the list.

name

What the list calls the function

Field: data carried by a Compiled instance.

interpreted

The interpreted version, which is installed whenever the compiled one is not

Field: data carried by a Compiled instance.

compile

(fn (_)) answering the compiled version; a raise fails, and answering the interpreted version declines

Field: data carried by a Compiled instance.

install

(fn (_ version)) installing a version where the function is called from

Field: data carried by a Compiled instance.

state

compiled, interpreted or failed

Field: data carried by a Compiled instance.

reason

The text of the raise that failed the compile, or the empty string

Field: data carried by a Compiled instance.

compiled

The compiled version while it is installed, and nil otherwise

Field: data carried by a Compiled instance.

(%install! version state reason)

Instance method: called on a Compiled instance.

(compile!)

Compile the function and install the compiled version. A compile that raises has failed: the interpreted version is installed and the raise’s text is kept as the reason. A compile that answers the interpreted version has declined, and the interpreted version is installed.

Instance method: called on a Compiled instance.

Returns: SYMBOL — The state the entry is left in: compiled, interpreted or failed

Examples:

((new Compiled name 'f interpreted first compile (fn (_) (Err raise 'value "no compiler here" ())) install (fn (_ v) v)) compile!) => 'failed
((new Compiled name 'f interpreted first compile (fn (_) first) install (fn (_ v) v)) compile!) => 'interpreted

(interpret!)

Install the interpreted version and let go of the compiled one, so that nothing the entry holds is this process’s alone.

Instance method: called on a Compiled instance.

Returns: SYMBOL — interpreted

Examples:

(do (def c (new Compiled name 'f interpreted first compile (fn (_) rest) install (fn (_ v) v))) (c compile!) (list (c interpret!) (c compiled))) => ('interpreted ())

all

Every entry, newest first

Static field: data held by Compiled itself, not by its instances.

(Compiled make name interpreted compile install)

Add a function to the list and compile it. Every entry is switched to interpreted before a state image is written, and compiled again after one is loaded, in the order the entries were made.

Parameters:

Returns: Compiled — The entry

See also: make-on-demand into-name into-cell

(Compiled make-on-demand name interpreted compile install)

Add a function to the list and compile it, as make does, for a compile that is dear and not always wanted. The entry is switched to interpreted with every other before a state image is written, and stays interpreted after one is loaded until its owner sends it compile!.

Parameters:

Returns: Compiled — The entry

See also: make compile!

(Compiled into-name name env)

An install function for a name’s binding: installing a version sets the name in that environment.

Parameters:

Returns: CALLABLE — (fn (_ version))

Examples:

(do (def f 1) ((op () env ((Compiled into-name 'f env) 2))) f) => 2

(Compiled into-cell cell)

An install function for the first of a pair, such as one cell of a type’s handler list.

Parameters:

Returns: CALLABLE — (fn (_ version))

Examples:

(do (def cell (pair 1 2)) ((Compiled into-cell cell) 5) (first cell)) => 5

(Compiled into-object target)

An install function for the function object itself: installing a version writes its type and its two data words into TARGET, so every holder of TARGET calls that version. TARGET keeps its flags and its identity.

Parameters:

Returns: CALLABLE — (fn (_ version))

Examples:

(do (def g (fn (_) 1)) ((Compiled into-object g) (fn (_) 2)) (g)) => 2

See also: in-place

(Compiled in-place name target compile)

Add a function to the list as make does, installed into TARGET itself (into-object). The interpreted version is a new function object holding TARGET’s two data words, which keeps TARGET’s body alive while TARGET holds the compiled version.

Parameters:

Returns: Compiled — The entry

See also: make into-object

(Compiled named name)

The newest entry of that name.

Parameters:

Returns: Compiled — The entry, or nil when no entry has the name

Examples:

(null? (Compiled named 'no-such-entry)) => #t

(Compiled interpret-all!)

Switch every entry to its interpreted version, newest first. The image writer does this before its walk.

Returns: NIL — nil

(Compiled compile-all!)

Compile every entry, oldest first, so that an entry which reads an earlier one’s compiled version finds the one just made.

Returns: NIL — nil

(Compiled list)

The state of every entry, oldest first.

Returns: LIST — One (name state reason) list for each entry

(Compiled report)

Print the list, oldest first: each function’s name, its state, and the reason when its compile failed.

Returns: NIL — nil