/* * Definitions for the interpreter. The major defintion is that of a * ValueStruct that represents the types of values that may be computed in a * program. */ #ifndef interp_h #define interp_h /* * A major distinction in value types is between l-values and r-values. * L-values are those that represent memory locations, to which r-values can be * assigned. The name prefixes "L" and "R" refer to the LHS and RHS * respectively of an assignment statement. */ typedef enum { LVAL, RVAL } ValType; /* * A value structure tag indicates the type of value that is stored in the val * union field. */ #include "val.h" /* * A ValueStruct is a union of types of computable values. A "type" in this * context means one of general value types, i.e., integer, real, boolean, * string, list, tuple, or function. * * There are a couple of misnomers remnant from the Modula-2 code. * Specifically, a tuple value is called a "StructVal", and a function value is * called a "ProcVal". There are also some remnant Modula-2 value types that * are not currently used. These misnomers and left-over types are retained * for compilation purposes, pending some may-never-happen global refactoriing * of the code. */ typedef struct Val { ValType LorR; /* Is it an l- or r-value. */ ValTag tag; /* Tag indicating the general type of value, ie., a tag for the val union */ TypeStruct type; /* The full type struct, needed for structured vals. */ int size; /* The stored value of TypeSize(val) */ union { /* The following 7 fields are for the diffent types of r-values. */ int IntVal; /* An integer value */ double RealVal; /* A real value */ bool BoolVal; /* A boolean value */ struct StringStruct* StringVal;/* A string value */ char *StructVal; /* A structured, aka tuple value */ struct ListStruct* ListVal; /* A list value */ struct Sym *ProcVal; /* A proc, aka op function value (unevaluated). */ /* The next field is for an l-value. It points to a value in a storage * pool. */ char *LVal; /* The value of an l-value is its storage pointer. */ /* The following 5 fields are vestigial from Modula-2 */ long LIntVal; /* A long int value -- dumb since sizeof(int) virtually always = sizeof(long) */ double LRealVal;/* A long real value */ char CharVal; /* A char value, including char subranges */ long SetVal; /* A set value */ char *PtrVal; /* A pointer, aka ref value */ } val; } Value; typedef Value *ValueStruct; /* * Interpreter runtime exit statuses */ typedef enum { OKStatus, /* Execution terminated normally. */ NilPointerStatus, /* Abnormal termination -- ref through nil pointer */ NilProcStatus, /* Abnormal termination -- ref through nil proc var */ NilTypeStatus, /* Abnormal termination -- ref through nil type */ MemOutStatus, /* Abnormal termination -- out of memory */ ArrayBndStatus, /* Abnormal termination -- array index out of bnds */ StackOverStatus /* Abnormal termination -- stack overflow */ } ExitStatus; /* * Static pool and runtime stack structures. */ static int STATICSIZE = 25000; static int ENVIRSIZE = 200; static int STACKSIZE = 25000; static int DISPLAYSIZE = 1000; /* Raise this because new syntax to allow keywordless obj defs can lead to lots of excess nesting. Some use of the error token in parser.y might fix it, but dont' feel like dealing with it that way right now. */ #ifdef USEWITHCPP extern "C" #endif char *StaticPool; /* The static storage pool for global vars. */ #ifdef USEWITHCPP extern "C" #endif char *EnvirPool; /* The static storage pool for environment vars. */ #ifdef USEWITHCPP extern "C" #endif char *Stack; /* The runtime stack for parms and locals. */ #ifdef USEWITHCPP extern "C" #endif char **Display; /* The runtime display */ #ifdef USEWITHCPP extern "C" #endif char *tos; /* The current top of stack pointer. */ #ifdef USEWITHCPP extern "C" #endif char *ftos; /* Top of stack pointer used during parm binding. */ /* * Some handy macros for the basic types associated with values. See isInt, * etc. in type-preds.h */ #define isIntV(v) (isInt(v->tag)) #define isLIntV(v) (isLongInt(v->tag)) #define isRealV(v) (isReal(v->tag)) #define isLRealV(v) (isLongReal(v->tag)) #define isCharV(v) (isChar(v->tag)) #define isBoolV(v) (isBool(v->tag)) /* * Visible functions */ #ifdef USEWITHCPP extern "C" #endif ValueStruct interp(); #ifdef USEWITHCPP extern "C" #endif void interpStmts(nodep); #ifdef USEWITHCPP extern "C" #endif ValueStruct interpExpr(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doExprSeq(); #ifdef USEWITHCPP extern "C" #endif void doAssmnt(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doProcCall(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doCast(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doMult(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doDiv(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doMod(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doRealDiv(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doPlus(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doMinus(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doUnyPlus(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doUnyMinus(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doAnd(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doOr(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doXOr(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doImplies(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doIff(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doIfExpr(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doNot(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doEq(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doNotEq(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doLess(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doGreater(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doLessEq(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doGreaterEq(); #ifdef USEWITHCPP extern "C" #endif bool SetContains(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doIn(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doLen(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doListConstructor(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doDotDot(); #ifdef USEWITHCPP extern "C" #endif int SetNormalize(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doDesignator(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doQidRecord(); #ifdef USEWITHCPP extern "C" #endif ValueStruct lvalue(); #ifdef USEWITHCPP extern "C" #endif ValueStruct designator(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doArrayRef(); #ifdef USEWITHCPP extern "C" #endif ValueStruct doArraySliceRef(); #ifdef USEWITHCPP extern "C" #endif ValueStruct RecordRef(); #ifdef USEWITHCPP extern "C" #endif ValueStruct PointerRef(); #ifdef USEWITHCPP extern "C" #endif ValueStruct QidRef(); #ifdef USEWITHCPP extern "C" #endif struct Sym *QuickLookupQid(); #ifdef USEWITHCPP extern "C" #endif bool isGlobal(); #ifdef USEWITHCPP extern "C" #endif char *GetAddr(); #ifdef USEWITHCPP extern "C" #endif char *GetFormalAddr(); #ifdef USEWITHCPP extern "C" #endif char *StaticAddr(); #ifdef USEWITHCPP extern "C" #endif char *StackAddr(); #ifdef USEWITHCPP extern "C" #endif void PushActRec(); #ifdef USEWITHCPP extern "C" #endif char *GetTos(); #ifdef USEWITHCPP extern "C" #endif char *GetFTos(); #ifdef USEWITHCPP extern "C" #endif void SetTos(); #ifdef USEWITHCPP extern "C" #endif void SetFTos(); #ifdef USEWITHCPP extern "C" #endif ValueStruct MakeVal(); #ifdef USEWITHCPP extern "C" #endif ValTag ValueTag(); #ifdef USEWITHCPP extern "C" #endif int Integerize(); #ifdef USEWITHCPP extern "C" #endif int LIntegerize(); #ifdef USEWITHCPP extern "C" #endif void InitInterp(); #ifdef USEWITHCPP extern "C" #endif ValueStruct eval(); #ifdef USEWITHCPP extern "C" #endif void push(); #ifdef USEWITHCPP extern "C" #endif char* pop(); #ifdef USEWITHCPP extern "C" #endif char* top(); #endif