
<<FILE: M2D.mesa>>
<<Modula-2 Datastructure>>
<<Last Edited by: Gutknecht, September 18, 1985 0:14:02 am PDT>>
    <<Satterthwaite December 11, 1985 3:11:31 pm PST>>

M2D: CEDAR DEFINITIONS =

BEGIN

WordSize: CARDINAL = 32;
SET: TYPE = PACKED ARRAY [0..WordSize-1] OF BOOL;

nilval: CARDINAL = 177777B;
MaxCodeLength: CARDINAL = 8;

ObjPtr: TYPE = REF Object;
HeaderPtr: TYPE = REF Object.Header;
ConstPtr: TYPE = REF Object.Const;
TypPtr: TYPE = REF Object.Typ;
VarPtr: TYPE = REF Object.Var;
FieldPtr: TYPE = REF Object.Field;
ProcPtr: TYPE = REF Object.Proc;
ModulePtr: TYPE = REF Object.Module;
LinkagePtr: TYPE = REF Object.Linkage;

BDPtr: TYPE = REF BDesc;
PDPtr: TYPE = REF BDesc.Block;
CDPtr: TYPE = REF BDesc.Code;

StrPtr: TYPE = REF Structure;
EnumPtr: TYPE = REF Structure.Enum;
RangePtr: TYPE = REF Structure.Range;
PointerPtr: TYPE = REF Structure.Pointer;
SetPtr: TYPE = REF Structure.Set;
ArrayPtr: TYPE = REF Structure.Array;
RecordPtr: TYPE = REF Structure.Record;
ProcTypPtr: TYPE = REF Structure.ProcTyp;
OpaquePtr: TYPE = REF Structure.Opaque;

ParPtr: TYPE = REF Parameter;
ImpPtr: TYPE = REF ImportItem;
ExpPtr: TYPE = REF ExportItem;

ObjClass: TYPE = { Header, Const, Typ, Var, Field, Proc, Module, Linkage };

StrForm: TYPE = { Undef, Bool, Char, Card, Int, Double, Real, LongReal, String, Enum, Range, Pointer, Set, Array, Record, ProcTyp, 
Opaque };

ConstValue: TYPE = RECORD
 [ SELECT OVERLAID StrForm FROM
Bool    => [ B: BOOL ],
Char    => [ Ch: CHAR ],
Int    => [ I: LONG INTEGER ],
Card, Enum => [ C: LONG INTEGER ],
Set    => [ S: SET ],
Double => [ D: LONG INTEGER ],
Real    => [ R: REAL ],
LongReal => [ X: REAL ],
String    => [ D0, D1, D2, D3: CARDINAL ]
ENDCASE ];

Object: TYPE = RECORD
[ name: CARDINAL _ 0,
typ: StrPtr _ NIL,
next: ObjPtr _ NIL,
ext: SELECT class: ObjClass FROM
Header =>
[ kind: ObjClass _ $Proc, -- Proc, Module or Typ
last: ObjPtr _ NIL,
base: ObjPtr _ NIL,
firstImp: ImpPtr _ NIL,
cell: CARDINAL _ 0 ], -- record base addr 
Const =>
[ conval: ConstValue ],
Typ =>
[ mod: ModulePtr _ NIL ],
Var =>
[ mod: CARDINAL _ 0,
lev: CARDINAL _ 0,
cell: CARDINAL _ 0,
varpar: BOOL _ FALSE ],
Field =>
[ offset: CARDINAL _ 0 ],
Proc =>
[ bd: BDPtr _ NIL,
firstParam: ParPtr _ NIL],
Module =>
[ mod: CARDINAL _ 0,
key: LONG CARDINAL _ 0,
prio: CARDINAL _ 0,
pc: CARDINAL _ 0 ,
pAnc: PDPtr _ NIL, -- proc ancestor --
firstExp: ExpPtr _ NIL,
firstObj: ObjPtr _ NIL ],
Linkage =>
[ baseref: CARDINAL _ 0 ],
ENDCASE];

BodyForm: TYPE = { Block, Code };

BDesc: TYPE = RECORD
[ SELECT form: BodyForm FROM
Block =>
[ mod: CARDINAL _ 0,
num: CARDINAL _ 0,
pc: CARDINAL _ 0,
lev: CARDINAL _ 0,
firstLocal: ObjPtr _ NIL,
pAnc: PDPtr _ NIL,
mAnc: ModulePtr _ NIL,
LNK: CARDINAL _ 0, -- LNK=SL, LNK+1=FRX
cell: CARDINAL _ 0,
adr: CARDINAL _ 0,
needsBUP: BOOL _ FALSE,
impRegs: SET _ ALL [FALSE]],
Code =>
[ num: CARDINAL _ 0,
length: CARDINAL _ 0,
cod: ARRAY [0..MaxCodeLength) OF [0..255] ]
ENDCASE
];

Structure: TYPE = RECORD
[ strobj: TypPtr _ NIL, --type naming structure
size: CARDINAL _ 0,
ref: CARDINAL _ 0,
ext: SELECT form: StrForm FROM
Undef, Bool, Char, Int, Card, Double, Real, LongReal, String =>
[],
Enum =>
[ NofConst: CARDINAL _ 0 ],
Range =>
[ BaseTyp: StrPtr _ NIL,
min: INTEGER _ 0,
max: INTEGER _ 0,
BndAdr: INTEGER _ 0 ],
Pointer =>
[ BaseTyp: StrPtr _ NIL,
BaseId: CARDINAL _ 0 -- to handle forward refs -- ],
Set =>
[ BaseTyp: StrPtr _ NIL ],
Array =>
[ ElemTyp: StrPtr _ NIL,
IndexTyp: StrPtr _ NIL,
dyn: BOOL _ FALSE ],
Record =>
[ firstFld: ObjPtr _ NIL ],
ProcTyp =>
[ firstPar: ParPtr _ NIL,
resTyp: StrPtr _ NIL ],
Opaque =>
[],
ENDCASE _ Undef[]
];

Parameter: TYPE = RECORD [ typ: StrPtr, varpar: BOOL, next: ParPtr ];
ImportItem: TYPE = RECORD [ name: CARDINAL, item: ObjPtr, next: ImpPtr ];
ExportItem: TYPE = RECORD [ name: CARDINAL, item: ObjPtr, next: ExpPtr ];

mainmod, sysmod: VAR ModulePtr;

undftyp, booltyp, chartyp, inttyp, cardtyp, bitstyp, dbltyp, realtyp, lrltyp,
proctyp, stringtyp, notyp, addrtyp, wordtyp: VAR StrPtr;

UNION: PROC [r, s: SET] RETURNS [R: SET];
INTERSECTION: PROC [r, s: SET] RETURNS [R: SET];
SETDIFF: PROC [r, s: SET] RETURNS [R: SET];
SYMMDIFF: PROC [r, s: SET] RETURNS [R: SET];
SUBSET: PROC [r, s: SET] RETURNS [B: BOOL];

InitData: PROC

END.


