From ce3518f362743d7a004f952358864748eecf8c0d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 1 Jan 2015 11:11:02 -0800 Subject: 478 - snapshot while debugging chessboard This took a couple of hours to track down. I had to shrink down to a 2x2 chessboard, isolate a half-move (just a square to clear) that triggered an error, then hard-code the half-move to make it non-interactive, then copy my changes over to the non-cursor version in chessboard.mu, then start debugging trace. And then I found I was using an 'index-address' rather than 'index' to go from a board to a file-address inside 'make-move'. And that was corrupting the array of file pointers. Things I wish I had to help me here: a) a type checker. b) more speed. Are lists slowing down super-linearly? need an arc profiler. c) a side channel for traces even when the program is in cursor mode. I do have that (hence the 'new-trace' before calling main), but for some reason it wasn't convenient. Just had to buckle down, I think. d) the right '#ifdef's to switch between hard-coded move and interactive move, text vs cursor mode, etc. e) just in general better curation of traces to easily see what's going on. But that's just a pipe dream. --- mu.arc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'mu.arc') diff --git a/mu.arc b/mu.arc index 1993f81e..52697ab9 100644 --- a/mu.arc +++ b/mu.arc @@ -236,6 +236,8 @@ (def run fn-names (freeze function*) (load-system-functions) +;? (write function*) +;? (quit) (= traces* (queue)) (each it fn-names (enq make-routine.it running-routines*)) @@ -368,7 +370,7 @@ (pop-stack routine*) (if empty.routine* (return ninstrs)) (when (pos '<- (body.routine* pc.routine*)) - (die "No results returned: @(body.routine* pc.routine*)")) + (die "No results returned: @(tostring:prn (body.routine* pc.routine*))")) (++ pc.routine*)) (++ curr-cycle*) (trace "run" "-- " int-canon.memory*) @@ -469,6 +471,10 @@ (withs (operand (canonize arg.0) elemtype typeinfo.operand!elem idx (m arg.1)) +;? (write arg.0) +;? (pr " => ") +;? (write operand) +;? (prn) (unless (< -1 idx array-len.operand) (die "@idx is out of bounds of array @operand")) (m `((,(+ v.operand @@ -724,10 +730,16 @@ (++ n)))) (def canonize (operand) +;? (tr "0: @operand") (ret operand +;? (prn "1: " operand) +;? (tr "1: " operand) ; todo: why does this die? (zap absolutize operand) +;? (tr "2: @(tostring write.operand)") (while (pos '(deref) metadata.operand) - (zap deref operand)))) + (zap deref operand) +;? (tr "3: @(tostring write.operand)") + ))) (def array-len (operand) (trace "array-len" operand) @@ -1545,7 +1557,7 @@ ;? (print-primitive ("arg now: " literal)) ;? (print-primitive a:string-address) ;? (print-primitive "@":literal) -;? print-primitive:a:string-address/deref ; todo: test (m on scoped array) +;? (print-primitive a:string-address/deref) ; todo: test (m on scoped array) ;? (print-primitive "\n":literal) ;? ;? (assert nil:literal) ; result-len = result-len + arg.length - 1 (for the 'underscore' being replaced) @@ -1730,6 +1742,7 @@ ;; load all provided files and start at 'main' (reset) +(new-trace "chessboard") ;? (set dump-trace*) (awhen (pos "--" argv) (map add-code:readfile (cut argv (+ it 1))) @@ -1741,6 +1754,7 @@ (run 'main) (if ($.current-charterm) ($.close-charterm)) (prn "\nmemory: " int-canon.memory*) -;? (prn completed-routines*) + (each routine completed-routines* + (aif rep.routine!error (prn "error - " it))) ) (reset) -- cgit 1.4.1-2-gfad0 a id='n34' href='#n34'>34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
='n79' href='#n79'>79