diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3alloc.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/expl3/l3alloc.dtx | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3alloc.dtx b/Master/texmf-dist/source/latex/expl3/l3alloc.dtx index a2031c45493..5c5d82b13ad 100644 --- a/Master/texmf-dist/source/latex/expl3/l3alloc.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3alloc.dtx @@ -32,11 +32,11 @@ %% %% ----------------------------------------------------------------------- % -%<*driver|package> +%<*driver> \RequirePackage{l3names} -%</driver|package> +%</driver> %\fi -\GetIdInfo$Id: l3alloc.dtx 1362 2009-05-28 20:19:21Z joseph $ +\GetIdInfo$Id: l3alloc.dtx 1867 2010-03-23 13:03:12Z will $ {L3 Experimental register allocation}% %\iffalse %<*driver> @@ -64,6 +64,10 @@ % % \section{Allocating registers and the like} % +% Note that this module is only used for generating an pkg{expl3}-based +% format. Under \LaTeXe, the |etex.sty| package is used for allocation +% management. +% % This module provides the basic mechanism for allocating \TeX's % registers. While designing this we have to take into account the % following characteristics: @@ -92,6 +96,21 @@ % % \section{Functions} % +% +% \begin{function}{\alloc_new:nnnN} +% \begin{syntax} +% "\alloc_new:nnnN" \Arg{type} \Arg{min} \Arg{max} <alloc_cmd> +% \end{syntax} +% Shorthand for allocating new registers. Defines \cs{<type>_new:N} and +% \cs{<type>_new_local:N} allocators of the specified <type>, indexed up from +% <min> for global registers and down from <max> for local registers, with +% registers assigned using the function <alloc_cmd>. +% +% Internally uses "\alloc_setup_type:nnn" and "\alloc_reg:NnNN" +% defined below in case you want finer-grained control. +% \end{function} +% +% % \begin{function}{\alloc_setup_type:nnn} % \begin{syntax} % "\alloc_setup_type:nnn" \Arg{type} \Arg{g_start_num} \Arg{l_start_num} @@ -126,10 +145,9 @@ % % \subsection{Internal functions} % -% \begin{function}{ \alloc_next_g:n | -% \alloc_next_l:n } +% \begin{function}{ \alloc_next:Nn } % \begin{syntax} -% "\alloc_next_g:n" \Arg{type} +% "\alloc_next:Nn" "l"/"g" \Arg{type} % \end{syntax} % These functions find the next free register for the specified type. % \end{function} @@ -137,12 +155,7 @@ % \subsection{Module code} % % \begin{macrocode} -%<*package> -\ProvidesExplPackage - {\filename}{\filedate}{\fileversion}{\filedescription} -\package_check_loaded_expl: -%</package> -%<*initex|package> +%<*initex> % \end{macrocode} % % \begin{macro}{\alloc_setup_type:nnn} @@ -150,114 +163,101 @@ % last allocated global or local register. We also need a sequence % to store the `exceptions'. % \begin{macrocode} -\cs_new_nopar:Npn \alloc_setup_type:nnn #1 #2 #3{ - \num_new:c {g_ #1 _allocation_num} - \num_new:c {l_ #1 _allocation_num} - \seq_new:c {g_ #1 _allocation_seq} - \num_set:cn {g_ #1 _allocation_num}{#2} - \num_set:cn {l_ #1 _allocation_num}{#3} +\cs_new_nopar:Npn \alloc_setup_type:nnn #1#2#3 { + \seq_new:c {g_#1_allocation_seq} + \tl_new:cn {g_#1_allocation_tl } {#2} + \tl_new:cn {l_#1_allocation_tl } {#3} } % \end{macrocode} % \end{macro} % -% \begin{macro}{\alloc_next_g:n} -% \begin{macro}{\alloc_next_l:n} -% These routines find the next free register. For globally allocated -% registers we first increment the counter that keeps track of them. -% \begin{macrocode} -\cs_new_nopar:Npn \alloc_next_g:n #1 { - \num_gincr:c {g_ #1 _allocation_num} -% \end{macrocode} -% Then we need to check whether we have run out of registers. +% \begin{macro}{\alloc_next:Nn} +% This routine finds the next free register. For globally allocated +% registers we first increment the counter that keeps track of them; +% for local registers, decrement. % \begin{macrocode} - \intexpr_compare:nTF { - \num_use:c{g_ #1 _allocation_num} = \num_use:c{l_ #1 _allocation_num} - } - {\iow_term:x{We~ ran~ out~ of~ registers~ of~ type~ g_#1!}} - { -% \end{macrocode} -% We also need to check whether the value of the counter already -% occurs in the list of already allocated registers. -% \begin{macrocode} - \seq_if_in:cxT {g_ #1 _allocation_seq} - {\num_use:c{g_ #1 _allocation_num}} -% \end{macrocode} -% If it does, we find the next value. -% \begin{macrocode} - { \iow_term:x{\num_use:c{g_ #1 _allocation_num}~already~allocated!} - \alloc_next_g:n {#1} } +\cs_new_nopar:Npn \alloc_next:Nn #1#2 { + \tl_set:cx {#1_#2_allocation_tl} + { + \intexpr_eval:n + { + \tl_use:c {#1_#2_allocation_tl} + \if:w #1 g + \else: - \fi: 1 + } } % \end{macrocode} -% By now the |.._allocation_num| counter will contain the number of -% the register we will assign a control seuence for. +% Then we need to check whether we have run out of registers. % \begin{macrocode} - } + \intexpr_compare:nNnTF + { \tl_use:c{g_#2_allocation_tl} } = { \tl_use:c{l_#2_allocation_tl} } + { + \iow_term:x { + We~ ran~ out~ of~ + \if:w #1 g \scan_stop: global~ \else: local~ \fi: + 'l#2!'~ registers! + } + } % \end{macrocode} -% For the locally allocated registers we have a similar function. +% We also need to check whether the value of the counter already +% occurs in the list of already allocated registers. % \begin{macrocode} -\cs_new_nopar:Npn \alloc_next_l:n #1 { - \num_gdecr:c {l_ #1 _allocation_num} + { + \seq_if_in:cxTF {g_#2_allocation_seq} {\tl_use:c{#1_#2_allocation_tl}} + { + \iow_log:x{ \tl_use:c{#1_#2_allocation_tl}~already~allocated. } + \alloc_next:Nn #1 {#2} + } % \end{macrocode} -% (Will: should that be "\num_decr" (no "g") ?!) +% By now the |.._allocation_tl| counter will contain the number of +% the register we will assign a control sequence for. % \begin{macrocode} - \intexpr_compare:nTF { - \num_use:c{g_ #1 _allocation_num} = \num_use:c{l_ #1 _allocation_num} - } - {\iow_term:x{We~ ran~ out~ of~ registers~ of~ type~ l_#1!}} - { - \seq_if_in:cxTF {g_ #1 _allocation_seq} - {\num_use:c{l_ #1 _allocation_num}} - { \iow_term:x{\num_use:c{l_ #1 _allocation_num}~already~allocated!} - \alloc_next_l:n {#1} } - { \iow_term:x{\num_use:c{l_ #1 _allocation_num}~free!} } + { \iow_log:x{\tl_use:c{#1_#2_allocation_tl}~free.} } } - } +} % \end{macrocode} % \end{macro} -% \end{macro} % % \begin{macro}{\alloc_reg:NnNN} -% This internal macro performs the actual allocation. Its first -% argument is either 'g' for a globally allocated register or `l' -% for a locally allocated register. The second argument is the -% type of register to allocate, the third argument is the command -% to use and the fourth argument is the control sequence that is to -% be defined to point to the register. -% \begin{macrocode} -\cs_new_nopar:Npn \alloc_reg:NnNN #1 #2 #3 #4{ -% \end{macrocode} -% It first checks that the control sequence that is to denote the -% register does not already exist. +% This internal macro performs the actual allocation. Its first +% argument is either `|g|' for a globally allocated register or `|l|' +% for a locally allocated register. The second argument is the +% type of register to allocate, the third argument is the command +% to use and the fourth argument is the control sequence that is to +% be defined to point to the register. % \begin{macrocode} +\cs_new_nopar:Npn \alloc_reg:NnNN #1#2#3#4 { \chk_if_free_cs:N #4 -% \end{macrocode} -% Next, it decides whether a prefix is needed for the allocation -% command; -% \begin{macrocode} \if:w #1 g \exp_after:wN \pref_global:D \fi: -% \end{macrocode} -% And finally the actual allocation takes place. -% \begin{macrocode} - #3 #4 \num_use:c{#1_ #2 _allocation_num} + #3 #4 \tl_use:c{#1_ #2 _allocation_tl} %%\cs_record_meaning:N#1 -% \end{macrocode} -% All that's left to do is write a message in the log file. -% \begin{macrocode} \iow_log:x{ - \token_to_str:N#4=#2~register~\num_use:c{#1_ #2 _allocation_num}} -% \end{macrocode} -% Finally, it calls |\alloc_next_|\meta{\texttt{\textup g}/\texttt{\textup l}} to find the next free register -% number. -% \begin{macrocode} - \use:c{alloc_next_#1:n} {#2} + \token_to_str:N#4~=~#2~register~\tl_use:c{#1_#2_allocation_tl} + } + \alloc_next:Nn #1 {#2} } % \end{macrocode} % \end{macro} % +% +% \begin{macro}{\alloc_new:nnnN} +% Shorthand for defining new register types and their allocators: +% \begin{macrocode} +\cs_new:Npn \alloc_new:nnnN #1#2#3#4 { + \alloc_setup_type:nnn {#1} {#2} {#3} + \cs_new_nopar:cpn {#1_new:N} ##1 { + \alloc_reg:NnNN g {#1} #4 ##1 + } + \cs_new_nopar:cpn {#1_new_local:N} ##1 { + \alloc_reg:NnNN l {#1} #4 ##1 + } +} +% \end{macrocode} +% \end{macro} +% % \begin{macrocode} -%</initex|package> +%</initex> % \end{macrocode} % % \begin{macrocode} |