about summary refs log tree commit diff stats
path: root/html/apps/mu.subx.html
Commit message (Collapse)AuthorAgeFilesLines
* 5941Kartik Agaram2020-01-271-5176/+5289
|
* 5937Kartik Agaram2020-01-271-3230/+3270
|
* 5931Kartik Agaram2020-01-271-1/+1
|
* 5930Kartik Agaram2020-01-271-5132/+5290
|
* 5925Kartik Agaram2020-01-271-2425/+2467
|
* 5922Kartik Agaram2020-01-261-5556/+5674
|
* 5917Kartik Agaram2020-01-221-4299/+4293
|
* 5912Kartik Agaram2020-01-201-4115/+4450
|
* 5904Kartik Agaram2020-01-191-9/+9
|
* 5901Kartik Agaram2020-01-191-36/+36
|
* 5897 - rename comparison instructionsKartik Agaram2020-01-161-110/+110
| | | | | | | Signed and unsigned don't quite capture the essence of what the different combinations of x86 flags are doing for SubX. The crucial distinction is that one set of comparison operators is for integers and the second is for addresses.
* 5894Kartik Agaram2020-01-161-5/+5
|
* 5889Kartik Agaram2020-01-141-4117/+4286
|
* 5884Kartik Agaram2020-01-121-5032/+5030
|
* 5881Kartik Agaram2020-01-101-4887/+4976
|
* 5877Kartik Agaram2020-01-031-2/+2
|
* 5876 - address -> addrKartik Agaram2020-01-031-59/+59
|
* 5855Kartik Agaram2020-01-011-4274/+4559
|
* 5835Kartik Agaram2019-12-281-3696/+4764
|
* 5806Kartik Agaram2019-12-091-3902/+3913
|
* 5786Kartik Agaram2019-11-301-2320/+2356
|
* 5783Kartik Agaram2019-11-301-2546/+3584
|
* 5771Kartik Agaram2019-11-281-2159/+2556
|
* 5766Kartik Agaram2019-11-261-197/+299
|
* 5763Kartik Agaram2019-11-261-844/+886
|
* 5761Kartik Agaram2019-11-261-2099/+2229
|
* 5756Kartik Agaram2019-11-181-982/+1000
|
* 5755Kartik Agaram2019-11-181-897/+958
| | | | Support function calls with literal arguments.
* 5754Kartik Agaram2019-11-181-1095/+1168
| | | | Support binary instructions with an immediate operand.
* 5752Kartik Agaram2019-11-181-1094/+1109
| | | | | | | Support binary operations with reg/mem and reg operands. Everything is passing. However, the self-hosting translator now generates some discrepancies compared to the C++ translator :(
* 5751 - start of table of Mu primitivesKartik Agaram2019-11-181-940/+1099
| | | | | So far this is just the same as our most recent tests. But now we have a 'DSL' for adding more primitives.
* 5750Kartik Agaram2019-11-171-440/+816
| | | | | We can now compile primitive statements while selecting the right template to code-gen each one from. Even when multiple templates have the same name.
* 5747Kartik Agaram2019-11-151-1023/+1317
|
* 5745Kartik Agaram2019-11-141-1038/+1068
| | | | | | I've been under-estimating the complexity of translating primitive statements. We need to separately track information for each primitive about operands for both the source and emitted SubX notation.
* 5741Kartik Agaram2019-11-141-1014/+1020
| | | | | Support variables at positive stack offsets (formal parameters for functions), and also an indicator for 'any register' for primitive operations.
* 5738Kartik Agaram2019-11-101-898/+1081
|
* 5732Kartik Agaram2019-11-091-1000/+973
|
* 5731Kartik Agaram2019-11-091-910/+899
|
* 5730Kartik Agaram2019-11-091-606/+1028
|
* 5726Kartik Agaram2019-11-031-6/+6
|
* 5725Kartik Agaram2019-10-301-368/+371
|
* 5724Kartik Agaram2019-10-291-536/+537
|
* 5723Kartik Agaram2019-10-291-0/+666
an class='oid'>79ca54b3 ^
df0485ae ^
79ca54b3 ^
df0485ae ^
79ca54b3 ^

4ca73eb6 ^
79ca54b3 ^
5b698455 ^
79ca54b3 ^



f3060715 ^

0c145043 ^
4ca73eb6 ^
0c145043 ^


4d1f6bd7 ^
2647f843 ^
4d1f6bd7 ^
0c145043 ^

5b698455 ^
0c145043 ^


14a1649c ^
0c145043 ^


188206bd ^
4ca73eb6 ^
188206bd ^


4d1f6bd7 ^
2647f843 ^
4d1f6bd7 ^
188206bd ^

5b698455 ^
188206bd ^





14a1649c ^


188206bd ^



4ca73eb6 ^
188206bd ^


4d1f6bd7 ^
2647f843 ^
4d1f6bd7 ^
188206bd ^

5b698455 ^
188206bd ^


14a1649c ^


188206bd ^


33d602db ^
4ca73eb6 ^
33d602db ^






















33d602db ^










445a1494 ^




4ca73eb6 ^
445a1494 ^



4d1f6bd7 ^
445a1494 ^














































33d602db ^

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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262



                                       
                                   


                                                                            
                                                       
                                                                                                           

                                               
                                                                                 

                                               
                                                                                 

                                               
                                                                                 

                                               
                                                                                 

                                               
                                                                                 

                                                 
                                                                                 

                                                          
                    
                                                
                                                      
           
                                 
                       

                          
                                     
                                                                         

                                                             
         

       
                                  
                                   
                                                     
                  






                                                                         
                         



                                                                          
                                                                                







                                                            
                         




                                                                          
                                                                               

                                             
                                                                               

                                             
                                                                               

                                             
                                                                                




                                                                                     
                         
                             
                      

                                                                          
                                               
                                             
                                                                                



                                                                 

       
                            
                                   


                                                                            
                                                       
                                                                          
                                                                                                                                         

                                               
                                                                                 


                                                          
                                     


                                                         
                               
                                   


                                                                            
                                                       
                                                                          
                                                                                                                                         

                                               
                                                                                 





                                                          


                                                           



                                                                    
                                   


                                                                            
                                                       
                                                                          
                                                                                                                                         

                                               
                                                                                 


                                                          


                                                           


                                                                    
                         
                                   






















                                                                                                                                                                                  










                                       




                                                                 
                                   



                                                                            
                                                       














































                                                                                                                                                                                  

       
(selective-load "mu.arc" section-level)

(reset)
(new-trace "read-move-legal")
(add-code:readfile "chessboard.mu")
(add-code
  '((function! main [
      (default-space:space-address <- new space:literal 30:literal/capacity)
      (stdin:channel-address <- init-channel 1:literal)
      (r:integer/routine <- fork read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-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)
      (c:character <- copy ((#\newline 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>)"))
; todo: we can't test that keys pressed are printed to screen
; but that's at a lower level
;? (quit)

(reset)
(new-trace "read-move-incomplete")
(add-code:readfile "chessboard.mu")
; initialize some variables at specific raw locations
;? (prn "== init")
(run-code 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))
(wipe completed-routines*)
; the component under test; we'll be running this repeatedly
(let read-move-routine (make-routine 'read-move memory*.1 memory*.2)
;?   (prn "== first key")
  (run-code 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))
  (wipe completed-routines*)
  ; check that read-move consumes it and then goes to sleep
  (enq read-move-routine running-routines*)
  (run)
  (when (ran-to-completion 'read-move)
    (prn "F - chessboard waits after first letter of move"))
  (wipe completed-routines*)
  ; send in a few more letters
;?   (prn "== more keys")
  (restart read-move-routine)
  (run-code send-more-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)
    (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))
  ; check that read-move consumes them and then goes to sleep
  (when (ran-to-completion 'read-move)
    (prn "F - chessboard waits after each subsequent letter of move until the last"))
  (wipe completed-routines*)
  ; send final key
;?   (prn "== final key")
  (restart read-move-routine)
;?   (set dump-trace*)
  (run-code send-final-key
    (default-space:space-address <- new space:literal 30:literal/capacity)
    (c:character <- copy ((#\newline literal)))
    (x:tagged-value <- save-type c:character)
    (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value))
  ; check that read-move consumes it and -- this time -- returns
  (when (~ran-to-completion 'read-move)
    (prn "F - 'read-move' completes after final letter of move"))
)

(reset)
(new-trace "read-move-quit")
(add-code:readfile "chessboard.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.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.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.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.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)