alloc.tex (6238B)
1 % Resources are allocated as follows. All ranges are inclusive. 2 % By "temporary", we mean the register may be clobbered by any macro. In some 3 % cases, not being able to use temporary registers with certain macros is very 4 % restrictive, so these macros are documented as not using temporary registers. 5 % Also, macros likely to be assigned to active characters should not use 6 % temporary registers, because then checking for conflicts is difficult. 7 % count: 8 % 0--9: page identification 9 % 10--29: internal to allocator 10 % 30--100: temporary 11 % 101--254: allocated inserts 12 % 255: temporary 13 % 256--65535: allocated 14 % dimen, skip: 15 % 0--100: temporary 16 % 101--254: allocated inserts 17 % 255: temporary 18 % 256--65535: allocated 19 % muskip, toks, attr: 20 % 0--255: temporary 21 % 256--65535: allocated 22 % box: 23 % 0--9: temporary 24 % 10--29: internal to allocator 25 % 30--100: temporary 26 % 101--254: allocated inserts 27 % 255: \outputbox 28 % 256--65535: allocated 29 % read, write: 30 % 0--15: allocated 31 % fam: 32 % 0 body 33 % 1 variables 34 % 2 symbols 35 % 3 extension 36 % 4--255: allocated 37 % cctab: 38 % 0: default 39 % 1--255: temporary 40 % 256--32767: allocated 41 % TODO: marks? How do eTeX marks classes work? 42 43 \protected\def\newif#1{% 44 \gcsdef{\ea\@remif\csstring#1true}{\let#1=\iftrue}% 45 \gcsdef{\ea\@remif\csstring#1false}{\let#1=\iffalse}% 46 \glet#1=\iffalse 47 } 48 {\uccode`1=`i \uccode`2=`f \uppercase{\gdef\@remif12{}}} 49 50 \newif\if@galloc 51 \countdef\@allocnum=10 \@allocnum=-1 52 53 \chardef\@countlist=11 \setbox\@countlist=\hbox{} 54 \chardef\@dimenlist=12 \setbox\@dimenlist=\hbox{} 55 \chardef\@skiplist=13 \setbox\@skiplist=\hbox{} 56 \chardef\@muskiplist=14 \setbox\@muskiplist=\hbox{} 57 \chardef\@boxlist=15 \setbox\@boxlist=\hbox{} 58 \chardef\@tokslist=16 \setbox\@tokslist=\hbox{} 59 \chardef\@readlist=17 \setbox\@readlist=\hbox{} 60 \chardef\@writelist=18 \setbox\@writelist=\hbox{} 61 \chardef\@famlist=19 \setbox\@famlist=\hbox{} 62 \chardef\@attrlist=20 \setbox\@attrlist=\hbox{} 63 \chardef\@cctablist=21 \setbox\@cctablist=\hbox{} 64 \chardef\@insertlist=22 \setbox\@insertlist=\hbox{} 65 66 \countdef\@countnext=11 \@countnext=256 \chardef\@countmax=65535 67 \countdef\@dimennext=12 \@dimennext=256 \chardef\@dimenmax=65535 68 \countdef\@skipnext=13 \@skipnext=256 \chardef\@skipmax=65535 69 \countdef\@muskipnext=14 \@muskipnext=256 \chardef\@muskipmax=65535 70 \countdef\@boxnext=15 \@boxnext=256 \chardef\@boxmax=65535 71 \countdef\@toksnext=16 \@toksnext=256 \chardef\@toksmax=65535 72 \countdef\@readnext=17 \@readnext=0 \chardef\@readmax=15 73 \countdef\@writenext=18 \@writenext=0 \chardef\@writemax=15 74 \countdef\@famnext=19 \@famnext=4 \chardef\@fammax=255 75 \countdef\@attrnext=20 \@attrnext=256 \chardef\@attrmax=65535 76 \countdef\@cctabnext=21 \@cctabnext=256 \chardef\@cctabmax=32767 77 \countdef\@insertnext=22 \@insertnext=254 \chardef\@insertmin=101 78 79 \def\@allocate#1#2#3#4#5#6#7#8{% 80 \gsetbox#3=\hbox{\unhbox#3\global\@allocnum=\lastpenalty \unpenalty}% 81 \ifnum\@allocnum=0 82 \ifnum#5#6#7% 83 \errmessage{No room for a new \string#1}% 84 \else 85 \global\@allocnum=#5% 86 \global#4#5% 87 \fi 88 \fi 89 \if@galloc\global\fi#2#8=\@allocnum 90 \@gallocfalse 91 \wlog{\string#8=\string#1\the\@allocnum}% 92 } 93 94 \protected\def\newcount{\@allocate\count\countdef\@countlist\incr\@countnext>\@countmax} 95 \protected\def\newdimen{\@allocate\dimen\dimendef\@dimenlist\incr\@dimennext>\@dimenmax} 96 \protected\def\newskip{\@allocate\skip\skipdef\@skiplist\incr\@skipnext>\@skipmax} 97 \protected\def\newmuskip{\@allocate\muskip\muskipdef\@muskiplist\incr\@muskipnext>\@muskipmax} 98 \protected\def\newbox{\@allocate\box\chardef\@boxlist\incr\@boxnext>\@boxmax} 99 \protected\def\newtoks{\@allocate\toks\toksdef\@tokslist\incr\@toksnext>\@toksmax} 100 \protected\def\newread{\@allocate\read\chardef\@readlist\incr\@readnext>\@readmax} 101 \protected\def\newwrite{\@allocate\write\chardef\@writelist\incr\@writenext>\@writemax} 102 \protected\def\newfam{\@allocate\fam\chardef\@famlist\incr\@famnext>\@fammax} 103 \protected\def\newattr{\@allocate\attr\attrdef\@attrlist\incr\@attrnext>\@attrmax} 104 \protected\def\newcctab{\@allocate\cctab\chardef\@cctablist\incr\@cctabnext>\@cctabmax} 105 \protected\def\newinsert{\@allocate\insert\chardef\@insertlist\decr\@insertnext<\@insertmin} 106 107 \protected\def\gnewcount{\@galloctrue \newcount} 108 \protected\def\gnewdimen{\@galloctrue \newdimen} 109 \protected\def\gnewskip{\@galloctrue \newskip} 110 \protected\def\gnewmuskip{\@galloctrue \newmuskip} 111 \protected\def\gnewbox{\@galloctrue \newbox} 112 \protected\def\gnewtoks{\@galloctrue \newtoks} 113 \protected\def\gnewread{\@galloctrue \newread} 114 \protected\def\gnewwrite{\@galloctrue \newwrite} 115 \protected\def\gnewfam{\@galloctrue \newfam} 116 \protected\def\gnewattr{\@galloctrue \newattr} 117 \protected\def\gnewcctab{\@galloctrue \newcctab} 118 \protected\def\gnewinsert{\@galloctrue \newinsert} 119 120 \def\@free#1#2#3{% 121 \gsetbox#1=\hbox{\unhbox#1\penalty#2#3}% 122 } 123 124 \protected\def\freecount{\@free\@countlist\regnum} 125 \protected\def\freedimen{\@free\@dimenlist\regnum} 126 \protected\def\freeskip{\@free\@skiplist\regnum} 127 \protected\def\freemuskip{\@free\@muskiplist\regnum} 128 \protected\def\freebox{\@free\@boxlist{}} 129 \protected\def\freetoks{\@free\@tokslist\regnum} 130 \protected\def\freeread{\@free\@readlist{}} 131 \protected\def\freewrite{\@free\@writelist{}} 132 \protected\def\freefam{\@free\@famlist{}} 133 \protected\def\freeattr{\@free\@attrlist\regnum} 134 \protected\def\freecctab{\@free\@cctablist{}} 135 \protected\def\freeinsert{\@free\@insertlist{}} 136 137 % Temporaries of various types: 138 % TODO: distinguish between local and global temporaries? 139 \countdef\countA=30 \countdef\countB=31 \countdef\countC=32 140 \dimendef\dimenA=30 \dimendef\dimenB=31 \dimendef\dimenC=32 141 \skipdef\skipA=30 \skipdef\skipB=31 \skipdef\skipC=32 142 \muskipdef\muskipA=30 \muskipdef\muskipB=31 \muskipdef\muskipC=32 143 \chardef\boxA=30 \chardef\boxB=31 \chardef\boxC=32 144 \toksdef\toksA=30 \toksdef\toksB=31 \toksdef\toksC=32 145 % temporary control sequences: csA csB csC ... 146 147 \endinput