Mercurial > hg > xemacs-beta
annotate src/syntax.h @ 5915:1af53d35dd53
Avoid allocation in #'integer-length; add #'logcount.
lisp/ChangeLog addition:
2015-05-29 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
Add #'integer-length, #'logcount here.
* cl-extra.el:
* cl-extra.el (integer-length):
Update this to avoid allocating memory.
* cl-extra.el (logcount): New. Return the number of one bits in
INTEGER, if non-negative. Function from Common Lisp.
tests/ChangeLog addition:
2015-05-29 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test #'integer-length, #'logcount in this file.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 29 May 2015 17:06:24 +0100 |
parents | 2dc8711af537 |
children |
rev | line source |
---|---|
428 | 1 /* Declarations having to do with XEmacs syntax tables. |
2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc. | |
1296 | 3 Copyright (C) 2002, 2003 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: FSF 19.28. */ | |
21 | |
440 | 22 #ifndef INCLUDED_syntax_h_ |
23 #define INCLUDED_syntax_h_ | |
428 | 24 |
25 #include "chartab.h" | |
26 | |
27 /* A syntax table is a type of char table. | |
28 | |
29 The values in a syntax table are either integers or conses of | |
30 integers and chars. The lowest 7 bits of the integer are the syntax | |
31 class. If this is Sinherit, then the actual syntax value needs to | |
32 be retrieved from the standard syntax table. | |
33 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
34 It turns out to be worth optimizing lookups of character syntax in two |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
35 ways. First, although the logic involved in finding the actual integer |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
36 isn't complex, the syntax value is accessed in functions such as |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
37 scan_lists() many times for each character scanned. A "mirror syntax |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
38 table" that contains the actual integers speeds this up. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
39 |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
40 Second, due to the syntax-table text property, the table for looking up |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
41 syntax may change from character to character. Since looking up properties |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
42 is expensive, a "syntax cache" which contains the current syntax table and |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
43 the region where it is valid can speed up linear scans dramatically. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
44 |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
45 The low 7 bits of the integer is a code, as follows. The 8th bit is |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
46 used as the prefix bit flag (see below). |
428 | 47 */ |
48 | |
49 enum syntaxcode | |
50 { | |
51 Swhitespace, /* whitespace character */ | |
52 Spunct, /* random punctuation character */ | |
53 Sword, /* word constituent */ | |
54 Ssymbol, /* symbol constituent but not word constituent */ | |
55 Sopen, /* a beginning delimiter */ | |
56 Sclose, /* an ending delimiter */ | |
57 Squote, /* a prefix character like Lisp ' */ | |
58 Sstring, /* a string-grouping character like Lisp " */ | |
59 Smath, /* delimiters like $ in TeX. */ | |
60 Sescape, /* a character that begins a C-style escape */ | |
61 Scharquote, /* a character that quotes the following character */ | |
62 Scomment, /* a comment-starting character */ | |
63 Sendcomment, /* a comment-ending character */ | |
64 Sinherit, /* use the standard syntax table for this character */ | |
460 | 65 Scomment_fence, /* Starts/ends comment which is delimited on the |
66 other side by a char with the same syntaxcode. */ | |
67 Sstring_fence, /* Starts/ends string which is delimited on the | |
68 other side by a char with the same syntaxcode. */ | |
428 | 69 Smax /* Upper bound on codes that are meaningful */ |
70 }; | |
71 | |
72 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, | |
73 int *multi_p_out); | |
74 | |
1296 | 75 void update_syntax_table (Lisp_Object table); |
76 | |
77 DECLARE_INLINE_HEADER ( | |
78 void | |
79 update_mirror_syntax_if_dirty (Lisp_Object table) | |
80 ) | |
81 { | |
82 if (XCHAR_TABLE (table)->dirty) | |
83 update_syntax_table (table); | |
84 } | |
85 | |
428 | 86 /* Return the syntax code for a particular character and mirror table. */ |
87 | |
1296 | 88 DECLARE_INLINE_HEADER ( |
1315 | 89 int |
1296 | 90 SYNTAX_CODE (Lisp_Object table, Ichar c) |
91 ) | |
92 { | |
93 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); | |
94 update_mirror_syntax_if_dirty (table); | |
5902
2dc8711af537
Make get_char_table in loop bodies more tolerable without optimization.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
95 return XFIXNUM (get_char_table_mirrors_ok (c, table)); |
1296 | 96 } |
97 | |
98 #ifdef NOT_WORTH_THE_EFFORT | |
99 | |
100 /* Same but skip the dirty check. */ | |
101 | |
102 DECLARE_INLINE_HEADER ( | |
1315 | 103 int |
1296 | 104 SYNTAX_CODE_1 (Lisp_Object table, Ichar c) |
105 ) | |
106 { | |
107 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p); | |
5902
2dc8711af537
Make get_char_table in loop bodies more tolerable without optimization.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
108 return (enum syntaxcode) XFIXNUM (get_char_table_mirrors_ok (c, table)); |
1296 | 109 } |
110 | |
111 #endif /* NOT_WORTH_THE_EFFORT */ | |
428 | 112 |
113 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177)) | |
826 | 114 |
428 | 115 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c)) |
116 | |
826 | 117 DECLARE_INLINE_HEADER ( |
118 int | |
867 | 119 WORD_SYNTAX_P (Lisp_Object table, Ichar c) |
826 | 120 ) |
428 | 121 { |
122 return SYNTAX (table, c) == Sword; | |
123 } | |
124 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
125 /* OK, here's a graphic diagram of the format of the syntax values. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
126 Here, the value has already been extracted from the Lisp integer, |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
127 so there are no tag bits to worry about. |
428 | 128 |
129 Bit number: | |
130 | |
131 [ 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ] | |
132 [ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 ] | |
133 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
134 | <-----------> <-------------> <-------------> ^ <-----------> |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
135 | unused |comment bits | unused | syntax code |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
136 v | | | | | | | | | |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
137 unusable | | | | | | | | | |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
138 due to | | | | | | | | | |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
139 type tag | | | | | | | | `--> prefix flag |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
140 in Lisp | | | | | | | | |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
141 integer | | | | | | | `--> comment end style B, second char |
428 | 142 | | | | | | `----> comment end style A, second char |
143 | | | | | `------> comment end style B, first char | |
144 | | | | `--------> comment end style A, first char | |
145 | | | `----------> comment start style B, second char | |
146 | | `------------> comment start style A, second char | |
147 | `--------------> comment start style B, first char | |
148 `----------------> comment start style A, first char | |
149 | |
150 In a 64-bit integer, there would be 32 more unused bits between | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
151 the unusable bit and the comment bits. |
428 | 152 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
153 In older versions of XEmacs, bits 8-14 contained the matching |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
154 character for parentheses. Such a scheme will not work for Mule, |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
155 because the matching parenthesis could be any character and |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
156 requires 21 bits, which we don't have on a 32-bit platform. |
428 | 157 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
158 What we do is use another char table for the matching parenthesis |
428 | 159 and store a pointer to it in the first char table. (This frees |
160 code from having to worry about passing two tables around.) | |
161 */ | |
162 | |
163 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
164 /* The prefix flag bit for backward-prefix-chars is in bit 7. */ |
428 | 165 |
166 #define SYNTAX_PREFIX(table, c) \ | |
167 ((SYNTAX_CODE (table, c) >> 7) & 1) | |
168 | |
169 /* Bits 23-16 are used to implement up to two comment styles | |
170 in a single buffer. They have the following meanings: | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
171 bit |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
172 23 first of a one or two character comment-start sequence of style a. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
173 22 first of a one or two character comment-start sequence of style b. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
174 21 second of a two-character comment-start sequence of style a. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
175 20 second of a two-character comment-start sequence of style b. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
176 19 first of a one or two character comment-end sequence of style a. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
177 18 first of a one or two character comment-end sequence of style b. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
178 17 second of a two-character comment-end sequence of style a. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
179 16 second of a two-character comment-end sequence of style b. |
428 | 180 */ |
181 | |
182 #define SYNTAX_COMMENT_BITS(table, c) \ | |
183 ((SYNTAX_CODE (table, c) >> 16) &0xff) | |
184 | |
185 #define SYNTAX_FIRST_OF_START_A 0x80 | |
186 #define SYNTAX_FIRST_OF_START_B 0x40 | |
187 #define SYNTAX_SECOND_OF_START_A 0x20 | |
188 #define SYNTAX_SECOND_OF_START_B 0x10 | |
189 #define SYNTAX_FIRST_OF_END_A 0x08 | |
190 #define SYNTAX_FIRST_OF_END_B 0x04 | |
191 #define SYNTAX_SECOND_OF_END_A 0x02 | |
192 #define SYNTAX_SECOND_OF_END_B 0x01 | |
193 | |
194 #define SYNTAX_COMMENT_STYLE_A 0xaa | |
195 #define SYNTAX_COMMENT_STYLE_B 0x55 | |
196 #define SYNTAX_FIRST_CHAR_START 0xc0 | |
197 #define SYNTAX_FIRST_CHAR_END 0x0c | |
198 #define SYNTAX_FIRST_CHAR 0xcc | |
199 #define SYNTAX_SECOND_CHAR_START 0x30 | |
200 #define SYNTAX_SECOND_CHAR_END 0x03 | |
201 #define SYNTAX_SECOND_CHAR 0x33 | |
202 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
203 /* Array of syntax codes, indexed by characters which designate them. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
204 Designators must be ASCII characters (ie, in the range 0x00-0x7F). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
205 Bounds checking is the responsibility of calling code. */ |
5542
dab422055bab
Correct array bound for syntax_code_spec.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5402
diff
changeset
|
206 extern const unsigned char syntax_spec_code[0200]; |
428 | 207 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
208 /* Array of designators indexed by syntax code. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
209 Indicies should be of type enum syntaxcode. */ |
442 | 210 extern const unsigned char syntax_code_spec[]; |
428 | 211 |
665 | 212 Lisp_Object scan_lists (struct buffer *buf, Charbpos from, int count, |
428 | 213 int depth, int sexpflag, int no_error); |
665 | 214 int char_quoted (struct buffer *buf, Charbpos pos); |
428 | 215 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
216 /* TABLE is a syntax table, not the mirror table. */ |
867 | 217 Lisp_Object syntax_match (Lisp_Object table, Ichar ch); |
428 | 218 |
219 extern int no_quit_in_re_search; | |
826 | 220 |
221 | |
222 /****************************** syntax caches ********************************/ | |
460 | 223 |
224 extern int lookup_syntax_properties; | |
225 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
226 /* The `syntax-table' property overrides the syntax table or directly |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
227 specifies the syntax. Since looking up properties is expensive, we cache |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
228 the information about the syntax-table property. When moving linearly |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
229 through text (e.g. in the regex routines or the scanning routines in |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
230 syntax.c), recalculation is needed only when the syntax-table property |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
231 changes (i.e. not every position). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
232 When we do need to recalculate, we can update the info from the previous |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
233 info faster than if we did the whole calculation from scratch. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
234 #### sjt sez: I'm not sure I believe that last claim. That seems to |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
235 require that we use directional information, etc, but that is ignored in |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
236 the current implementation. */ |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
237 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
238 enum syntax_source { syntax_source_property_code = 0, |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
239 syntax_source_property_table = 1, |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
240 syntax_source_buffer_table = 2 }; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
241 #define SOURCE_IS_TABLE(source) (source) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
242 |
460 | 243 struct syntax_cache |
244 { | |
3092 | 245 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
246 NORMAL_LISP_OBJECT_HEADER header; |
3092 | 247 #endif /* NEW_GC */ |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
248 enum syntax_source source; /* Source of syntax information: the buffer's |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
249 syntax table, a syntax table specified by |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
250 a syntax-table property, or a syntax code |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
251 specified by a syntax-table property. */ |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
252 Lisp_Object object; /* The buffer or string the current syntax |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
253 cache applies to, or Qnil for a string of |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
254 text not coming from a buffer or string. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
255 struct buffer *buffer; /* The buffer that supplies the syntax tables, |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
256 or NULL for the standard syntax table. If |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
257 OBJECT is a buffer, this will always be |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
258 the same buffer. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
259 int syntax_code; /* Syntax code of current char. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
260 Lisp_Object syntax_table; /* Syntax table for current pos. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
261 Lisp_Object mirror_table; /* Mirror table for this table. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
262 Lisp_Object start, end; /* Markers to keep track of the known region |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
263 in a buffer. |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
264 Both are Qnil if object is a string. |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
265 Normally these correspond to prev_change |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
266 and next_change, respectively, except when |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
267 insertions and deletions occur. Then |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
268 prev_change and next change will be |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
269 refreshed from these markers. See |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
270 signal_syntax_cache_extent_adjust(). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
271 We'd like to use an extent, but it seems |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
272 that having an extent over the entire |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
273 buffer causes serious slowdowns in extent |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
274 operations! Yuck! |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
275 #### May not be true any more. */ |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
276 Charxpos next_change; /* Position of the next extent change. */ |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
277 Charxpos prev_change; /* Position of the previous extent change. */ |
460 | 278 }; |
826 | 279 |
3092 | 280 #ifdef NEW_GC |
281 typedef struct syntax_cache Lisp_Syntax_Cache; | |
282 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3498
diff
changeset
|
283 DECLARE_LISP_OBJECT (syntax_cache, Lisp_Syntax_Cache); |
3092 | 284 |
285 #define XSYNTAX_CACHE(x) \ | |
286 XRECORD (x, syntax_cache, Lisp_Syntax_Cache) | |
287 #define wrap_syntax_cache(p) wrap_record (p, syntax_cache) | |
288 #define SYNTAX_CACHE_P(x) RECORDP (x, syntax_cache) | |
289 #define CHECK_SYNTAX_CACHE(x) CHECK_RECORD (x, syntax_cache) | |
290 #define CONCHECK_SYNTAX_CACHE(x) CONCHECK_RECORD (x, syntax_cache) | |
291 #endif /* NEW_GC */ | |
292 | |
1296 | 293 extern const struct sized_memory_description syntax_cache_description; |
294 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
295 /* Note that the external interface to the syntax cache uses charpos's, but |
3250 | 296 internally we use bytepos's, for speed. */ |
826 | 297 void update_syntax_cache (struct syntax_cache *cache, Charxpos pos, int count); |
298 struct syntax_cache *setup_syntax_cache (struct syntax_cache *cache, | |
299 Lisp_Object object, | |
300 struct buffer *buffer, | |
301 Charxpos from, int count); | |
302 struct syntax_cache *setup_buffer_syntax_cache (struct buffer *buffer, | |
303 Charxpos from, int count); | |
460 | 304 |
305 /* Make syntax cache state good for CHARPOS, assuming it is | |
306 currently good for a position before CHARPOS. */ | |
826 | 307 DECLARE_INLINE_HEADER ( |
308 void | |
309 UPDATE_SYNTAX_CACHE_FORWARD (struct syntax_cache *cache, Charxpos pos) | |
310 ) | |
311 { | |
1315 | 312 /* #### Formerly this function, and the next one, had |
313 | |
314 if (pos < cache->prev_change || pos >= cache->next_change) | |
315 | |
316 just like for plain UPDATE_SYNTAX_CACHE. However, sometimes the | |
317 value of POS may be invalid (particularly, it may be 0 for a buffer). | |
318 FSF has the check at only one end, so let's try the same. */ | |
319 if (pos >= cache->next_change) | |
826 | 320 update_syntax_cache (cache, pos, 1); |
321 } | |
460 | 322 |
323 /* Make syntax cache state good for CHARPOS, assuming it is | |
324 currently good for a position after CHARPOS. */ | |
826 | 325 DECLARE_INLINE_HEADER ( |
326 void | |
327 UPDATE_SYNTAX_CACHE_BACKWARD (struct syntax_cache *cache, Charxpos pos) | |
328 ) | |
329 { | |
1315 | 330 if (pos < cache->prev_change) |
826 | 331 update_syntax_cache (cache, pos, -1); |
332 } | |
460 | 333 |
334 /* Make syntax cache state good for CHARPOS */ | |
826 | 335 DECLARE_INLINE_HEADER ( |
336 void | |
337 UPDATE_SYNTAX_CACHE (struct syntax_cache *cache, Charxpos pos) | |
338 ) | |
339 { | |
1315 | 340 if (pos < cache->prev_change || pos >= cache->next_change) |
826 | 341 update_syntax_cache (cache, pos, 0); |
342 } | |
460 | 343 |
826 | 344 #define SYNTAX_FROM_CACHE(cache, c) \ |
345 SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (cache, c)) | |
460 | 346 |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
347 #define SYNTAX_CODE_FROM_CACHE(cache, c) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
348 (SOURCE_IS_TABLE ((cache)->source) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
349 ? SYNTAX_CODE ((cache)->mirror_table, c) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
350 : (cache)->syntax_code) |
1296 | 351 |
352 #ifdef NOT_WORTH_THE_EFFORT | |
353 /* If we really cared about the theoretical performance hit of the dirty | |
354 check in SYNTAX_CODE, we could use SYNTAX_CODE_1 and endeavor to always | |
355 keep the mirror table clean, e.g. by checking for dirtiness at the time | |
356 we set up the syntax cache. There are lots of potential problems, of | |
357 course -- incomplete understanding of the possible pathways into the | |
358 code, with some that are bypassing the setups, Lisp code being executed | |
359 in the meantime that could change things (e.g. QUIT is called in many | |
360 functions and could execute arbitrary Lisp very easily), etc. The QUIT | |
361 problem is the biggest one, probably, and one of the main reasons it's | |
362 probably just not worth it. */ | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
363 #define SYNTAX_CODE_FROM_CACHE(cache, c) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
364 (SOURCE_IS_TABLE ((cache)->source) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
365 ? SYNTAX_CODE_1 ((cache)->mirror_table, c) \ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
366 : (cache)->syntax_code) |
1296 | 367 #endif |
826 | 368 |
369 | |
370 /***************************** syntax code macros ****************************/ | |
460 | 371 |
372 #define SYNTAX_CODE_PREFIX(c) \ | |
373 ((c >> 7) & 1) | |
374 | |
375 #define SYNTAX_CODE_COMMENT_BITS(c) \ | |
376 ((c >> 16) &0xff) | |
377 | |
378 #define SYNTAX_CODES_START_P(a, b) \ | |
379 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) >> 2) \ | |
380 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_START)) | |
381 | |
382 #define SYNTAX_CODES_END_P(a, b) \ | |
383 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) >> 2) \ | |
384 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END)) | |
385 | |
386 #define SYNTAX_CODES_COMMENT_MASK_START(a, b) \ | |
387 (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_A) \ | |
388 ? SYNTAX_COMMENT_STYLE_A \ | |
389 : (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_B) \ | |
390 ? SYNTAX_COMMENT_STYLE_B \ | |
391 : 0)) | |
392 #define SYNTAX_CODES_COMMENT_MASK_END(a, b) \ | |
393 (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_A) \ | |
394 ? SYNTAX_COMMENT_STYLE_A \ | |
395 : (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_B) \ | |
396 ? SYNTAX_COMMENT_STYLE_B \ | |
397 : 0)) | |
398 | |
399 #define SYNTAX_CODE_START_FIRST_P(a) \ | |
400 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) | |
401 | |
402 #define SYNTAX_CODE_START_SECOND_P(a) \ | |
403 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_START) | |
404 | |
405 #define SYNTAX_CODE_END_FIRST_P(a) \ | |
406 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) | |
407 | |
408 #define SYNTAX_CODE_END_SECOND_P(a) \ | |
409 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_END) | |
410 | |
411 | |
412 #define SYNTAX_CODES_MATCH_START_P(a, b, mask) \ | |
413 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START & (mask)) \ | |
414 && (SYNTAX_CODE_COMMENT_BITS (b) \ | |
415 & SYNTAX_SECOND_CHAR_START & (mask))) | |
416 | |
417 #define SYNTAX_CODES_MATCH_END_P(a, b, mask) \ | |
418 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END & (mask)) \ | |
419 && (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END & (mask))) | |
420 | |
421 #define SYNTAX_CODE_MATCHES_1CHAR_P(a, mask) \ | |
422 ((SYNTAX_CODE_COMMENT_BITS (a) & (mask))) | |
423 | |
424 #define SYNTAX_CODE_COMMENT_1CHAR_MASK(a) \ | |
425 ((SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_A) \ | |
426 ? SYNTAX_COMMENT_STYLE_A \ | |
427 : (SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_B) \ | |
428 ? SYNTAX_COMMENT_STYLE_B \ | |
429 : 0))) | |
430 | |
431 | |
440 | 432 #endif /* INCLUDED_syntax_h_ */ |