Next: , Up: compiler topics   [Index]


17.3.1 Handling of lexical top level bindings

Core language representation

Bindings defined by the core language form library-letrec* are named top level bindings; they are akin to the C language “global variables”. The form library-letrec* has the format:

(library-letrec* ((?lex ?loc ?init) ...) ?body)

in which: ?lex is a lexical gensym that uniquely identifies the binding in the core language form; ?loc is a location gensym which will be used at run–time to hold the current value of the binding in its value slot; ?init is the initialisation expression.

References to top level bindings are represented by standalone ?lex gensyms; assignments to top level bindings are represented by set! forms:

(set! ?lex ?rhs)

where the right–hand side expression ?rhs will, at run–time, evaluate to the new binding’s value.

Recordised language representation

The library-letrec* form is recordised into a rec*bind form:

(rec*bind ((?prel ?init) ...) ?body)

in which ?prel is a prelex struct holding both the ?lex and ?loc gensyms. References to top level bindings are represented by standalone prelex structs; assignments to top level bindings are represented by assign structs:

(assign ?prel ?rhs)

Implementation of references and assignments

Since the actual value of a top level binding is stored in the value field of a loc gensym:

Results of optimising rec*bind forms

A compiler pass takes care of performing “letrec optimisation”: structs of type rec*bind are transformed into a nested hierarchy of bind, fix and assign forms. Different cases must be handled in different ways.


Next: , Up: compiler topics   [Index]