<> <> <> <> DIRECTORY AMModel USING [Context, RootContext, Section], AMEvents USING [BreakAt, DuplicateBreakpoint], AMTypes USING [TVType, TV], AMViewerOps USING [ReportProc, SectionFromSource, ViewerFromSection], BackStop USING [Call], Commander USING [CommandProc, Register], CommandTool USING [ArgumentVector, Parse], Convert USING [IntFromRope], Interpreter USING [Evaluate], InterpreterOps USING [EvalHead, WorldFromHead], InterpreterToolPrivate USING [Break, BreakObject, nextBI], IO USING [PutF1, PutRope, STREAM], List USING [Assoc, PutAssoc], PrintTV USING [Print, PrintType], ProcessProps USING [GetPropList], Rope USING [Concat, Fetch, IsEmpty, Length, ROPE, Substr], SafeStorage USING [IsCollectorActive, NWordsAllocated], SymTab USING [Create, Ref], UserProfile USING [Boolean], WorldVM USING [LocalWorld, World]; InterpreterCommandsImpl: CEDAR MONITOR IMPORTS AMEvents, AMModel, AMTypes, AMViewerOps, BackStop, Commander, CommandTool, Convert, Interpreter, InterpreterOps, InterpreterToolPrivate, IO, List, PrintTV, ProcessProps, Rope, SafeStorage, SymTab, UserProfile, WorldVM = BEGIN OPEN InterpreterToolPrivate; ROPE: TYPE = Rope.ROPE; <> EvalCommand: Commander.CommandProc = { head: InterpreterOps.EvalHead = NARROW[List.Assoc[$EvalHead, ProcessProps.GetPropList[]]]; line: ROPE _ cmd.commandLine; context: AMModel.Context; symTab: SymTab.Ref; resultTV: AMTypes.TV; errorRope: ROPE; noResult: BOOL; depth: INT _ 4; width: INT _ 32; printType: BOOL _ FALSE; collections: INT _ SafeStorage.IsCollectorActive[].previousIncarnation; words: INT _ SafeStorage.NWordsAllocated[]; inner: PROC = { IF noResult THEN RETURN; IF printType THEN { cmd.out.PutRope["***Printing Type...\n"]; PrintTV.PrintType[ put: cmd.out, type: AMTypes.TVType[resultTV], depth: depth, width: width, verbose: depth > 4 ]; } ELSE PrintTV.Print[ put: cmd.out, tv: resultTV, depth: depth, width: width, verbose: depth > 4 ]; }; <> TRUSTED{ IF head = NIL THEN context _ AMModel.RootContext[WorldVM.LocalWorld[]] ELSE { context _ head.context; IF context = NIL THEN context _ AMModel.RootContext[InterpreterOps.WorldFromHead[head]]; }; symTab _ LOOPHOLE[List.Assoc[$SymTab, cmd.propertyList]]; IF symTab = NIL THEN { symTab _ SymTab.Create[]; [] _ List.PutAssoc[key: $SymTab, val: symTab, aList: cmd.propertyList]; }; }; line _ Rope.Substr[base: line, len: line.Length[] - 1]; -- remove the CR UNTIL line.IsEmpty[] -- strip postfix !'s and ?'s DO ch: CHAR _ line.Fetch[line.Length[] - 1]; SELECT ch FROM '! => {depth _ depth + 1; width _ width + width}; '? => printType _ TRUE; ENDCASE => EXIT; line _ Rope.Substr[base: line, len: line.Length[] - 1]; ENDLOOP; line _ line.Concat["\n"]; -- replace the CR [resultTV, errorRope, noResult] _ Interpreter.Evaluate[rope: Rope.Concat["& _ ", line], context: context, symTab: symTab]; IF errorRope # NIL THEN IO.PutF1[cmd.out, "Error: %g\n", [rope[errorRope]] ] ELSE IO.PutF1[cmd.out, "%g\n", [rope[BackStop.Call[inner]]] ] }; SetBreakCommand: Commander.CommandProc = { <> out: IO.STREAM = cmd.out; world: WorldVM.World; break: Break _ NIL; argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd]; HighlightBreakPoint: PROC [break: Break] = { report: AMViewerOps.ReportProc = -- [msg: ROPE, severity: Severity] TRUSTED {out.PutRope[msg]}; inner: SAFE PROC = TRUSTED{ [] _ AMViewerOps.ViewerFromSection[break.section, report]; }; -- yekk. msg: ROPE _ BackStop.Call[inner]; IF msg # NIL THEN out.PutRope[msg]; }; inner: SAFE PROC = TRUSTED { section: AMModel.Section _ NIL; warning: REF; name: ROPE _ argv[1]; index: INT _ Convert.IntFromRope[argv[2]]; out.PutRope["Setting break..."]; [section, warning] _ AMViewerOps.SectionFromSource[world, name, index]; IF warning = NIL THEN out.PutRope["(possible source version mismatch)"]; break _ NEW[BreakObject _ [index: 0, breakID: NIL, world: world, section: section]]; break.breakID _ AMEvents.BreakAt[world, section, break ! AMEvents.DuplicateBreakpoint => {break _ NIL; CONTINUE}]; IF break # NIL THEN {break.index _ nextBI; nextBI _ nextBI + 1}; }; <> TRUSTED{world _ WorldVM.LocalWorld[]}; msg _ BackStop.Call[inner]; IF msg.Length[] = 0 AND break # NIL THEN { IO.PutF1[out, "Break #%g set.\n", [integer[break.index]] ]; HighlightBreakPoint[break: break]; RETURN; }; IF msg.Length[] # 0 THEN {break _ NIL; result _ $Failure} ELSE msg _ "a break is already set here.\n"; }; <> showStats: BOOL _ UserProfile.Boolean["ShowEvalStatistics", FALSE]; Commander.Register["_", EvalCommand, "a simple evaluation command", NIL, FALSE]; Commander.Register["eval", EvalCommand, "a simple evaluation command", NIL, FALSE]; Commander.Register["SetBreak", SetBreakCommand, "SetBreak fileName charPos"]; END.