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       # if single arg is 'test', run tests
  9       var tmp/ecx: (addr addr array byte) <- index args, 1
 10       var tmp2/eax: boolean <- string-equal? *tmp, "test"
 11       compare tmp2, 0  # false
 12       {
 13         break-if-=
 14         run-tests
 15         return 0  # TODO: get at Num-test-failures somehow
 16       }
 17       # if single arg is 'screen', run in full-screen mode
 18       tmp2 <- string-equal? *tmp, "screen"
 19       compare tmp2, 0  # false
 20       {
 21         break-if-=
 22         interactive
 23         return 0
 24       }
 25       # if single arg is 'type', run in typewriter mode
 26       tmp2 <- string-equal? *tmp, "type"
 27       compare tmp2, 0  # false
 28       {
 29         break-if-=
 30         repl
 31         return 0
 32       }
 33       # if single arg is 'test' ...
 34       tmp2 <- string-equal? *tmp, "test2"
 35       compare tmp2, 0  # false
 36       {
 37         break-if-=
 38         test
 39         return 0
 40       }
 41     }
 42     # otherwise error message
 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  # 'ctrl-q'
 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 #?   var env-storage: environment
 73 #?   var env/esi: (addr environment) <- address env-storage
 74 #?   initialize-environment-with-fake-screen env, 5, 0xa
 75 #?   var g/eax: grapheme <- copy 0x22  # '"'
 76 #?   process env, g
 77 #?   g <- copy 0x61  # 'a'
 78 #?   process env, g
 79 #?   g <- copy 0x22  # '"'
 80 #?   process env, g
 81 #?   render env
 82 }
 83 
 84 fn repl {
 85   {
 86     # prompt
 87     print-string-to-real-screen "> "
 88     # read
 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  # false
 95     break-if-!=
 96     # parse
 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  # false
103       break-if-!=
104       var g/eax: grapheme <- read-grapheme line
105       process env, g
106       loop
107     }
108     # eval
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     # print
114     var empty?/eax: boolean <- value-stack-empty? stack
115     {
116       compare empty?, 0  # false
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 }