Go to the first, previous, next, last section, table of contents.


Class CompiledFunction

Class CompiledFunction instances contain the actual executable bytecodes that drive the Muq interpreter, along with constants needed by the code. (Making the constant vector a separate object would be slightly cleaner design, but would slow down procedure call/return by requiring two objects to be found instead of just one.)

Thunks and promises are simply compiled-functions with special flags set on them. (Internally, they are also referenced via pointers with special flags set, so as to be able to implement promise and thunk functionality extremely efficiently in the interpreter, without actually having to waste any instructions on each bytecode checking to see if the arguments are thunks and need to be evaluated. In a sense, thunks add zero overhead to the basic Muq instruction dispatch code.)

CompiledFunction instances do not actually possess the full overhead of a standard muq object, with creation time, change time and so forth: since compiled-functions may be created by the thousand when using anonymous functions as data constructors (via capture of lexical environment in lisp lambdas, say) or when using promises to program in pure-functional style, I have attempted to reduce space overhead of compiled-functions to the absolute minimum.

The physical layout of a compiledFunction instance is currently approximately:

Thus, if one minimizes the amount of code actually stored in a compiledFunction by having most of its work done by another compiledFunction, it may reasonably be used as a lightweight object, capable of containing information with only about five words more overhead than a vector, but unlike a vector, able to provide encapsulation and arbitrary computation in response to a call.

Since compiledFunction objects are not really true objects, storing arbitrary properties on them via the normal object-oriented property get/set calls is not currently supported.

Compiled-functions export the following public properties:

$S.asRoot?           True iff "as-root{...}" is used in source.
$S.compileTime?      True iff "compileTime" flagged in source.
$S.constCount        Number of constants in constant vector.
$S.generic?           True iff is a old-style generic (CommonLisp sense) fn.
$S.mosGeneric?       True iff is a Muq Object System generic fn.
$S.keptPromise?      True iff promise has been evaluated.
$S.neverInline?      True iff "neverInline" flagged in source.
$S.owner              User owning compiledFunction.
$S.pleaseInline?     True iff "pleaseInline" flagged in source.
$S.prim?              True iff fn is a C-coded in-server primitive.
$S.promiseOrThunk?  True iff either of the promise? or thunk? values is true.
$S.promise?           True iff function is a promise.
$S.source             Source function for this compiled function.
$S.thunk?             True iff function is a thunk.

Note: For convenience, the $S properties are also available in the public (default) propdir.


Go to the first, previous, next, last section, table of contents.