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