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


7.5 Expanding libraries from source

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

Function: expand-library sexp
Function: expand-library sexp filename
Function: expand-library sexp filename verify-libname

Expand the symbolic expression sexp and intern the result (see libutils interning). When successful: return a <library> object; if an error occurs: raise an exception.

sexp must be a symbolic expression (library . ---) representing a R6RS library form with optional Vicare extensions.

The optional filename must be #f or a string representing the source file from which the library was loaded; it is used for information purposes. When not given defaults to #f.

The optional argument verify-libname must be a procedure accepting a R6RS library name as argument and returning unspecified values; it is meant to perform some validation upon the library name components and raise an exception if something is wrong; otherwise it should just return.

Function: expand-library->sexp sexp

This function is for debugging purposes. Expand the library form sexp and return the return values of expand-library in an alist with the following symbols as keys:

uid libname
import-libdesc* visit-libdesc* invoke-libdesc*
invoke-code visit-code
export-subst global-env
guard-code guard-libdesc*
option*

We can toy with the library expander using the following code:

#!r6rs
(import (vicare)
  (prefix (vicare libraries) libs.))
(print-gensym #f)
(debug-print (libs.expand-library->sexp ?sexp))

where ?sexp is the library symbolic expression. For example, expanding the library:

(library (ciao)
  (export var fun mac etv)
  (import (vicare))
  (define var 1)
  (define (fun)
    2)
  (define-syntax (mac stx)
    3)
  (define-syntax etv
    (make-expand-time-value
     (+ 4 5))))

yields the invoke-code:

(library-letrec*
    ((lex.var loc.lex.var '1)
     (lex.fun loc.lex.fun (annotated-case-lambda fun (() '2))))
  ((primitive void)))

the visit-code:

(begin
  (set! loc.lab.mac
        (annotated-case-lambda
            (#'lambda (#'stx) #'3)
          ((lex.stx) '3)))
  (set! loc.lab.etv
        (annotated-call
            (make-expand-time-value (+ 4 5))
          (primitive make-expand-time-value)
          (annotated-call (+ 4 5) (primitive +) '4 '5))))

the export-subst:

((etv . lab.etv)
 (mac . lab.mac)
 (fun . lab.fun)
 (var . lab.var))

the global-env:

((lab.var global        . loc.lex.var)
 (lab.fun global        . loc.lex.fun)
 (lab.mac global-macro  . loc.lab.mac)
 (lab.etv global-etv    . loc.lab.etv))

Another example, for the library:

(library (ciao (1 2))
  (export doit)
  (import (vicare))
  (stale-when (< 1 2)
    (define a 123))
  (stale-when (< 2 3)
    (define b 123))
  (define (doit)
    123))

the guard-code is:

(if (if '#f
        '#t
       (annotated-call (< 1 2) (primitive <) '1 '2))
    '#t
  (annotated-call (< 2 3) (primitive <) '2 '3))

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