scsh-users
[Top] [All Lists]

Re: Now it works (was Re:Modules)

To: Francisco Vides Fernandez <pax@dedalo.ws>
Subject: Re: Now it works (was Re:Modules)
From: Martin Gasbichler <gasbichl@informatik.uni-tuebingen.de>
Date: Tue, 10 Dec 2002 19:24:39 +0100
Cc: sperber@informatik.uni-tuebingen.de (Michael Sperber [Mr. Preprocessor]), scsh@zurich.ai.mit.edu
>>>>> "FVF" == Francisco Vides Fernandez <pax@dedalo.ws> writes:

[snip]
FVF> And loads all structures into config package. Right. But these
FVF> structures aren't opened after I load them. I guess I should open with
FVF> a scheme form. I've searched the equivalent for the ,open command in a
FVF> scheme form, but I can't find it. Can you give me some clue?

Here is some code to access structures at run time. It uses a lot of
undocumented procedures of the module system so don't take this as an
official extension of the module system, hold me reliable for any
consequences, or tell anybody about it...

;; contents of rt-module.scm

(define-record-type rt-structure :rt-structure
  (make-rt-structure meta-structure)
  rt-structure?
  (meta-structure rt-structure-meta-structure))

(define (rt-structure-loaded? rt-structure)
  (package-loaded?
   (structure-package (rt-structure-meta-structure rt-structure))))

(define-record-discloser :rt-structure
  (lambda (s)
    (list 'rt-stucture (structure-name (rt-structure-meta-structure
s)))))

(define (reify-structure name)
  (let ((struct (get-structure name)))
    (make-rt-structure struct)))

(define (load-rt-structure rts)
  (ensure-loaded (rt-structure-meta-structure rts)))

(define (rt-structure-binding structure name)
  (if (not (rt-structure-loaded? structure))
      (error "Structure not loaded" structure))
  (contents
   (binding-place
    (generic-lookup (rt-structure-meta-structure structure)
                    name))))

(define (load-config-file file)
  (load file (config-package)))

;; structure definition
(define-structure rt-modules rt-modules-interface
  (open scheme
        meta-types ; syntax-type
        interfaces ; for-each-declaration
        define-record-types
        records
        signals
        bindings
        packages
        packages-internal
        locations
        environments
        ensures-loaded
        package-commands-internal)
  (files rt-module))

load-config-file will load a file into the config package

reify-structure returns a run-time representation of a structure

load-rt-structure loads the structure

rt-structure-binding returns the value of a name within a structure

-- 
Martin

<Prev in Thread] Current Thread [Next in Thread>