Skip to content

Commit

Permalink
Final \__int removals
Browse files Browse the repository at this point in the history
We have enough 'open ended' int expression usage that we do need
\int_eval:w I think. That allows us to reduce the number of
\@@_int_eval:w cases to those which are *really* needed (FPU).
  • Loading branch information
josephwright committed Mar 30, 2018
1 parent e5d4d96 commit 3e73c2f
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 128 deletions.
30 changes: 13 additions & 17 deletions l3experimental/l3str/l3str-convert.dtx
Expand Up @@ -434,9 +434,7 @@
\if_int_compare:w 1 < "1 \token_to_str:N #1 \exp_stop_f:
#1 \prg_return_true:
\else:
\if_case:w \__int_eval:w
\exp_after:wN ` \token_to_str:N #1 - `a
\__int_eval_end:
\if_case:w \int_eval:n { \exp_after:wN ` \token_to_str:N #1 - `a }
A
\or: B
\or: C
Expand Down Expand Up @@ -501,18 +499,18 @@
{
\exp_after:wN \exp_after:wN
\exp_after:wN \use_i:nnn
\cs:w c_@@_byte_ \__int_value:w \__int_eval:w
\cs:w c_@@_byte_ \int_value:w \int_eval:w
}
\cs_new:Npn \@@_output_hexadecimal:n #1
{ \@@_output_hexadecimal:w #1 \@@_output_end: }
\cs_new:Npn \@@_output_hexadecimal:w
{
\exp_after:wN \exp_after:wN
\exp_after:wN \use_none:n
\cs:w c_@@_byte_ \__int_value:w \__int_eval:w
\cs:w c_@@_byte_ \int_value:w \int_eval:w
}
\cs_new:Npn \@@_output_end:
{ \__int_eval_end: _tl \cs_end: }
{ \scan_stop: _tl \cs_end: }
% \end{macrocode}
% \end{macro}
% \end{macro}
Expand Down Expand Up @@ -996,7 +994,7 @@
\cs_new_protected:Npn \@@_convert_decode_:
{ \@@_convert_gmap:N \@@_decode_native_char:N }
\cs_new:Npn \@@_decode_native_char:N #1
{ #1 \s__tl \__int_value:w `#1 \s__tl }
{ #1 \s__tl \int_value:w `#1 \s__tl }
% \end{macrocode}
% \end{macro}
% \end{macro}
Expand Down Expand Up @@ -1211,7 +1209,7 @@
\use_none_delimit_by_q_stop:w #1 \q_stop
\tex_dimen:D "#1 = \l_@@_internal_int sp \scan_stop:
\tex_skip:D \l_@@_internal_int = "#1 sp \scan_stop:
\tex_toks:D \l_@@_internal_int \exp_after:wN { \__int_value:w "#2 }
\tex_toks:D \l_@@_internal_int \exp_after:wN { \int_value:w "#2 }
\int_incr:N \l_@@_internal_int
\@@_decode_eight_bit_load:nn
}
Expand All @@ -1233,7 +1231,7 @@
\tex_the:D \tex_toks:D \tex_dimen:D
\fi:
\fi:
\__int_value:w `#1 \s__tl
\int_value:w `#1 \s__tl
}
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -1877,7 +1875,7 @@
\exp_after:wN \use_none_delimit_by_q_stop:w
\fi:
\exp_after:wN \@@_encode_utf_viii_loop:wwnnw
\__int_value:w \int_div_truncate:nn {#1} {64} ; #1 ;
\int_value:w \int_div_truncate:nn {#1} {64} ; #1 ;
#5 \q_stop
\@@_output_byte:n { #2 - 64 * ( #1 - 2 ) }
}
Expand Down Expand Up @@ -2054,15 +2052,15 @@
\if_int_compare:w `#1 < "C0 \exp_stop_f:
\s__tl
\if_int_compare:w `#1 < "80 \exp_stop_f:
\__int_value:w `#1
\int_value:w `#1
\else:
\flag_raise:n { str_extra }
\flag_raise:n { str_error }
\int_use:N \c_@@_replacement_char_int
\fi:
\else:
\exp_after:wN \@@_decode_utf_viii_continuation:wwN
\__int_value:w \__int_eval:w `#1 - "C0 \exp_after:wN \__int_eval_end:
\int_value:w \int_eval:n { `#1 - "C0 } \exp_after:wN
\fi:
\s__tl
\use_none_delimit_by_q_stop:w {"80} {"800} {"10000} {"110000} \q_stop
Expand All @@ -2077,9 +2075,7 @@
"C0 \exp_stop_f:
#3
\exp_after:wN \@@_decode_utf_viii_aux:wNnnwN
\__int_value:w \__int_eval:w
#1 * "40 + `#3 - "80
\exp_after:wN \__int_eval_end:
\int_value:w \int_eval:n { #1 * "40 + `#3 - "80 } \exp_after:wN
\else:
\s__tl
\flag_raise:n { str_missing }
Expand Down Expand Up @@ -2107,7 +2103,7 @@
\@@_decode_utf_viii_overflow:w #1
\fi:
\exp_after:wN \@@_decode_utf_viii_continuation:wwN
\__int_value:w \__int_eval:w #1 - #4 \exp_after:wN \__int_eval_end:
\int_value:w \int_eval:n { #1 - #4 } \exp_after:wN
\fi:
\s__tl
#2 {#4} #5
Expand Down Expand Up @@ -2398,7 +2394,7 @@
\@@_decode_utf_xvi_pair_end:Nw #1
\fi:
\if_case:w
\__int_eval:w ( \@@_tmp:w #1#2 - "D6 ) / 4 \__int_eval_end:
\int_eval:n { ( \@@_tmp:w #1#2 - "D6 ) / 4 } \scan_stop:
\or: \exp_after:wN \@@_decode_utf_xvi_quad:NNwNN
\or: \exp_after:wN \@@_decode_utf_xvi_extra:NNw
\fi:
Expand Down
8 changes: 4 additions & 4 deletions l3experimental/xgalley/l3galley.dtx
Expand Up @@ -2452,7 +2452,7 @@
}
}
\cs_new:Npn \@@_save_display_club_penalties:n #1
{ \__int_value:w \etex_clubpenalties:D \int_eval:n {#1} , }
{ \int_value:w \etex_clubpenalties:D \int_eval:n {#1} , }
\cs_new_protected:Npn \galley_save_display_widow_penalties:N #1
{
\clist_set:Nx #1
Expand All @@ -2464,7 +2464,7 @@
}
\cs_new:Npn \@@_save_display_widow_penalties:n #1
{
\__int_value:w \etex_displaywidowpenalties:D
\int_value:w \etex_displaywidowpenalties:D
\int_eval:n {#1} ,
}
\cs_new_protected:Npn \galley_save_widow_penalties:N #1
Expand All @@ -2477,14 +2477,14 @@
}
}
\cs_new:Npn \@@_save_widow_penalties:n #1
{ \__int_value:w \etex_widowpenalties:D \int_eval:n {#1} , }
{ \int_value:w \etex_widowpenalties:D \int_eval:n {#1} , }
% \end{macrocode}
% This one is not an array, but is stored in a primitive, so there is
% a simple conversion. The general interline penalty is always the
% last value in the primitive array.
% \begin{macrocode}
\cs_new_protected:Npn \galley_interline_penalty:
{ \__int_value:w \etex_interlinepenalties:D \etex_interlinepenalties:D 0 \exp_stop_f: }
{ \int_value:w \etex_interlinepenalties:D \etex_interlinepenalties:D 0 \exp_stop_f: }
% \end{macrocode}
% \end{macro}
% \end{macro}
Expand Down
8 changes: 4 additions & 4 deletions l3kernel/l3candidates.dtx
Expand Up @@ -4147,14 +4147,14 @@
\exp_after:wN { \exp_after:wN }
\fi:
\exp_after:wN #3
\int_value:w \__int_eval:w #2 - #1 \exp_after:wN ;
\int_value:w \int_eval:n { #2 - #1 } \exp_after:wN ;
\exp_after:wN { \exp:w \@@_range_skip:w #1 ; { } #4 }
}
\cs_new:Npn \@@_range_skip:w #1 ; #2
{
\if_int_compare:w #1 > 0 \exp_stop_f:
\exp_after:wN \@@_range_skip:w
\int_value:w \__int_eval:w #1 - 1 \exp_after:wN ;
\int_value:w \int_eval:n { #1 - 1 } \exp_after:wN ;
\else:
\exp_after:wN \exp_end:
\fi:
Expand All @@ -4167,15 +4167,15 @@
{
\if_int_compare:w #1 > 1 \exp_stop_f:
\exp_after:wN \@@_range_collect_braced:w
\int_value:w \__int_eval:w #1 - 1 \exp_after:wN ;
\int_value:w \int_eval:n { #1 - 1 } \exp_after:wN ;
\fi:
{ #2 {#3} }
}
\cs_new:Npn \@@_range_collect_unbraced:w #1 ; #2#3
{
\if_int_compare:w #1 > 1 \exp_stop_f:
\exp_after:wN \@@_range_collect_unbraced:w
\int_value:w \__int_eval:w #1 - 1 \exp_after:wN ;
\int_value:w \int_eval:n { #1 - 1 } \exp_after:wN ;
\fi:
{ #2 #3 }
}
Expand Down
8 changes: 4 additions & 4 deletions l3kernel/l3file.dtx
Expand Up @@ -2115,7 +2115,7 @@
\tex_edef:D \l_@@_line_part_tl { \if_false: } \fi:
#1
\exp_after:wN \@@_wrap_line_loop:w
\int_value:w \__int_eval:w
\int_value:w \int_eval:w
}
\cs_new:Npn \@@_wrap_line_loop:w #1 ; #2#3#4#5#6#7#8#9
{
Expand All @@ -2124,7 +2124,7 @@
\fi:
#2 #3 #4 #5 #6 #7 #8 #9
\exp_after:wN \@@_wrap_line_loop:w
\int_value:w \__int_eval:w #1 - 8 ;
\int_value:w \int_eval:w #1 - 8 ;
}
\cs_new:Npn \@@_wrap_line_aux:Nw #1#2#3 \exp_after:wN #4 ;
{
Expand All @@ -2148,7 +2148,7 @@
\cs_new:Npn \@@_wrap_line_end:NnnnnnnnN #1#2#3#4#5#6#7#8#9
{
#2 #3 #4 #5 #6 #7 #8
\use_none:nnnnn \__int_eval:w 8 - ; #9
\use_none:nnnnn \int_eval:w 8 - ; #9
\token_if_eq_charcode:NNTF \c_space_token #9
{ \@@_wrap_line_end:nw { } }
{ \if_false: { \fi: } \@@_wrap_break:w #9 }
Expand All @@ -2160,7 +2160,7 @@
\@@_wrap_next_line:w
}
\cs_new:Npn \@@_wrap_end_chunk:w
#1 \__int_eval:w #2 - #3 ; #4#5 \q_stop
#1 \int_eval:w #2 - #3 ; #4#5 \q_stop
{
\if_false: { \fi: }
\exp_args:Nf \@@_wrap_next:nw { \int_eval:n { #2 - #4 } }
Expand Down
4 changes: 2 additions & 2 deletions l3kernel/l3flag.dtx
Expand Up @@ -204,7 +204,7 @@
\if_cs_exist:w flag~#2~#1 \cs_end:
\cs_set_eq:cN { flag~#2~#1 } \tex_undefined:D
\exp_after:wN \@@_clear:wn
\int_value:w \__int_eval:w 1 + #1
\int_value:w \int_eval:w 1 + #1
\else:
\use_i:nnn
\fi:
Expand Down Expand Up @@ -300,7 +300,7 @@
\cs_new:Npn \@@_height_loop:wn #1 ; #2
{
\if_cs_exist:w flag~#2~#1 \cs_end:
\exp_after:wN \@@_height_loop:wn \int_value:w \__int_eval:w 1 +
\exp_after:wN \@@_height_loop:wn \int_value:w \int_eval:w 1 +
\else:
\exp_after:wN \@@_height_end:wn
\fi:
Expand Down
49 changes: 14 additions & 35 deletions l3kernel/l3int.dtx
Expand Up @@ -92,6 +92,17 @@
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP, added = 2018-03-30]{\int_eval:w}
% \begin{syntax}
% \cs{int_eval:w} \Arg{integer expression}
% \end{syntax}
% Evaluates the \meta{integer expression} as described for
% \cs{int_eval:n}. The end of the expression is the first token
% encountered that cannot form part of such an expression. In particular,
% spaces do \emph{not} terminate the expression but \cs{scan_stop}:
% does.
% \end{function}
%
% \begin{function}[EXP, updated = 2012-09-26]{\int_abs:n}
% \begin{syntax}
% \cs{int_abs:n} \Arg{integer expression}
Expand Down Expand Up @@ -932,41 +943,6 @@
% \end{texnote}
% \end{function}
%
% \section{Internal functions}
%
% \begin{function}[EXP]{\__int_to_roman:w}
% \begin{syntax}
% \cs{__int_to_roman:w} \meta{integer}
% \cs{__int_to_roman:w} \meta{integer denotation} \meta{optional space}
% \end{syntax}
% Converts an \meta{integer} to lower case Roman representation. The
% \meta{integer} is found as in \cs{int_value:w} by expanding what
% follows exhaustively. One (optional) space is lost if the
% \meta{integer} is given by explicit digits. Note that this function
% produces a string of letters with category code~$12$. Negative
% \meta{integer} values result in no output, although the function
% does not terminate expansion until a suitable endpoint is found in
% the same way as for positive numbers.
% \begin{texnote}
% This is the \TeX{} primitive \tn{romannumeral} renamed.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\__int_eval:w, \__int_eval_end:}
% \begin{syntax}
% \cs{__int_eval:w} \meta{intexpr} \cs{__int_eval_end:}
% \end{syntax}
% Evaluates \meta{integer expression} as described for \cs{int_eval:n}.
% The evaluation stops when an unexpandable token which is not a valid
% part of an integer is read or when \cs{__int_eval_end:} is
% reached. The latter is gobbled by the scanner mechanism:
% \cs{__int_eval_end:} itself is unexpandable but used correctly
% the entire construct is expandable.
% \begin{texnote}
% This is the \eTeX{} primitive \tn{numexpr}.
% \end{texnote}
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
Expand Down Expand Up @@ -1020,6 +996,7 @@
% \subsection{Integer expressions}
%
% \begin{macro}{\int_eval:n}
% \begin{macro}{\int_eval:w}
% Wrapper for \cs{@@_eval:w}: can be used in an integer expression
% or directly in the input stream.
% When debugging, use parentheses to catch early termination.
Expand All @@ -1028,8 +1005,10 @@
{ { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_eval:n } }
\cs_new:Npn \int_eval:n #1
{ \int_value:w \@@_eval:w #1 \@@_eval_end: }
\cs_new:Npn \int_eval:w { \int_value:w \@@_eval:w }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[EXP]{\int_abs:n}
% \begin{macro}[EXP]{\@@_abs:N}
Expand Down
25 changes: 8 additions & 17 deletions l3kernel/l3str.dtx
Expand Up @@ -856,15 +856,6 @@
%<@@=str>
% \end{macrocode}
%
% \begin{macro}{\@@_int_eval:w}
% Access to primitive: there are a few uses where we cannot grab the
% expression as an argument, so need the \texttt{w} signature. Other cases
% are retained (no using \cs{int_eval:n}) as there is a performance gain.
% \begin{macrocode}
\cs_new_eq:NN \@@_int_eval:w \etex_numexpr:D
% \end{macrocode}
% \end{macro}
%
% \subsection{Creating and setting string variables}
%
% \begin{macro}
Expand Down Expand Up @@ -1470,7 +1461,7 @@
\cs_new:Npn \@@_item:nn #1#2
{
\exp_after:wN \@@_item:w
\int_value:w \@@_int_eval:w #2 \exp_after:wN ;
\int_value:w \int_eval:w #2 \exp_after:wN ;
\int_value:w \@@_count:n {#1} ;
#1 \q_stop
}
Expand All @@ -1483,7 +1474,7 @@
{
\exp_after:wN \use_i_delimit_by_q_stop:nw
\exp:w \exp_after:wN \@@_skip_exp_end:w
\int_value:w \@@_int_eval:w #1 + #2 ;
\int_value:w \int_eval:n { #1 + #2 } ;
}
}
{
Expand Down Expand Up @@ -1522,12 +1513,12 @@
\exp_after:wN \@@_skip_loop:wNNNNNNNN
\else:
\exp_after:wN \@@_skip_end:w
\int_value:w \@@_int_eval:w
\int_value:w \int_eval:w
\fi:
#1 ;
}
\cs_new:Npn \@@_skip_loop:wNNNNNNNN #1; #2#3#4#5#6#7#8#9
{ \exp_after:wN \@@_skip_exp_end:w \int_value:w \@@_int_eval:w #1 - 8 ; }
{ \exp_after:wN \@@_skip_exp_end:w \int_value:w \int_eval:n { #1 - 8 } ; }
\cs_new:Npn \@@_skip_end:w #1 ;
{
\exp_after:wN \@@_skip_end:NNNNNNNN
Expand Down Expand Up @@ -1569,8 +1560,8 @@
{
\exp_after:wN \@@_range:w
\int_value:w \@@_count:n {#1} \exp_after:wN ;
\int_value:w \@@_int_eval:w #2 - 1 \exp_after:wN ;
\int_value:w \@@_int_eval:w #3 ;
\int_value:w \int_eval:n { #2 - 1 } \exp_after:wN ;
\int_value:w \int_eval:n {#3} ;
#1 \q_stop
}
\cs_new:Npn \@@_range:w #1; #2; #3;
Expand All @@ -1582,7 +1573,7 @@
\cs_new:Npn \@@_range:nnw #1#2
{
\exp_after:wN \@@_collect_delimit_by_q_stop:w
\int_value:w \@@_int_eval:w #2 - #1 \exp_after:wN ;
\int_value:w \int_eval:n { #2 - #1 } \exp_after:wN ;
\exp:w \@@_skip_exp_end:w #1 ;
}
% \end{macrocode}
Expand Down Expand Up @@ -1648,7 +1639,7 @@
\cs_new:Npn \@@_collect_loop:wnNNNNNNN #1; #2 #3#4#5#6#7#8#9
{
\exp_after:wN \@@_collect_loop:wn
\int_value:w \@@_int_eval:w #1 - 7 ;
\int_value:w \int_eval:n { #1 - 7 } ;
{ #2 #3#4#5#6#7#8#9 }
}
\cs_new:Npn \@@_collect_end:wn #1 ;
Expand Down

0 comments on commit 3e73c2f

Please sign in to comment.