about summary refs log tree commit diff stats
path: root/arc/chessboard.mu
blob: 45fc12da8882c5de7a1491f9dc959186aced7293 (plain) (blame)
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
;; data structure: board
(primitive square)
(address square-address (square))  ; pointer. verbose but sadly necessary for now
(array file (square))  ; ranks and files are arrays of squares
(address file-address (file))
(address file-address-address (file-address))  ; pointer to a pointer
(array board (file-address))
(address board-address (board))

(function init-board [
  (default-space:space-address <- new space:literal 30:literal)
  (initial-position:integer-array-address <- next-input)
  ; assert(length(initial-position) == 64)
;?   ($print initial-position:integer-array-address/deref) ;? 1
  (len:integer <- length initial-position:integer-array-address/deref)
;?   ($print len:integer) ;? 1
;?   ($print (("\n" literal))) ;? 1
  (correct-length?:boolean <- equal len:integer 64:literal)
  (assert correct-length?:boolean (("chessboard had incorrect size" literal)))
  (b:board-address <- new board:literal 8:literal)
  (col:integer <- copy 0:literal)
  { begin
    (done?:boolean <- equal col:integer 8:literal)
    (break-if done?:boolean)
    (file:file-address-address <- index-address b:board-address/deref col:integer)
    (file:file-address-address/deref <- init-file initial-position:integer-array-address col:integer)
    (col:integer <- add col:integer 1:literal)
    (loop)
  }
  (reply b:board-address)
])

(function init-file [
  (default-space:space-address <- new space:literal 30:literal)
  (position:integer-array-address <- next-input)
  (index:integer <- next-input)
  (index:integer <- multiply index:integer 8:literal)
  (result:file-address <- new file:literal 8:literal)
  (row:integer <- copy 0:literal)
  { begin
    (done?:boolean <- equal row:integer 8:literal)
    (break-if done?:boolean)
    (dest:square-address <- index-address result:file-address/deref row:integer)
    (dest:square-address/deref <- index position:integer-array-address/deref index:integer)
    (row:integer <- add row:integer 1:literal)
    (index:integer <- add index:integer 1:literal)
    (loop)
  }
  (reply result:file-address)
])

