GPM.Mesa
last written by Paxton June 21, 1982 10:54 am
originating from Strachey's General Purpose Macrogenerator
as described in Computer Journal, Oct. 1965. pp. 225-241
written in Mesa by Bill Paxton, November 1981
Last Edited by: Maxwell, December 17, 1982 9:51 am
DIRECTORY
Rope USING [ROPE],
IO USING [Handle];
GPM: CEDAR DEFINITIONS = BEGIN
Handle: TYPE = REF Object;
Object:
TYPE =
RECORD [
stream: IO.Handle,
st: REF Stack,
outputChar: CHARACTER ← 0C,
startCall: CHARACTER ← '&,
endCall: CHARACTER ← ';,
singleQuote: CHARACTER ← '', -- treat next char as if surrounded by startQuote, endQuote
startQuote: CHARACTER ← '<,
endQuote: CHARACTER ← '>,
sepArg: CHARACTER ← ',,
numArg: CHARACTER ← '~,
output: REF TEXT,
outputPtr: NAT ← 0,
s: Index, -- next available cell in the stack
e: Index, -- chain of name-value pairs for current definitions
h: Index,
-- index of length cell for incomplete string on top of stack
h=0 means destination is output stream rather than stack
p: Index, -- start of chain of calls entered but not yet completed
f: Index,
-- start of chain of calls started but not yet entered
i.e., have seen the & but not the matching ;
c: Index,
-- index of next character to be scanned
c=0 means source is input stream rather than stack
a: CHARACTER, -- temp for use by NextCh and Load
w: Index, -- temp for use with Find
q: NAT -- level of nesting inside <'s
];
Stack: TYPE = RECORD [entries: SEQUENCE length:NAT OF Entry];
Index: TYPE = [0..maxIndex] ← 0;
maxIndex: NAT = LAST[NAT];
Entry: TYPE = RECORD [ data: INTEGER ];
data: SELECT kind:* FROM
index => [ index: Index ],
length => [ length: Index ],
char => [ char: CHARACTER ],
builtin => [ name: BuiltIn ],
ENDCASE];
BuiltIn: TYPE = [1..3];
DEF: BuiltIn = 1;
VAL: BuiltIn = 2;
UPDATE: BuiltIn = 3;
Open: PROC [stream: IO.Handle] RETURNS [Handle];
Close: PROC [self: Handle];
GetChar: PROC [self: Handle] RETURNS [char: CHARACTER];
GetIndex: PROC [self: Handle] RETURNS [i: LONG INTEGER];
Error: ERROR [ec: ErrorCode, errorMsg: Rope.ROPE];
ErrorCode: TYPE = { MacroError, EndOfStream };
DumpToStream: PROC [output: IO.Handle, input: Handle];
END.