[latex3-commits] [git/LaTeX3-latex3-latex3] master: Implement \intarray_const_from_clist:Nn (1ab3402)
Bruno Le Floch
bruno at le-floch.fr
Sat May 5 00:38:41 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/1ab34027134845caf54e1df356985f721fda1461
>---------------------------------------------------------------
commit 1ab34027134845caf54e1df356985f721fda1461
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Sat May 5 00:38:41 2018 +0200
Implement \intarray_const_from_clist:Nn
>---------------------------------------------------------------
1ab34027134845caf54e1df356985f721fda1461
l3kernel/l3candidates.dtx | 42 +++++++++++++++++++++++++--
l3kernel/testfiles/m3expl001.luatex.tlg | 2 ++
l3kernel/testfiles/m3expl001.ptex.tlg | 2 ++
l3kernel/testfiles/m3expl001.tlg | 2 ++
l3kernel/testfiles/m3expl001.uptex.tlg | 2 ++
l3kernel/testfiles/m3expl001.xetex.tlg | 2 ++
l3kernel/testfiles/m3expl003.luatex.tlg | 2 ++
l3kernel/testfiles/m3expl003.ptex.tlg | 2 ++
l3kernel/testfiles/m3expl003.tlg | 2 ++
l3kernel/testfiles/m3expl003.uptex.tlg | 2 ++
l3kernel/testfiles/m3expl003.xetex.tlg | 2 ++
l3kernel/testfiles/m3intarray001.luatex.tlg | 38 ++++++++++++++++++++++++
l3kernel/testfiles/m3intarray001.lvt | 7 +++++
l3kernel/testfiles/m3intarray001.tlg | 38 ++++++++++++++++++++++++
14 files changed, 143 insertions(+), 2 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 6ba99ac..7a8b59a 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -375,7 +375,17 @@
%
% \subsection{Working with contents of integer arrays}
%
-% \begin{function}[added = 2018-05-03, rEXP]{\intarray_to_clist:N}
+% \begin{function}[added = 2018-05-04, rEXP]{\intarray_const_from_clist:Nn}
+% \begin{syntax}
+% \cs{intarray_const_from_clist:Nn} \meta{intarray~var} \meta{intexpr clist}
+% \end{syntax}
+% Creates a new constant \meta{integer array variable} or raises an
+% error if the name is already taken. The \meta{integer array
+% variable} is set (globally) to contain as its items the results of
+% evaluating each \meta{integer expression} in the \meta{comma list}.
+% \end{function}
+%
+% \begin{function}[added = 2018-05-04, rEXP]{\intarray_to_clist:N}
% \begin{syntax}
% \cs{intarray_to_clist:N} \meta{intarray~var}
% \end{syntax}
@@ -385,7 +395,7 @@
% result has one fewer comma than the number of items.
% \end{function}
%
-% \begin{function}[added = 2018-05-03]{\intarray_show:N, \intarray_log:N}
+% \begin{function}[added = 2018-05-04]{\intarray_show:N, \intarray_log:N}
% \begin{syntax}
% \cs{intarray_show:N} \meta{intarray~var}
% \cs{intarray_log:N} \meta{intarray~var}
@@ -2150,6 +2160,34 @@
%
% \subsubsection{Working with contents of integer arrays}
%
+% \begin{macro}{\intarray_const_from_clist:Nn, \@@_const_from_clist:nN}
+% Similar to \cs{intarray_new:Nn} (which we don't use because when
+% debugging is enabled that function checks the variable name starts
+% with |g_|). We make use of the fact that \TeX{} allows allocation
+% of successive \tn{fontdimen} as long as no other font has been
+% declared: no need to count the comma list items first. We need the
+% code in \cs{intarray_gset:Nnn} that checks the item value is not too
+% big, namely \cs{@@_gset_overflow_test:nw}, but not the code that
+% checks bounds. At the end, set the size of the intarray.
+% \begin{macrocode}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_scope:NN c #1 } { }
+\cs_new_protected:Npn \intarray_const_from_clist:Nn #1#2
+ {
+ \@@_new:N #1
+ \int_zero:N \l_@@_loop_int
+ \clist_map_inline:nn {#2}
+ { \exp_args:Nf \@@_const_from_clist:nN { \int_eval:n {##1} } #1 }
+ \@@_count:w #1 \l_@@_loop_int
+ }
+\cs_new_protected:Npn \@@_const_from_clist:nN #1#2
+ {
+ \int_incr:N \l_@@_loop_int
+ \@@_gset_overflow_test:nw {#1}
+ \__kernel_intarray_gset:Nnn #2 \l_@@_loop_int {#1}
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}[rEXP]{\intarray_to_clist:N, \@@_to_clist:Nn, \@@_to_clist:w}
% Loop through the array, putting a comma before each item. Remove
% the leading comma with |f|-expansion. We also use the auxiliary in
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index e0fa715..efd1568 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5672,6 +5672,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 5aaf5ce..f587a7d 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5665,6 +5665,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 71d1410..d81e114 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5665,6 +5665,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index ea0e5c5..46cff82 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5663,6 +5663,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 7462007..a9bdcc2 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5646,6 +5646,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index e0fa715..efd1568 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5672,6 +5672,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 5aaf5ce..f587a7d 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5665,6 +5665,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 71d1410..d81e114 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5665,6 +5665,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index ea0e5c5..46cff82 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5663,6 +5663,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 7462007..a9bdcc2 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5646,6 +5646,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \intarray_const_from_clist:Nn on line ...
+Defining \__intarray_const_from_clist:nN on line ...
Defining \intarray_to_clist:N on line ...
Defining \__intarray_to_clist:Nn on line ...
Defining \__intarray_to_clist:w on line ...
diff --git a/l3kernel/testfiles/m3intarray001.luatex.tlg b/l3kernel/testfiles/m3intarray001.luatex.tlg
index 31c24ca..3ef7517 100644
--- a/l3kernel/testfiles/m3intarray001.luatex.tlg
+++ b/l3kernel/testfiles/m3intarray001.luatex.tlg
@@ -173,3 +173,41 @@ The integer array \g_testd_intarray contains 10 items:
l. ... }
0
============================================================
+============================================================
+TEST 6: Const
+============================================================
+Defining \c_teste_intarray on line ...
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/overflow"
+!
+! Integers larger than 2^{30}-1 cannot be stored in arrays.
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| An attempt was made to store -1073741824 at position \l__intarray_loop_int
+| in the array '\c_teste_intarray'. The largest allowed value -1073741823 will
+| be used instead.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/overflow"
+!
+! Integers larger than 2^{30}-1 cannot be stored in arrays.
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| An attempt was made to store 1073741824 at position \l__intarray_loop_int
+| in the array '\c_teste_intarray'. The largest allowed value 1073741823 will
+| be used instead.
+|...............................................
+7,43,-1073741823,1073741823
+============================================================
diff --git a/l3kernel/testfiles/m3intarray001.lvt b/l3kernel/testfiles/m3intarray001.lvt
index da1b797..41512b0 100644
--- a/l3kernel/testfiles/m3intarray001.lvt
+++ b/l3kernel/testfiles/m3intarray001.lvt
@@ -88,4 +88,11 @@
\TYPE { \intarray_item:Nn \g_testd_intarray { 3 } }
}
+\TEST { Const }
+ {
+ \intarray_const_from_clist:Nn \c_teste_intarray
+ { 3 + 4 , ~ { -1+`, } , , - \c_max_int / 2 , \c_max_int / 2 }
+ \TYPE { \intarray_to_clist:N \c_teste_intarray }
+ }
+
\END
diff --git a/l3kernel/testfiles/m3intarray001.tlg b/l3kernel/testfiles/m3intarray001.tlg
index 6861196..8ba2104 100644
--- a/l3kernel/testfiles/m3intarray001.tlg
+++ b/l3kernel/testfiles/m3intarray001.tlg
@@ -183,3 +183,41 @@ The integer array \g_testd_intarray contains 10 items:
l. ... }
0
============================================================
+============================================================
+TEST 6: Const
+============================================================
+Defining \c_teste_intarray on line ...
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/overflow"
+!
+! Integers larger than 2^{30}-1 cannot be stored in arrays.
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| An attempt was made to store -1073741824 at position \l__intarray_loop_int
+| in the array '\c_teste_intarray'. The largest allowed value -1073741823 will
+| be used instead.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/overflow"
+!
+! Integers larger than 2^{30}-1 cannot be stored in arrays.
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| An attempt was made to store 1073741824 at position \l__intarray_loop_int
+| in the array '\c_teste_intarray'. The largest allowed value 1073741823 will
+| be used instead.
+|...............................................
+7,43,-1073741823,1073741823
+============================================================
More information about the latex3-commits
mailing list