/* Copyright 2001,2009-2015,2018,2025 Free Software Foundation, Inc. This file is part of Guile. Guile is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Guile is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Guile. If not, see . */ #ifndef _SCM_FRAMES_INTERNAL_H_ #define _SCM_FRAMES_INTERNAL_H_ #include struct scm_frame { void *stack_holder; ptrdiff_t fp_offset; ptrdiff_t sp_offset; uint32_t *ip; }; struct scm_vm_frame { scm_t_bits tag_and_flags; struct scm_frame frame; }; 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) 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, const struct scm_frame *frame); SCM_INTERNAL SCM scm_c_make_frame (enum scm_vm_frame_kind kind, const struct scm_frame *frame); 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)); } SCM_INTERNAL void scm_i_frame_print (SCM frame, SCM port, scm_print_state *pstate); SCM_INTERNAL void scm_init_frames (void); #endif /* _SCM_FRAMES_INTERNAL_H_ */