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