-- file: TexMemoryImpl.mesa
-- Pascal-to-Mesa translator output, translated at September 27, 1985 10:21:37 am PDT


DIRECTORY
  PascalBasic,
  TexTypes,
  TexInteraction,
  TexMemory,
  TexSymbols,
  TexParagraph,
  TexSysdepInline;

TexMemoryImpl: PROGRAM IMPORTS PascalBasic, TexTypes, TexInteraction, TexSymbols, TexParagraph, TexSysdepInline EXPORTS TexMemory = PUBLIC
BEGIN OPEN PascalBasic, TexTypes, TexInteraction, TexMemory, TexSymbols, TexParagraph, TexSysdepInline;


LoMemMax: Halfword;

HiMemMin: Halfword;
--:116----117:

VarUsed: PascalInteger;

DynUsed: PascalInteger;
--:117----118:--
Avail: Halfword;

MemEnd: Halfword;

--:118----124:--
Rover: Halfword;
 GetAvail: PROCEDURE RETURNS[GetAvailResult: Halfword] = 
BEGIN P:Halfword; P←Avail;
IF P#0  THEN Avail←Mem[Avail]↑.Hh.Rh  ELSE IF  INT[MemEnd]<MemMax  THEN BEGIN
MemEnd←MemEnd+1;P←MemEnd; END  ELSE BEGIN HiMemMin← INT[HiMemMin]-1;
P←HiMemMin;IF  INT[HiMemMin]<=LoMemMax  THEN BEGIN Runaway[];
Overflow[172,MemMax+1-MemMin]; END; END;Mem[P]↑.Hh.Rh←0;
DynUsed←DynUsed+1;GetAvailResult←P; END;--:120----123:
 FlushList: PROCEDURE[P: Halfword] = 
BEGIN Q:Halfword;
 WHILE P#0 DO BEGIN Q←Mem[P]↑.Hh.Rh;BEGIN Mem[P]↑.Hh.Rh←Avail;
Avail←P;DynUsed←DynUsed-1; END;P←Q; END ENDLOOP ; END;--:123----125:
 GetNode: PROCEDURE[S: PascalInteger] RETURNS[GetNodeResult: Halfword] = 
