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