Mercurial > hg > xemacs-beta
annotate modules/sample/external/sample.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 | dd9541c73e70 |
| children |
| rev | line source |
|---|---|
| 996 | 1 /* |
| 2 * Very simple sample module. Illustrates most of the salient features | |
| 3 * of Emacs dynamic modules. | |
| 4 * (C) Copyright 1998, 1999 J. Kean Johnston. All rights reserved. | |
| 5 * (C) Copyright 2002 Jerry James. | |
|
4737
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
6 * |
|
5417
dd9541c73e70
Converted the modules samples to GPLv3 or later.
Mats Lidell <matsl@xemacs.org>
parents:
4737
diff
changeset
|
7 * This sample is free software; you can redistribute it and/or modify it |
|
dd9541c73e70
Converted the modules samples to GPLv3 or later.
Mats Lidell <matsl@xemacs.org>
parents:
4737
diff
changeset
|
8 * under the terms of the GNU General Public License as published by the |
|
dd9541c73e70
Converted the modules samples to GPLv3 or later.
Mats Lidell <matsl@xemacs.org>
parents:
4737
diff
changeset
|
9 * Free Software Foundation, either version 3 of the License, or (at your |
|
dd9541c73e70
Converted the modules samples to GPLv3 or later.
Mats Lidell <matsl@xemacs.org>
parents:
4737
diff
changeset
|
10 * option) any later version. |
| 996 | 11 */ |
| 12 | |
| 13 #include <config.h> | |
| 14 #include "lisp.h" | |
| 15 | |
| 16 /* | |
| 17 * This sample introduces three new Lisp objects to the Lisp reader. | |
| 18 * The first, a simple boolean value, and the second a string. The | |
| 19 * Third is a sample function that simply prints a message. | |
| 20 */ | |
| 21 int sample_bool; | |
| 22 Lisp_Object Vsample_string; | |
| 23 | |
| 24 DEFUN ("sample-function", Fsample_function, 0, 0, "", /* | |
| 25 This is a sample function loaded dynamically. | |
| 26 | |
| 27 You will notice in the source code for this module that the | |
| 28 declaration is identical to internal Emacs functions. This | |
| 29 makes it possible to use the exact same code in a dumped | |
| 30 version of Emacs. | |
| 31 */ | |
| 32 ()) | |
| 33 { | |
| 34 message ("Eureka! It worked"); | |
| 35 return Qt; | |
| 36 } | |
| 37 | |
| 38 /* | |
| 39 * Each dynamically loaded Emacs module is given a name at compile | |
| 40 * time. This is a short name, and must be a valid part of a C | |
| 41 * identifier. This name is used to construct the name of several | |
| 42 * functions which must appear in the module source code. | |
| 43 * The first such function, modules_of_XXXX, should load in any dependent | |
| 44 * modules. This function is optional, and the module will still load if | |
| 45 * it is not present in the module. | |
| 46 * | |
| 47 * The second function, which is NOT optional, is syms_of_XXXX, in which | |
| 48 * all functions that the module will be provided are declared. This | |
| 49 * function will contain calls to DEFSUBR(). | |
| 50 * | |
| 51 * The third function, which is also NOT optional, is vars_of_XXXX, in | |
| 52 * which you declare all variables that the module provides. This | |
| 53 * function will contain calls to DEFVAR_LISP(), DEFVAR_BOOL() etc. | |
| 54 * | |
| 55 * When declaring functions and variables in the syms_of_XXXX and | |
| 56 * vars_of_XXXX functions, you use the exact same syntax that you | |
| 57 * would as if this module were being compiled into the pure Emacs. | |
| 58 * | |
| 59 * The fourth function, which is optional, is unload_XXXX, in which actions | |
| 60 * that must be taken to unload the module are listed. XEmacs will unbind | |
| 61 * functions and variables for you. Anything else that must be done should | |
| 62 * appear in this function. | |
| 63 * | |
| 64 * All four of these functions are declared as void functions, | |
| 65 * taking no parameters. Since this sample module is called 'sample', | |
| 66 * the functions will be named 'modules_of_sample', 'syms_of_sample', | |
| 67 * 'vars_of_sample', and 'unload_sample'. | |
| 68 */ | |
| 69 | |
| 70 void | |
| 71 modules_of_sample() | |
| 72 { | |
| 73 /* | |
| 74 * This function isn't actually required as we will not be loading | |
| 75 * in any dependent modules, but if we were, we would do something like: | |
| 76 * emodules_load ("dependent.ell", "sample2", "1.0.0"); | |
| 77 */ | |
| 78 } | |
| 79 | |
| 80 void | |
| 81 syms_of_sample() | |
| 82 { | |
| 83 DEFSUBR(Fsample_function); | |
| 84 } | |
| 85 | |
| 86 void | |
| 87 vars_of_sample() | |
| 88 { | |
| 89 DEFVAR_LISP ("sample-string", &Vsample_string /* | |
| 90 This is a sample string, declared in a dynamic module. | |
| 91 | |
| 92 The syntax and conventions used for all normal Emacs variables | |
| 93 apply equally to modules, using an identical syntax. | |
| 94 */ ); | |
| 95 | |
| 96 DEFVAR_BOOL ("sample-boolean", &sample_bool /* | |
| 97 *Sample boolean value, in a dynamic module. | |
| 98 | |
| 99 This is a user-settable variable, as indicated by the * | |
| 100 as the first character of the description. Declared in | |
| 101 a module exactly as it would be internally in Emacs. | |
| 102 */ ); | |
| 103 } | |
| 104 | |
| 105 #ifdef HAVE_SHLIB | |
| 106 void | |
| 107 unload_sample() | |
| 108 { | |
| 109 /* We don't need to do anything here in the sample case. However, if you | |
| 110 create any new types with INIT_LRECORD_IMPLEMENTATION (sample_type), then | |
| 111 UNDEF_LRECORD_IMPLEMENTATION (sample_type) must appear here. Also, any | |
| 112 symbols declared with DEFSYMBOL (Qsample_var), or one of its variants, | |
| 113 must have a corresponding unstaticpro_nodump (&Qsample_var) here. */ | |
| 114 } | |
| 115 #endif |
