mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Optimize make-stack
* libguile/continuations.h: * libguile/continuations.c (scm_i_continuation_to_frame): Operate on low-level C structures instead of heap objects. * libguile/frames.h: * libguile/frames.c (frame_offset, frame_stack_base): Const args. (scm_c_frame_closure): New helper. (scm_frame_procedure): Use the new helper. * libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack): Rework to avoid allocating frames as we traverse the stack, and to avoid an n**2 case where there are outer cuts.
This commit is contained in:
parent
8de051da47
commit
3b14dd2f27
5 changed files with 103 additions and 80 deletions
|
@ -58,7 +58,7 @@ scm_i_frame_print (SCM frame, SCM port, scm_print_state *pstate)
|
|||
}
|
||||
|
||||
static SCM*
|
||||
frame_stack_base (enum scm_vm_frame_kind kind, struct scm_frame *frame)
|
||||
frame_stack_base (enum scm_vm_frame_kind kind, const struct scm_frame *frame)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ frame_stack_base (enum scm_vm_frame_kind kind, struct scm_frame *frame)
|
|||
}
|
||||
|
||||
static scm_t_ptrdiff
|
||||
frame_offset (enum scm_vm_frame_kind kind, struct scm_frame *frame)
|
||||
frame_offset (enum scm_vm_frame_kind kind, const struct scm_frame *frame)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
|
@ -124,13 +124,27 @@ SCM_DEFINE (scm_frame_p, "frame?", 1, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
/* Retrieve the local in slot 0, which may or may not actually be a
|
||||
procedure, and may or may not actually be the procedure being
|
||||
applied. If you want the procedure, look it up from the IP. */
|
||||
SCM
|
||||
scm_c_frame_closure (enum scm_vm_frame_kind kind, const struct scm_frame *frame)
|
||||
{
|
||||
SCM *fp = frame_stack_base (kind, frame) + frame->fp_offset;
|
||||
|
||||
return SCM_FRAME_PROGRAM (fp);
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_frame_procedure, "frame-procedure", 1, 0, 0,
|
||||
(SCM frame),
|
||||
"")
|
||||
#define FUNC_NAME s_scm_frame_procedure
|
||||
{
|
||||
SCM_VALIDATE_VM_FRAME (1, frame);
|
||||
return SCM_FRAME_PROGRAM (SCM_VM_FRAME_FP (frame));
|
||||
|
||||
/* FIXME: Retrieve procedure from address? */
|
||||
return scm_c_frame_closure (SCM_VM_FRAME_KIND (frame),
|
||||
SCM_VM_FRAME_DATA (frame));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue