From: Andy Wingo Date: Thu, 15 May 2008 11:55:33 +0000 (+0200) Subject: `link' instruction links to symbols by module X-Git-Url: https://git.hcoop.net/bpt/guile.git/commitdiff_plain/6167de4f72d5aed29a73f3a4e7e6b4bfebe4287a `link' instruction links to symbols by module * module/system/il/compile.scm (make-glil-var): Only dump the module if we actually have one. * module/system/il/ghil.scm (ghil-define): Make sure that ghil-var-env is a ghil-env. * src/vm_loader.c (link): * module/system/vm/assemble.scm (dump-object!): Rewrite `link' to take two Scheme arguments on the stack: the symbol, as before, and the module in which the symbol was found at compile time. This introduces some undesireable early binding, but it does let the vm load up modules, and (potentially) have multiple modules in one .go file. On a practical level, I can now compile modules and have their .go files load up the modules' dependencies as necessary. --- diff --git a/module/system/il/compile.scm b/module/system/il/compile.scm index f0e636bcf..51b914b6a 100644 --- a/module/system/il/compile.scm +++ b/module/system/il/compile.scm @@ -100,8 +100,9 @@ ((eq? e (ghil-var-env var)) (make-glil-external op depth (ghil-var-index var))))) ((module) - (make-glil-module op (ghil-mod-module (ghil-env-mod (ghil-var-env var))) - (ghil-var-name var))) + (let ((env (ghil-var-env var))) + (make-glil-module op (and env (ghil-mod-module (ghil-env-mod env))) + (ghil-var-name var)))) (else (error "Unknown kind of variable:" var)))) (define (codegen ghil) diff --git a/module/system/il/ghil.scm b/module/system/il/ghil.scm index c3f3f82ca..0def60ad0 100644 --- a/module/system/il/ghil.scm +++ b/module/system/il/ghil.scm @@ -212,7 +212,7 @@ (define (ghil-define mod sym) (or (assq-ref (ghil-mod-table mod) sym) - (let ((var (make-ghil-var mod sym 'module))) + (let ((var (make-ghil-var (make-ghil-env mod) sym 'module))) (apush! sym var (ghil-mod-table mod)) var))) diff --git a/module/system/vm/assemble.scm b/module/system/vm/assemble.scm index 19e633b82..33274e780 100644 --- a/module/system/vm/assemble.scm +++ b/module/system/vm/assemble.scm @@ -257,8 +257,9 @@ ;; dump bytecode (push-code! `(load-program ,bytes))) (( module name) - ;; FIXME: dump module - (push-code! `(link ,(symbol->string name)))) + (dump! (and=> module module-name)) + (dump! name) + (push-code! '(link))) (( module name) ;; FIXME: dump module (push-code! `(define ,(symbol->string name)))) diff --git a/src/vm_loader.c b/src/vm_loader.c index f90100272..e658381dc 100644 --- a/src/vm_loader.c +++ b/src/vm_loader.c @@ -178,16 +178,23 @@ VM_DEFINE_LOADER (load_program, "load-program") NEXT; } -VM_DEFINE_LOADER (link, "link") +VM_DEFINE_INSTRUCTION (link, "link", 0, 2, 1) { - SCM sym; - size_t len; - - FETCH_LENGTH (len); - sym = scm_from_locale_symboln ((char *)ip, len); - ip += len; - - PUSH (scm_lookup (sym)); + SCM modname, mod, sym; + POP (sym); + POP (modname); + if (SCM_NFALSEP (modname)) + { + mod = scm_c_module_lookup (scm_resolve_module (modname), + "%module-public-interface"); + if (SCM_FALSEP (mod)) + SCM_MISC_ERROR ("Could not load module", SCM_LIST1 (modname)); + + PUSH (scm_module_lookup (SCM_VARIABLE_REF (mod), sym)); + } + else + PUSH (scm_lookup (sym)); + NEXT; }