Skip to content

Commit 75a6113

Browse files
authored
Tweak the wc.asm as the 1 error exit case is for all/any error; exercise an error in wc-test target (#69)
* tweak the wc.asm as the error is for all/any error, exercise and error in wc-test target * dumb it down for windows
1 parent 36516f1 commit 75a6113

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ wc-test: vm grol_cvm
4444
diff /tmp/wc_all_expected /tmp/wc_all_output
4545
./grol_cvm programs/wc.vm programs/*.asm > /tmp/wc_all_output
4646
diff /tmp/wc_all_expected /tmp/wc_all_output
47+
# error case --- file doesn't exist will abort with error message on stderr
48+
./vm run -loglevel critical programs/wc.vm programs/wc.asm nofilesuchfile programs/simple.asm; test $$? -eq 1
49+
./grol_cvm programs/wc.vm programs/wc.asm nofilesuchfile programs/simple.asm; test $$? -eq 1
4750

4851
echo-test: vm grol_cvm
4952
./vm compile programs/echo.asm

programs/wc.asm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ arg_loop:
3131
; Open file
3232
; Sys Open flags path
3333
Sys Open O_RDONLY 0 ; flags=O_RDONLY(0), path=0(Accumulator)
34-
JLT 0 open_error
34+
JLT 0 sys_error
3535
Push 0; fd_param
3636

3737
Call count_lines
@@ -43,7 +43,7 @@ arg_loop:
4343
; Close file
4444
Pop 0; fd_param
4545
Sys Close 0
46-
JNE 0 open_error ; really a close error but... reuse same path/exit.
46+
JNE 0 sys_error
4747
; Print current file count
4848
LoadR cur_count
4949
Call itoa
@@ -60,9 +60,9 @@ arg_loop:
6060
no_total_print:
6161
Sys Exit 0
6262

63-
open_error:
63+
sys_error:
6464
Sys Write8 STDOUT stdout_err_msg
65-
Sys Write8 STDERR open_err_msg
65+
Sys Write8 STDERR err_msg
6666
Pop 0
6767
Sys Write8 STDERR 0 ; filename from A
6868
Sys Write8 STDERR newline_str
@@ -92,7 +92,8 @@ not_newline:
9292
JGT 0 count_loop
9393
JumpR read_loop
9494
check_result:
95-
JNE 0 open_error ; error case
95+
JNE 0 sys_error ; error case, abort
96+
; else EOF case, return count
9697
LoadS count
9798
Return; Will generate ret 35 (cleanup stack variables (32 + 3 = 35 words))
9899

@@ -109,8 +110,8 @@ space_str:
109110
str8 " "
110111
newline_str:
111112
str8 "\n"
112-
open_err_msg:
113-
str8 "Error: cannot open file "
113+
err_msg:
114+
str8 "File error: "
114115
stdout_err_msg:
115116
str8 "...err...\n"
116117
total_label:

0 commit comments

Comments
 (0)