(SCHEME_OBJECT *, SCHEME_OBJECT, SCHEME_OBJECT *, int);
static long assign_variable_cache
(SCHEME_OBJECT, SCHEME_OBJECT, SCHEME_OBJECT *, int);
+static SCHEME_OBJECT * extend_environment
+ (SCHEME_OBJECT, SCHEME_OBJECT, SCHEME_OBJECT);
static long guarantee_extension_space
(SCHEME_OBJECT);
static long allocate_frame_extension
&& ((get_trap_kind (*shadowed_cell)) == TRAP_COMPILER_CACHED))
? (GET_TRAP_CACHE (*shadowed_cell))
: SHARP_F);
- unsigned long length = (GET_EXTENDED_FRAME_LENGTH (environment));
- SCHEME_OBJECT pair;
/* Make sure there is enough space available to move any
references that need moving. */
: 0));
/* Create the binding. */
- pair = (cons (symbol, (MAP_TO_UNASSIGNED (value))));
- ((GET_EXTENDED_FRAME_BINDINGS (environment)) [length]) = pair;
- SET_EXTENDED_FRAME_LENGTH (environment, (length + 1));
+ SCHEME_OBJECT * cell = (extend_environment (environment, symbol, value));
/* Move any references that need moving. */
return
((old_cache != SHARP_F)
- ? (update_cache_references
- (old_cache, (PAIR_CDR_LOC (pair)), environment, symbol))
+ ? (update_cache_references (old_cache, cell, environment, symbol))
: PRIM_DONE);
}
}
+
+static SCHEME_OBJECT *
+extend_environment (SCHEME_OBJECT environment, SCHEME_OBJECT symbol,
+ SCHEME_OBJECT value)
+{
+ SCHEME_OBJECT pair = (cons (symbol, (MAP_TO_UNASSIGNED (value))));
+ unsigned long length = (GET_EXTENDED_FRAME_LENGTH (environment));
+ ((GET_EXTENDED_FRAME_BINDINGS (environment)) [length]) = pair;
+ SET_EXTENDED_FRAME_LENGTH (environment, (length + 1));
+ return (PAIR_CDR_LOC (pair));
+}
\f
static long
guarantee_extension_space (SCHEME_OBJECT environment)
{
SCHEME_OBJECT frame = 0;
SCHEME_OBJECT * cell = (find_binding_cell (environment, symbol, (&frame)));
- SCHEME_OBJECT dummy_cell = UNBOUND_OBJECT;
if (cell == 0)
- /* There's no binding for the variable, and we don't have access
- to the global environment. The compiled code needs a cache, so
- we'll install one, but it won't be attached to any environment
- structure. */
- cell = (&dummy_cell);
+ {
+ /* There's no binding for the variable, and we don't have access
+ to the global environment. The compiled code needs a cache, so
+ we'll install one that's attached to the outermost frame. */
+ DIE_IF_ERROR (guarantee_extension_space (frame));
+ cell = (extend_environment (frame, symbol, UNBOUND_OBJECT));
+ }
else if (GLOBAL_FRAME_P (frame))
strengthen_symbol (symbol);
/* This procedure must complete to keep the data structures
find_binding_cell (SCHEME_OBJECT environment, SCHEME_OBJECT symbol,
SCHEME_OBJECT * frame_ret)
{
+ assert (ENVIRONMENT_P (environment));
SCHEME_OBJECT frame = environment;
while (1)
{
SCHEME_OBJECT * cell = (scan_frame (frame, symbol, 0));
- if ((cell != 0) || (!PROCEDURE_FRAME_P (frame)))
+ if ((cell != 0)
+ /* This is safe because if 'frame' was the global frame then
+ 'cell' would be non-null. Therefore 'frame' must be a
+ procedure frame. */
+ || (!ENVIRONMENT_P (GET_FRAME_PARENT (frame))))
{
if (frame_ret != 0)
(*frame_ret) = frame;
(scan_procedure_bindings ((GET_FRAME_PROCEDURE (frame)),
frame, symbol, find_unbound_p));
}
- else if (GLOBAL_FRAME_P (frame))
- return (SYMBOL_GLOBAL_VALUE_CELL (symbol));
- else
- return (0);
+ assert (GLOBAL_FRAME_P (frame));
+ return (SYMBOL_GLOBAL_VALUE_CELL (symbol));
}
static SCHEME_OBJECT *