summaryrefslogtreecommitdiff
path: root/tex/context/base/syst-etx.tex
blob: e2770cfe97693794b13728659a496e042e8d8fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
%D \module
%D   [       file=syst-etx,
%D        version=1999.03.17, % some time ...
%D          title=\CONTEXT\ System Macros,
%D       subtitle=Efficient \PLAIN\ \TEX\ loading,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This module prepares \CONTEXT\ for \ETEX. We don't use
%D the definition files that come with this useful \TEX\
%D extension, but implement our own alternatives.

%D \CONTEXT\ was one of the first systems that had support for \ETEX\
%D built in. In the process we found out that the extensions were not
%D as bug free as the rest of \TEX. Especially the bugs in \type
%D {lastnode}, flushing of token lists with an index in the extension
%D range, and spurious box behaviour of boxes adressed in the extended
%D box space made us a bit careful. It's hard to to track down such
%D bugs, especially if one has a mind set of \TEX\ being bug free. If
%D you encounter unexpected behaviour let me know. Currently the
%D scantokens mechanism can handle only one||liners, but Taco will
%D provide an alternative some day.
%D
%D \starttyping
%D \bgroup
%D   \lccode`a=12\lowercase{\xdef\whatever{a}}\egroup
%D   \def\whatever{test \whatever test}
%D   \scantokens\expandafter{\whatever}
%D \egroup
%D \stoptyping

\unprotect

%D \ETEX\ has a not so handy way of telling you the version number,
%D i.e. the revision number has a period in it:

\long\def\gobbleoneargument#1{}

\beginETEX
  \mathchardef\etexversion=\numexpr\eTeXversion*100+\expandafter\gobbleoneargument\eTeXrevision\relax
\endETEX

\beginTEX
  \mathchardef\etexversion=0
\endTEX

%D Constants to be used with \type {\grouptype}.

\chardef\@@bottomlevelgroup   =  0
\chardef\@@simplegroup        =  1
\chardef\@@hboxgroup          =  2
\chardef\@@adjustedhboxgroup  =  3
\chardef\@@vboxgroup          =  4
\chardef\@@vtopgroup          =  5
\chardef\@@aligngroup         =  6
\chardef\@@noaligngroup       =  7
\chardef\@@outputgroup        =  8
\chardef\@@mathgroup          =  9
\chardef\@@discretionarygroup = 10
\chardef\@@insertgroup        = 11
\chardef\@@vcentergroup       = 12
\chardef\@@mathchoicegroup    = 13
\chardef\@@semisimplegroup    = 14
\chardef\@@mathshiftgroup     = 15
\chardef\@@mathleftgroup      = 16

\chardef\@@vadjustgroup       = \@@insertgroup

%D Constants to be used with \type {\interactionmode}.

\chardef\@@batchmode     = 0
\chardef\@@nonstopmode   = 1
\chardef\@@scrollmode    = 2
\chardef\@@errorstopmode = 3

%D Constants to be used with \type {\lastnodetype}.

\chardef\@@charnode          =  0
\chardef\@@hlistnode         =  1
\chardef\@@vlistnode         =  2
\chardef\@@rulenode          =  3
\chardef\@@insertnode        =  4
\chardef\@@marknode          =  5
\chardef\@@adjustnode        =  6
\chardef\@@ligaturenode      =  7
\chardef\@@discretionarynode =  8
\chardef\@@whatsitnode       =  9
\chardef\@@mathnode          = 10
\chardef\@@gluenode          = 11
\chardef\@@kernnode          = 12
\chardef\@@penaltynode       = 13
\chardef\@@unsetnode         = 14
\chardef\@@mathsnode         = 15

%D Constants to be used with \type {\iftype}.

\chardef\@@charif     =  1
\chardef\@@catif      =  2
\chardef\@@numif      =  3
\chardef\@@dimif      =  4
\chardef\@@oddif      =  5
\chardef\@@vmodeif    =  6
\chardef\@@hmodeif    =  7
\chardef\@@mmodeif    =  8
\chardef\@@innerif    =  9
\chardef\@@voidif     = 10
\chardef\@@hboxif     = 11
\chardef\@@vboxif     = 12
\chardef\@@xif        = 13
\chardef\@@eofif      = 14
\chardef\@@trueif     = 15
\chardef\@@falseif    = 16
\chardef\@@caseif     = 17
\chardef\@@definedif  = 18
\chardef\@@csnameif   = 19
\chardef\@@fontcharif = 20

%D Just in case we are not using \ETEX, we define some out of
%D range constants.

\beginTEX

\chardef\grouptype       = 255
\chardef\interactionmode = 255
\chardef\nodetype        = 255
\chardef\iftype          = 255

\endTEX

%D Of course we want even bigger log files, so we copied this
%D from the \ETEX\ source files.

\beginETEX \tracing...

\def\tracingall
  {\tracingonline    \@ne
   \tracingcommands  \thr@@
   \tracingstats     \tw@
   \tracingpages     \@ne
   \tracingoutput    \@ne
   \tracinglostchars \tw@
   \tracingmacros    \tw@
   \tracingparagraphs\@ne
   \tracingrestores  \@ne
   \showboxbreadth   \maxdimen
   \showboxdepth     \maxdimen
   \tracinggroups    \@ne
   \tracingifs       \@ne
   \tracingscantokens\@ne
   \tracingnesting   \@ne
   \tracingassigns   \tw@
   \errorstopmode}

\def\loggingall
  {\tracingall
   \tracingonline    \z@}

\def\tracingnone
  {\tracingassigns   \z@
   \tracingnesting   \z@
   \tracingscantokens\z@
   \tracingifs       \z@
   \tracinggroups    \z@
   \showboxdepth     \thr@@
   \showboxbreadth   5
   \tracingrestores  \z@
   \tracingparagraphs\z@
   \tracingmacros    \z@
   \tracinglostchars \@ne
   \tracingoutput    \z@
   \tracingpages     \z@
   \tracingstats     \z@
   \tracingcommands  \z@
   \tracingonline    \z@ }

\endETEX

%D Just to be sure:

\ifx\eTeX\undefined

  \def\eTeX{$\varepsilon$-\TeX}

\fi

%D In \ETEX\ we have lots of registers, so we redefine a few
%D low level macros. We reserve some extra space for inserts
%D and as soon as we near the end of the first register
%D memory bank (often some 10 less than 255), we switch to the
%D slower range \type {\@@medallocation}||\type {\@@maxallocation}.

\beginETEX \new...

%D First we redefine the plain \TEX\ register allocation macros.

\def\newcount   {\myalloc@0\count   \countdef   \@@maxallocation}
\def\newdimen   {\myalloc@1\dimen   \dimendef   \@@maxallocation}
\def\newskip    {\myalloc@2\skip    \skipdef    \@@maxallocation}
\def\newmuskip  {\myalloc@3\muskip  \muskipdef  \@@maxallocation}
\def\newbox     {\myalloc@4\box     \mathchardef\@@maxallocation}
\def\newtoks    {\myalloc@5\toks    \toksdef    \@@maxallocation}
\def\newread    {\myalloc@6\read    \chardef    \@@minallocation}
\def\newwrite   {\myalloc@7\write   \chardef    \@@minallocation}
\def\newmarks   {\myalloc@8\marks   \mathchardef\@@maxallocation}
\def\newlanguage{\myalloc@9\language\chardef    \@@minallocation}

%D Since in \CONTEXT\ we only have one math family left we
%D redefine \type {\newfam}.

\def\newfam#1{\chardef#1=15 }

%D Therefore we should reset the related counter.

\count18=1

%D We use some constants in the tests.

\mathchardef\@@minallocation =    16
\mathchardef\@@medallocation =   256
\mathchardef\@@maxallocation = 32767

%D I cannot imagine that more than~8 extra insert classes
%D are needed, but, for critical editions, we may need many
%D more, so:

\chardef\@@insallocation=32

%D However, there's a bug in \ETEX\ versions smaller than 2.2,
%D so we need to play safe:

\ifnum\etexversion<202 \chardef\@@insallocation=8 \fi

%D My low level allocation macro now comes down to:

\def\myalloc@#1#2#3#4#5%
  {\global\advance\count1#1by\@ne
   \ifnum\count1#1>\@@medallocation \else
     \global\advance\insc@unt by -\@@insallocation
     \ifnum\count1#1<\insc@unt \else
       \global\count1#1=\@@medallocation % \wait
     \fi
     \global\advance\insc@unt by +\@@insallocation
   \fi
   \ifnum\count1#1>#4%
     \global\count1#1=#4%
     \errmessage{No room for (\string#2) \string#5}%
   \fi
   \allocationnumber=\count1#1%
   \global#3#5=\allocationnumber
   \wlog{\string#5=\string#2\the\allocationnumber}}

\endETEX

%D These macros can be checked by tests like:
%D
%D \starttyping
%D \let\wlog\message \dorecurse{1000}{\newcount\dummy}
%D \stoptyping

%D A few bonus bindings.

\let\normalprotected  = \protected
\let\normalunexpanded = \unexpanded

%D \macros
%D   {begcsname}
%D
%D Handy for \ETEX-only usage:

\beginETEX \ifcsname

  \def\begcsname#1\endcsname{\ifcsname#1\endcsname\csname#1\endcsname\fi}

\endETEX

\beginTEX

  \def\begcsname#1\endcsname{\csname#1\endcsname}

\endTEX

\protect \endinput