DIRECTORY Commander USING [CommandProc, Register], IO, RefText USING [AppendChar], Rope USING [FromRefText, ROPE], TJaM USING [Any, AtomFromRope, CommandProc, CvX, Def, ExecuteAtom, ExecuteRope, Exit, Frame, LineComplete, NewFrame, Number, Pop, Register, RopeFromAtom, Stop]; TJaMDriverImpl: CEDAR PROGRAM IMPORTS Commander, IO, RefText, Rope, TJaM ~ BEGIN OPEN TJaM; ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; Ref: TYPE ~ REF Rep; Rep: TYPE ~ RECORD[ frame: Frame, in, out: STREAM ฌ NIL ]; refKey: ATOM ~ $JaMInterpreter; promptKey: ATOM ~ AtomFromRope[".prompt"]; promptRope: ROPE ~ "(*) .print"; promptVal: Any ~ CvX[promptRope]; printKey: ATOM ~ AtomFromRope[".print"]; quitKey: ATOM ~ AtomFromRope[".quit"]; GetRef: SIGNAL RETURNS [Ref]; ApplyPrint: CommandProc ~ { self: Ref ~ SIGNAL GetRef[]; x: REF ~ Pop[frame]; WITH x SELECT FROM x: Number => WITH n: x SELECT FROM int => IO.Put1[self.out, IO.int[n.int]]; real => IO.Put1[self.out, IO.real[n.real]]; ENDCASE => ERROR; x: ATOM => IO.PutRope[self.out, RopeFromAtom[x]]; x: ROPE => IO.PutRope[self.out, x]; ENDCASE => IO.Put1[self.out, IO.refAny[x]]; }; Quit: ERROR ~ CODE; ApplyQuit: CommandProc ~ { ERROR Quit; }; AppendLine: PROC[text: REF TEXT, stream: STREAM] RETURNS[REF TEXT] ~ { DO char: CHAR ~ IO.GetChar[stream]; text ฌ RefText.AppendChar[text, char]; IF char='\n THEN EXIT; ENDLOOP; RETURN[text]; }; JaMInterpreterProcess: PROC[self: Ref] ~ { frame: Frame ~ self.frame; inner: PROC ~ { buffer: REF TEXT ~ NEW[TEXT[500]]; DO command: ROPE ฌ NIL; text: REF TEXT ฌ buffer; text.length ฌ 0; ExecuteAtom[frame, promptKey]; { DO text ฌ AppendLine[text, self.in]; command ฌ Rope.FromRefText[text]; IF LineComplete[command] THEN EXIT; ENDLOOP; ExecuteRope[frame: frame, rope: command ! Stop => CONTINUE; Exit => RESUME; Quit => EXIT; ]; }; ENDLOOP; }; Register[frame, AtomFromRope[".print"], ApplyPrint]; Register[frame, AtomFromRope[".quit"], ApplyQuit]; Def[frame, promptKey, promptVal]; inner[]; }; Run: Commander.CommandProc ~ { self: Ref ~ NEW[Rep ฌ [frame: NewFrame[]]]; self.in ฌ cmd.in; self.out ฌ cmd.out; JaMInterpreterProcess[self ! GetRef => RESUME [self]]; }; Commander.Register["TJaM", Run, "TJaM read-eval-print loop"]; END. ฦ TJaMDriverImpl.mesa Copyright ำ 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved. Michael Plass, December 20, 1989 3:40:16 pm PST Doug Wyatt, November 27, 1992 1:37 pm PST ส–(cedarcode) style•NewlineDelimiter ™codešœ™Kšœ ฯeœC™NK™/K™)K™—šฯk ˜ Kšœ žœ˜(Kšžœ˜Kšœžœ˜Kšœžœžœ˜Kšœžœ–˜ —K˜Kšะlnœžœž˜Kšžœ žœ˜*šœžœžœ˜K˜Kšžœžœžœ˜Kšžœžœžœžœ˜K˜Kšœžœžœ˜šœžœžœ˜Kšœ ˜ Kšœ žœž˜K˜K˜—šœžœ˜K˜—K˜Kšœ žœ˜*Kšœ žœ˜ Kšœ!˜!Kšœ žœ˜(Kšœ žœ˜&K˜šฯnœžœžœ˜K˜—š  œ˜Kšœ žœ ˜Kšœžœ˜šžœžœž˜šœ žœžœž˜"Kšœžœžœ ˜(Kšœžœžœ˜+Kšžœžœ˜—Kšœžœžœ$˜1Kšœžœžœ˜#Kšžœžœžœ ˜+—K˜K˜—Kš œžœžœ˜K˜š  œœ˜Kšžœ˜ K˜K˜—š  œžœžœžœ žœžœžœžœ˜Fšž˜Kšœžœžœ˜ K˜&Kšžœ žœžœ˜Kšžœ˜—Kšžœ˜ K˜K˜—š œžœ˜*K˜šœžœ˜Kš œžœžœžœžœ˜"šž˜Kšœ žœžœ˜Kšœžœžœ ˜K˜Kšœ˜Kšœ˜šž˜Kšœ!˜!K˜!Kšžœžœžœ˜#Kšžœ˜—šœ)˜)Kšœžœ˜Kšœžœ˜Kšœžœ˜ K˜—K˜Kšžœ˜—K˜—K˜4K˜2Kšœ!˜!Kšœ˜K˜K˜—š œ˜Kšœ žœ˜+Kšœ˜Kšœ˜Kšœ'žœ ˜6K˜K˜—K˜=K˜—Kšžœ˜—…—ฎ x