Mercurial > hg > xemacs-beta
annotate src/debug.c @ 5560:58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
src/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* alloc.c:
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT_1):
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT):
* alloc.c (cons_print_preprocess):
* alloc.c (vector_print_preprocess):
* alloc.c (vector_nsubst_structures_descend):
* alloc.c (Fmake_symbol):
* alloc.c (UNMARK_symbol):
* alloc.c (sweep_symbols):
* alloc.c (reinit_alloc_objects_early):
* alloc.c (reinit_alloc_early):
* bytecode.c:
* bytecode.c (compiled_function_print_preprocess):
* bytecode.c (compiled_function_nsubst_structures_descend):
* bytecode.c (set_compiled_function_arglist):
* bytecode.c (set_compiled_function_interactive):
* bytecode.c (bytecode_objects_create):
* chartab.c:
* chartab.c (print_preprocess_mapper):
* chartab.c (nsubst_structures_mapper):
* chartab.c (char_table_nsubst_structures_descend):
* chartab.c (chartab_objects_create):
* elhash.c:
* elhash.c (nsubst_structures_map_hash_table):
* elhash.c (hash_table_nsubst_structures_descend):
* elhash.c (print_preprocess_mapper):
* elhash.c (hash_table_print_preprocess):
* elhash.c (inchash_eq):
* elhash.c (hash_table_objects_create):
* elhash.c (syms_of_elhash):
* elhash.h:
* emacs.c (main_1):
* fns.c:
* fns.c (check_eq_nokey):
* fns.c (Fnsubst):
* fns.c (syms_of_fns):
* lisp.h:
* lisp.h (struct Lisp_Symbol):
* lisp.h (IN_OBARRAY):
* lisp.h (struct):
* lisp.h (PRINT_PREPROCESS):
* lread.c (read1):
* lrecord.h:
* lrecord.h (struct lrecord_implementation):
* lrecord.h (DEFINE_DUMPABLE_MODULE_LISP_OBJECT):
* print.c:
* print.c (PRINT_CIRCLE_LIMIT):
* print.c (print_continuous_numbering_changed):
* print.c (print_prepare):
* print.c (print_finish):
* print.c (Fprin1_to_string):
* print.c (print_cons):
* print.c (print_preprocess_inchash_eq):
* print.c (print_preprocess):
* print.c (print_sort_get_numbers):
* print.c (print_sort_compare_ordinals):
* print.c (print_gensym_or_circle):
* print.c (nsubst_structures_descend):
* print.c (nsubst_structures):
* print.c (print_internal):
* print.c (print_symbol):
* print.c (vars_of_print):
* rangetab.c:
* rangetab.c (range_table_print_preprocess):
* rangetab.c (range_table_nsubst_structures_descend):
* rangetab.c (rangetab_objects_create):
* rangetab.c (syms_of_rangetab):
* symbols.c:
* symbols.c (symbol_print_preprocess):
* symbols.c (Fintern):
* symbols.c (Funintern):
* symbols.c (reinit_symbol_objects_early):
* symbols.c (init_symbols_once_early):
* symsinit.h:
Implement print-circle, printing circular structures in a readable
fashion, and treating them appropriately on read. This is by means
of two new object methods, print_preprocess (detecting
circularities), and nsubst_structures_descend (replacing
placeholders with the read objects).
Expose the substitution to Lisp via #'nsubst and its new
:descend-structures keyword.
Store information as to whether symbols are interned in obarray or
not in their header, making checking for keywords and uninterned
symbols (and thus printing) cheaper.
Default print_gensym to t, as Common Lisp does, and as a
more-than-decade old comment suggests.
lisp/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-output-file-form):
* bytecomp.el (byte-compile-output-docform):
Bind print-circle, print-continuous-numbering in these functions,
now those variables are available.
* lisp.el (forward-sexp):
* lisp.el (backward-sexp):
Recognise leading #N= as being part of an expression.
tests/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-reader-tests.el:
* automated/lisp-tests.el (literal-with-uninterned):
* automated/symbol-tests.el (foo):
Test print-circle, for printing (mutually-)recursive and circular
structures.
Bind print-continuous-numbering where appropriate.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sun, 04 Sep 2011 19:51:35 +0100 |
| parents | 308d34e9f07d |
| children | 56144c8593a8 |
| rev | line source |
|---|---|
| 428 | 1 /* Debugging aids -- togglable assertions. |
| 2 Copyright (C) 1994 Free Software Foundation, Inc. | |
| 3 | |
| 4 This file is part of XEmacs. | |
| 5 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4852
diff
changeset
|
6 XEmacs is free software: you can redistribute it and/or modify it |
| 428 | 7 under the terms of the GNU General Public License as published by the |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4852
diff
changeset
|
8 Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4852
diff
changeset
|
9 option) any later version. |
| 428 | 10 |
| 11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4852
diff
changeset
|
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 428 | 18 |
| 19 /* Synched up with: Not in FSF. */ | |
| 20 | |
| 21 /* This file has been Mule-ized. */ | |
| 22 | |
| 23 /* Written by Chuck Thompson */ | |
| 24 | |
| 25 #include <config.h> | |
| 26 #include "lisp.h" | |
| 27 #include "debug.h" | |
| 28 #include "bytecode.h" | |
| 29 | |
| 30 /* | |
| 31 * To add a new debug class: | |
| 1318 | 32 * 1. Add a symbol definition for it here or in general-slots.h, if one |
| 33 * doesn't exist elsewhere. If you add it here, make sure to add a | |
| 34 * defsymbol line for it in syms_of_debug. | |
| 428 | 35 * 2. Add an extern definition for the symbol to debug.h. |
| 36 * 3. Add entries for the class to struct debug_classes in debug.h. | |
| 37 * 4. Add a FROB line for it in xemacs_debug_loop. | |
| 38 */ | |
| 39 | |
| 40 struct debug_classes active_debug_classes; | |
| 41 | |
| 42 enum debug_loop | |
| 43 { | |
| 436 | 44 X_ADD, |
| 45 X_DELETE, | |
| 46 X_LIST, | |
| 47 X_ACTIVE, | |
| 48 X_INIT, | |
| 49 X_VALIDATE, | |
| 50 X_TYPE, | |
| 51 X_SETTYPE | |
| 428 | 52 }; |
| 53 | |
| 54 static Lisp_Object | |
| 1204 | 55 xemacs_debug_loop (enum debug_loop op, Lisp_Object class_, Lisp_Object type) |
| 428 | 56 { |
| 436 | 57 int flag = (op == X_ADD) ? 1 : 0; |
| 428 | 58 Lisp_Object retval = Qnil; |
| 59 | |
| 1318 | 60 #define FROB(item) \ |
| 61 if (op == X_LIST || op == X_ACTIVE || op == X_INIT || EQ (class_, Q##item)) \ | |
| 62 { \ | |
| 63 if (op == X_ADD || op == X_DELETE || op == X_INIT) \ | |
| 64 active_debug_classes.item = flag; \ | |
| 65 else if (op == X_LIST \ | |
| 66 || (op == X_ACTIVE && active_debug_classes.item)) \ | |
| 67 retval = Fcons (Q##item, retval); \ | |
| 68 else if (op == X_VALIDATE) \ | |
| 69 return Qt; \ | |
| 70 else if (op == X_SETTYPE) \ | |
| 71 active_debug_classes.types_of_##item = XINT (type); \ | |
| 72 else if (op == X_TYPE) \ | |
| 73 retval = make_int (active_debug_classes.types_of_##item); \ | |
| 74 if (op == X_INIT) active_debug_classes.types_of_##item = VALBITS; \ | |
| 428 | 75 } |
| 76 | |
| 77 FROB (redisplay); | |
| 78 FROB (buffers); | |
| 79 FROB (extents); | |
| 80 FROB (faces); | |
| 81 FROB (windows); | |
| 82 FROB (frames); | |
| 83 FROB (devices); | |
| 84 FROB (byte_code); | |
| 85 | |
| 86 return retval; | |
| 87 #undef FROB | |
| 88 } | |
| 89 | |
| 90 DEFUN ("add-debug-class-to-check", Fadd_debug_class_to_check, 1, 1, 0, /* | |
| 91 Add a debug class to the list of active classes. | |
| 92 */ | |
| 1204 | 93 (class_)) |
| 428 | 94 { |
| 1204 | 95 if (NILP (xemacs_debug_loop (X_VALIDATE, class_, Qnil))) |
| 563 | 96 invalid_argument ("No such debug class exists", Qunbound); |
| 428 | 97 else |
| 1204 | 98 xemacs_debug_loop (X_ADD, class_, Qnil); |
| 428 | 99 |
| 436 | 100 return (xemacs_debug_loop (X_ACTIVE, Qnil, Qnil)); |
| 428 | 101 } |
| 102 | |
| 103 DEFUN ("delete-debug-class-to-check", Fdelete_debug_class_to_check, 1, 1, 0, /* | |
| 104 Delete a debug class from the list of active classes. | |
| 105 */ | |
| 1204 | 106 (class_)) |
| 428 | 107 { |
| 1204 | 108 if (NILP (xemacs_debug_loop (X_VALIDATE, class_, Qnil))) |
| 563 | 109 invalid_argument ("No such debug class exists", Qunbound); |
| 428 | 110 else |
| 1204 | 111 xemacs_debug_loop (X_DELETE, class_, Qnil); |
| 428 | 112 |
| 436 | 113 return (xemacs_debug_loop (X_ACTIVE, Qnil, Qnil)); |
| 428 | 114 } |
| 115 | |
| 116 DEFUN ("debug-classes-being-checked", Fdebug_classes_being_checked, 0, 0, 0, /* | |
| 117 Return a list of active debug classes. | |
| 118 */ | |
| 119 ()) | |
| 120 { | |
| 436 | 121 return (xemacs_debug_loop (X_ACTIVE, Qnil, Qnil)); |
| 428 | 122 } |
| 123 | |
| 124 DEFUN ("debug-classes-list", Fdebug_classes_list, 0, 0, 0, /* | |
| 125 Return a list of all defined debug classes. | |
| 126 */ | |
| 127 ()) | |
| 128 { | |
| 436 | 129 return (xemacs_debug_loop (X_LIST, Qnil, Qnil)); |
| 428 | 130 } |
| 131 | |
| 132 DEFUN ("set-debug-classes-to-check", Fset_debug_classes_to_check, 1, 1, 0, /* | |
| 133 Set which classes of debug statements should be active. | |
| 134 CLASSES should be a list of debug classes. | |
| 135 */ | |
| 136 (classes)) | |
| 137 { | |
| 138 Lisp_Object rest; | |
| 139 | |
| 140 CHECK_LIST (classes); | |
| 141 | |
| 142 /* Make sure all objects in the list are valid. If anyone is not | |
| 143 valid, reject the entire list without doing anything. */ | |
| 1204 | 144 LIST_LOOP (rest, classes) |
| 428 | 145 { |
| 436 | 146 if (NILP (xemacs_debug_loop (X_VALIDATE, XCAR (rest), Qnil))) |
| 563 | 147 sferror ("Invalid object in class list", Qunbound); |
| 428 | 148 } |
| 149 | |
| 150 LIST_LOOP (rest, classes) | |
| 151 Fadd_debug_class_to_check (XCAR (rest)); | |
| 152 | |
| 436 | 153 return (xemacs_debug_loop (X_ACTIVE, Qnil, Qnil)); |
| 428 | 154 } |
| 155 | |
| 156 DEFUN ("set-debug-class-types-to-check", Fset_debug_class_types_to_check, 2, 2, 0, /* | |
| 157 For the given debug CLASS, set which TYPES are actually interesting. | |
| 158 TYPES should be an integer representing the or'd value of all desired types. | |
| 159 Lists of defined types and their values are located in the source code. | |
| 160 */ | |
| 1204 | 161 (class_, type)) |
| 428 | 162 { |
| 163 CHECK_INT (type); | |
| 1204 | 164 if (NILP (xemacs_debug_loop (X_VALIDATE, class_, Qnil))) |
| 563 | 165 invalid_argument ("Invalid debug class", Qunbound); |
| 428 | 166 |
| 1204 | 167 xemacs_debug_loop (X_SETTYPE, class_, type); |
| 428 | 168 |
| 1204 | 169 return (xemacs_debug_loop (X_TYPE, class_, Qnil)); |
| 428 | 170 } |
| 171 | |
| 172 DEFUN ("debug-types-being-checked", Fdebug_types_being_checked, 1, 1, 0, /* | |
| 173 For the given CLASS, return the associated type value. | |
| 174 */ | |
| 1204 | 175 (class_)) |
| 428 | 176 { |
| 1204 | 177 if (NILP (xemacs_debug_loop (X_VALIDATE, class_, Qnil))) |
| 563 | 178 invalid_argument ("Invalid debug class", Qunbound); |
| 428 | 179 |
| 1204 | 180 return (xemacs_debug_loop (X_TYPE, class_, Qnil)); |
| 428 | 181 } |
| 182 | |
| 183 void | |
| 184 syms_of_debug (void) | |
| 185 { | |
| 186 DEFSUBR (Fadd_debug_class_to_check); | |
| 187 DEFSUBR (Fdelete_debug_class_to_check); | |
| 188 DEFSUBR (Fdebug_classes_being_checked); | |
| 189 DEFSUBR (Fdebug_classes_list); | |
| 190 DEFSUBR (Fset_debug_classes_to_check); | |
| 191 DEFSUBR (Fset_debug_class_types_to_check); | |
| 192 DEFSUBR (Fdebug_types_being_checked); | |
| 193 } | |
| 194 | |
| 195 void | |
| 196 reinit_vars_of_debug (void) | |
| 197 { | |
| 198 /* If you need to have any classes active early on in startup, then | |
| 199 the flags should be set here. | |
| 200 All functions called by this function are "allowed" according | |
| 201 to emacs.c. */ | |
| 436 | 202 xemacs_debug_loop (X_INIT, Qnil, Qnil); |
| 428 | 203 } |
| 204 | |
| 205 void | |
| 206 vars_of_debug (void) | |
| 207 { | |
|
4852
e0138eaaca0c
need to provide debug-xemacs for debug-on-error changes to work
Ben Wing <ben@xemacs.org>
parents:
2367
diff
changeset
|
208 Fprovide (intern ("debug-xemacs")); |
| 428 | 209 } |
