A program’s closures compiled where they stand, through compile-asm’s function world.
compile-fn!Compile the closure F where it stands: every holder of F calls the compiled version from here on, and the interpreted version stays on the Compiled list as the reference. Integer doors, obj-ref, obj-set!, first, rest, pair, eq?, null?, pair?, symbol?, not, if, when, unless, match, do, and, or, def, set! and let (not a named let) compile in place; a (guard (name handler) body) is outlined into two closures, run by the engine’s guard and compiled in turn. A fn literal is outlined and handed the locals of F it reads as values: one called where it is written, ((fn (self …) …) arg …), with self only at the head of a call, becomes a closure taking those locals as parameters, compiled in turn; one that reads no local is made once and compiled in turn; any other answers a closure holding the values whose one call is of its body compiled in turn, so its self-calls stay compiled; one whose locals F writes after it, or whose body sets one, is refused. A call of any other closure, or of a C primitive the engine’s ISA manifest does not label spine, passes it values, and a send (C sel …) to a class’s public static method calls the method method-of resolves when F is compiled, and one to its own public static field calls the class to read or write it. A rest parameter, (fn (self a . more) …), is bound to the list of the arguments after a’s, and such a function’s self-call is a call and not a jump. Applied, by apply or by the engine as a type’s handler is, the compiled F takes the values it is handed as a closure does: the first compile puts a routine in this base’s callable-apply slot (Base slot!) that tells it so, and a state image is written with the engine’s routine back in the slot. A body with a form the rewrite cannot carry leaves F interpreted, with the reason on the entry; anything but a closure raises a type error and makes no entry.
Parameters:
SYMBOL — What the list of compiled functions calls itANY — A closure made by fnReturns: Compiled — The entry: (entry state) is compiled, or failed with (entry reason)