https://github.com/akkartik/mu/blob/master/apps/tile/main.mu
1 fn main args-on-stack: (addr array addr array byte) -> exit-status/ebx: int {
2 var args/eax: (addr array addr array byte) <- copy args-on-stack
3 var len/ecx: int <- length args
4 $main-body: {
5 compare len, 2
6 {
7 break-if-!=
8
9 var tmp/ecx: (addr addr array byte) <- index args, 1
10 var tmp2/eax: boolean <- string-equal? *tmp, "test"
11 compare tmp2, 0
12 {
13 break-if-=
14 run-tests
15 exit-status <- copy 0
16 break $main-body
17 }
18
19 tmp2 <- string-equal? *tmp, "screen"
20 compare tmp2, 0
21 {
22 break-if-=
23 interactive
24 exit-status <- copy 0
25 break $main-body
26 }
27
28 tmp2 <- string-equal? *tmp, "type"
29 compare tmp2, 0
30 {
31 break-if-=
32 repl
33 exit-status <- copy 0
34 break $main-body
35 }
36
37 tmp2 <- string-equal? *tmp, "test2"
38 compare tmp2, 0
39 {
40 break-if-=
41 test
42 exit-status <- copy 0
43 break $main-body
44 }
45 }
46
47 print-string-to-real-screen "usage:\n"
48 print-string-to-real-screen " to run tests: tile test\n"
49 print-string-to-real-screen " full-screen mode: tile screen\n"
50 print-string-to-real-screen " regular REPL: tile type\n"
51 exit-status <- copy 1
52 }
53 }
54
55 fn interactive {
56 enable-screen-grid-mode
57 enable-keyboard-immediate-mode
58 var env-storage: environment
59 var env/esi: (addr environment) <- address env-storage
60 initialize-environment env
61 draw-screen env
62 {
63 var key/eax: grapheme <- read-key-from-real-keyboard
64 compare key, 0x11
65 break-if-=
66 process env, key
67 render env
68 loop
69 }
70 enable-keyboard-type-mode
71 enable-screen-type-mode
72 }
73
74 fn test {
75 var env-storage: environment
76 var env/esi: (addr environment) <- address env-storage
77 initialize-environment-with-fake-screen env, 5, 0xa
78 var g/eax: grapheme <- copy 0x31
79 process env, g
80 g <- copy 1
81 process env, g
82
83 }
84
85 fn repl {
86 {
87
88 var line-storage: (stream byte 0x100)
89 var line/ecx: (addr stream byte) <- address line-storage
90 print-string-to-real-screen "> "
91
92 clear-stream line
93 read-line-from-real-keyboard line
94 var done?/eax: boolean <- stream-empty? line
95 compare done?, 0
96 break-if-!=
97
98 var env-storage: environment
99 var env/esi: (addr environment) <- address env-storage
100 initialize-environment env
101 {
102 var done?/eax: boolean <- stream-empty? line
103 compare done?, 0
104 break-if-!=
105 var g/eax: grapheme <- read-grapheme line
106 process env, g
107 loop
108 }
109
110 var stack-storage: value-stack
111 var stack/edi: (addr value-stack) <- address stack-storage
112 initialize-value-stack stack, 0x10
113 evaluate-environment env, stack
114
115 var empty?/eax: boolean <- value-stack-empty? stack
116 {
117 compare empty?, 0
118 break-if-!=
119 var result/eax: int <- pop-int-from-value-stack stack
120 print-int32-decimal-to-real-screen result
121 print-string-to-real-screen "\n"
122 }
123
124 loop
125 }
126 }