mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Replace dynamic link on stack with previous frame size
* libguile/frames.h (SCM_FRAME_DYNAMIC_LINK) (SCM_FRAME_SET_DYNAMIC_LINK): Instead of storing the absolute value of the previous FP, store its offset from the current FP. This allows us to avoid relinking when composing continuations or when relocating the stack. * libguile/frames.c (scm_frame_dynamic_link, scm_c_frame_previous): No need to relocate the dynamic link. * libguile/vm.c (vm_return_to_continuation_inner): (vm_reinstate_partial_continuation_inner, vm_expand_stack_inner): Don't relocate the frame pointer chain. (scm_i_vm_mark_stack): Terminate when FP is above stack_top, not when 0. (make_vm): Init FP to stack_top.
This commit is contained in:
parent
8f027385db
commit
72353de77d
3 changed files with 12 additions and 55 deletions
|
@ -309,8 +309,6 @@ SCM_DEFINE (scm_frame_return_address, "frame-return-address", 1, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
#define RELOC(kind, frame, val) ((val) + frame_offset (kind, frame))
|
||||
|
||||
SCM_DEFINE (scm_frame_dynamic_link, "frame-dynamic-link", 1, 0, 0,
|
||||
(SCM frame),
|
||||
"")
|
||||
|
@ -320,8 +318,7 @@ SCM_DEFINE (scm_frame_dynamic_link, "frame-dynamic-link", 1, 0, 0,
|
|||
/* fixme: munge fp if holder is a continuation */
|
||||
return scm_from_uintptr_t
|
||||
((scm_t_uintptr)
|
||||
RELOC (SCM_VM_FRAME_KIND (frame), SCM_VM_FRAME_DATA (frame),
|
||||
SCM_FRAME_DYNAMIC_LINK (SCM_VM_FRAME_FP (frame))));
|
||||
SCM_FRAME_DYNAMIC_LINK (SCM_VM_FRAME_FP (frame)));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
@ -339,12 +336,7 @@ scm_c_frame_previous (enum scm_vm_frame_kind kind, struct scm_frame *frame)
|
|||
|
||||
new_fp = SCM_FRAME_DYNAMIC_LINK (this_fp);
|
||||
|
||||
if (!new_fp)
|
||||
return 0;
|
||||
|
||||
new_fp = RELOC (kind, frame, new_fp);
|
||||
|
||||
if (new_fp > stack_top)
|
||||
if (new_fp >= stack_top)
|
||||
return 0;
|
||||
|
||||
new_sp = SCM_FRAME_PREVIOUS_SP (this_fp);
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
/* Each element on the stack occupies the same amount of space. */
|
||||
union scm_vm_stack_element
|
||||
{
|
||||
union scm_vm_stack_element *as_fp;
|
||||
scm_t_uintptr as_uint;
|
||||
scm_t_uint32 *as_ip;
|
||||
SCM as_scm;
|
||||
|
||||
|
@ -100,8 +100,8 @@ union scm_vm_stack_element
|
|||
#define SCM_FRAME_PREVIOUS_SP(fp) ((fp) + 2)
|
||||
#define SCM_FRAME_RETURN_ADDRESS(fp) ((fp)[0].as_ip)
|
||||
#define SCM_FRAME_SET_RETURN_ADDRESS(fp, ra) ((fp)[0].as_ip = (ra))
|
||||
#define SCM_FRAME_DYNAMIC_LINK(fp) ((fp)[1].as_fp)
|
||||
#define SCM_FRAME_SET_DYNAMIC_LINK(fp, dl) ((fp)[1].as_fp = (dl))
|
||||
#define SCM_FRAME_DYNAMIC_LINK(fp) ((fp) + (fp)[1].as_uint)
|
||||
#define SCM_FRAME_SET_DYNAMIC_LINK(fp, dl) ((fp)[1].as_uint = ((dl) - (fp)))
|
||||
#define SCM_FRAME_SLOT(fp,i) ((fp) - (i) - 1)
|
||||
#define SCM_FRAME_LOCAL(fp,i) (SCM_FRAME_SLOT (fp, i)->as_scm)
|
||||
#define SCM_FRAME_NUM_LOCALS(fp, sp) ((fp) - (sp))
|
||||
|
|
|
@ -179,21 +179,6 @@ vm_return_to_continuation_inner (void *data_ptr)
|
|||
cp->stack_size * sizeof (*cp->stack_bottom));
|
||||
vm_restore_sp (vp, vp->stack_top - cp->stack_size);
|
||||
|
||||
if (reloc)
|
||||
{
|
||||
union scm_vm_stack_element *fp = vp->fp;
|
||||
while (fp)
|
||||
{
|
||||
union scm_vm_stack_element *next_fp = SCM_FRAME_DYNAMIC_LINK (fp);
|
||||
if (next_fp)
|
||||
{
|
||||
next_fp += reloc;
|
||||
SCM_FRAME_SET_DYNAMIC_LINK (fp, next_fp);
|
||||
}
|
||||
fp = next_fp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -385,13 +370,6 @@ vm_reinstate_partial_continuation_inner (void *data_ptr)
|
|||
vp->fp = cp->fp + reloc;
|
||||
vp->ip = cp->ra;
|
||||
|
||||
/* now relocate frame pointers */
|
||||
{
|
||||
union scm_vm_stack_element *fp;
|
||||
for (fp = vp->fp; fp < base_fp; fp = SCM_FRAME_DYNAMIC_LINK (fp))
|
||||
SCM_FRAME_SET_DYNAMIC_LINK (fp, SCM_FRAME_DYNAMIC_LINK (fp) + reloc);
|
||||
}
|
||||
|
||||
data->reloc = reloc;
|
||||
|
||||
return NULL;
|
||||
|
@ -876,7 +854,7 @@ make_vm (void)
|
|||
vp->ip = NULL;
|
||||
vp->sp = vp->stack_top;
|
||||
vp->sp_min_since_gc = vp->sp;
|
||||
vp->fp = NULL;
|
||||
vp->fp = vp->stack_top;
|
||||
vp->engine = vm_default_engine;
|
||||
vp->trace_level = 0;
|
||||
for (i = 0; i < SCM_VM_NUM_HOOKS; i++)
|
||||
|
@ -967,7 +945,9 @@ scm_i_vm_mark_stack (struct scm_vm *vp, struct GC_ms_entry *mark_stack_ptr,
|
|||
|
||||
memset (&cache, 0, sizeof (cache));
|
||||
|
||||
for (fp = vp->fp, sp = vp->sp; fp; fp = SCM_FRAME_DYNAMIC_LINK (fp))
|
||||
for (fp = vp->fp, sp = vp->sp;
|
||||
fp < vp->stack_top;
|
||||
fp = SCM_FRAME_DYNAMIC_LINK (fp))
|
||||
{
|
||||
scm_t_ptrdiff nlocals = SCM_FRAME_NUM_LOCALS (fp, sp);
|
||||
size_t slot = nlocals - 1;
|
||||
|
@ -1047,24 +1027,9 @@ vm_expand_stack_inner (void *data_ptr)
|
|||
vp->stack_limit = vp->stack_bottom;
|
||||
reloc = vp->stack_top - old_top;
|
||||
|
||||
if (reloc)
|
||||
{
|
||||
union scm_vm_stack_element *fp;
|
||||
if (vp->fp)
|
||||
vp->fp += reloc;
|
||||
data->new_sp += reloc;
|
||||
fp = vp->fp;
|
||||
while (fp)
|
||||
{
|
||||
union scm_vm_stack_element *next_fp = SCM_FRAME_DYNAMIC_LINK (fp);
|
||||
if (next_fp)
|
||||
{
|
||||
next_fp += reloc;
|
||||
SCM_FRAME_SET_DYNAMIC_LINK (fp, next_fp);
|
||||
}
|
||||
fp = next_fp;
|
||||
}
|
||||
}
|
||||
|
||||
return new_bottom;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue