DIRECTORY Commander, EditedStream, IO, List, Menus, Misp, Process, ProcessProps, Rope, ViewerClasses, ViewerIO; MispAlone: CEDAR PROGRAM IMPORTS Commander, EditedStream, IO, List, Menus, Misp, Process, ProcessProps, --ReadEvalPrint,-- Rope, ViewerIO = BEGIN InterpreterData: TYPE = REF InterpreterDataRep; InterpreterDataRep: TYPE = RECORD [ process: UNSAFE PROCESS, stop: REF BOOL]; ReadEvalPrint: PROC [from, to: IO.STREAM, env: Misp.Environment, cwd: Rope.ROPE, stopRef: REF BOOL] = BEGIN InnerReadEvalPrint: PROC = { raw, cooked: REF ANY _ NIL; Flush: PROC = { to.PutRope[" ... flushing input ... "]; WHILE from.CharsAvail[] > 0 DO [] _ from.GetChar[] ENDLOOP; to.PutRope[" ... done flushing\n"]; }; DO { ENABLE ABORTED => GOTO Abort; to.PutF["%lMisp>%l ", IO.rope["b"], IO.rope["B"]]; raw _ from.GetRefAny[ ! IO.EndOfStream => EXIT; IO.Error => { IF ec = $StreamClosed THEN EXIT; to.PutRope["IO Error on input"]; Flush[]; LOOP; }; EditedStream.Rubout => { to.PutRope[" -- \n"]; LOOP; }; ]; cooked _ Misp.Eval[raw, env, NIL ! Misp.Stop => { to.PutF["Stopped, at stack = %g", IO.rope[Misp.PrintValRope[stack]]]; stopRef^ _ FALSE; Flush[]; LOOP; }; Misp.Error => { to.PutF["%g\n Stack: %g\n", IO.rope[msg], IO.rope[Misp.PrintValRope[stack]]]; LOOP; }; Misp.Throw => { to.PutF["Uncaught Throw -- signal: %g, value: %g\n Stack: %g\n", IO.atom[atom], IO.rope[Misp.PrintValRope[value]], IO.rope[Misp.PrintValRope[stack]]]; LOOP; }; ]; to.PutF["%g\n", IO.rope[Misp.PrintValRope[cooked]]]; EXITS Abort => { to.PutRope[" ... aborted"]; Flush[]; }; } ENDLOOP; cwd _ cwd; }; ProcessProps.AddPropList[List.PutAssoc[$WorkingDirectory, cwd, NIL], InnerReadEvalPrint]; cwd _ cwd; END; MispCommand: Commander.CommandProc = BEGIN in, out: IO.STREAM; v: ViewerClasses.Viewer; env: Misp.Environment; cwd: Rope.ROPE _ NARROW[ProcessProps.GetProp[$WorkingDirectory]]; id: InterpreterData _ NEW [InterpreterDataRep _ [ process: NIL, stop: NEW [BOOL _ FALSE] ]]; [in, out] _ ViewerIO.CreateViewerStreams[Rope.Cat["Misp Interpreter: WD = ", cwd]]; v _ ViewerIO.GetViewerFromStream[out]; Menus.AppendMenuEntry[v.menu, Menus.CreateEntry[name: "Stop", proc: Stop, clientData: id]]; Menus.AppendMenuEntry[v.menu, Menus.CreateEntry[name: "STOP!", proc: StopHard, clientData: id]]; env _ Misp.NewEnvironment[name: "Root", in: in, out: out, sizeGuess: 200, stop: [ShouldStop, id.stop]]; Misp.DefinePrimitives[env]; TRUSTED {Process.Detach[id.process _ FORK ReadEvalPrint[in, out, env, cwd, id.stop]]}; END; ShouldStop: PROC [data: REF] RETURNS [abort: BOOL _ FALSE] --Interpreter.AbortProc-- = { stop: REF BOOL _ NARROW[data]; abort _ stop # NIL AND stop^; }; Stop: PROC [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift, control: BOOL _ FALSE] --Menus.ClickProc-- = { id: InterpreterData _ NARROW[clientData]; id.stop^ _ TRUE; }; StopHard: PROC [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift, control: BOOL _ FALSE] --Menus.ClickProc-- = { id: InterpreterData _ NARROW[clientData]; TRUSTED {Process.Abort[id.process]}; }; Commander.Register[ key: "Misp", proc: MispCommand, doc: "Opens a new viewer for interacting with the Misp interpreter"] END. RMispAlone.Mesa Last Edited by: Spreitzer, July 30, 1985 3:26:30 pm PDT Pavel, June 20, 1985 1:27:30 pm PDT ReadEvalPrint, MispCommand: Commander.CommandProc = BEGIN h: ReadEvalPrint.Handle; env: Misp.Environment; h _ ReadEvalPrint.CreateViewerEvaluator[ clientProc: EachLine, prompt: "%lMisp>%l ", info: [name: "Misp Interpreter", iconic: FALSE]]; env _ Misp.NewEnvironment[name: "Root (with IO)", in: h.in, out: h.out]; Misp.DefinePrimitives[env]; h.clientData _ env; h.readABORTEDRope _ " -- \n"; h.readIOSignalRope _ " -- \n"; h.evalABORTEDRope _ " ... Aborted\n"; h.evalUNWINDRope _ " ... Unwound\n"; TRUSTED {Process.Detach[FORK MispBase[h]]}; END; MispBase: PROC [h: ReadEvalPrint.Handle] = { DO ReadEvalPrint.MainLoop[h: h, forkAndDetach: FALSE, properties: NIL ! Misp.Error => { h.out.PutF["%g\nStack: ", IO.rope[msg]]; Misp.PrintVal[h.out, stack]; h.out.PutChar['\n]; ReadEvalPrint.Stop[h]; LOOP; } ]; EXIT; -- Normal exit from the Main Loop ENDLOOP; }; EachLine: ReadEvalPrint.ClientProc = { [h: ReadEvalPrint.Handle, command: ROPE] RETURNS [result: ROPE _ NIL] env: Misp.Environment _ NARROW[h.clientData]; input: IO.STREAM _ IO.RIS[command]; raw, cooked: REF ANY; DO raw _ input.GetRefAny[ ! IO.EndOfStream => EXIT; ]; cooked _ Misp.Eval[raw, env, NIL]; Misp.PrintVal[h.out, cooked]; h.out.PutChar['\n]; ENDLOOP; }; ΚΖ– "cedar" style˜™J™7Icode™#—J˜šΟk ˜ Kšœ ˜ K˜ Kšœ˜K˜Kšœ˜Kšœ˜Kšœ˜K˜ K™K˜Kšœ˜Kšœ ˜ —K˜šΠbx œœ˜Kšœœ,Οcœ˜r—K˜Kš˜K˜Kšœœœ˜/šœœœ˜#Kšœ œœ˜Kšœœœ˜—K˜šΟn œœ œœ#œ œœ˜eš˜š œœ˜Kšœ œœœ˜š œœ˜K˜'Kšœœœ˜;K˜#K˜—K˜šœ˜Kšœœœ˜Kšœœ œ ˜2šœ˜Kšœœ˜šœ ˜ Kšœœœ˜ K˜ Kšœ˜Kšœ˜Kšœ˜—˜K˜Kšœ˜K˜—Kšœ˜—K˜šœœ˜"˜Kšœ"œ!˜EKšœ œ˜K˜Kšœ˜K˜—šœ˜Kšœœ œ!˜NKšœ˜Kšœ˜—˜KšœBœ œ!œ!˜—Kšœ˜K˜—Kšœ˜—K˜Kšœœ"˜4š˜šœ ˜ K˜K˜Kšœ˜——Kšœœ˜ —K˜ K˜—K˜Kšœ?œ˜YK˜ —Kšœ˜—K˜šœ$˜$Kš˜Kšœ œœ˜K˜Kšœ˜Kšœ œœ*˜Ašœœ˜1Kšœ œ˜ Kšœœœœ˜Kšœ˜—KšœS˜SKšœ&˜&Kšœ[˜[Kšœ`˜`Kšœg˜gK˜K˜Kšœœ-˜VKšœ˜—K˜š  œœœœ œœŸœ˜XKšœœœœ˜Kšœœœ˜K˜—K˜š œœ œœœœœ9œœŸœ˜”Kšœœ ˜)Kšœ œ˜K˜—K˜š œœ œœœœœ9œœŸœ˜˜Kšœœ ˜)Kšœ˜$K˜—K˜š  œ™$š™Kšœ™Kšœ™K™Kšœ~œ™†K™KšœH™HK™K™K™Kšœ+™+Kšœ#™#Kšœ%™%Kšœ$™$K™Kšœœ™+—Kšœ™—K™š œœ™,š™šœ,œœ™D™Kšœœ ™(K™K™Kšœ™Kšœ™K™—K™—KšœŸ!™'Kšœ™—K™—K™•StartOfExpansionI -- [h: ReadEvalPrint.Handle, command: ROPE] RETURNS [result: ROPE _ NIL]š œ™&KšΠckE™EK™Kšœœ™-Kš œœœœœ ™#Kšœ œœ™K™š™™Kšœœ™K™—K™Kšœœ™"K™K™Kšœ™—Kšœ™—K–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]˜Kšœx˜xK˜Kšœ˜—…— žΆ