about summary refs log tree commit diff stats
path: root/chessboard-cursor.arc.t.1
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-21 01:23:57 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-21 01:58:02 -0800
commitfab56ebcecbf04db315c7f6f0ab642ef48ee48dd (patch)
tree1e50414be92114b0b4ed774a9cf038bf5a2bf836 /chessboard-cursor.arc.t.1
parent4d1f6bd73041c11a58287816a6b645df32b4dff1 (diff)
downloadmu-fab56ebcecbf04db315c7f6f0ab642ef48ee48dd.tar.gz
594 - random snapshot after a lengthy debug
I'd caused a bug in Arc: https://github.com/arclanguage/anarki/commit/97b3464256

Almost done interrupting and restarting routines.
Diffstat (limited to 'chessboard-cursor.arc.t.1')
-rw-r--r--chessboard-cursor.arc.t.1384
1 files changed, 384 insertions, 0 deletions
diff --git a/chessboard-cursor.arc.t.1 b/chessboard-cursor.arc.t.1
new file mode 100644
index 00000000..85ac8a78
--- /dev/null
+++ b/chessboard-cursor.arc.t.1
@@ -0,0 +1,384 @@
+(selective-load "mu.arc" section-level)
+
+;? (reset)
+;? (new-trace "read-move-legal")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (2:string-address/raw <- get screen:terminal-address/deref data:offset)
+;?       (r:integer/routine <- fork read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address screen:terminal-address)
+;?       (c:character <- copy ((#\a literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\2 literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\- literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\a literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\4 literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (sleep until-routine-done:literal r:integer/routine)
+;?      ])))
+;? ;? (set dump-trace*)
+;? ;? (= dump-trace* (obj whitelist '("schedule")))
+;? ;? (= dump-trace* (obj whitelist '("schedule" "run")))
+;? (run 'main)
+;? (each routine completed-routines*
+;? ;?   (prn "  " routine)
+;?   (awhen rep.routine!error
+;?     (prn "error - " it)))
+;? (when (~ran-to-completion 'read-move)
+;?   (prn "F - chessboard accepts legal moves (<rank><file>-<rank><file>)"))
+;? (when (~memory-contains-array memory*.2 "a2-a4")
+;?   (prn "F - chessboard prints moves read from keyboard"))
+;? ;? (quit)
+
+; todo: test that restarting a routine works
+;   when it died
+;   when it timed out
+;   when it completed
+; test that run checks status of sleep
+; run multiple routines in tandem
+
+(def restart (routine)
+  (while (in top.routine!fn-name 'read 'write)
+    (pop-stack routine))
+  (prn routine)
+;?   (let r read-move-routine
+;?     (each frame rep.r!call-stack
+;?       (prn " @frame!fn-name")
+;?       (each (key val) frame
+;?         (prn "  " key " " val))))
+  (wipe rep.routine!sleep)
+  (enq routine running-routines*))
+
+(reset)
+(new-trace "read-move-incomplete")
+(add-code:readfile "chessboard-cursor.mu")
+(prn "init")
+; initialize location 1 to stdin; location 2 to screen fake; 3 to the contents
+; of the fake
+(add-code 
+  '((function test-init [
+      (1:channel-address/raw <- init-channel 1:literal)
+      (2:terminal-address/raw <- init-fake-terminal 20:literal 10:literal)
+      (3:string-address/raw <- get 2:terminal-address/raw/deref data:offset)
+     ])))
+(prn "run init")
+(run 'test-init)
+(prn "make routine under test")
+; the component under test; we'll be running this repeatedly
+(let read-move-routine (make-routine 'read-move memory*.1 memory*.2)
+  (set rep.read-move-routine!helper)
+  (prn "send first key")
+  ; send in first letter
+  (add-code
+    '((function test-send-first-key [
+        (default-space:space-address <- new space:literal 30:literal/capacity)
+        (c:character <- copy ((#\a literal)))
+        (x:tagged-value <- save-type c:character)
+        (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+       ])))
+  (run 'test-send-first-key)
+  (prn "consume first key")
+;?   (prn read-move-routine)
+  ; check that read-move consumes it and then goes to sleep
+  (enq read-move-routine running-routines*)
+;?   (set dump-trace*)
+;?   (prn int-canon.memory*)
+  (wipe completed-routines*)
+;?   (set dump-trace*)
+  (keep-running)
+  (prn rep.read-move-routine!sleep)
+;?   (prn int-canon.memory*)
+;?   (each routine completed-routines*
+;?     (prn routine))
+;?   (quit)
+  (prn "check routine state")
+  (when (ran-to-completion 'read-move)
+    (prn "F - chessboard waits after first letter of move"))
+  ; send in a few more letters
+  (prn "send and consume more keys")
+  (add-code
+    '((function test-send-next-keys [
+        (default-space:space-address <- new space:literal 30:literal/capacity)
+        (c:character <- copy ((#\2 literal)))
+        (x:tagged-value <- save-type c:character)
+        (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+        (c:character <- copy ((#\- literal)))
+        (x:tagged-value <- save-type c:character)
+        (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+        (c:character <- copy ((#\a literal)))
+        (x:tagged-value <- save-type c:character)
+        (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+       ])))
+;?   (set dump-trace*)
+  (restart read-move-routine)
+  (run 'test-send-next-keys)
+;?   (each routine completed-routines*
+;?     (prn routine))
+;?   (quit)
+;?   (prn "-- before: " rep.read-move-routine!sleep)
+;?   (while (~empty running-routines*)
+;?     (prn "iter: " rep.read-move-routine!sleep)
+;?     (= routine* deq.running-routines*)
+;?     (when rep.routine*!limit
+;?       ; start the clock if it wasn't already running
+;?       (or= rep.routine*!running-since curr-cycle*))
+;?     (routine-mark
+;?       (run-for-time-slice scheduling-interval*))
+;?     (prn "after iter: " rep.read-move-routine!sleep)
+;?     (when routine*
+;?       (if
+;?           rep.routine*!sleep
+;?             (do
+;?                 (set sleeping-routines*.routine*))
+;?           rep.routine*!error
+;?             (do
+;?                 (push routine* completed-routines*))
+;?           empty.routine*
+;?             (do
+;?                 (push routine* completed-routines*))
+;?           (no rep.routine*!limit)
+;?             (do
+;?                 (enq routine* running-routines*))
+;?           :else
+;?             (err "illegal scheduler state"))
+;?       (= routine* nil))
+;?     (each (routine _) canon.sleeping-routines*
+;?       (when (ready-to-wake-up routine)
+;?         (wipe sleeping-routines*.routine)  ; do this before modifying routine
+;?         (wipe rep.routine!sleep)
+;?         (++ pc.routine)
+;?         (enq routine running-routines*)))
+;?     (when (and (or (~empty running-routines*)
+;?                    (~empty sleeping-routines*))
+;?                (all [rep._ 'helper] (as cons running-routines*))
+;?                (all [rep._ 'helper] keys.sleeping-routines*))
+;?       (until (empty running-routines*)
+;?         (push (deq running-routines*) completed-routines*))
+;?       (each (routine _) sleeping-routines*
+;?         (wipe sleeping-routines*.routine)
+;?         (push routine completed-routines*)))
+;?     )
+;?   (prn "-- after: " rep.read-move-routine!sleep)
+;?   (quit)
+  ; check that read-move consumes it and then goes to sleep
+  (prn "check routine state")
+  (when (ran-to-completion 'read-move)
+    (prn "F - chessboard waits after each subsequent letter of move until the last"))
+  ; send final key
+  (prn "send final key")
+  (add-code
+    '((function test-send-final-key [
+        (default-space:space-address <- new space:literal 30:literal/capacity)
+        (c:character <- copy ((#\4 literal)))
+        (x:tagged-value <- save-type c:character)
+        (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+       ])))
+  (run 'test-send-final-key)
+  ; check that read-move consumes it and -- this time -- returns
+  (prn "consume final key")
+  (restart read-move-routine)
+  (keep-running)
+  (prn rep.read-move-routine!sleep)
+  (prn "check routine done")
+;?   (each routine completed-routines*
+;?     (prn routine))
+  (when (~ran-to-completion 'read-move)
+    (prn "F - 'read-move' completes after final letter of move"))
+)
+
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (2:string-address/raw <- get screen:terminal-address/deref data:offset)
+;?       (r:integer/routine <- fork-helper read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address screen:terminal-address)
+;?       (c:character <- copy ((#\a literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\2 literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\- literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (c:character <- copy ((#\a literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (sleep until-routine-done:literal r:integer/routine)
+;?      ])))
+;? (run 'main)
+;? (when (ran-to-completion 'read-move)
+;?   (prn "F - chessboard hangs until 5 characters are entered"))
+;? (when (~memory-contains-array memory*.2 "a2-a")
+;?   (prn "F - chessboard prints keys from keyboard before entire move is read"))
+
+;? (reset)
+;? (new-trace "read-move-quit")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (r:integer/routine <- fork-helper read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
+;?       (c:character <- copy ((#\q literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (sleep until-routine-done:literal r:integer/routine)
+;?      ])))
+;? (run 'main)
+;? (when (~ran-to-completion 'read-move)
+;?   (prn "F - chessboard quits on move starting with 'q'"))
+;? 
+;? (reset)
+;? (new-trace "read-illegal-file")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (r:integer/routine <- fork-helper read-file:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
+;?       (c:character <- copy ((#\i literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (sleep until-routine-done:literal r:integer/routine)
+;?      ])))
+;? ;? (= dump-trace* (obj whitelist '("schedule")))
+;? (run 'main)
+;? ;? (each routine completed-routines*
+;? ;?   (prn "  " routine))
+;? (when (or (ran-to-completion 'read-file)
+;?           (let routine routine-running!read-file
+;?             (~posmatch "file too high" rep.routine!error)))
+;?   (prn "F - 'read-file' checks that file lies between 'a' and 'h'"))
+;? 
+;? (reset)
+;? (new-trace "read-illegal-rank")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (r:integer/routine <- fork-helper read-rank:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
+;?       (c:character <- copy ((#\9 literal)))
+;?       (x:tagged-value <- save-type c:character)
+;?       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+;?       (sleep until-routine-done:literal r:integer/routine)
+;?      ])))
+;? (run 'main)
+;? (when (or (ran-to-completion 'read-rank)
+;?           (let routine routine-running!read-rank
+;?             (~posmatch "rank too high" rep.routine!error)))
+;?   (prn "F - 'read-rank' checks that rank lies between '1' and '8'"))
+;? 
+;? (reset)
+;? (new-trace "print-board")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
+;?                                                   ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+;?                                                   ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+;?                                                   ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
+;?                                                   ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal))
+;?                                                   ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+;?                                                   ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+;?                                                   ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
+;?       (b:board-address <- init-board initial-position:list-address)
+;?       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       (print-board screen:terminal-address b:board-address)
+;?       (5:string-address/raw <- get screen:terminal-address/deref data:offset)
+;?      ])))
+;? ;? (set dump-trace*)
+;? ;? (= dump-trace* (obj whitelist '("run")))
+;? (run 'main)
+;? (each routine completed-routines*
+;?   (awhen rep.routine!error
+;?     (prn "error - " it)))
+;? ;? (prn memory*.5)
+;? (when (~memory-contains-array memory*.5
+;?           (+ "8 | r n b q k b n r "
+;?              "7 | p p p p p p p p "
+;?              "6 | _ _ _ _ _ _ _ _ "
+;?              "5 | _ _ _ _ _ _ _ _ "
+;?              "4 | _ _ _ _ _ _ _ _ "
+;?              "3 | _ _ _ _ _ _ _ _ "
+;?              "2 | P P P P P P P P "
+;?              "1 | R N B Q K B N R "
+;?              "  +---------------- "
+;?              "    a b c d e f g h "))
+;?   (prn "F - print-board works; chessboard begins at @memory*.5"))
+;? 
+;? ; todo: how to fold this more elegantly with the previous test?
+;? (reset)
+;? (new-trace "make-move")
+;? (add-code:readfile "chessboard-cursor.mu")
+;? (add-code
+;?   '((function! main [
+;?       (default-space:space-address <- new space:literal 30:literal/capacity)
+;?       ; hook up stdin
+;?       (stdin:channel-address <- init-channel 1:literal)
+;?       ; fake screen
+;?       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
+;?       ; initial position
+;?       (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
+;?                                                   ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+;?                                                   ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+;?                                                   ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
+;?                                                   ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal))
+;?                                                   ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+;?                                                   ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+;?                                                   ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
+;?       (b:board-address <- init-board initial-position:list-address)
+;?       ; move: a2-a4
+;?       (m:move-address <- new move:literal)
+;?       (f:integer-integer-pair-address <- get-address m:move-address/deref from:offset)
+;?       (dest:integer-address <- get-address f:integer-integer-pair-address/deref 0:offset)
+;?       (dest:integer-address/deref <- copy 0:literal)  ; from-file: a
+;?       (dest:integer-address <- get-address f:integer-integer-pair-address/deref 1:offset)
+;?       (dest:integer-address/deref <- copy 1:literal)  ; from-rank: 2
+;?       (t0:integer-integer-pair-address <- get-address m:move-address/deref to:offset)
+;?       (dest:integer-address <- get-address t0:integer-integer-pair-address/deref 0:offset)
+;?       (dest:integer-address/deref <- copy 0:literal)  ; to-file: a
+;?       (dest:integer-address <- get-address t0:integer-integer-pair-address/deref 1:offset)
+;?       (dest:integer-address/deref <- copy 3:literal)  ; to-rank: 4
+;?       (b:board-address <- make-move b:board-address m:move-address)
+;?       (print-board screen:terminal-address b:board-address)
+;?       (5:string-address/raw <- get screen:terminal-address/deref data:offset)
+;?      ])))
+;? ;? (set dump-trace*)
+;? ;? (= dump-trace* (obj whitelist '("run")))
+;? (run 'main)
+;? (each routine completed-routines*
+;?   (awhen rep.routine!error
+;?     (prn "error - " it)))
+;? ;? (prn memory*.5)
+;? (when (~memory-contains-array memory*.5
+;?           (+ "8 | r n b q k b n r "
+;?              "7 | p p p p p p p p "
+;?              "6 | _ _ _ _ _ _ _ _ "
+;?              "5 | _ _ _ _ _ _ _ _ "
+;?              "4 | P _ _ _ _ _ _ _ "
+;?              "3 | _ _ _ _ _ _ _ _ "
+;?              "2 | _ P P P P P P P "
+;?              "1 | R N B Q K B N R "
+;?              "  +---------------- "
+;?              "    a b c d e f g h "))
+;?   (prn "F - make-move works; chessboard begins at @memory*.5"))
+
+(reset)
es' href='/akkartik/mu/commit/045closure_name.cc?h=main&id=363be37f3f41db063ced940e310d6bba6ef82ef3'>363be37f ^
82ac0b7e ^




b24eb476 ^
82ac0b7e ^
f3760b0f ^
9dcbec39 ^
6c96a437 ^
1b76245c ^
82ac0b7e ^
1b76245c ^
1e38eee5 ^
82ac0b7e ^







b24eb476 ^
82ac0b7e ^
f3760b0f ^
9dcbec39 ^
1e38eee5 ^
82ac0b7e ^
f22250a1 ^

82ac0b7e ^

5f98a10c ^
b24eb476 ^

82ac0b7e ^
ae256ea1 ^
af023b32 ^
9dcbec39 ^
e4630643 ^

ae256ea1 ^
82ac0b7e ^
f3760b0f ^
82ac0b7e ^
1e38eee5 ^


1ead3562 ^
1e38eee5 ^
192d59d3 ^
1e38eee5 ^
9dcbec39 ^

2655ae72 ^




760f683f ^

897ae8c1 ^
2655ae72 ^


897ae8c1 ^

760f683f ^
2655ae72 ^

897ae8c1 ^

2655ae72 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167