1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 17:50:29 +02:00

rework late binding resolution to be simpler and more efficient

* libguile/programs.h (struct scm_program):
* libguile/programs.c (scm_c_make_program): Record the current module
  when making a program. This replaces the per-late binding recorded
  module in the generated code, which should be more efficient, both in
  terms of garbage, and in not calling resolve-module.
  (program-module): New accessor.

* module/system/vm/program.scm: Add program-module to exports.

* libguile/vm-i-loader.c (link-later): Remove this instruction, since now
  the entry in the object table is just a symbol, and can be loaded with
  load-symbol.

* libguile/vm-i-system.c (late-variable-ref, late-variable-set): Rework
  so as to look up in the module of the current program. The logic could
  be condensed quite a bit if scm_module_lookup () knew what to do with
  mod==#f.

* module/system/vm/assemble.scm (dump-object!): Dump <vlink-later> just
  as load-symbol, as mentioned in the note on link-later.

* module/system/il/ghil.scm: Update comment to reflect the new reality.
This commit is contained in:
Andy Wingo 2008-09-09 07:15:01 +02:00
parent 7618201efd
commit 8e3670748f
7 changed files with 40 additions and 51 deletions

View file

@ -262,34 +262,33 @@ VM_DEFINE_INSTRUCTION (variable_ref, "variable-ref", 0, 0, 1)
VM_DEFINE_INSTRUCTION (late_variable_ref, "late-variable-ref", 1, 0, 1)
{
unsigned objnum = FETCH ();
SCM pair_or_var;
SCM sym_or_var;
CHECK_OBJECT (objnum);
pair_or_var = OBJECT_REF (objnum);
sym_or_var = OBJECT_REF (objnum);
if (!SCM_VARIABLEP (pair_or_var))
if (!SCM_VARIABLEP (sym_or_var))
{
SYNC_REGISTER ();
if (SCM_LIKELY (scm_module_system_booted_p))
if (SCM_LIKELY (scm_module_system_booted_p && SCM_NFALSEP (bp->module)))
{
/* either one of these calls might longjmp */
SCM mod = scm_resolve_module (SCM_CAR (pair_or_var));
pair_or_var = scm_module_lookup (mod, SCM_CDR (pair_or_var));
/* might longjmp */
sym_or_var = scm_module_lookup (bp->module, sym_or_var);
}
else
{
pair_or_var = scm_lookup (SCM_CDR (pair_or_var));
sym_or_var = scm_sym2var (sym_or_var, SCM_BOOL_F, SCM_BOOL_F);
}
if (!VARIABLE_BOUNDP (pair_or_var))
if (!VARIABLE_BOUNDP (sym_or_var))
{
err_args = SCM_LIST1 (pair_or_var);
err_args = SCM_LIST1 (sym_or_var);
goto vm_error_unbound;
}
OBJECT_SET (objnum, pair_or_var);
OBJECT_SET (objnum, sym_or_var);
}
PUSH (VARIABLE_REF (pair_or_var));
PUSH (VARIABLE_REF (sym_or_var));
NEXT;
}
@ -327,28 +326,27 @@ VM_DEFINE_INSTRUCTION (variable_set, "variable-set", 0, 1, 0)
VM_DEFINE_INSTRUCTION (late_variable_set, "late-variable-set", 1, 1, 0)
{
unsigned objnum = FETCH ();
SCM pair_or_var;
SCM sym_or_var;
CHECK_OBJECT (objnum);
pair_or_var = OBJECT_REF (objnum);
sym_or_var = OBJECT_REF (objnum);
if (!SCM_VARIABLEP (pair_or_var))
if (!SCM_VARIABLEP (sym_or_var))
{
SYNC_BEFORE_GC ();
if (SCM_LIKELY (scm_module_system_booted_p))
if (SCM_LIKELY (scm_module_system_booted_p && SCM_NFALSEP (bp->module)))
{
/* either one of these calls might longjmp */
SCM mod = scm_resolve_module (SCM_CAR (pair_or_var));
pair_or_var = scm_module_lookup (mod, SCM_CDR (pair_or_var));
/* might longjmp */
sym_or_var = scm_module_lookup (bp->module, sym_or_var);
}
else
{
pair_or_var = scm_lookup (SCM_CDR (pair_or_var));
sym_or_var = scm_sym2var (sym_or_var, SCM_BOOL_F, SCM_BOOL_F);
}
OBJECT_SET (objnum, pair_or_var);
OBJECT_SET (objnum, sym_or_var);
}
VARIABLE_SET (pair_or_var, *sp);
VARIABLE_SET (sym_or_var, *sp);
DROP ();
NEXT;
}