*** empty log message ***
[bpt/guile.git] / src / frames.c
CommitLineData
ac99cb0c
KN
1/* Copyright (C) 2001 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42#include <string.h>
43#include "frames.h"
44
45\f
46scm_bits_t scm_tc16_heap_frame;
47
48SCM
49scm_c_make_heap_frame (SCM *fp)
50{
51 struct scm_heap_frame *p =
52 scm_must_malloc (sizeof (struct scm_heap_frame), "make_heap_frame");
53 p->fp = fp;
54 p->program = SCM_UNDEFINED;
55 p->variables = SCM_UNDEFINED;
56 p->dynamic_link = SCM_UNDEFINED;
57 p->external_link = SCM_UNDEFINED;
58 SCM_RETURN_NEWSMOB (scm_tc16_heap_frame, p);
59}
60
61static SCM
62heap_frame_mark (SCM obj)
63{
64 struct scm_heap_frame *p = SCM_HEAP_FRAME_DATA (obj);
65 scm_gc_mark (p->program);
66 scm_gc_mark (p->variables);
67 scm_gc_mark (p->dynamic_link);
68 return p->external_link;
69}
70
71/* Scheme interface */
72
73SCM_DEFINE (scm_frame_p, "frame?", 1, 0, 0,
74 (SCM obj),
75 "")
76#define FUNC_NAME s_scm_frame_p
77{
78 return SCM_BOOL (SCM_HEAP_FRAME_P (obj));
79}
80#undef FUNC_NAME
81
82SCM_DEFINE (scm_frame_program, "frame-program", 1, 0, 0,
83 (SCM frame),
84 "")
85#define FUNC_NAME s_scm_frame_program
86{
87 SCM_VALIDATE_HEAP_FRAME (1, frame);
88 return SCM_STACK_FRAME_PROGRAM (SCM_HEAP_FRAME_DATA (frame)->fp);
89}
90#undef FUNC_NAME
91
92SCM_DEFINE (scm_frame_local_variables, "frame-local-variables", 1, 0, 0,
93 (SCM frame),
94 "")
95#define FUNC_NAME s_scm_frame_local_variables
96{
97 struct scm_heap_frame *p;
98
99 SCM_VALIDATE_HEAP_FRAME (1, frame);
100 p = SCM_HEAP_FRAME_DATA (frame);
101
102 if (SCM_UNBNDP (p->variables))
103 {
104 SCM prog = scm_frame_program (frame);
105 struct scm_program *pp = SCM_PROGRAM_DATA (prog);
106 int i, size = pp->nargs + pp->nlocs;
107 p->variables = scm_make_vector (SCM_MAKINUM (size), SCM_BOOL_F);
108 for (i = 0; i < size; i++)
109 SCM_VELTS (p->variables)[i] = SCM_STACK_FRAME_VARIABLE (p->fp, i);
110 }
111 return p->variables;
112}
113#undef FUNC_NAME
114
115SCM_DEFINE (scm_frame_return_address, "frame-return-address", 1, 0, 0,
116 (SCM frame),
117 "")
118#define FUNC_NAME s_scm_frame_return_address
119{
120 SCM_VALIDATE_HEAP_FRAME (1, frame);
121
122 return scm_long2num ((long) SCM_VM_BYTE_ADDRESS
123 (SCM_STACK_FRAME_RETURN_ADDRESS
124 (SCM_HEAP_FRAME_DATA (frame)->fp)));
125}
126#undef FUNC_NAME
127
128SCM_DEFINE (scm_frame_dynamic_link, "frame-dynamic-link", 1, 0, 0,
129 (SCM frame),
130 "")
131#define FUNC_NAME s_scm_frame_dynamic_link
132{
133 struct scm_heap_frame *p;
134
135 SCM_VALIDATE_HEAP_FRAME (1, frame);
136 p = SCM_HEAP_FRAME_DATA (frame);
137
138 if (SCM_UNBNDP (p->dynamic_link))
139 {
140 SCM *fp = SCM_VM_STACK_ADDRESS (SCM_STACK_FRAME_DYNAMIC_LINK (p->fp));
141 if (fp)
142 p->dynamic_link = scm_c_make_heap_frame (fp);
143 else
144 p->dynamic_link = SCM_BOOL_F;
145 }
146
147 return p->dynamic_link;
148}
149#undef FUNC_NAME
150
151SCM_DEFINE (scm_frame_external_link, "frame-external-link", 1, 0, 0,
152 (SCM frame),
153 "")
154#define FUNC_NAME s_scm_frame_external_link
155{
156 struct scm_heap_frame *p;
157
158 SCM_VALIDATE_HEAP_FRAME (1, frame);
159 p = SCM_HEAP_FRAME_DATA (frame);
160
161 if (SCM_UNBNDP (p->external_link))
162 p->external_link = SCM_STACK_FRAME_EXTERNAL_LINK (p->fp);
163
164 return p->external_link;
165}
166#undef FUNC_NAME
167
168\f
169void
170scm_init_frames (void)
171{
172 scm_tc16_heap_frame = scm_make_smob_type ("heap_frame", 0);
173 scm_set_smob_mark (scm_tc16_heap_frame, heap_frame_mark);
174
175#ifndef SCM_MAGIC_SNARFER
176#include "frames.x"
177#endif
178}
179
180/*
181 Local Variables:
182 c-file-style: "gnu"
183 End:
184*/