Commit | Line | Data |
---|---|---|
63c51b9a | 1 | /* Debugging extensions for Guile |
78a0461a | 2 | * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation |
ee340120 MD |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2, or (at your option) | |
7 | * any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this software; see the file COPYING. If not, write to | |
82892bed JB |
16 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
17 | * Boston, MA 02111-1307 USA | |
ee340120 MD |
18 | * |
19 | * As a special exception, the Free Software Foundation gives permission | |
20 | * for additional uses of the text contained in its release of GUILE. | |
21 | * | |
22 | * The exception is that, if you link the GUILE library with other files | |
23 | * to produce an executable, this does not by itself cause the | |
24 | * resulting executable to be covered by the GNU General Public License. | |
25 | * Your use of that executable is in no way restricted on account of | |
26 | * linking the GUILE library code into it. | |
27 | * | |
28 | * This exception does not however invalidate any other reasons why | |
29 | * the executable file might be covered by the GNU General Public License. | |
30 | * | |
31 | * This exception applies only to the code released by the | |
32 | * Free Software Foundation under the name GUILE. If you copy | |
33 | * code from other Free Software Foundation releases into a copy of | |
34 | * GUILE, as the General Public License permits, the exception does | |
35 | * not apply to the code that you add in this way. To avoid misleading | |
36 | * anyone as to the status of such modified files, you must delete | |
37 | * this exception notice from them. | |
38 | * | |
39 | * If you write modifications of your own for GUILE, it is your choice | |
40 | * whether to permit this exception to apply to your modifications. | |
41 | * If you do not wish that, delete this exception notice. | |
42 | * | |
43 | * The author can be reached at djurfeldt@nada.kth.se | |
82892bed | 44 | * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */ |
f0e9217a | 45 | |
1bbd0b84 GB |
46 | /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999, |
47 | gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */ | |
48 | ||
49 | ||
f0e9217a MD |
50 | #include <stdio.h> |
51 | #include "_scm.h" | |
20e6290e | 52 | #include "eval.h" |
a6e350dd | 53 | #include "stackchk.h" |
20e6290e JB |
54 | #include "throw.h" |
55 | #include "genio.h" | |
41d3b325 | 56 | #include "macros.h" |
20e6290e JB |
57 | #include "smob.h" |
58 | #include "procprop.h" | |
59 | #include "srcprop.h" | |
60 | #include "alist.h" | |
61 | #include "continuations.h" | |
62 | #include "strports.h" | |
63 | #include "read.h" | |
64 | #include "feature.h" | |
260b1416 | 65 | #include "dynwind.h" |
650de6d7 | 66 | #include "modules.h" |
f0e9217a | 67 | |
1bbd0b84 | 68 | #include "scm_validate.h" |
20e6290e | 69 | #include "debug.h" |
f0e9217a MD |
70 | \f |
71 | ||
72 | /* {Run time control of the debugging evaluator} | |
73 | */ | |
74 | ||
a1ec6916 | 75 | SCM_DEFINE (scm_debug_options, "debug-options-interface", 0, 1, 0, |
1bbd0b84 GB |
76 | (SCM setting), |
77 | "") | |
78 | #define FUNC_NAME s_scm_debug_options | |
f0e9217a MD |
79 | { |
80 | SCM ans; | |
81 | SCM_DEFER_INTS; | |
5e8d7fd4 MD |
82 | ans = scm_options (setting, |
83 | scm_debug_opts, | |
84 | SCM_N_DEBUG_OPTIONS, | |
1bbd0b84 | 85 | FUNC_NAME); |
f0e9217a | 86 | #ifndef SCM_RECKLESS |
5e8d7fd4 | 87 | if (!(1 <= SCM_N_FRAMES && SCM_N_FRAMES <= SCM_MAX_FRAME_SIZE)) |
f0e9217a | 88 | { |
1bbd0b84 GB |
89 | scm_options (ans, scm_debug_opts, SCM_N_DEBUG_OPTIONS, FUNC_NAME); |
90 | scm_out_of_range (FUNC_NAME, setting); | |
f0e9217a MD |
91 | } |
92 | #endif | |
5e8d7fd4 | 93 | SCM_RESET_DEBUG_MODE; |
a6e350dd | 94 | scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P; |
5e8d7fd4 | 95 | scm_debug_eframe_size = 2 * SCM_N_FRAMES; |
bfc69694 | 96 | SCM_ALLOW_INTS; |
f0e9217a MD |
97 | return ans; |
98 | } | |
1bbd0b84 | 99 | #undef FUNC_NAME |
260b1416 MD |
100 | |
101 | static void | |
102 | with_traps_before (void *data) | |
103 | { | |
104 | int *trap_flag = data; | |
105 | *trap_flag = SCM_TRAPS_P; | |
106 | SCM_TRAPS_P = 1; | |
107 | } | |
108 | ||
109 | static void | |
110 | with_traps_after (void *data) | |
111 | { | |
112 | int *trap_flag = data; | |
113 | SCM_TRAPS_P = *trap_flag; | |
114 | } | |
115 | ||
116 | static SCM | |
117 | with_traps_inner (void *data) | |
118 | { | |
119 | SCM thunk = (SCM) data; | |
120 | return scm_apply (thunk, SCM_EOL, SCM_EOL); | |
121 | } | |
1cc91f1b | 122 | |
a1ec6916 | 123 | SCM_DEFINE (scm_with_traps, "with-traps", 1, 0, 0, |
1bbd0b84 GB |
124 | (SCM thunk), |
125 | "") | |
126 | #define FUNC_NAME s_scm_with_traps | |
f0e9217a | 127 | { |
260b1416 | 128 | int trap_flag; |
1bbd0b84 | 129 | SCM_VALIDATE_THUNK(1,thunk); |
260b1416 MD |
130 | return scm_internal_dynamic_wind (with_traps_before, |
131 | with_traps_inner, | |
132 | with_traps_after, | |
133 | (void *) thunk, | |
134 | &trap_flag); | |
f0e9217a | 135 | } |
1bbd0b84 | 136 | #undef FUNC_NAME |
f0e9217a MD |
137 | |
138 | \f | |
63c51b9a MD |
139 | static SCM scm_sym_source, scm_sym_dots; |
140 | static SCM scm_sym_procname; | |
f0e9217a MD |
141 | |
142 | /* {Memoized Source} | |
143 | */ | |
144 | ||
145 | long scm_tc16_memoized; | |
146 | ||
1cc91f1b | 147 | |
f0e9217a | 148 | static int |
1bbd0b84 | 149 | prinmemoized (SCM obj,SCM port,scm_print_state *pstate) |
f0e9217a | 150 | { |
9882ea19 | 151 | int writingp = SCM_WRITINGP (pstate); |
b7f3516f | 152 | scm_puts ("#<memoized ", port); |
9882ea19 | 153 | SCM_SET_WRITINGP (pstate, 1); |
33b97402 MD |
154 | #ifdef GUILE_DEBUG |
155 | scm_iprin1 (SCM_MEMOIZED_EXP (obj), port, pstate); | |
156 | #else | |
9882ea19 | 157 | scm_iprin1 (scm_unmemoize (obj), port, pstate); |
33b97402 | 158 | #endif |
9882ea19 | 159 | SCM_SET_WRITINGP (pstate, writingp); |
b7f3516f | 160 | scm_putc ('>', port); |
f0e9217a MD |
161 | return 1; |
162 | } | |
163 | ||
a1ec6916 | 164 | SCM_DEFINE (scm_memoized_p, "memoized?", 1, 0, 0, |
1bbd0b84 GB |
165 | (SCM obj), |
166 | "") | |
167 | #define FUNC_NAME s_scm_memoized_p | |
f0e9217a | 168 | { |
0c95b57d | 169 | return SCM_BOOL(SCM_MEMOIZEDP (obj)); |
f0e9217a | 170 | } |
1bbd0b84 | 171 | #undef FUNC_NAME |
f0e9217a | 172 | |
f0e9217a | 173 | SCM |
1bbd0b84 | 174 | scm_make_memoized (SCM exp, SCM env) |
f0e9217a | 175 | { |
6c179711 | 176 | /* *fixme* Check that env is a valid environment. */ |
f0e9217a | 177 | register SCM z, ans; |
f83e2737 | 178 | SCM_ENTER_A_SECTION; |
23a62151 MD |
179 | SCM_NEWSMOB (z, exp, env); |
180 | SCM_NEWSMOB (ans, scm_tc16_memoized, z); | |
f83e2737 | 181 | SCM_EXIT_A_SECTION; |
f0e9217a MD |
182 | return ans; |
183 | } | |
184 | ||
33b97402 MD |
185 | #ifdef GUILE_DEBUG |
186 | /* | |
187 | * Some primitives for construction of memoized code | |
188 | * | |
189 | * - procedure: memcons CAR CDR [ENV] | |
190 | * | |
191 | * Construct a pair, encapsulated in a memoized object. | |
192 | * | |
193 | * The CAR and CDR can be either normal or memoized. If ENV isn't | |
194 | * specified, the top-level environment of the current module will | |
195 | * be assumed. All environments must match. | |
196 | * | |
197 | * - procedure: make-gloc VARIABLE [ENV] | |
198 | * | |
199 | * Return a gloc, encapsulated in a memoized object. | |
200 | * | |
201 | * (Glocs can't exist in normal list structures, since they will | |
202 | * be mistaken for structs.) | |
203 | * | |
204 | * - procedure: gloc? OBJECT | |
205 | * | |
206 | * Return #t if OBJECT is a memoized gloc. | |
207 | * | |
208 | * - procedure: make-iloc FRAME BINDING CDRP | |
209 | * | |
210 | * Return an iloc referring to frame no. FRAME, binding | |
211 | * no. BINDING. If CDRP is non-#f, the iloc is referring to a | |
212 | * frame consisting of a single pair, with the value stored in the | |
213 | * CDR. | |
214 | * | |
215 | * - procedure: iloc? OBJECT | |
216 | * | |
217 | * Return #t if OBJECT is an iloc. | |
218 | * | |
219 | * - procedure: mem->proc MEMOIZED | |
220 | * | |
221 | * Construct a closure from the memoized lambda expression MEMOIZED | |
222 | * | |
223 | * WARNING! The code is not copied! | |
224 | * | |
225 | * - procedure: proc->mem CLOSURE | |
226 | * | |
227 | * Turn the closure CLOSURE into a memoized object. | |
228 | * | |
229 | * WARNING! The code is not copied! | |
230 | * | |
231 | * - constant: SCM_IM_AND | |
232 | * - constant: SCM_IM_BEGIN | |
233 | * - constant: SCM_IM_CASE | |
234 | * - constant: SCM_IM_COND | |
235 | * - constant: SCM_IM_DO | |
236 | * - constant: SCM_IM_IF | |
237 | * - constant: SCM_IM_LAMBDA | |
238 | * - constant: SCM_IM_LET | |
239 | * - constant: SCM_IM_LETSTAR | |
240 | * - constant: SCM_IM_LETREC | |
241 | * - constant: SCM_IM_OR | |
242 | * - constant: SCM_IM_QUOTE | |
243 | * - constant: SCM_IM_SET | |
244 | * - constant: SCM_IM_DEFINE | |
245 | * - constant: SCM_IM_APPLY | |
246 | * - constant: SCM_IM_CONT | |
bbab09f6 | 247 | * - constant: SCM_IM_DISPATCH |
33b97402 MD |
248 | */ |
249 | ||
250 | #include "variable.h" | |
251 | #include "procs.h" | |
252 | ||
a1ec6916 | 253 | SCM_DEFINE (scm_make_gloc, "make-gloc", 1, 1, 0, |
1bbd0b84 GB |
254 | (SCM var, SCM env), |
255 | "") | |
256 | #define FUNC_NAME s_scm_make_gloc | |
33b97402 MD |
257 | { |
258 | #if 1 /* Unsafe */ | |
0c95b57d | 259 | if (SCM_CONSP (var)) |
33b97402 MD |
260 | var = scm_cons (SCM_BOOL_F, var); |
261 | else | |
262 | #endif | |
1bbd0b84 | 263 | SCM_VALIDATE_VARIABLE(1,var); |
33b97402 MD |
264 | if (SCM_UNBNDP (env)) |
265 | env = scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var)); | |
266 | else | |
1bbd0b84 | 267 | SCM_VALIDATE_NULLORCONS(2,env); |
33b97402 MD |
268 | return scm_make_memoized (SCM_VARVCELL (var) + 1, env); |
269 | } | |
1bbd0b84 | 270 | #undef FUNC_NAME |
33b97402 | 271 | |
a1ec6916 | 272 | SCM_DEFINE (scm_gloc_p, "gloc?", 1, 0, 0, |
1bbd0b84 GB |
273 | (SCM obj), |
274 | "") | |
275 | #define FUNC_NAME s_scm_gloc_p | |
33b97402 | 276 | { |
cabe682c | 277 | return SCM_BOOL((SCM_MEMOIZEDP (obj) |
1bbd0b84 | 278 | && (SCM_MEMOIZED_EXP (obj) & 7) == 1)); |
33b97402 | 279 | } |
1bbd0b84 | 280 | #undef FUNC_NAME |
33b97402 | 281 | |
a1ec6916 | 282 | SCM_DEFINE (scm_make_iloc, "make-iloc", 3, 0, 0, |
1bbd0b84 GB |
283 | (SCM frame, SCM binding, SCM cdrp), |
284 | "") | |
285 | #define FUNC_NAME s_scm_make_iloc | |
33b97402 | 286 | { |
47c6b75e GB |
287 | SCM_VALIDATE_INUM(1,frame); |
288 | SCM_VALIDATE_INUM(2,binding); | |
33b97402 MD |
289 | return (SCM_ILOC00 |
290 | + SCM_IFRINC * SCM_INUM (frame) | |
291 | + (SCM_NFALSEP (cdrp) ? SCM_ICDR : 0) | |
292 | + SCM_IDINC * SCM_INUM (binding)); | |
293 | } | |
1bbd0b84 | 294 | #undef FUNC_NAME |
33b97402 | 295 | |
a1ec6916 | 296 | SCM_DEFINE (scm_iloc_p, "iloc?", 1, 0, 0, |
1bbd0b84 GB |
297 | (SCM obj), |
298 | "") | |
299 | #define FUNC_NAME s_scm_iGUILE_p | |
33b97402 | 300 | { |
1bbd0b84 | 301 | return SCM_BOOL(SCM_ILOCP (obj)); |
33b97402 | 302 | } |
1bbd0b84 | 303 | #undef FUNC_NAME |
33b97402 | 304 | |
a1ec6916 | 305 | SCM_DEFINE (scm_memcons, "memcons", 2, 1, 0, |
1bbd0b84 GB |
306 | (SCM car, SCM cdr, SCM env), |
307 | "") | |
308 | #define FUNC_NAME s_scm_memcons | |
33b97402 | 309 | { |
0c95b57d | 310 | if (SCM_MEMOIZEDP (car)) |
33b97402 MD |
311 | { |
312 | /*fixme* environments may be two different but equal top-level envs */ | |
313 | if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (car) != env) | |
e8e9b690 | 314 | SCM_MISC_ERROR ("environment mismatch arg1 <-> arg3", |
33b97402 MD |
315 | scm_cons2 (car, env, SCM_EOL)); |
316 | else | |
317 | env = SCM_MEMOIZED_ENV (car); | |
318 | car = SCM_MEMOIZED_EXP (car); | |
319 | } | |
0c95b57d | 320 | if (SCM_MEMOIZEDP (cdr)) |
33b97402 MD |
321 | { |
322 | if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (cdr) != env) | |
e8e9b690 | 323 | SCM_MISC_ERROR ("environment mismatch arg2 <-> arg3", |
33b97402 MD |
324 | scm_cons2 (cdr, env, SCM_EOL)); |
325 | else | |
326 | env = SCM_MEMOIZED_ENV (cdr); | |
327 | cdr = SCM_MEMOIZED_EXP (cdr); | |
328 | } | |
329 | if (SCM_UNBNDP (env)) | |
330 | env = scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var)); | |
331 | else | |
e8e9b690 | 332 | SCM_VALIDATE_NULLORCONS(3,env); |
33b97402 MD |
333 | return scm_make_memoized (scm_cons (car, cdr), env); |
334 | } | |
1bbd0b84 | 335 | #undef FUNC_NAME |
33b97402 | 336 | |
a1ec6916 | 337 | SCM_DEFINE (scm_mem_to_proc, "mem->proc", 1, 0, 0, |
1bbd0b84 GB |
338 | (SCM obj), |
339 | "") | |
340 | #define FUNC_NAME s_scm_mem_to_proc | |
33b97402 MD |
341 | { |
342 | SCM env; | |
1bbd0b84 | 343 | SCM_VALIDATE_MEMOIZED(1,obj); |
33b97402 MD |
344 | env = SCM_MEMOIZED_ENV (obj); |
345 | obj = SCM_MEMOIZED_EXP (obj); | |
346 | if (!(SCM_NIMP (obj) && SCM_CAR (obj) == SCM_IM_LAMBDA)) | |
e8e9b690 | 347 | SCM_MISC_ERROR ("expected lambda expression", |
33b97402 MD |
348 | scm_cons (obj, SCM_EOL)); |
349 | return scm_closure (SCM_CDR (obj), env); | |
350 | } | |
1bbd0b84 | 351 | #undef FUNC_NAME |
33b97402 | 352 | |
a1ec6916 | 353 | SCM_DEFINE (scm_proc_to_mem, "proc->mem", 1, 0, 0, |
1bbd0b84 GB |
354 | (SCM obj), |
355 | "") | |
356 | #define FUNC_NAME s_scm_proc_to_mem | |
33b97402 | 357 | { |
5623a9b4 | 358 | SCM_VALIDATE_CLOSURE (1, obj); |
33b97402 MD |
359 | return scm_make_memoized (scm_cons (SCM_IM_LAMBDA, SCM_CODE (obj)), |
360 | SCM_ENV (obj)); | |
361 | } | |
1bbd0b84 | 362 | #undef FUNC_NAME |
33b97402 MD |
363 | |
364 | #endif /* GUILE_DEBUG */ | |
365 | ||
a1ec6916 | 366 | SCM_DEFINE (scm_unmemoize, "unmemoize", 1, 0, 0, |
1bbd0b84 GB |
367 | (SCM m), |
368 | "") | |
369 | #define FUNC_NAME s_scm_unmemoize | |
f0e9217a | 370 | { |
1bbd0b84 | 371 | SCM_VALIDATE_MEMOIZED(1,m); |
bfe3154c | 372 | return scm_unmemocopy (SCM_MEMOIZED_EXP (m), SCM_MEMOIZED_ENV (m)); |
f0e9217a | 373 | } |
1bbd0b84 | 374 | #undef FUNC_NAME |
f0e9217a | 375 | |
a1ec6916 | 376 | SCM_DEFINE (scm_memoized_environment, "memoized-environment", 1, 0, 0, |
1bbd0b84 GB |
377 | (SCM m), |
378 | "") | |
379 | #define FUNC_NAME s_scm_memoized_environment | |
f0e9217a | 380 | { |
1bbd0b84 | 381 | SCM_VALIDATE_MEMOIZED(1,m); |
bfe3154c | 382 | return SCM_MEMOIZED_ENV (m); |
f0e9217a | 383 | } |
1bbd0b84 | 384 | #undef FUNC_NAME |
f0e9217a | 385 | |
a1ec6916 | 386 | SCM_DEFINE (scm_procedure_name, "procedure-name", 1, 0, 0, |
1bbd0b84 GB |
387 | (SCM proc), |
388 | "") | |
389 | #define FUNC_NAME s_scm_procedure_name | |
f0e9217a | 390 | { |
1bbd0b84 | 391 | SCM_VALIDATE_PROC(1,proc); |
f0e9217a | 392 | switch (SCM_TYP7 (proc)) { |
a726dd9d MD |
393 | case scm_tcs_subrs: |
394 | return SCM_SNAME (proc); | |
395 | default: | |
f0e9217a | 396 | { |
63c51b9a | 397 | SCM name = scm_procedure_property (proc, scm_sym_name); |
f0e9217a | 398 | #if 0 |
63c51b9a MD |
399 | /* Source property scm_sym_procname not implemented yet... */ |
400 | SCM name = scm_source_property (SCM_CAR (SCM_CDR (SCM_CODE (proc))), scm_sym_procname); | |
f0e9217a | 401 | if (SCM_FALSEP (name)) |
63c51b9a | 402 | name = scm_procedure_property (proc, scm_sym_name); |
f0e9217a | 403 | #endif |
c75512d6 MD |
404 | if (SCM_FALSEP (name) && SCM_CLOSUREP (proc)) |
405 | name = scm_reverse_lookup (SCM_ENV (proc), proc); | |
f0e9217a MD |
406 | return name; |
407 | } | |
f0e9217a MD |
408 | } |
409 | } | |
1bbd0b84 | 410 | #undef FUNC_NAME |
f0e9217a | 411 | |
a1ec6916 | 412 | SCM_DEFINE (scm_procedure_source, "procedure-source", 1, 0, 0, |
1bbd0b84 GB |
413 | (SCM proc), |
414 | "") | |
415 | #define FUNC_NAME s_scm_procedure_source | |
f0e9217a | 416 | { |
6b5a304f | 417 | SCM_VALIDATE_NIM (1,proc); |
f0e9217a MD |
418 | switch (SCM_TYP7 (proc)) { |
419 | case scm_tcs_closures: | |
420 | { | |
421 | SCM src; | |
63c51b9a | 422 | src = scm_source_property (SCM_CDR (SCM_CODE (proc)), scm_sym_copy); |
f0e9217a | 423 | if (src != SCM_BOOL_F) |
63c51b9a | 424 | return scm_cons2 (scm_sym_lambda, SCM_CAR (SCM_CODE (proc)), src); |
f0e9217a | 425 | src = SCM_CODE (proc); |
63c51b9a | 426 | return scm_cons (scm_sym_lambda, |
f0e9217a | 427 | scm_unmemocopy (src, |
e2806c10 | 428 | SCM_EXTEND_ENV (SCM_CAR (src), |
f0e9217a MD |
429 | SCM_EOL, |
430 | SCM_ENV (proc)))); | |
431 | } | |
432 | case scm_tc7_contin: | |
433 | case scm_tcs_subrs: | |
434 | #ifdef CCLO | |
435 | case scm_tc7_cclo: | |
436 | #endif | |
437 | /* It would indeed be a nice thing if we supplied source even for | |
438 | built in procedures! */ | |
63c51b9a | 439 | return scm_procedure_property (proc, scm_sym_source); |
f0e9217a | 440 | default: |
1bbd0b84 | 441 | SCM_WTA(1,proc); |
f0e9217a MD |
442 | return 0; |
443 | } | |
444 | } | |
1bbd0b84 | 445 | #undef FUNC_NAME |
f0e9217a | 446 | |
a1ec6916 | 447 | SCM_DEFINE (scm_procedure_environment, "procedure-environment", 1, 0, 0, |
1bbd0b84 GB |
448 | (SCM proc), |
449 | "") | |
450 | #define FUNC_NAME s_scm_procedure_environment | |
f0e9217a | 451 | { |
6b5a304f | 452 | SCM_VALIDATE_NIM (1,proc); |
f0e9217a MD |
453 | switch (SCM_TYP7 (proc)) { |
454 | case scm_tcs_closures: | |
455 | return SCM_ENV (proc); | |
456 | case scm_tc7_contin: | |
457 | case scm_tcs_subrs: | |
458 | #ifdef CCLO | |
459 | case scm_tc7_cclo: | |
460 | #endif | |
461 | return SCM_EOL; | |
462 | default: | |
1bbd0b84 | 463 | SCM_WTA(1,proc); |
f0e9217a MD |
464 | return 0; |
465 | } | |
466 | } | |
1bbd0b84 | 467 | #undef FUNC_NAME |
f0e9217a | 468 | |
bfe3154c | 469 | \f |
f0e9217a MD |
470 | |
471 | /* Eval in a local environment. We would like to have the ability to | |
e38ecb05 MD |
472 | * evaluate in a specified local environment, but due to the |
473 | * memoization this isn't normally possible. We solve it by copying | |
474 | * the code before evaluating. One solution would be to have eval.c | |
475 | * generate yet another evaluator. They are not very big actually. | |
f0e9217a | 476 | */ |
a1ec6916 | 477 | SCM_DEFINE (scm_local_eval, "local-eval", 1, 1, 0, |
1bbd0b84 | 478 | (SCM exp, SCM env), |
4079f87e GB |
479 | "Evaluate @var{exp} in its environment. If @var{env} is supplied, |
480 | it is the environment in which to evaluate @var{exp}. Otherwise, | |
481 | @var{exp} must be a memoized code object (in which case, its environment | |
482 | is implicit).") | |
1bbd0b84 | 483 | #define FUNC_NAME s_scm_local_eval |
f0e9217a | 484 | { |
6c179711 MD |
485 | if (SCM_UNBNDP (env)) |
486 | { | |
1bbd0b84 | 487 | SCM_VALIDATE_MEMOIZED(1,exp); |
6c179711 MD |
488 | return scm_eval_3 (SCM_MEMOIZED_EXP (exp), 0, SCM_MEMOIZED_ENV (exp)); |
489 | } | |
f0e9217a MD |
490 | return scm_eval_3 (exp, 1, env); |
491 | } | |
1bbd0b84 | 492 | #undef FUNC_NAME |
f0e9217a | 493 | |
c75512d6 | 494 | #if 0 |
1bbd0b84 | 495 | SCM_REGISTER_PROC (s_reverse_lookup, "reverse-lookup", 2, 0, 0, scm_reverse_lookup); |
c75512d6 MD |
496 | #endif |
497 | ||
498 | SCM | |
499 | scm_reverse_lookup (SCM env, SCM data) | |
500 | { | |
501 | SCM names, values; | |
f1e1c997 | 502 | while (SCM_NIMP (env) && SCM_SLOPPY_CONSP (SCM_CAR (env))) |
c75512d6 MD |
503 | { |
504 | names = SCM_CAAR (env); | |
505 | values = SCM_CDAR (env); | |
0c95b57d | 506 | while (SCM_CONSP (names)) |
c75512d6 MD |
507 | { |
508 | if (SCM_CAR (values) == data) | |
509 | return SCM_CAR (names); | |
510 | names = SCM_CDR (names); | |
511 | values = SCM_CDR (values); | |
512 | } | |
513 | if (names != SCM_EOL && values == data) | |
514 | return names; | |
515 | env = SCM_CDR (env); | |
516 | } | |
517 | return SCM_BOOL_F; | |
518 | } | |
519 | ||
bfe3154c | 520 | SCM |
6e8d25a6 | 521 | scm_start_stack (SCM id, SCM exp, SCM env) |
bfe3154c MD |
522 | { |
523 | SCM answer; | |
c6b8a41a | 524 | scm_debug_frame vframe; |
c0ab1b8d | 525 | scm_debug_info vframe_vect_body; |
9fa2c7b1 MD |
526 | vframe.prev = scm_last_debug_frame; |
527 | vframe.status = SCM_VOIDFRAME; | |
528 | vframe.vect = &vframe_vect_body; | |
529 | vframe.vect[0].id = id; | |
530 | scm_last_debug_frame = &vframe; | |
cb412265 | 531 | answer = scm_eval_3 (exp, 1, env); |
9fa2c7b1 MD |
532 | scm_last_debug_frame = vframe.prev; |
533 | return answer; | |
534 | } | |
535 | ||
b8229a3b MS |
536 | SCM_SYNTAX(s_start_stack, "start-stack", scm_makacro, scm_m_start_stack); |
537 | ||
8a04c1a2 | 538 | static SCM |
6e8d25a6 | 539 | scm_m_start_stack (SCM exp, SCM env) |
9fa2c7b1 | 540 | { |
bfe3154c | 541 | exp = SCM_CDR (exp); |
cabe682c GB |
542 | SCM_ASSERT (SCM_ECONSP (exp) |
543 | && SCM_ECONSP (SCM_CDR (exp)) | |
c6b8a41a | 544 | && SCM_NULLP (SCM_CDDR (exp)), |
bfe3154c MD |
545 | exp, |
546 | SCM_WNA, | |
547 | s_start_stack); | |
9fa2c7b1 | 548 | return scm_start_stack (scm_eval_car (exp, env), SCM_CADR (exp), env); |
bfe3154c | 549 | } |
f0e9217a MD |
550 | |
551 | /* {Debug Objects} | |
552 | * | |
553 | * The debugging evaluator throws these on frame traps. | |
554 | */ | |
555 | ||
556 | long scm_tc16_debugobj; | |
557 | ||
f0e9217a | 558 | static int |
1bbd0b84 | 559 | prindebugobj (SCM obj,SCM port,scm_print_state *pstate) |
f0e9217a | 560 | { |
b7f3516f | 561 | scm_puts ("#<debug-object ", port); |
bfe3154c | 562 | scm_intprint (SCM_DEBUGOBJ_FRAME (obj), 16, port); |
b7f3516f | 563 | scm_putc ('>', port); |
f0e9217a MD |
564 | return 1; |
565 | } | |
566 | ||
a1ec6916 | 567 | SCM_DEFINE (scm_debug_object_p, "debug-object?", 1, 0, 0, |
1bbd0b84 GB |
568 | (SCM obj), |
569 | "") | |
570 | #define FUNC_NAME s_scm_debug_object_p | |
f0e9217a | 571 | { |
0c95b57d | 572 | return SCM_BOOL(SCM_DEBUGOBJP (obj)); |
f0e9217a | 573 | } |
1bbd0b84 | 574 | #undef FUNC_NAME |
f0e9217a | 575 | |
1cc91f1b | 576 | |
f0e9217a | 577 | SCM |
1bbd0b84 | 578 | scm_make_debugobj (scm_debug_frame *frame) |
f0e9217a MD |
579 | { |
580 | register SCM z; | |
f0e9217a | 581 | SCM_NEWCELL (z); |
f83e2737 | 582 | SCM_ENTER_A_SECTION; |
a6c64c3c | 583 | SCM_SET_DEBUGOBJ_FRAME (z, (SCM) frame); |
f83e2737 MD |
584 | SCM_SETCAR (z, scm_tc16_debugobj); |
585 | SCM_EXIT_A_SECTION; | |
f0e9217a MD |
586 | return z; |
587 | } | |
588 | ||
f0e9217a MD |
589 | \f |
590 | ||
fe57f652 MD |
591 | /* Undocumented debugging procedure */ |
592 | #ifdef GUILE_DEBUG | |
a1ec6916 | 593 | SCM_DEFINE (scm_debug_hang, "debug-hang", 0, 1, 0, |
1bbd0b84 GB |
594 | (SCM obj), |
595 | "") | |
596 | #define FUNC_NAME s_scm_debug_hang | |
e38ecb05 MD |
597 | { |
598 | int go = 0; | |
599 | while (!go) ; | |
600 | return SCM_UNSPECIFIED; | |
601 | } | |
1bbd0b84 | 602 | #undef FUNC_NAME |
fe57f652 | 603 | #endif |
e38ecb05 MD |
604 | |
605 | \f | |
606 | ||
f0e9217a MD |
607 | void |
608 | scm_init_debug () | |
609 | { | |
5e8d7fd4 | 610 | scm_init_opts (scm_debug_options, scm_debug_opts, SCM_N_DEBUG_OPTIONS); |
ee340120 | 611 | |
23a62151 MD |
612 | scm_tc16_memoized = scm_make_smob_type_mfpe ("memoized", 0, |
613 | scm_markcdr, NULL, prinmemoized, NULL); | |
614 | ||
615 | scm_tc16_debugobj = scm_make_smob_type_mfpe ("debug-object", 0, | |
616 | NULL, NULL, prindebugobj, NULL); | |
f0e9217a | 617 | |
63c51b9a MD |
618 | scm_sym_procname = SCM_CAR (scm_sysintern ("procname", SCM_UNDEFINED)); |
619 | scm_sym_dots = SCM_CAR (scm_sysintern ("...", SCM_UNDEFINED)); | |
620 | scm_sym_source = SCM_CAR (scm_sysintern ("source", SCM_UNDEFINED)); | |
f0e9217a | 621 | |
33b97402 MD |
622 | #ifdef GUILE_DEBUG |
623 | scm_sysintern ("SCM_IM_AND", SCM_IM_AND); | |
624 | scm_sysintern ("SCM_IM_BEGIN", SCM_IM_BEGIN); | |
625 | scm_sysintern ("SCM_IM_CASE", SCM_IM_CASE); | |
626 | scm_sysintern ("SCM_IM_COND", SCM_IM_COND); | |
627 | scm_sysintern ("SCM_IM_DO", SCM_IM_DO); | |
628 | scm_sysintern ("SCM_IM_IF", SCM_IM_IF); | |
629 | scm_sysintern ("SCM_IM_LAMBDA", SCM_IM_LAMBDA); | |
630 | scm_sysintern ("SCM_IM_LET", SCM_IM_LET); | |
631 | scm_sysintern ("SCM_IM_LETSTAR", SCM_IM_LETSTAR); | |
632 | scm_sysintern ("SCM_IM_LETREC", SCM_IM_LETREC); | |
633 | scm_sysintern ("SCM_IM_OR", SCM_IM_OR); | |
634 | scm_sysintern ("SCM_IM_QUOTE", SCM_IM_QUOTE); | |
bbab09f6 | 635 | scm_sysintern ("SCM_IM_SET_X", SCM_IM_SET_X); |
33b97402 MD |
636 | scm_sysintern ("SCM_IM_DEFINE", SCM_IM_DEFINE); |
637 | scm_sysintern ("SCM_IM_APPLY", SCM_IM_APPLY); | |
638 | scm_sysintern ("SCM_IM_CONT", SCM_IM_CONT); | |
bbab09f6 | 639 | scm_sysintern ("SCM_IM_DISPATCH", SCM_IM_DISPATCH); |
33b97402 | 640 | #endif |
f0e9217a MD |
641 | scm_add_feature ("debug-extensions"); |
642 | ||
643 | #include "debug.x" | |
644 | } |