-- file: TangleOutput.mesa
-- Pascal-to-Mesa translator output, translated at September 14, 1985 3:58:20 pm PDT


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  TanglePrivate,
  TangleProcArray;

TangleOutput: PROGRAM IMPORTS PascalWizardFiles, TanglePrivate, TangleProcArray EXPORTS TanglePrivate = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, TanglePrivate, TangleProcArray;
--74:----PROCEDURE PRINT←REPL(P:TEXT←POINTER);VAR K:0..MAX←TOKS;
-- A:SIXTEEN←BITS;ZP:0..2;
-- BEGIN IF P>=TEXT←PTR THEN WRITE(TERM←OUT,'BAD')ELSE BEGIN K:=TOK←START[P
-- ];ZP:=P MOD 3;WHILE K<TOK←START[P+3]DO BEGIN A:=TOK←MEM[ZP,K];
-- IF A>=128 THEN[75:]BEGIN K:=K+1;
-- IF A<168 THEN BEGIN A:=(A-128)*256+TOK←MEM[ZP,K];PRINT←ID(A);
-- IF BYTE←MEM[A MOD 2,BYTE←START[A]]=34 THEN WRITE(TERM←OUT,'"')ELSE WRITE
-- (TERM←OUT,' ');END ELSE IF A<208 THEN BEGIN WRITE(TERM←OUT,'@<');
-- PRINT←ID((A-168)*256+TOK←MEM[ZP,K]);WRITE(TERM←OUT,'@>');
-- END ELSE BEGIN A:=(A-208)*256+TOK←MEM[ZP,K];
-- WRITE(TERM←OUT,'@',XCHR[123],A:1,'@',XCHR[125]);END;
-- END[:75]ELSE[76:]CASE A OF 9:WRITE(TERM←OUT,'@',XCHR[123]);
-- 10:WRITE(TERM←OUT,'@',XCHR[125]);12:WRITE(TERM←OUT,'@''');
-- 13:WRITE(TERM←OUT,'@"');125:WRITE(TERM←OUT,'@$');0:WRITE(TERM←OUT,'#');
-- 64:WRITE(TERM←OUT,'@@');2:WRITE(TERM←OUT,'@=');3:WRITE(TERM←OUT,'@\');
-- OTHERS:WRITE(TERM←OUT,XCHR[A])END[:76];K:=K+1;END;END;END;----:74----84:
 PushLevel: PROCEDURE[P: NamePointer]
 = 
BEGIN IF StackPtr=StackSize  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "stack"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END  ELSE BEGIN Stack↑[StackPtr]←CurState;
StackPtr←StackPtr+1;CurState.NameField←P;
CurState.ReplField←Equiv↑[P];Zo← CurState.ReplField MOD 3;
CurState.ByteField←TokStart↑[CurState.ReplField];
CurState.EndField←TokStart↑[CurState.ReplField+3];
CurState.ModField←0; END; END;--:84----85:-- PopLevel: PROCEDURE = 
BEGIN 
 {IF TextLink↑[CurState.ReplField]=0  THEN BEGIN IF Ilk↑[CurState.
NameField]=3  THEN--91:--BEGIN NamePtr←NamePtr-1;TextPtr←TextPtr-1;
Z← TextPtr MOD 3;
--IF TOK←PTR[Z]>MAX←TOK←PTR[Z]THEN MAX←TOK←PTR[Z]:=TOK←PTR[Z];
TokPtr↑[Z]←TokStart↑[TextPtr];
--BYTE←PTR[NAME←PTR MOD 2]:=BYTE←PTR[NAME←PTR MOD 2]-1;-- END--:91--;
 END  ELSE IF  INT[TextLink↑[CurState.ReplField]]<MaxTexts  THEN BEGIN
CurState.ReplField←TextLink↑[CurState.ReplField];
Zo← CurState.ReplField MOD 3;
CurState.ByteField←TokStart↑[CurState.ReplField];
CurState.EndField←TokStart↑[CurState.ReplField+3]; GOTO Label10; END;
StackPtr←StackPtr-1;
IF  INT[StackPtr]>0  THEN BEGIN CurState←Stack↑[StackPtr];
Zo← CurState.ReplField MOD 3; END;EXITS Label10 => NULL}; END;--:85----87:
 GetOutput: PROCEDURE RETURNS[GetOutputResult: SixteenBits] = 
BEGIN  A:SixteenBits;
B:EightBits;Bal:SixteenBits;K:PascalInteger[0..MaxBytes];W:PascalInteger[0..1];
 DO {--Label20:--{IF StackPtr=0  THEN BEGIN A←0; GOTO Label31; END;
IF CurState.ByteField=CurState.EndField  THEN BEGIN CurVal←
-CurState.ModField;PopLevel[];IF CurVal=0  THEN  GOTO Label20;A←129; GOTO Label31;
 END;A←TokMem[Zo, CurState.ByteField]↑;
CurState.ByteField← INT[CurState.ByteField]+1;
IF  INT[A]<128  THEN IF A=0  THEN--92:--BEGIN PushLevel[NamePtr-1]; GOTO Label20;
 END--:92-- ELSE  GOTO Label31;A←( INT[A]-128)*256+TokMem[Zo, CurState.ByteField]↑;
CurState.ByteField← INT[CurState.ByteField]+1;IF  INT[A]<10240  THEN--89:
BEGIN SELECT Ilk↑[A]FROM 0 =>BEGIN CurVal←A;A←130; END;
1 =>BEGIN CurVal← INT[Equiv↑[A]]-32768;A←128; END;2 =>BEGIN PushLevel[A];
 GOTO Label20; END;3 =>BEGIN--90:
 WHILE(CurState.ByteField=CurState.EndField)AND ( INT[StackPtr]>0)DO
PopLevel[] ENDLOOP ;
IF(StackPtr=0)OR (TokMem[Zo, CurState.ByteField]↑#40) THEN BEGIN BEGIN
PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "! No parameter given for "]; END;
PrintId[A];Error[]; GOTO Label20; END;--93:--Bal←1;
CurState.ByteField← INT[CurState.ByteField]+1;
{WHILE TRUE DO BEGIN B←TokMem[Zo, CurState.ByteField]↑;
CurState.ByteField← INT[CurState.ByteField]+1;
IF B=0  THEN StoreTwoBytes[NamePtr+32767] ELSE BEGIN IF  INT[B]>=128  THEN
BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←B;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;B←TokMem[Zo, CurState.ByteField]↑;
CurState.ByteField← INT[CurState.ByteField]+1;
 END  ELSE SELECT B FROM 40 =>Bal← INT[Bal]+1;41 =>BEGIN Bal← INT[Bal]-1;
IF Bal=0  THEN  GOTO Label30; END;
39 =>DO BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←B;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;B←TokMem[Zo, CurState.ByteField]↑;
CurState.ByteField← INT[CurState.ByteField]+1; IF B=39 THEN EXIT; ENDLOOP; ENDCASE => NULL;
BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←B;
TokPtr↑[Z]←TokPtr↑[Z]+1; END; END; END ENDLOOP ;EXITS Label30 => NULL};--:93--Equiv↑[NamePtr]←TextPtr;
Ilk↑[NamePtr]←2;W← NamePtr MOD 2;K←BytePtr↑[W];
--IF K=MAX←BYTES THEN BEGIN WRITELN(TERM←OUT);
-- WRITE(TERM←OUT,'! Sorry, ','byte memory',' capacity exceeded');ERROR;
-- HISTORY:=3;JUMP←OUT;END;BYTE←MEM[W,K]:=35;K:=K+1;BYTE←PTR[W]:=K;
IF  INT[NamePtr]>MaxNames-2  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "name"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;ByteStart↑[NamePtr+2]←K;NamePtr←NamePtr+1;
IF  INT[TextPtr]>MaxTexts-3  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "text"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TextLink↑[TextPtr]←0;
TokStart↑[TextPtr+3]←TokPtr↑[Z];TextPtr←TextPtr+1;
Z← TextPtr MOD 3--:90--;PushLevel[A]; GOTO Label20; END;
 ENDCASE =>BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! This can't happen ("]; PascalWriteLongString[file: @TermOut, item: "output"]; PascalWriteLongString[file: @TermOut, item: ")"]};Error[];History←3;
JumpOut[]; END ; GOTO Label31; END--:89--;IF  INT[A]<20480  THEN--88:--BEGIN A← INT[A]-10240;
IF Equiv↑[A]#0  THEN PushLevel[A] ELSE IF A#0  THEN BEGIN BEGIN 
PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "! Not present: <"]; END;PrintId[A];
PascalWriteLongString[file: @TermOut, item: ">"];Error[]; END; GOTO Label20; END--:88--;CurVal← INT[A]-20480;A←129;
CurState.ModField←CurVal;EXITS Label31 => NULL};--IF TROUBLE←SHOOTING THEN DEBUG←HELP;
GetOutputResult←A;EXIT; EXITS Label20 => NULL} ENDLOOP; END;--:87----97:--
END.