https://github.com/akkartik/mu/blob/master/apps/print-file.mu
1
2
3
4
5
6
7
8
9
10 fn main _args: (addr array (addr array byte)) -> exit-status/ebx: int {
11 var args/eax: (addr array (addr array byte)) <- copy _args
12 $main-body: {
13 var n/ecx: int <- length args
14 compare n, 1
15 {
16 break-if->
17 print-string "usage: cat <filename>\n"
18 break $main-body
19 }
20 {
21 break-if-<=
22 var filename/edx: (addr addr array byte) <- index args 1
23 var in: (handle buffered-file)
24 {
25 var addr-in/eax: (addr handle buffered-file) <- address in
26 open *filename, 0, addr-in
27 }
28 var _in-addr/eax: (addr buffered-file) <- lookup in
29 var in-addr/ecx: (addr buffered-file) <- copy _in-addr
30 {
31 var c/eax: byte <- read-byte-buffered in-addr
32 compare c, 0xffffffff
33 break-if-=
34 print-byte c
35 loop
36 }
37 }
38 }
39 exit-status <- copy 0
40 }