mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-25 04:40:19 +02:00
`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.
This commit is contained in:
parent
26e69c9469
commit
6167de4f72
4 changed files with 23 additions and 14 deletions
|
@ -100,8 +100,9 @@
|
||||||
((eq? e (ghil-var-env var))
|
((eq? e (ghil-var-env var))
|
||||||
(make-glil-external op depth (ghil-var-index var)))))
|
(make-glil-external op depth (ghil-var-index var)))))
|
||||||
((module)
|
((module)
|
||||||
(make-glil-module op (ghil-mod-module (ghil-env-mod (ghil-var-env var)))
|
(let ((env (ghil-var-env var)))
|
||||||
(ghil-var-name 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))))
|
(else (error "Unknown kind of variable:" var))))
|
||||||
|
|
||||||
(define (codegen ghil)
|
(define (codegen ghil)
|
||||||
|
|
|
@ -212,7 +212,7 @@
|
||||||
|
|
||||||
(define (ghil-define mod sym)
|
(define (ghil-define mod sym)
|
||||||
(or (assq-ref (ghil-mod-table 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))
|
(apush! sym var (ghil-mod-table mod))
|
||||||
var)))
|
var)))
|
||||||
|
|
||||||
|
|
|
@ -257,8 +257,9 @@
|
||||||
;; dump bytecode
|
;; dump bytecode
|
||||||
(push-code! `(load-program ,bytes)))
|
(push-code! `(load-program ,bytes)))
|
||||||
((<vlink> module name)
|
((<vlink> module name)
|
||||||
;; FIXME: dump module
|
(dump! (and=> module module-name))
|
||||||
(push-code! `(link ,(symbol->string name))))
|
(dump! name)
|
||||||
|
(push-code! '(link)))
|
||||||
((<vdefine> module name)
|
((<vdefine> module name)
|
||||||
;; FIXME: dump module
|
;; FIXME: dump module
|
||||||
(push-code! `(define ,(symbol->string name))))
|
(push-code! `(define ,(symbol->string name))))
|
||||||
|
|
|
@ -178,16 +178,23 @@ VM_DEFINE_LOADER (load_program, "load-program")
|
||||||
NEXT;
|
NEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_DEFINE_LOADER (link, "link")
|
VM_DEFINE_INSTRUCTION (link, "link", 0, 2, 1)
|
||||||
{
|
{
|
||||||
SCM sym;
|
SCM modname, mod, sym;
|
||||||
size_t len;
|
POP (sym);
|
||||||
|
POP (modname);
|
||||||
FETCH_LENGTH (len);
|
if (SCM_NFALSEP (modname))
|
||||||
sym = scm_from_locale_symboln ((char *)ip, len);
|
{
|
||||||
ip += len;
|
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));
|
PUSH (scm_lookup (sym));
|
||||||
|
|
||||||
NEXT;
|
NEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue