MODULEPack them together in reverse order.; IMPORT Atom, AtomList, IO, Process, ThreadF, Fmt; REVEAL T = Public BRANDED "Debug.T" OBJECT tags: AtomList.T := NIL; p: INTEGER := 0; name: TEXT := ""; OVERRIDES init := Init; print := Print; push := Push; pop := Pop; getList := GetList; getText := GetText; crash := CrashT; END; PROCEDURE Debug Init (self: T; name: TEXT; p: INTEGER): T = BEGIN self.p := p; self.name := name; RETURN self; END Init; PROCEDUREPush (self: T; p: INTEGER; tag: Atom.T) = BEGIN self.tags := AtomList.Cons(tag, self.tags); IF p < self.p THEN IO.Put(self.name & ": " & Atom.ToText(tag) & " begin\n"); END; END Push; PROCEDUREPop (self: T; p: INTEGER) = BEGIN IF self.tags # NIL THEN IF p < self.p THEN IO.Put(self.name & ": " & Atom.ToText(self.tags.head) & " end\n"); END; self.tags := self.tags.tail; END; END Pop; PROCEDUREGetList (self: T): AtomList.T = BEGIN RETURN AtomList.Reverse(self.tags); END GetList;
PROCEDUREGetText (self: T): TEXT = VAR ret: TEXT; al: AtomList.T := self.tags; BEGIN IF al # NIL THEN ret := Atom.ToText(al.head); al := al.tail; ELSE ret := ""; END; WHILE al # NIL DO ret := Atom.ToText(al.head) & " " & ret; al := al.tail; END; RETURN ret; END GetText; PROCEDURECrashT (self: T; t: TEXT; al: AtomList.T) = BEGIN Crash(t & ": " & AtomListToText(self.tags), al); END CrashT; PROCEDUREPrintAtomList (t: TEXT; al: AtomList.T) = BEGIN IO.Put(t & ": " & AtomListToText(al) & "\n"); END PrintAtomList; PROCEDURECrash (t: TEXT; al: AtomList.T) = BEGIN Process.Crash(t & ": " & AtomListToText(al)); END Crash; PROCEDUREAtomListToText (al: AtomList.T) : TEXT = VAR ret: TEXT; BEGIN IF al # NIL THEN ret := Atom.ToText(al.head); al := al.tail; ELSE ret := ""; END; WHILE al # NIL DO ret := ret & ", " & Atom.ToText(al.head); al := al.tail; END; RETURN ret; END AtomListToText; BEGIN END Debug.