1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-07 12:40:19 +02:00

Inline "struct scm_frame" into tagged frame objects

This avoids an indirection and will make the tracer's job easier.

* libguile/frames.h (struct scm_vm_frame): New data type.
(scm_is_vm_frame):
(scm_vm_frame):
(scm_vm_frame_kind):
(scm_vm_frame_fp):
(scm_vm_frame_sp):
(scm_vm_frame_ip):
(scm_frame_init_from_vm_frame): New helpers.

* libguile/frames.c:
* libguile/stacks.c:
* libguile/stacks.h:
* libguile/vm.c: Update all users of SCM_VM_FRAME_* macros to use new
helpers.
This commit is contained in:
Andy Wingo 2025-05-29 21:53:36 +02:00
parent 75842cf215
commit aa73d31ded
5 changed files with 101 additions and 57 deletions

View file

@ -1,4 +1,4 @@
/* Copyright 2001,2009-2015,2018
/* Copyright 2001,2009-2015,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
@ -20,6 +20,8 @@
#ifndef _SCM_FRAMES_H_
#define _SCM_FRAMES_H_
#include <string.h>
#include <libguile/gc.h>
#include "programs.h"
@ -127,24 +129,61 @@ struct scm_frame
uint32_t *ip;
};
enum scm_vm_frame_kind
{
SCM_VM_FRAME_KIND_VM,
SCM_VM_FRAME_KIND_CONT
};
struct scm_vm_frame
{
scm_t_bits tag_and_flags;
struct scm_frame frame;
};
#define SCM_VM_FRAME_P(x) (SCM_HAS_TYP7 (x, scm_tc7_frame))
#define SCM_VM_FRAME_KIND(x) ((enum scm_vm_frame_kind) (SCM_CELL_WORD_0 (x) >> 8))
#define SCM_VM_FRAME_DATA(x) ((struct scm_frame *)SCM_CELL_WORD_1 (x))
#define SCM_VM_FRAME_STACK_HOLDER(f) SCM_VM_FRAME_DATA (f)->stack_holder
#define SCM_VM_FRAME_FP_OFFSET(f) SCM_VM_FRAME_DATA (f)->fp_offset
#define SCM_VM_FRAME_SP_OFFSET(f) SCM_VM_FRAME_DATA (f)->sp_offset
#define SCM_VM_FRAME_FP(f) (scm_i_frame_stack_top (f) - SCM_VM_FRAME_FP_OFFSET (f))
#define SCM_VM_FRAME_SP(f) (scm_i_frame_stack_top (f) - SCM_VM_FRAME_SP_OFFSET (f))
#define SCM_VM_FRAME_IP(f) SCM_VM_FRAME_DATA (f)->ip
enum scm_vm_frame_kind
{
SCM_VM_FRAME_KIND_VM,
SCM_VM_FRAME_KIND_CONT
};
static inline int
scm_is_vm_frame (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_frame);
}
#define SCM_VM_FRAME_P(x) (scm_is_vm_frame (x))
#define SCM_VALIDATE_VM_FRAME(p,x) SCM_MAKE_VALIDATE (p, x, VM_FRAME_P)
SCM_INTERNAL union scm_vm_stack_element* scm_i_frame_stack_top (SCM frame);
static inline struct scm_vm_frame*
scm_vm_frame (SCM x)
{
if (!scm_is_vm_frame (x))
abort ();
return (struct scm_vm_frame *) SCM_UNPACK_POINTER (x);
}
static inline enum scm_vm_frame_kind
scm_vm_frame_kind (struct scm_vm_frame *frame)
{
return (enum scm_vm_frame_kind) (frame->tag_and_flags >> 8);
}
SCM_INTERNAL union scm_vm_stack_element*
scm_vm_frame_stack_top (struct scm_vm_frame *frame);
static inline union scm_vm_stack_element*
scm_vm_frame_fp (struct scm_vm_frame *frame)
{
return scm_vm_frame_stack_top (frame) - frame->frame.fp_offset;
}
static inline union scm_vm_stack_element*
scm_vm_frame_sp (struct scm_vm_frame *frame)
{
return scm_vm_frame_stack_top (frame) - frame->frame.sp_offset;
}
static inline uint32_t*
scm_vm_frame_ip (struct scm_vm_frame *frame)
{
return frame->frame.ip;
}
/* See notes in frames.c before using this. */
SCM_INTERNAL SCM scm_c_frame_closure (enum scm_vm_frame_kind kind,
@ -156,6 +195,13 @@ SCM_INTERNAL SCM scm_c_make_frame (enum scm_vm_frame_kind kind,
SCM_INTERNAL int scm_c_frame_previous (enum scm_vm_frame_kind kind,
struct scm_frame *frame);
static inline void
scm_frame_init_from_vm_frame (struct scm_frame *frame,
const struct scm_vm_frame *vm_frame)
{
memcpy (frame, &vm_frame->frame, sizeof (*frame));
}
#endif
SCM_API SCM scm_frame_p (SCM obj);