JaMTSImpl.mesa
Last edited by:
Doug Wyatt, November 21, 1983 1:57 pm
Maureen Stone January 31, 1984 5:19:30 pm PST
DIRECTORY
IO USING [STREAM, PutChar],
Commander USING [Register, CommandProc],
List USING [Assoc, CopyTopList],
Rope USING [ROPE, Cat],
JaM USING [Any, Create, Execute, ExecuteRope, LineComplete, Register, RopeToAtom, SetAbort, State, Store, Stop],
ReadEvalPrint USING [ClientProc, CreateStreamEvaluator, Handle, MainLoop],
Menus USING [MenuProc, InsertMenuEntry],
MBQueue USING [Create, CreateMenuEntry],
TypeScript USING [Create],
ViewerIO USING [CreateViewerStreams],
ViewerClasses USING [Viewer],
ViewerOps USING [AddProp, ComputeColumn],
ProcessProps USING [GetPropList],
JaMTS USING [JaMData, JaMDataRec],
Convert USING [RopeFromInt];
JaMTSImpl: CEDAR PROGRAM
IMPORTS JaM, ReadEvalPrint, Rope, Convert, Commander, List, ProcessProps, IO, Menus, MBQueue, TypeScript, ViewerIO, ViewerOps
EXPORTS JaMTS
= BEGIN
STREAM: TYPE = IO.STREAM;
ROPE: TYPE = Rope.ROPE;
DefaultPrompt: PROC[self: JaM.State] = {
JaM.ExecuteRope[self, "(*) .print"];
};
prompt: ATOM = JaM.RopeToAtom[".prompt"];
JaMPromptProc: PROC[h: ReadEvalPrint.Handle] = {
data: JaMTS.JaMData = NARROW[h.clientData];
JaM.Execute[data.state, prompt ! JaM.Stop => CONTINUE];
};
JaMClientProc: ReadEvalPrint.ClientProc = {
[h: Handle, command: Rope.ROPE] RETURNS [result: Rope.ROPE ← NIL]
data: JaMTS.JaMData = NARROW[h.clientData];
data.input ← Rope.Cat[data.input, command];
IF JaM.LineComplete[data.input] THEN {
JaM.ExecuteRope[data.state, data.input ! JaM.Stop => CONTINUE];
data.input ← NIL;
}
ELSE IO.PutChar[h.out,'*]; --indicates inside a string or array.
};
lastHandle: ReadEvalPrint.Handle ← NIL;
GetLastHandle: PUBLIC PROC RETURNS[ReadEvalPrint.Handle] = {RETURN[lastHandle]};
until we get the problems with the commandtool worked out.
SetAbort: Menus.MenuProc = {
[parent: REF, clientData: REF, mouseButton: MouseButton, shift, control: BOOL]
data: JaMTS.JaMData = NARROW[clientData];
JaM.SetAbort[data.state, TRUE];
};
CreateJaMTS: PUBLIC PROC [name: Rope.ROPE, commandLine: Rope.ROPE, searchRules: LIST OF REF ANY] RETURNS[ReadEvalPrint.Handle]= {
the new viewer will have the ReadEvalPrint.Handle as the property $ReadEvalPrint
the clientData in the ReadEvalPrint.Handle is a JaMTS.JamData
in, out: STREAM;
h: ReadEvalPrint.Handle;
state: JaM.State;
viewer: ViewerClasses.Viewer ← TypeScript.Create[
info: [name: name, iconic: FALSE, column: right], paint: FALSE];
[in: in, out: out] ← ViewerIO.CreateViewerStreams[name: NIL, viewer: viewer, editedStream: TRUE];
h ← ReadEvalPrint.CreateStreamEvaluator[clientProc: JaMClientProc, prompt: "%l%l", in: in, out: out, topLevel: TRUE];
h.viewer ← viewer;
state ← JaM.Create[h.out];
h.clientData ← NEW[JaMTS.JaMDataRec ← [state: state, input: NIL]];
h.promptProc ← JaMPromptProc;
h.menuHitQueue ← MBQueue.Create[];
Menus.InsertMenuEntry
[menu: h.viewer.menu, line: 0, entry: MBQueue.CreateMenuEntry[q: h.menuHitQueue,
name: "ABORT!", proc: SetAbort, clientData: h.clientData]];
ViewerOps.ComputeColumn[column: right];
ViewerOps.AddProp[h.viewer, $ReadEvalPrint, h];
JaM.Register[state, ".prompt", DefaultPrompt];
JaM.Store[self: state, key: JaM.RopeToAtom[".searchrules"],val: searchRules];
JaM.ExecuteRope[state, "(basic.jam) .run" ! JaM.Stop => CONTINUE];
JaM.ExecuteRope[state, commandLine ! JaM.Stop => CONTINUE];
ReadEvalPrint.MainLoop[h: h, forkAndDetach: TRUE, properties: ProcessProps.GetPropList[]];
lastHandle ← h;
RETURN[h];
};
called: INT ← 0;
NewJaMTS: Commander.CommandProc = {
name: Rope.ROPE ← "JaM";
rules: LIST OF REF ANY ← List.CopyTopList[NARROW[List.Assoc[key: $SearchRules, aList: cmd.propertyList]]];
IF called#0 THEN name ← Rope.Cat[name,Convert.RopeFromInt[from: called, showRadix: FALSE]];
result ← CreateJaMTS[name, cmd.commandLine, rules];
called ← called+1;
};
Commander.Register[key: "JaM", proc: NewJaMTS, doc: "Start JaM and its typescript"];
END.