Mercurial > hg > xemacs-beta
annotate src/lread.c @ 4921:17362f371cc2
add more byte-code assertions and better failure output
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-03 Ben Wing <ben@xemacs.org>
* alloc.c (Fmake_byte_code):
* bytecode.h:
* lisp.h:
* lread.c:
* lread.c (readevalloop):
* lread.c (Fread):
* lread.c (Fread_from_string):
* lread.c (read_list_conser):
* lread.c (read_list):
* lread.c (vars_of_lread):
* symbols.c:
* symbols.c (Fdefine_function):
Turn on the "compiled-function annotation hack". Implement it
properly by hooking into Fdefalias(). Note in the docstring to
`defalias' that we do this. Remove some old broken code and
change code that implemented the old kludgy way of hooking into
the Lisp reader into bracketed by `#ifdef
COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY', which is not enabled.
Also enable byte-code metering when DEBUG_XEMACS -- this is a form
of profiling for computing histograms of which sequences of two
bytecodes are used most often.
* bytecode-ops.h:
* bytecode-ops.h (OPCODE):
New file. Extract out all the opcodes and declare them using
OPCODE(), a bit like frame slots and such. This way the file can
be included multiple times if necessary to iterate multiple times
over the byte opcodes.
* bytecode.c:
* bytecode.c (NUM_REMEMBERED_BYTE_OPS):
* bytecode.c (OPCODE):
* bytecode.c (assert_failed_with_remembered_ops):
* bytecode.c (READ_UINT_2):
* bytecode.c (READ_INT_1):
* bytecode.c (READ_INT_2):
* bytecode.c (PEEK_INT_1):
* bytecode.c (PEEK_INT_2):
* bytecode.c (JUMP_RELATIVE):
* bytecode.c (JUMP_NEXT):
* bytecode.c (PUSH):
* bytecode.c (POP_WITH_MULTIPLE_VALUES):
* bytecode.c (DISCARD):
* bytecode.c (UNUSED):
* bytecode.c (optimize_byte_code):
* bytecode.c (optimize_compiled_function):
* bytecode.c (Fbyte_code):
* bytecode.c (vars_of_bytecode):
* bytecode.c (init_opcode_table_multi_op):
* bytecode.c (reinit_vars_of_bytecode):
* emacs.c (main_1):
* eval.c (funcall_compiled_function):
* symsinit.h:
Any time we change either the instruction pointer or the stack
pointer, assert that we're going to move it to a valid location.
This should catch failures right when they occur rather than
sometime later. This requires that we pass in another couple of
parameters into some functions (only with error-checking enabled,
see below).
Also keep track, using a circular queue, of the last 100 byte
opcodes seen, and when we hit an assert failure during byte-code
execution, output the contents of the queue in a nice readable
fashion. This requires that bytecode-ops.h be included a second
time so that a table mapping opcodes to the name of their operation
can be constructed. This table is constructed in new function
reinit_vars_of_bytecode().
Everything in the last two paras happens only when
ERROR_CHECK_BYTE_CODE.
Add some longish comments describing how the arrays that hold the
stack and instructions, and the pointers used to access them, work.
* gc.c:
Import some code from my `latest-fix' workspace to mark the
staticpro's in order from lowest to highest, rather than highest to
lowest, so it's easier to debug when something goes wrong.
* lisp.h (abort_with_message): Renamed from abort_with_msg().
* symbols.c (defsymbol_massage_name_1):
* symbols.c (defsymbol_nodump):
* symbols.c (defsymbol):
* symbols.c (defkeyword):
* symeval.h (DEFVAR_SYMVAL_FWD_OBJECT):
Make the various calls to staticpro() instead call staticpro_1(),
passing in the name of the C var being staticpro'ed, so that it
shows up in staticpro_names. Otherwise staticpro_names just has
1000+ copies of the word `location'.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 03 Feb 2010 08:01:55 -0600 |
parents | 91b3d00e717f |
children | 8ee3c10d1ed5 |
rev | line source |
---|---|
428 | 1 /* Lisp parsing and input streams. |
2 Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Tinker Systems. | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
4 Copyright (C) 1996, 2001, 2002, 2003, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
24 | |
25 /* This file has been Mule-ized. */ | |
26 | |
27 #include <config.h> | |
28 #include "lisp.h" | |
29 | |
30 #include "buffer.h" | |
31 #include "bytecode.h" | |
32 #include "elhash.h" | |
1292 | 33 #include "file-coding.h" |
428 | 34 #include "lstream.h" |
35 #include "opaque.h" | |
1292 | 36 #include "profile.h" |
3439 | 37 #include "charset.h" /* For Funicode_to_char. */ |
428 | 38 |
39 #include "sysfile.h" | |
40 #include "sysfloat.h" | |
771 | 41 #ifdef WIN32_NATIVE |
42 #include "syswindows.h" | |
43 #endif | |
428 | 44 |
45 Lisp_Object Qread_char, Qstandard_input; | |
46 Lisp_Object Qvariable_documentation; | |
47 #define LISP_BACKQUOTES | |
48 #ifdef LISP_BACKQUOTES | |
49 /* | |
50 Nonzero means inside a new-style backquote | |
51 with no surrounding parentheses. | |
52 Fread initializes this to zero, so we need not specbind it | |
53 or worry about what happens to it when there is an error. | |
54 | |
55 XEmacs: | |
56 Nested backquotes are perfectly legal and fail utterly with | |
57 this silliness. */ | |
58 static int new_backquote_flag, old_backquote_flag; | |
59 Lisp_Object Qbackquote, Qbacktick, Qcomma, Qcomma_at, Qcomma_dot; | |
60 #endif | |
61 Lisp_Object Qvariable_domain; /* I18N3 */ | |
62 Lisp_Object Vvalues, Vstandard_input, Vafter_load_alist; | |
2548 | 63 Lisp_Object Vload_suppress_alist; |
64 Lisp_Object Qload, Qload_internal, Qfset; | |
428 | 65 |
66 /* Hash-table that maps directory names to hashes of their contents. */ | |
67 static Lisp_Object Vlocate_file_hash_table; | |
68 | |
69 Lisp_Object Qexists, Qreadable, Qwritable, Qexecutable; | |
70 | |
71 /* See read_escape() for an explanation of this. */ | |
72 #if 0 | |
73 int fail_on_bucky_bit_character_escapes; | |
74 #endif | |
75 | |
76 /* This symbol is also used in fns.c */ | |
77 #define FEATUREP_SYNTAX | |
78 | |
79 #ifdef FEATUREP_SYNTAX | |
80 Lisp_Object Qfeaturep; | |
81 #endif | |
82 | |
83 /* non-zero if inside `load' */ | |
84 int load_in_progress; | |
85 | |
86 /* Whether Fload_internal() should check whether the .el is newer | |
87 when loading .elc */ | |
88 int load_warn_when_source_newer; | |
89 /* Whether Fload_internal() should check whether the .elc doesn't exist */ | |
90 int load_warn_when_source_only; | |
91 /* Whether Fload_internal() should ignore .elc files when no suffix is given */ | |
92 int load_ignore_elc_files; | |
1123 | 93 /* Whether Fload_internal() should ignore out-of-date .elc files when no |
94 suffix is given */ | |
95 int load_ignore_out_of_date_elc_files; | |
96 /* Always display messages showing when a file is loaded, regardless of | |
97 whether the flag to `load' tries to suppress them. */ | |
98 int load_always_display_messages; | |
99 /* Show the full path in loading messages. */ | |
100 int load_show_full_path_in_messages; | |
428 | 101 |
102 /* Search path for files to be loaded. */ | |
103 Lisp_Object Vload_path; | |
104 | |
105 /* Search path for files when dumping. */ | |
106 /* Lisp_Object Vdump_load_path; */ | |
107 | |
108 /* This is the user-visible association list that maps features to | |
109 lists of defs in their load files. */ | |
110 Lisp_Object Vload_history; | |
111 | |
112 /* This is used to build the load history. */ | |
113 Lisp_Object Vcurrent_load_list; | |
114 | |
115 /* Name of file actually being read by `load'. */ | |
116 Lisp_Object Vload_file_name; | |
117 | |
118 /* Same as Vload_file_name but not Lisp-accessible. This ensures that | |
119 our #$ checks are reliable. */ | |
120 Lisp_Object Vload_file_name_internal; | |
121 | |
122 /* Function to use for reading, in `load' and friends. */ | |
123 Lisp_Object Vload_read_function; | |
124 | |
125 /* The association list of objects read with the #n=object form. | |
126 Each member of the list has the form (n . object), and is used to | |
127 look up the object for the corresponding #n# construct. | |
128 It must be set to nil before all top-level calls to read0. */ | |
129 Lisp_Object Vread_objects; | |
130 | |
131 /* Nonzero means load should forcibly load all dynamic doc strings. */ | |
132 /* Note that this always happens (with some special behavior) when | |
133 purify_flag is set. */ | |
134 static int load_force_doc_strings; | |
135 | |
136 /* List of descriptors now open for Fload_internal. */ | |
137 static Lisp_Object Vload_descriptor_list; | |
138 | |
139 /* In order to implement "load_force_doc_strings", we keep | |
140 a list of all the compiled-function objects and such | |
141 that we have created in the process of loading this file. | |
142 See the rant below. | |
143 | |
144 We specbind this just like Vload_file_name, so there's no | |
145 problems with recursive loading. */ | |
146 static Lisp_Object Vload_force_doc_string_list; | |
147 | |
148 /* A resizing-buffer stream used to temporarily hold data while reading */ | |
149 static Lisp_Object Vread_buffer_stream; | |
150 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
151 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
152 /* The stuff throughout this file that sets the following variable is |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
153 concerned with old-style .elc files that set up compiled functions using |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
154 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
155 (fset 'fun #[... ...]) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
156 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
157 Where #[... ...] is a literal compiled-function object. We want the |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
158 name of the function to get stored as the annotation, so in a clever but |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
159 nastily kludgy fashion, we hack the code that reads lists so that if it |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
160 sees a symbol `fset' as the first argument, it stores the second argument |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
161 in Vcurrent_compiled_function_annotation, and then when the third |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
162 argument gets read and a compiled-function object created by a call to |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
163 Fmake_byte_code(), the stored annotation will get snarfed up. Elsewhere, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
164 we reset Vcurrent_compiled_function_annotation to nil so it's not still |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
165 defined in case we have a #[... ...] in other circumstances -- in that |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
166 case we use the filename (Vload_file_name_internal). |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
167 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
168 Now it's arguable that I should simply have hacked Ffset() |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
169 appropriately. This is all moot, however, be nowadays calls that set up |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
170 compiled functions look like |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
171 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
172 (defalias 'fun #[... ...]) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
173 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
174 Where Fdefalias is like Ffset but sets up load-history for the function. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
175 Hence it's exactly the right place to hack, and it's not even messy. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
176 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
177 When we're sure the annotation mechanism works the new way, delete all |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
178 this old nasty code. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
179 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
180 --ben 2-2-10 */ |
428 | 181 Lisp_Object Vcurrent_compiled_function_annotation; |
182 #endif | |
183 | |
184 static int load_byte_code_version; | |
185 | |
186 /* An array describing all known built-in structure types */ | |
187 static structure_type_dynarr *the_structure_type_dynarr; | |
188 | |
189 #if 0 /* FSF stuff */ | |
190 /* For use within read-from-string (this reader is non-reentrant!!) */ | |
191 static int read_from_string_index; | |
192 static int read_from_string_limit; | |
193 #endif | |
194 | |
195 #if 0 /* More FSF implementation kludges. */ | |
196 /* In order to implement load-force-doc-string, FSF saves the | |
197 #@-quoted string when it's seen, and goes back and retrieves | |
198 it later. | |
199 | |
200 This approach is not only kludgy, but it in general won't work | |
201 correctly because there's no stack of remembered #@-quoted-strings | |
202 and those strings don't generally appear in the file in the same | |
203 order as their #$ references. (Yes, that is amazingly stupid too. | |
204 | |
205 It would be trivially easy to always encode the #@ string | |
206 [which is a comment, anyway] in the middle of the (#$ . INT) cons | |
207 reference. That way, it would be really easy to implement | |
208 load-force-doc-string in a non-kludgy way by just retrieving the | |
209 string immediately, because it's delivered on a silver platter.) | |
210 | |
211 And finally, this stupid approach doesn't work under Mule, or | |
212 under MS-DOS or Windows NT, or under VMS, or any other place | |
213 where you either can't do an ftell() or don't get back a byte | |
214 count. | |
215 | |
216 Oh, and one more lossage in this approach: If you attempt to | |
217 dump any ELC files that were compiled with `byte-compile-dynamic' | |
218 (as opposed to just `byte-compile-dynamic-docstring'), you | |
219 get hosed. FMH! (as the illustrious JWZ was prone to utter) | |
220 | |
221 The approach we use is clean, solves all of these problems, and is | |
222 probably easier to implement anyway. We just save a list of all | |
223 the containing objects that have (#$ . INT) conses in them (this | |
224 will only be compiled-function objects and lists), and when the | |
225 file is finished loading, we go through and fill in all the | |
814 | 226 doc strings at once. --ben */ |
428 | 227 |
228 /* This contains the last string skipped with #@. */ | |
229 static char *saved_doc_string; | |
230 /* Length of buffer allocated in saved_doc_string. */ | |
231 static int saved_doc_string_size; | |
232 /* Length of actual data in saved_doc_string. */ | |
233 static int saved_doc_string_length; | |
234 /* This is the file position that string came from. */ | |
235 static int saved_doc_string_position; | |
236 #endif | |
237 | |
1123 | 238 static int locate_file_open_or_access_file (Ibyte *fn, int access_mode); |
428 | 239 EXFUN (Fread_from_string, 3); |
240 | |
241 /* When errors are signaled, the actual readcharfun should not be used | |
242 as an argument if it is an lstream, so that lstreams don't escape | |
243 to the Lisp level. */ | |
1261 | 244 #define READCHARFUN_MAYBE(x) (LSTREAMP (x) \ |
245 ? (build_msg_string ("internal input stream")) \ | |
428 | 246 : (x)) |
247 | |
248 | |
2268 | 249 static DECLARE_DOESNT_RETURN (read_syntax_error (const char *)); |
250 | |
428 | 251 static DOESNT_RETURN |
442 | 252 read_syntax_error (const char *string) |
428 | 253 { |
563 | 254 signal_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 255 } |
256 | |
257 static Lisp_Object | |
442 | 258 continuable_read_syntax_error (const char *string) |
428 | 259 { |
563 | 260 return signal_continuable_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 261 } |
262 | |
263 | |
264 /* Handle unreading and rereading of characters. */ | |
867 | 265 static Ichar |
428 | 266 readchar (Lisp_Object readcharfun) |
267 { | |
268 /* This function can GC */ | |
269 | |
270 if (BUFFERP (readcharfun)) | |
271 { | |
867 | 272 Ichar c; |
428 | 273 struct buffer *b = XBUFFER (readcharfun); |
274 | |
275 if (!BUFFER_LIVE_P (b)) | |
563 | 276 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 277 |
278 if (BUF_PT (b) >= BUF_ZV (b)) | |
279 return -1; | |
280 c = BUF_FETCH_CHAR (b, BUF_PT (b)); | |
281 BUF_SET_PT (b, BUF_PT (b) + 1); | |
282 | |
283 return c; | |
284 } | |
285 else if (LSTREAMP (readcharfun)) | |
286 { | |
867 | 287 Ichar c = Lstream_get_ichar (XLSTREAM (readcharfun)); |
428 | 288 #ifdef DEBUG_XEMACS /* testing Mule */ |
289 static int testing_mule = 0; /* Change via debugger */ | |
444 | 290 if (testing_mule) |
291 { | |
292 if (c >= 0x20 && c <= 0x7E) stderr_out ("%c", c); | |
293 else if (c == '\n') stderr_out ("\\n\n"); | |
294 else stderr_out ("\\%o ", c); | |
295 } | |
296 #endif /* testing Mule */ | |
428 | 297 return c; |
298 } | |
299 else if (MARKERP (readcharfun)) | |
300 { | |
867 | 301 Ichar c; |
665 | 302 Charbpos mpos = marker_position (readcharfun); |
428 | 303 struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
304 | |
305 if (mpos >= BUF_ZV (inbuffer)) | |
306 return -1; | |
307 c = BUF_FETCH_CHAR (inbuffer, mpos); | |
308 set_marker_position (readcharfun, mpos + 1); | |
309 return c; | |
310 } | |
311 else | |
312 { | |
313 Lisp_Object tem = call0 (readcharfun); | |
314 | |
315 if (!CHAR_OR_CHAR_INTP (tem)) | |
316 return -1; | |
317 return XCHAR_OR_CHAR_INT (tem); | |
318 } | |
319 } | |
320 | |
321 /* Unread the character C in the way appropriate for the stream READCHARFUN. | |
322 If the stream is a user function, call it with the char as argument. */ | |
323 | |
324 static void | |
867 | 325 unreadchar (Lisp_Object readcharfun, Ichar c) |
428 | 326 { |
327 if (c == -1) | |
328 /* Don't back up the pointer if we're unreading the end-of-input mark, | |
329 since readchar didn't advance it when we read it. */ | |
330 ; | |
331 else if (BUFFERP (readcharfun)) | |
332 BUF_SET_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1); | |
333 else if (LSTREAMP (readcharfun)) | |
334 { | |
867 | 335 Lstream_unget_ichar (XLSTREAM (readcharfun), c); |
428 | 336 #ifdef DEBUG_XEMACS /* testing Mule */ |
337 { | |
338 static int testing_mule = 0; /* Set this using debugger */ | |
339 if (testing_mule) | |
340 fprintf (stderr, | |
341 (c >= 0x20 && c <= 0x7E) ? "UU%c" : | |
342 ((c == '\n') ? "UU\\n\n" : "UU\\%o"), c); | |
343 } | |
344 #endif | |
345 } | |
346 else if (MARKERP (readcharfun)) | |
347 set_marker_position (readcharfun, marker_position (readcharfun) - 1); | |
348 else | |
349 call1 (readcharfun, make_char (c)); | |
350 } | |
351 | |
352 static Lisp_Object read0 (Lisp_Object readcharfun); | |
353 static Lisp_Object read1 (Lisp_Object readcharfun); | |
354 static Lisp_Object read_list (Lisp_Object readcharfun, | |
867 | 355 Ichar terminator, |
428 | 356 int allow_dotted_lists, |
357 int check_for_doc_references); | |
358 | |
359 static void readevalloop (Lisp_Object readcharfun, | |
360 Lisp_Object sourcefile, | |
361 Lisp_Object (*evalfun) (Lisp_Object), | |
362 int printflag); | |
363 | |
364 static Lisp_Object | |
365 load_unwind (Lisp_Object stream) /* used as unwind-protect function in load */ | |
366 { | |
367 Lstream_close (XLSTREAM (stream)); | |
368 return Qnil; | |
369 } | |
370 | |
2548 | 371 /* Check if NONRELOC/RELOC (an absolute filename) is suppressed according |
372 to load-suppress-alist. */ | |
373 static int | |
374 check_if_suppressed (Ibyte *nonreloc, Lisp_Object reloc) | |
375 { | |
376 Bytecount len; | |
377 | |
378 if (!NILP (reloc)) | |
379 { | |
380 nonreloc = XSTRING_DATA (reloc); | |
381 len = XSTRING_LENGTH (reloc); | |
382 } | |
383 else | |
384 len = qxestrlen (nonreloc); | |
385 | |
386 if (len >= 4 && !qxestrcmp_ascii (nonreloc + len - 4, ".elc")) | |
387 len -= 4; | |
388 else if (len >= 3 && !qxestrcmp_ascii (nonreloc + len - 3, ".el")) | |
389 len -= 3; | |
390 | |
2567 | 391 { |
392 EXTERNAL_LIST_LOOP_2 (acons, Vload_suppress_alist) | |
393 { | |
394 if (CONSP (acons) && STRINGP (XCAR (acons))) | |
395 { | |
396 Lisp_Object name = XCAR (acons); | |
397 if (XSTRING_LENGTH (name) == len && | |
398 !memcmp (XSTRING_DATA (name), nonreloc, len)) | |
399 { | |
400 struct gcpro gcpro1; | |
401 Lisp_Object val; | |
402 | |
403 GCPRO1 (reloc); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4608
diff
changeset
|
404 val = IGNORE_MULTIPLE_VALUES (Feval (XCDR (acons))); |
2567 | 405 UNGCPRO; |
406 | |
407 if (!NILP (val)) | |
408 return 1; | |
409 } | |
410 } | |
411 } | |
412 } | |
2548 | 413 |
414 return 0; | |
415 } | |
416 | |
428 | 417 /* The plague is coming. |
418 | |
419 Ring around the rosy, pocket full of posy, | |
420 Ashes ashes, they all fall down. | |
421 */ | |
422 void | |
423 ebolify_bytecode_constants (Lisp_Object vector) | |
424 { | |
425 int len = XVECTOR_LENGTH (vector); | |
426 int i; | |
427 | |
428 for (i = 0; i < len; i++) | |
429 { | |
430 Lisp_Object el = XVECTOR_DATA (vector)[i]; | |
431 | |
432 /* We don't check for `eq', `equal', and the others that have | |
433 bytecode opcodes. This might lose if someone passes #'eq or | |
434 something to `funcall', but who would really do that? As | |
435 they say in law, we've made a "good-faith effort" to | |
436 unfuckify ourselves. And doing it this way avoids screwing | |
437 up args to `make-hash-table' and such. As it is, we have to | |
438 add an extra Ebola check in decode_weak_list_type(). --ben */ | |
439 if (EQ (el, Qassoc)) el = Qold_assoc; | |
440 else if (EQ (el, Qdelq)) el = Qold_delq; | |
441 #if 0 | |
442 /* I think this is a bad idea because it will probably mess | |
443 with keymap code. */ | |
444 else if (EQ (el, Qdelete)) el = Qold_delete; | |
445 #endif | |
446 else if (EQ (el, Qrassq)) el = Qold_rassq; | |
447 else if (EQ (el, Qrassoc)) el = Qold_rassoc; | |
448 | |
449 XVECTOR_DATA (vector)[i] = el; | |
450 } | |
451 } | |
452 | |
453 static Lisp_Object | |
558 | 454 pas_de_holgazan_ici (int fd, Lisp_Object victim) |
428 | 455 { |
456 Lisp_Object tem; | |
457 EMACS_INT pos; | |
458 | |
459 if (!INTP (XCDR (victim))) | |
563 | 460 invalid_byte_code ("Bogus doc string reference", victim); |
428 | 461 pos = XINT (XCDR (victim)); |
462 if (pos < 0) | |
463 pos = -pos; /* kludge to mark a user variable */ | |
814 | 464 tem = unparesseuxify_doc_string (fd, pos, 0, Vload_file_name_internal, 0); |
428 | 465 if (!STRINGP (tem)) |
563 | 466 signal_error_1 (Qinvalid_byte_code, tem); |
428 | 467 return tem; |
468 } | |
469 | |
470 static Lisp_Object | |
471 load_force_doc_string_unwind (Lisp_Object oldlist) | |
472 { | |
473 struct gcpro gcpro1; | |
474 Lisp_Object list = Vload_force_doc_string_list; | |
475 Lisp_Object tail; | |
476 int fd = XINT (XCAR (Vload_descriptor_list)); | |
477 | |
478 GCPRO1 (list); | |
479 /* restore the old value first just in case an error occurs. */ | |
480 Vload_force_doc_string_list = oldlist; | |
481 | |
482 LIST_LOOP (tail, list) | |
483 { | |
484 Lisp_Object john = Fcar (tail); | |
485 if (CONSP (john)) | |
486 { | |
487 assert (CONSP (XCAR (john))); | |
488 assert (!purify_flag); /* should have been handled in read_list() */ | |
558 | 489 XCAR (john) = pas_de_holgazan_ici (fd, XCAR (john)); |
428 | 490 } |
491 else | |
492 { | |
493 Lisp_Object doc; | |
494 | |
495 assert (COMPILED_FUNCTIONP (john)); | |
496 if (CONSP (XCOMPILED_FUNCTION (john)->instructions)) | |
497 { | |
498 struct gcpro ngcpro1; | |
558 | 499 Lisp_Object juan = (pas_de_holgazan_ici |
814 | 500 (fd, |
501 XCOMPILED_FUNCTION (john)->instructions)); | |
428 | 502 Lisp_Object ivan; |
503 | |
504 NGCPRO1 (juan); | |
505 ivan = Fread (juan); | |
506 if (!CONSP (ivan)) | |
563 | 507 invalid_byte_code ("invalid lazy-loaded byte code", ivan); |
428 | 508 XCOMPILED_FUNCTION (john)->instructions = XCAR (ivan); |
509 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
510 if (XCOMPILED_FUNCTION (john)->flags.ebolified | |
511 && VECTORP (XCDR (ivan))) | |
512 ebolify_bytecode_constants (XCDR (ivan)); | |
513 XCOMPILED_FUNCTION (john)->constants = XCDR (ivan); | |
514 NUNGCPRO; | |
515 } | |
516 doc = compiled_function_documentation (XCOMPILED_FUNCTION (john)); | |
517 if (CONSP (doc)) | |
518 { | |
519 assert (!purify_flag); /* should have been handled in | |
520 read_compiled_function() */ | |
558 | 521 doc = pas_de_holgazan_ici (fd, doc); |
428 | 522 set_compiled_function_documentation (XCOMPILED_FUNCTION (john), |
523 doc); | |
524 } | |
525 } | |
526 } | |
527 | |
528 if (!NILP (list)) | |
529 free_list (list); | |
530 | |
531 UNGCPRO; | |
532 return Qnil; | |
533 } | |
534 | |
535 /* Close all descriptors in use for Fload_internal. | |
536 This is used when starting a subprocess. */ | |
537 | |
538 void | |
539 close_load_descs (void) | |
540 { | |
541 Lisp_Object tail; | |
542 LIST_LOOP (tail, Vload_descriptor_list) | |
771 | 543 retry_close (XINT (XCAR (tail))); |
428 | 544 } |
545 | |
546 #ifdef I18N3 | |
547 Lisp_Object Vfile_domain; | |
548 #endif /* I18N3 */ | |
549 | |
550 DEFUN ("load-internal", Fload_internal, 1, 6, 0, /* | |
551 Execute a file of Lisp code named FILE; no coding-system frobbing. | |
552 This function is identical to `load' except for the handling of the | |
553 CODESYS and USED-CODESYS arguments under XEmacs/Mule. (When Mule | |
554 support is not present, both functions are identical and ignore the | |
555 CODESYS and USED-CODESYS arguments.) | |
556 | |
557 If support for Mule exists in this Emacs, the file is decoded | |
558 according to CODESYS; if omitted, no conversion happens. If | |
559 USED-CODESYS is non-nil, it should be a symbol, and the actual coding | |
560 system that was used for the decoding is stored into it. It will in | |
561 general be different from CODESYS if CODESYS specifies automatic | |
562 encoding detection or end-of-line detection. | |
563 */ | |
444 | 564 (file, noerror, nomessage, nosuffix, codesys, used_codesys)) |
428 | 565 { |
566 /* This function can GC */ | |
567 int fd = -1; | |
568 int speccount = specpdl_depth (); | |
569 int source_only = 0; | |
1123 | 570 /* NEWER and OLDER are filenames w/o directory, used in loading messages |
571 to e.g. warn of newer .el files when the .elc is being loaded. */ | |
428 | 572 Lisp_Object newer = Qnil; |
1123 | 573 Lisp_Object older = Qnil; |
428 | 574 Lisp_Object handler = Qnil; |
575 Lisp_Object found = Qnil; | |
1292 | 576 Lisp_Object retval; |
1123 | 577 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
428 | 578 int reading_elc = 0; |
780 | 579 int from_require = EQ (nomessage, Qrequire); |
1261 | 580 int message_p = NILP (nomessage) || load_always_display_messages; |
428 | 581 struct stat s1, s2; |
1261 | 582 Ibyte *spaces = alloca_ibytes (load_in_progress * 2 + 10); |
583 int i; | |
1292 | 584 PROFILE_DECLARE (); |
428 | 585 |
1266 | 586 GCPRO4 (file, newer, older, found); |
428 | 587 CHECK_STRING (file); |
588 | |
1292 | 589 PROFILE_RECORD_ENTERING_SECTION (Qload_internal); |
590 | |
428 | 591 /* If file name is magic, call the handler. */ |
592 handler = Ffind_file_name_handler (file, Qload); | |
593 if (!NILP (handler)) | |
1292 | 594 { |
595 retval = call5 (handler, Qload, file, noerror, nomessage, nosuffix); | |
596 goto done; | |
597 } | |
428 | 598 |
599 /* Do this after the handler to avoid | |
600 the need to gcpro noerror, nomessage and nosuffix. | |
601 (Below here, we care only whether they are nil or not.) */ | |
602 file = Fsubstitute_in_file_name (file); | |
603 if (!NILP (used_codesys)) | |
604 CHECK_SYMBOL (used_codesys); | |
605 | |
1261 | 606 if (noninteractive) |
607 { | |
608 for (i = 0; i < load_in_progress * 2; i++) | |
609 spaces[i] = ' '; | |
610 spaces[i] = '\0'; | |
611 } | |
612 else | |
613 spaces[0] = '\0'; | |
614 | |
428 | 615 /* Avoid weird lossage with null string as arg, |
616 since it would try to load a directory as a Lisp file. | |
617 Unix truly sucks. */ | |
618 if (XSTRING_LENGTH (file) > 0) | |
619 { | |
867 | 620 Ibyte *foundstr; |
428 | 621 int foundlen; |
622 | |
623 fd = locate_file (Vload_path, file, | |
624 ((!NILP (nosuffix)) ? Qnil : | |
625 build_string (load_ignore_elc_files ? ".el:" : | |
626 ".elc:.el:")), | |
627 &found, | |
628 -1); | |
629 | |
630 if (fd < 0) | |
631 { | |
444 | 632 if (NILP (noerror)) |
563 | 633 signal_error (Qfile_error, "Cannot open load file", file); |
428 | 634 else |
635 { | |
1292 | 636 retval = Qnil; |
637 goto done; | |
428 | 638 } |
639 } | |
640 | |
2367 | 641 foundstr = alloca_ibytes (XSTRING_LENGTH (found) + 1); |
771 | 642 qxestrcpy (foundstr, XSTRING_DATA (found)); |
643 foundlen = qxestrlen (foundstr); | |
428 | 644 |
645 /* The omniscient JWZ thinks this is worthless, but I beg to | |
646 differ. --ben */ | |
647 if (load_ignore_elc_files) | |
1123 | 648 newer = Ffile_name_nondirectory (found); |
649 else if ((load_warn_when_source_newer || | |
650 load_ignore_out_of_date_elc_files) && | |
428 | 651 !memcmp (".elc", foundstr + foundlen - 4, 4)) |
652 { | |
771 | 653 if (! qxe_fstat (fd, &s1)) /* can't fail, right? */ |
428 | 654 { |
655 int result; | |
656 /* temporarily hack the 'c' off the end of the filename */ | |
657 foundstr[foundlen - 1] = '\0'; | |
771 | 658 result = qxe_stat (foundstr, &s2); |
428 | 659 if (result >= 0 && |
660 (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | |
1123 | 661 { |
662 /* .elc exists and is out-of-date wrt .el */ | |
663 Lisp_Object el_name = make_string (foundstr, foundlen - 1); | |
664 struct gcpro nngcpro1; | |
665 NNGCPRO1 (el_name); | |
666 newer = Ffile_name_nondirectory (el_name); | |
667 if (load_ignore_out_of_date_elc_files) | |
668 { | |
669 int newfd = | |
670 locate_file_open_or_access_file | |
671 (XSTRING_DATA (el_name), -1); | |
672 | |
673 if (newfd >= 0) | |
674 { | |
675 older = Ffile_name_nondirectory (found); | |
676 found = el_name; | |
677 retry_close (fd); | |
678 fd = newfd; | |
679 } | |
680 } | |
681 NNUNGCPRO; | |
682 } | |
428 | 683 /* put the 'c' back on (kludge-o-rama) */ |
684 foundstr[foundlen - 1] = 'c'; | |
685 } | |
686 } | |
687 else if (load_warn_when_source_only && | |
688 /* `found' ends in ".el" */ | |
689 !memcmp (".el", foundstr + foundlen - 3, 3) && | |
690 /* `file' does not end in ".el" */ | |
691 memcmp (".el", | |
692 XSTRING_DATA (file) + XSTRING_LENGTH (file) - 3, | |
693 3)) | |
1123 | 694 source_only = 1; |
428 | 695 |
696 if (!memcmp (".elc", foundstr + foundlen - 4, 4)) | |
697 reading_elc = 1; | |
698 } | |
699 | |
1123 | 700 #define PRINT_LOADING_MESSAGE_1(loading, done) \ |
701 do { \ | |
702 if (load_ignore_elc_files) \ | |
703 { \ | |
704 if (message_p) \ | |
1261 | 705 message (loading done, spaces, \ |
1123 | 706 XSTRING_DATA (load_show_full_path_in_messages ? \ |
707 found : newer)); \ | |
708 } \ | |
709 else if (!NILP (older)) \ | |
710 { \ | |
711 assert (load_ignore_out_of_date_elc_files); \ | |
1261 | 712 message (loading done " (file %s is out-of-date)", spaces, \ |
1123 | 713 XSTRING_DATA (load_show_full_path_in_messages ? \ |
714 found : newer), \ | |
715 XSTRING_DATA (older)); \ | |
716 } \ | |
717 else if (!NILP (newer)) \ | |
1261 | 718 message (loading done " (file %s is newer)", spaces, \ |
1123 | 719 XSTRING_DATA (load_show_full_path_in_messages ? \ |
720 found : file), \ | |
721 XSTRING_DATA (newer)); \ | |
722 else if (source_only) \ | |
1261 | 723 message (loading done " (file %s.elc does not exist)", spaces, \ |
1123 | 724 XSTRING_DATA (load_show_full_path_in_messages ? \ |
725 found : file), \ | |
726 XSTRING_DATA (Ffile_name_nondirectory (file))); \ | |
727 else if (message_p) \ | |
1261 | 728 message (loading done, spaces, \ |
1123 | 729 XSTRING_DATA (load_show_full_path_in_messages ? \ |
730 found : file)); \ | |
428 | 731 } while (0) |
732 | |
1261 | 733 #define PRINT_LOADING_MESSAGE(done) \ |
734 do { \ | |
735 if (from_require) \ | |
736 PRINT_LOADING_MESSAGE_1 ("%sRequiring %s...", done); \ | |
737 else \ | |
738 PRINT_LOADING_MESSAGE_1 ("%sLoading %s...", done); \ | |
780 | 739 } while (0) |
740 | |
428 | 741 PRINT_LOADING_MESSAGE (""); |
742 | |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
743 LISP_READONLY (found) = 1; |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
744 |
428 | 745 { |
746 /* Lisp_Object's must be malloc'ed, not stack-allocated */ | |
747 Lisp_Object lispstream = Qnil; | |
442 | 748 const int block_size = 8192; |
428 | 749 struct gcpro ngcpro1; |
750 | |
751 NGCPRO1 (lispstream); | |
752 lispstream = make_filedesc_input_stream (fd, 0, -1, LSTR_CLOSING); | |
753 /* 64K is used for normal files; 8K should be OK here because Lisp | |
754 files aren't really all that big. */ | |
755 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, | |
756 block_size); | |
771 | 757 lispstream = make_coding_input_stream |
758 (XLSTREAM (lispstream), get_coding_system_for_text_file (codesys, 1), | |
800 | 759 CODING_DECODE, 0); |
428 | 760 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, |
761 block_size); | |
762 /* NOTE: Order of these is very important. Don't rearrange them. */ | |
853 | 763 internal_bind_int (&load_in_progress, 1 + load_in_progress); |
428 | 764 record_unwind_protect (load_unwind, lispstream); |
853 | 765 internal_bind_lisp_object (&Vload_descriptor_list, |
766 Fcons (make_int (fd), Vload_descriptor_list)); | |
767 internal_bind_lisp_object (&Vload_file_name_internal, found); | |
768 /* this is not a simple internal_bind. */ | |
428 | 769 record_unwind_protect (load_force_doc_string_unwind, |
770 Vload_force_doc_string_list); | |
853 | 771 Vload_force_doc_string_list = Qnil; |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
772 /* load-file-name is not read-only to Lisp. */ |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
773 internal_bind_lisp_object (&Vload_file_name, Fcopy_sequence(found)); |
428 | 774 #ifdef I18N3 |
853 | 775 /* set it to nil; a call to #'domain will set it. */ |
776 internal_bind_lisp_object (&Vfile_domain, Qnil); | |
428 | 777 #endif |
778 | |
4448
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
779 /* Is there a #!? If so, read it, and unread ;!. |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
780 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
781 GNU implement this by treating any #! anywhere in the source text as |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
782 commenting out the whole line. */ |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
783 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
784 char shebangp[2]; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
785 int num_read; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
786 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
787 num_read = Lstream_read (XLSTREAM (lispstream), shebangp, |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
788 sizeof(shebangp)); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
789 if (sizeof(shebangp) == num_read |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
790 && 0 == strncmp("#!", shebangp, sizeof(shebangp))) |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
791 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
792 shebangp[0] = ';'; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
793 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
794 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
795 Lstream_unread (XLSTREAM (lispstream), shebangp, num_read); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
796 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
797 |
428 | 798 /* Now determine what sort of ELC file we're reading in. */ |
853 | 799 internal_bind_int (&load_byte_code_version, load_byte_code_version); |
428 | 800 if (reading_elc) |
801 { | |
802 char elc_header[8]; | |
803 int num_read; | |
804 | |
805 num_read = Lstream_read (XLSTREAM (lispstream), elc_header, 8); | |
806 if (num_read < 8 | |
807 || strncmp (elc_header, ";ELC", 4)) | |
808 { | |
809 /* Huh? Probably not a valid ELC file. */ | |
810 load_byte_code_version = 100; /* no Ebolification needed */ | |
811 Lstream_unread (XLSTREAM (lispstream), elc_header, num_read); | |
812 } | |
813 else | |
814 load_byte_code_version = elc_header[4]; | |
815 } | |
816 else | |
817 load_byte_code_version = 100; /* no Ebolification needed */ | |
818 | |
819 readevalloop (lispstream, file, Feval, 0); | |
820 if (!NILP (used_codesys)) | |
821 Fset (used_codesys, | |
822 XCODING_SYSTEM_NAME | |
771 | 823 (coding_stream_detected_coding_system (XLSTREAM (lispstream)))); |
824 unbind_to (speccount); | |
428 | 825 |
826 NUNGCPRO; | |
827 } | |
828 | |
829 { | |
830 Lisp_Object tem; | |
831 /* #### Disgusting kludge */ | |
832 /* Run any load-hooks for this file. */ | |
833 /* #### An even more disgusting kludge. There is horrible code */ | |
834 /* that is relying on the fact that dumped lisp files are found */ | |
835 /* via `load-path' search. */ | |
836 Lisp_Object name = file; | |
837 | |
1123 | 838 if (!NILP (Ffile_name_absolute_p (file))) |
839 name = Ffile_name_nondirectory (file); | |
428 | 840 |
1261 | 841 tem = Fassoc (name, Vafter_load_alist); |
428 | 842 if (!NILP (tem)) |
843 { | |
844 struct gcpro ngcpro1; | |
845 | |
846 NGCPRO1 (tem); | |
847 /* Use eval so that errors give a semi-meaningful backtrace. --Stig */ | |
848 tem = Fcons (Qprogn, Fcdr (tem)); | |
849 Feval (tem); | |
850 NUNGCPRO; | |
851 } | |
852 } | |
853 | |
854 if (!noninteractive) | |
855 PRINT_LOADING_MESSAGE ("done"); | |
856 | |
1292 | 857 retval = Qt; |
858 done: | |
859 PROFILE_RECORD_EXITING_SECTION (Qload_internal); | |
428 | 860 UNGCPRO; |
1292 | 861 return retval; |
428 | 862 } |
863 | |
864 | |
865 /* ------------------------------- */ | |
866 /* locate_file */ | |
867 /* ------------------------------- */ | |
868 | |
869 static int | |
870 decode_mode_1 (Lisp_Object mode) | |
871 { | |
872 if (EQ (mode, Qexists)) | |
873 return F_OK; | |
874 else if (EQ (mode, Qexecutable)) | |
875 return X_OK; | |
876 else if (EQ (mode, Qwritable)) | |
877 return W_OK; | |
878 else if (EQ (mode, Qreadable)) | |
879 return R_OK; | |
880 else if (INTP (mode)) | |
881 { | |
882 check_int_range (XINT (mode), 0, 7); | |
883 return XINT (mode); | |
884 } | |
885 else | |
563 | 886 invalid_argument ("Invalid value", mode); |
428 | 887 return 0; /* unreached */ |
888 } | |
889 | |
890 static int | |
891 decode_mode (Lisp_Object mode) | |
892 { | |
893 if (NILP (mode)) | |
894 return R_OK; | |
895 else if (CONSP (mode)) | |
896 { | |
897 int mask = 0; | |
2367 | 898 EXTERNAL_LIST_LOOP_2 (elt, mode) |
899 mask |= decode_mode_1 (elt); | |
428 | 900 return mask; |
901 } | |
902 else | |
903 return decode_mode_1 (mode); | |
904 } | |
905 | |
906 DEFUN ("locate-file", Flocate_file, 2, 4, 0, /* | |
907 Search for FILENAME through PATH-LIST. | |
908 | |
909 If SUFFIXES is non-nil, it should be a list of suffixes to append to | |
910 file name when searching. | |
911 | |
912 If MODE is non-nil, it should be a symbol or a list of symbol representing | |
913 requirements. Allowed symbols are `exists', `executable', `writable', and | |
914 `readable'. If MODE is nil, it defaults to `readable'. | |
915 | |
2548 | 916 Filenames are checked against `load-suppress-alist' to determine if they |
917 should be ignored. | |
918 | |
428 | 919 `locate-file' keeps hash tables of the directories it searches through, |
920 in order to speed things up. It tries valiantly to not get confused in | |
921 the face of a changing and unpredictable environment, but can occasionally | |
922 get tripped up. In this case, you will have to call | |
923 `locate-file-clear-hashing' to get it back on track. See that function | |
924 for details. | |
925 */ | |
926 (filename, path_list, suffixes, mode)) | |
927 { | |
928 /* This function can GC */ | |
929 Lisp_Object tp; | |
930 | |
931 CHECK_STRING (filename); | |
932 | |
933 if (LISTP (suffixes)) | |
934 { | |
2367 | 935 EXTERNAL_LIST_LOOP_2 (elt, suffixes) |
936 CHECK_STRING (elt); | |
428 | 937 } |
938 else | |
939 CHECK_STRING (suffixes); | |
940 | |
941 locate_file (path_list, filename, suffixes, &tp, decode_mode (mode)); | |
942 return tp; | |
943 } | |
944 | |
945 /* Recalculate the hash table for the given string. DIRECTORY should | |
946 better have been through Fexpand_file_name() by now. */ | |
947 | |
948 static Lisp_Object | |
949 locate_file_refresh_hashing (Lisp_Object directory) | |
950 { | |
951 Lisp_Object hash = | |
771 | 952 make_directory_hash_table (XSTRING_DATA (directory)); |
428 | 953 |
954 if (!NILP (hash)) | |
955 Fputhash (directory, hash, Vlocate_file_hash_table); | |
956 return hash; | |
957 } | |
958 | |
959 /* find the hash table for the given directory, recalculating if necessary */ | |
960 | |
961 static Lisp_Object | |
962 locate_file_find_directory_hash_table (Lisp_Object directory) | |
963 { | |
964 Lisp_Object hash = Fgethash (directory, Vlocate_file_hash_table, Qnil); | |
965 if (NILP (hash)) | |
966 return locate_file_refresh_hashing (directory); | |
967 else | |
968 return hash; | |
969 } | |
970 | |
971 /* The SUFFIXES argument in any of the locate_file* functions can be | |
972 nil, a list, or a string (for backward compatibility), with the | |
973 following semantics: | |
974 | |
975 a) nil - no suffix, just search for file name intact | |
976 (semantically different from "empty suffix list", which | |
977 would be meaningless.) | |
978 b) list - list of suffixes to append to file name. Each of these | |
979 must be a string. | |
980 c) string - colon-separated suffixes to append to file name (backward | |
981 compatibility). | |
982 | |
983 All of this got hairy, so I decided to use a mapper. Calling a | |
984 function for each suffix shouldn't slow things down, since | |
985 locate_file is rarely called with enough suffixes for funcalls to | |
986 make any difference. */ | |
987 | |
988 /* Map FUN over SUFFIXES, as described above. FUN will be called with a | |
989 char * containing the current file name, and ARG. Mapping stops when | |
990 FUN returns non-zero. */ | |
991 static void | |
992 locate_file_map_suffixes (Lisp_Object filename, Lisp_Object suffixes, | |
867 | 993 int (*fun) (Ibyte *, void *), |
428 | 994 void *arg) |
995 { | |
996 /* This function can GC */ | |
867 | 997 Ibyte *fn; |
428 | 998 int fn_len, max; |
999 | |
1000 /* Calculate maximum size of any filename made from | |
1001 this path element/specified file name and any possible suffix. */ | |
1002 if (CONSP (suffixes)) | |
1003 { | |
1004 /* We must traverse the list, so why not do it right. */ | |
1005 Lisp_Object tail; | |
1006 max = 0; | |
1007 LIST_LOOP (tail, suffixes) | |
1008 { | |
1009 if (XSTRING_LENGTH (XCAR (tail)) > max) | |
1010 max = XSTRING_LENGTH (XCAR (tail)); | |
1011 } | |
1012 } | |
1013 else if (NILP (suffixes)) | |
1014 max = 0; | |
1015 else | |
1016 /* Just take the easy way out */ | |
1017 max = XSTRING_LENGTH (suffixes); | |
1018 | |
1019 fn_len = XSTRING_LENGTH (filename); | |
2367 | 1020 fn = alloca_ibytes (max + fn_len + 1); |
771 | 1021 memcpy (fn, XSTRING_DATA (filename), fn_len); |
428 | 1022 |
1023 /* Loop over suffixes. */ | |
1024 if (!STRINGP (suffixes)) | |
1025 { | |
1026 if (NILP (suffixes)) | |
1027 { | |
1028 /* Case a) discussed in the comment above. */ | |
1029 fn[fn_len] = 0; | |
1030 if ((*fun) (fn, arg)) | |
1031 return; | |
1032 } | |
1033 else | |
1034 { | |
1035 /* Case b) */ | |
1036 Lisp_Object tail; | |
1037 LIST_LOOP (tail, suffixes) | |
1038 { | |
1039 memcpy (fn + fn_len, XSTRING_DATA (XCAR (tail)), | |
1040 XSTRING_LENGTH (XCAR (tail))); | |
1041 fn[fn_len + XSTRING_LENGTH (XCAR (tail))] = 0; | |
1042 if ((*fun) (fn, arg)) | |
1043 return; | |
1044 } | |
1045 } | |
1046 } | |
1047 else | |
1048 { | |
1049 /* Case c) */ | |
867 | 1050 const Ibyte *nsuffix = XSTRING_DATA (suffixes); |
428 | 1051 |
1052 while (1) | |
1053 { | |
867 | 1054 Ibyte *esuffix = qxestrchr (nsuffix, ':'); |
771 | 1055 Bytecount lsuffix = esuffix ? esuffix - nsuffix : |
1056 qxestrlen (nsuffix); | |
428 | 1057 |
1058 /* Concatenate path element/specified name with the suffix. */ | |
771 | 1059 qxestrncpy (fn + fn_len, nsuffix, lsuffix); |
428 | 1060 fn[fn_len + lsuffix] = 0; |
1061 | |
1062 if ((*fun) (fn, arg)) | |
1063 return; | |
1064 | |
1065 /* Advance to next suffix. */ | |
1066 if (esuffix == 0) | |
1067 break; | |
1068 nsuffix += lsuffix + 1; | |
1069 } | |
1070 } | |
1071 } | |
1072 | |
771 | 1073 struct locate_file_in_directory_mapper_closure |
1074 { | |
428 | 1075 int fd; |
1076 Lisp_Object *storeptr; | |
1077 int mode; | |
1078 }; | |
1079 | |
1123 | 1080 /* open() or access() a file to be returned by locate_file(). if |
1081 ACCESS_MODE >= 0, do an access() with that mode, else open(). Does | |
1082 various magic, e.g. opening the file read-only and binary and setting | |
1083 the close-on-exec flag on the file. */ | |
1084 | |
1085 static int | |
1086 locate_file_open_or_access_file (Ibyte *fn, int access_mode) | |
1087 { | |
1088 int val; | |
1089 | |
1090 /* Check that we can access or open it. */ | |
1091 if (access_mode >= 0) | |
1092 val = qxe_access (fn, access_mode); | |
1093 else | |
1094 { | |
1095 val = qxe_open (fn, O_RDONLY | OPEN_BINARY, 0); | |
1096 | |
1097 #ifndef WIN32_NATIVE | |
1098 if (val >= 0) | |
1099 /* If we actually opened the file, set close-on-exec flag | |
1100 on the new descriptor so that subprocesses can't whack | |
1101 at it. */ | |
1102 (void) fcntl (val, F_SETFD, FD_CLOEXEC); | |
1103 #endif | |
1104 } | |
1105 | |
1106 return val; | |
1107 } | |
1108 | |
428 | 1109 static int |
867 | 1110 locate_file_in_directory_mapper (Ibyte *fn, void *arg) |
428 | 1111 { |
1112 struct locate_file_in_directory_mapper_closure *closure = | |
771 | 1113 (struct locate_file_in_directory_mapper_closure *) arg; |
428 | 1114 struct stat st; |
1115 | |
1116 /* Ignore file if it's a directory. */ | |
771 | 1117 if (qxe_stat (fn, &st) >= 0 |
428 | 1118 && (st.st_mode & S_IFMT) != S_IFDIR) |
1119 { | |
1120 /* Check that we can access or open it. */ | |
1123 | 1121 closure->fd = locate_file_open_or_access_file (fn, closure->mode); |
428 | 1122 |
1123 if (closure->fd >= 0) | |
1124 { | |
2548 | 1125 if (!check_if_suppressed (fn, Qnil)) |
1126 { | |
1127 /* We succeeded; return this descriptor and filename. */ | |
1128 if (closure->storeptr) | |
1129 *closure->storeptr = build_intstring (fn); | |
1130 | |
1131 return 1; | |
1132 } | |
428 | 1133 } |
1134 } | |
1135 /* Keep mapping. */ | |
1136 return 0; | |
1137 } | |
1138 | |
1139 | |
1140 /* look for STR in PATH, optionally adding SUFFIXES. DIRECTORY need | |
1141 not have been expanded. */ | |
1142 | |
1143 static int | |
1144 locate_file_in_directory (Lisp_Object directory, Lisp_Object str, | |
1145 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1146 int mode) | |
1147 { | |
1148 /* This function can GC */ | |
1149 struct locate_file_in_directory_mapper_closure closure; | |
1150 Lisp_Object filename = Qnil; | |
1151 struct gcpro gcpro1, gcpro2, gcpro3; | |
1152 | |
1153 GCPRO3 (directory, str, filename); | |
1154 | |
1155 filename = Fexpand_file_name (str, directory); | |
1156 if (NILP (filename) || NILP (Ffile_name_absolute_p (filename))) | |
1157 /* If there are non-absolute elts in PATH (eg ".") */ | |
1158 /* Of course, this could conceivably lose if luser sets | |
1159 default-directory to be something non-absolute ... */ | |
1160 { | |
1161 if (NILP (filename)) | |
1162 /* NIL means current directory */ | |
1163 filename = current_buffer->directory; | |
1164 else | |
1165 filename = Fexpand_file_name (filename, | |
1166 current_buffer->directory); | |
1167 if (NILP (Ffile_name_absolute_p (filename))) | |
1168 { | |
1169 /* Give up on this directory! */ | |
1170 UNGCPRO; | |
1171 return -1; | |
1172 } | |
1173 } | |
1174 | |
1175 closure.fd = -1; | |
1176 closure.storeptr = storeptr; | |
1177 closure.mode = mode; | |
1178 | |
771 | 1179 locate_file_map_suffixes (filename, suffixes, |
1180 locate_file_in_directory_mapper, | |
428 | 1181 &closure); |
1182 | |
1183 UNGCPRO; | |
1184 return closure.fd; | |
1185 } | |
1186 | |
1187 /* do the same as locate_file() but don't use any hash tables. */ | |
1188 | |
1189 static int | |
1190 locate_file_without_hash (Lisp_Object path, Lisp_Object str, | |
1191 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1192 int mode) | |
1193 { | |
1194 /* This function can GC */ | |
1195 int absolute = !NILP (Ffile_name_absolute_p (str)); | |
1196 | |
2367 | 1197 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1198 { |
2367 | 1199 int val = locate_file_in_directory (elt, str, suffixes, storeptr, |
428 | 1200 mode); |
1201 if (val >= 0) | |
1202 return val; | |
1203 if (absolute) | |
1204 break; | |
1205 } | |
1206 return -1; | |
1207 } | |
1208 | |
1209 static int | |
867 | 1210 locate_file_construct_suffixed_files_mapper (Ibyte *fn, void *arg) |
428 | 1211 { |
771 | 1212 Lisp_Object *tail = (Lisp_Object *) arg; |
1213 *tail = Fcons (build_intstring (fn), *tail); | |
428 | 1214 return 0; |
1215 } | |
1216 | |
1217 /* Construct a list of all files to search for. | |
1218 It makes sense to have this despite locate_file_map_suffixes() | |
1219 because we need Lisp strings to access the hash-table, and it would | |
1220 be inefficient to create them on the fly, again and again for each | |
1221 path component. See locate_file(). */ | |
1222 | |
1223 static Lisp_Object | |
1224 locate_file_construct_suffixed_files (Lisp_Object filename, | |
1225 Lisp_Object suffixes) | |
1226 { | |
1227 Lisp_Object tail = Qnil; | |
1228 struct gcpro gcpro1; | |
1229 GCPRO1 (tail); | |
1230 | |
1231 locate_file_map_suffixes (filename, suffixes, | |
1232 locate_file_construct_suffixed_files_mapper, | |
1233 &tail); | |
1234 | |
1235 UNGCPRO; | |
1236 return Fnreverse (tail); | |
1237 } | |
1238 | |
1239 DEFUN ("locate-file-clear-hashing", Flocate_file_clear_hashing, 1, 1, 0, /* | |
1240 Clear the hash records for the specified list of directories. | |
1241 `locate-file' uses a hashing scheme to speed lookup, and will correctly | |
1242 track the following environmental changes: | |
1243 | |
1244 -- changes of any sort to the list of directories to be searched. | |
1245 -- addition and deletion of non-shadowing files (see below) from the | |
1246 directories in the list. | |
1247 -- byte-compilation of a .el file into a .elc file. | |
1248 | |
1249 `locate-file' will primarily get confused if you add a file that shadows | |
1250 \(i.e. has the same name as) another file further down in the directory list. | |
1251 In this case, you must call `locate-file-clear-hashing'. | |
1252 | |
1253 If PATH is t, it means to fully clear all the accumulated hashes. This | |
1254 can be used if the internal tables grow too large, or when dumping. | |
1255 */ | |
1256 (path)) | |
1257 { | |
1258 if (EQ (path, Qt)) | |
1259 Fclrhash (Vlocate_file_hash_table); | |
1260 else | |
1261 { | |
2367 | 1262 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1263 { |
2367 | 1264 Lisp_Object pathel = Fexpand_file_name (elt, Qnil); |
428 | 1265 Fremhash (pathel, Vlocate_file_hash_table); |
1266 } | |
1267 } | |
1268 return Qnil; | |
1269 } | |
1270 | |
1271 /* Search for a file whose name is STR, looking in directories | |
1272 in the Lisp list PATH, and trying suffixes from SUFFIXES. | |
1273 SUFFIXES is a list of possible suffixes, or (for backward | |
1274 compatibility) a string containing possible suffixes separated by | |
1275 colons. | |
1276 On success, returns a file descriptor. On failure, returns -1. | |
1277 | |
1278 MODE nonnegative means don't open the files, | |
1279 just look for one for which access(file,MODE) succeeds. In this case, | |
951 | 1280 returns a nonnegative value on success. On failure, returns -1. |
428 | 1281 |
2548 | 1282 If STOREPTR is non-nil, it points to a slot where the name of |
428 | 1283 the file actually found should be stored as a Lisp string. |
1284 Nil is stored there on failure. | |
1285 | |
1286 Called openp() in FSFmacs. */ | |
1287 | |
1288 int | |
1289 locate_file (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, | |
1290 Lisp_Object *storeptr, int mode) | |
1291 { | |
1292 /* This function can GC */ | |
1293 Lisp_Object suffixtab = Qnil; | |
2367 | 1294 Lisp_Object pathel_expanded; |
428 | 1295 int val; |
1296 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1297 | |
1298 if (storeptr) | |
1299 *storeptr = Qnil; | |
1300 | |
1301 /* Is it really necessary to gcpro path and str? It shouldn't be | |
1302 unless some caller has fucked up. There are known instances that | |
1303 call us with build_string("foo:bar") as SUFFIXES, though. */ | |
1304 GCPRO4 (path, str, suffixes, suffixtab); | |
1305 | |
1306 /* if this filename has directory components, it's too complicated | |
1307 to try and use the hash tables. */ | |
1308 if (!NILP (Ffile_name_directory (str))) | |
1309 { | |
1310 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1311 UNGCPRO; | |
1312 return val; | |
1313 } | |
1314 | |
1315 suffixtab = locate_file_construct_suffixed_files (str, suffixes); | |
1316 | |
2367 | 1317 { |
1318 EXTERNAL_LIST_LOOP_2 (pathel, path) | |
1319 { | |
1320 Lisp_Object hash_table; | |
1321 int found = 0; | |
1322 | |
1323 /* If this path element is relative, we have to look by hand. */ | |
1324 if (NILP (pathel) || NILP (Ffile_name_absolute_p (pathel))) | |
1325 { | |
1326 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1327 mode); | |
1328 if (val >= 0) | |
428 | 1329 { |
2367 | 1330 UNGCPRO; |
1331 return val; | |
428 | 1332 } |
2367 | 1333 continue; |
1334 } | |
1335 | |
1336 pathel_expanded = Fexpand_file_name (pathel, Qnil); | |
1337 hash_table = locate_file_find_directory_hash_table (pathel_expanded); | |
1338 | |
1339 if (!NILP (hash_table)) | |
1340 { | |
1341 /* Loop over suffixes. */ | |
1342 LIST_LOOP_2 (elt, suffixtab) | |
1343 if (!NILP (Fgethash (elt, hash_table, Qnil))) | |
1344 { | |
1345 found = 1; | |
1346 break; | |
1347 } | |
1348 } | |
1349 | |
1350 if (found) | |
1351 { | |
1352 /* This is a likely candidate. Look by hand in this directory | |
1353 so we don't get thrown off if someone byte-compiles a file. */ | |
1354 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1355 mode); | |
1356 if (val >= 0) | |
1357 { | |
1358 UNGCPRO; | |
1359 return val; | |
1360 } | |
1361 | |
1362 /* Hmm ... the file isn't actually there. (Or possibly it's | |
1363 a directory ...) So refresh our hashing. */ | |
1364 locate_file_refresh_hashing (pathel_expanded); | |
1365 } | |
1366 } | |
428 | 1367 } |
1368 | |
1369 /* File is probably not there, but check the hard way just in case. */ | |
1370 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1371 if (val >= 0) | |
1372 { | |
1373 /* Sneaky user added a file without telling us. */ | |
1374 Flocate_file_clear_hashing (path); | |
1375 } | |
1376 | |
1377 UNGCPRO; | |
1378 return val; | |
1379 } | |
1380 | |
1381 | |
1382 #ifdef LOADHIST | |
1383 | |
1384 /* Merge the list we've accumulated of globals from the current input source | |
1385 into the load_history variable. The details depend on whether | |
1386 the source has an associated file name or not. */ | |
1387 | |
1388 static void | |
1389 build_load_history (int loading, Lisp_Object source) | |
1390 { | |
1391 REGISTER Lisp_Object tail, prev, newelt; | |
1392 REGISTER Lisp_Object tem, tem2; | |
1393 int foundit; | |
1394 | |
1395 #if !defined(LOADHIST_DUMPED) | |
1396 /* Don't bother recording anything for preloaded files. */ | |
1397 if (purify_flag) | |
1398 return; | |
1399 #endif | |
1400 | |
1401 tail = Vload_history; | |
1402 prev = Qnil; | |
1403 foundit = 0; | |
1404 while (!NILP (tail)) | |
1405 { | |
1406 tem = Fcar (tail); | |
1407 | |
1408 /* Find the feature's previous assoc list... */ | |
1409 if (internal_equal (source, Fcar (tem), 0)) | |
1410 { | |
1411 foundit = 1; | |
1412 | |
1413 /* If we're loading, remove it. */ | |
1414 if (loading) | |
1415 { | |
1416 if (NILP (prev)) | |
1417 Vload_history = Fcdr (tail); | |
1418 else | |
1419 Fsetcdr (prev, Fcdr (tail)); | |
1420 } | |
1421 | |
1422 /* Otherwise, cons on new symbols that are not already members. */ | |
1423 else | |
1424 { | |
1425 tem2 = Vcurrent_load_list; | |
1426 | |
1427 while (CONSP (tem2)) | |
1428 { | |
1429 newelt = XCAR (tem2); | |
1430 | |
1431 if (NILP (Fmemq (newelt, tem))) | |
1432 Fsetcar (tail, Fcons (Fcar (tem), | |
1433 Fcons (newelt, Fcdr (tem)))); | |
1434 | |
1435 tem2 = XCDR (tem2); | |
1436 QUIT; | |
1437 } | |
1438 } | |
1439 } | |
1440 else | |
1441 prev = tail; | |
1442 tail = Fcdr (tail); | |
1443 QUIT; | |
1444 } | |
1445 | |
1446 /* If we're loading, cons the new assoc onto the front of load-history, | |
1447 the most-recently-loaded position. Also do this if we didn't find | |
1448 an existing member for the current source. */ | |
1449 if (loading || !foundit) | |
1450 Vload_history = Fcons (Fnreverse (Vcurrent_load_list), | |
1451 Vload_history); | |
1452 } | |
1453 | |
1454 #else /* !LOADHIST */ | |
1455 #define build_load_history(x,y) | |
1456 #endif /* !LOADHIST */ | |
1457 | |
1458 | |
1459 static void | |
1460 readevalloop (Lisp_Object readcharfun, | |
1461 Lisp_Object sourcename, | |
1462 Lisp_Object (*evalfun) (Lisp_Object), | |
1463 int printflag) | |
1464 { | |
1465 /* This function can GC */ | |
867 | 1466 REGISTER Ichar c; |
1849 | 1467 Lisp_Object val = Qnil; |
428 | 1468 int speccount = specpdl_depth (); |
1469 struct gcpro gcpro1, gcpro2; | |
1470 struct buffer *b = 0; | |
1471 | |
1472 if (BUFFERP (readcharfun)) | |
1473 b = XBUFFER (readcharfun); | |
1474 else if (MARKERP (readcharfun)) | |
1475 b = XMARKER (readcharfun)->buffer; | |
1476 | |
1477 /* Don't do this. It is not necessary, and it needlessly exposes | |
1478 READCHARFUN (which can be a stream) to Lisp. --hniksic */ | |
1479 /*specbind (Qstandard_input, readcharfun);*/ | |
1480 | |
2548 | 1481 internal_bind_lisp_object (&Vcurrent_load_list, Qnil); |
428 | 1482 |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
1483 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 1484 Vcurrent_compiled_function_annotation = Qnil; |
1485 #endif | |
1486 GCPRO2 (val, sourcename); | |
1487 | |
1488 LOADHIST_ATTACH (sourcename); | |
1489 | |
1490 while (1) | |
1491 { | |
1492 QUIT; | |
1493 | |
1494 if (b != 0 && !BUFFER_LIVE_P (b)) | |
563 | 1495 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 1496 |
1497 c = readchar (readcharfun); | |
1498 if (c == ';') | |
1499 { | |
1500 /* Skip comment */ | |
1501 while ((c = readchar (readcharfun)) != '\n' && c != -1) | |
1502 QUIT; | |
1503 continue; | |
1504 } | |
1505 if (c < 0) | |
1506 break; | |
1507 | |
1508 /* Ignore whitespace here, so we can detect eof. */ | |
1509 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') | |
1510 continue; | |
1511 | |
814 | 1512 unreadchar (readcharfun, c); |
1513 Vread_objects = Qnil; | |
1514 if (NILP (Vload_read_function)) | |
1515 val = read0 (readcharfun); | |
428 | 1516 else |
814 | 1517 val = call1 (Vload_read_function, readcharfun); |
428 | 1518 val = (*evalfun) (val); |
1519 if (printflag) | |
1520 { | |
1521 Vvalues = Fcons (val, Vvalues); | |
1522 if (EQ (Vstandard_output, Qt)) | |
1523 Fprin1 (val, Qnil); | |
1524 else | |
1525 Fprint (val, Qnil); | |
1526 } | |
1527 } | |
1528 | |
1529 build_load_history (LSTREAMP (readcharfun) || | |
1530 /* This looks weird, but it's what's in FSFmacs */ | |
1531 (b ? BUF_NARROWED (b) : BUF_NARROWED (current_buffer)), | |
1532 sourcename); | |
1533 UNGCPRO; | |
1534 | |
771 | 1535 unbind_to (speccount); |
428 | 1536 } |
1537 | |
1538 DEFUN ("eval-buffer", Feval_buffer, 0, 2, "bBuffer: ", /* | |
1539 Execute BUFFER as Lisp code. | |
1540 Programs can pass two arguments, BUFFER and PRINTFLAG. | |
1541 BUFFER is the buffer to evaluate (nil means use current buffer). | |
1542 PRINTFLAG controls printing of output: | |
444 | 1543 nil means discard it; anything else is a stream for printing. |
428 | 1544 |
1545 If there is no error, point does not move. If there is an error, | |
1546 point remains at the end of the last character read from the buffer. | |
1547 */ | |
444 | 1548 (buffer, printflag)) |
428 | 1549 { |
1550 /* This function can GC */ | |
1551 int speccount = specpdl_depth (); | |
1552 Lisp_Object tem, buf; | |
1553 | |
444 | 1554 if (NILP (buffer)) |
428 | 1555 buf = Fcurrent_buffer (); |
1556 else | |
444 | 1557 buf = Fget_buffer (buffer); |
428 | 1558 if (NILP (buf)) |
563 | 1559 invalid_argument ("No such buffer", Qunbound); |
428 | 1560 |
1561 if (NILP (printflag)) | |
1562 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ | |
1563 else | |
1564 tem = printflag; | |
1565 specbind (Qstandard_output, tem); | |
1566 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
1567 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); | |
1568 readevalloop (buf, XBUFFER (buf)->filename, Feval, | |
1569 !NILP (printflag)); | |
1570 | |
771 | 1571 return unbind_to (speccount); |
428 | 1572 } |
1573 | |
1574 #if 0 | |
826 | 1575 DEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /* |
428 | 1576 Execute the current buffer as Lisp code. |
1577 Programs can pass argument PRINTFLAG which controls printing of output: | |
1578 nil means discard it; anything else is stream for print. | |
1579 | |
1580 If there is no error, point does not move. If there is an error, | |
1581 point remains at the end of the last character read from the buffer. | |
1582 */ | |
1583 (printflag)) | |
1584 { | |
1585 code omitted; | |
1586 } | |
1587 #endif /* 0 */ | |
1588 | |
1589 DEFUN ("eval-region", Feval_region, 2, 3, "r", /* | |
1590 Execute the region as Lisp code. | |
444 | 1591 When called from programs, expects two arguments START and END |
428 | 1592 giving starting and ending indices in the current buffer |
1593 of the text to be executed. | |
444 | 1594 Programs can pass third optional argument STREAM which controls output: |
428 | 1595 nil means discard it; anything else is stream for printing it. |
1596 | |
1597 If there is no error, point does not move. If there is an error, | |
1598 point remains at the end of the last character read from the buffer. | |
1599 | |
1600 Note: Before evaling the region, this function narrows the buffer to it. | |
1601 If the code being eval'd should happen to trigger a redisplay you may | |
1602 see some text temporarily disappear because of this. | |
1603 */ | |
444 | 1604 (start, end, stream)) |
428 | 1605 { |
1606 /* This function can GC */ | |
1607 int speccount = specpdl_depth (); | |
1608 Lisp_Object tem; | |
1609 Lisp_Object cbuf = Fcurrent_buffer (); | |
1610 | |
444 | 1611 if (NILP (stream)) |
428 | 1612 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ |
1613 else | |
444 | 1614 tem = stream; |
428 | 1615 specbind (Qstandard_output, tem); |
1616 | |
444 | 1617 if (NILP (stream)) |
428 | 1618 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
844 | 1619 record_unwind_protect (save_restriction_restore, |
1620 save_restriction_save (current_buffer)); | |
428 | 1621 |
444 | 1622 /* This both uses start and checks its type. */ |
1623 Fgoto_char (start, cbuf); | |
1624 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), end, cbuf); | |
428 | 1625 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval, |
444 | 1626 !NILP (stream)); |
428 | 1627 |
771 | 1628 return unbind_to (speccount); |
428 | 1629 } |
1630 | |
1631 DEFUN ("read", Fread, 0, 1, 0, /* | |
1632 Read one Lisp expression as text from STREAM, return as Lisp object. | |
1633 If STREAM is nil, use the value of `standard-input' (which see). | |
1634 STREAM or the value of `standard-input' may be: | |
1635 a buffer (read from point and advance it) | |
1636 a marker (read from where it points and advance it) | |
1637 a function (call it with no arguments for each character, | |
1638 call it with a char as argument to push a char back) | |
1639 a string (takes text from string, starting at the beginning) | |
1640 t (read text line using minibuffer and use it). | |
1641 */ | |
1642 (stream)) | |
1643 { | |
1644 if (NILP (stream)) | |
1645 stream = Vstandard_input; | |
1646 if (EQ (stream, Qt)) | |
1647 stream = Qread_char; | |
1648 | |
1649 Vread_objects = Qnil; | |
1650 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
1651 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 1652 Vcurrent_compiled_function_annotation = Qnil; |
1653 #endif | |
1654 if (EQ (stream, Qread_char)) | |
1655 { | |
1656 Lisp_Object val = call1 (Qread_from_minibuffer, | |
771 | 1657 build_msg_string ("Lisp expression: ")); |
428 | 1658 return Fcar (Fread_from_string (val, Qnil, Qnil)); |
1659 } | |
1660 | |
1661 if (STRINGP (stream)) | |
1662 return Fcar (Fread_from_string (stream, Qnil, Qnil)); | |
1663 | |
1664 return read0 (stream); | |
1665 } | |
1666 | |
1667 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /* | |
1668 Read one Lisp expression which is represented as text by STRING. | |
1669 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | |
1670 START and END optionally delimit a substring of STRING from which to read; | |
1671 they default to 0 and (length STRING) respectively. | |
1672 */ | |
1673 (string, start, end)) | |
1674 { | |
1675 Bytecount startval, endval; | |
1676 Lisp_Object tem; | |
1677 Lisp_Object lispstream = Qnil; | |
1678 struct gcpro gcpro1; | |
1679 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
1680 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 1681 Vcurrent_compiled_function_annotation = Qnil; |
1682 #endif | |
1683 GCPRO1 (lispstream); | |
1684 CHECK_STRING (string); | |
1685 get_string_range_byte (string, start, end, &startval, &endval, | |
1686 GB_HISTORICAL_STRING_BEHAVIOR); | |
1687 lispstream = make_lisp_string_input_stream (string, startval, | |
1688 endval - startval); | |
1689 | |
1690 Vread_objects = Qnil; | |
1691 | |
1692 tem = read0 (lispstream); | |
1693 /* Yeah, it's ugly. Gonna make something of it? | |
1694 At least our reader is reentrant ... */ | |
1695 tem = | |
1696 (Fcons (tem, make_int | |
793 | 1697 (string_index_byte_to_char |
771 | 1698 (string, |
428 | 1699 startval + Lstream_byte_count (XLSTREAM (lispstream)))))); |
1700 Lstream_delete (XLSTREAM (lispstream)); | |
1701 UNGCPRO; | |
1702 return tem; | |
1703 } | |
1704 | |
1705 | |
1706 | |
1707 /* Use this for recursive reads, in contexts where internal tokens | |
1708 are not allowed. See also read1(). */ | |
1709 static Lisp_Object | |
1710 read0 (Lisp_Object readcharfun) | |
1711 { | |
1712 Lisp_Object val = read1 (readcharfun); | |
1713 | |
1714 if (CONSP (val) && UNBOUNDP (XCAR (val))) | |
1715 { | |
867 | 1716 Ichar c = XCHAR (XCDR (val)); |
853 | 1717 free_cons (val); |
428 | 1718 return Fsignal (Qinvalid_read_syntax, |
1719 list1 (Fchar_to_string (make_char (c)))); | |
1720 } | |
1721 | |
1722 return val; | |
1723 } | |
3543 | 1724 |
1725 /* A Unicode escape, as in C# (though we only permit them in strings | |
1726 and characters, not arbitrarily in the source code.) */ | |
1727 static Ichar | |
1728 read_unicode_escape (Lisp_Object readcharfun, int unicode_hex_count) | |
1729 { | |
1730 REGISTER Ichar i = 0, c; | |
1731 REGISTER int count = 0; | |
1732 Lisp_Object lisp_char; | |
1733 while (++count <= unicode_hex_count) | |
1734 { | |
1735 c = readchar (readcharfun); | |
1736 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ | |
1737 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); | |
1738 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1739 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1740 else | |
1741 { | |
1742 syntax_error ("Non-hex digit used for Unicode escape", | |
1743 make_char (c)); | |
1744 break; | |
1745 } | |
1746 } | |
1747 | |
4268 | 1748 if (i >= 0x110000 || i < 0) |
4096 | 1749 { |
1750 syntax_error ("Not a Unicode code point", make_int(i)); | |
1751 } | |
1752 | |
3543 | 1753 lisp_char = Funicode_to_char(make_int(i), Qnil); |
1754 | |
1755 if (EQ(Qnil, lisp_char)) | |
1756 { | |
4096 | 1757 /* Will happen on non-Mule. Silent corruption is what happens |
1758 elsewhere, and we used to do that to be consistent, but GNU error, | |
1759 so people writing portable code need to be able to handle that, and | |
1760 given a choice I prefer that behaviour. | |
1761 | |
1762 An undesirable aspect to this error is that the code point is shown | |
1763 as a decimal integer, which is mostly unreadable. */ | |
1764 syntax_error ("Unsupported Unicode code point", make_int(i)); | |
3543 | 1765 } |
4096 | 1766 |
1767 return XCHAR(lisp_char); | |
3543 | 1768 } |
1769 | |
428 | 1770 |
867 | 1771 static Ichar |
428 | 1772 read_escape (Lisp_Object readcharfun) |
1773 { | |
1774 /* This function can GC */ | |
867 | 1775 Ichar c = readchar (readcharfun); |
428 | 1776 |
1777 if (c < 0) | |
563 | 1778 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1779 |
1780 switch (c) | |
1781 { | |
1782 case 'a': return '\007'; | |
1783 case 'b': return '\b'; | |
1784 case 'd': return 0177; | |
1785 case 'e': return 033; | |
1786 case 'f': return '\f'; | |
1787 case 'n': return '\n'; | |
1788 case 'r': return '\r'; | |
1789 case 't': return '\t'; | |
1790 case 'v': return '\v'; | |
1791 case '\n': return -1; | |
1792 | |
1793 case 'M': | |
1794 c = readchar (readcharfun); | |
1795 if (c < 0) | |
563 | 1796 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1797 if (c != '-') |
563 | 1798 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1799 c = readchar (readcharfun); |
1800 if (c < 0) | |
563 | 1801 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1802 if (c == '\\') |
1803 c = read_escape (readcharfun); | |
1804 return c | 0200; | |
1805 | |
1806 /* Originally, FSF_KEYS provided a degree of FSF Emacs | |
1807 compatibility by defining character "modifiers" alt, super, | |
1808 hyper and shift to infest the characters (i.e. integers). | |
1809 | |
1810 However, this doesn't cut it for XEmacs 20, which | |
1811 distinguishes characters from integers. Without Mule, ?\H-a | |
1812 simply returns ?a because every character is clipped into | |
1813 0-255. Under Mule it is much worse -- ?\H-a with FSF_KEYS | |
1814 produces an illegal character, and moves us to crash-land. | |
1815 | |
1816 For these reasons, FSF_KEYS hack is useless and without hope | |
1817 of ever working under XEmacs 20. */ | |
1818 #ifdef FSF_KEYS | |
831 | 1819 /* Deleted */ |
1820 #endif | |
428 | 1821 |
1822 case 'C': | |
1823 c = readchar (readcharfun); | |
1824 if (c < 0) | |
563 | 1825 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1826 if (c != '-') |
563 | 1827 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1828 case '^': |
1829 c = readchar (readcharfun); | |
1830 if (c < 0) | |
563 | 1831 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1832 if (c == '\\') |
1833 c = read_escape (readcharfun); | |
1834 /* FSFmacs junk for non-ASCII controls. | |
1835 Not used here. */ | |
1836 if (c == '?') | |
1837 return 0177; | |
1838 else | |
1839 return c & (0200 | 037); | |
1840 | |
1841 case '0': | |
1842 case '1': | |
1843 case '2': | |
1844 case '3': | |
1845 case '4': | |
1846 case '5': | |
1847 case '6': | |
1848 case '7': | |
1849 /* An octal escape, as in ANSI C. */ | |
1850 { | |
867 | 1851 REGISTER Ichar i = c - '0'; |
428 | 1852 REGISTER int count = 0; |
1853 while (++count < 3) | |
1854 { | |
1855 if ((c = readchar (readcharfun)) >= '0' && c <= '7') | |
1856 i = (i << 3) + (c - '0'); | |
1857 else | |
1858 { | |
1859 unreadchar (readcharfun, c); | |
1860 break; | |
1861 } | |
1862 } | |
831 | 1863 if (i >= 0400) |
3367 | 1864 syntax_error ("Non-ISO-8859-1 character specified with octal escape", |
831 | 1865 make_int (i)); |
428 | 1866 return i; |
1867 } | |
1868 | |
1869 case 'x': | |
1870 /* A hex escape, as in ANSI C, except that we only allow latin-1 | |
1871 characters to be read this way. What is "\x4e03" supposed to | |
1872 mean, anyways, if the internal representation is hidden? | |
1873 This is also consistent with the treatment of octal escapes. */ | |
1874 { | |
867 | 1875 REGISTER Ichar i = 0; |
428 | 1876 REGISTER int count = 0; |
1877 while (++count <= 2) | |
1878 { | |
1879 c = readchar (readcharfun); | |
867 | 1880 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ |
428 | 1881 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
1882 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1883 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1884 else | |
1885 { | |
1886 unreadchar (readcharfun, c); | |
1887 break; | |
1888 } | |
1889 } | |
4483
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1890 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1891 if (count == 3) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1892 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1893 c = readchar (readcharfun); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1894 if ((c >= '0' && c <= '9') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1895 (c >= 'a' && c <= 'f') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1896 (c >= 'A' && c <= 'F')) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1897 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1898 Lisp_Object args[2]; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1899 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1900 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1901 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1902 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1903 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1904 args[0] = build_string ("?\\x%x"); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1905 args[1] = make_int (i); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1906 syntax_error ("Overlong hex character escape", |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1907 Fformat (2, args)); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1908 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1909 unreadchar (readcharfun, c); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1910 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1911 |
428 | 1912 return i; |
1913 } | |
3367 | 1914 case 'U': |
1915 /* Post-Unicode-2.0: Up to eight hex chars */ | |
3543 | 1916 return read_unicode_escape(readcharfun, 8); |
3367 | 1917 case 'u': |
3543 | 1918 /* Unicode-2.0 and before; four hex chars. */ |
1919 return read_unicode_escape(readcharfun, 4); | |
428 | 1920 |
1921 default: | |
1922 return c; | |
1923 } | |
1924 } | |
1925 | |
1926 | |
1927 | |
1928 /* read symbol-constituent stuff into `Vread_buffer_stream'. */ | |
1929 static Bytecount | |
867 | 1930 read_atom_0 (Lisp_Object readcharfun, Ichar firstchar, int *saw_a_backslash) |
428 | 1931 { |
1932 /* This function can GC */ | |
867 | 1933 Ichar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun)); |
428 | 1934 Lstream_rewind (XLSTREAM (Vread_buffer_stream)); |
1935 | |
1936 *saw_a_backslash = 0; | |
1937 | |
1938 while (c > 040 /* #### - comma should be here as should backquote */ | |
1939 && !(c == '\"' || c == '\'' || c == ';' | |
1940 || c == '(' || c == ')' | |
1941 || c == '[' || c == ']' || c == '#' | |
1942 )) | |
1943 { | |
1944 if (c == '\\') | |
1945 { | |
1946 c = readchar (readcharfun); | |
1947 if (c < 0) | |
563 | 1948 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1949 *saw_a_backslash = 1; |
1950 } | |
867 | 1951 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), c); |
428 | 1952 QUIT; |
1953 c = readchar (readcharfun); | |
1954 } | |
1955 | |
1956 if (c >= 0) | |
1957 unreadchar (readcharfun, c); | |
1958 /* blasted terminating 0 */ | |
867 | 1959 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), 0); |
428 | 1960 Lstream_flush (XLSTREAM (Vread_buffer_stream)); |
1961 | |
1962 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; | |
1963 } | |
1964 | |
867 | 1965 static Lisp_Object parse_integer (const Ibyte *buf, Bytecount len, int base); |
428 | 1966 |
1967 static Lisp_Object | |
1968 read_atom (Lisp_Object readcharfun, | |
867 | 1969 Ichar firstchar, |
428 | 1970 int uninterned_symbol) |
1971 { | |
1972 /* This function can GC */ | |
1973 int saw_a_backslash; | |
1974 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash); | |
1975 char *read_ptr = (char *) | |
1976 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)); | |
1977 | |
1978 /* Is it an integer? */ | |
1979 if (! (saw_a_backslash || uninterned_symbol)) | |
1980 { | |
1981 /* If a token had any backslashes in it, it is disqualified from | |
1982 being an integer or a float. This means that 123\456 is a | |
1983 symbol, as is \123 (which is the way (intern "123") prints). | |
1984 Also, if token was preceded by #:, it's always a symbol. | |
1985 */ | |
1986 char *p = read_ptr + len; | |
1987 char *p1 = read_ptr; | |
1988 | |
1989 if (*p1 == '+' || *p1 == '-') p1++; | |
1990 if (p1 != p) | |
1991 { | |
1992 int c; | |
1993 | |
1994 while (p1 != p && (c = *p1) >= '0' && c <= '9') | |
1995 p1++; | |
1996 /* Integers can have trailing decimal points. */ | |
1997 if (p1 > read_ptr && p1 < p && *p1 == '.') | |
1998 p1++; | |
1999 if (p1 == p) | |
2000 { | |
2001 /* It is an integer. */ | |
2002 if (p1[-1] == '.') | |
2003 p1[-1] = '\0'; | |
2004 #if 0 | |
2005 { | |
2006 int number = 0; | |
2007 if (sizeof (int) == sizeof (EMACS_INT)) | |
2008 number = atoi (read_buffer); | |
2009 else if (sizeof (long) == sizeof (EMACS_INT)) | |
2010 number = atol (read_buffer); | |
2011 else | |
2500 | 2012 ABORT (); |
428 | 2013 return make_int (number); |
2014 } | |
2015 #else | |
867 | 2016 return parse_integer ((Ibyte *) read_ptr, len, 10); |
428 | 2017 #endif |
2018 } | |
2019 } | |
1983 | 2020 #ifdef HAVE_RATIO |
2021 if (isratio_string (read_ptr)) | |
2022 { | |
2013 | 2023 /* GMP ratio_set_string has no effect with initial + sign */ |
2010 | 2024 if (*read_ptr == '+') |
2025 read_ptr++; | |
1983 | 2026 ratio_set_string (scratch_ratio, read_ptr, 0); |
2027 ratio_canonicalize (scratch_ratio); | |
2028 return Fcanonicalize_number (make_ratio_rt (scratch_ratio)); | |
2029 } | |
2030 #endif | |
428 | 2031 if (isfloat_string (read_ptr)) |
2032 return make_float (atof (read_ptr)); | |
2033 } | |
2034 | |
2035 { | |
2036 Lisp_Object sym; | |
2037 if (uninterned_symbol) | |
867 | 2038 sym = Fmake_symbol ( make_string ((Ibyte *) read_ptr, len)); |
428 | 2039 else |
2040 { | |
867 | 2041 Lisp_Object name = make_string ((Ibyte *) read_ptr, len); |
428 | 2042 sym = Fintern (name, Qnil); |
2043 } | |
2044 return sym; | |
2045 } | |
2046 } | |
2047 | |
2048 | |
2049 static Lisp_Object | |
867 | 2050 parse_integer (const Ibyte *buf, Bytecount len, int base) |
428 | 2051 { |
867 | 2052 const Ibyte *lim = buf + len; |
2053 const Ibyte *p = buf; | |
428 | 2054 EMACS_UINT num = 0; |
2055 int negativland = 0; | |
2056 | |
2057 if (*p == '-') | |
2058 { | |
2059 negativland = 1; | |
2060 p++; | |
2061 } | |
2062 else if (*p == '+') | |
2063 { | |
2064 p++; | |
2065 } | |
2066 | |
2067 if (p == lim) | |
2068 goto loser; | |
2069 | |
2070 for (; (p < lim) && (*p != '\0'); p++) | |
2071 { | |
2072 int c = *p; | |
2073 EMACS_UINT onum; | |
2074 | |
2075 if (isdigit (c)) | |
2076 c = c - '0'; | |
2077 else if (isupper (c)) | |
2078 c = c - 'A' + 10; | |
2079 else if (islower (c)) | |
2080 c = c - 'a' + 10; | |
2081 else | |
2082 goto loser; | |
2083 | |
2084 if (c < 0 || c >= base) | |
2085 goto loser; | |
2086 | |
2087 onum = num; | |
2088 num = num * base + c; | |
2089 if (num < onum) | |
2090 goto overflow; | |
2091 } | |
2092 | |
2093 { | |
2094 EMACS_INT int_result = negativland ? - (EMACS_INT) num : (EMACS_INT) num; | |
2095 Lisp_Object result = make_int (int_result); | |
2096 if (num && ((XINT (result) < 0) != negativland)) | |
2097 goto overflow; | |
2098 if (XINT (result) != int_result) | |
2099 goto overflow; | |
2100 return result; | |
2101 } | |
2102 overflow: | |
1983 | 2103 #ifdef HAVE_BIGNUM |
2104 { | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4268
diff
changeset
|
2105 bignum_set_string (scratch_bignum, (const char *) buf, base); |
1983 | 2106 return make_bignum_bg (scratch_bignum); |
2107 } | |
2108 #else | |
428 | 2109 return Fsignal (Qinvalid_read_syntax, |
771 | 2110 list3 (build_msg_string |
428 | 2111 ("Integer constant overflow in reader"), |
2112 make_string (buf, len), | |
2113 make_int (base))); | |
1983 | 2114 #endif /* HAVE_BIGNUM */ |
428 | 2115 loser: |
2116 return Fsignal (Qinvalid_read_syntax, | |
771 | 2117 list3 (build_msg_string |
428 | 2118 ("Invalid integer constant in reader"), |
2119 make_string (buf, len), | |
2120 make_int (base))); | |
2121 } | |
2122 | |
2123 | |
2124 static Lisp_Object | |
2125 read_integer (Lisp_Object readcharfun, int base) | |
2126 { | |
2127 /* This function can GC */ | |
2128 int saw_a_backslash; | |
2129 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash); | |
2130 return (parse_integer | |
2131 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)), | |
2132 ((saw_a_backslash) | |
2133 ? 0 /* make parse_integer signal error */ | |
2134 : len), | |
2135 base)); | |
2136 } | |
2137 | |
2138 static Lisp_Object | |
2139 read_bit_vector (Lisp_Object readcharfun) | |
2140 { | |
2141 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); | |
440 | 2142 Lisp_Object val; |
428 | 2143 |
2144 while (1) | |
2145 { | |
444 | 2146 unsigned char bit; |
867 | 2147 Ichar c = readchar (readcharfun); |
444 | 2148 if (c == '0') |
2149 bit = 0; | |
2150 else if (c == '1') | |
2151 bit = 1; | |
2152 else | |
2153 { | |
2154 if (c >= 0) | |
2155 unreadchar (readcharfun, c); | |
2156 break; | |
2157 } | |
2158 Dynarr_add (dyn, bit); | |
428 | 2159 } |
2160 | |
440 | 2161 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), |
2162 Dynarr_length (dyn)); | |
2163 Dynarr_free (dyn); | |
2164 | |
2165 return val; | |
428 | 2166 } |
2167 | |
2168 | |
2169 | |
2170 /* structures */ | |
2171 | |
2172 struct structure_type * | |
2173 define_structure_type (Lisp_Object type, | |
2174 int (*validate) (Lisp_Object data, | |
578 | 2175 Error_Behavior errb), |
428 | 2176 Lisp_Object (*instantiate) (Lisp_Object data)) |
2177 { | |
2178 struct structure_type st; | |
2179 | |
2180 st.type = type; | |
2181 st.keywords = Dynarr_new (structure_keyword_entry); | |
2182 st.validate = validate; | |
2183 st.instantiate = instantiate; | |
2184 Dynarr_add (the_structure_type_dynarr, st); | |
2185 | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4677
diff
changeset
|
2186 return Dynarr_lastp (the_structure_type_dynarr); |
428 | 2187 } |
2188 | |
2189 void | |
2190 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword, | |
2191 int (*validate) (Lisp_Object keyword, | |
2192 Lisp_Object value, | |
578 | 2193 Error_Behavior errb)) |
428 | 2194 { |
2195 struct structure_keyword_entry en; | |
2196 | |
2197 en.keyword = keyword; | |
2198 en.validate = validate; | |
2199 Dynarr_add (st->keywords, en); | |
2200 } | |
2201 | |
2202 static struct structure_type * | |
2203 recognized_structure_type (Lisp_Object type) | |
2204 { | |
2205 int i; | |
2206 | |
2207 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++) | |
2208 { | |
2209 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i); | |
2210 if (EQ (st->type, type)) | |
2211 return st; | |
2212 } | |
2213 | |
2214 return 0; | |
2215 } | |
2216 | |
2217 static Lisp_Object | |
2218 read_structure (Lisp_Object readcharfun) | |
2219 { | |
867 | 2220 Ichar c = readchar (readcharfun); |
428 | 2221 Lisp_Object list = Qnil; |
2222 Lisp_Object orig_list = Qnil; | |
2223 Lisp_Object already_seen = Qnil; | |
2224 int keyword_count; | |
2225 struct structure_type *st; | |
2226 struct gcpro gcpro1, gcpro2; | |
2227 | |
2228 GCPRO2 (orig_list, already_seen); | |
2229 if (c != '(') | |
442 | 2230 RETURN_UNGCPRO (continuable_read_syntax_error ("#s not followed by paren")); |
428 | 2231 list = read_list (readcharfun, ')', 0, 0); |
2232 orig_list = list; | |
2233 { | |
2234 int len = XINT (Flength (list)); | |
2235 if (len == 0) | |
442 | 2236 RETURN_UNGCPRO (continuable_read_syntax_error |
428 | 2237 ("structure type not specified")); |
2238 if (!(len & 1)) | |
2239 RETURN_UNGCPRO | |
442 | 2240 (continuable_read_syntax_error |
428 | 2241 ("structures must have alternating keyword/value pairs")); |
2242 } | |
2243 | |
2244 st = recognized_structure_type (XCAR (list)); | |
2245 if (!st) | |
2246 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2247 list2 (build_msg_string |
428 | 2248 ("unrecognized structure type"), |
2249 XCAR (list)))); | |
2250 | |
2251 list = Fcdr (list); | |
2252 keyword_count = Dynarr_length (st->keywords); | |
2253 while (!NILP (list)) | |
2254 { | |
2255 Lisp_Object keyword, value; | |
2256 int i; | |
2257 struct structure_keyword_entry *en = NULL; | |
2258 | |
2259 keyword = Fcar (list); | |
2260 list = Fcdr (list); | |
2261 value = Fcar (list); | |
2262 list = Fcdr (list); | |
2263 | |
2264 if (!NILP (memq_no_quit (keyword, already_seen))) | |
2265 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2266 list2 (build_msg_string |
428 | 2267 ("structure keyword already seen"), |
2268 keyword))); | |
2269 | |
2270 for (i = 0; i < keyword_count; i++) | |
2271 { | |
2272 en = Dynarr_atp (st->keywords, i); | |
2273 if (EQ (keyword, en->keyword)) | |
2274 break; | |
2275 } | |
2276 | |
2277 if (i == keyword_count) | |
2278 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2279 list2 (build_msg_string |
428 | 2280 ("unrecognized structure keyword"), |
2281 keyword))); | |
2282 | |
2283 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME)) | |
2284 RETURN_UNGCPRO | |
2285 (Fsignal (Qinvalid_read_syntax, | |
771 | 2286 list3 (build_msg_string |
428 | 2287 ("invalid value for structure keyword"), |
2288 keyword, value))); | |
2289 | |
2290 already_seen = Fcons (keyword, already_seen); | |
2291 } | |
2292 | |
2293 if (st->validate && ! (st->validate) (orig_list, ERROR_ME)) | |
2294 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2295 list2 (build_msg_string |
428 | 2296 ("invalid structure initializer"), |
2297 orig_list))); | |
2298 | |
2299 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list))); | |
2300 } | |
2301 | |
2302 | |
2303 static Lisp_Object read_compiled_function (Lisp_Object readcharfun, | |
2304 int terminator); | |
2305 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator); | |
2306 | |
2307 /* Get the next character; filter out whitespace and comments */ | |
2308 | |
867 | 2309 static Ichar |
428 | 2310 reader_nextchar (Lisp_Object readcharfun) |
2311 { | |
2312 /* This function can GC */ | |
867 | 2313 Ichar c; |
428 | 2314 |
2315 retry: | |
2316 QUIT; | |
2317 c = readchar (readcharfun); | |
2318 if (c < 0) | |
563 | 2319 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 2320 |
2321 switch (c) | |
2322 { | |
2323 default: | |
2324 { | |
2325 /* Ignore whitespace and control characters */ | |
2326 if (c <= 040) | |
2327 goto retry; | |
2328 return c; | |
2329 } | |
2330 | |
2331 case ';': | |
2332 { | |
2333 /* Comment */ | |
2334 while ((c = readchar (readcharfun)) >= 0 && c != '\n') | |
2335 QUIT; | |
2336 goto retry; | |
2337 } | |
2338 } | |
2339 } | |
2340 | |
2341 #if 0 | |
2342 static Lisp_Object | |
2343 list2_pure (int pure, Lisp_Object a, Lisp_Object b) | |
2344 { | |
2345 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b); | |
2346 } | |
2347 #endif | |
2348 | |
3543 | 2349 static Lisp_Object |
2350 read_string (Lisp_Object readcharfun, Ichar delim, int raw, | |
2351 int honor_unicode) | |
2352 { | |
2353 #ifdef I18N3 | |
2354 /* #### If the input stream is translating, then the string | |
2355 should be marked as translatable by setting its | |
2356 `string-translatable' property to t. .el and .elc files | |
2357 normally are translating input streams. See Fgettext() | |
2358 and print_internal(). */ | |
2359 #endif | |
2360 Ichar c; | |
2361 int cancel = 0; | |
2362 | |
2363 Lstream_rewind(XLSTREAM(Vread_buffer_stream)); | |
2364 while ((c = readchar(readcharfun)) >= 0 && c != delim) | |
2365 { | |
2366 if (c == '\\') | |
2367 { | |
2368 if (raw) | |
2369 { | |
2370 c = readchar(readcharfun); | |
2371 if (honor_unicode && ('u' == c || 'U' == c)) | |
2372 { | |
2373 c = read_unicode_escape(readcharfun, | |
2374 'U' == c ? 8 : 4); | |
2375 } | |
2376 else | |
2377 { | |
2378 /* For raw strings, insert the | |
2379 backslash and the next char, */ | |
2380 Lstream_put_ichar(XLSTREAM | |
2381 (Vread_buffer_stream), | |
2382 '\\'); | |
2383 } | |
2384 } | |
2385 else | |
2386 /* otherwise, backslash escapes the next char. */ | |
2387 c = read_escape(readcharfun); | |
2388 } | |
2389 /* c is -1 if \ newline has just been seen */ | |
2390 if (c == -1) | |
2391 { | |
2392 if (Lstream_byte_count | |
2393 (XLSTREAM(Vread_buffer_stream)) == | |
2394 0) | |
2395 cancel = 1; | |
2396 } | |
2397 else | |
2398 Lstream_put_ichar(XLSTREAM | |
2399 (Vread_buffer_stream), | |
2400 c); | |
2401 QUIT; | |
2402 } | |
2403 if (c < 0) | |
2404 return Fsignal(Qend_of_file, | |
2405 list1(READCHARFUN_MAYBE(readcharfun))); | |
2406 | |
2407 /* If purifying, and string starts with \ newline, | |
2408 return zero instead. This is for doc strings | |
2409 that we are really going to find in lib-src/DOC.nn.nn */ | |
2410 if (purify_flag && NILP(Vinternal_doc_file_name) | |
2411 && cancel) | |
2412 return Qzero; | |
2413 | |
2414 Lstream_flush(XLSTREAM(Vread_buffer_stream)); | |
2415 return make_string(resizing_buffer_stream_ptr | |
2416 (XLSTREAM(Vread_buffer_stream)), | |
2417 Lstream_byte_count(XLSTREAM(Vread_buffer_stream))); | |
2418 } | |
2419 | |
2420 static Lisp_Object | |
2421 read_raw_string (Lisp_Object readcharfun) | |
2422 { | |
2423 Ichar c; | |
2424 Ichar permit_unicode = 0; | |
2425 | |
2426 do { | |
2427 c = reader_nextchar(readcharfun); | |
2428 switch (c) { | |
2429 /* #r:engine"my sexy raw string" -- raw string w/ flags*/ | |
2430 /* case ':': */ | |
2431 /* #ru"Hi there\u20AC \U000020AC" -- raw string, honouring Unicode. */ | |
2432 case 'u': | |
2433 case 'U': | |
2434 permit_unicode = c; | |
2435 continue; | |
2436 | |
2437 /* #r"my raw string" -- raw string */ | |
2438 case '\"': | |
2439 return read_string(readcharfun, '\"', 1, permit_unicode); | |
2440 /* invalid syntax */ | |
2441 default: | |
2442 { | |
2443 if (permit_unicode) | |
2444 { | |
2445 unreadchar(readcharfun, permit_unicode); | |
2446 } | |
2447 unreadchar(readcharfun, c); | |
2448 return Fsignal(Qinvalid_read_syntax, | |
2449 list1(build_string | |
2450 ("unrecognized raw string syntax"))); | |
2451 } | |
2452 } | |
2453 } while (1); | |
2454 } | |
2455 | |
428 | 2456 /* Read the next Lisp object from the stream READCHARFUN and return it. |
2457 If the return value is a cons whose car is Qunbound, then read1() | |
2458 encountered a misplaced token (e.g. a right bracket, right paren, | |
2459 or dot followed by a non-number). To filter this stuff out, | |
2460 use read0(). */ | |
2461 | |
2462 static Lisp_Object | |
2463 read1 (Lisp_Object readcharfun) | |
2464 { | |
867 | 2465 Ichar c; |
428 | 2466 |
2467 retry: | |
2468 c = reader_nextchar (readcharfun); | |
2469 | |
2470 switch (c) | |
2471 { | |
2472 case '(': | |
2473 { | |
2474 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */ | |
2475 /* if this is disabled, then other code in eval.c must be enabled */ | |
867 | 2476 Ichar ch = reader_nextchar (readcharfun); |
428 | 2477 switch (ch) |
2478 { | |
2479 case '`': | |
2480 { | |
2481 Lisp_Object tem; | |
853 | 2482 int speccount = internal_bind_int (&old_backquote_flag, |
2483 1 + old_backquote_flag); | |
428 | 2484 tem = read0 (readcharfun); |
771 | 2485 unbind_to (speccount); |
428 | 2486 ch = reader_nextchar (readcharfun); |
2487 if (ch != ')') | |
2488 { | |
2489 unreadchar (readcharfun, ch); | |
2490 return Fsignal (Qinvalid_read_syntax, | |
771 | 2491 list1 (build_msg_string |
428 | 2492 ("Weird old-backquote syntax"))); |
2493 } | |
2494 return list2 (Qbacktick, tem); | |
2495 } | |
2496 case ',': | |
2497 { | |
2498 if (old_backquote_flag) | |
2499 { | |
2500 Lisp_Object tem, comma_type; | |
2501 ch = readchar (readcharfun); | |
2502 if (ch == '@') | |
2503 comma_type = Qcomma_at; | |
2504 else | |
2505 { | |
2506 if (ch >= 0) | |
2507 unreadchar (readcharfun, ch); | |
2508 comma_type = Qcomma; | |
2509 } | |
2510 tem = read0 (readcharfun); | |
2511 ch = reader_nextchar (readcharfun); | |
2512 if (ch != ')') | |
2513 { | |
2514 unreadchar (readcharfun, ch); | |
2515 return Fsignal (Qinvalid_read_syntax, | |
771 | 2516 list1 (build_msg_string |
428 | 2517 ("Weird old-backquote syntax"))); |
2518 } | |
2519 return list2 (comma_type, tem); | |
2520 } | |
2521 else | |
2522 { | |
2523 unreadchar (readcharfun, ch); | |
2524 #if 0 | |
2525 return Fsignal (Qinvalid_read_syntax, | |
771 | 2526 list1 (build_msg_string ("Comma outside of backquote"))); |
428 | 2527 #else |
2528 /* #### - yuck....but this is reverse compatible. */ | |
2529 /* mostly this is required by edebug, which does its own | |
2530 annotated reading. We need to have an annotated_read | |
2531 function that records (with markers) the buffer | |
2532 positions of the elements that make up lists, then that | |
2533 can be used in edebug and bytecomp and the check above | |
2534 can go back in. --Stig */ | |
2535 break; | |
2536 #endif | |
2537 } | |
2538 } | |
2539 default: | |
2540 unreadchar (readcharfun, ch); | |
2541 } /* switch(ch) */ | |
2542 #endif /* old backquote crap... */ | |
2543 return read_list (readcharfun, ')', 1, 1); | |
2544 } | |
2545 case '[': | |
2546 return read_vector (readcharfun, ']'); | |
2547 | |
2548 case ')': | |
2549 case ']': | |
2550 /* #### - huh? these don't do what they seem... */ | |
2551 return noseeum_cons (Qunbound, make_char (c)); | |
2552 case '.': | |
2553 { | |
2554 /* If a period is followed by a number, then we should read it | |
2555 as a floating point number. Otherwise, it denotes a dotted | |
2556 pair. | |
2557 */ | |
2558 c = readchar (readcharfun); | |
2559 unreadchar (readcharfun, c); | |
2560 | |
867 | 2561 /* Can't use isdigit on Ichars */ |
428 | 2562 if (c < '0' || c > '9') |
2563 return noseeum_cons (Qunbound, make_char ('.')); | |
2564 | |
2565 /* Note that read_atom will loop | |
2566 at least once, assuring that we will not try to UNREAD | |
2567 two characters in a row. | |
2568 (I think this doesn't matter anymore because there should | |
2569 be no more danger in unreading multiple characters) */ | |
2570 return read_atom (readcharfun, '.', 0); | |
2571 } | |
2572 | |
2573 case '#': | |
2574 { | |
2575 c = readchar (readcharfun); | |
2576 switch (c) | |
2577 { | |
2578 #if 0 /* FSFmacs silly char-table syntax */ | |
2579 case '^': | |
2580 #endif | |
2581 #if 0 /* FSFmacs silly bool-vector syntax */ | |
2582 case '&': | |
2583 #endif | |
2584 /* "#["-- byte-code constant syntax */ | |
2585 /* purecons #[...] syntax */ | |
2586 case '[': return read_compiled_function (readcharfun, ']' | |
2587 /*, purify_flag */ ); | |
2588 /* "#:"-- gensym syntax */ | |
2589 case ':': return read_atom (readcharfun, -1, 1); | |
2590 /* #'x => (function x) */ | |
2591 case '\'': return list2 (Qfunction, read0 (readcharfun)); | |
2592 #if 0 | |
2593 /* RMS uses this syntax for fat-strings. | |
2594 If we use it for vectors, then obscure bugs happen. | |
2595 */ | |
2596 /* "#(" -- Scheme/CL vector syntax */ | |
2597 case '(': return read_vector (readcharfun, ')'); | |
2598 #endif | |
2599 #if 0 /* FSFmacs */ | |
2600 case '(': | |
2601 { | |
2602 Lisp_Object tmp; | |
2603 struct gcpro gcpro1; | |
2604 | |
2605 /* Read the string itself. */ | |
2606 tmp = read1 (readcharfun); | |
2607 if (!STRINGP (tmp)) | |
2608 { | |
2609 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp))) | |
853 | 2610 free_cons (tmp); |
428 | 2611 return Fsignal (Qinvalid_read_syntax, |
2612 list1 (build_string ("#"))); | |
2613 } | |
2614 GCPRO1 (tmp); | |
2615 /* Read the intervals and their properties. */ | |
2616 while (1) | |
2617 { | |
2618 Lisp_Object beg, end, plist; | |
867 | 2619 Ichar ch; |
428 | 2620 int invalid = 0; |
2621 | |
2622 beg = read1 (readcharfun); | |
2623 if (CONSP (beg) && UNBOUNDP (XCAR (beg))) | |
2624 { | |
2625 ch = XCHAR (XCDR (beg)); | |
853 | 2626 free_cons (beg); |
428 | 2627 if (ch == ')') |
2628 break; | |
2629 else | |
2630 invalid = 1; | |
2631 } | |
2632 if (!invalid) | |
2633 { | |
2634 end = read1 (readcharfun); | |
2635 if (CONSP (end) && UNBOUNDP (XCAR (end))) | |
2636 { | |
853 | 2637 free_cons (end); |
428 | 2638 invalid = 1; |
2639 } | |
2640 } | |
2641 if (!invalid) | |
2642 { | |
2643 plist = read1 (readcharfun); | |
2644 if (CONSP (plist) && UNBOUNDP (XCAR (plist))) | |
2645 { | |
853 | 2646 free_cons (plist); |
428 | 2647 invalid = 1; |
2648 } | |
2649 } | |
2650 if (invalid) | |
2651 RETURN_UNGCPRO | |
2652 (Fsignal (Qinvalid_read_syntax, | |
2653 list2 | |
771 | 2654 (build_msg_string ("invalid string property list"), |
428 | 2655 XCDR (plist)))); |
2656 Fset_text_properties (beg, end, plist, tmp); | |
2657 } | |
2658 UNGCPRO; | |
2659 return tmp; | |
2660 } | |
2661 #endif /* 0 */ | |
2662 case '@': | |
2663 { | |
2664 /* #@NUMBER is used to skip NUMBER following characters. | |
2665 That's used in .elc files to skip over doc strings | |
2666 and function definitions. */ | |
2667 int i, nskip = 0; | |
2668 | |
2669 /* Read a decimal integer. */ | |
2670 while ((c = readchar (readcharfun)) >= 0 | |
2671 && c >= '0' && c <= '9') | |
2672 nskip = (10 * nskip) + (c - '0'); | |
2673 if (c >= 0) | |
2674 unreadchar (readcharfun, c); | |
2675 | |
2676 /* FSF has code here that maybe caches the skipped | |
2677 string. See above for why this is totally | |
2678 losing. We handle this differently. */ | |
2679 | |
2680 /* Skip that many characters. */ | |
2681 for (i = 0; i < nskip && c >= 0; i++) | |
2682 c = readchar (readcharfun); | |
2683 | |
2684 goto retry; | |
2685 } | |
2686 case '$': return Vload_file_name_internal; | |
2687 /* bit vectors */ | |
2688 case '*': return read_bit_vector (readcharfun); | |
2689 /* #o10 => 8 -- octal constant syntax */ | |
2690 case 'o': return read_integer (readcharfun, 8); | |
2691 /* #xdead => 57005 -- hex constant syntax */ | |
2692 case 'x': return read_integer (readcharfun, 16); | |
2693 /* #b010 => 2 -- binary constant syntax */ | |
2694 case 'b': return read_integer (readcharfun, 2); | |
3543 | 2695 /* #r"raw\stringt" -- raw string syntax */ |
2696 case 'r': return read_raw_string(readcharfun); | |
428 | 2697 /* #s(foobar key1 val1 key2 val2) -- structure syntax */ |
2698 case 's': return read_structure (readcharfun); | |
2699 case '<': | |
2700 { | |
2701 unreadchar (readcharfun, c); | |
2702 return Fsignal (Qinvalid_read_syntax, | |
771 | 2703 list1 (build_msg_string ("Cannot read unreadable object"))); |
428 | 2704 } |
2705 #ifdef FEATUREP_SYNTAX | |
2706 case '+': | |
2707 case '-': | |
2708 { | |
456 | 2709 Lisp_Object feature_exp, obj, tem; |
428 | 2710 struct gcpro gcpro1, gcpro2; |
2711 | |
456 | 2712 feature_exp = read0(readcharfun); |
428 | 2713 obj = read0(readcharfun); |
2714 | |
2715 /* the call to `featurep' may GC. */ | |
456 | 2716 GCPRO2 (feature_exp, obj); |
2717 tem = call1 (Qfeaturep, feature_exp); | |
428 | 2718 UNGCPRO; |
2719 | |
2720 if (c == '+' && NILP(tem)) goto retry; | |
2721 if (c == '-' && !NILP(tem)) goto retry; | |
2722 return obj; | |
2723 } | |
2724 #endif | |
2725 case '0': case '1': case '2': case '3': case '4': | |
2726 case '5': case '6': case '7': case '8': case '9': | |
2727 /* Reader forms that can reuse previously read objects. */ | |
2728 { | |
2729 int n = 0; | |
2730 Lisp_Object found; | |
2731 | |
2732 /* Using read_integer() here is impossible, because it | |
2733 chokes on `='. Using parse_integer() is too hard. | |
2734 So we simply read it in, and ignore overflows, which | |
2735 is safe. */ | |
2736 while (c >= '0' && c <= '9') | |
2737 { | |
2738 n *= 10; | |
2739 n += c - '0'; | |
2740 c = readchar (readcharfun); | |
2741 } | |
2742 found = assq_no_quit (make_int (n), Vread_objects); | |
2743 if (c == '=') | |
2744 { | |
2745 /* #n=object returns object, but associates it with | |
2746 n for #n#. */ | |
2747 Lisp_Object obj; | |
2748 if (CONSP (found)) | |
2749 return Fsignal (Qinvalid_read_syntax, | |
771 | 2750 list2 (build_msg_string |
428 | 2751 ("Multiply defined symbol label"), |
2752 make_int (n))); | |
2753 obj = read0 (readcharfun); | |
2754 Vread_objects = Fcons (Fcons (make_int (n), obj), | |
2755 Vread_objects); | |
2756 return obj; | |
2757 } | |
2758 else if (c == '#') | |
2759 { | |
2760 /* #n# returns a previously read object. */ | |
2761 if (CONSP (found)) | |
2762 return XCDR (found); | |
2763 else | |
2764 return Fsignal (Qinvalid_read_syntax, | |
771 | 2765 list2 (build_msg_string |
428 | 2766 ("Undefined symbol label"), |
2767 make_int (n))); | |
2768 } | |
2769 return Fsignal (Qinvalid_read_syntax, | |
2770 list1 (build_string ("#"))); | |
2771 } | |
2772 default: | |
2773 { | |
2774 unreadchar (readcharfun, c); | |
2775 return Fsignal (Qinvalid_read_syntax, | |
2776 list1 (build_string ("#"))); | |
2777 } | |
2778 } | |
2779 } | |
2780 | |
2781 /* Quote */ | |
2782 case '\'': return list2 (Qquote, read0 (readcharfun)); | |
2783 | |
2784 #ifdef LISP_BACKQUOTES | |
2785 case '`': | |
2786 { | |
2787 Lisp_Object tem; | |
853 | 2788 int speccount = internal_bind_int (&new_backquote_flag, |
2789 1 + new_backquote_flag); | |
428 | 2790 tem = read0 (readcharfun); |
771 | 2791 unbind_to (speccount); |
428 | 2792 return list2 (Qbackquote, tem); |
2793 } | |
2794 | |
2795 case ',': | |
2796 { | |
2797 if (new_backquote_flag) | |
2798 { | |
2799 Lisp_Object comma_type = Qnil; | |
2800 int ch = readchar (readcharfun); | |
2801 | |
2802 if (ch == '@') | |
2803 comma_type = Qcomma_at; | |
2804 else if (ch == '.') | |
2805 comma_type = Qcomma_dot; | |
2806 else | |
2807 { | |
2808 if (ch >= 0) | |
2809 unreadchar (readcharfun, ch); | |
2810 comma_type = Qcomma; | |
2811 } | |
2812 return list2 (comma_type, read0 (readcharfun)); | |
2813 } | |
2814 else | |
2815 { | |
2816 /* YUCK. 99.999% backwards compatibility. The Right | |
2817 Thing(tm) is to signal an error here, because it's | |
2818 really invalid read syntax. Instead, this permits | |
2819 commas to begin symbols (unless they're inside | |
2820 backquotes). If an error is signalled here in the | |
2821 future, then commas should be invalid read syntax | |
2822 outside of backquotes anywhere they're found (i.e. | |
2823 they must be quoted in symbols) -- Stig */ | |
2824 return read_atom (readcharfun, c, 0); | |
2825 } | |
2826 } | |
2827 #endif | |
2828 | |
2829 case '?': | |
2830 { | |
2831 /* Evil GNU Emacs "character" (ie integer) syntax */ | |
2832 c = readchar (readcharfun); | |
2833 if (c < 0) | |
2834 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun))); | |
2835 | |
2836 if (c == '\\') | |
2837 c = read_escape (readcharfun); | |
4439 | 2838 if (c < 0) |
2839 return Fsignal (Qinvalid_read_syntax, list1 (READCHARFUN_MAYBE (readcharfun))); | |
428 | 2840 return make_char (c); |
2841 } | |
2842 | |
2843 case '\"': | |
3543 | 2844 /* String */ |
2845 return read_string(readcharfun, '\"', 0, 1); | |
428 | 2846 |
2847 default: | |
2848 { | |
2849 /* Ignore whitespace and control characters */ | |
2850 if (c <= 040) | |
2851 goto retry; | |
2852 return read_atom (readcharfun, c, 0); | |
2853 } | |
2854 } | |
2855 } | |
2856 | |
2857 | |
2858 | |
2859 #define LEAD_INT 1 | |
2860 #define DOT_CHAR 2 | |
2861 #define TRAIL_INT 4 | |
2862 #define E_CHAR 8 | |
2863 #define EXP_INT 16 | |
2864 | |
2865 int | |
442 | 2866 isfloat_string (const char *cp) |
428 | 2867 { |
2868 int state = 0; | |
867 | 2869 const Ibyte *ucp = (const Ibyte *) cp; |
428 | 2870 |
2871 if (*ucp == '+' || *ucp == '-') | |
2872 ucp++; | |
2873 | |
2874 if (*ucp >= '0' && *ucp <= '9') | |
2875 { | |
2876 state |= LEAD_INT; | |
2877 while (*ucp >= '0' && *ucp <= '9') | |
2878 ucp++; | |
2879 } | |
2880 if (*ucp == '.') | |
2881 { | |
2882 state |= DOT_CHAR; | |
2883 ucp++; | |
2884 } | |
2885 if (*ucp >= '0' && *ucp <= '9') | |
2886 { | |
2887 state |= TRAIL_INT; | |
2888 while (*ucp >= '0' && *ucp <= '9') | |
2889 ucp++; | |
2890 } | |
2891 if (*ucp == 'e' || *ucp == 'E') | |
2892 { | |
2893 state |= E_CHAR; | |
2894 ucp++; | |
2895 if ((*ucp == '+') || (*ucp == '-')) | |
2896 ucp++; | |
2897 } | |
2898 | |
2899 if (*ucp >= '0' && *ucp <= '9') | |
2900 { | |
2901 state |= EXP_INT; | |
2902 while (*ucp >= '0' && *ucp <= '9') | |
2903 ucp++; | |
2904 } | |
2905 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n') | |
2906 || (*ucp == '\r') || (*ucp == '\f')) | |
2907 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) | |
2908 || state == (DOT_CHAR|TRAIL_INT) | |
2909 || state == (LEAD_INT|E_CHAR|EXP_INT) | |
2910 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) | |
2911 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
2912 } | |
1983 | 2913 |
2914 #ifdef HAVE_RATIO | |
2915 int | |
2916 isratio_string (const char *cp) | |
2917 { | |
2010 | 2918 /* Possible minus/plus sign */ |
2919 if (*cp == '-' || *cp == '+') | |
1983 | 2920 cp++; |
2921 | |
2922 /* Numerator */ | |
2923 if (*cp < '0' || *cp > '9') | |
2924 return 0; | |
2925 | |
2926 do { | |
2927 cp++; | |
2928 } while (*cp >= '0' && *cp <= '9'); | |
2929 | |
2930 /* Slash */ | |
2931 if (*cp++ != '/') | |
2932 return 0; | |
2933 | |
2934 /* Denominator */ | |
2935 if (*cp < '0' || *cp > '9') | |
2936 return 0; | |
2937 | |
2938 do { | |
2939 cp++; | |
2940 } while (*cp >= '0' && *cp <= '9'); | |
2941 | |
2942 return *cp == '\0' || *cp == ' ' || *cp =='\t' || *cp == '\n' || | |
2943 *cp == '\r' || *cp == '\f'; | |
2944 } | |
2945 #endif | |
428 | 2946 |
2947 static void * | |
2948 sequence_reader (Lisp_Object readcharfun, | |
867 | 2949 Ichar terminator, |
428 | 2950 void *state, |
2951 void * (*conser) (Lisp_Object readcharfun, | |
2952 void *state, Charcount len)) | |
2953 { | |
2954 Charcount len; | |
2955 | |
2956 for (len = 0; ; len++) | |
2957 { | |
867 | 2958 Ichar ch; |
428 | 2959 |
2960 QUIT; | |
2961 ch = reader_nextchar (readcharfun); | |
2962 | |
2963 if (ch == terminator) | |
2964 return state; | |
2965 else | |
2966 unreadchar (readcharfun, ch); | |
2967 #ifdef FEATUREP_SYNTAX | |
2968 if (ch == ']') | |
442 | 2969 read_syntax_error ("\"]\" in a list"); |
428 | 2970 else if (ch == ')') |
442 | 2971 read_syntax_error ("\")\" in a vector"); |
428 | 2972 #endif |
2973 state = ((conser) (readcharfun, state, len)); | |
2974 } | |
2975 } | |
2976 | |
2977 | |
2978 struct read_list_state | |
2979 { | |
2980 Lisp_Object head; | |
2981 Lisp_Object tail; | |
2982 int length; | |
2983 int allow_dotted_lists; | |
867 | 2984 Ichar terminator; |
428 | 2985 }; |
2986 | |
2987 static void * | |
2286 | 2988 read_list_conser (Lisp_Object readcharfun, void *state, Charcount UNUSED (len)) |
428 | 2989 { |
2990 struct read_list_state *s = (struct read_list_state *) state; | |
2991 Lisp_Object elt; | |
2992 | |
2993 elt = read1 (readcharfun); | |
2994 | |
2995 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2996 { | |
2997 Lisp_Object tem = elt; | |
867 | 2998 Ichar ch; |
428 | 2999 |
3000 elt = XCDR (elt); | |
853 | 3001 free_cons (tem); |
428 | 3002 tem = Qnil; |
3003 ch = XCHAR (elt); | |
3004 #ifdef FEATUREP_SYNTAX | |
3005 if (ch == s->terminator) /* deal with #+, #- reader macros */ | |
3006 { | |
3007 unreadchar (readcharfun, s->terminator); | |
3008 goto done; | |
3009 } | |
3010 else if (ch == ']') | |
442 | 3011 read_syntax_error ("']' in a list"); |
428 | 3012 else if (ch == ')') |
442 | 3013 read_syntax_error ("')' in a vector"); |
428 | 3014 else |
3015 #endif | |
3016 if (ch != '.') | |
563 | 3017 signal_error (Qinternal_error, "BUG! Internal reader error", elt); |
428 | 3018 else if (!s->allow_dotted_lists) |
442 | 3019 read_syntax_error ("\".\" in a vector"); |
428 | 3020 else |
3021 { | |
3022 if (!NILP (s->tail)) | |
3023 XCDR (s->tail) = read0 (readcharfun); | |
3024 else | |
3025 s->head = read0 (readcharfun); | |
3026 elt = read1 (readcharfun); | |
3027 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
3028 { | |
3029 ch = XCHAR (XCDR (elt)); | |
853 | 3030 free_cons (elt); |
428 | 3031 if (ch == s->terminator) |
3032 { | |
3033 unreadchar (readcharfun, s->terminator); | |
3034 goto done; | |
3035 } | |
3036 } | |
442 | 3037 read_syntax_error (". in wrong context"); |
428 | 3038 } |
3039 } | |
3040 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3041 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 3042 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset)) |
3043 { | |
3044 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt))) | |
3045 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt)); | |
3046 else | |
3047 Vcurrent_compiled_function_annotation = elt; | |
3048 } | |
3049 #endif | |
3050 | |
3051 elt = Fcons (elt, Qnil); | |
3052 if (!NILP (s->tail)) | |
3053 XCDR (s->tail) = elt; | |
3054 else | |
3055 s->head = elt; | |
3056 s->tail = elt; | |
3057 done: | |
3058 s->length++; | |
3059 return s; | |
3060 } | |
3061 | |
3062 | |
814 | 3063 /* allow_dotted_lists means that something like (foo bar . baz) |
3064 is acceptable. If -1, means check for starting with defun | |
3065 and make structure pure. (not implemented, probably for very | |
3066 good reasons) | |
3067 | |
3068 If check_for_doc_references, look for (#$ . INT) doc references | |
3069 in the list and record if load_force_doc_strings is non-zero. | |
3070 (Such doc references will be destroyed during the loadup phase | |
3071 by replacing with Qzero, because Snarf-documentation will fill | |
3072 them in again.) | |
3073 | |
3074 WARNING: If you set this, you sure as hell better not call | |
3075 free_list() on the returned list here. | |
3076 */ | |
428 | 3077 |
3078 static Lisp_Object | |
3079 read_list (Lisp_Object readcharfun, | |
867 | 3080 Ichar terminator, |
428 | 3081 int allow_dotted_lists, |
3082 int check_for_doc_references) | |
3083 { | |
3084 struct read_list_state s; | |
3085 struct gcpro gcpro1, gcpro2; | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3086 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 3087 Lisp_Object old_compiled_function_annotation = |
3088 Vcurrent_compiled_function_annotation; | |
3089 #endif | |
3090 | |
3091 s.head = Qnil; | |
3092 s.tail = Qnil; | |
3093 s.length = 0; | |
3094 s.allow_dotted_lists = allow_dotted_lists; | |
3095 s.terminator = terminator; | |
3096 GCPRO2 (s.head, s.tail); | |
3097 | |
3098 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3099 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 3100 Vcurrent_compiled_function_annotation = old_compiled_function_annotation; |
3101 #endif | |
3102 | |
3103 if ((purify_flag || load_force_doc_strings) && check_for_doc_references) | |
3104 { | |
3105 /* check now for any doc string references and record them | |
3106 for later. */ | |
3107 Lisp_Object tail; | |
3108 | |
3109 /* We might be dealing with an imperfect list so don't | |
3110 use LIST_LOOP */ | |
3111 for (tail = s.head; CONSP (tail); tail = XCDR (tail)) | |
3112 { | |
3113 Lisp_Object holding_cons = Qnil; | |
3114 | |
3115 { | |
3116 Lisp_Object elem = XCAR (tail); | |
3117 /* elem might be (#$ . INT) ... */ | |
3118 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3119 holding_cons = tail; | |
3120 /* or it might be (quote (#$ . INT)) i.e. | |
3121 (quote . ((#$ . INT) . nil)) in the case of | |
3122 `autoload' (autoload evaluates its arguments, while | |
3123 `defvar', `defun', etc. don't). */ | |
3124 if (CONSP (elem) && EQ (XCAR (elem), Qquote) | |
3125 && CONSP (XCDR (elem))) | |
3126 { | |
3127 elem = XCAR (XCDR (elem)); | |
3128 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3129 holding_cons = XCDR (XCAR (tail)); | |
3130 } | |
3131 } | |
3132 | |
3133 if (CONSP (holding_cons)) | |
3134 { | |
3135 if (purify_flag) | |
3136 { | |
3137 if (NILP (Vinternal_doc_file_name)) | |
3138 /* We have not yet called Snarf-documentation, so | |
3139 assume this file is described in the DOC file | |
3140 and Snarf-documentation will fill in the right | |
3141 value later. For now, replace the whole list | |
3142 with 0. */ | |
3143 XCAR (holding_cons) = Qzero; | |
3144 else | |
3145 /* We have already called Snarf-documentation, so | |
3146 make a relative file name for this file, so it | |
3147 can be found properly in the installed Lisp | |
3148 directory. We don't use Fexpand_file_name | |
3149 because that would make the directory absolute | |
3150 now. */ | |
3151 XCAR (XCAR (holding_cons)) = | |
3152 concat2 (build_string ("../lisp/"), | |
3153 Ffile_name_nondirectory | |
3154 (Vload_file_name_internal)); | |
3155 } | |
3156 else | |
3157 /* Not pure. Just add to Vload_force_doc_string_list, | |
3158 and the string will be filled in properly in | |
3159 load_force_doc_string_unwind(). */ | |
3160 Vload_force_doc_string_list = | |
3161 /* We pass the cons that holds the (#$ . INT) so we | |
3162 can modify it in-place. */ | |
3163 Fcons (holding_cons, Vload_force_doc_string_list); | |
3164 } | |
3165 } | |
3166 } | |
3167 | |
3168 UNGCPRO; | |
3169 return s.head; | |
3170 } | |
3171 | |
3172 static Lisp_Object | |
3173 read_vector (Lisp_Object readcharfun, | |
867 | 3174 Ichar terminator) |
428 | 3175 { |
3176 Lisp_Object tem; | |
3177 Lisp_Object *p; | |
3178 int len; | |
3179 int i; | |
3180 struct read_list_state s; | |
3181 struct gcpro gcpro1, gcpro2; | |
3182 | |
3183 s.head = Qnil; | |
3184 s.tail = Qnil; | |
3185 s.length = 0; | |
3186 s.allow_dotted_lists = 0; | |
3187 GCPRO2 (s.head, s.tail); | |
3188 | |
3189 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3190 | |
3191 UNGCPRO; | |
3192 tem = s.head; | |
3193 len = XINT (Flength (tem)); | |
3194 | |
814 | 3195 s.head = make_vector (len, Qnil); |
428 | 3196 |
3197 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); | |
3198 i < len; | |
3199 i++, p++) | |
3200 { | |
853 | 3201 Lisp_Object otem = tem; |
428 | 3202 tem = Fcar (tem); |
3203 *p = tem; | |
853 | 3204 tem = XCDR (otem); |
428 | 3205 free_cons (otem); |
3206 } | |
3207 return s.head; | |
3208 } | |
3209 | |
3210 static Lisp_Object | |
867 | 3211 read_compiled_function (Lisp_Object readcharfun, Ichar terminator) |
428 | 3212 { |
3213 /* Accept compiled functions at read-time so that we don't | |
3214 have to build them at load-time. */ | |
3215 Lisp_Object stuff; | |
3216 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1]; | |
3217 struct gcpro gcpro1; | |
3218 int len; | |
3219 int iii; | |
3220 int saw_a_doc_ref = 0; | |
3221 | |
3222 /* Note: we tell read_list not to search for doc references | |
3223 because we need to handle the "doc reference" for the | |
3224 instructions and constants differently. */ | |
3225 stuff = read_list (readcharfun, terminator, 0, 0); | |
3226 len = XINT (Flength (stuff)); | |
3227 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1) | |
3228 return | |
442 | 3229 continuable_read_syntax_error ("#[...] used with wrong number of elements"); |
428 | 3230 |
3231 for (iii = 0; CONSP (stuff); iii++) | |
3232 { | |
853 | 3233 Lisp_Object victim = stuff; |
428 | 3234 make_byte_code_args[iii] = Fcar (stuff); |
3235 if ((purify_flag || load_force_doc_strings) | |
3236 && CONSP (make_byte_code_args[iii]) | |
3237 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) | |
3238 { | |
3239 if (purify_flag && iii == COMPILED_DOC_STRING) | |
3240 { | |
3241 /* same as in read_list(). */ | |
3242 if (NILP (Vinternal_doc_file_name)) | |
3243 make_byte_code_args[iii] = Qzero; | |
3244 else | |
3245 XCAR (make_byte_code_args[iii]) = | |
3246 concat2 (build_string ("../lisp/"), | |
3247 Ffile_name_nondirectory | |
3248 (Vload_file_name_internal)); | |
3249 } | |
3250 else | |
3251 saw_a_doc_ref = 1; | |
3252 } | |
3253 stuff = Fcdr (stuff); | |
3254 free_cons (victim); | |
3255 } | |
3256 GCPRO1 (make_byte_code_args[0]); | |
3257 gcpro1.nvars = len; | |
3258 | |
3259 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
3260 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2])) | |
3261 ebolify_bytecode_constants (make_byte_code_args[2]); | |
3262 | |
3263 /* make-byte-code looks at purify_flag, which should have the same | |
3264 * value as our "read-pure" argument */ | |
3265 stuff = Fmake_byte_code (len, make_byte_code_args); | |
3266 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20); | |
3267 if (saw_a_doc_ref) | |
3268 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list); | |
3269 UNGCPRO; | |
3270 return stuff; | |
3271 } | |
3272 | |
3273 | |
3274 | |
3275 void | |
3276 init_lread (void) | |
3277 { | |
3278 Vvalues = Qnil; | |
3279 | |
3280 load_in_progress = 0; | |
3281 | |
3282 Vload_descriptor_list = Qnil; | |
3283 | |
3284 /* kludge: locate-file does not work for a null load-path, even if | |
3285 the file name is absolute. */ | |
3286 | |
3287 Vload_path = Fcons (build_string (""), Qnil); | |
3288 | |
3289 /* This used to get initialized in init_lread because all streams | |
3290 got closed when dumping occurs. This is no longer true -- | |
3291 Vread_buffer_stream is a resizing output stream, and there is no | |
3292 reason to close it at dump-time. | |
3293 | |
3294 Vread_buffer_stream is set to Qnil in vars_of_lread, and this | |
3295 will initialize it only once, at dump-time. */ | |
3296 if (NILP (Vread_buffer_stream)) | |
3297 Vread_buffer_stream = make_resizing_buffer_output_stream (); | |
3298 | |
3299 Vload_force_doc_string_list = Qnil; | |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3300 |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3301 Vload_file_name_internal = Qnil; |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3302 Vload_file_name = Qnil; |
428 | 3303 } |
3304 | |
3305 void | |
3306 syms_of_lread (void) | |
3307 { | |
3308 DEFSUBR (Fread); | |
3309 DEFSUBR (Fread_from_string); | |
3310 DEFSUBR (Fload_internal); | |
3311 DEFSUBR (Flocate_file); | |
3312 DEFSUBR (Flocate_file_clear_hashing); | |
3313 DEFSUBR (Feval_buffer); | |
3314 DEFSUBR (Feval_region); | |
3315 | |
563 | 3316 DEFSYMBOL (Qstandard_input); |
3317 DEFSYMBOL (Qread_char); | |
3318 DEFSYMBOL (Qload); | |
1292 | 3319 DEFSYMBOL (Qload_internal); |
563 | 3320 DEFSYMBOL (Qfset); |
428 | 3321 |
3322 #ifdef LISP_BACKQUOTES | |
563 | 3323 DEFSYMBOL (Qbackquote); |
428 | 3324 defsymbol (&Qbacktick, "`"); |
3325 defsymbol (&Qcomma, ","); | |
3326 defsymbol (&Qcomma_at, ",@"); | |
3327 defsymbol (&Qcomma_dot, ",."); | |
3328 #endif | |
3329 | |
563 | 3330 DEFSYMBOL (Qexists); |
3331 DEFSYMBOL (Qreadable); | |
3332 DEFSYMBOL (Qwritable); | |
3333 DEFSYMBOL (Qexecutable); | |
428 | 3334 } |
3335 | |
3336 void | |
3337 structure_type_create (void) | |
3338 { | |
3339 the_structure_type_dynarr = Dynarr_new (structure_type); | |
3340 } | |
3341 | |
3342 void | |
3343 reinit_vars_of_lread (void) | |
3344 { | |
3345 Vread_buffer_stream = Qnil; | |
3346 staticpro_nodump (&Vread_buffer_stream); | |
3347 } | |
3348 | |
3349 void | |
3350 vars_of_lread (void) | |
3351 { | |
3352 DEFVAR_LISP ("values", &Vvalues /* | |
3353 List of values of all expressions which were read, evaluated and printed. | |
3354 Order is reverse chronological. | |
3355 */ ); | |
3356 | |
3357 DEFVAR_LISP ("standard-input", &Vstandard_input /* | |
3358 Stream for read to get input from. | |
3359 See documentation of `read' for possible values. | |
3360 */ ); | |
3361 Vstandard_input = Qt; | |
3362 | |
3363 DEFVAR_LISP ("load-path", &Vload_path /* | |
3364 *List of directories to search for files to load. | |
3365 Each element is a string (directory name) or nil (try default directory). | |
3366 | |
3367 Note that the elements of this list *may not* begin with "~", so you must | |
3368 call `expand-file-name' on them before adding them to this list. | |
3369 | |
3370 Initialized based on EMACSLOADPATH environment variable, if any, | |
3371 otherwise to default specified in by file `paths.h' when XEmacs was built. | |
3372 If there were no paths specified in `paths.h', then XEmacs chooses a default | |
3373 value for this variable by looking around in the file-system near the | |
3374 directory in which the XEmacs executable resides. | |
3375 */ ); | |
3376 Vload_path = Qnil; | |
3377 | |
3378 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path, | |
3379 "*Location of lisp files to be used when dumping ONLY."); */ | |
3380 | |
3381 DEFVAR_BOOL ("load-in-progress", &load_in_progress /* | |
3382 Non-nil iff inside of `load'. | |
3383 */ ); | |
3384 | |
2548 | 3385 DEFVAR_LISP ("load-suppress-alist", &Vload_suppress_alist /* |
3386 An alist of expressions controlling whether particular files can be loaded. | |
3387 Each element looks like (FILENAME EXPR). | |
3388 FILENAME should be a full pathname, but without the .el suffix. | |
3389 When `load' is run and is about to load the specified file, it evaluates | |
3390 the form to determine if the file can be loaded. | |
3391 This variable is normally initialized automatically. | |
3392 */ ); | |
3393 Vload_suppress_alist = Qnil; | |
3394 | |
428 | 3395 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /* |
3396 An alist of expressions to be evalled when particular files are loaded. | |
3397 Each element looks like (FILENAME FORMS...). | |
3398 When `load' is run and the file-name argument is FILENAME, | |
3399 the FORMS in the corresponding element are executed at the end of loading. | |
3400 | |
3401 FILENAME must match exactly! Normally FILENAME is the name of a library, | |
3402 with no directory specified, since that is how `load' is normally called. | |
3403 An error in FORMS does not undo the load, | |
3404 but does prevent execution of the rest of the FORMS. | |
3405 */ ); | |
3406 Vafter_load_alist = Qnil; | |
3407 | |
3408 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /* | |
3409 *Whether `load' should check whether the source is newer than the binary. | |
3410 If this variable is true, then when a `.elc' file is being loaded and the | |
3411 corresponding `.el' is newer, a warning message will be printed. | |
3412 */ ); | |
1261 | 3413 load_warn_when_source_newer = 1; |
428 | 3414 |
3415 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /* | |
3416 *Whether `load' should warn when loading a `.el' file instead of an `.elc'. | |
3417 If this variable is true, then when `load' is called with a filename without | |
3418 an extension, and the `.elc' version doesn't exist but the `.el' version does, | |
3419 then a message will be printed. If an explicit extension is passed to `load', | |
3420 no warning will be printed. | |
3421 */ ); | |
3422 load_warn_when_source_only = 0; | |
3423 | |
3424 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /* | |
3425 *Whether `load' should ignore `.elc' files when a suffix is not given. | |
3426 This is normally used only to bootstrap the `.elc' files when building XEmacs. | |
3427 */ ); | |
3428 load_ignore_elc_files = 0; | |
3429 | |
1123 | 3430 DEFVAR_BOOL ("load-ignore-out-of-date-elc-files", |
3431 &load_ignore_out_of_date_elc_files /* | |
3432 *Whether `load' should ignore out-of-date `.elc' files when no suffix is given. | |
3433 This is normally used when compiling packages of elisp files that may have | |
3434 complex dependencies. Ignoring all elc files with `load-ignore-elc-files' | |
3435 would also be safe, but much slower. | |
3436 */ ); | |
3437 load_ignore_out_of_date_elc_files = 0; | |
3438 | |
3439 DEFVAR_BOOL ("load-always-display-messages", | |
3440 &load_always_display_messages /* | |
3441 *Whether `load' should always display loading messages. | |
3442 If this is true, every file loaded will be shown, regardless of the setting | |
3443 of the NOMESSAGE parameter, and even when files are loaded indirectly, e.g. | |
2857 | 3444 due to `require'. |
1123 | 3445 */ ); |
3446 load_always_display_messages = 0; | |
3447 | |
3448 DEFVAR_BOOL ("load-show-full-path-in-messages", | |
3449 &load_show_full_path_in_messages /* | |
3450 *Whether `load' should show the full path in all loading messages. | |
3451 */ ); | |
3452 load_show_full_path_in_messages = 0; | |
3453 | |
428 | 3454 #ifdef LOADHIST |
3455 DEFVAR_LISP ("load-history", &Vload_history /* | |
3456 Alist mapping source file names to symbols and features. | |
3457 Each alist element is a list that starts with a file name, | |
3458 except for one element (optional) that starts with nil and describes | |
3459 definitions evaluated from buffers not visiting files. | |
3460 The remaining elements of each list are symbols defined as functions | |
3461 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'. | |
3462 */ ); | |
3463 Vload_history = Qnil; | |
3464 | |
3465 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /* | |
3466 Used for internal purposes by `load'. | |
3467 */ ); | |
3468 Vcurrent_load_list = Qnil; | |
3469 #endif | |
3470 | |
3471 DEFVAR_LISP ("load-file-name", &Vload_file_name /* | |
3472 Full name of file being loaded by `load'. | |
3473 */ ); | |
3474 Vload_file_name = Qnil; | |
3475 | |
3476 DEFVAR_LISP ("load-read-function", &Vload_read_function /* | |
3477 Function used by `load' and `eval-region' for reading expressions. | |
3478 The default is nil, which means use the function `read'. | |
3479 */ ); | |
3480 Vload_read_function = Qnil; | |
3481 | |
3482 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /* | |
3483 Non-nil means `load' should force-load all dynamic doc strings. | |
3484 This is useful when the file being loaded is a temporary copy. | |
3485 */ ); | |
3486 load_force_doc_strings = 0; | |
3487 | |
3488 /* See read_escape(). */ | |
3489 #if 0 | |
3490 /* Used to be named `puke-on-fsf-keys' */ | |
3491 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes", | |
3492 &fail_on_bucky_bit_character_escapes /* | |
3493 Whether `read' should signal an error when it encounters unsupported | |
3494 character escape syntaxes or just read them incorrectly. | |
3495 */ ); | |
3496 fail_on_bucky_bit_character_escapes = 0; | |
3497 #endif | |
3498 | |
3499 /* This must be initialized in init_lread otherwise it may start out | |
3500 with values saved when the image is dumped. */ | |
3501 staticpro (&Vload_descriptor_list); | |
3502 | |
3503 /* Initialized in init_lread. */ | |
3504 staticpro (&Vload_force_doc_string_list); | |
3505 | |
3506 Vload_file_name_internal = Qnil; | |
3507 staticpro (&Vload_file_name_internal); | |
3508 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3509 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK_OLD_WAY |
428 | 3510 Vcurrent_compiled_function_annotation = Qnil; |
3511 staticpro (&Vcurrent_compiled_function_annotation); | |
3512 #endif | |
3513 | |
3514 /* So that early-early stuff will work */ | |
1292 | 3515 Ffset (Qload, Qload_internal); |
428 | 3516 |
3517 #ifdef FEATUREP_SYNTAX | |
563 | 3518 DEFSYMBOL (Qfeaturep); |
771 | 3519 Fprovide (intern ("xemacs")); |
428 | 3520 #ifdef INFODOCK |
771 | 3521 Fprovide (intern ("infodock")); |
428 | 3522 #endif /* INFODOCK */ |
3523 #endif /* FEATUREP_SYNTAX */ | |
3524 | |
3525 #ifdef LISP_BACKQUOTES | |
3526 old_backquote_flag = new_backquote_flag = 0; | |
3527 #endif | |
3528 | |
3529 #ifdef I18N3 | |
3530 Vfile_domain = Qnil; | |
3531 #endif | |
3532 | |
3533 Vread_objects = Qnil; | |
3534 staticpro (&Vread_objects); | |
3535 | |
3536 Vlocate_file_hash_table = make_lisp_hash_table (200, | |
3537 HASH_TABLE_NON_WEAK, | |
3538 HASH_TABLE_EQUAL); | |
3539 staticpro (&Vlocate_file_hash_table); | |
3540 #ifdef DEBUG_XEMACS | |
3541 symbol_value (XSYMBOL (intern ("Vlocate-file-hash-table"))) | |
3542 = Vlocate_file_hash_table; | |
3543 #endif | |
3544 } |