PS.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
Doug Wyatt, August 21, 1987 1:57:15 pm PDT
DIRECTORY
Basics USING [Comparison],
FS USING [AccessOptions],
IO USING [STREAM];
PS: CEDAR DEFINITIONS
~
BEGIN
Comparison: TYPE ~ Basics.Comparison;
STREAM: TYPE ~ IO.STREAM;
Type declarations
Text: TYPE ~ REF READONLY TEXT;
MutableText:
TYPE ~
REF
TEXT;
TypeCode:
TYPE ~ {null, integer, real, boolean, array, string, name, dict, operator, file, mark, save, font};
Access:
TYPE ~ {none, executeOnly, readOnly, unlimited};
Any: TYPE ~ RECORD [val: Val, ref: REF];
Val:
TYPE ~
RECORD [
executable: BOOL,
variant:
SELECT type: TypeCode
FROM
null => [],
integer => [int: INT],
real => [real: REAL],
boolean => [bool: BOOL],
array => [access: Access, start, length: ArrayIndex], -- ref: ArrayRef
string => [access: Access, start, length: StringIndex], -- ref: StringRef
dict => [], -- ref: DictRef
file => [access: Access], -- ref: FileRef
name => [], -- ref: NameRef
operator => [], -- ref: OperatorRef
mark => [],
save => [level: Level],
font => [], -- ref: FontRef
ENDCASE
];
null: Any ~ [val: [executable: FALSE, variant: null[]], ref: NIL];
mark: Any ~ [val: [executable:
FALSE, variant: mark[]], ref:
NIL];
Array: TYPE ~ RECORD [val: Val.array, ref: ArrayRef];
ArrayRef: TYPE ~ REF ArrayRep;
ArrayRep: TYPE ~ RECORD [level: Level, elements: SEQUENCE size: ArrayIndex OF Any];
String: TYPE ~ RECORD [val: Val.string, ref: StringRef];
StringRef: TYPE ~ REF StringRep;
StringRep: TYPE ~ RECORD [level: Level, elements: SEQUENCE size: StringIndex OF CHAR];
Dict: TYPE ~ RECORD [val: Val.dict, ref: DictRef];
DictRef: TYPE ~ REF DictRep;
DictRep:
TYPE ~
RECORD [
level: Level,
access: Access,
length: DictIndex,
maxlength: DictIndex,
tuples: SEQUENCE mod: DictIndex OF Tuple
];
DictIndex: TYPE ~ NAT;
Tuple: TYPE ~ RECORD [key: Any, val: Any];
nullTuple: Tuple ~ [null, null];
File: TYPE ~ RECORD [val: Val.file, ref: FileRef];
FileRef: TYPE ~ REF FileRep;
FileRep:
TYPE ~
RECORD [stream:
STREAM];
Name: TYPE ~ RECORD [val: Val.name, ref: NameRef];
NameRef: TYPE ~ REF NameRep;
NameRep:
TYPE ~
RECORD [level: Level, string: String, hash:
CARDINAL];
Operator: TYPE ~ RECORD [val: Val.operator, ref: OperatorRef];
OperatorRef: TYPE ~ REF OperatorRep;
OperatorRep: TYPE ~ RECORD [proc: OperatorProc, text: Text];
OperatorProc:
TYPE ~
PROC [self: Root];
RestoreItem: TYPE ~ REF RestoreItemRep;
RestoreItemRep:
TYPE ~
RECORD [
next: RestoreItem,
variant:
SELECT tag: *
FROM
array => [ref, copy: ArrayRef],
string => [ref, copy: StringRef],
dict => [ref, copy: DictRef],
ENDCASE
];
OStack: TYPE ~ REF OStackRep;
OStackRep:
TYPE ~
RECORD [
SEQUENCE size: StackIndex
OF Any];
DStack: TYPE ~ REF DStackRep;
DStackRep:
TYPE ~
RECORD [
SEQUENCE size: StackIndex
OF Dict];
RestoreStack: TYPE ~ REF RestoreStackRep;
RestoreStackRep:
TYPE ~
ARRAY Level
OF RestoreItem;
Root: TYPE ~ REF RootRep;
RootRep:
TYPE ~
RECORD [
zone: ZONE,
buffer: MutableText,
ostack: OStack, -- operand stack
osize: StackIndex, -- size of ostack
ocount: StackIndex, -- current depth of ostack
dstack: DStack, -- dictionary stack
dsize: StackIndex, -- size of dstack
dcount: StackIndex, -- current depth of dstack
esize: StackIndex, -- size of "estack"
ecount: StackIndex, -- depth of "estack"
restore: RestoreStack, -- save/restore stack
level: Level, -- current save level
systemdict: Dict,
userdict: Dict,
errordict: Dict,
nameDict: Dict, -- string => name
stdin: File,
stdout: File,
stderr: File,
random: Random.RandomStream,
scratch: Scratch,
graphics: Graphics
];
Scratch: TYPE ~ REF ScratchRep;
Graphics: TYPE ~ REF GraphicsRep;
GraphicsRep: TYPE;
Errors
Error: ERROR [error: ErrorCode];
ErrorCode: TYPE ~ {dictfull, dictstackoverflow, dictstackunderflow, execstackoverflow, interrupt, invalidaccess, invalidexit, invalidfileaccess, invalidfont, invalidrestore, ioerror, limitcheck, nocurrentpoint, rangecheck, stackoverflow, stackunderflow, syntaxerror, timeout, typecheck, undefined, undefinedfilename, undefinedresult, unimplemented, unmatchedmark, unregistered, VMerror};
Bug: ERROR;
Types and attributes
Type:
PROC [x: Any]
RETURNS [TypeCode]
~ INLINE { RETURN [x.val.type] };
NameFromType: PROC [self: Root, type: TypeCode] RETURNS [Name];
XCheck:
PROC [x: Any]
RETURNS [
BOOL]
~ INLINE { RETURN [x.val.executable] };
CvLit:
PROC [x: Any]
RETURNS [Any]
~ INLINE { x.val.executable ← FALSE; RETURN[x] };
CvX:
PROC [x: Any]
RETURNS [Any]
~ INLINE { x.val.executable ← TRUE; RETURN[x] };
IntFromAny: PROC [x: Any] RETURNS [INT];
RealFromAny: PROC [x: Any] RETURNS [REAL];
BoolFromAny: PROC [x: Any] RETURNS [BOOL];
ArrayFromAny: PROC [x: Any, access: Access] RETURNS [Array];
StringFromAny: PROC [x: Any, access: Access] RETURNS [String];
DictFromAny: PROC [x: Any, access: Access] RETURNS [Dict];
FileFromAny: PROC [x: Any, access: Access] RETURNS [File];
NameFromAny: PROC [x: Any] RETURNS [Name];
OperatorFromAny: PROC [x: Any] RETURNS [Operator];
AnyFromInt: PROC [INT] RETURNS [Any];
AnyFromReal: PROC [REAL] RETURNS [Any];
AnyFromBool: PROC [BOOL] RETURNS [Any];
AnyFromArray: PROC [Array] RETURNS [Any];
AnyFromString: PROC [String] RETURNS [Any];
AnyFromDict: PROC [Dict] RETURNS [Any];
AnyFromFile: PROC [File] RETURNS [Any];
AnyFromName: PROC [Name] RETURNS [Any];
AnyFromOperator: PROC [Operator] RETURNS [Any];
Operand stack manipulation operators
PushAny: PROC [self: Root, x: Any];
PushInt: PROC [self: Root, int: INT];
PushReal: PROC [self: Root, real: REAL];
PushBool: PROC [self: Root, bool: BOOL];
PushArray: PROC [self: Root, array: Array];
PushString: PROC [self: Root, string: String];
PushDict: PROC [self: Root, dict: Dict];
PushFile: PROC [self: Root, file: File];
PushName: PROC [self: Root, name: Name];
PushLevel: PROC [self: Root, level: Level];
PopAny: PROC [self: Root] RETURNS [Any];
PopInt: PROC [self: Root] RETURNS [INT];
PopReal: PROC [self: Root] RETURNS [REAL];
PopBool: PROC [self: Root] RETURNS [BOOL];
PopArray: PROC [self: Root, access: Access] RETURNS [Array];
PopString: PROC [self: Root, access: Access] RETURNS [String];
PopDict: PROC [self: Root, access: Access] RETURNS [Dict];
PopFile: PROC [self: Root, access: Access] RETURNS [File];
PopName: PROC [self: Root] RETURNS [Name];
PopOperator: PROC [self: Root] RETURNS [Operator];
PopLevel: PROC [self: Root] RETURNS [Level];
PopProc: PROC [self: Root] RETURNS [Any];
PushMark: PROC [self: Root];
PopMark: PROC [self: Root];
Copy: PROC [self: Root, n: INT];
Roll: PROC [self: Root, n, j: INT];
Index: PROC [self: Root, n: INT] RETURNS [Any];
Clear: PROC [self: Root];
Count: PROC [self: Root] RETURNS [StackIndex] ~ INLINE { RETURN [self.ocount] };
ClearToMark: PROC [self: Root];
CountToMark: PROC [self: Root] RETURNS [StackIndex];
TypeIndex: PROC [self: Root, n: StackIndex] RETURNS [TypeCode];
Arithmetic and math operators
Ceiling: PROC [real: REAL] RETURNS [REAL];
Floor: PROC [real: REAL] RETURNS [REAL];
Round: PROC [real: REAL] RETURNS [REAL];
Truncate: PROC [real: REAL] RETURNS [REAL];
Rand: PROC [self: Root] RETURNS [INT];
SRand: PROC [self: Root, seed: INT];
RRand: PROC [self: Root] RETURNS [INT];
Array operators
ArrayCreate: PROC [self: Root, size: INT] RETURNS [Array];
ArrayAccess:
PROC [array: Array]
RETURNS [Access]
~ INLINE { RETURN [array.val.access] };
ArraySetAccess:
PROC [array: Array, access: Access]
RETURNS [Array]
~ INLINE { array.val.access ← access; RETURN [array] };
ArrayLength:
PROC [array: Array]
RETURNS [ArrayIndex]
~ INLINE { RETURN [array.val.length] };
ArrayGet: PROC [array: Array, index: INT] RETURNS [Any];
ArrayPut: PROC [self: Root, array: Array, index: INT, x: Any];
ArrayGetInterval: PROC [array: Array, index, count: INT] RETURNS [Array];
ArrayPutInterval: PROC [self: Root, array: Array, index: INT, interval: Array];
ArrayCopy: PROC [self: Root, array: Array, from: Array] RETURNS [Array];
ArrayForAll: PROC [array: Array, action: PROC [Any]];
ALoad: PROC [self: Root, array: Array];
AStore: PROC [self: Root, array: Array];
String operators
StringCreate: PROC [self: Root, size: INT] RETURNS [String];
StringCreateFromText: PROC [self: Root, text: Text] RETURNS [String];
StringAccess:
PROC [string: String]
RETURNS [Access]
~ INLINE { RETURN [string.val.access] };
StringSetAccess:
PROC [string: String, access: Access]
RETURNS [String]
~ INLINE { string.val.access ← access; RETURN [string] };
StringLength:
PROC [string: String]
RETURNS [StringIndex]
~ INLINE { RETURN [string.val.length] };
StringGet: PROC [string: String, index: INT] RETURNS [CHAR];
StringPut: PROC [self: Root, string: String, index: INT, x: CHAR];
StringGetInterval: PROC [string: String, index, count: INT] RETURNS [String];
StringPutInterval: PROC [self: Root, string: String, index: INT, interval: String];
StringCopy: PROC [self: Root, string: String, from: String] RETURNS [String];
StringForAll: PROC [string: String, action: PROC [CHAR]];
Search: PROC [string, seek: String, anchor: BOOL] RETURNS [found: BOOL, index: INT];
StringEq: PROC [string1, string2: String] RETURNS [BOOL];
StringCompare: PROC [string1, string2: String] RETURNS [Comparison];
StringToken: PROC [self: Root, string: String]
RETURNS [found: BOOL, token: Any, post: String];
Dictionary operators
DictCreate: PROC [self: Root, size: INT] RETURNS [Dict];
DictAccess:
PROC [dict: Dict]
RETURNS [Access]
~ INLINE { RETURN [dict.ref.access] };
DictSetAccess:
PROC [self: Root, dict: Dict, access: Access]
RETURNS [Dict]
~ INLINE { dict.ref.access ← access; RETURN [dict] };
DictLength:
PROC [dict: Dict]
RETURNS [DictIndex]
~ INLINE { RETURN [dict.ref.length] };
DictMaxLength:
PROC [dict: Dict]
RETURNS [DictIndex]
~ INLINE { RETURN [dict.ref.maxlength] };
DictGet: PROC [dict: Dict, key: Any] RETURNS [Any];
DictGetText: PROC [dict: Dict, text: Text] RETURNS [Any];
DictPut: PROC [self: Root, dict: Dict, key: Any, val: Any, name: BOOL ← FALSE];
Known: PROC [dict: Dict, key: Any] RETURNS [BOOL];
DictCopy: PROC [self: Root, dict: Dict, from: Dict] RETURNS [Dict];
DictForAll: PROC [dict: Dict, action: PROC [Any, Any]];
Begin: PROC [self: Root, dict: Dict];
End: PROC [self: Root];
Def: PROC [self: Root, key: Any, val: Any];
Load: PROC [self: Root, key: Any] RETURNS [Any];
Store: PROC [self: Root, key: Any, val: Any];
Where: PROC [self: Root, key: Any] RETURNS [found: BOOL, where: Dict];
CurrentDict: PROC [self: Root] RETURNS [Dict];
CountDictStack: PROC [self: Root] RETURNS [StackIndex];
DictStack: PROC [self: Root, array: Array] RETURNS [Array];
Relational operators
Eq: PROC [x1, x2: Any] RETURNS [BOOL];
EqText: PROC [x: Any, text: Text] RETURNS [BOOL];
Compare: PROC [x1, x2: Any] RETURNS [Comparison];
File operators
FileAccessMode: TYPE ~ FS.AccessOptions;
FileCreate: PROC [self: Root, string: String, accessMode: FileAccessMode] RETURNS [File];
FileFromStream: PROC [self: Root, stream: STREAM] RETURNS [File];
FileAccess:
PROC [file: File]
RETURNS [Access]
~ INLINE { RETURN [file.val.access] };
FileSetAccess:
PROC [file: File, access: Access]
RETURNS [File]
~ INLINE { file.val.access ← access; RETURN [file] };
Read: PROC [file: File] RETURNS [CHAR];
EndOfFile: ERROR;
Write: PROC [file: File, char: CHAR];
ReadHexString: PROC [self: Root, file: File, string: String] RETURNS [String, BOOL];
WriteHexString: PROC [file: File, string: String];
ReadString: PROC [self: Root, file: File, string: String] RETURNS [String, BOOL];
WriteString: PROC [file: File, string: String];
ReadLine: PROC [self: Root, file: File, string: String] RETURNS [String, BOOL];
BytesAvailable: PROC [file: File] RETURNS [INT];
FlushFile: PROC [file: File];
ResetFile: PROC [file: File];
CloseFile: PROC [file: File];
Status: PROC [file: File] RETURNS [BOOL];
FileToken: PROC [self: Root, file: File] RETURNS [found: BOOL, token: Any];
Echo: PROC [self: Root, echo: BOOL];
Name operators
NameLength: PROC [name: Name] RETURNS [INT];
NameFromText: PROC [self: Root, text: Text] RETURNS [Name];
NameFromString: PROC [self: Root, string: String] RETURNS [Name];
Conversion operators
IntFromChar: PROC [char: CHAR] RETURNS [INT] ~ INLINE { RETURN [ORD[char]] };
CharFromInt: PROC [int: INT] RETURNS [CHAR];
RealFromInt: PROC [int: INT] RETURNS [REAL] ~ INLINE { RETURN [REAL[int]] };
IntFromReal: PROC [real: REAL] RETURNS [INT];
IntFromString: PROC [String] RETURNS [INT];
RealFromString: PROC [String] RETURNS [REAL];
StringFromInt: PROC [self: Root, string: String, int: INT, radix: INT ← 10] RETURNS [String];
StringFromReal: PROC [self: Root, string: String, real: REAL] RETURNS [String];
StringFromName: PROC [self: Root, string: String, name: Name] RETURNS [String];
StringFromOperator: PROC [self: Root, string: String, operator: Operator] RETURNS [String];
StringFromText: PROC [self: Root, string: String, text: Text,
start: NAT ← 0, len: NAT ← NAT.LAST] RETURNS [String];
Virtual memory operators
Save: PROC [self: Root] RETURNS [Level];
Restore: PROC [self: Root, level: Level];
Execution
Execute: PROC [self: Root, x: Any, directly: BOOL ← FALSE];
CurrentFile: SIGNAL RETURNS [File];
Exit: SIGNAL;
Stop: ERROR;
Quit: ERROR;
Initialization
Register: PROC [self: Root, text: Text, val: Any];
RegisterOperator: PROC [self: Root, text: Text, proc: OperatorProc];
NoteInitialization: PROC [PROC [Root]];
END.