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