(function print-board [
  (default-space:space-address <- new space:literal 30:literal)
  (screen:terminal-address <- next-input)
  (b:board-address <- next-input)
  (row:integer <- copy 7:literal)
  ; print each row
  { begin
    (done?:boolean <- less-than row:integer 0:literal)
    (break-if done?:boolean)
    ; print rank number as a legend
    (rank:integer <- add row:integer 1:literal)
    (print-integer screen:terminal-address rank:integer)
    (s:string-address <- new " | ")
    (print-string screen:terminal-address s:string-address)
    ; print each square in the row
    (col:integer <- copy 0:literal)
    { begin
      (done?:boolean <- equal col:integer 8:literal)
      (break-if done?:boolean)
      (f:file-address <- index b:board-address/deref col:integer)
      (s:square <- index f:file-address/deref row:integer)
      (print-character screen:terminal-address s:square)
      (print-character screen:terminal-address ((#\space literal)))
      (col:integer <- add col:integer 1:literal)
      (loop)
    }
    (row:integer <- subtract row:integer 1:literal)
    (cursor-to-next-line screen:terminal-address)
    (loop)
  }
  ; print file letters as legend
  (s:string-address <- new "  +----------------")
  (print-string screen:terminal-address s:string-address)
  (cursor-to-next-line screen:terminal-address)
  (s:string-address <- new "    a b c d e f g h")
  (print-string screen:terminal-address s:string-address)
  (cursor-to-next-line screen:terminal-address)
])

;; data structure: move
(and-record move [
  from:integer-integer-pair
  to:integer-integer-pair
])

(address move-address (move))

(function read-move [
  (default-space:space-address <- new space:literal 30:literal)
  (stdin:channel-address <- next-input)
  (from-file:integer <- read-file stdin:channel-address)
  { begin
    (break-if from-file:integer)
    (reply nil:literal)
  }
  (from-rank:integer <- read-rank stdin:channel-address)
  (expect-stdin stdin:channel-address ((#\- literal)))
  (to-file:integer <- read-file stdin:channel-address)
  (to-rank:integer <- read-rank stdin:channel-address)
  (expect-stdin stdin:channel-address ((#\newline literal)))
  ; construct the move object
  (result:move-address <- new move:literal)
  (f:integer-integer-pair-address <- get-address result:move-address/deref from:offset)
  (dest:integer-address <- get-address f:integer-integer-pair-address/deref 0:offset)
  (dest:integer-address/deref <- copy from-file:integer)
  (dest:integer-address <- get-address f:integer-integer-pair-address/deref 1:offset)
  (dest:integer-address/deref <- copy from-rank:integer)
  (t0:integer-integer-pair-address <- get-address result:move-address/deref to:offset)
  (dest:integer-address <- get-address t0:integer-integer-pair-address/deref 0:offset)
  (dest:integer-address/deref <- copy to-file:integer)
  (dest:integer-address <- get-address t0:integer-integer-pair-address/deref 1:offset)
  (dest:integer-address/deref <- copy to-rank:integer)
  (reply result:move-address)
])

; todo: assumes stdin is always at raw address 1
(function read-file [
  (default-space:space-address <- new space:literal 30:literal)
  (stdin:channel-address <- next-input)
  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
;?   ($print x:tagged-value) ;? 1
;?   ($print (("\n" literal))) ;? 1
  (a:character <- copy ((#\a literal)))
  (file-base:integer <- character-to-integer a:character)
  (c:character <- maybe-coerce x:tagged-value character:literal)
;?   ($print (("AAA " literal))) ;? 1
;?   ($print c:character) ;? 1
;?   ($print (("\n" literal))) ;? 1
  { begin
    (quit:boolean <- equal c:character ((#\q literal)))
    (break-unless quit:boolean)
    (reply nil:literal)
  }
  (file:integer <- character-to-integer c:character)
  (file:integer <- subtract file:integer file-base:integer)
  ; assert('a' <= from-file <= 'h')
  (above-min:boolean <- greater-or-equal file:integer 0:literal)
  (assert above-min:boolean (("file too low" literal)))
  (below-max:boolean <- lesser-or-equal file:integer 7:literal)
  (assert below-max:boolean (("file too high" literal)))
  (reply file:integer)
])

(function read-rank [
  (default-space:space-address <- new space:literal 30:literal)
  (stdin:channel-address <- next-input)
  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
  (c:character <- maybe-coerce x:tagged-value character:literal)
;?   ($print (("BBB " literal))) ;? 1
;?   ($print c:character) ;? 1
;?   ($print (("\n" literal))) ;? 1
  { begin
    (quit:boolean <- equal c:character ((#\q literal)))
    (break-unless quit:boolean)
    (reply nil:literal)
  }
  (rank:integer <- character-to-integer c:character)
  (one:character <- copy ((#\1 literal)))
  (rank-base:integer <- character-to-integer one:character)
  (rank:integer <- subtract rank:integer rank-base:integer)
  ; assert('1' <= rank <= '8')
  (above-min:boolean <- greater-or-equal rank:integer 0:literal)
  (assert above-min:boolean (("rank too low" literal)))
  (below-max:boolean <- lesser-or-equal rank:integer 7:literal)
  (assert below-max:boolean (("rank too high" literal)))
  (reply rank:integer)
])

; slurp a character and check that it matches
(function expect-stdin [
  (default-space:space-address <- new space:literal 30:literal)
  (stdin:channel-address <- next-input)
  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
  (c:character <- maybe-coerce x:tagged-value character:literal)
  (expected:character <- next-input)
  (match?:boolean <- equal c:character expected:character)
  (assert match?:boolean (("expected character not found" literal)))
])

(function make-move [
  (default-space:space-address <- new space:literal 30:literal)
  (b:board-address <- next-input)
  (m:move-address <- next-input)
  (x:integer-integer-pair <- get m:move-address/deref from:offset)
  (from-file:integer <- get x:integer-integer-pair 0:offset)
  (from-rank:integer <- get x:integer-integer-pair 1:offset)
  (f:file-address <- index b:board-address/deref from-file:integer)
  (src:square-address <- index-address f:file-address/deref from-rank:integer)
  (x:integer-integer-pair <- get m:move-address/deref to:offset)
  (to-file:integer <- get x:integer-integer-pair 0:offset)
  (to-rank:integer <- get x:integer-integer-pair 1:offset)
  (f:file-address <- index b:board-address/deref to-file:integer)
  (dest:square-address <- index-address f:file-address/deref to-rank:integer)
  (dest:square-address/deref <- copy src:square-address/deref)
  (src:square-address/deref <- copy ((#\_ literal)))
  (reply b:board-address)
])

(function chessboard [
  (default-space:space-address <- new space:literal 30:literal)
  (initial-position:integer-array-address <- init-array ((#\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:integer-array-address)
  (cursor-mode)
  ; hook up stdin
  (stdin:channel-address <- init-channel 1:literal)
  (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address)
  ; buffer stdin
  (buffered-stdin:channel-address <- init-channel 1:literal)
  (fork-helper buffer-lines:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address)
  ($print (("Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves." literal)))
  (cursor-to-next-line nil:literal/terminal)
  { begin
    (cursor-to-next-line nil:literal/terminal)
    (print-board nil:literal/terminal b:board-address)
    (cursor-to-next-line nil:literal/terminal)
    ($print (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>." literal)))
    (cursor-to-next-line nil:literal/terminal)
    ($print (("Hit 'q' to exit." literal)))
    (cursor-to-next-line nil:literal/terminal)
    ($print (("move: " literal)))
    (m:move-address <- read-move buffered-stdin:channel-address)
;?     (retro-mode) ;? 1
;?     ($print stdin:channel-address) ;? 1
;?     ($print (("\n" literal))) ;? 1
;?     ($print buffered-stdin:channel-address) ;? 1
;?     ($print (("\n" literal))) ;? 1
;?     ($dump-memory) ;? 1
;?     (cursor-mode) ;? 1
    (break-unless m:move-address)
    (b:board-address <- make-move b:board-address m:move-address)
    (loop)
  }
  (retro-mode)
])

(function main [
  (chessboard)
])

; todo:
;   backspace, ctrl-u
# registers except ESP may be clobbered at this point # pop args to scan-next-byte # . . discard first 2 args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . . restore ed 59/pop-to-ECX # check that scan-next-byte didn't abort # . check-ints-equal(ed->value, 0, msg) # . . push args 68/push "F - test-scan-next-byte-reads-final-byte: unexpected abort"/imm32 68/push 0/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # return if abort 81 7/subop/compare 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # compare *(ECX+4) 75/jump-if-not-equal $test-scan-next-byte-reads-final-byte:end/disp8 # check-ints-equal(EAX, 0x61/a, msg) # . . push args 68/push "F - test-scan-next-byte-reads-final-byte"/imm32 68/push 0x61/imm32/a 50/push-EAX # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP $test-scan-next-byte-reads-final-byte:end: # . epilog # don't restore ESP from EBP; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP 5d/pop-to-EBP c3/return test-scan-next-byte-handles-Eof: # - check that the right sentinel value is returned when there's no data remaining to be read # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # clear all streams # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-buffered-file+4) # . . push args b8/copy-to-EAX _test-buffered-file/imm32 05/add-to-EAX 4/imm32 50/push-EAX # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-error-stream) # . . push args 68/push _test-error-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-error-buffered-file+4) # . . push args b8/copy-to-EAX _test-error-buffered-file/imm32 05/add-to-EAX 4/imm32 50/push-EAX # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # leave '_test-stream' empty # initialize exit-descriptor 'ed' for the call to 'scan-next-byte' below # . var ed/ECX : exit-descriptor 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # subtract from ESP 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX # . tailor-exit-descriptor(ed, 12) # . . push args 68/push 0xc/imm32/nbytes-of-args-for-scan-next-byte 51/push-ECX/ed # . . call e8/call tailor-exit-descriptor/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # EAX = scan-next-byte(_test-buffered-file, _test-error-buffered-file, ed) # . . push args 51/push-ECX/ed 68/push _test-error-buffered-file/imm32 68/push _test-buffered-file/imm32 # . . call e8/call scan-next-byte/disp32 # registers except ESP may be clobbered at this point # pop args to scan-next-byte # . . discard first 2 args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . . restore ed 59/pop-to-ECX # check that scan-next-byte didn't abort # . check-ints-equal(ed->value, 0, msg) # . . push args 68/push "F - test-scan-next-byte-handles-Eof: unexpected abort"/imm32 68/push 0/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # return if abort 81 7/subop/compare 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # compare *(ECX+4) 75/jump-if-not-equal $test-scan-next-byte-handles-Eof:end/disp8 # check-ints-equal(EAX, Eof, msg) # . . push args 68/push "F - test-scan-next-byte-handles-Eof"/imm32 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP $test-scan-next-byte-handles-Eof:end: # . epilog # don't restore ESP from EBP; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP 5d/pop-to-EBP c3/return test-scan-next-byte-aborts-on-invalid-byte: # - check that the a bad byte immediately aborts # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # clear all streams # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-buffered-file+4) # . . push args b8/copy-to-EAX _test-buffered-file/imm32 05/add-to-EAX 4/imm32 50/push-EAX # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-error-stream) # . . push args 68/push _test-error-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-error-buffered-file+4) # . . push args b8/copy-to-EAX _test-error-buffered-file/imm32 05/add-to-EAX 4/imm32 50/push-EAX # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # initialize '_test-stream' to "x" # . write(_test-stream, "x") # . . push args 68/push "x"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # initialize exit-descriptor 'ed' for the call to 'scan-next-byte' below # . var ed/ECX : exit-descriptor 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # subtract from ESP 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX # . tailor-exit-descriptor(ed, 12) # . . push args 68/push 0xc/imm32/nbytes-of-args-for-scan-next-byte 51/push-ECX/ed # . . call e8/call tailor-exit-descriptor/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # EAX = scan-next-byte(_test-buffered-file, _test-error-buffered-file, ed) # . . push args 51/push-ECX/ed 68/push _test-error-buffered-file/imm32 68/push _test-buffered-file/imm32 # . . call e8/call scan-next-byte/disp32 # registers except ESP may be clobbered at this point # pop args to scan-next-byte # . . discard first 2 args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . . restore ed 59/pop-to-ECX # check that scan-next-byte aborted # . check-ints-equal(ed->value, 2, msg) # . . push args 68/push "F - test-scan-next-byte-aborts-on-invalid-byte"/imm32 68/push 2/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP $test-scan-next-byte-aborts-on-invalid-byte:end: # . epilog # don't restore ESP from EBP; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP 5d/pop-to-EBP c3/return skip-until-newline: # in : (address buffered-file) -> <void> # pseudocode: # push EAX # while true # EAX = read-byte-buffered(in) # if (EAX == Eof) break # if (EAX == 0x0a) break # pop EAX # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers 50/push-EAX $skip-until-newline:loop: # . EAX = read-byte-buffered(in) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . if (EAX == Eof) break 3d/compare-EAX-and 0xffffffff/imm32/Eof 74/jump-if-equal $skip-until-newline:end/disp8 # . if (EAX != 0xa/newline) loop 3d/compare-EAX-and 0xa/imm32/newline 75/jump-if-not-equal $skip-until-newline:loop/disp8 $skip-until-newline:end: # . restore registers 58/pop-to-EAX # . epilog 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP 5d/pop-to-EBP c3/return test-skip-until-newline: # - check that the read pointer points after the newline # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . clear-stream(_test-buffered-file+4) # . . push args b8/copy-to-EAX _test-buffered-file/imm32 05/add-to-EAX 4/imm32 50/push-EAX # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # initialize '_test-stream' to "abc\nde" # . write(_test-stream, "abc") # . . push args 68/push "abc\n"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . write(_test-stream, "de") # . . push args 68/push "de"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # skip-until-newline(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call e8/call skip-until-newline/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(_test-buffered-file->read, 4, msg) # . . push args 68/push "F - test-skip-until-newline"/imm32 68/push 4/imm32 b8/copy-to-EAX _test-buffered-file/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 . # push *(EAX+8) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # . end c3/return == data _test-error-stream: # current write index 0/imm32 # current read index 0/imm32 # line 0x80/imm32 # 128 bytes # data (8 lines x 16 bytes/line) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # a test buffered file for _test-error-stream _test-error-buffered-file: # file descriptor or (address stream) _test-error-stream/imm32 # current write index 0/imm32 # current read index 0/imm32 # length 6/imm32 # data 00 00 00 00 00 00 # 6 bytes # . . vim:nowrap:textwidth=0