1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 01:30:27 +02:00

allocate free variables inline to closures

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
  (SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
  (SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
  (scm_program_free_variable_ref, scm_program_free_variable_set_x):
  Allocate free variables inline with programs, instead of being in a
  vect. Should improve locality, and require fewer local variables in
  the VM.

* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
  variables.

* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
  and free_vars_count.
  (CHECK_FREE_VARIABLE): Update for inline free vars.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
  vars.
  (make-closure, fix-closure): Take the closure vals as separate stack
  args, and copy or fix them inline into the appropriate closure.

* module/language/objcode/spec.scm (program-free-variables): Define a
  local version of this removed function.

* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
  a vector when making closures.

* module/system/vm/program.scm: Export program-num-free-variables,
  program-free-variable-ref, program-free-variable-set!, and remove
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
  when making closures.
This commit is contained in:
Andy Wingo 2010-01-09 16:42:27 +01:00
parent 75c3ed2820
commit 6f16379e9a
10 changed files with 114 additions and 56 deletions

View file

@ -42,13 +42,30 @@ SCM_DEFINE (scm_make_program, "make-program", 1, 2, 0,
objtable = SCM_BOOL_F;
else if (scm_is_true (objtable))
SCM_VALIDATE_VECTOR (2, objtable);
if (SCM_UNLIKELY (SCM_UNBNDP (free_variables)))
free_variables = SCM_BOOL_F;
else if (free_variables != SCM_BOOL_F)
SCM_VALIDATE_VECTOR (3, free_variables);
return scm_double_cell (scm_tc7_program, (scm_t_bits)objcode,
(scm_t_bits)objtable, (scm_t_bits)free_variables);
if (SCM_UNBNDP (free_variables) || scm_is_false (free_variables))
{
SCM ret = scm_words (scm_tc7_program, 3);
SCM_SET_CELL_OBJECT_1 (ret, objcode);
SCM_SET_CELL_OBJECT_2 (ret, objtable);
return ret;
}
else
{
size_t i, len;
SCM ret;
SCM_VALIDATE_VECTOR (3, free_variables);
len = scm_c_vector_length (free_variables);
if (SCM_UNLIKELY (len >> 16))
SCM_OUT_OF_RANGE (3, free_variables);
ret = scm_words (scm_tc7_program | (len<<16), 3 + len);
SCM_SET_CELL_OBJECT_1 (ret, objcode);
SCM_SET_CELL_OBJECT_2 (ret, objtable);
for (i = 0; i < len; i++)
SCM_SET_CELL_OBJECT (ret, 3+i,
SCM_SIMPLE_VECTOR_REF (free_variables, i));
return ret;
}
}
#undef FUNC_NAME
@ -264,13 +281,42 @@ scm_c_program_source (SCM program, size_t ip)
return source; /* (addr . (filename . (line . column))) */
}
SCM_DEFINE (scm_program_free_variables, "program-free-variables", 1, 0, 0,
SCM_DEFINE (scm_program_num_free_variables, "program-num-free-variables", 1, 0, 0,
(SCM program),
"")
#define FUNC_NAME s_scm_program_free_variables
#define FUNC_NAME s_scm_program_num_free_variables
{
SCM_VALIDATE_PROGRAM (1, program);
return SCM_PROGRAM_FREE_VARIABLES (program);
return scm_from_ulong (SCM_PROGRAM_NUM_FREE_VARIABLES (program));
}
#undef FUNC_NAME
SCM_DEFINE (scm_program_free_variable_ref, "program-free-variable-ref", 2, 0, 0,
(SCM program, SCM i),
"")
#define FUNC_NAME s_scm_program_free_variable_ref
{
unsigned long idx;
SCM_VALIDATE_PROGRAM (1, program);
SCM_VALIDATE_ULONG_COPY (2, i, idx);
if (idx >= SCM_PROGRAM_NUM_FREE_VARIABLES (program))
SCM_OUT_OF_RANGE (2, i);
return SCM_PROGRAM_FREE_VARIABLE_REF (program, idx);
}
#undef FUNC_NAME
SCM_DEFINE (scm_program_free_variable_set_x, "program-free-variable-set!", 3, 0, 0,
(SCM program, SCM i, SCM x),
"")
#define FUNC_NAME s_scm_program_free_variable_set_x
{
unsigned long idx;
SCM_VALIDATE_PROGRAM (1, program);
SCM_VALIDATE_ULONG_COPY (2, i, idx);
if (idx >= SCM_PROGRAM_NUM_FREE_VARIABLES (program))
SCM_OUT_OF_RANGE (2, i);
SCM_PROGRAM_FREE_VARIABLE_SET (program, idx, x);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME