(****************************************
*                                       *
*     MODULA-2 Multi-Pass Compiler      *
*     ****************************      *
*                                       *
*       VAX/VMS Implementation          *
*                                       *
*                                       *
*     MVCompiler:                       *
*                                       * 
*     private part of the common base   *
*     of the Modula-2 compiler          *
*                                       * 
*     Version 3.1 of  1-FEB-1983        *
*                                       *
*                                       *
*                                       *
*     Based on PDP11 Implementation:    *
*     Version M22 of 17.03.81           *
*					*
*     Institut fuer Informatik          *
*     ETH-Zuerich                       *
*     CH-8092 Zuerich                   *
*                                       *
****************************************)

(****************************************
* Updates: see implementation module    *
****************************************)

DEFINITION MODULE MVCompiler; (* VAX: JK, PP, EK *)

  EXPORT QUALIFIED
         spellmax, levmax, modnamlength,
         maxcard, maxint, minint, maxchar, maxaddr, wordsize, basemax,
         Idptr, Stptr, Listptr, Stringptr, XRefptr,
         Idclass, Idset, Structform, Stset,
         Recpart, Varkind, Kindvar, Parkind, Stpures, Stfuncs,
         Spellix, Levrange, Constval, Modnamarr, Keyarr,
         boolptr, charptr, intptr, cardptr, intcarptr, realptr,
         dfloatptr, gfloatptr, hfloatptr,
         procptr, bitsetptr, wordptr, addrptr, processptr,
         byteptr, shortwordptr, quadwordptr, octawordptr,
         substptr, strptrs,
         root, mainmodp, sysmodp,
         globvarnext,
         stctad, stringcount, stringroot,
         spelltab,
         Symbol;

  CONST
    spellmax = 14999;     (* maximum length of all identifiers *)
    levmax = 15;          (* maximal nesting level *)
    modnamlength = 24;    (* maximal length for module identifiers *)
    maxcard = 0FFFFFFFFH; (* maximal cardinal number *)
    maxint = 2147483647;  (* maximal integer number *)
    minint = -maxint-1;   (* minimal integer number *)
    maxchar = 0FFH;       (* maximal character constant *)
    maxaddr = maxcard;    (* maximal address *)
    wordsize = 32;        (* bits per computer word *)
    basemax = wordsize;   (* maximal number of set elements *)

  TYPE
    Idptr      = POINTER TO Identrec;
    Stptr      = POINTER TO Structrec;

    Structform = (enums,bools,chars,ints,cards,words,subranges,reals,
                  pointers,sets,proctypes,arrays,records,hides,opens);
    Stset      = SET OF Structform;
    Idclass    = (consts, types, vars, fields, pures, funcs,
                  mods, unknown, indrct);
    Idset      = SET OF Idclass;
    Recpart    = (fixedpart, tagfield, variantpart);

    Structrec  = RECORD
                   size : CARDINAL; (* byte size *)
                   stidp : Idptr; (* identifier defining this structure *)
                   inlist : BOOLEAN; (* structure entered into a list *)
                   CASE form : Structform OF
                     bools,chars,ints,cards,words,reals: (* no field *) |
                     enums: fcstp : Idptr;
                       cstnr : CARDINAL |
                     subranges: scalp : Stptr;
                       min, max : CARDINAL |
                     pointers: elemp : Stptr |
                     sets: basep : Stptr |
                     arrays: 
                       elp, ixp : Stptr;
                       dyn : BOOLEAN; |
                     records: 
                       CASE rpart : Recpart OF
                         fixedpart: 
                           fieldp : Idptr;
                           tagp : Stptr; |
                         tagfield: 
                           fstvarp, elsevarp : Stptr;
                           tagtyp : Stptr |
                         variantpart: 
                           nxtvarp, subtagp : Stptr;
                           varval : CARDINAL
                       END (* case Recpart *) |
                     proctypes: 
                       fstparam : Idptr; (* pointer to parameter list *)
                       parlgth : CARDINAL; (* bytes needed for parameters *)
                       CASE rkind : Idclass OF
                         funcs: 
                           funcp : Stptr; (* pointer to function type *) |
                         pures: (* no further fields *)
                       END; |
                     hides,opens: (* conversion from hides to opens *)
                       openstruc : Stptr; (* used for opens *)
                   END (* case Structform *)
                 END (**record**);

    Varkind    = (noparam, valparam, varparam);
    Kindvar    = (global, local, absolute, separate);
    Parkind    = (default, ref, immed, descr, stdescr);
    Listptr    = POINTER TO Listrec;
    Listrec    = RECORD
                   element : Idptr;
                   next : Listptr;
                 END;
    Stringptr  = POINTER TO Stringval;
    Stringval  = RECORD
                   loadoffset : CARDINAL;
                   valentry : CARDINAL;
                   slink : Stringptr;
                   (* loadoffset means the offset in the     *)
                   (* string data area of the loaded program *)
                   (* valentry is an address to the heap     *)
                   (* entry of the string value              *)
                   (* the structure of valentry should be:   *)
                   (*   POINTER TO ARRAY [0..length] OF CHAR *)
                   (* the element with index length is a 0C  *)
                   (* slink links the strings to be loaded   *)
                 END;
                   (* cross reference list entries: *)
    XRefptr    = POINTER TO XRefrec;
    XRefrec    = RECORD
                   lineno : CARDINAL;
                   mark :   BOOLEAN;
                   nextref: XRefptr;
                 END;
    Constval   = RECORD
                   CASE Structform OF
                     arrays: (* for string constants only *)
                       svalue : Stringptr; |
                     reals: rvalue : POINTER TO REAL;
                   ELSE (* oneword constants *)
                     value : CARDINAL;
                   END;
                 END;
    Keyarr     = ARRAY [0..1] OF CARDINAL;
    Modnamarr  = ARRAY [0..modnamlength-1] OF CHAR;
    Spellix    = [0..spellmax];
    Levrange   = [0..levmax];
    Stpures    = (decp, disp, exlp, halp, incp, inlp, newp, nprp, 
                  trsp, uxcp);
    Stfuncs    = (absf, adrf, ashf, capf, chrf, fltf, higf, lenf,
                  oddf, ordf, regf, sizf, trcf, tszf, valf);

    Identrec   = RECORD
                   name : Spellix;
                   link : Idptr;
                   xref : XRefptr;
                   CASE BOOLEAN OF
                     FALSE: nxtidp : Idptr |
                     TRUE : idtyp : Stptr
                   END (* case boolean *);
                   globmodp : Idptr; (* pointer to global module *)
                   CASE klass : Idclass OF
                     consts,unknown: (*unknown may convert to consts*)
                       cvalue : Constval; |
                     types: dstaddr: CARDINAL; |
                     vars: 
                       vlevel : Levrange;
                       vaddr : CARDINAL;   (* offset *)
                       state : Kindvar;
                       CASE vkind : Varkind OF
                         valparam, varparam:
                           pkind : Parkind;
                           nxtparam : Idptr;
                           caddr : CARDINAL |
                         noparam: (* no further field *)
                       END (* case Varkind *) |
                     fields: fldaddr : CARDINAL |
                     pures, funcs, mods: 
                       CASE isstandard : BOOLEAN OF
                         TRUE: 
                           CASE Idclass OF
                             pures: pname : Stpures |
                             funcs: fname : Stfuncs
                           END (* case Idclass *) |
                         FALSE: 
                           procnum : CARDINAL;
                           locp : Idptr;
                           msp : Listptr;
                           plev : Levrange;
                           varlength: CARDINAL;
                           externalaccess : BOOLEAN;
                           used : BOOLEAN;
                           CASE Idclass OF
                             pures,funcs: 
                               foreignname : Spellix;
                               usedisp : BOOLEAN; |
                             mods: 
                               impp : Listptr;
                               expp : Idptr;
                               qualexp : BOOLEAN;
                               CASE globalmodule : BOOLEAN OF
                                 FALSE: (* no further field *) |
                                 TRUE: 
                                  modnum : CARDINAL;
                                  modulekey : Keyarr;
                                  identifier : Modnamarr;
                                  foreign : BOOLEAN;
                               END; (* case globalmodule *)
                           END; (* case Idclass *)
                       END (* case isstandard *); |
                     indrct: (* no further fields *)
                   END (* case Idclass *)
                 END; (* record *)


  VAR
    boolptr    : Stptr;   (* structure of type BOOLEAN *)
    charptr    : Stptr;   (* structure of type CHAR    *)
    intptr     : Stptr;   (* structure of type INTEGER *)
    cardptr    : Stptr;   (* structure of type CARDINAL *)
    intcarptr  : Stptr;   (* structure of intcar - type *)
    realptr    : Stptr;   (* structure of type REAL *)
    dfloatptr  : Stptr;   (* structure of type D-Floating *)
    gfloatptr  : Stptr;   (* structure of type G-Floating *)
    hfloatptr  : Stptr;   (* structure of type H-Floating *)
    procptr    : Stptr;   (* structure of type PROC *)
    bitsetptr  : Stptr;   (* structure of type BITSET  *)
    wordptr    : Stptr;   (* structure of type WORD    *)
    byteptr    : Stptr;   (* structure of type BYTE    *)
    shortwordptr: Stptr;  (* structure of type SHORTWORD *)
    quadwordptr: Stptr;   (* structure of type QUADWORD *)
    octawordptr: Stptr;   (* structure of type OCTAWORD *)
    addrptr    : Stptr;   (* structure of type ADDRESS *)
    processptr : Stptr;   (* structure of type PROCESS *)
    strptrs    : ARRAY [0..20] OF Stptr;
    (* table of string structure entries *)
    substptr   : Idptr;   (* list of procedures to be substituted *)
    root       : Idptr;   (* root of standardname entries  *)
    mainmodp   : Idptr;   (* pointer to main module *)
    sysmodp    : Idptr;   (* pointer to module SYSTEM *)
    globvarnext: CARDINAL;(* next free address for global variables *)
    stctad     : CARDINAL;(* string constant table address *)
    stringcount: CARDINAL;(* number of bytes needed for string area *)
    stringroot : Stringptr;(* chain of strings to be loaded *)
    spelltab   : ARRAY Spellix OF CHAR; (* identifier table *)

  TYPE
    Symbol = (eop,                                                      (* 0H*)
(* Pass 1 *)  andsy,divsy,times,slash,modsy,notsy,plus,minus,orsy,      (* 9H*)
              eql,neq,grt,geq,lss,leq,insy,                             (*10H*)
              lparent,rparent,lbrack,rbrack,lconbr,rconbr,              (*16H*)
              comma,semicolon,period,colon,range,                       (*1BH*)
              constsy,typesy,varsy,arraysy,recordsy,variant,setsy,      (*22H*)
              pointersy,tosy,arrow,hidden,                              (*26H*)
              importsy,exportsy,fromsy,qualifiedsy,                     (*2AH*)
              beginsy,casesy,ofsy,ifsy,thensy,elsifsy,elsesy,loopsy,    (*32H*)
              exitsy,repeatsy,untilsy,whilesy,dosy,withsy,              (*38H*)
              forsy,bysy,returnsy,becomes,endsy,                        (*3DH*)
              call,endblock,                                            (*3FH*)
              definitionsy,implementationsy,proceduresy,modulesy,       (*43H*)
              symbolsy,foreignsy,refsy,immedsy,descrsy,stdescrsy,       (*49H*)
              ident,intcon,cardcon,intcarcon,realcon,charcon,stringcon, (*50H*)
              option,errorsy,eol,                                       (*53H*)
(* Pass 2 *)  namesy,                                                   (*54H*)
(* Pass 3 *)  field,anycon);                                            (*56H*)

END MVCompiler.
