JaMExtrasImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Last Edited by: Rick Beach, January 3, 1985 8:13:40 pm PST
Stone, February 14, 1985 7:28:12 pm PST
DIRECTORY
IO USING [Close, GetChar, GetBool, GetInt, GetReal, GetCedarTokenRope, GetTokenRope, GetLineRope, Error, EndOf, EndOfStream, STREAM],
JaM USING [PushBool, PushInt, PushReal, PushRope, State, PopBool, PopStream, PopRope],
Process USING [priorityBackground, priorityNormal, SetPriority],
JaMExtras,
Rope USING [Concat, FromChar, ROPE];
JaMExtrasImpl: CEDAR PROGRAM
IMPORTS IO, JaM, Process, Rope
EXPORTS JaMExtras
~ BEGIN
STREAM: TYPE ~ IO.STREAM;
ROPE: TYPE ~ Rope.ROPE;
ApplyConcat: PUBLIC PROC[self: JaM.State] = {
b: ROPE = JaM.PopRope[self];
a: ROPE = JaM.PopRope[self];
JaM.PushRope[self, Rope.Concat[a, b]];
};
ApplyIOChar: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushRope[self, Rope.FromChar[stream.GetChar[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}]]]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOBool: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushBool[self, stream.GetBool[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}]]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOInt: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushInt[self, stream.GetInt[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}]]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOReal: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushReal[self, stream.GetReal[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}]]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOLine: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushRope[self, stream.GetLineRope[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}]]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOToken: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushRope[self, stream.GetTokenRope[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}].token]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOCedarToken: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
ok: BOOLEANNOT stream.EndOf[];
IF ok THEN JaM.PushRope[self, stream.GetCedarTokenRope[ ! IO.EndOfStream, IO.Error => {ok ← FALSE; CONTINUE}].token]
ELSE stream.Close[];
JaM.PushBool[self, ok];
};
ApplyIOClose: PUBLIC PROC[self: JaM.State] = {
stream: STREAM = JaM.PopStream[self];
stream.Close[];
};
ApplyNicePriority: PUBLIC PROC[self: JaM.State] = {
nice: BOOLEAN = JaM.PopBool[self];
Process.SetPriority[IF nice THEN Process.priorityBackground ELSE Process.priorityNormal];
};
END.