`link' instruction links to symbols by module
authorAndy Wingo <wingo@pobox.com>
Thu, 15 May 2008 11:55:33 +0000 (13:55 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 15 May 2008 11:55:33 +0000 (13:55 +0200)
* 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.

module/system/il/compile.scm
module/system/il/ghil.scm
module/system/vm/assemble.scm
src/vm_loader.c

index f0e636b..51b914b 100644 (file)
         ((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)
index c3f3f82..0def60a 100644 (file)
 
 (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)))
           
index 19e633b..33274e7 100644 (file)
         ;; dump bytecode
         (push-code! `(load-program ,bytes)))
        ((<vlink> module name)
-        ;; FIXME: dump module
-        (push-code! `(link ,(symbol->string name))))
+         (dump! (and=> module module-name))
+         (dump! name)
+        (push-code! '(link)))
        ((<vdefine> module name)
         ;; FIXME: dump module
         (push-code! `(define ,(symbol->string name))))
index f901002..e658381 100644 (file)
@@ -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;
 }