Commit | Line | Data |
---|---|---|
68baa7e7 | 1 | /* Debugging extensions for Guile |
dbb605f5 | 2 | * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008 Free Software Foundation |
ee340120 | 3 | * |
73be1d9e MV |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2.1 of the License, or (at your option) any later version. | |
ee340120 | 8 | * |
73be1d9e | 9 | * This library is distributed in the hope that it will be useful, |
ee340120 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. | |
ee340120 | 13 | * |
73be1d9e MV |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software | |
92205699 | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
73be1d9e | 17 | */ |
f0e9217a | 18 | |
1bbd0b84 | 19 | |
dbb605f5 LC |
20 | #ifdef HAVE_CONFIG_H |
21 | # include <config.h> | |
22 | #endif | |
1bbd0b84 | 23 | |
a0599745 | 24 | #include "libguile/_scm.h" |
5e3545d0 | 25 | #include "libguile/async.h" |
a0599745 | 26 | #include "libguile/eval.h" |
37c56aec | 27 | #include "libguile/list.h" |
a0599745 MD |
28 | #include "libguile/stackchk.h" |
29 | #include "libguile/throw.h" | |
30 | #include "libguile/macros.h" | |
31 | #include "libguile/smob.h" | |
32 | #include "libguile/procprop.h" | |
33 | #include "libguile/srcprop.h" | |
34 | #include "libguile/alist.h" | |
35 | #include "libguile/continuations.h" | |
36 | #include "libguile/strports.h" | |
37 | #include "libguile/read.h" | |
38 | #include "libguile/feature.h" | |
39 | #include "libguile/dynwind.h" | |
40 | #include "libguile/modules.h" | |
41 | #include "libguile/ports.h" | |
42 | #include "libguile/root.h" | |
b06a8b87 | 43 | #include "libguile/fluids.h" |
b3d7f6df | 44 | #include "libguile/objects.h" |
a0599745 MD |
45 | |
46 | #include "libguile/validate.h" | |
47 | #include "libguile/debug.h" | |
22fc179a HWN |
48 | |
49 | #include "libguile/private-options.h" | |
f0e9217a MD |
50 | \f |
51 | ||
22fc179a | 52 | |
f0e9217a MD |
53 | /* {Run time control of the debugging evaluator} |
54 | */ | |
55 | ||
a1ec6916 | 56 | SCM_DEFINE (scm_debug_options, "debug-options-interface", 0, 1, 0, |
1bbd0b84 | 57 | (SCM setting), |
ba94f79e MG |
58 | "Option interface for the debug options. Instead of using\n" |
59 | "this procedure directly, use the procedures @code{debug-enable},\n" | |
3939e9df | 60 | "@code{debug-disable}, @code{debug-set!} and @code{debug-options}.") |
1bbd0b84 | 61 | #define FUNC_NAME s_scm_debug_options |
f0e9217a MD |
62 | { |
63 | SCM ans; | |
5e3545d0 | 64 | |
661ae7ab MV |
65 | scm_dynwind_begin (0); |
66 | scm_dynwind_critical_section (SCM_BOOL_F); | |
5e3545d0 | 67 | |
62560650 | 68 | ans = scm_options (setting, scm_debug_opts, FUNC_NAME); |
5e8d7fd4 | 69 | if (!(1 <= SCM_N_FRAMES && SCM_N_FRAMES <= SCM_MAX_FRAME_SIZE)) |
f0e9217a | 70 | { |
62560650 | 71 | scm_options (ans, scm_debug_opts, FUNC_NAME); |
1e76143f | 72 | SCM_OUT_OF_RANGE (1, setting); |
f0e9217a | 73 | } |
5e8d7fd4 | 74 | SCM_RESET_DEBUG_MODE; |
a6e350dd | 75 | scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P; |
5e8d7fd4 | 76 | scm_debug_eframe_size = 2 * SCM_N_FRAMES; |
5e3545d0 | 77 | |
661ae7ab | 78 | scm_dynwind_end (); |
f0e9217a MD |
79 | return ans; |
80 | } | |
1bbd0b84 | 81 | #undef FUNC_NAME |
260b1416 | 82 | |
22fc179a | 83 | |
260b1416 MD |
84 | static void |
85 | with_traps_before (void *data) | |
86 | { | |
87 | int *trap_flag = data; | |
88 | *trap_flag = SCM_TRAPS_P; | |
89 | SCM_TRAPS_P = 1; | |
90 | } | |
91 | ||
92 | static void | |
93 | with_traps_after (void *data) | |
94 | { | |
95 | int *trap_flag = data; | |
96 | SCM_TRAPS_P = *trap_flag; | |
97 | } | |
98 | ||
99 | static SCM | |
100 | with_traps_inner (void *data) | |
101 | { | |
702551e6 | 102 | SCM thunk = SCM_PACK ((scm_t_bits) data); |
fdc28395 | 103 | return scm_call_0 (thunk); |
260b1416 | 104 | } |
1cc91f1b | 105 | |
a1ec6916 | 106 | SCM_DEFINE (scm_with_traps, "with-traps", 1, 0, 0, |
1bbd0b84 | 107 | (SCM thunk), |
ba94f79e | 108 | "Call @var{thunk} with traps enabled.") |
1bbd0b84 | 109 | #define FUNC_NAME s_scm_with_traps |
f0e9217a | 110 | { |
260b1416 | 111 | int trap_flag; |
34d19ef6 | 112 | SCM_VALIDATE_THUNK (1, thunk); |
260b1416 MD |
113 | return scm_internal_dynamic_wind (with_traps_before, |
114 | with_traps_inner, | |
115 | with_traps_after, | |
451e591c | 116 | (void *) SCM_UNPACK (thunk), |
260b1416 | 117 | &trap_flag); |
f0e9217a | 118 | } |
1bbd0b84 | 119 | #undef FUNC_NAME |
f0e9217a MD |
120 | |
121 | \f | |
85db4a2c DH |
122 | SCM_SYMBOL (scm_sym_procname, "procname"); |
123 | SCM_SYMBOL (scm_sym_dots, "..."); | |
124 | SCM_SYMBOL (scm_sym_source, "source"); | |
f0e9217a MD |
125 | |
126 | /* {Memoized Source} | |
127 | */ | |
128 | ||
92c2555f | 129 | scm_t_bits scm_tc16_memoized; |
1cc91f1b | 130 | |
f0e9217a | 131 | static int |
e841c3e0 | 132 | memoized_print (SCM obj, SCM port, scm_print_state *pstate) |
f0e9217a | 133 | { |
9882ea19 | 134 | int writingp = SCM_WRITINGP (pstate); |
b7f3516f | 135 | scm_puts ("#<memoized ", port); |
9882ea19 | 136 | SCM_SET_WRITINGP (pstate, 1); |
33b97402 | 137 | scm_iprin1 (SCM_MEMOIZED_EXP (obj), port, pstate); |
9882ea19 | 138 | SCM_SET_WRITINGP (pstate, writingp); |
b7f3516f | 139 | scm_putc ('>', port); |
f0e9217a MD |
140 | return 1; |
141 | } | |
142 | ||
a1ec6916 | 143 | SCM_DEFINE (scm_memoized_p, "memoized?", 1, 0, 0, |
1bbd0b84 | 144 | (SCM obj), |
ba94f79e | 145 | "Return @code{#t} if @var{obj} is memoized.") |
1bbd0b84 | 146 | #define FUNC_NAME s_scm_memoized_p |
f0e9217a | 147 | { |
7888309b | 148 | return scm_from_bool(SCM_MEMOIZEDP (obj)); |
f0e9217a | 149 | } |
1bbd0b84 | 150 | #undef FUNC_NAME |
f0e9217a | 151 | |
f0e9217a | 152 | SCM |
1bbd0b84 | 153 | scm_make_memoized (SCM exp, SCM env) |
f0e9217a | 154 | { |
6c179711 | 155 | /* *fixme* Check that env is a valid environment. */ |
d193b04b | 156 | SCM_RETURN_NEWSMOB (scm_tc16_memoized, SCM_UNPACK (scm_cons (exp, env))); |
f0e9217a MD |
157 | } |
158 | ||
33b97402 MD |
159 | #ifdef GUILE_DEBUG |
160 | /* | |
161 | * Some primitives for construction of memoized code | |
162 | * | |
163 | * - procedure: memcons CAR CDR [ENV] | |
164 | * | |
165 | * Construct a pair, encapsulated in a memoized object. | |
166 | * | |
167 | * The CAR and CDR can be either normal or memoized. If ENV isn't | |
168 | * specified, the top-level environment of the current module will | |
169 | * be assumed. All environments must match. | |
170 | * | |
33b97402 MD |
171 | * - procedure: make-iloc FRAME BINDING CDRP |
172 | * | |
173 | * Return an iloc referring to frame no. FRAME, binding | |
174 | * no. BINDING. If CDRP is non-#f, the iloc is referring to a | |
175 | * frame consisting of a single pair, with the value stored in the | |
176 | * CDR. | |
177 | * | |
178 | * - procedure: iloc? OBJECT | |
179 | * | |
180 | * Return #t if OBJECT is an iloc. | |
181 | * | |
182 | * - procedure: mem->proc MEMOIZED | |
183 | * | |
184 | * Construct a closure from the memoized lambda expression MEMOIZED | |
185 | * | |
186 | * WARNING! The code is not copied! | |
187 | * | |
188 | * - procedure: proc->mem CLOSURE | |
189 | * | |
190 | * Turn the closure CLOSURE into a memoized object. | |
191 | * | |
192 | * WARNING! The code is not copied! | |
193 | * | |
194 | * - constant: SCM_IM_AND | |
195 | * - constant: SCM_IM_BEGIN | |
196 | * - constant: SCM_IM_CASE | |
197 | * - constant: SCM_IM_COND | |
198 | * - constant: SCM_IM_DO | |
199 | * - constant: SCM_IM_IF | |
200 | * - constant: SCM_IM_LAMBDA | |
201 | * - constant: SCM_IM_LET | |
202 | * - constant: SCM_IM_LETSTAR | |
203 | * - constant: SCM_IM_LETREC | |
204 | * - constant: SCM_IM_OR | |
205 | * - constant: SCM_IM_QUOTE | |
206 | * - constant: SCM_IM_SET | |
207 | * - constant: SCM_IM_DEFINE | |
208 | * - constant: SCM_IM_APPLY | |
209 | * - constant: SCM_IM_CONT | |
bbab09f6 | 210 | * - constant: SCM_IM_DISPATCH |
33b97402 MD |
211 | */ |
212 | ||
a0599745 MD |
213 | #include "libguile/variable.h" |
214 | #include "libguile/procs.h" | |
33b97402 | 215 | |
a1ec6916 | 216 | SCM_DEFINE (scm_memcons, "memcons", 2, 1, 0, |
1bbd0b84 | 217 | (SCM car, SCM cdr, SCM env), |
ba94f79e MG |
218 | "Return a new memoized cons cell with @var{car} and @var{cdr}\n" |
219 | "as members and @var{env} as the environment.") | |
1bbd0b84 | 220 | #define FUNC_NAME s_scm_memcons |
33b97402 | 221 | { |
0c95b57d | 222 | if (SCM_MEMOIZEDP (car)) |
33b97402 MD |
223 | { |
224 | /*fixme* environments may be two different but equal top-level envs */ | |
225 | if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (car) != env) | |
e8e9b690 | 226 | SCM_MISC_ERROR ("environment mismatch arg1 <-> arg3", |
37c56aec | 227 | scm_list_2 (car, env)); |
33b97402 MD |
228 | else |
229 | env = SCM_MEMOIZED_ENV (car); | |
230 | car = SCM_MEMOIZED_EXP (car); | |
231 | } | |
0c95b57d | 232 | if (SCM_MEMOIZEDP (cdr)) |
33b97402 MD |
233 | { |
234 | if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (cdr) != env) | |
e8e9b690 | 235 | SCM_MISC_ERROR ("environment mismatch arg2 <-> arg3", |
37c56aec | 236 | scm_list_2 (cdr, env)); |
33b97402 MD |
237 | else |
238 | env = SCM_MEMOIZED_ENV (cdr); | |
239 | cdr = SCM_MEMOIZED_EXP (cdr); | |
240 | } | |
241 | if (SCM_UNBNDP (env)) | |
7e73eaee | 242 | env = scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE); |
33b97402 | 243 | else |
34d19ef6 | 244 | SCM_VALIDATE_NULLORCONS (3, env); |
33b97402 MD |
245 | return scm_make_memoized (scm_cons (car, cdr), env); |
246 | } | |
1bbd0b84 | 247 | #undef FUNC_NAME |
33b97402 | 248 | |
a1ec6916 | 249 | SCM_DEFINE (scm_mem_to_proc, "mem->proc", 1, 0, 0, |
1bbd0b84 | 250 | (SCM obj), |
9fcf3cbb | 251 | "Convert a memoized object (which must represent a body)\n" |
ba94f79e | 252 | "to a procedure.") |
1bbd0b84 | 253 | #define FUNC_NAME s_scm_mem_to_proc |
33b97402 MD |
254 | { |
255 | SCM env; | |
34d19ef6 | 256 | SCM_VALIDATE_MEMOIZED (1, obj); |
33b97402 MD |
257 | env = SCM_MEMOIZED_ENV (obj); |
258 | obj = SCM_MEMOIZED_EXP (obj); | |
9fcf3cbb | 259 | return scm_closure (obj, env); |
33b97402 | 260 | } |
1bbd0b84 | 261 | #undef FUNC_NAME |
33b97402 | 262 | |
a1ec6916 | 263 | SCM_DEFINE (scm_proc_to_mem, "proc->mem", 1, 0, 0, |
1bbd0b84 | 264 | (SCM obj), |
ba94f79e | 265 | "Convert a procedure to a memoized object.") |
1bbd0b84 | 266 | #define FUNC_NAME s_scm_proc_to_mem |
33b97402 | 267 | { |
5623a9b4 | 268 | SCM_VALIDATE_CLOSURE (1, obj); |
9fcf3cbb | 269 | return scm_make_memoized (SCM_CODE (obj), SCM_ENV (obj)); |
33b97402 | 270 | } |
1bbd0b84 | 271 | #undef FUNC_NAME |
33b97402 MD |
272 | |
273 | #endif /* GUILE_DEBUG */ | |
274 | ||
9fcf3cbb | 275 | SCM_DEFINE (scm_i_unmemoize_expr, "unmemoize-expr", 1, 0, 0, |
1bbd0b84 | 276 | (SCM m), |
ba94f79e | 277 | "Unmemoize the memoized expression @var{m},") |
9fcf3cbb | 278 | #define FUNC_NAME s_scm_i_unmemoize_expr |
f0e9217a | 279 | { |
34d19ef6 | 280 | SCM_VALIDATE_MEMOIZED (1, m); |
9fcf3cbb | 281 | return scm_i_unmemocopy_expr (SCM_MEMOIZED_EXP (m), SCM_MEMOIZED_ENV (m)); |
f0e9217a | 282 | } |
1bbd0b84 | 283 | #undef FUNC_NAME |
f0e9217a | 284 | |
a1ec6916 | 285 | SCM_DEFINE (scm_memoized_environment, "memoized-environment", 1, 0, 0, |
1bbd0b84 | 286 | (SCM m), |
ba94f79e | 287 | "Return the environment of the memoized expression @var{m}.") |
1bbd0b84 | 288 | #define FUNC_NAME s_scm_memoized_environment |
f0e9217a | 289 | { |
34d19ef6 | 290 | SCM_VALIDATE_MEMOIZED (1, m); |
bfe3154c | 291 | return SCM_MEMOIZED_ENV (m); |
f0e9217a | 292 | } |
1bbd0b84 | 293 | #undef FUNC_NAME |
f0e9217a | 294 | |
a1ec6916 | 295 | SCM_DEFINE (scm_procedure_name, "procedure-name", 1, 0, 0, |
1bbd0b84 | 296 | (SCM proc), |
ba94f79e | 297 | "Return the name of the procedure @var{proc}") |
1bbd0b84 | 298 | #define FUNC_NAME s_scm_procedure_name |
f0e9217a | 299 | { |
34d19ef6 | 300 | SCM_VALIDATE_PROC (1, proc); |
f0e9217a | 301 | switch (SCM_TYP7 (proc)) { |
a726dd9d MD |
302 | case scm_tcs_subrs: |
303 | return SCM_SNAME (proc); | |
304 | default: | |
f0e9217a | 305 | { |
63c51b9a | 306 | SCM name = scm_procedure_property (proc, scm_sym_name); |
f0e9217a | 307 | #if 0 |
63c51b9a | 308 | /* Source property scm_sym_procname not implemented yet... */ |
f9450cdb | 309 | SCM name = scm_source_property (SCM_CAR (SCM_CLOSURE_BODY (proc)), scm_sym_procname); |
7888309b | 310 | if (scm_is_false (name)) |
63c51b9a | 311 | name = scm_procedure_property (proc, scm_sym_name); |
f0e9217a | 312 | #endif |
7888309b | 313 | if (scm_is_false (name) && SCM_CLOSUREP (proc)) |
c75512d6 | 314 | name = scm_reverse_lookup (SCM_ENV (proc), proc); |
f0e9217a MD |
315 | return name; |
316 | } | |
f0e9217a MD |
317 | } |
318 | } | |
1bbd0b84 | 319 | #undef FUNC_NAME |
f0e9217a | 320 | |
a1ec6916 | 321 | SCM_DEFINE (scm_procedure_source, "procedure-source", 1, 0, 0, |
1bbd0b84 | 322 | (SCM proc), |
ba94f79e | 323 | "Return the source of the procedure @var{proc}.") |
1bbd0b84 | 324 | #define FUNC_NAME s_scm_procedure_source |
f0e9217a | 325 | { |
34d19ef6 | 326 | SCM_VALIDATE_NIM (1, proc); |
b3d7f6df | 327 | again: |
f0e9217a MD |
328 | switch (SCM_TYP7 (proc)) { |
329 | case scm_tcs_closures: | |
330 | { | |
212e58ed DH |
331 | const SCM formals = SCM_CLOSURE_FORMALS (proc); |
332 | const SCM body = SCM_CLOSURE_BODY (proc); | |
333 | const SCM src = scm_source_property (body, scm_sym_copy); | |
334 | ||
7888309b | 335 | if (scm_is_true (src)) |
212e58ed DH |
336 | { |
337 | return scm_cons2 (scm_sym_lambda, formals, src); | |
338 | } | |
339 | else | |
340 | { | |
341 | const SCM env = SCM_EXTEND_ENV (formals, SCM_EOL, SCM_ENV (proc)); | |
342 | return scm_cons2 (scm_sym_lambda, | |
343 | scm_i_finite_list_copy (formals), | |
9fcf3cbb | 344 | scm_i_unmemocopy_body (body, env)); |
212e58ed | 345 | } |
f0e9217a | 346 | } |
b3d7f6df MD |
347 | case scm_tcs_struct: |
348 | if (!SCM_I_OPERATORP (proc)) | |
349 | break; | |
350 | goto procprop; | |
351 | case scm_tc7_smob: | |
352 | if (!SCM_SMOB_DESCRIPTOR (proc).apply) | |
353 | break; | |
f0e9217a MD |
354 | case scm_tcs_subrs: |
355 | #ifdef CCLO | |
356 | case scm_tc7_cclo: | |
357 | #endif | |
b3d7f6df | 358 | procprop: |
f0e9217a MD |
359 | /* It would indeed be a nice thing if we supplied source even for |
360 | built in procedures! */ | |
63c51b9a | 361 | return scm_procedure_property (proc, scm_sym_source); |
b3d7f6df MD |
362 | case scm_tc7_pws: |
363 | { | |
364 | SCM src = scm_procedure_property (proc, scm_sym_source); | |
7888309b | 365 | if (scm_is_true (src)) |
b3d7f6df MD |
366 | return src; |
367 | proc = SCM_PROCEDURE (proc); | |
368 | goto again; | |
369 | } | |
f0e9217a | 370 | default: |
b3d7f6df | 371 | ; |
f0e9217a | 372 | } |
b3d7f6df MD |
373 | SCM_WRONG_TYPE_ARG (1, proc); |
374 | return SCM_BOOL_F; /* not reached */ | |
f0e9217a | 375 | } |
1bbd0b84 | 376 | #undef FUNC_NAME |
f0e9217a | 377 | |
a1ec6916 | 378 | SCM_DEFINE (scm_procedure_environment, "procedure-environment", 1, 0, 0, |
1bbd0b84 | 379 | (SCM proc), |
ba94f79e | 380 | "Return the environment of the procedure @var{proc}.") |
1bbd0b84 | 381 | #define FUNC_NAME s_scm_procedure_environment |
f0e9217a | 382 | { |
34d19ef6 | 383 | SCM_VALIDATE_NIM (1, proc); |
f0e9217a MD |
384 | switch (SCM_TYP7 (proc)) { |
385 | case scm_tcs_closures: | |
386 | return SCM_ENV (proc); | |
f0e9217a MD |
387 | case scm_tcs_subrs: |
388 | #ifdef CCLO | |
389 | case scm_tc7_cclo: | |
390 | #endif | |
391 | return SCM_EOL; | |
392 | default: | |
276dd677 DH |
393 | SCM_WRONG_TYPE_ARG (1, proc); |
394 | /* not reached */ | |
f0e9217a MD |
395 | } |
396 | } | |
1bbd0b84 | 397 | #undef FUNC_NAME |
f0e9217a | 398 | |
bfe3154c | 399 | \f |
f0e9217a MD |
400 | |
401 | /* Eval in a local environment. We would like to have the ability to | |
e38ecb05 MD |
402 | * evaluate in a specified local environment, but due to the |
403 | * memoization this isn't normally possible. We solve it by copying | |
404 | * the code before evaluating. One solution would be to have eval.c | |
405 | * generate yet another evaluator. They are not very big actually. | |
f0e9217a | 406 | */ |
a1ec6916 | 407 | SCM_DEFINE (scm_local_eval, "local-eval", 1, 1, 0, |
1bbd0b84 | 408 | (SCM exp, SCM env), |
b380b885 MD |
409 | "Evaluate @var{exp} in its environment. If @var{env} is supplied,\n" |
410 | "it is the environment in which to evaluate @var{exp}. Otherwise,\n" | |
411 | "@var{exp} must be a memoized code object (in which case, its environment\n" | |
412 | "is implicit).") | |
1bbd0b84 | 413 | #define FUNC_NAME s_scm_local_eval |
f0e9217a | 414 | { |
6c179711 MD |
415 | if (SCM_UNBNDP (env)) |
416 | { | |
82b3290d MD |
417 | SCM_VALIDATE_MEMOIZED (1, exp); |
418 | return scm_i_eval_x (SCM_MEMOIZED_EXP (exp), SCM_MEMOIZED_ENV (exp)); | |
6c179711 | 419 | } |
82b3290d | 420 | return scm_i_eval (exp, env); |
f0e9217a | 421 | } |
1bbd0b84 | 422 | #undef FUNC_NAME |
f0e9217a | 423 | |
c75512d6 | 424 | #if 0 |
1bbd0b84 | 425 | SCM_REGISTER_PROC (s_reverse_lookup, "reverse-lookup", 2, 0, 0, scm_reverse_lookup); |
c75512d6 MD |
426 | #endif |
427 | ||
428 | SCM | |
429 | scm_reverse_lookup (SCM env, SCM data) | |
430 | { | |
d2e53ed6 | 431 | while (scm_is_pair (env) && scm_is_pair (SCM_CAR (env))) |
c75512d6 | 432 | { |
22a52da1 DH |
433 | SCM names = SCM_CAAR (env); |
434 | SCM values = SCM_CDAR (env); | |
d2e53ed6 | 435 | while (scm_is_pair (names)) |
c75512d6 | 436 | { |
bc36d050 | 437 | if (scm_is_eq (SCM_CAR (values), data)) |
c75512d6 MD |
438 | return SCM_CAR (names); |
439 | names = SCM_CDR (names); | |
440 | values = SCM_CDR (values); | |
441 | } | |
d2e53ed6 | 442 | if (!scm_is_null (names) && scm_is_eq (values, data)) |
c75512d6 MD |
443 | return names; |
444 | env = SCM_CDR (env); | |
445 | } | |
446 | return SCM_BOOL_F; | |
447 | } | |
448 | ||
bfe3154c | 449 | SCM |
6e8d25a6 | 450 | scm_start_stack (SCM id, SCM exp, SCM env) |
bfe3154c MD |
451 | { |
452 | SCM answer; | |
92c2555f MV |
453 | scm_t_debug_frame vframe; |
454 | scm_t_debug_info vframe_vect_body; | |
9de87eea | 455 | vframe.prev = scm_i_last_debug_frame (); |
9fa2c7b1 MD |
456 | vframe.status = SCM_VOIDFRAME; |
457 | vframe.vect = &vframe_vect_body; | |
458 | vframe.vect[0].id = id; | |
9de87eea | 459 | scm_i_set_last_debug_frame (&vframe); |
82b3290d | 460 | answer = scm_i_eval (exp, env); |
9de87eea | 461 | scm_i_set_last_debug_frame (vframe.prev); |
9fa2c7b1 MD |
462 | return answer; |
463 | } | |
464 | ||
b8229a3b MS |
465 | SCM_SYNTAX(s_start_stack, "start-stack", scm_makacro, scm_m_start_stack); |
466 | ||
8a04c1a2 | 467 | static SCM |
6e8d25a6 | 468 | scm_m_start_stack (SCM exp, SCM env) |
68baa7e7 | 469 | #define FUNC_NAME s_start_stack |
9fa2c7b1 | 470 | { |
bfe3154c | 471 | exp = SCM_CDR (exp); |
d2e53ed6 MV |
472 | if (!scm_is_pair (exp) |
473 | || !scm_is_pair (SCM_CDR (exp)) | |
474 | || !scm_is_null (SCM_CDDR (exp))) | |
68baa7e7 | 475 | SCM_WRONG_NUM_ARGS (); |
9fa2c7b1 | 476 | return scm_start_stack (scm_eval_car (exp, env), SCM_CADR (exp), env); |
bfe3154c | 477 | } |
68baa7e7 DH |
478 | #undef FUNC_NAME |
479 | ||
f0e9217a MD |
480 | |
481 | /* {Debug Objects} | |
482 | * | |
483 | * The debugging evaluator throws these on frame traps. | |
484 | */ | |
485 | ||
92c2555f | 486 | scm_t_bits scm_tc16_debugobj; |
f0e9217a | 487 | |
f0e9217a | 488 | static int |
e81d98ec | 489 | debugobj_print (SCM obj, SCM port, scm_print_state *pstate SCM_UNUSED) |
f0e9217a | 490 | { |
b7f3516f | 491 | scm_puts ("#<debug-object ", port); |
37c56aec | 492 | scm_intprint ((long) SCM_DEBUGOBJ_FRAME (obj), 16, port); |
b7f3516f | 493 | scm_putc ('>', port); |
f0e9217a MD |
494 | return 1; |
495 | } | |
496 | ||
a1ec6916 | 497 | SCM_DEFINE (scm_debug_object_p, "debug-object?", 1, 0, 0, |
1bbd0b84 | 498 | (SCM obj), |
ba94f79e | 499 | "Return @code{#t} if @var{obj} is a debug object.") |
1bbd0b84 | 500 | #define FUNC_NAME s_scm_debug_object_p |
f0e9217a | 501 | { |
7888309b | 502 | return scm_from_bool(SCM_DEBUGOBJP (obj)); |
f0e9217a | 503 | } |
1bbd0b84 | 504 | #undef FUNC_NAME |
f0e9217a | 505 | |
1cc91f1b | 506 | |
f0e9217a | 507 | SCM |
92c2555f | 508 | scm_make_debugobj (scm_t_debug_frame *frame) |
f0e9217a | 509 | { |
228a24ef | 510 | return scm_cell (scm_tc16_debugobj, (scm_t_bits) frame); |
f0e9217a MD |
511 | } |
512 | ||
f0e9217a MD |
513 | \f |
514 | ||
fe57f652 MD |
515 | /* Undocumented debugging procedure */ |
516 | #ifdef GUILE_DEBUG | |
a1ec6916 | 517 | SCM_DEFINE (scm_debug_hang, "debug-hang", 0, 1, 0, |
1bbd0b84 | 518 | (SCM obj), |
ba94f79e MG |
519 | "Go into an endless loop, which can be only terminated with\n" |
520 | "a debugger.") | |
1bbd0b84 | 521 | #define FUNC_NAME s_scm_debug_hang |
e38ecb05 MD |
522 | { |
523 | int go = 0; | |
524 | while (!go) ; | |
525 | return SCM_UNSPECIFIED; | |
526 | } | |
1bbd0b84 | 527 | #undef FUNC_NAME |
fe57f652 | 528 | #endif |
e38ecb05 MD |
529 | |
530 | \f | |
531 | ||
f0e9217a MD |
532 | void |
533 | scm_init_debug () | |
534 | { | |
62560650 | 535 | scm_init_opts (scm_debug_options, scm_debug_opts); |
ee340120 | 536 | |
e841c3e0 | 537 | scm_tc16_memoized = scm_make_smob_type ("memoized", 0); |
e841c3e0 | 538 | scm_set_smob_print (scm_tc16_memoized, memoized_print); |
23a62151 | 539 | |
e841c3e0 KN |
540 | scm_tc16_debugobj = scm_make_smob_type ("debug-object", 0); |
541 | scm_set_smob_print (scm_tc16_debugobj, debugobj_print); | |
f0e9217a | 542 | |
33b97402 | 543 | #ifdef GUILE_DEBUG |
1be6b49c ML |
544 | scm_c_define ("SCM_IM_AND", SCM_IM_AND); |
545 | scm_c_define ("SCM_IM_BEGIN", SCM_IM_BEGIN); | |
546 | scm_c_define ("SCM_IM_CASE", SCM_IM_CASE); | |
547 | scm_c_define ("SCM_IM_COND", SCM_IM_COND); | |
548 | scm_c_define ("SCM_IM_DO", SCM_IM_DO); | |
549 | scm_c_define ("SCM_IM_IF", SCM_IM_IF); | |
550 | scm_c_define ("SCM_IM_LAMBDA", SCM_IM_LAMBDA); | |
551 | scm_c_define ("SCM_IM_LET", SCM_IM_LET); | |
552 | scm_c_define ("SCM_IM_LETSTAR", SCM_IM_LETSTAR); | |
553 | scm_c_define ("SCM_IM_LETREC", SCM_IM_LETREC); | |
554 | scm_c_define ("SCM_IM_OR", SCM_IM_OR); | |
555 | scm_c_define ("SCM_IM_QUOTE", SCM_IM_QUOTE); | |
556 | scm_c_define ("SCM_IM_SET_X", SCM_IM_SET_X); | |
557 | scm_c_define ("SCM_IM_DEFINE", SCM_IM_DEFINE); | |
558 | scm_c_define ("SCM_IM_APPLY", SCM_IM_APPLY); | |
559 | scm_c_define ("SCM_IM_CONT", SCM_IM_CONT); | |
560 | scm_c_define ("SCM_IM_DISPATCH", SCM_IM_DISPATCH); | |
33b97402 | 561 | #endif |
f0e9217a MD |
562 | scm_add_feature ("debug-extensions"); |
563 | ||
a0599745 | 564 | #include "libguile/debug.x" |
f0e9217a | 565 | } |
89e00824 ML |
566 | |
567 | /* | |
568 | Local Variables: | |
569 | c-file-style: "gnu" | |
570 | End: | |
571 | */ |