The input S-expression to a syntax compiler is the full subexpression which invoked the syntax. Thus, the car of this syntax will always be the global variable name though which the syntax was accessed. The goal of the compiler is to perform as much evaluation work as possible on this expression without using variable values; part of this work is converting variable names to static distance coordinates and linkable global references.
The compiler is passed a compile-time environment as a Scheme_Env *; in this environment the ``value'' of each local variable is a symbol which is the variable's name. The function scheme_static_distance takes a synbol and a compile-time environment and returns the location of the variable in a run-time environment, either as a static-distance value ( scheme_static_distance_type or scheme_static_distance_unbox_type), a global variable or reference value ( scheme_variable_type or scheme_variable_reference_type), or a constant value. More information about compile-time environments is in section 3.16.
The compiler is also passed a pointer to a Scheme_Compile_Info structure. This structure contains information about the context in which the syntax occurs; before the compiler returns, this structure must be filled in with information needed by the external context. This record also tells the compiler whether to return linked or unlinked code (avoiding an additional linking pass if the compiled code can only be linked once).
When the syntax compiler compiles sub-expressions, then it must provide an appropriately initialized Scheme_Compile_Info structure for each sub-expression compilation. The syntax compiler may find the information returned by sub-expressions to be useful. In any case, syntax compiler is responsible for merging the compilation info from the subexpressions into its own Scheme_Compile_Info. Utilities are provided to facilitate this process.
The result of compilation is a collection of data that needs to be linked with some syntax-specific linking function. The result of compilation is (usually) a function-data pair created with make_syntax_compilation.
Sometimes it is useful to save compiled code to disk. In order to save this function-data pair to a file as compiled code, MzScheme must be able to: