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