ASObjects.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Arnon, November 23, 1987 10:16:14 am PST
DIRECTORY
SafeStorage,
IO,
Atom,
Rope,
Basics,
Imager,
MathExpr;
ASObjects: CEDAR DEFINITIONS
= BEGIN
Types From Imported Interfaces
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
EXPR: TYPE = MathExpr.EXPR;
Object Types
ObjectFlavor: TYPE = {StructureElement, Structure, Class, NoFlavor};
Object: TYPE = REF ObjectRec;
ObjectRec: TYPE ~
RECORD [
primaryKey: ROPE, -- key for search of a LoganBerry DB
openDB: LoganBerry.OpenDB, -- which DB
SELECT type:* FROM
onLine => [
name: Rope.ROPENIL, -- Structure => nonNIL (needed in addition to primaryKey field?)
flavor: ObjectFlavor, -- 3/87 unclear this field needed; even if so, could bundle it into name field; all in all, redundant (no - used for Structure, StructureElement distinctions in superclass searches)
class: Object ← NIL, -- StructureElement => Structure; Structure => Class; Class => Class (the superclass)
data: REFNIL -- StructureElement => value; Structure => instanceData; Class => Method Dictionary
];
offLine => [];
ENDCASE
];
Method (and Property) Dictionary Types
Properties are thought of as Methods of type Value
MethodDictionary: TYPE = Atom.PropList;
MethodType: TYPE = {Value, SideEffect, TrueNullaryOp, NullaryOp, UnaryOp, BinaryOp, BinaryMixedOp, TernaryOp, TernaryMixedOp, QuaternaryOp, NaryOp, LegalFirstCharOp, ReadOp, FromRopeOp, ToRopeOp, ToExprOp, FromExprOp, FromBOOLOp, FromINTOp, UnaryPredicate, BinaryPredicate, CompareToZeroOp, BinaryCompareOp, StructuredToGroundOp, ElementRankOp, UnaryImbedOp, BinaryImbedOp, ListImbedOp, MatrixImbedOp, StructureFromSetConstructor, VectorStructureConstructor, SequenceStructureConstructor, MatrixStructureConstructor, PolynomialStructureConstructor};
Method: TYPE = REF MethodRec;
MethodRec: TYPE = RECORD [
type: MethodType,
operator: BOOLTRUE, -- TRUE if this method is an Operator, as opposed to a Constructor. Only Operators are offered in a user menu of a Structure's methods
value: REF, -- REF proc if type # Value; should never be NIL, since confuses with absence of method. If don't care about Value, set value ← methodKey
desiredArgStructures: REF UnaryToListOp ← NIL, -- Proc[Structure -> LIST OF Structure]; if ouptut LIST contains only one Structure, then expected that all args belong to it (useful e.g. for vector and matrix constructors).
doc: ROPE
];
Method Operations
MakeMethod: PROC [type: MethodType, operator: BOOL, value: REF, desiredArgStructures: REF UnaryToListOp, doc: ROPE] RETURNS[Method];
DesiredArgStructures: PROC [methodSelector: ATOM, structure: Object] RETURNS[LIST OF Object];
Does method lookup
DefaultDesiredArgStructures: UnaryToListOp;
RETURN[ LIST[structure] ]; (arg is expected to be a Structure)
GetMethodAndRecastArgs: PROC [methodSelector: ATOM, structure: Object, inArgs: LIST OF Object] RETURNS [ok: BOOL, method: Method, outArgs: LIST OF Object ← NIL];
Lookup method in structure, and recast args
RecastArgs: PROC [method: Method, structure: Object, inArgs: LIST OF Object] RETURNS [ok: BOOL, outArgs: LIST OF Object ← NIL];
Try to recast args
ApplyLegalFirstCharMethod: PROC [method: Method, char: CHAR, structure: Object ← NIL] RETURNS[BOOL];
ApplyFromRopeMethod: PROC [method: Method, in: ROPE, structure: Object ← NIL] RETURNS[Object];
ApplyReadMethod: PROC [method: Method, in: STREAM, structure: Object ← NIL] RETURNS[Object];
ApplyFromExprMethod: PROC [method: Method, in: EXPR, structure: Object] RETURNS[Object];
ApplyCompareToZeroMethod: PROC [method: Method, arg: Object] RETURNS[Basics.Comparison];
ApplyBinaryCompareMethod: PROC [method: Method, firstArg, secondArg: Object] RETURNS[Basics.Comparison];
ApplyBinaryImbedMethod: PROC [method: Method, data1: Object, data2: REF, structure: Object] RETURNS[Object];
ApplyMixedMethod: PROC [method: Method, objectArgs: LIST OF Object, refArg: REF] RETURNS[Object];
ApplyPredNoLkpNoRecast: PROC [method: Method, argList: LIST OF Object] RETURNS[BOOL];
ApplyPredNoLkpRecast: PROC [method: Method, structure: Object, argList: LIST OF Object] RETURNS[BOOL];
ApplyPredLkpNoRecast: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[BOOL];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
ApplyPredLkpRecast: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[BOOL];
ApplyNoLkpNoRecastRef: PROC [method: Method, argList: LIST OF Object] RETURNS[value: REF];
Apply method from structure. It is assumed that method exists, and that correct number and types of args are supplied.
ApplyNoLkpRecastRef: PROC [method: Method, structure: Object, argList: LIST OF Object] RETURNS[value: REF];
ApplyLkpNoRecastRef: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: REF];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
ApplyLkpRecastRef: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: REF];
ApplyNoLkpNoRecastRef[GetMethodAndRecastArgs]; It is assumed that method exists, that correct number of args are supplied, and that args are recastable to desiredArgStructure. Error if anything at all goes wrong.
ApplyNoLkpNoRecastObject: PROC [method: Method, argList: LIST OF Object] RETURNS[value: Object];
ERROR if method output type is not imbeddable as an Object
ApplyNoLkpRecastObject: PROC [method: Method, structure: Object, argList: LIST OF Object] RETURNS[value: Object];
ApplyLkpNoRecastObject: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: Object];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
ApplyLkpRecastObject: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: Object];
ApplyNoLkpNoRecastObject[GetMethodAndRecastArgs]; It is assumed that method exists, that correct number of args are supplied, and that args are recastable to desiredArgStructure. Error if anything at all goes wrong.
ApplyNoLkpNoRecastExpr: PROC [method: Method, argList: LIST OF Object] RETURNS[value: EXPR];
RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
ApplyNoLkpRecastExpr: PROC [method: Method, structure: Object, argList: LIST OF Object] RETURNS[value: EXPR];
ApplyLkpRecastExpr: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: EXPR];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
ApplyLkpNoRecastExpr: PROC [methodSelector: ATOM, structure: Object, argList: LIST OF Object] RETURNS[value: EXPR];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
Object Operation Types
SideEffect: TYPE = PROC [] RETURNS [];
TrueNullaryOp: TYPE = PROC [] RETURNS [result: Object];
UnaryOp: TYPE = PROC [arg: Object] RETURNS [result: Object];
UnaryPredicate: TYPE = PROC [arg: Object] RETURNS [BOOL];
UnaryInPlaceOp: TYPE = PROC [arg: Object];
UnaryToListOp: TYPE = PROC [arg: Object] RETURNS [result: LIST OF Object];
BinaryOp: TYPE = PROC [firstArg, secondArg: Object] RETURNS [result: Object];
BinaryPredicate: TYPE = PROC [firstArg, secondArg: Object] RETURNS [BOOL];
EqualityOp: TYPE = PROC [firstArg, secondArg: Object] RETURNS [BOOL]; -- redundant
BinaryInPlaceOp: TYPE = PROC [firstArg: Object, secondArg: REF];
BinaryMixedOp: TYPE = PROC [firstArg: Object, secondArg: REF] RETURNS [result: Object];
BinaryToPairOp: TYPE = PROC [firstArg: Object, secondArg: REF] RETURNS [firstResult, secondResult: Object];
TernaryOp: TYPE = PROC [firstArg, secondArg, thirdArg: Object] RETURNS [result: Object];
TernaryMixedOp: TYPE = PROC [firstArg, secondArg: Object, thirdArg: REF] RETURNS [result: Object];
QuaternaryOp: TYPE = PROC [firstArg, secondArg, thirdArg, fourthArg: Object] RETURNS [result: Object];
NaryOp: TYPE = PROC [args: LIST OF Object] RETURNS [result: Object];
Class Operations
MakeClass: PROC [name: Rope.ROPE, superClass: Object, methodDictionary: MethodDictionary ← NIL] RETURNS[class: Object];
Typically a class is created with MethodDictionary = NIL, then MethodDictionary loaded with AddMethodToClass
AddMethodToClass: PROC [methodSelector: ATOM, method: Method, class: Object];
Existing method, if any (generally there shouldn't be), is replaced
SetSuperClass: PROC [object: Object, superClass: Object];
Sets class field of a Class, or class.class field of a Structure
LookupMethodInClass: PROC [methodSelector: ATOM, class: Object] RETURNS[method: Method];
Look up method in this class and its superclasses.
BuildClassOperators: PROC [class: Object] RETURNS[opNames: LIST OF ROPE, operators: LIST OF Method];
END.