-- DebugOps.mesa  last edit, Bruce  September 29, 1980  10:03 AM

DIRECTORY
  DebugFormat USING [BBHandle, BitAddress, Foo],
  MachineDefs USING [
    AccessOptions, AddModifyProc, BYTE, DefaultAccess, DefaultVersion, FileHandle,
    FileName, InvalidateFileCache, GFHandle, ModifyFile, CacheNewFile, PageNumber,
    VersionOptions],
  PrincOps USING [BytePC],
  Symbols USING [CSEIndex, typeANY],
  Window USING [Handle];

DebugOps: DEFINITIONS IMPORTS MachineDefs =
  BEGIN

  BitAddress: TYPE = DebugFormat.BitAddress;
  Foo: TYPE = DebugFormat.Foo;
  BBHandle: TYPE = DebugFormat.BBHandle;
  GFHandle: TYPE = MachineDefs.GFHandle;

  -- READing and WRITEing
  LongREAD: PROCEDURE [loc: LONG POINTER] RETURNS [val: UNSPECIFIED];
  LongWRITE: PROCEDURE [loc: LONG POINTER, val: UNSPECIFIED];
  LongCopyREAD: PROCEDURE [
    from: LONG POINTER, nwords: CARDINAL, to: LONG POINTER];
  LongCopyWRITE: PROCEDURE [
    from: LONG POINTER, nwords: CARDINAL, to: LONG POINTER];

  ShortREAD: PROCEDURE [loc: POINTER] RETURNS [val: UNSPECIFIED] =
    INLINE BEGIN RETURN[LongREAD[Lengthen[loc]]] END;
  ShortWRITE: PROCEDURE [loc: POINTER, val: UNSPECIFIED] =
    INLINE BEGIN LongWRITE[Lengthen[loc],val] END;
  ShortCopyREAD: PROCEDURE [from: POINTER, nwords: CARDINAL, to: POINTER] =
    INLINE BEGIN LongCopyREAD[Lengthen[from], nwords, to] END;
  ShortCopyWRITE: PROCEDURE [from: POINTER, nwords: CARDINAL, to: POINTER] =
    INLINE BEGIN LongCopyWRITE[from, nwords, Lengthen[to]] END;

  Lengthen: PROCEDURE [POINTER] RETURNS [LONG POINTER];

  ReadCodeByte: PROC [gf: GFHandle, pc: PrincOps.BytePC]
    RETURNS [MachineDefs.BYTE];
  WriteCodeByte: PROC [
    gf: GFHandle, pc: PrincOps.BytePC, inst: MachineDefs.BYTE];
  ReadCodeWord: PROC [gf: GFHandle, offset: INTEGER] RETURNS [UNSPECIFIED];

  -- Variable Display
  FooProc: TYPE = PROCEDURE [f: Foo];
  DisplayFoo: FooProc;
  Display: PROCEDURE [f: DebugFormat.Foo, rec: BOOLEAN ← FALSE];

  -- File Cache
  CacheNewFile: PROCEDURE [
    name: STRING, access: MachineDefs.AccessOptions ← MachineDefs.DefaultAccess,
    version: MachineDefs.VersionOptions ← MachineDefs.DefaultVersion]
      RETURNS [MachineDefs.FileHandle] = INLINE {
    RETURN[MachineDefs.CacheNewFile[name,access,version]]};
  FileName: PROCEDURE [name: STRING, file: MachineDefs.FileHandle] = INLINE {
    MachineDefs.FileName[name,file]};
  ModifyFile: PROCEDURE [name: STRING] RETURNS [BOOLEAN] = INLINE {
    RETURN[MachineDefs.ModifyFile[name]]}; 
  InvalidateFileCache: PROCEDURE = INLINE {MachineDefs.InvalidateFileCache};
  AddModifyProc: PROC [proc: PROC[STRING,MachineDefs.FileHandle] RETURNS [BOOLEAN]] =
    INLINE {MachineDefs.AddModifyProc[proc]};

  AddStatisticsProcedure: PROC[PROC];

  -- Debug Window
  window: Window.Handle;
  fileSW: Window.Handle;

  -- Interpreter
  Interpret: PROC [
    exp: STRING, results: FooProc ← DisplayFoo,
    targetType: Symbols.CSEIndex ← Symbols.typeANY];

  Numeric: PROC [STRING] RETURNS [BOOLEAN];
  StringToModule: PROC [STRING] RETURNS [STRING];

  StringExpToNum: PROC [exp: STRING, radix: CARDINAL] RETURNS [UNSPECIFIED];
  StringExpToLNum: PROC [exp: STRING, radix: CARDINAL]
    RETURNS [LONG UNSPECIFIED];
  StringExpToOctal: PROC [STRING] RETURNS [CARDINAL];
  StringExpToLOctal: PROC [STRING] RETURNS [LONG CARDINAL];
  StringExpToDecimal: PROC [STRING] RETURNS [INTEGER];
  StringExpToLDecimal: PROC [STRING] RETURNS [LONG INTEGER];

  ParseError: SIGNAL [errorLoc: CARDINAL];
  SyntaxError: SIGNAL [errorLoc: CARDINAL];
  InvalidCharacter: SIGNAL [index: CARDINAL];
  InvalidNumber: SIGNAL [f: Foo];

  -- other signals
  NotImplemented: SIGNAL [msg: STRING];
  CommandNotAllowed: SIGNAL;
  UserAborted: SIGNAL;
  WriteProtected: SIGNAL [page: CARDINAL];
  InvalidAddress: ERROR [address: LONG POINTER];
  NonExistentMemoryPage: ERROR [page: MachineDefs.PageNumber];
  Abort, Proceed, Kill, Quit: SIGNAL;

  END.