Next: , Previous: , Up: compiler   [Index]


17.17 Inserting global assignments

The following bindings are exported by the library (vicare compiler).

Function: pass-insert-global-assignments input

Perform code transformations traversing the whole hierarchy in input, which must be a struct instance representing recordised code, and building a new hierarchy of transformed, recordized code; return the new hierarchy.

This module inserts global assignments forms that put the value of lexical top level bindings in the slot value of the corresponding loc gensym; for bindings whose value is a closure object: the value is also stored in the proc slot of the loc gensym.

As example, the library:

(library (insert-global-assignments-demo-1)
  (export a b c d)
  (import (rnrs))
  (define (a) '1)
  (define (b) '2)
  (define (c) '3)
  (define d '4))

is expanded into the core language form:

(library-letrec*
    ((a.lex a.loc (lambda () '1))
     (b.lex b.loc (lambda () '2))
     (c.lex c.loc (lambda () '3))
     (d.lex d.loc '4))
  (quote #!void))

then recordised and transformed into:

(fix ((a.lex_0 (lambda () (constant 1)))
      (b.lex_0 (lambda () (constant 2)))
      (c.lex_0 (lambda () (constant 3))))
  (seq
    (funcall (primref $set-symbol-value/proc!)
             (constant a.loc) a.lex_0)
    (funcall (primref $init-symbol-value!)
             (constant b.loc) b.lex_0)
    (funcall (primref $init-symbol-value!)
             (constant c.loc) c.lex_0)
    (bind ((d.lex_0 (constant 4)))
      (seq
        (funcall (primref $init-symbol-value!)
                 (constant d.loc) d.lex_0)
        (constant #!void)))))