summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expl3/l3int.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3int.dtx')
-rw-r--r--Master/texmf-dist/source/latex/expl3/l3int.dtx101
1 files changed, 56 insertions, 45 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3int.dtx b/Master/texmf-dist/source/latex/expl3/l3int.dtx
index 8b61ae04eab..df635a93fe3 100644
--- a/Master/texmf-dist/source/latex/expl3/l3int.dtx
+++ b/Master/texmf-dist/source/latex/expl3/l3int.dtx
@@ -36,7 +36,7 @@
\RequirePackage{l3names}
%</driver|package>
%\fi
-\GetIdInfo$Id: l3int.dtx 1621 2009-10-25 06:36:19Z will $
+\GetIdInfo$Id: l3int.dtx 1867 2010-03-23 13:03:12Z will $
{L3 Experimental Integer module}
%\iffalse
%<*driver>
@@ -74,21 +74,18 @@
%
% \section{Functions}
%
-% \begin{function}{%
-% \int_new:N |
-% \int_new:c |
-%^^A \int_new_l:N |
-% }
+% \begin{function}{ \int_new:N |
+% \int_new:c |
+% \int_new_local:N |
+% \int_new_local:c }
% \begin{syntax}
% "\int_new:N" <int>
% \end{syntax}
-% Globally defines <int> to be a new variable of type "int" although
-% you can still choose if it should be a an "\l_" or "\g_" type.
-% There is no way to define constant counters with these functions.
-%^^A The function "\int_new_l:N" defines <int> locally only.
+% Defines <int> to be a new variable of type "int".
+% With the |local| variant, the variable is only available within the
+% current group level (or below).
% \begin{texnote}
% "\int_new:N" is the equivalent to plain \TeX{}'s \tn{newcount}.
-% However, the internal register allocation is done differently.
% \end{texnote}
% \end{function}
%
@@ -341,6 +338,10 @@
% <int> register.
% \end{variable}
%
+% \begin{variable}{\c_max_register_int}
+% Maximum number of registers.
+% \end{variable}
+%
%
% \begin{variable}{%
% \l_tmpa_int |
@@ -456,32 +457,35 @@
% \subsection{Allocation and setting}
%
% \begin{macro}{\int_new:N,\int_new:c}
-%^^A \begin{macro}{\int_new_l:N}
-% Allocation of a new internal counter is already done above. Here we define
-% the next likely variant.
-%
+% \begin{macro}{\int_new_local:N,\int_new_local:c}
% For the \LaTeX3 format:
% \begin{macrocode}
%<*initex>
-\alloc_setup_type:nnn {int} {11} \c_max_register_num
-\cs_new_nopar:Npn \int_new:N #1 {\alloc_reg:NnNN g {int} \tex_countdef:D#1}
-\cs_new_nopar:Npn \int_new_l:N #1 {\alloc_reg:NnNN l {int} \tex_countdef:D#1}
+\alloc_new:nnnN {int} {11} {\c_max_register_int} \tex_countdef:D
%</initex>
% \end{macrocode}
% For `l3in2e':
% \begin{macrocode}
%<*package>
-\cs_new_nopar:Npn \int_new:N #1 {
+\cs_new_protected_nopar:Npn \int_new:N #1 {
\chk_if_free_cs:N #1
\newcount #1
}
+\cs_new_protected_nopar:Npn \int_new_local:N #1 {
+ \chk_if_free_cs:N #1
+ \int_compare:nNnTF
+ \tex_currentgrouplevel:D = 0
+ \newcount \loccount
+ #1
+}
%</package>
% \end{macrocode}
% \begin{macrocode}
\cs_generate_variant:Nn \int_new:N {c}
+\cs_generate_variant:Nn \int_new_local:N {c}
% \end{macrocode}
% \end{macro}
-%^^A \end{macro}
+% \end{macro}
%
%
% \begin{macro}{\int_set:Nn}
@@ -491,12 +495,12 @@
% Setting counters is again something that I would like to make
% uniform at the moment to get a better overview.
% \begin{macrocode}
-\cs_new_nopar:Npn \int_set:Nn #1#2{#1 \intexpr_eval:w #2\intexpr_eval_end:
+\cs_new_protected_nopar:Npn \int_set:Nn #1#2{#1 \intexpr_eval:w #2\intexpr_eval_end:
%<*check>
\chk_local_or_pref_global:N #1
%</check>
}
-\cs_new_nopar:Npn \int_gset:Nn {
+\cs_new_protected_nopar:Npn \int_gset:Nn {
%<*check>
\pref_global_chk:
%</check>
@@ -521,17 +525,17 @@
% Incrementing and decrementing of integer registers is done with
% the following functions.
% \begin{macrocode}
-\cs_new_nopar:Npn \int_incr:N #1{\int_advance:w#1\c_one
+\cs_new_protected_nopar:Npn \int_incr:N #1{\int_advance:w#1\c_one
%<*check>
\chk_local_or_pref_global:N #1
%</check>
}
-\cs_new_nopar:Npn \int_decr:N #1{\int_advance:w#1\c_minus_one
+\cs_new_protected_nopar:Npn \int_decr:N #1{\int_advance:w#1\c_minus_one
%<*check>
\chk_local_or_pref_global:N #1
%</check>
}
-\cs_new_nopar:Npn \int_gincr:N {
+\cs_new_protected_nopar:Npn \int_gincr:N {
% \end{macrocode}
% We make sure that a local variable is not updated globally by
% changing the internal test (i.e.\ |\chk_local_or_pref_global:N|) before
@@ -546,7 +550,7 @@
%</check>
%<-check> \pref_global:D
\int_incr:N}
-\cs_new_nopar:Npn \int_gdecr:N {
+\cs_new_protected_nopar:Npn \int_gdecr:N {
%<*check>
\pref_global_chk:
%</check>
@@ -556,10 +560,10 @@
% With the |\int_add:Nn| functions we can shorten the above code.
% If this makes it too slow \ldots
% \begin{macrocode}
-\cs_set_nopar:Npn \int_incr:N #1{\int_add:Nn#1\c_one}
-\cs_set_nopar:Npn \int_decr:N #1{\int_add:Nn#1\c_minus_one}
-\cs_set_nopar:Npn \int_gincr:N #1{\int_gadd:Nn#1\c_one}
-\cs_set_nopar:Npn \int_gdecr:N #1{\int_gadd:Nn#1\c_minus_one}
+\cs_set_protected_nopar:Npn \int_incr:N #1{\int_add:Nn#1\c_one}
+\cs_set_protected_nopar:Npn \int_decr:N #1{\int_add:Nn#1\c_minus_one}
+\cs_set_protected_nopar:Npn \int_gincr:N #1{\int_gadd:Nn#1\c_one}
+\cs_set_protected_nopar:Npn \int_gdecr:N #1{\int_gadd:Nn#1\c_minus_one}
% \end{macrocode}
%
% \begin{macrocode}
@@ -584,12 +588,12 @@
% \begin{macro}{\int_gzero:c}
% Functions that reset an \m{int} register to zero.
% \begin{macrocode}
-\cs_new_nopar:Npn \int_zero:N #1 {#1=\c_zero}
+\cs_new_protected_nopar:Npn \int_zero:N #1 {#1=\c_zero}
\cs_generate_variant:Nn \int_zero:N {c}
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new_nopar:Npn \int_gzero:N #1 {\pref_global:D #1=\c_zero}
+\cs_new_protected_nopar:Npn \int_gzero:N #1 {\pref_global:D #1=\c_zero}
\cs_generate_variant:Nn \int_gzero:N {c}
% \end{macrocode}
% \end{macro}
@@ -608,7 +612,7 @@
% Adding and substracting to and from a counter \ldots
% We should think of using these functions
% \begin{macrocode}
-\cs_new_nopar:Npn \int_add:Nn #1#2{
+\cs_new_protected_nopar:Npn \int_add:Nn #1#2{
% \end{macrocode}
% We need to say |by| in case the first argument is a register
% accessed by its number, e.g., |\count23|. Not that it should
@@ -625,13 +629,13 @@
\chk_local_or_pref_global:N #1
%</check>
}
-\cs_new_nopar:Npn \int_gadd:Nn {
+\cs_new_protected_nopar:Npn \int_gadd:Nn {
%<*check>
\pref_global_chk:
%</check>
%<-check> \pref_global:D
\int_add:Nn }
-\cs_new_nopar:Npn \int_gsub:Nn {
+\cs_new_protected_nopar:Npn \int_gsub:Nn {
%<*check>
\pref_global_chk:
%</check>
@@ -692,7 +696,7 @@
% character \TeX{} produces to the character we actually want which
% will give us letters with category code~11.%
% \begin{macrocode}
-\cs_new_nopar:Npn \int_roman_lcuc_mapping:Nnn #1#2#3{
+\cs_new_protected_nopar:Npn \int_roman_lcuc_mapping:Nnn #1#2#3{
\cs_set_nopar:cpn {int_to_lc_roman_#1:}{#2}
\cs_set_nopar:cpn {int_to_uc_roman_#1:}{#3}
}
@@ -927,16 +931,23 @@
% As stated, most constants can be defined as |\tex_chardef:D| or
% |\tex_mathchardef:D| but that's engine dependent.
% \begin{macrocode}
-\cs_new_nopar:Npn \int_const:Nn #1#2 {
- \intexpr_compare:nNnTF {#2} > \c_minus_one {
- \intexpr_compare:nNnTF {#2} > \c_max_register_num {
- \int_new:N #1 \int_set:Nn #1{#2}
- } {
- \chk_if_free_cs:N #1 \tex_mathchardef:D #1 = \intexpr_eval:n{#2}
+\cs_new_protected_nopar:Npn \int_const:Nn #1#2 {
+ \intexpr_compare:nTF { #2 > \c_minus_one }
+ {
+ \intexpr_compare:nTF { #2 > \c_max_register_int }
+ {
+ \int_new:N #1
+ \int_gset:Nn #1 {#2}
+ }
+ {
+ \chk_if_free_cs:N #1
+ \tex_global:D \tex_mathchardef:D #1 = \intexpr_eval:n {#2}
+ }
+ }
+ {
+ \int_new:N #1
+ \int_gset:Nn #1 {#2}
}
- } {
- \int_new:N #1 \int_set:Nn #1{#2}
- }
}
% \end{macrocode}
% \end{macro}