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