From dc3803320013059ad400853e3f6a2851f7f82c04 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 24 Feb 2015 00:35:56 -0800 Subject: 831 - wire up trace browser to interactive repl --- mu.arc | 37 ++++++++++++++++++++++++++++++++++--- trace.mu | 49 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/mu.arc b/mu.arc index a50573ca..9676112a 100644 --- a/mu.arc +++ b/mu.arc @@ -867,6 +867,18 @@ ;? (prn x) ;? 1 ;? (new-string:repr:eval x)) ;? 1 + $clear-trace + (do1 nil (wipe interactive-traces*)) + $save-trace +;? (let x (string:map [string:intersperse ": " _] +;? (as cons (interactive-traces* (m arg.0)))) + (let x (string:map [string:intersperse ": " _] + (apply join + (map [as cons _] rev.interactive-traces*))) +;? (write x)(write #\newline) ;? 1 +;? (prn x) ;? 1 + (new-string x)) + ; first-class continuations current-continuation (w/uniq continuation-name @@ -3067,11 +3079,30 @@ (add-next-space-generator function*!interactive 'interactive) (= location*!interactive (assign-names-to-location function*!interactive 'interactive location*!interactive)) (replace-names-with-location function*!interactive 'interactive) + (= traces* (queue)) ; skip preprocessing (run-more 'interactive)) + (when (no cdr.argv) + (add-code:readfile "trace.mu") + (freeze function*) + (load-system-functions) + (wipe interactive-commands*) + (wipe interactive-traces*) + (= interactive-cmdidx* 0) + (= traces* (queue)) +;? (set dump-trace*) ;? 2 ; interactive mode - (whilet expr (do (pr "mu> ") (read)) - (run-interactive expr))) - + (point break + (while t + (pr interactive-cmdidx*)(pr "> ") + (let expr (read) + (unless expr (break)) + (push expr interactive-commands*) + (run-interactive expr)) + (push traces* interactive-traces*) + (++ interactive-cmdidx*) + ))) + +(if ($.current-charterm) ($.close-charterm)) (reset) ;? (print-times) diff --git a/trace.mu b/trace.mu index b2013953..d0302354 100644 --- a/trace.mu +++ b/trace.mu @@ -504,6 +504,39 @@ (reply nil:literal) ]) +(function browse-trace [ + (default-space:space-address <- new space:literal 30:literal/capacity) + (x:string-address <- next-input) +;? ($start-tracing) ;? 1 +;? (x:string-address <- new +;? "schedule: main +;? run: main 0: (((1 integer)) <- ((copy)) ((1 literal))) +;? run: main 0: 1 => ((1 integer)) +;? mem: ((1 integer)): 1 <= 1 +;? run: main 1: (((2 integer)) <- ((copy)) ((3 literal))) +;? run: main 1: 3 => ((2 integer)) +;? mem: ((2 integer)): 2 <= 3 +;? run: main 2: (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) +;? mem: ((1 integer)) => 1 +;? mem: ((2 integer)) => 3 +;? run: main 2: 4 => ((3 integer)) +;? mem: ((3 integer)): 3 <= 4 +;? schedule: done with routine") + (s:stream-address <- init-stream x:string-address) + (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) + (0:space-address/names:screen-state <- screen-state traces:instruction-trace-address-array-address) + (cursor-mode) + (print-traces-collapsed 0:space-address/screen-state nil:literal/terminal) + { begin + (quit?:boolean <- process-key 0:space-address/screen-state nil:literal/keyboard nil:literal/terminal) + (break-if quit?:boolean) + (loop) + } + ; move cursor to bottom before exiting + (to-bottom 0:space-address/screen-state nil:literal/terminal) + (retro-mode) +]) + (function main [ (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new @@ -520,19 +553,5 @@ mem: ((2 integer)) => 3 run: main 2: 4 => ((3 integer)) mem: ((3 integer)): 3 <= 4 schedule: done with routine") - (s:stream-address <- init-stream x:string-address) - (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) - (0:space-address/names:screen-state <- screen-state traces:instruction-trace-address-array-address) -;? ($print (("#traces: " literal))) ;? 1 -;? ($print len:integer) ;? 1 -;? ($print (("\n" literal))) ;? 1 - (cursor-mode) - (print-traces-collapsed 0:space-address/screen-state nil:literal/terminal) - { begin - (quit?:boolean <- process-key 0:space-address/screen-state nil:literal/keyboard nil:literal/terminal) - (break-if quit?:boolean) - (loop) - } - ; move cursor to bottom before exiting - (to-bottom 0:space-address/screen-state nil:literal/terminal) + (browse-trace x:string-address) ]) -- cgit 1.4.1-2-gfad0