BEGIN  P:Halfword;
Q:Halfword;R:PascalInteger;T:Halfword; DO {--Label20:--P←Rover;{{DO--127:
Q← INT[P]+Mem[P]↑.Hh.Lh;WHILE(Mem[Q]↑.Hh.Rh=65515)DO BEGIN T←Mem[Q+1]↑.Hh.Rh;
IF Q=Rover  THEN Rover←T;Mem[T+1]↑.Hh.Lh←Mem[Q+1]↑.Hh.Lh;
Mem[Mem[Q+1]↑.Hh.Lh+1]↑.Hh.Rh←T;Q← INT[Q]+Mem[Q]↑.Hh.Lh; END ENDLOOP ;R←Q-S;
IF R>P+1  THEN--128:--BEGIN Mem[P]↑.Hh.Lh←R-P;Rover←P; GOTO Label40; END--:128--;
IF R=P  THEN IF((Mem[P+1]↑.Hh.Rh#Rover)OR (Mem[P+1]↑.Hh.Lh#Rover)) THEN--129
-- :--BEGIN Rover←Mem[P+1]↑.Hh.Rh;T←Mem[P+1]↑.Hh.Lh;Mem[Rover+1]↑.Hh.Lh←T;
Mem[T+1]↑.Hh.Rh←Rover; GOTO Label40; END--:129--;Mem[P]↑.Hh.Lh← INT[Q]-P--:127--;
P←Mem[P+1]↑.Hh.Rh; IF P=Rover THEN EXIT; ENDLOOP;
IF S=1073741824  THEN BEGIN GetNodeResult←65515; GOTO Label10; END;
IF  INT[LoMemMax+2]<HiMemMin  THEN--126:
BEGIN IF  INT[LoMemMax]+1000<HiMemMin  THEN T← INT[LoMemMax]+1000  ELSE T← PascalDIVPower2[(
 INT[LoMemMax]+HiMemMin+2),1];P←Mem[Rover+1]↑.Hh.Lh;Q←LoMemMax;
Mem[P+1]↑.Hh.Rh←Q;Mem[Rover+1]↑.Hh.Lh←Q;Mem[Q+1]↑.Hh.Rh←Rover;
Mem[Q+1]↑.Hh.Lh←P;Mem[Q]↑.Hh.Rh←65515;Mem[Q]↑.Hh.Lh← INT[T]-LoMemMax;
LoMemMax←T;Mem[LoMemMax]↑.Hh.Rh←0;Mem[LoMemMax]↑.Hh.Lh←0;
Rover←Q; GOTO Label20; END--:126--;Overflow[172,MemMax+1-MemMin];
EXITS Label40 => NULL};Mem[R]↑.Hh.Rh←0;VarUsed←VarUsed+S;GetNodeResult←R;EXITS Label10 => NULL};EXIT; EXITS Label20 => NULL} ENDLOOP; END;--:125----130:
 FreeNode: PROCEDURE[P: Halfword,S: Halfword] = 
BEGIN Q:Halfword;
 Mem[P]↑.Hh.Lh←S;Mem[P]↑.Hh.Rh←65515;Q←Mem[Rover+1]↑.Hh.Lh;
Mem[P+1]↑.Hh.Lh←Q;Mem[P+1]↑.Hh.Rh←Rover;Mem[Rover+1]↑.Hh.Lh←P;
Mem[Q+1]↑.Hh.Rh←P;VarUsed←VarUsed-S; END;--:130----131:
 SortAvail: PROCEDURE = 
BEGIN P, Q, R:Halfword;OldRover:Halfword;
 P←GetNode[1073741824];P←Mem[Rover+1]↑.Hh.Rh;
Mem[Rover+1]↑.Hh.Rh←65515;OldRover←Rover;WHILE P#OldRover DO--132:
IF  INT[P]<Rover  THEN BEGIN Q←P;P←Mem[Q+1]↑.Hh.Rh;Mem[Q+1]↑.Hh.Rh←Rover;
Rover←Q; END  ELSE BEGIN Q←Rover;
WHILE  INT[Mem[Q+1]↑.Hh.Rh]<P DO Q←Mem[Q+1]↑.Hh.Rh ENDLOOP ;R←Mem[P+1]↑.Hh.Rh;
Mem[P+1]↑.Hh.Rh←Mem[Q+1]↑.Hh.Rh;Mem[Q+1]↑.Hh.Rh←P;P←R; END--:132-- ENDLOOP ;
P←Rover;
WHILE Mem[P+1]↑.Hh.Rh#65515 DO BEGIN Mem[Mem[P+1]↑.Hh.Rh+1]↑.Hh.Lh←P;
P←Mem[P+1]↑.Hh.Rh; END ENDLOOP ;Mem[P+1]↑.Hh.Rh←Rover;Mem[Rover+1]↑.Hh.Lh←P; END;
--:131----136:-- NewNullBox: PROCEDURE RETURNS[NewNullBoxResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[7];Mem[P]↑.Hh.B0←0;Mem[P]↑.Hh.B1←0;Mem[P+1]↑.Int←0;
Mem[P+2]↑.Int←0;Mem[P+3]↑.Int←0;Mem[P+4]↑.Int←0;Mem[P+5]↑.Hh.Rh←0;
Mem[P+5]↑.Hh.B0←0;Mem[P+5]↑.Hh.B1←0;Mem[P+6]↑.Gr←0.0;NewNullBoxResult←P;
 END;--:136----139:-- NewRule: PROCEDURE RETURNS[NewRuleResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[4];Mem[P]↑.Hh.B0←2;Mem[P]↑.Hh.B1←0;
Mem[P+1]↑.Int←-1073741824;Mem[P+2]↑.Int←-1073741824;
Mem[P+3]↑.Int←-1073741824;NewRuleResult←P; END;--:139----144:
 NewLigature: PROCEDURE[F,C: Quarterword,Q: Halfword] RETURNS[NewLigatureResult: Halfword]
 = 
BEGIN P:Halfword; P←GetNode[2];Mem[P]↑.Hh.B0←6;Mem[P]↑.Hh.B1←0;
Mem[P+1]↑.Hh.B0←F;Mem[P+1]↑.Hh.B1←C;Mem[P+1]↑.Hh.Rh←Q;NewLigatureResult←P;
 END;--:144----145:-- NewDisc: PROCEDURE RETURNS[NewDiscResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[2];Mem[P]↑.Hh.B0←7;Mem[P]↑.Hh.B1←0;Mem[P+1]↑.Hh.Lh←0;
Mem[P+1]↑.Hh.Rh←0;NewDiscResult←P; END;--:145----147:
 NewMath: PROCEDURE[W: Scaled,S: SmallNumber] RETURNS[NewMathResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[2];Mem[P]↑.Hh.B0←9;Mem[P]↑.Hh.B1←S;Mem[P+1]↑.Int←W;
NewMathResult←P; END;--:147----151:-- NewSpec: PROCEDURE[P: Halfword] RETURNS[NewSpecResult: Halfword]
 = 
BEGIN Q:Halfword; Q←GetNode[4];Mem[Q]↑←Mem[P]↑;Mem[Q]↑.Hh.Rh←0;
Mem[Q+1]↑.Int←Mem[P+1]↑.Int;Mem[Q+2]↑.Int←Mem[P+2]↑.Int;
Mem[Q+3]↑.Int←Mem[P+3]↑.Int;NewSpecResult←Q; END;--:151----152:
 NewParamGlue: PROCEDURE[N: SmallNumber] RETURNS[NewParamGlueResult: Halfword] = 
BEGIN P:Halfword;
Q:Halfword; P←GetNode[2];Mem[P]↑.Hh.B0←10;Mem[P]↑.Hh.B1←N+1;
Mem[P+1]↑.Hh.Rh←0;Q←--224:--Eqtb↑[3026+N].Hh.Rh--:224--;Mem[P+1]↑.Hh.Lh←Q;
Mem[Q]↑.Hh.Rh←Mem[Q]↑.Hh.Rh+1;NewParamGlueResult←P; END;--:152----153:
 NewGlue: PROCEDURE[Q: Halfword] RETURNS[NewGlueResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[2];Mem[P]↑.Hh.B0←10;Mem[P]↑.Hh.B1←0;Mem[P+1]↑.Hh.Rh←0;
Mem[P+1]↑.Hh.Lh←Q;Mem[Q]↑.Hh.Rh←Mem[Q]↑.Hh.Rh+1;NewGlueResult←P; END;--:153
--154:-- NewSkipParam: PROCEDURE[N: SmallNumber] RETURNS[NewSkipParamResult: Halfword] = 
BEGIN P:Halfword;
 TempPtr←NewSpec[--224:--Eqtb↑[3026+N].Hh.Rh--:224--];
P←NewGlue[TempPtr];Mem[TempPtr]↑.Hh.Rh←0;Mem[P]↑.Hh.B1←N+1;
NewSkipParamResult←P; END;--:154----156:-- NewKern: PROCEDURE[W: Scaled] RETURNS[NewKernResult: Halfword]
 = 
BEGIN P:Halfword; P←GetNode[2];Mem[P]↑.Hh.B0←11;Mem[P]↑.Hh.B1←0;
Mem[P+1]↑.Int←W;NewKernResult←P; END;--:156----158:
 NewPenalty: PROCEDURE[M: PascalInteger] RETURNS[NewPenaltyResult: Halfword] = 
BEGIN P:Halfword;
 P←GetNode[2];Mem[P]↑.Hh.B0←12;Mem[P]↑.Hh.B1←0;Mem[P+1]↑.Int←M;
NewPenaltyResult←P; END;--:158----167:-- CheckMem: PROCEDURE[PrintLocs: PascalBoolean]
 = 
BEGIN  P, Q:Halfword;Clobbered:PascalBoolean;
 --169:-- --170:-- FOR i:INT    IN [ INT[MemMin ].. INT[LoMemMax ]] DO  P ← i; Free↑[P]←FALSE ENDLOOP;
FOR i:INT    IN [ INT[HiMemMin ].. INT[MemEnd ]] DO  P ← i; Free↑[P]←FALSE ENDLOOP;--168:--P←Avail;Q←0;
Clobbered←FALSE;
{WHILE P#0 DO BEGIN IF( INT[P]>MemEnd)OR ( INT[P]<HiMemMin) THEN Clobbered←TRUE
 ELSE IF Free↑[P] THEN Clobbered←TRUE;
IF Clobbered  THEN BEGIN PrintNl[173];PrintInt[Q]; GOTO Label31; END;
Free↑[P]←TRUE;Q←P;P←Mem[Q]↑.Hh.Rh; END ENDLOOP ;EXITS Label31 => NULL};--:168--P←Rover;Q←0;
Clobbered←FALSE;
{DO IF( INT[P]>=LoMemMax)OR ( INT[P]<MemMin) THEN Clobbered←TRUE  ELSE IF( INT[Mem[P
+1]↑.Hh.Rh]>=LoMemMax)OR ( INT[Mem[P+1]↑.Hh.Rh]<MemMin) THEN Clobbered←TRUE
 ELSE IF NOT ((Mem[P]↑.Hh.Rh=65515))OR ( INT[Mem[P]↑.Hh.Lh]<2)OR (
 INT[P]+Mem[P]↑.Hh.Lh>LoMemMax)OR (Mem[Mem[P+1]↑.Hh.Rh+1]↑.Hh.Lh#P) THEN Clobbered←TRUE;
IF Clobbered  THEN BEGIN PrintNl[174];PrintInt[Q]; GOTO Label32; END;
FOR i:INT    IN [ INT[P ].. INT[ INT[P]+Mem[P]↑.Hh.Lh-1 ]] DO  Q ← i;  IF Free↑[Q] THEN BEGIN PrintNl[175]
;PrintInt[Q]; GOTO Label32; END;Free↑[Q]←TRUE; ENDLOOP;Q←P;P←Mem[P+1]↑.Hh.Rh;
 IF P=Rover THEN EXIT; ENDLOOP;EXITS Label32 => NULL};--:169--P←MemMin;
WHILE  INT[P]<=LoMemMax DO BEGIN IF(Mem[P]↑.Hh.Rh=65515) THEN BEGIN PrintNl[
176];PrintInt[P]; END;WHILE  ( INT[P]<=LoMemMax)AND NOT Free↑[P]DO P←P+1 ENDLOOP ;
WHILE ( INT[P]<=LoMemMax)AND Free↑[P]DO P←P+1 ENDLOOP ; END--:170-- ENDLOOP ;
IF PrintLocs  THEN--171:--BEGIN PrintNl[177];
FOR i:INT    IN [ INT[MemMin ].. INT[LoMemMax ]] DO  P ← i; IF  NOT Free↑[P]AND (
( INT[P]>WasLoMax)OR WasFree↑[P]) THEN BEGIN PrintChar[32];PrintInt[P]; END ENDLOOP;
FOR i:INT    IN [ INT[HiMemMin ].. INT[MemEnd ]] DO  P ← i; IF  NOT Free↑[P]AND ( ( INT[P]<WasHiMin)OR (
 INT[P]>WasMemEnd)OR WasFree↑[P]) THEN BEGIN PrintChar[32];PrintInt[P]; END ENDLOOP;
 END--:171--;FOR i:INT    IN [ INT[MemMin ].. INT[LoMemMax ]] DO  P ← i; WasFree↑[P]←Free↑[P] ENDLOOP;
FOR i:INT    IN [ INT[HiMemMin ].. INT[MemEnd ]] DO  P ← i; WasFree↑[P]←Free↑[P] ENDLOOP;
WasMemEnd←MemEnd;WasLoMax←LoMemMax;WasHiMin←HiMemMin; END;
--:167----172:-- SearchMem: PROCEDURE[P: Halfword] = 
BEGIN Q:PascalInteger;
 FOR i:INT    IN [ INT[MemMin ].. INT[LoMemMax ]] DO  Q ← i;  IF Mem[Q]↑.Hh.Rh=P  THEN BEGIN
PrintNl[178];PrintInt[Q];PrintChar[41]; END;
IF Mem[Q]↑.Hh.Lh=P  THEN BEGIN PrintNl[179];PrintInt[Q];PrintChar[41];
 END; ENDLOOP;
FOR i:INT    IN [ INT[HiMemMin ].. INT[MemEnd ]] DO  Q ← i;  IF Mem[Q]↑.Hh.Rh=P  THEN BEGIN
PrintNl[178];PrintInt[Q];PrintChar[41]; END;
IF Mem[Q]↑.Hh.Lh=P  THEN BEGIN PrintNl[179];PrintInt[Q];PrintChar[41];
 END; ENDLOOP;--255:
FOR i:INT    IN [ INT[1 ].. INT[4077 ]] DO  Q ← i;  IF Eqtb↑[Q].Hh.Rh=P  THEN BEGIN PrintNl[363];
PrintInt[Q];PrintChar[41]; END;--:255-- ENDLOOP;--285:
IF  INT[SavePtr]>0  THEN FOR i:INT    IN [ INT[0 ].. INT[SavePtr-1 ]] DO  Q ← i;  IF SaveStack↑[Q].Hh.
Rh=P  THEN BEGIN PrintNl[407];PrintInt[Q];PrintChar[41]; END;--:285-- ENDLOOP;
--933:
FOR i:INT    IN [ INT[0 ].. INT[307 ]] DO  Q ← i;  IF HyphList↑[Q]=P  THEN BEGIN PrintNl[797];
PrintInt[Q];PrintChar[41]; END;--:933-- ENDLOOP; END;--:172----174:

END.