Merge branch 'master' of git://git.savannah.gnu.org/guile
[bpt/guile.git] / libguile / frames.h
1 /* Copyright (C) 2001 Free Software Foundation, Inc.
2 * *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #ifndef _SCM_FRAMES_H_
19 #define _SCM_FRAMES_H_
20
21 #include <libguile.h>
22 #include "programs.h"
23
24 \f
25 /*
26 * VM frames
27 */
28
29 /* VM Frame Layout
30 ---------------
31
32 | | <- fp + bp->nargs + bp->nlocs + 4
33 +------------------+ = SCM_FRAME_UPPER_ADDRESS (fp)
34 | Return address |
35 | MV return address|
36 | Dynamic link |
37 | External link | <- fp + bp->nargs + bp->nlocs
38 | Local variable 1 | = SCM_FRAME_DATA_ADDRESS (fp)
39 | Local variable 0 | <- fp + bp->nargs
40 | Argument 1 |
41 | Argument 0 | <- fp
42 | Program | <- fp - 1
43 +------------------+ = SCM_FRAME_LOWER_ADDRESS (fp)
44 | |
45
46 As can be inferred from this drawing, it is assumed that
47 `sizeof (SCM *) == sizeof (SCM)', since pointers (the `link' parts) are
48 assumed to be as long as SCM objects. */
49
50 #define SCM_FRAME_DATA_ADDRESS(fp) \
51 (fp + SCM_PROGRAM_DATA (SCM_FRAME_PROGRAM (fp))->nargs \
52 + SCM_PROGRAM_DATA (SCM_FRAME_PROGRAM (fp))->nlocs)
53 #define SCM_FRAME_UPPER_ADDRESS(fp) (SCM_FRAME_DATA_ADDRESS (fp) + 4)
54 #define SCM_FRAME_LOWER_ADDRESS(fp) (fp - 1)
55
56 #define SCM_FRAME_BYTE_CAST(x) ((scm_byte_t *) SCM_UNPACK (x))
57 #define SCM_FRAME_STACK_CAST(x) ((SCM *) SCM_UNPACK (x))
58
59 #define SCM_FRAME_RETURN_ADDRESS(fp) \
60 (SCM_FRAME_BYTE_CAST (SCM_FRAME_DATA_ADDRESS (fp)[3]))
61 #define SCM_FRAME_MV_RETURN_ADDRESS(fp) \
62 (SCM_FRAME_BYTE_CAST (SCM_FRAME_DATA_ADDRESS (fp)[2]))
63 #define SCM_FRAME_DYNAMIC_LINK(fp) \
64 (SCM_FRAME_STACK_CAST (SCM_FRAME_DATA_ADDRESS (fp)[1]))
65 #define SCM_FRAME_SET_DYNAMIC_LINK(fp, dl) \
66 ((SCM_FRAME_DATA_ADDRESS (fp)[1])) = (SCM)(dl);
67 #define SCM_FRAME_EXTERNAL_LINK(fp) (SCM_FRAME_DATA_ADDRESS (fp)[0])
68 #define SCM_FRAME_VARIABLE(fp,i) fp[i]
69 #define SCM_FRAME_PROGRAM(fp) fp[-1]
70
71 \f
72 /*
73 * Heap frames
74 */
75
76 SCM_API scm_t_bits scm_tc16_vm_frame;
77
78 struct scm_vm_frame
79 {
80 SCM stack_holder;
81 SCM *fp;
82 SCM *sp;
83 scm_byte_t *ip;
84 scm_t_ptrdiff offset;
85 };
86
87 #define SCM_VM_FRAME_P(x) SCM_SMOB_PREDICATE (scm_tc16_vm_frame, x)
88 #define SCM_VM_FRAME_DATA(x) ((struct scm_vm_frame*)SCM_SMOB_DATA (x))
89 #define SCM_VM_FRAME_STACK_HOLDER(f) SCM_VM_FRAME_DATA(f)->stack_holder
90 #define SCM_VM_FRAME_FP(f) SCM_VM_FRAME_DATA(f)->fp
91 #define SCM_VM_FRAME_SP(f) SCM_VM_FRAME_DATA(f)->sp
92 #define SCM_VM_FRAME_IP(f) SCM_VM_FRAME_DATA(f)->ip
93 #define SCM_VM_FRAME_OFFSET(f) SCM_VM_FRAME_DATA(f)->offset
94 #define SCM_VALIDATE_VM_FRAME(p,x) SCM_MAKE_VALIDATE (p, x, VM_FRAME_P)
95
96 /* FIXME rename scm_byte_t */
97 SCM_API SCM scm_c_make_vm_frame (SCM stack_holder, SCM *fp, SCM *sp,
98 scm_byte_t *ip, scm_t_ptrdiff offset);
99 SCM_API SCM scm_vm_frame_p (SCM obj);
100 SCM_API SCM scm_vm_frame_program (SCM frame);
101 SCM_API SCM scm_vm_frame_arguments (SCM frame);
102 SCM_API SCM scm_vm_frame_source (SCM frame);
103 SCM_API SCM scm_vm_frame_local_ref (SCM frame, SCM index);
104 SCM_API SCM scm_vm_frame_local_set_x (SCM frame, SCM index, SCM val);
105 SCM_API SCM scm_vm_frame_return_address (SCM frame);
106 SCM_API SCM scm_vm_frame_mv_return_address (SCM frame);
107 SCM_API SCM scm_vm_frame_dynamic_link (SCM frame);
108 SCM_API SCM scm_vm_frame_external_link (SCM frame);
109 SCM_API SCM scm_vm_frame_stack (SCM frame);
110
111 SCM_API SCM scm_c_vm_frame_prev (SCM frame);
112
113 SCM_INTERNAL void scm_bootstrap_frames (void);
114 SCM_INTERNAL void scm_init_frames (void);
115
116 #endif /* _SCM_FRAMES_H_ */
117
118 /*
119 Local Variables:
120 c-file-style: "gnu"
121 End:
122 */