Debian Codegraph @

texmf-dist/source/latex/l3kernel/l3debug.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3debug.dtx
4 %
5 % Copyright (C) 2019-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3kernel bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \documentclass[full,kernel]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3debug} module\\ Debugging support^^A
35 % }
36 %
37 % \author{^^A
38 % The \LaTeX{} Project\thanks
39 % {^^A
40 % E-mail:
41 % \href{mailto:[email protected]}
42 % {[email protected]}^^A
43 % }^^A
44 % }
45 %
46 % \date{Released 2026-05-15}
47 %
48 % \maketitle
49 %
50 % \begin{documentation}
51 %
52 % \end{documentation}
53 %
54 % \begin{implementation}
55 %
56 % \section{\pkg{l3debug} implementation}
57 %
58 % Internal kernel functions that are only defined here are listed in
59 % \pkg{l3kernel-functions},
60 % see~\ref{sec:l3kernel-functions:l3debug-internals}.
61 %
62 % \begin{macrocode}
63 %<*def>
64 % \end{macrocode}
65 %
66 % \begin{macrocode}
67 %<@@=debug>
68 % \end{macrocode}
69 %
70 % Standard file identification.
71 % \begin{macrocode}
72 \ProvidesExplFile{l3debug.def}{2026-05-15}{}{L3 Debugging support}
73 % \end{macrocode}
74 %
75 % \begin{variable}{\s_@@_stop}
76 % Internal scan marks.
77 % \begin{macrocode}
78 \scan_new:N \s_@@_stop
79 % \end{macrocode}
80 % \end{variable}
81 %
82 % \begin{macro}[EXP]{\@@_use_i_delimit_by_s_stop:nw}
83 % Functions to gobble up to a scan mark.
84 % \begin{macrocode}
85 \cs_new:Npn \@@_use_i_delimit_by_s_stop:nw #1 #2 \s_@@_stop {#1}
86 % \end{macrocode}
87 % \end{macro}
88 %
89 % \begin{variable}{\q_@@_recursion_tail,\q_@@_recursion_stop}
90 % Internal quarks.
91 % \begin{macrocode}
92 \quark_new:N \q_@@_recursion_tail
93 \quark_new:N \q_@@_recursion_stop
94 % \end{macrocode}
95 % \end{variable}
96 %
97 % \begin{macro}[EXP]{\@@_if_recursion_tail_stop:N}
98 % Functions to query recursion quarks.
99 % \begin{macrocode}
100 \cs_new:Npn \@@_use_none_delimit_by_q_recursion_stop:w
101 #1 \q_@@_recursion_stop { }
102 \__kernel_quark_new_test:N \@@_if_recursion_tail_stop:N
103 % \end{macrocode}
104 % \end{macro}
105 %
106 % \begin{macro}{\debug_on:n, \debug_off:n, \@@_all_on:, \@@_all_off:}
107 % \begin{macrocode}
108 \cs_gset_protected:Npn \debug_on:n #1
109 {
110 \exp_args:No \clist_map_inline:nn { \tl_to_str:n {#1} }
111 {
112 \cs_if_exist_use:cF { @@_ ##1 _on: }
113 { \msg_error:nnn { debug } { debug } {##1} }
114 }
115 }
116 \cs_gset_protected:Npn \debug_off:n #1
117 {
118 \exp_args:No \clist_map_inline:nn { \tl_to_str:n {#1} }
119 {
120 \cs_if_exist_use:cF { @@_ ##1 _off: }
121 { \msg_error:nnn { debug } { debug } {##1} }
122 }
123 }
124 \cs_new_protected:Npn \@@_all_on:
125 {
126 \debug_on:n
127 {
128 check-assertions ,
129 check-declarations ,
130 check-expressions ,
131 deprecation ,
132 log-functions ,
133 }
134 }
135 \cs_new_protected:Npn \@@_all_off:
136 {
137 \debug_off:n
138 {
139 check-assertions ,
140 check-declarations ,
141 check-expressions ,
142 deprecation ,
143 log-functions ,
144 }
145 }
146 % \end{macrocode}
147 % \end{macro}
148 %
149 % \begin{macro}{\debug_suspend:, \debug_resume:}
150 % \begin{macro}{\@@_suspended:T}
151 % \begin{macro}{\l_@@_suspended_tl}
152 % Suspend and resume locally all debug-related errors and logging
153 % except deprecation errors. The \cs{debug_suspend:} and \cs{debug_resume:}
154 % pairs can be nested. We keep track of nesting in a token list
155 % containing a number of periods. At first begin with the
156 % \enquote{non-suspended} version of \cs{@@_suspended:T}.
157 % \begin{macrocode}
158 \tl_new:N \l_@@_suspended_tl { }
159 \cs_gset_protected:Npn \debug_suspend:
160 {
161 \tl_put_right:Nn \l_@@_suspended_tl { . }
162 \cs_set_eq:NN \@@_suspended:T \use:n
163 }
164 \cs_gset_protected:Npn \debug_resume:
165 {
166 \__kernel_tl_set:Nx \l_@@_suspended_tl
167 { \tl_tail:N \l_@@_suspended_tl }
168 \tl_if_empty:NT \l_@@_suspended_tl
169 {
170 \cs_set_eq:NN \@@_suspended:T \use_none:n
171 }
172 }
173 \cs_new_eq:NN \@@_suspended:T \use_none:n
174 % \end{macrocode}
175 % \end{macro}
176 % \end{macro}
177 % \end{macro}
178 %
179 % \begin{macro}
180 % {\@@_check-assertions_on:, \@@_check-assertions_off:}
181 % \begin{macro}[EXP]
182 % {
183 % \debug_assert:nN,
184 % \debug_assert:nn,
185 % \debug_assert:nNn,
186 % \debug_assert:nnn
187 % }
188 % \begin{macrocode}
189 \cs_new_protected:cpn { @@_check-assertions_on: }
190 {
191 \cs_set:Npn \debug_assert:nN ##1##2
192 {
193 \@@_suspended:T \use_none:nnnn
194 \debug_assert:nNe
195 { ##1 }
196 ##2
197 { Assertion~failed:~\tl_to_str:n { ##2 } }
198 }
199 \cs_set:Npn \debug_assert:nn ##1##2
200 {
201 \@@_suspended:T \use_none:nnnn
202 \debug_assert:nne
203 { ##1 }
204 { ##2 }
205 { Assertion~failed:~\tl_to_str:n { ##2 } }
206 }
207 \cs_set:Npn \debug_assert:nNn ##1##2##3
208 {
209 \@@_suspended:T \use_none:nnn
210 \bool_if:NF ##2
211 {
212 \exp_args:Nne \__kernel_msg_expandable_error:nn
213 { ##3 }
214 { \msg_error_text:n { ##1 } }
215 }
216 }
217 \cs_set:Npn \debug_assert:nnn ##1##2##3
218 {
219 \@@_suspended:T \use_none:nnn
220 \bool_if:nF { ##2 }
221 {
222 \exp_args:Nne \__kernel_msg_expandable_error:nn
223 { ##3 }
224 { \msg_error_text:n { ##1 } }
225 }
226 }
227 }
228 \cs_new_protected:cpn { @@_check-assertions_off: }
229 {
230 \cs_set:Npn \debug_assert:nN ##1##2 { }
231 \cs_set:Npn \debug_assert:nn ##1##2 { }
232 \cs_set:Npn \debug_assert:nNn ##1##2##3 { }
233 \cs_set:Npn \debug_assert:nnn ##1##2##3 { }
234 }
235 % \end{macrocode}
236 % \end{macro}
237 % \end{macro}
238 %
239 % \begin{macro}
240 % {\@@_check-declarations_on:, \@@_check-declarations_off:}
241 % \begin{macro}
242 % {
243 % \__kernel_chk_var_exist:N,
244 % \__kernel_chk_cs_exist:N,
245 % \__kernel_chk_cs_exist:c
246 % }
247 % \begin{macro}[EXP]{\__kernel_chk_flag_exist:NN}
248 % \begin{macro}{\__kernel_chk_var_local:N, \__kernel_chk_var_global:N}
249 % \begin{macro}{\__kernel_chk_var_scope:NN}
250 % When debugging is enabled these two functions set up functions that
251 % test their argument (when \texttt{check-declarations} is active)
252 % \begin{itemize}
253 % \item \cs{__kernel_chk_var_exist:N} and \cs{__kernel_chk_cs_exist:N}, two
254 % functions that test that their argument is defined;
255 % \item \cs{__kernel_chk_var_scope:NN} that checks that its argument |#2|
256 % has scope |#1|.
257 % \item \cs{__kernel_chk_var_local:N} and \cs{__kernel_chk_var_global:N} that
258 % perform both checks.
259 % \end{itemize}
260 % \begin{macrocode}
261 \cs_new_protected:Npn \__kernel_chk_var_exist:N #1 { }
262 \cs_new_protected:Npn \__kernel_chk_cs_exist:N #1 { }
263 \cs_generate_variant:Nn \__kernel_chk_cs_exist:N { c }
264 \cs_new:Npn \__kernel_chk_flag_exist:NN { }
265 \cs_new_protected:Npn \__kernel_chk_var_local:N #1 { }
266 \cs_new_protected:Npn \__kernel_chk_var_global:N #1 { }
267 \cs_new_protected:Npn \__kernel_chk_var_scope:NN #1#2 { }
268 \cs_new_protected:cpn { @@_check-declarations_on: }
269 {
270 \cs_set_protected:Npn \__kernel_chk_var_exist:N ##1
271 {
272 \@@_suspended:T \use_none:nnn
273 \cs_if_exist:NF ##1
274 {
275 \msg_error:nne { debug } { non-declared-variable }
276 { \token_to_str:N ##1 }
277 }
278 }
279 \cs_set_protected:Npn \__kernel_chk_cs_exist:N ##1
280 {
281 \@@_suspended:T \use_none:nnn
282 \cs_if_exist:NF ##1
283 {
284 \msg_error:nne { kernel } { command-not-defined }
285 { \token_to_str:N ##1 }
286 }
287 }
288 \cs_set:Npn \__kernel_chk_flag_exist:NN ##1##2
289 {
290 \@@_suspended:T \use_iii:nnnn
291 \flag_if_exist:NTF ##2
292 { ##1 ##2 }
293 {
294 \msg_expandable_error:nnn { kernel } { bad-variable } {##2}
295 ##1 \l_tmpa_flag
296 }
297 }
298 \cs_set_protected:Npn \__kernel_chk_var_scope:NN
299 {
300 \@@_suspended:T \use_none:nnn
301 \@@_chk_var_scope_aux:NN
302 }
303 \cs_set_protected:Npn \__kernel_chk_var_local:N ##1
304 {
305 \@@_suspended:T \use_none:nnnnn
306 \__kernel_chk_var_exist:N ##1
307 \@@_chk_var_scope_aux:NN l ##1
308 }
309 \cs_set_protected:Npn \__kernel_chk_var_global:N ##1
310 {
311 \@@_suspended:T \use_none:nnnnn
312 \__kernel_chk_var_exist:N ##1
313 \@@_chk_var_scope_aux:NN g ##1
314 }
315 }
316 \cs_new_protected:cpn { @@_check-declarations_off: }
317 {
318 \cs_set_protected:Npn \__kernel_chk_var_exist:N ##1 { }
319 \cs_set_protected:Npn \__kernel_chk_cs_exist:N ##1 { }
320 \cs_set:Npn \__kernel_chk_flag_exist:NN { }
321 \cs_set_protected:Npn \__kernel_chk_var_local:N ##1 { }
322 \cs_set_protected:Npn \__kernel_chk_var_global:N ##1 { }
323 \cs_set_protected:Npn \__kernel_chk_var_scope:NN ##1##2 { }
324 }
325 % \end{macrocode}
326 % \end{macro}
327 % \end{macro}
328 % \end{macro}
329 % \end{macro}
330 % \end{macro}
331 %
332 % \begin{macro}{\@@_chk_var_scope_aux:NN}
333 % \begin{macro}{\@@_chk_var_scope_aux:Nn}
334 % \begin{macro}{\@@_chk_var_scope_aux:NNn}
335 % First check whether the name of the variable |#2| starts with
336 % \meta{letter}|_|. If it does then pass that letter, the
337 % \meta{scope}, and the variable name to
338 % \cs{@@_chk_var_scope_aux:NNn}. That function compares the two
339 % letters and triggers an error if they differ (the \cs{scan_stop:}
340 % case is not reachable here). If the second character was not |_|
341 % then pass the same data to the same auxiliary, except for its first
342 % argument which is now a control sequence. That control sequence is
343 % actually a token list (but to avoid triggering the checking code we
344 % manipulate it using \cs{cs_set_nopar:Npn}) containing a single
345 % letter \meta{scope} according to what the first assignment to the
346 % given variable was.
347 % \begin{macrocode}
348 \cs_new_protected:Npn \@@_chk_var_scope_aux:NN #1#2
349 { \exp_args:NNf \@@_chk_var_scope_aux:Nn #1 { \cs_to_str:N #2 } }
350 \cs_new_protected:Npn \@@_chk_var_scope_aux:Nn #1#2
351 {
352 \if:w _ \use_i:nn \@@_use_i_delimit_by_s_stop:nw #2 ? ? \s_@@_stop
353 \exp_after:wN \@@_chk_var_scope_aux:NNn
354 \@@_use_i_delimit_by_s_stop:nw #2 ? \s_@@_stop
355 #1 {#2}
356 \else:
357 \exp_args:Nc \@@_chk_var_scope_aux:NNn
358 { @@_chk_/ #2 }
359 #1 {#2}
360 \fi:
361 }
362 \cs_new_protected:Npn \@@_chk_var_scope_aux:NNn #1#2#3
363 {
364 \if:w #1 #2
365 \else:
366 \if:w #1 \scan_stop:
367 \cs_gset_nopar:Npn #1 {#2}
368 \else:
369 \msg_error:nneee { debug } { local-global }
370 {#1} {#2} { \iow_char:N \\ #3 }
371 \fi:
372 \fi:
373 }
374 \use:c { @@_check-declarations_off: }
375 % \end{macrocode}
376 % \end{macro}
377 % \end{macro}
378 % \end{macro}
379 %
380 % \begin{macro}{\@@_log-functions_on:, \@@_log-functions_off:}
381 % \begin{macro}{\__kernel_debug_log:e}
382 % These two functions (corresponding to the \pkg{expl3} option
383 % \texttt{log-functions}) control whether \cs{__kernel_debug_log:e}
384 % writes to the log file or not. By default, logging is off.
385 % \begin{macrocode}
386 \cs_new_protected:cpn { @@_log-functions_on: }
387 {
388 \cs_set_protected:Npn \__kernel_debug_log:e
389 { \@@_suspended:T \use_none:nn \iow_log:e }
390 }
391 \cs_new_protected:cpn { @@_log-functions_off: }
392 { \cs_set_protected:Npn \__kernel_debug_log:e { \use_none:n } }
393 \cs_new_protected:Npn \__kernel_debug_log:e { \use_none:n }
394 % \end{macrocode}
395 % \end{macro}
396 % \end{macro}
397 %
398 % \begin{macro}
399 % {\@@_check-expressions_on:, \@@_check-expressions_off:}
400 % \begin{macro}{\__kernel_chk_expr:nNnN}
401 % \begin{macro}{\@@_chk_expr_aux:nNnN}
402 % When debugging is enabled these two functions set
403 % \cs{__kernel_chk_expr:nNnN} to test or not whether the given
404 % expression is valid. The idea is to evaluate the expression within
405 % a brace group (to catch trailing \cs{use_none:nn} or similar), then
406 % test that the result is what we expect. This is done by turning it
407 % to an integer and hitting that with \cs{tex_romannumeral:D} after
408 % replacing the first character by |-0|. If all goes well, that
409 % primitive finds a non-positive integer and gives an empty output.
410 % If the original expression evaluation stopped early it leaves a
411 % trailing \cs{tex_relax:D}, which stops the second evaluation (used
412 % to convert to integer) before it encounters the final
413 % \cs{tex_relax:D}. Since \cs{tex_romannumeral:D} does not absorb
414 % \cs{tex_relax:D} the output will be nonempty. Note that |#3| is
415 % empty except for mu expressions for which it is \cs{tex_mutoglue:D}
416 % to avoid an \enquote{incompatible glue units} error. Note also that
417 % if we had omitted the first \cs{tex_relax:D} then for instance
418 % |1+2\relax+3| would incorrectly be accepted as a valid integer
419 % expression.
420 % \begin{macrocode}
421 \cs_new_protected:cpn { @@_check-expressions_on: }
422 {
423 \cs_set:Npn \__kernel_chk_expr:nNnN ##1##2
424 {
425 \@@_suspended:T { ##1 \use_none:nnnnnnn }
426 \exp_after:wN \@@_chk_expr_aux:nNnN
427 \exp_after:wN { \tex_the:D ##2 ##1 \scan_stop: }
428 ##2
429 }
430 }
431 \cs_new_protected:cpn { @@_check-expressions_off: }
432 { \cs_set:Npn \__kernel_chk_expr:nNnN ##1##2##3##4 {##1} }
433 \cs_new:Npn \__kernel_chk_expr:nNnN #1#2#3#4 {#1}
434 \cs_new:Npn \@@_chk_expr_aux:nNnN #1#2#3#4
435 {
436 \tl_if_empty:oF
437 {
438 \tex_romannumeral:D - 0
439 \exp_after:wN \use_none:n
440 \int_value:w #3 #2 #1 \scan_stop:
441 }
442 {
443 \msg_expandable_error:nnnn
444 { debug } { expr } {#4} {#1}
445 }
446 #1
447 }
448 % \end{macrocode}
449 % \end{macro}
450 % \end{macro}
451 % \end{macro}
452 %
453 % \begin{macro}{\@@_deprecation_on:, \@@_deprecation_off:}
454 % Make deprecated commands throw errors if the user requests it.
455 % This relies on two token lists, filled up in \pkg{l3deprecation} by
456 % calls to \cs{__kernel_deprecation_code:nn}.
457 % \begin{macrocode}
458 \cs_new_protected:Npn \@@_deprecation_on:
459 { \g_@@_deprecation_on_tl }
460 \cs_new_protected:Npn \@@_deprecation_off:
461 { \g_@@_deprecation_off_tl }
462 % \end{macrocode}
463 % \end{macro}
464 %
465 % \begin{variable}{
466 % \l_@@_tmp_tl,
467 % \l_@@_tmpa_tl,
468 % \l_@@_tmpb_tl,
469 % }
470 % For patching.
471 % \begin{macrocode}
472 \tl_new:N \l_@@_tmp_tl
473 \tl_new:N \l_@@_tmpa_tl
474 \tl_new:N \l_@@_tmpb_tl
475 % \end{macrocode}
476 % \end{variable}
477 %
478 % \begin{macro}{
479 % \@@_generate_parameter_list:NNN,
480 % \@@_build_parm_text:n,
481 % \@@_build_arg_list:n,
482 % \@@_arg_list_from_signature:nNN,
483 % \@@_arg_check_invalid:N,
484 % \@@_parm_terminate:w,
485 % \@@_arg_if_braced:n,
486 % \@@_get_base_form:N,
487 % \@@_arg_return:N,
488 % }
489 % \begin{macro}[TF]{\@@_arg_if_braced:N}
490 % Some functions don't take the arguments their signature indicates.
491 % For instance, \cs{clist_concat:NNN} doesn't take (directly) any
492 % argument, so patching it with something that uses |#1|, |#2|, or
493 % |#3| results in ``Illegal parameter number in definition of
494 % \cs{clist_concat:NNN}''.
495 %
496 % Instead of changing \emph{the} definition of the macros, we'll
497 % create a copy of such macros, say, \cs[no-index]{@@_clist_concat:NNN} which
498 % will be defined as
499 % |<debug code with #1, #2 and #3>\clist_concat:NNN#1#2#3|. For that
500 % we need to identify the signature of every function and build the
501 % appropriate parameter list.
502 %
503 % \cs{@@_generate_parameter_list:NNN} takes a function in |#1| and
504 % returns teo parameter lists: |#2| contains the simple |#1#2#3| as
505 % would be used in the \meta{parameter~text} of the definition and
506 % |#3| contains the same parameters but with braces where necessary.
507 %
508 % With the current implementation the resulting |#3| is, for example
509 % for |\some_function:NnNn|, |#1{#2}#3{#4}|. While this is correct,
510 % it might be unnecessary. Bracing everything will usually have the
511 % same outcome (unless the function was misused in the first place).
512 % What should be done?
513 % \begin{macrocode}
514 \cs_new_protected:Npn \@@_generate_parameter_list:NNN #1#2#3
515 {
516 \__kernel_tl_set:Nx \l_@@_tmp_tl
517 { \exp_last_unbraced:Nf \use_ii:nnn \cs_split_function:N #1 }
518 \__kernel_tl_set:Nx #2
519 { \exp_args:NV \@@_build_parm_text:n \l_@@_tmp_tl }
520 \__kernel_tl_set:Nx #3
521 { \exp_args:NV \@@_build_arg_list:n \l_@@_tmp_tl }
522 }
523 \cs_new:Npn \@@_build_parm_text:n #1
524 {
525 \@@_arg_list_from_signature:nNN { 1 } \c_false_bool #1
526 \q_@@_recursion_tail \q_@@_recursion_stop
527 }
528 \cs_new:Npn \@@_build_arg_list:n #1
529 {
530 \@@_arg_list_from_signature:nNN { 1 } \c_true_bool #1
531 \q_@@_recursion_tail \q_@@_recursion_stop
532 }
533 \cs_new:Npn \@@_arg_list_from_signature:nNN #1 #2 #3
534 {
535 \@@_if_recursion_tail_stop:N #3
536 \@@_arg_check_invalid:N #3
537 \bool_if:NT #2 { \@@_arg_if_braced:NT #3 { \use_none:n } }
538 \use:n { \c_hash_str \int_eval:n {#1} }
539 \exp_args:Nf \@@_arg_list_from_signature:nNN
540 { \int_eval:n {#1+1} } #2
541 }
542 % \end{macrocode}
543 % Argument types |w|, |p|, |T|, and |F| shouldn't be included in the
544 % parameter lists, so we abort the loop if either is found.
545 % \begin{macrocode}
546 \cs_new:Npn \@@_arg_check_invalid:N #1
547 {
548 \if:w w #1 \@@_parm_terminate:w \else:
549 \if:w p #1 \@@_parm_terminate:w \else:
550 \if:w T #1 \@@_parm_terminate:w \else:
551 \if:w F #1 \@@_parm_terminate:w \else:
552 \exp:w
553 \fi:
554 \fi:
555 \fi:
556 \fi:
557 \exp_end:
558 }
559 \cs_new:Npn \@@_parm_terminate:w
560 { \exp_after:wN \@@_use_none_delimit_by_q_recursion_stop:w \exp:w }
561 \prg_new_conditional:Npnn \@@_arg_if_braced:N #1 { T }
562 { \exp_args:Nf \@@_arg_if_braced:n { \@@_get_base_form:N #1 } }
563 \cs_new:Npn \@@_arg_if_braced:n #1
564 {
565 \if:w n #1 \prg_return_true: \else:
566 \if:w N #1 \prg_return_false: \else:
567 \msg_expandable_error:nnn
568 { debug } { bad-arg-type } {#1}
569 \fi:
570 \fi:
571 }
572 \msg_new:nnn { debug } { bad-arg-type }
573 { Wrong~argument~type~#1. }
574 % \end{macrocode}
575 % The macro below gets the base form of an
576 % argument type given a variant. It serves only to differentiate
577 % arguments which should be braced from ones which shouldn't. If all
578 % were to be braced this would be unnecessary. I moved the |n| and |N|
579 % variants to the beginning of the test as the are much more common
580 % here.
581 % \begin{macrocode}
582 \cs_new:Npn \@@_get_base_form:N #1
583 {
584 \if:w n #1 \@@_arg_return:N n \else:
585 \if:w N #1 \@@_arg_return:N N \else:
586 \if:w c #1 \@@_arg_return:N N \else:
587 \if:w o #1 \@@_arg_return:N n \else:
588 \if:w V #1 \@@_arg_return:N n \else:
589 \if:w v #1 \@@_arg_return:N n \else:
590 \if:w f #1 \@@_arg_return:N n \else:
591 \if:w e #1 \@@_arg_return:N n \else:
592 \if:w x #1 \@@_arg_return:N n \else:
593 \@@_arg_return:N \scan_stop:
594 \fi:
595 \fi:
596 \fi:
597 \fi:
598 \fi:
599 \fi:
600 \fi:
601 \fi:
602 \fi:
603 \exp_stop_f:
604 }
605 \cs_new:Npn \@@_arg_return:N #1
606 { \exp_after:wN #1 \exp:w \exp_end_continue_f:w }
607 % \end{macrocode}
608 % \end{macro}
609 % \end{macro}
610 %
611 % \begin{macro}{
612 % \__kernel_patch:nnn,
613 % \__kernel_patch_aux:nnn,
614 % \@@_setup_debug_code:Nnn,
615 % \@@_add_to_debug_code:Nnn,
616 % \@@_insert_debug_code:Nnn,
617 % \__kernel_patch_weird:nnn,
618 % \__kernel_patch_weird_aux:nnn,
619 % \@@_patch_weird:Nnn,
620 % }
621 % Simple patching by adding material at the start and end of (a
622 % collection of) functions is straight-forward as we know the catcode
623 % set up. The approach is essentially that in \pkg{etoolbox}. Notice
624 % the need to worry about spaces: those are otherwise lost as normally
625 % in \pkg{expl3} code they would be~|~|.
626 %
627 % As discussed above, some functions don't take arguments, so we can't
628 % patch something that uses an argument in them. For these functions
629 % \cs{__kernel_patch:nnn} is used. It starts by creating a copy of the
630 % function (say, \cs{clist_concat:NNN}) with a |__debug_| prefix in
631 % the name. This copy won't be changed. The code redefines the
632 % original function to take the exact same arguments as advertised in
633 % its signature (see \cs{@@_generate_parameter_list:NNN} above).
634 % The redefined function also contains the debug code in the proper
635 % position. If a function with the same name and the |__debug_| prefix
636 % was already defined, then the macro patches that definition by
637 % adding more debug code to it.
638 % \begin{macrocode}
639 \group_begin:
640 \cs_set_protected:Npn \__kernel_patch:nnn
641 {
642 \group_begin:
643 \char_set_catcode_other:N \#
644 \__kernel_patch_aux:nnn
645 }
646 \cs_set_protected:Npn \__kernel_patch_aux:nnn #1#2#3
647 {
648 \char_set_catcode_parameter:N \#
649 \char_set_catcode_space:N \ %
650 \tex_endlinechar:D -1 \scan_stop:
651 \tl_map_inline:nn {#3}
652 {
653 \cs_if_exist:cTF { @@_ \cs_to_str:N ##1 }
654 { \@@_add_to_debug_code:Nnn }
655 { \@@_setup_debug_code:Nnn }
656 ##1 {#1} {#2}
657 }
658 \group_end:
659 }
660 \cs_set_protected:Npn \@@_setup_debug_code:Nnn #1#2#3
661 {
662 \cs_gset_eq:cN { @@_ \cs_to_str:N #1 } #1
663 \@@_generate_parameter_list:NNN #1 \l_@@_tmpa_tl \l_@@_tmpb_tl
664 \exp_args:Ne \tex_scantokens:D
665 {
666 \tex_global:D \cs_prefix_spec:N #1
667 \tex_def:D \exp_not:N #1
668 \tl_use:N \l_@@_tmpa_tl
669 {
670 \tl_to_str:n {#2}
671 \exp_not:c { @@_ \cs_to_str:N #1 }
672 \tl_use:N \l_@@_tmpb_tl
673 \tl_to_str:n {#3}
674 }
675 }
676 }
677 \cs_set_protected:Npn \@@_add_to_debug_code:Nnn #1#2#3
678 {
679 \use:e
680 {
681 \cs_set:Npn \exp_not:N \@@_tmp:w
682 ##1 \tl_to_str:n { macro: }
683 ##2 \tl_to_str:n { -> }
684 ##3 \c_backslash_str \tl_to_str:n { @@_ }
685 \cs_to_str:N #1
686 ##4 \s_@@_stop
687 {
688 \exp_not:N \exp_args:Ne \exp_not:N \tex_scantokens:D
689 {
690 \tex_global:D ##1
691 \tex_def:D \exp_not:N #1 ##2
692 {
693 ##3 \tl_to_str:n {#2}
694 \c_backslash_str @@_ \cs_to_str:N #1
695 ##4 \tl_to_str:n {#3}
696 }
697 }
698 }
699 }
700 \exp_after:wN \@@_tmp:w \cs_meaning:N #1 \s_@@_stop
701 }
702 % \end{macrocode}
703 % Some functions, however, won't work with the signature reading setup
704 % above because their signature contains |w|eird arguments. These
705 % functions need to be patched using \cs{__kernel_patch_weird:nnn},
706 % which won't make a copy of the function, rather it will patch the
707 % debug code directly into it. This means that whatever argument the
708 % debug code uses must be actually used by the patched function.
709 % \begin{macrocode}
710 \cs_set_protected:Npn \__kernel_patch_weird:nnn
711 {
712 \group_begin:
713 \char_set_catcode_other:N \#
714 \__kernel_patch_weird_aux:nnn
715 }
716 \cs_set_protected:Npn \__kernel_patch_weird_aux:nnn #1#2#3
717 {
718 \char_set_catcode_parameter:N \#
719 \char_set_catcode_space:N \ %
720 \tex_endlinechar:D -1 \scan_stop:
721 \tl_map_inline:nn {#3}
722 { \@@_patch_weird:Nnn ##1 {#1} {#2} }
723 \group_end:
724 }
725 \cs_set_protected:Npn \@@_patch_weird:Nnn #1#2#3
726 {
727 \use:e
728 {
729 \tex_endlinechar:D -1 \scan_stop:
730 \exp_not:N \tex_scantokens:D
731 {
732 \tex_global:D \cs_prefix_spec:N #1
733 \tex_def:D \exp_not:N #1
734 \cs_parameter_spec:N #1
735 {
736 \tl_to_str:n {#2}
737 \cs_replacement_spec:N #1
738 \tl_to_str:n {#3}
739 }
740 }
741 }
742 }
743 % \end{macrocode}
744 % \end{macro}
745 %
746 % Patching the second argument to ensure it exists. This happens before
747 % we alter |#1| so the ordering is correct. For many variable types
748 % such as \texttt{int} a low-level error occurs when |#2| is unknown, so
749 % adding a check is not needed.
750 % \begin{macrocode}
751 \__kernel_patch:nnn
752 { \__kernel_chk_var_exist:N #2 }
753 { }
754 {
755 \bool_set_eq:NN
756 \bool_gset_eq:NN
757 \clist_set_eq:NN
758 \clist_gset_eq:NN
759 \fp_set_eq:NN
760 \fp_gset_eq:NN
761 \prop_set_eq:NN
762 \prop_gset_eq:NN
763 \seq_set_eq:NN
764 \seq_gset_eq:NN
765 \str_set_eq:NN
766 \str_gset_eq:NN
767 \tl_set_eq:NN
768 \tl_gset_eq:NN
769 }
770 % \end{macrocode}
771 %
772 % Patching both second and third arguments.
773 % \begin{macrocode}
774 \__kernel_patch:nnn
775 {
776 \__kernel_chk_var_exist:N #2
777 \__kernel_chk_var_exist:N #3
778 }
779 { }
780 {
781 \clist_concat:NNN
782 \clist_gconcat:NNN
783 \prop_concat:NNN
784 \prop_gconcat:NNN
785 \seq_concat:NNN
786 \seq_gconcat:NNN
787 \str_concat:NNN
788 \str_gconcat:NNN
789 \tl_concat:NNN
790 \tl_gconcat:NNN
791 }
792 % \end{macrocode}
793 %
794 %
795 % \begin{macrocode}
796 \cs_gset_protected:Npn \__kernel_tl_set:Nx { \cs_set_nopar:Npe }
797 \cs_gset_protected:Npn \__kernel_tl_gset:Nx { \cs_gset_nopar:Npe }
798 % \end{macrocode}
799 %
800 % Patching where the first argument to a function needs scope-checking:
801 % either local or global (so two lists).
802 % \begin{macrocode}
803 \__kernel_patch:nnn
804 { \__kernel_chk_var_local:N #1 }
805 { }
806 {
807 \bool_set:Nn
808 \bool_set_eq:NN
809 \bool_set_true:N
810 \bool_set_false:N
811 \box_set_eq:NN
812 \box_set_eq_drop:NN
813 \box_set_to_last:N
814 \clist_clear:N
815 \clist_set_eq:NN
816 \dim_zero:N
817 \dim_set:Nn
818 \dim_set_eq:NN
819 \dim_add:Nn
820 \dim_sub:Nn
821 \fp_set_eq:NN
822 \int_zero:N
823 \int_set_eq:NN
824 \int_add:Nn
825 \int_sub:Nn
826 \int_incr:N
827 \int_decr:N
828 \int_set:Nn
829 \hbox_set:Nn
830 \hbox_set_to_wd:Nnn
831 \hbox_set:Nw
832 \hbox_set_to_wd:Nnw
833 \muskip_zero:N
834 \muskip_set:Nn
835 \muskip_add:Nn
836 \muskip_sub:Nn
837 \muskip_set_eq:NN
838 \prop_clear:N
839 \prop_concat:NNN
840 \prop_pop:NnN
841 \prop_pop:NnNT
842 \prop_pop:NnNF
843 \prop_pop:NnNTF
844 \prop_put:Nnn
845 \prop_put_if_not_in:Nnn
846 \prop_put_from_keyval:Nn
847 \prop_remove:Nn
848 \prop_set_eq:NN
849 \prop_set_from_keyval:Nn
850 \seq_set_eq:NN
851 \skip_zero:N
852 \skip_set:Nn
853 \skip_set_eq:NN
854 \skip_add:Nn
855 \skip_sub:Nn
856 \str_clear:N
857 \str_set_eq:NN
858 \str_put_left:Nn
859 \str_put_right:Nn
860 \__kernel_tl_set:Nx
861 \tl_clear:N
862 \tl_set_eq:NN
863 \tl_put_left:Nn
864 \tl_put_left:NV
865 \tl_put_left:Nv
866 \tl_put_left:Ne
867 \tl_put_left:No
868 \tl_put_right:Nn
869 \tl_put_right:NV
870 \tl_put_right:Nv
871 \tl_put_right:Ne
872 \tl_put_right:No
873 \tl_build_begin:N
874 \tl_build_put_right:Nn
875 \tl_build_put_left:Nn
876 \vbox_set:Nn
877 \vbox_set_top:Nn
878 \vbox_set_to_ht:Nnn
879 \vbox_set_top_to_ht:Nnn
880 \vbox_set:Nw
881 \vbox_set_to_ht:Nnw
882 \vbox_set_split_to_ht:NNn
883 }
884 \__kernel_patch:nnn
885 { \__kernel_chk_var_global:N #1 }
886 { }
887 {
888 \bool_gset:Nn
889 \bool_gset_eq:NN
890 \bool_gset_true:N
891 \bool_gset_false:N
892 \box_gset_eq:NN
893 \box_gset_eq_drop:NN
894 \box_gset_to_last:N
895 \cctab_gset:Nn
896 \clist_gclear:N
897 \clist_gset_eq:NN
898 \dim_gset_eq:NN
899 \dim_gzero:N
900 \dim_gset:Nn
901 \dim_gadd:Nn
902 \dim_gsub:Nn
903 \fp_gset_eq:NN
904 \int_gzero:N
905 \int_gset_eq:NN
906 \int_gadd:Nn
907 \int_gsub:Nn
908 \int_gincr:N
909 \int_gdecr:N
910 \int_gset:Nn
911 \hbox_gset:Nn
912 \hbox_gset_to_wd:Nnn
913 \hbox_gset:Nw
914 \hbox_gset_to_wd:Nnw
915 \muskip_gzero:N
916 \muskip_gset:Nn
917 \muskip_gadd:Nn
918 \muskip_gsub:Nn
919 \muskip_gset_eq:NN
920 \prop_gclear:N
921 \prop_gconcat:NNN
922 \prop_gpop:NnN
923 \prop_gpop:NnNT
924 \prop_gpop:NnNF
925 \prop_gpop:NnNTF
926 \prop_gput:Nnn
927 \prop_gput_if_not_in:Nnn
928 \prop_gput_from_keyval:Nn
929 \prop_gremove:Nn
930 \prop_gset_eq:NN
931 \prop_gset_from_keyval:Nn
932 \seq_gset_eq:NN
933 \skip_gzero:N
934 \skip_gset:Nn
935 \skip_gset_eq:NN
936 \skip_gadd:Nn
937 \skip_gsub:Nn
938 \str_gclear:N
939 \str_gset_eq:NN
940 \str_gput_left:Nn
941 \str_gput_right:Nn
942 \__kernel_tl_gset:Nx
943 \tl_gclear:N
944 \tl_gset_eq:NN
945 \tl_gput_left:Nn
946 \tl_gput_left:NV
947 \tl_gput_left:Nv
948 \tl_gput_left:Ne
949 \tl_gput_left:No
950 \tl_gput_right:Nn
951 \tl_gput_right:NV
952 \tl_gput_right:Nv
953 \tl_gput_right:Ne
954 \tl_gput_right:No
955 \tl_build_gbegin:N
956 \tl_build_gput_right:Nn
957 \tl_build_gput_left:Nn
958 \vbox_gset:Nn
959 \vbox_gset_top:Nn
960 \vbox_gset_to_ht:Nnn
961 \vbox_gset_top_to_ht:Nnn
962 \vbox_gset:Nw
963 \vbox_gset_to_ht:Nnw
964 \vbox_gset_split_to_ht:NNn
965 }
966 % \end{macrocode}
967 %
968 % Scoping for constants.
969 % \begin{macrocode}
970 \__kernel_patch:nnn
971 { \__kernel_chk_var_scope:NN c #1 }
972 { }
973 {
974 \bool_const:Nn
975 \cctab_const:Nn
976 \dim_const:Nn
977 \int_const:Nn
978 \intarray_const_from_clist:Nn
979 \muskip_const:Nn
980 \prop_const_from_keyval:Nn
981 \prop_const_linked_from_keyval:Nn
982 \skip_const:Nn
983 \str_const:Nn
984 \tl_const:Nn
985 }
986 % \end{macrocode}
987 %
988 % Flag functions.
989 % \begin{macrocode}
990 \__kernel_patch:nnn
991 { \__kernel_chk_flag_exist:NN }
992 { }
993 {
994 \flag_ensure_raised:N
995 \flag_height:N
996 \flag_if_raised:NT
997 \flag_if_raised:NF
998 \flag_if_raised:NTF
999 \flag_if_raised_p:N
1000 \flag_raise:N
1001 }
1002 % \end{macrocode}
1003 %
1004 % Various one-offs.
1005 % \begin{macrocode}
1006 \__kernel_patch:nnn
1007 { \__kernel_chk_cs_exist:N #1 }
1008 { }
1009 { \cs_generate_variant:Nn }
1010 \__kernel_patch:nnn
1011 { \__kernel_chk_var_scope:NN g #1 }
1012 { }
1013 { \cctab_new:N }
1014 \__kernel_patch:nnn
1015 { \__kernel_chk_var_scope:NN l #1 }
1016 { }
1017 { \flag_new:N }
1018 \__kernel_patch:nnn
1019 {
1020 \__kernel_chk_var_scope:NN l #1
1021 \__kernel_chk_flag_exist:NN
1022 }
1023 { }
1024 { \flag_clear:N }
1025 \__kernel_patch:nnn
1026 { \__kernel_chk_var_scope:NN g #1 }
1027 { }
1028 { \intarray_new:Nn }
1029 \__kernel_patch:nnn
1030 { \__kernel_chk_var_scope:NN q #1 }
1031 { }
1032 { \quark_new:N }
1033 \__kernel_patch:nnn
1034 { \__kernel_chk_var_scope:NN s #1 }
1035 { }
1036 { \scan_new:N }
1037 % \end{macrocode}
1038 %
1039 % Patch various internal commands to log definitions of functions.
1040 % First, a kernel internal. Then internals from the \pkg{cs},
1041 % \pkg{keys} and \pkg{msg} modules.
1042 % \begin{macrocode}
1043 \__kernel_patch:nnn
1044 { }
1045 {
1046 \__kernel_debug_log:e
1047 { Defining~\token_to_str:N #1~ \msg_line_context: }
1048 }
1049 { \__kernel_chk_if_free_cs:N }
1050 %<@@=cs>
1051 \__kernel_patch_weird:nnn
1052 {
1053 \cs_if_free:NF #4
1054 {
1055 \__kernel_debug_log:e
1056 {
1057 Variant~\token_to_str:N #4~%
1058 already~defined;~ not~ changing~ it~ \msg_line_context:
1059 }
1060 }
1061 }
1062 { }
1063 { \@@_generate_variant:wwNN }
1064 %<@@=keys>
1065 \__kernel_patch:nnn
1066 {
1067 \cs_if_exist:cF { \c_@@_code_root_str #1 }
1068 { \__kernel_debug_log:e { Defining~key~#1~\msg_line_context: } }
1069 }
1070 { }
1071 { \@@_cmd_set_direct:nn }
1072 %<@@=msg>
1073 \__kernel_patch:nnn
1074 { }
1075 {
1076 \__kernel_debug_log:e
1077 { Defining~message~ #1 / #2 ~\msg_line_context: }
1078 }
1079 { \@@_chk_free:nn }
1080 % \end{macrocode}
1081 %
1082 % \begin{macrocode}
1083 %<@@=prg>
1084 % \end{macrocode}
1085 % Internal functions from \pkg{prg} module.
1086 % \begin{macrocode}
1087 \__kernel_patch_weird:nnn
1088 { \__kernel_chk_cs_exist:c { #5 _p : #6 } }
1089 { }
1090 { \@@_set_eq_conditional_p_form:wNnnnn }
1091 \__kernel_patch_weird:nnn
1092 { \__kernel_chk_cs_exist:c { #5 : #6 TF } }
1093 { }
1094 { \@@_set_eq_conditional_TF_form:wNnnnn }
1095 \__kernel_patch_weird:nnn
1096 { \__kernel_chk_cs_exist:c { #5 : #6 T } }
1097 { }
1098 { \@@_set_eq_conditional_T_form:wNnnnn }
1099 \__kernel_patch_weird:nnn
1100 { \__kernel_chk_cs_exist:c { #5 : #6 F } }
1101 { }
1102 { \@@_set_eq_conditional_F_form:wNnnnn }
1103 % \end{macrocode}
1104 %
1105 % \begin{macrocode}
1106 %<@@=regex>
1107 % \end{macrocode}
1108 % Internal functions from \pkg{regex} module.
1109 % \begin{macrocode}
1110 \__kernel_patch:nnn
1111 {
1112 \@@_trace_push:nnN { regex } { 1 } \@@_escape_use:nnnn
1113 \group_begin:
1114 \__kernel_tl_set:Nx \l_@@_tmpa_tl
1115 { \@@_trace_pop:nnN { regex } { 1 } \@@_escape_use:nnnn }
1116 \use_none:nnn
1117 }
1118 { }
1119 { \@@_escape_use:nnn }
1120 \__kernel_patch:nnn
1121 { \@@_trace_push:nnN { regex } { 1 } \@@_build:N }
1122 {
1123 \@@_trace_states:n { 2 }
1124 \@@_trace_pop:nnN { regex } { 1 } \@@_build:N
1125 }
1126 { \@@_build:N }
1127 \__kernel_patch:nnn
1128 { \@@_trace_push:nnN { regex } { 1 } \@@_build_for_cs:n }
1129 {
1130 \@@_trace_states:n { 2 }
1131 \@@_trace_pop:nnN { regex } { 1 } \@@_build_for_cs:n
1132 }
1133 { \@@_build_for_cs:n }
1134 \__kernel_patch:nnn
1135 {
1136 \@@_trace:nne { regex } { 2 }
1137 {
1138 regex~new~state~
1139 L=\int_use:N \l_@@_left_state_int ~ -> ~
1140 R=\int_use:N \l_@@_right_state_int ~ -> ~
1141 M=\int_use:N \l_@@_max_state_int ~ -> ~
1142 \int_eval:n { \l_@@_max_state_int + 1 }
1143 }
1144 }
1145 { }
1146 { \@@_build_new_state: }
1147 \__kernel_patch:nnn
1148 { \@@_trace_push:nnN { regex } { 1 } \@@_group_aux:nnnnN }
1149 { \@@_trace_pop:nnN { regex } { 1 } \@@_group_aux:nnnnN }
1150 { \@@_group_aux:nnnnN }
1151 \__kernel_patch:nnn
1152 { \@@_trace_push:nnN { regex } { 1 } \@@_branch:n }
1153 { \@@_trace_pop:nnN { regex } { 1 } \@@_branch:n }
1154 { \@@_branch:n }
1155 \__kernel_patch:nnn
1156 {
1157 \@@_trace_push:nnN { regex } { 1 } \@@_match:n
1158 \@@_trace:nne { regex } { 1 } { analyzing~query~token~list }
1159 }
1160 { \@@_trace_pop:nnN { regex } { 1 } \@@_match:n }
1161 { \@@_match:n }
1162 \__kernel_patch:nnn
1163 {
1164 \@@_trace_push:nnN { regex } { 1 } \@@_match_cs:n
1165 \@@_trace:nne { regex } { 1 } { analyzing~query~token~list }
1166 }
1167 { \@@_trace_pop:nnN { regex } { 1 } \@@_match_cs:n }
1168 { \@@_match_cs:n }
1169 \__kernel_patch:nnn
1170 { \@@_trace:nne { regex } { 1 } { initializing } }
1171 { }
1172 { \@@_match_init: }
1173 \__kernel_patch:nnn
1174 {
1175 \@@_trace:nne { regex } { 2 }
1176 { state~\int_use:N \l_@@_curr_state_int }
1177 }
1178 { }
1179 { \@@_use_state: }
1180 \__kernel_patch:nnn
1181 { \@@_trace_push:nnN { regex } { 1 } \@@_replacement:n }
1182 { \@@_trace_pop:nnN { regex } { 1 } \@@_replacement:n }
1183 { \@@_replacement:n }
1184 % \end{macrocode}
1185 %
1186 % \begin{macrocode}
1187 \group_end:
1188 % \end{macrocode}
1189 %
1190 % \begin{macrocode}
1191 %<@@=debug>
1192 % \end{macrocode}
1193 %
1194 % Patching arguments is a bit more involved: we do these one at a time.
1195 % The basic idea is the same, using a |#| token that is a string.
1196 % \begin{macrocode}
1197 \group_begin:
1198 \cs_set_protected:Npn \__kernel_patch:Nn #1
1199 {
1200 \group_begin:
1201 \char_set_catcode_other:N \#
1202 \__kernel_patch_aux:Nn #1
1203 }
1204 \cs_set_protected:Npn \__kernel_patch_aux:Nn #1#2
1205 {
1206 \char_set_catcode_parameter:N \#
1207 \tex_endlinechar:D -1 \scan_stop:
1208 \exp_args:Ne \tex_scantokens:D
1209 {
1210 \tex_global:D \cs_prefix_spec:N #1 \tex_def:D \exp_not:N #1
1211 \cs_parameter_spec:N #1
1212 { \exp_args:No \tl_to_str:n { #1 #2 } }
1213 }
1214 \group_end:
1215 }
1216 % \end{macrocode}
1217 %
1218 % The functions here can get a bit repetitive, so we define a helper
1219 % which can reuse the same patch code repeatedly. The main part of the
1220 % patch is the same, so we just have to deal with the part which varies
1221 % depending on the type of expression.
1222 % \begin{macrocode}
1223 \cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
1224 {
1225 \tl_map_inline:nn {#1}
1226 {
1227 \exp_args:NNe \__kernel_patch:Nn ##1
1228 {
1229 { \c_hash_str 1 }
1230 {
1231 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
1232 \exp_not:n {#2}
1233 \exp_not:N ##1
1234 }
1235 }
1236 }
1237 }
1238 %<@@=dim>
1239 \__kernel_patch_eval:nn
1240 {
1241 \dim_set:Nn
1242 \dim_gset:Nn
1243 \dim_add:Nn
1244 \dim_gadd:Nn
1245 \dim_sub:Nn
1246 \dim_gsub:Nn
1247 \dim_const:Nn
1248 }
1249 { \@@_eval:w { } }
1250 %<@@=int>
1251 \__kernel_patch_eval:nn
1252 {
1253 \int_set:Nn
1254 \int_gset:Nn
1255 \int_add:Nn
1256 \int_gadd:Nn
1257 \int_sub:Nn
1258 \int_gsub:Nn
1259 \int_const:Nn
1260 }
1261 { \@@_eval:w { } }
1262 \__kernel_patch_eval:nn
1263 {
1264 \muskip_set:Nn
1265 \muskip_gset:Nn
1266 \muskip_add:Nn
1267 \muskip_gadd:Nn
1268 \muskip_sub:Nn
1269 \muskip_gsub:Nn
1270 \muskip_const:Nn
1271 }
1272 { \tex_muexpr:D { \tex_mutoglue:D } }
1273 \__kernel_patch_eval:nn
1274 {
1275 \skip_set:Nn
1276 \skip_gset:Nn
1277 \skip_add:Nn
1278 \skip_gadd:Nn
1279 \skip_sub:Nn
1280 \skip_gsub:Nn
1281 \skip_const:Nn
1282 }
1283 { \tex_glueexpr:D { } }
1284 % \end{macrocode}
1285 %
1286 % Patching expandable expressions, first the one-argument versions,
1287 % then the two-argument ones.
1288 % \begin{macrocode}
1289 \cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
1290 {
1291 \tl_map_inline:nn {#1}
1292 {
1293 \exp_args:NNe \__kernel_patch:Nn ##1
1294 {
1295 {
1296 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
1297 \exp_not:n {#2}
1298 \exp_not:N ##1
1299 }
1300 }
1301 }
1302 }
1303 %<@@=box>
1304 \__kernel_patch_eval:nn
1305 { \@@_dim_eval:n }
1306 { \@@_dim_eval:w { } }
1307 %<@@=dim>
1308 \__kernel_patch_eval:nn
1309 {
1310 \dim_eval:n
1311 \dim_to_decimal:n
1312 \dim_to_decimal_in_sp:n
1313 \dim_abs:n
1314 \dim_sign:n
1315 }
1316 { \@@_eval:w { } }
1317 %<@@=int>
1318 \__kernel_patch_eval:nn
1319 {
1320 \int_eval:n
1321 \int_abs:n
1322 \int_sign:n
1323 }
1324 { \@@_eval:w { } }
1325 \__kernel_patch_eval:nn
1326 {
1327 \skip_eval:n
1328 \skip_horizontal:n
1329 \skip_vertical:n
1330 }
1331 { \tex_glueexpr:D { } }
1332 \__kernel_patch_eval:nn
1333 {
1334 \muskip_eval:n
1335 }
1336 { \tex_muexpr:D { \tex_mutoglue:D } }
1337 \cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
1338 {
1339 \tl_map_inline:nn {#1}
1340 {
1341 \exp_args:NNe \__kernel_patch:Nn ##1
1342 {
1343 {
1344 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
1345 \exp_not:n {#2}
1346 \exp_not:N ##1
1347 }
1348 {
1349 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
1350 \exp_not:n {#2}
1351 \exp_not:N ##1
1352 }
1353 }
1354 }
1355 }
1356 %<@@=dim>
1357 \__kernel_patch_eval:nn
1358 {
1359 \dim_max:nn
1360 \dim_min:nn
1361 }
1362 { \@@_eval:w { } }
1363 %<@@=int>
1364 \__kernel_patch_eval:nn
1365 {
1366 \int_max:nn
1367 \int_min:nn
1368 \int_div_truncate:nn
1369 \int_mod:nn
1370 }
1371 { \@@_eval:w { } }
1372 % \end{macrocode}
1373 %
1374 % Conditionals: three argument ones then one argument ones
1375 % \begin{macrocode}
1376 \cs_set_protected:Npn \__kernel_patch_cond:nn #1#2
1377 {
1378 \clist_map_inline:nn { :nNnT , :nNnF , :nNnTF , _p:nNn }
1379 {
1380 \exp_args:Nce \__kernel_patch:Nn { #1 ##1 }
1381 {
1382 {
1383 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
1384 \exp_not:n {#2}
1385 \exp_not:c { #1 ##1 }
1386 }
1387 { \c_hash_str 2 }
1388 {
1389 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 3 }
1390 \exp_not:n {#2}
1391 \exp_not:c { #1 ##1 }
1392 }
1393 }
1394 }
1395 }
1396 %<@@=dim>
1397 \__kernel_patch_cond:nn { dim_compare } { \@@_eval:w { } }
1398 %<@@=int>
1399 \__kernel_patch_cond:nn { int_compare } { \@@_eval:w { } }
1400 \cs_set_protected:Npn \__kernel_patch_cond:nn #1#2
1401 {
1402 \clist_map_inline:nn { :nT , :nF , :nTF , _p:n }
1403 {
1404 \exp_args:Nce \__kernel_patch:Nn { #1 ##1 }
1405 {
1406 {
1407 \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
1408 \exp_not:n {#2}
1409 \exp_not:c { #1 ##1 }
1410 }
1411 }
1412 }
1413 }
1414 %<@@=int>
1415 \__kernel_patch_cond:nn { int_if_even } { \@@_eval:w { } }
1416 \__kernel_patch_cond:nn { int_if_odd } { \@@_eval:w { } }
1417 % \end{macrocode}
1418 %
1419 % Step functions.
1420 % \begin{macrocode}
1421 %<@@=dim>
1422 \__kernel_patch:Nn \dim_step_function:nnnN
1423 {
1424 {
1425 \__kernel_chk_expr:nNnN {#1} \@@_eval:w { }
1426 \dim_step_function:nnnN
1427 }
1428 {
1429 \__kernel_chk_expr:nNnN {#2} \@@_eval:w { }
1430 \dim_step_function:nnnN
1431 }
1432 {
1433 \__kernel_chk_expr:nNnN {#3} \@@_eval:w { }
1434 \dim_step_function:nnnN
1435 }
1436 }
1437 %<@@=int>
1438 \__kernel_patch:Nn \int_step_function:nnnN
1439 {
1440 {
1441 \__kernel_chk_expr:nNnN {#1} \@@_eval:w { }
1442 \int_step_function:nnnN
1443 }
1444 {
1445 \__kernel_chk_expr:nNnN {#2} \@@_eval:w { }
1446 \int_step_function:nnnN
1447 }
1448 {
1449 \__kernel_chk_expr:nNnN {#3} \@@_eval:w { }
1450 \int_step_function:nnnN
1451 }
1452 }
1453 % \end{macrocode}
1454 %
1455 % Odds and ends
1456 % \begin{macrocode}
1457 \__kernel_patch:Nn \dim_to_fp:n { { (#1) } }
1458 % \end{macrocode}
1459 %
1460 % \begin{macrocode}
1461 \group_end:
1462 % \end{macrocode}
1463 %
1464 % \begin{macrocode}
1465 %<@@=skip>
1466 % \end{macrocode}
1467 % This one has catcode changes so must be done by hand.
1468 % \begin{macrocode}
1469 \cs_set_protected:Npn \@@_tmp:w #1
1470 {
1471 \prg_set_conditional:Npnn \skip_if_finite:n ##1 { p , T , F , TF }
1472 {
1473 \exp_after:wN \@@_if_finite:wwNw
1474 \skip_use:N \tex_glueexpr:D
1475 \__kernel_chk_expr:nNnN
1476 {##1} \tex_glueexpr:D { } \skip_if_finite:n
1477 \@@_sep: \prg_return_false:
1478 #1 \@@_sep: \prg_return_true: \s_@@_stop
1479 }
1480 }
1481 \exp_args:No \@@_tmp:w { \tl_to_str:n { fil } }
1482 % \end{macrocode}
1483 %
1484 % \begin{macrocode}
1485 %<@@=msg>
1486 % \end{macrocode}
1487 %
1488 % Messages.
1489 % \begin{macrocode}
1490 \msg_new:nnnn { debug } { debug }
1491 { The~debugging~option~'#1'~does~not~exist~\msg_line_context:. }
1492 {
1493 The~functions~'\iow_char:N\\debug_on:n'~and~
1494 '\iow_char:N\\debug_off:n'~only~accept~the~arguments~
1495 'all',~'check-declarations',~'check-expressions',~
1496 'deprecation',~'log-functions',~not~'#1'.
1497 }
1498 \msg_new:nnn { debug } { expr } { '#2'~in~#1 }
1499 \msg_new:nnnn { debug } { local-global }
1500 { Inconsistent~local/global~assignment }
1501 {
1502 \c_@@_coding_error_text_tl
1503 \if:w l #2 Local
1504 \else:
1505 \if:w g #2 Global \else: Constant \fi:
1506 \fi:
1507 \ %
1508 assignment~to~a~
1509 \if:w l #1 local
1510 \else:
1511 \if:w g #1 global \else: constant \fi:
1512 \fi:
1513 \ %
1514 variable~'#3'.
1515 }
1516 \msg_new:nnnn { debug } { non-declared-variable }
1517 { The~variable~#1~has~not~been~declared~\msg_line_context:. }
1518 {
1519 \c_@@_coding_error_text_tl
1520 Checking~is~active,~and~you~have~tried~do~so~something~like: \\
1521 \ \ \tl_set:Nn ~ #1 ~ \{ ~ ... ~ \} \\
1522 without~first~having: \\
1523 \ \ \tl_new:N ~ #1 \\
1524 \\
1525 LaTeX~will~continue,~creating~the~variable~where~it~is~the~one~being~set.
1526 }
1527 % \end{macrocode}
1528 %
1529 % \begin{macro}{\__kernel_if_debug:TF}
1530 % Flip the switch for deprecated code.
1531 % \begin{macrocode}
1532 \cs_set_protected:Npn \__kernel_if_debug:TF #1#2 {#1}
1533 % \end{macrocode}
1534 % \end{macro}
1535 %
1536 % \begin{macrocode}
1537 %</def>
1538 % \end{macrocode}
1539 %
1540 % \end{implementation}
1541 %
1542 % \PrintIndex