-- file code.mesa
-- last modified by Sweet, November 15, 1979  12:42 PM

DIRECTORY
  CodeDefs: FROM "codedefs" USING [Address, AJumps, Calls, CaseCVState, CCIndex, CgenUtil, Constructor, CrossJump, DJumps, Driver, DriverNotify, Expression, Final, Flow, FlowExpression, LabelCCIndex, Lexeme, OutCode, PeepholeQ, PeepholeU, PeepholeZ, StackImpl, Statement, Store, Temp, VarBasics, VarMove, VarUtils],
  CompilerUtil: FROM "compilerutil" USING [MakeSwappable],
  OpTableDefs: FROM "optabledefs" USING [OpTable],
  P5: FROM "p5" USING [Module],
  Symbols: FROM "symbols" USING [ContextLevel, CTXIndex, ISEIndex, RecordSEIndex],
  SymbolSegment: FROM "symbolsegment" USING [ByteIndex],
  Table: FROM "table" USING [AddNotify, DropNotify];

Code: PROGRAM 
    IMPORTS CodeDefs, CompilerUtil, OpTableDefs, P5, Table 
    EXPORTS CompilerUtil, P5 =
  PUBLIC BEGIN OPEN CodeDefs;


  -- the following variables are shared among the code generation modules

    dStar: BOOLEAN;
    curctxlvl: Symbols.ContextLevel;
    codeptr: CCIndex;
    bodyRetLabel, bodyComRetLabel: LabelCCIndex;
    bodyInRecord, bodyOutRecord: Symbols.RecordSEIndex;
    mainBody: BOOLEAN;
    ZEROlexeme: word literal Lexeme;
    acstack: INTEGER;
    stking: BOOLEAN;
    caseCVState: CaseCVState;
    mwCaseCV: Lexeme;
    fileindex, inlineFileIndex: SymbolSegment.ByteIndex;
    catchcount: CARDINAL;
    catchoutrecord: Symbols.RecordSEIndex;
    tempcontext: Symbols.CTXIndex;
    tempstart, framesz, cfs: CARDINAL;
    actenable: LabelCCIndex;
    xtracting: BOOLEAN;
    xtractlex: Lexeme;
    xtractsei: Symbols.ISEIndex;


    ACStackOverflow: SIGNAL = CODE;
    ACStackUnderflow: SIGNAL = CODE;
    StackNotEmptyAtStatement: SIGNAL = CODE;
    CodeNotImplemented: SIGNAL = CODE;
    DeletingUnreachableCode: SIGNAL = CODE;
    CodePassInconsistency: SIGNAL = CODE;
    CodePassError: ERROR [n: CARDINAL] = CODE;


  P5module: PROCEDURE =
    BEGIN -- starts the code generation pass
    Table.AddNotify[CodeDefs.DriverNotify];
    P5.Module[];
    Table.DropNotify[CodeDefs.DriverNotify];  RETURN
    END;

  P5Error: PROCEDURE [n: CARDINAL] =
    BEGIN
    ERROR CodePassError[n]
    END;

  BEGIN OPEN CompilerUtil;
  MakeSwappable[OpTableDefs.OpTable, pass5];
  MakeSwappable[CgenUtil, pass5];
  MakeSwappable[Driver, pass5];
  MakeSwappable[VarUtils, pass5];
  MakeSwappable[VarBasics, pass5];
  MakeSwappable[VarMove, pass5];
  MakeSwappable[Address, pass5];
  MakeSwappable[Temp, pass5];
  MakeSwappable[StackImpl, pass5];
  MakeSwappable[Flow, pass5];
  MakeSwappable[Store, pass5];
  MakeSwappable[Constructor, pass5];
  MakeSwappable[Expression, pass5];
  MakeSwappable[FlowExpression, pass5];
  MakeSwappable[Statement, pass5];
  MakeSwappable[Calls, pass5];
  MakeSwappable[OutCode, pass5];
  MakeSwappable[PeepholeQ, pass5];
  MakeSwappable[PeepholeU, pass5];
  MakeSwappable[PeepholeZ, pass5];
  MakeSwappable[AJumps, pass5];
  MakeSwappable[DJumps, pass5];
  MakeSwappable[CrossJump, pass5];
  MakeSwappable[Final, pass5];
  END;

  END...