AMTypes.Mesa
last modified on July 22, 1983 2:39 pm by Paul Rovner
DIRECTORY
Rope USING[ROPE],
SafeStorage USING[Type, nullType],
WorldVM USING[World, LocalWorld];
AMTypes: CEDAR DEFINITIONS IMPORTS WorldVM
= BEGIN OPEN Rope;
T Y P E S
Type: TYPE = SafeStorage.Type;
nullType: Type = SafeStorage.nullType;
TypedVariable: TYPE = REF ANY;
TV: TYPE = TypedVariable;
Status: TYPE = {mutable, readOnly, const};
Index: TYPE = NAT; --index range for records, enumerations, etc is [1..n]
Class: TYPE = {
definition, -- e.g. TypeClass[CODE[T]] where T: TYPE = ...--
cardinal, longCardinal, integer, longInteger, real, character, --basic--
atom, rope, list, ref, pointer, longPointer, descriptor, longDescriptor, basePointer, relativePointer, --address--
procedure, signal, error, program, port, --transfer--
enumerated, subrange,
union, sequence,
record, structure,
array,
countedZone, uncountedZone,
nil, -- e.g. TypeClass[TVType[NIL]]
unspecified,
process,
type,
opaque,
any, -- e.g. TypeClass[Range[CODE[REF ANY]]]
globalFrame, localFrame --frame--
};
E R R O R S
Error: ERROR[
reason: ErrorReason,
msg: ROPENIL,
type: Type ← nullType,  -- used with TypeFault, IncompatibleTypes
otherType: Type ← nullType -- used with IncompatibleTypes
];
ErrorReason: TYPE = {
noSymbols,   -- msg has moduleName
notImplemented,  -- mostly DefaultInitialValue cases
incompatibleTypes, -- raised by Assign
rangeFault,   -- e.g. empty subrange, Apply bounds check
notMutable,   -- raised by (e.g.) Assign
internalTV,   -- raised by (e.g.) RefFromTV
badName,    -- raised by NameToIndex
badIndex,    -- raised by (e.g.) IndexToType
typeFault    -- general applicability violation
};
P R O C E D U R E S
Access to general Type characteristics.
Size: PROC[type: Type, length: CARDINAL ← 0--sequence only: number of elements--]
RETURNS[words: CARDINAL--max for unions--];
DefaultInitialValue: PROC[type: Type] RETURNS[TypedVariable];
IndexToDefaultInitialValue: PROC[type: Type--record, structure--, index: Index]
RETURNS[TypedVariable];
TypeClass: PROC[type: Type] RETURNS[Class];
UnderClass: PROC[type: Type] RETURNS[Class] =
INLINE {RETURN[TypeClass[UnderType[type]]]};
Enumerated types and records declared in interfaces are painted.
IsPainted: PROC[type: Type] RETURNS[BOOL];
Access to general TV characteristics.
TVType: PROC[tv: TypedVariable] RETURNS[Type];
TVStatus: PROC[tv: TypedVariable] RETURNS[Status];
TVSize: PROC[tv: TypedVariable] RETURNS[words: INT];
Returns a predefined, special TV that is used to indicate the "empty" value.
GetEmptyTV: PROC RETURNS[TypedVariable];
The procedures below are applicable to all but the frame types, opaque and any.
New creates and returns a cleared object. tag has meaning only for union or sequence-containing record types. See DefaultInitialValue.
New: PROC[
type: Type,
status: Status ← mutable,
world: WorldVM.World ← WorldVM.LocalWorld[],
tag: TVNIL
]
RETURNS[TypedVariable];
Copy: PROC[tv: TypedVariable] RETURNS[TypedVariable];
Assign: PROC[lhs, rhs: TypedVariable];
AssignNew: PUBLIC PROC[lhs, rhs: TypedVariable];
Two TypedVariables are Eq if assignment to one is equivalent to assignment to the other; i.e, they address the same bits. Two TypedVariables are Equal if the values have the same size and same bits. NOTE no type checking is done.
TVEq: PROC[tv1, tv2: TypedVariable] RETURNS [BOOL];
TVEqual: PROC[tv1, tv2: TypedVariable] RETURNS [BOOL];
Procedures with applicability restrictions (based on Class, noted as comments)
NComponents: PROC[type: Type--record, structure--] RETURNS[Index];
VariableType: PROC[type: Type--record, structure--]
RETURNS[v: Type, c: Class--union, sequence, or nil--];
index range is [1..NComponents[TVType[tv]]]
IndexToTV: PROC[tv: TypedVariable--record, structure--, index: Index]
RETURNS[TypedVariable];
IndexToType returns the specified component of the type. SPECIAL CASE for union types: index = 0 gets you the tag type (redundant: Tag does this too).
IndexToType: PROC[type: Type--record, structure, union--, index: Index]
RETURNS[Type];
NameToIndex:
PROC[type: Type--record, structure, union, enumerated--, name: ROPE]
RETURNS[CARDINAL];
SPECIAL CASE for union types: index = 0 gets you the tag name
IndexToName:
PROC[type: Type--record, structure, union, enumerated--, index: CARDINAL]
RETURNS[ROPE];
applicable to enumerated, transfer, program, globalFrame, atom, rope
TVToType: PROC[tv: TypedVariable--type--] RETURNS[Type];
TVToName: PROC[tv: TypedVariable] RETURNS[ans: ROPE];
Tag: PROC[tv: TypedVariable--union--] RETURNS[TypedVariable--enumerated--];
Variant: PROC[tv: TypedVariable--union--] RETURNS[TypedVariable--record--];
IsOverlaid: PROC[type: Type--union--] RETURNS[BOOL];
record, structure, union, enumerated, sequence
IsMachineDependent: PROC[type: Type] RETURNS[BOOL];
applicable to array, sequence, procedure, signal, process, address (not atom, rope)
Domain: PROC[type: Type--array, sequence, transfer, union--] RETURNS[Type];
Range: PROC[type: Type] RETURNS[Type];
IsPacked: PROC[type: Type--array, sequence--] RETURNS[BOOL];
IsComputed: PROC[type: Type--union, sequence--] RETURNS[BOOL];
Apply: PROC[mapper: TypedVariable--array, sequence--, arg: TypedVariable]
RETURNS[TypedVariable];
For a rope, Length returns an INT for the number of characters in the given rope. For a sequence, Length returns an INT specifying the (max) number of elements in the sequence. Use Tag[tv] to obtain the actual sequence tag field. Their values may differ if the tag type has a non-zero lower bound.
Length: PROC[tv: TypedVariable--sequence, rope--] RETURNS[INT];
Fetch: PROC[tv: TypedVariable--rope--, index: INT] RETURNS[CHAR];
Referent: PROC[
tv: TypedVariable--ref, list, pointer, longPointer, relativePointer--,
base: TypedVariable ← NIL--non-nil only if ref is a relativePointer. UNSAFE
]
RETURNS[TypedVariable];
ConcreteRef returns a TV for the REF <concrete referent type>. NIL -> NIL. ConcreteRef is implemented only for REFANY's that are really ATOM, LIST or ROPE guys (Error[reason: notImplemented] is raised otherwise)
ConcreteRef: PROC[tv: TypedVariable--ref any--] RETURNS[TypedVariable];
ReferentStatus: PROC[type: Type--address (not basePointer, atom)--] RETURNS[Status];
IsRefAny: PROC[type: Type--ref--] RETURNS[BOOL];
IsInterface: PROC[type: Type--record--] RETURNS[BOOL];
IsAtom: PROC[tv: TypedVariable--ref any--] RETURNS[BOOL];
IsRope: PROC[tv: TypedVariable--ref any--] RETURNS[BOOL];
IsNil: PROC[tv: TypedVariable--address--] RETURNS[BOOL];
IsOrdered: PROC[type: Type--basePointer, relativePointer--] RETURNS[BOOL];
PropertyList: PROC[tv: TypedVariable--atom--] RETURNS[TypedVariable--list, nil--];
use Coerce to Narrow or Widen
Coerce: PROC[tv: TypedVariable, targetType: Type] RETURNS[TypedVariable];
IF name exists and REFs to moduleName and/or fileName ROPEs are provided, TypeToName provides that info too.
TypeToName: PROC[
type: Type--definition--,
moduleName: REF ROPENIL,
fileName: REF ROPENIL
]
RETURNS[ROPE];
peels off one layer of definition
Ground: PROC[type: Type--definition, subrange--] RETURNS[Type];
peels off all layers of definition
GroundStar: PUBLIC PROC[type: Type--definition, subrange--] RETURNS[Type];
returns first non-definition type
UnderType: PUBLIC PROC[type: Type--definition--] RETURNS[Type];
InRange: PROC[type: Type--subrange--, groundTV: TypedVariable] RETURNS[BOOL];
First: PROC[type: Type--enumerated, subrange, basic--] RETURNS[TypedVariable];
Last: PROC[type: Type--enumerated, subrange, basic--] RETURNS[TypedVariable];
returns NIL if no next
Next: PROC[tv: TypedVariable--enumerated, subrange, basic--] RETURNS[TypedVariable];
NValues: PROC[type: Type--enumerated--] RETURNS[INT];
index range is [1..NValues[type]]
Value: PROC[type: Type--enumerated--, index: CARDINAL] RETURNS[TypedVariable];
may return NIL
StaticParent: PROC[tv: TypedVariable--procedure--]
RETURNS[TypedVariable--procedure--];
Access to local and global frames
may return NIL
Locals: PROC[tv: TypedVariable--localFrame--]
RETURNS[TypedVariable--record--];
may return NIL
EnclosingBody: PROC[tv: TypedVariable--localFrame--]
RETURNS[TypedVariable--localFrame--];
Argument: PROC[tv: TypedVariable--local or catch frame--, index: Index]
RETURNS[TypedVariable];
Result: PROC[tv: TypedVariable--local or catch frame--, index: Index]
RETURNS[TypedVariable];
Procedure: PROC[tv: TypedVariable--localFrame--]
RETURNS[TypedVariable--procedure--];
Signal: PROC[tv: TypedVariable--catch frame--]
RETURNS[TypedVariable--signal descriptor--];
DynamicParent: PROC[tv: TypedVariable--localFrame--]
RETURNS[TypedVariable--localFrame--];
GlobalParent: PROC[tv: TypedVariable--transfer or local frame--]
RETURNS[TypedVariable--globalFrame--];
Globals: PROC[tv: TypedVariable--globalFrame--] RETURNS[TypedVariable--record--];
END.