   (*****************************************************************************)
   (*                                                                           *)
   (*                          File: GLOBAL.TEXT                                *)
   (*                                                                           *)
   (*              (C) Copyright 1981 Silicon Valley Software, Inc.             *)
   (*                            1983, 1984 Apple Computer, Inc.                *)
   (*                                                                           *)
   (*                            All rights reserved.                22-Jun-82  *)
   (*                                                                           *)
   (*  5-06-83: pac81 expanded to pac150 for longer listing file lines          *)
   (*  5-11-83: forwcount                                                       *)
   (*  5-27-83: OverflowFlag                                                    *)
   (*  6-16-83: heap                                                            *)
   (*  6-22-83: interptr reinstated                                             *)
   (*  6-23-83: iniu                                                            *)
   (*  6-24-83: copyrights procedure                                            *)
   (*  8-28-83: cheapwarning procedure                                          *)
   (*  9-01-83: objptr renamed to nilclassptr                                   *)
   (* 10-25-83: RodFlag, ForwChkFlag                                            *)
   (* 12-20-83: UnitsToInit, HasClasses, ClassesToInit                          *)
   (* 12-27-84: CrProc, ClassLevel, NeedesInit, and MethodLevel fields          *)
   (* 12-27-83: KlassPtr, CkObCpPtr, CkObCnPtr                                  *)
   (* 01-01-84: NUMRW changed to remove CREATION as a reserved word             *)
   (* 01-03-84: LastMethod replaced with LastEvenMethod and LastOddMethod       *)
   (* 01-09-84: CurrClass                                                       *)
   (* 01-21-84: AllBegSys, DecBgegSys, IdDecBegSys                              *)
   (* 01-31-84: Stuff added for new optimization                                *)
   (* 02-06-84: Declarations for INLINE procedure attribute                     *)
   (* 03-29-84: Declarations for C procedure attribute                          *)
   (* 04-14-84: UNIVflag added to N to allow UNIV proc params                   *)
   (*****************************************************************************)
    {[j=15-/40/80!,i=1,o=95]}

  LABEL 999;

  CONST
    TITLE          = 'Lisa Pascal Compiler ';

    {$ifc foros}
    VERSION        = 'V1.164 (20-Apr-84)';
    {$elsec}
    VERSION        = 'V0.10.2 (Monitor)          ';
    DATE           = '11-Jan-84';
    {$endc}


    D0             = 0;                {register equates}
    D1             = 1;
    D2             = 2;
    D3             = 3;
    D4             = 4;
    D5             = 5;
    D6             = 6;
    D7             = 7;

    A0             = 8;
    A1             = 9;
    A2             = 10;
    A3             = 11;
    A4             = 12;
    A5             = 13;
    A6             = 14;
    SP             = 15;

    D1st           = D4;               {first D register available for OPT}
    Dnth           = D7;               {last D register available for OPT}
    A1st           = A3;               {first A register available for OPT}
    Anth           = A4;               {last A register available for OPT}

    Byte           = 1;                {size codes expected by code generator}
    WORD           = 2;
    LONG           = 3;

    SLinkOffset    = 8;                {static link offset}
    MAXREFS        = 100;              {count of refs for opt.}

    {$ifc not IULIB}
    ALFALEN        = 8;                {max identifer length}
    {$endc}

    BuffBlockSize  = 16;               {i-code buffer block size}
    BuffByteSize   = BuffBlockSize * 512; {i-code buffer byte size}

    InbufBLockSize = 8;                {input buffer block size}
    InbufByteSize  = InbufBLockSize * 512; {input buffer byte size}

    MaxErrs        = 10;               {max nbr of errors reported per line}

    MAXDISPLAY     = 16;               {max display nesting depth}
    MAXLEVEL       = 8;                {max proc nesting level}
    MAXUNITS       = 256;              {max nbr of used units in USES}
    NUMRW          = 44;               {number of reserved words}                                       {!01-01-84}
    MAXFILES       = 5;                {max nesting of input files}
    MaxCondDepth   = 20;               {max $ifc nesting depth}

    MAXLNUM        = 65100;            {max listing line, make higher than Gen}

  TYPE                                                                         {!} {[f-]}
    Symbol = (IDENTSY,   ICONSTSY,  RCONSTSY,  DOSY,      OFSY,
              TOSY,      FORSY,     ASSIGNSY,  NILSY,     IFSY,
              THENSY,    ELSESY,    DOWNTOSY,  BEGINSY,   ENDSY,
              WITHSY,    GOTOSY,    CONSTSY,   VARSY,     TYPESY,
              ARRAYSY,   RECORDSY,  SETSY,     FILESY,    FUNCTSY,
              PROCSY,    LABELSY,   PACKEDSY,  PROGRAMSY, STRINGSY,
              CASESY,    WHILESY,   UNTILSY,   REPEATSY,  CCONSTSY,
              SCONSTSY,  LPARENSY,  RPARENSY,  LBRACKSY,  RBRACKSY,
              PERIODSY,  COMMASY,   SEMISY,    COLONSY,   UPARROWSY,
              OTHERSY,

              {UCSD Symbols}
              UNITSY,    USESSY,    INTERSY,   IMPLESY,   INTRINSY,

              {Classcal symbols}                                               {!C}
              SUBCLSY,   METHSY,                                               {!C 01-01-84}

              {Unary Operators}
              ATSIGNSY,  NOTSY,

              {Multops}
              STARSY,    SLASHSY,   DIVSY,     MODSY,     ANDSY,

              {Addops}
              PLUSSY,    MINUSSY,   ORSY,

              {Relops}
              LTSY,      GTSY,      LESY,      GESY,      EQSY,
              NESY,      INSY,

              {Error and End-of-File symbols}
              ERRSY,     EOFSY,

              {Character classes without corresponding symbols.
               Note that the ordering of LETCL..DIGITCL should
               not be altered and that these character classes
               must appear at the end of symbol.}
              DOLLARSY,  LBRACECL,  BLANKCL,   LETCL,     DIGITCL);            {!} {[f+]}

    SetOfSys       = SET OF Symbol;

    pT             = ^T;               {ptrs to T (type) symbol table entries}
    pN             = ^N;               {ptrs to N (name) symbol table entries}

    TypeForms      = (SCALAR, SUBRANGE, CLASSES, POINTERS, SETS, ARRAYS, RECORDS, FILES,
                      TAGFIELD, VARIANT, STRINGS, SCONST, PROCVALUES); {keep order} {!C}

    DeclKind       = (STANDARD, DECLARED);

    pIntList       = ^IntList;         {ptrs to integer lists, e.g., case tags}
    IntList        = RECORD
                       IntVal: Integer;
                       NextInt: pIntList;
                     END;

    T              = PACKED RECORD     {symbol table type info}
                       Bytes: Integer;
                       Bits: 0..7;
                       Marked: Boolean;                                        {!DBG!}
                       FType: Boolean;
                       CASE Form: TypeForms OF
                         SCALAR:
                           (CASE ScalKind: DeclKind OF
                              DECLARED:
                                (MaxConst: pN)); {Reversed list}
                         SUBRANGE:
                           (RangeOf: pT;
                            Min, Max: LongInt);
                         POINTERS:
                           (PointerTo: pT);
                         SETS:
                           (SetOf: pT);
                         ARRAYS:
                           (ArrayOf, IndexedBy: pT;
                            PckdArr: Boolean;
                            BitPacked: Boolean;
                            BitsPerEl: 1..8);
                         RECORDS:
                           (PckdRec: Boolean;
                            Fields: pN;
                            FstField: pN;
                            VarPart: pT);
                         TAGFIELD:
                           (TagName: pN;
                            Variants: pT);
                         VARIANT:
                           (VarFldLst: pN;
                            NextVar, SubVar: pT;
                            VarValus: pIntList);
                         FILES:
                           (PckdFile: Boolean;
                            FileOf: pT);
                         STRINGS, SCONST:
                           (StringLen: 0..255);
                         CLASSES:
                           (WasDeclared, NeedsInit: Boolean;
                            SuperClass: pT;
                            TotalOrder: pT;
                            ClassLevel: Integer;                               {!12-27-83}
                            SizeInstance: Integer;
                            LastOddMethod, LastEvenMethod: Integer;            {!01-03-84}
                            MethodOff, MethodLev: Integer;
                            ItsId: pN;
                            ClFields, ClFstField, ClFstMethod, CrProc: pN);    {!12-27-83}
                     END;

    NodeKind       = (IDENTNODE, UNNODE, BINNODE, TRINODE, CSTNODE, REGISTER,
                      ASGNNODE, CSE);

    GenRegister    = D0..SP;

    NameClass      = (CONSTS, TYPES, VARS, FIELD, PROC, FUNC, UNITS);
    NClassSet      = SET OF NameClass;

    AccessKind     = (DRCT, INDRCT);

    PFkind         = (DECL, EXTDECL, FORWDECL, FORMAL, METHDECL, FORWMETHDECL, {!C}
                      INLINEDECL, CDECL);                                      {!03-29-84}

    UnitKind       = (REGUNIT, INTRUNIT, SHARUNIT); {keep order}

    {$ifc not IULIB}
    Alfa           = PACKED ARRAY [1..ALFALEN] OF Char;
    {$endc}

    pLabRec        = ^LabRec;          {ptrs to labels}
    LabRec         = RECORD            {label info}
                       NextLabel: pLabRec;
                       LabelNo: Integer; {User label no.}
                       ILabelNo: Integer; {Internal label no.}
                       GlobRefNo: Integer; {-1 = No Global Refs}
                       Defined: Boolean;
                     END;

    InlinePtr      = ^InlineCode;      {pointers to INLINE code}               {!02-06-84}
    InlineCode     = RECORD            {one word of inline code}               {!02-06-84}
                       InlineWord: Integer;
                       NextInlineWord: InlinePtr;
                     END;

    StrValType     = ^StrValRec;       {ptrs to string constant "chunks"}
    StrValRec      = RECORD            {one "chunk" of a string}
                       StrPart: Alfa;
                       Next: StrValType;
                     END;

    SetValType     = ^SetValRec;       {ptrs to a "chunk" of a set}
    SetValRec      = RECORD            {one chunk of a set}
                       NextSet: SetValType;
                       SetVal: SET OF 0..31;
                     END;

    Valu           = RECORD            {constant values}
                       CASE Integer OF
                         1:
                           (Ivalu: LongInt);
                         2:
                           (Rvalu: Real);
                         3:
                           (Svalu: StrValType;
                            SvaluLen: Integer);
                         4:
                           (SetValu: SetValType;
                            MaxSetEl: Integer);
                     END;

    LevRange       = - MAXUNITS..MAXLEVEL;

    PBoolean       = ^Boolean;

    N              = RECORD            {symbol table identifer info}
                       CASE Node: NodeKind OF
                         IDENTNODE:
                           (Name: Alfa;
                            Llink, Rlink, Next: pN;
                            IdType: pT;
                            CASE Class: NameClass OF
                              CONSTS:
                                (ValueOf: Valu);
                              VARS:
                                (Vkind: AccessKind;
                                 IsSELF: Boolean; {true iff is "SELF"}         {!C}
                                 UNIVflag: Boolean; {true if UNIV param}       {!04/14/84}
                                 InRegister: Integer;
                                 {-2  iff must be in memory:
                                         1) @ taken
                                         2) passed as var parameter
                                         3) inter. glob. reference,
                                  -1  could go in register
                                  >=0 var in reg. InRegister}
                                 Vlev: LevRange;
                                 Voff: Integer);
                              FIELD:
                                (FOff: Integer;
                                 PckdField: Boolean;
                                 BitOff: 0..15);
                              PROC, FUNC:
                                (CASE PFdeclKind: DeclKind OF
                                   STANDARD:
                                     (Key: 1..999);
                                   DECLARED:
                                     (PFlev: LevRange;
                                      PFargList: pN;
                                      CASE PFdecl: PFkind OF
                                        DECL, EXTDECL, FORWDECL, INLINEDECL,   {!02-06-84}
                                        CDECL,                                 {!03-29-84}
                                        METHDECL, FORWMETHDECL:                {!C}
                                          (MethodLevel, MethodNo: Integer;     {!C 12-27-83}
                                           ParmBytes, Lc, RtnNo: Integer;
                                           InlineCode: InlinePtr);             {!02-06-84}
                                        FORMAL:
                                          (PFOff: Integer)));
                              UNITS:
                                (Ulev: LevRange;
                                 ULc: Integer;
                                 Utop: PBoolean;                               {!DBG!}
                                 Ukind: UnitKind;
                                 HasClasses: Boolean));                        {!12-20-83}
                         REGISTER:
                           (Reg: GenRegister; {Register number}
                            Load: 0..2; {0=>last use CSE;1=>cont'd or 1st&last use;2=>1st use CSE}
                            LoadSize: Integer;
                                      {size of thing to load into reg.
                                        0 -> nothing to load}
                            LoadExpr: pN); {if nil, just Reg Reference}
                         CSE:                                                  {!01-31-84}
                           (CSEpN: pN;
                            CSEIndex: Integer);
                         UNNODE:
                           (UnOp: 0..255;
                            UnSubOp: Integer;
                            UnArg: pN);
                         BINNODE:
                           (BinOp: 0..255;
                            BinSubOp: Integer;
                            RightArg: pN;
                            CASE Integer OF
                              0:
                                (LeftArg: pN);
                              1:
                                (LeftPt: pT));
                         TRINODE:
                           (TriOp: 0..255;
                            Tri1, OrigTri1, Tri2: pN;
                            TriSuper: pT;
                            CASE Integer OF
                              0:
                                (TripN: pN);
                              1:
                                (TriPt: pT));
                         CSTNODE:
                           (CstType: pT;
                            CstValu: Valu);
                         ASGNNODE:
                           (AsgnOp: 0..255;
                            AsgnVar, AsgnExpr: pN;
                            AsgnpN: pN);
                     END;

    StmtTypes      = (BEGINST, ASSIGNST, IFST, WHILEST, REPST, WITHST, FORTOST, FORDOWNST,
                      CALLST, GOTOST, CASEST, CSTMTST, LABEDST, METHODCALL, TEMPST,
                      NULLST);

    RegSetRec      =  RECORD
                        CASE Boolean OF
                          True:
                            (iMask: Integer);
                          False:
                            (sMask: SET OF D0..SP);
                      END;

    pStmt          = ^Stmt;        {ptrs to the head of statements}
    Stmt           = RECORD        {statement tree nodes}
                       NextStmt: pStmt;
                       StmtNumb: Integer;
                       CASE StmtOp: StmtTypes OF
                         BEGINST:
                           (SubSt: pStmt);
                         METHODCALL, ASSIGNST:
                           (AssOp: 0..255;
                            Flippable: Boolean;
                            AssSubOp: Integer;
                            AssVar, AssExpr: pN);
                         FORTOST, FORDOWNST:
                           (ForVar: pN;
                            ForInit, ForLimit: pN;
                            ForSt: pStmt;
                            ForSize: Integer;
                            xForVar1, xForVar2: pN);
                         IFST:
                           (IfExpr: pN;
                            ThenSt, ElseSt: pStmt);
                         WITHST:
                           (WithVar: pN;
                            WithBody: pStmt);
                         REPST, WHILEST:
                           (CondExpr: pN;
                            LoopStmt: pStmt);
                         CALLST:
                           (ProcpN: pN;
                            pArgList: pN);
                         GOTOST:
                           (GotoLab: pLabRec;
                            LabLev: LevRange);
                         CASEST:
                           (CaseExpr: pN;
                            CStmtList: pStmt;
                            OtherStmt: pStmt);
                         CSTMTST:
                           (CaseVals: pIntList;
                            ThisCase: pStmt);
                         LABEDST:
                           (StLab: pLabRec;
                            LabStmt: pStmt);
                         TEMPST:
                           (TempNode: pN;
                            TempLevel: Integer;
                            TempCSEregs: RegSetRec);
                     END;

    Where          = (BLK, REC, PARAMS, KLASS); {Display kinds}

    Attr           = RECORD            {statement attribute}
                       ASize: Integer;
                       Typtr: pT;
                       TreePtr: pN;
                     END;

    CondRange      = 0..MaxCondDepth;  {range of $ifc nesting depths}

   {"look"  means continue to compile the source till you find the condition
    "match" means skip the source till you find the condition}
    CondState      = (NULL, LOOKELSE, LOOKEND, MATCHELSE, MATCHEND);

    VarRef         = RECORD            {counts refs to a variable}
                       PVar: pN;       {the variable}
                       Refs: Integer;  {references}
                     END;

    RegContents    = (NADA, WITHSEL, GLOBALBASE, AVARIABLE);

    RegDesc        = RECORD            {describes contents of register}
                       CASE Contents: RegContents OF
                         WITHSEL, GLOBALBASE:
                           (RLevel: Integer);
                         AVARIABLE:
                           (PVar: pN);
                     END;

    InputFileTypes = (USED, INCLUDED, SOURCE);

    ErrRecord      = RECORD            {errors accumulated on a line}
                       Pos: 0..150;
                       Nbr: Integer;
                       Name: Alfa;
                     END;

    String150      = String[150];      {listing lines}

    String9        = String[9];        {ShowProcName param type}

    InbufType      = PACKED ARRAY [0..(InbufByteSize - 1)] OF Char;

    UnitRange      = 0..MAXUNITS;
    DispRange      = 0..MAXDISPLAY;

  VAR
    Token:         Symbol;             {currently scanned togen}
    Ident:         Alfa;               {most recently scanned identifier}
    IntVal:        LongInt;            {value of most recently scanned integer}
    RealVal:       Real;               {value of most recently scanned real}
    StrVal:        StrValType;         {value of most recently scanned string}
    Ch:            Char;               {Current input character}
    DotDot:        Boolean;            {true ==> ".." scanned and not a ":"}
    DotFlag:       Boolean;            {true ==> ".." picked up during real nbr scan}

    ChClass:       ARRAY [0..255] OF Symbol; {symbol type of each character}
    RWsymbol:      ARRAY [1..NUMRW] OF Symbol; {symbol type of each reserved word}
    RWnames:       ARRAY [1..NUMRW] OF Alfa; {the reserved words}
    LRWnames:      ARRAY [0..8] OF Integer; {"hash" ptrs to get at RWnames}
    (*
    BlockBegSys, StatBegSys, TypeDels, ConstBegSys, TypeBegSys, SimpTypeBegSys, SelectSys,
    FacBegSys, DecBegSys, IdDecBegSys, AllBegSys: SetOfSys; {various symbol sets} {!01-21-84}
    *)
    IntPtr, SIntPtr, LIntPtr, RealPtr, CharPtr, BoolPtr, TextPtr, InterPtr, NilPtr, Str0Ptr,
    Str1Ptr, AlfaPtr: pT;

    uCstPtr, uTypPtr, uVarPtr, uFldPtr, uPrcPtr, uFctPtr: pN; {"undefined" ptrs}

    OutputPtr:     pN;                 {OUTPUT file type ptr}
    InputPtr:      pN;                 {INPUT file type ptr}
    ReadPtr:       pN;                 {Read symbol table ptr}
    WritePtr:      pN;                 {Write symbol table ptr}

    KlassPtr:      pN;                 {%_CLASS procedure ptr}
    CkObCpPtr:     pN;                 {%_CKOBCP function ptr}
    CkObCnPtr:     pN;                 {%_CKOBCN function ptr}
    InObCpPtr:     pN;                 {%_INOBCP function ptr}
    InObCnPtr:     pN;                 {%_INOBCN function ptr}

    TopOfOpenFileStack: Integer;       {0..5 index to top of OpenFileStack}

    OpenFileStack: ARRAY [1..MAXFILES] OF
                     RECORD            {info pushed for nested source files}
                       LastRelBlkRead: Integer;
                       NextChToRead: Integer;
                       LastValidByte: Integer;
                       NumValidBlocks: Integer;
                       LineNbr, PrevLnbr: Integer;
                       FName: SUStr;
                       SrcFile: FILE;
                       SrcEolSource: Boolean;
                       BufSaved: Boolean;
                       LPrinted: Boolean;
                       ErrIdx: 0..MaxErrs;
                       ErrLst: ARRAY [1..MaxErrs] OF ErrRecord;
                       pCurL: Integer;
                       CurL, PrevL: String150;
                     END;

    InbufP:        Integer;            {input buffer ptr}
    InbufLastValidByte: Integer;       {last byte in current buffer}
    InbufNumValidBlocks: Integer;      {last block in current buffer}
    Inbuf:         InbufType;          {the input buffer}
    EolSource:     Boolean;            {true ==> Chr(13) read in buffer}
    SaveInbufP:    ^InbufType;         {save buffer to save inbuf}

    ListingFCBP:   IOFCBP;             {listing file FCB ptr}
    ListingBufrP:  IOBufrP;            {listing file buffer ptr}
    ListingOk:     Boolean;            {true ==> process listing directive}
    ListOpen:      Boolean;            {true ==> listing file is open}
    Listing:       Boolean;            {true ==> $L+ to generate listing}
    ConsListing:   Boolean;            {true ==> listing is to console screen}
    LinePrinted:   Boolean;            {true ==> current input line has been printed}
    AsmListOk:     Boolean;            {true ==> generate line nbr i-codes}
    ShowAsmCode:   Boolean;            {true ==> $ASM+ to generate full listing}
    NewListFile:   Boolean;            {true ==> new listing file opened}
    NewAsmStatus:  Boolean;            {true ==> a $ASM+- has occurred}
    Pass2Listing:  Boolean;            {true ==> generate line nbr i-codes}
    LineNumber:    Integer;            {current file line number}
    TotalLines:    LongInt;            {total number of lines processed}
    CurLine:       String150;          {current input line image}
    PrevLine:      String150;          {previous input line image}
    pCurLine:      Integer;            {current length of CurLine}
    PrevLn:        Integer;            {file line number of previous line}
    LastLine:      Integer;            {most recently i-code generated line nbr}
    Left, Right:   Char;               {left/right lex level displays for listing}
    ProcLev:       Char;               {proc level display for listing}
    NestLev:       Integer;            {lex nesting level}
    Blanks:        String[80];         {a string of blanks to ShowProcName}
    ShowPStr:      SUStr;              {ShowProcName's string value}

    Errors:        Integer;            {total nbr of errors}
    ErrFile:       Text;               {error log file}
    ErrFName:      SUStr;              {error log filename}
    ErrFileOpen:   Boolean;            {true ==> error log file is open}
    ErrIndex:      0..MaxErrs;         {nbr of errors on current line}
    ErrList:       ARRAY [1..MaxErrs] OF ErrRecord; {error status of current line}
    LastErrLn:     LongInt;            {line nbr of most recent error line}
    EofLn:         LongInt;            {line number of last input line}
    EofLine:       String150;          {line image of last input line}
    MsgFile:       FILE;               {error message file}
    MsgFileOpen:   Boolean;            {true ==> error message file is open}
    Aborted:       Boolean;            {true ==> compilation was aborted}

    IOFlag:        Boolean;            {true ==> $I+ (unused)}
    RangeFlag:     Boolean;            {true ==> $R+ for range checking}
    OflowFlag:     Boolean;            {true ==> $OV+ for overflow checking}
    RodFlag:       Boolean;            {true ==> $F++ to make Rod Perkins happy!}
    ForwChkFlag:   Boolean;            {true ==> $F+ to control fwd proc check}
    CodeFlag:      Boolean;            {true ==> $C+ to generate i-code}
    DbugFlag:      Boolean;            {true ==> $D+ to gen debug switch for ListBug}
    StkXFlag:      Boolean;            {true ==> $X+ to get Gen to gen stk exp. code}
    OptFlag:       Boolean;            {true ==> $OPT opt. master switch}
    OptLimFlag:    Boolean;            {true ==> $OPT+ limited (original) opt.}
    SwapFlag:      Boolean;            {true ==> $S+ to load in all segments at init}
    CallGen:       Boolean;            {true ==> $G+ to allow chaining to Gen}
    CallEditor:    Boolean;            {true ==> $E+ to allow chaining to Editor}

    PrintErrors:   Boolean;            {true ==> let SearchAll report errors}
    InClassDecl:   Boolean;            {true ==> doing Subclass declaration (ClassList)}
    FlipBytes:     Boolean;            {true ==> change byte sex (unused)}
    InUnit:        Boolean;            {true ==> compiling a unit}
    Using:         Boolean;            {true ==> processing a USES file}
    InUses:        Boolean;            {true ==> processing used file declarations}
    InterFlag:     Boolean;            {true ==> processing an Interface section}

    AsmOnly:       Boolean;            {true ==> Gen option $ASM ONLY}
    AsmProc:       Boolean;            {true ==> Gen option $ASM PROC}
    SaveA2D3:      Boolean;            {true ==> Gen option $A}
    MacFlag:       Boolean;            {true ==> Gen option $M}

    Ecmd:          String[2];          {<esc>E to call the editor}
    Gcmd:          String[2];          {<esc>G to call the code generator}

    CurrentProc:   pN;                 {current proc being compiled}
    HeapMark:      PBoolean;           {used to control heap allocation}
    ProcStmt:      pStmt;              {ptr to the head of a proc's tree}

    {$IFC IULIB}
    SearchLibrary: Boolean;            {true ==> $U+ to search intrinsic lib}
    IULibIn:       Boolean;            {true ==> IU lib has been opened}
    {$ENDC}

    UFname:        SUStr;              {current $U filename}
    NumUnits:      Integer;            {total nbr of used units}
    InIU:          Boolean;            {true ==> compiling an intrinsic unit}
    FirstUBlock, FirstUByte, LastUBlock, LastUByte: Integer; {interface block ptrs}
    IntFName:      SUStr;              {file name of file containing interface}

    ForwPList:     pN;                 {forward references to procs}

    Level:         LevRange;           {current nesting level}
    Disx:          DispRange;          {display level as set by SearchAll}
    Top:           DispRange;          {current top of the Display}

    Display:       ARRAY [DispRange] OF
                     RECORD
                       NameTree: pN;                                           {!C}
                       CASE Occur: Where OF
                         BLK:
                           (ProcBase: PBoolean;                                {!DBG!}
                            Labels, ExitLabel: pLabRec;
                            RootLink: pN);
                         REC:
                           (RecPckd: Boolean;
                            CASE RecAcc: AccessKind OF
                              INDRCT:
                                (RecLevel: LevRange));
                         KLASS:
                           (KType: pT;                                         {!C}
                            WVar: pN);                                         {!C}
                         {PARAMS: ();}
                     END;

    gAttr:         Attr;               {current expression attributes}

    HandleCheck:   Boolean;            {true ==> $H+ for Clascal handle checks}
    WithDHandle:   Integer;            {used to do handle checks in WITH}
    ExprDHandle:   Integer;            {used to do handle checks in expressions}
    LHSDHandle:    Integer;            {used to do handle checks in assignments}

    ThisClass:     pT;                 {pT for class whose methods we are compiling}
    CurrClass:     String9;            {name of class corresoinding to ThisClass}
    NextCrNbr:     Integer;            {next available nbr for CREATION name}
    ProcPtr:       pT;                 {return type of proc so to trap procs called as funcs}
    NilClassPtr:   pT;                 {the base of all subclasses}
    ForwCList:     pN;                 {forward references to classes}         {!C}

    CodeOpened:    Boolean;            {true ==> i-code file is open}
    ICodeFile:     FILE;               {the i-code file}
    Buff:          PACKED ARRAY [0..(BuffByteSize - 1)] OF Char; {i-code buffer}
    ByteNo, BlockNo: Integer;          {current i-code byte and block number}

    ICodeName:     SUStr;              {i-code filename for the code generator}
    ObjName:       SUStr;              {.obj filename for the code generator}

    LocProcNo:     Integer;            {local proc counter to gen internal names}

    UnitList:      pN;                 {ptr to list of units}
    UnitsToInit:   Boolean;            {true==>some units need init}           {!12-20-83}
    ClassesToInit: Boolean;            {true==>some classes need init}         {!12-20-83}

    SegName:       Alfa;               {current segment name from $S <name>}
    ProgName:      Alfa;               {program or unit name}

    DebugDebug:    Boolean;            {true ==> generate debug info}          {!DBG!}
    Debugging:     Text;               {debug info file}                       {!DBG!}
    DebugOpened:   Boolean;            {true ==> Debug file is open}           {!DBG!}
    DebugFile:     FILE;               {Debugger output file (not completed?)} {!DBG!}
    DbgBuf:        PACKED ARRAY [0..511] OF Char; {Debugger output buffer}     {!DBG!}
    DbgIdx:        0..512;             {current offset in DbgBuf}              {!DBG!}
    DbgBlkNum:     Integer;            {current DebugFile block nbr}           {!DBG!}

    CondTos:       CondRange;          {CondStack top of stack ptr}
    CondStack:     ARRAY [CondRange] OF CondState; {nested $IFC's status}
    CondRoot:      pN;                 {root of tree of $setc id's}
    ParsingOption: Boolean;            {true ==> parsing $ifc/$setc}
    RBrackChar:    Char;               {a "*" or rt. brace for end of comment}

    RegMask:       RegSetRec;          {what registers were used in proc}

    WithLevel:     Integer;            {current WITH nesting level (from Dump)}
    WithRefs:      ARRAY [DispRange] OF {count of refs to indirect with vars}
                     RECORD
                       Refs: Integer;
                       Indirect: Boolean;
                       PUpArrow: pN;   {used to detect WITH P^ DO options}
                       EverChange: Boolean;
                     END;

    iGlobalRefs:   ARRAY [DispRange] OF Integer; {count of intermed. level glob. refs}

    sGlobalRefs:   ARRAY [UnitRange] OF Integer; {count of shared glob. refs}

    CurRefs:       Integer;
    VarRefs:       ARRAY [0..MAXREFS] OF VarRef; {count of local & global refs}

    GlobalRegisters,                   {global register allocations}
    CurRegisters:  ARRAY [GenRegister] OF RegDesc; {current register contents}

    GlobFlippable: Boolean;            {used to detect potential sideeffect in assignment
                                        statements}
    HasGlobalLabel: Boolean;           {true iff there are global labels in this procedure}
    Forwcount:     Integer;            {count of current number of unresolved forward-declared
                                        procs/funcs}

    ErrNum, RefNum: Integer;           {PLinitHeap params}

  {-------------------------------------------------------------------------------}

  CONST
    BlockBegSys    = [LABELSY, CONSTSY, TYPESY, VARSY, PROCSY, FUNCTSY, BEGINSY,
                      METHSY];
    ConstBegSys    = [PLUSSY, MINUSSY, ICONSTSY, RCONSTSY, SCONSTSY, CCONSTSY,
                      IDENTSY, LPARENSY, NOTSY, LBRACKSY];                    {!01-20-84}
    SimpTypeBegSys = [LPARENSY] + ConstBegSys - [SCONSTSY];
    TypeDels       = [ARRAYSY, FILESY, RECORDSY, SETSY, STRINGSY, SUBCLSY];
    TypeBegSys     = [UPARROWSY, PACKEDSY] + TypeDels + SimpTypeBegSys;
    SelectSys      = [UPARROWSY, PERIODSY, LBRACKSY];
    FacBegSys      = [ICONSTSY, RCONSTSY, SCONSTSY, CCONSTSY, IDENTSY, LPARENSY,
                      LBRACKSY, NOTSY, NILSY, ATSIGNSY];
    StatBegSys     = [BEGINSY, GOTOSY, IFSY, WHILESY, REPEATSY, FORSY, WITHSY,
                      CASESY];
    IdDecBegSys    = [LABELSY, CONSTSY, TYPESY, VARSY];                       {!01-21-84}
    DecBegSys      = IdDecBegSys + [PROCSY, FUNCTSY];                         {!01-21-84}
    AllBegSys      = BlockBegSys + StatBegSys;                                {!01-21-84}

  {-------------------------------------------------------------------------------}

  FUNCTION OpenNewFile(Filename: SUStr; FileType: InputFileTypes): Boolean;
    FORWARD;

  PROCEDURE PreviousFile;
    FORWARD;

  PROCEDURE FilePos(VAR Block, Byte: Integer);
    FORWARD;

  PROCEDURE FileSeek(Block: Integer);
    FORWARD;

  PROCEDURE FillInbuf;
    FORWARD;

  FUNCTION ShowProcName(Class: String9; Name: Alfa; Level: Integer): SUStrP;
    FORWARD;

  PROCEDURE LeftCheck;
    FORWARD;

  PROCEDURE RightCheck;
    FORWARD;

  PROCEDURE ListLine(VAR TotalLines: LongInt);
    FORWARD;

  PROCEDURE ListErrors;
    FORWARD;

  PROCEDURE NextCh;
    FORWARD;

  PROCEDURE Scan;
    FORWARD;

  PROCEDURE Skip(ErrorNo: Integer; FSys: SetOfSys);
    FORWARD;

  PROCEDURE EnterId(fN: pN);
    FORWARD;

  FUNCTION SearchAll(fClass: NClassSet): pN;
    FORWARD;

  FUNCTION SearchLocal(FTree: pN): pN;
    FORWARD;

  FUNCTION SearchClasses(FpT: pT; VAR HigherLevel: Boolean;
                         StartAtSuper: Boolean): pN;                           {!C 12-14-83}
    FORWARD;

  PROCEDURE ChToString(VAR FAttr: Attr);
    FORWARD;

  PROCEDURE UpdateSetConst(fLb, fUb: LongInt; VAR fSetCstPart: pN);
    FORWARD;

  PROCEDURE Constant(FSys: SetOfSys; VAR fValu: Valu; VAR FpT: pT);
    FORWARD;

  PROCEDURE KillExec;
    FORWARD;

  PROCEDURE Error(ErrNum: Integer);
    FORWARD;

  PROCEDURE NError(ErrNum: Integer; ErrName: Alfa);
    FORWARD;

  FUNCTION CompTypes(FpT1, FpT2: pT): Boolean;
    FORWARD;

  FUNCTION EqTypes(FpT1, FpT2: pT): Boolean;                                   {!C}
    FORWARD;                                                                   {!C}

  FUNCTION CompFormals(FormArg1, FormArg2: pN; Exact: Boolean): Boolean;
    FORWARD;

  FUNCTION StringType(FpT: pT): Boolean;
    FORWARD;

  PROCEDURE GetBounds(FpT: pT; VAR Fmin, Fmax: Integer);
    FORWARD;

  FUNCTION FullBytes(FpT: pT): Integer;
    FORWARD;

  PROCEDURE Out(a: Integer);
    FORWARD;

  PROCEDURE Out2(a: Integer);
    FORWARD;

  FUNCTION HasBody(FSys: SetOfSys; ProcpN: pN; VAR HeapMark: PBoolean): Boolean;
    FORWARD;

  PROCEDURE Copyrights;

    CONST
      SVS = '1981 SVS, Inc.';
      COPY1 = 'Copyright';
      APPLE = '1983, 1984 Apple Computer, Inc.';
      COPY2 = 'Copyright';

    BEGIN {CopyRights - this routine appears here to cause the Apple and SVS
           copyrights to appear physically in the linked code file. It is the
           first routine in the blank segment so that the copyrights appear early
           in the file. It is also called to display the copyright message on the
           screen. Note: the word "copyright" must appear verbatim in code}
      Write('(c)', SVS);
      IF COPY1 = '' THEN;
      WriteLn('  (c)', APPLE);
      IF COPY2 = '' THEN;
    END;

