7.17.7 Compilation

Prev Up Next Page 296 of 800 Search internet

Compilation is a process which takes the value definitions of the codex, compiles them to a more efficient internal form, and stores the compiled functions in the code of the page. Compilation of the page construct is treated in a special way.

Compilation only considers the value aspect of constructs. Constructs that are proclaimed to denote lamdba abstraction, functional application, truth, or if-then-else are translated into their respective compiled representations. Constructs whose value is defined by a definition are translated according to the definition. A construct whose value is defined by an introduction is treated thus:

The compiler first compares the introduction to a built-in list of introductions the compiler knows 'from birth'. If a match is found, the construct is translated into the built-in representation of that known construct. If no match is found, the introduction is translated as if it was a definition.

In that way, a number of constructs become much faster than they would otherwise be. As an example, addition x+y is introduced. The compiler inside lgwam(1) recognizes the particular pattern used for definition of addition on the base page and translates addition into built-in addition. But if some compiler does not know addition beforehand, it defines addition according to the given definition which will work, though slowly.

Note that the compiler is in lgwam and not in lgc(1). The lgc compiler runs on the lgwam abstract machine and uses the lgwam compiler as backend. The lgc compiler has access to the lgwam compiler because the lgwam compiler is introduced on the base page. Put another way, the base page contains an introduction of a function named 'compile' and the right hand side of that definition happens to be recognized as defining the compiler. Thus, the lgwam compiler is used for the 'compile' construct of the base page, and that allows lgc to use it.

Prev Up Next Page 296 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05