From d3a9db3aff54ea485f409eaaef3d8f56ad77f0dc Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 5 Oct 2020 11:00:05 -0700 Subject: 6958 --- html/apps/tile/main.mu.html | 171 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 html/apps/tile/main.mu.html (limited to 'html/apps/tile/main.mu.html') diff --git a/html/apps/tile/main.mu.html b/html/apps/tile/main.mu.html new file mode 100644 index 00000000..8fbd435b --- /dev/null +++ b/html/apps/tile/main.mu.html @@ -0,0 +1,171 @@ + + + + +Mu - apps/tile/main.mu + + + + + + + + + + +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       # 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         exit-status <- copy 0  # TODO: get at Num-test-failures somehow
+ 16         break $main-body
+ 17       }
+ 18       # if single arg is 'screen', run in full-screen mode
+ 19       tmp2 <- string-equal? *tmp, "screen"
+ 20       compare tmp2, 0  # false
+ 21       {
+ 22         break-if-=
+ 23         interactive
+ 24         exit-status <- copy 0
+ 25         break $main-body
+ 26       }
+ 27       # if single arg is 'type', run in typewriter mode
+ 28       tmp2 <- string-equal? *tmp, "type"
+ 29       compare tmp2, 0  # false
+ 30       {
+ 31         break-if-=
+ 32         repl
+ 33         exit-status <- copy 0
+ 34         break $main-body
+ 35       }
+ 36     }
+ 37     # otherwise error message
+ 38     print-string-to-real-screen "usage:\n"
+ 39     print-string-to-real-screen "  to run tests: tile test\n"
+ 40     print-string-to-real-screen "  full-screen mode: tile screen\n"
+ 41     print-string-to-real-screen "  regular REPL: tile type\n"
+ 42     exit-status <- copy 1
+ 43   }
+ 44 }
+ 45 
+ 46 fn interactive {
+ 47   enable-screen-grid-mode
+ 48   enable-keyboard-immediate-mode
+ 49   var env-storage: environment
+ 50   var env/esi: (addr environment) <- address env-storage
+ 51   initialize-environment env
+ 52   draw-screen env
+ 53   {
+ 54     var key/eax: grapheme <- read-key-from-real-keyboard
+ 55     compare key, 0x71  # 'q'
+ 56     break-if-=
+ 57     process env, key
+ 58     render env
+ 59     loop
+ 60   }
+ 61   enable-keyboard-type-mode
+ 62   enable-screen-type-mode
+ 63 }
+ 64 
+ 65 fn repl {
+ 66   enable-keyboard-immediate-mode
+ 67   var env-storage: environment
+ 68   var env/esi: (addr environment) <- address env-storage
+ 69   initialize-environment env
+ 70   var stack-storage: value-stack
+ 71   var stack/edi: (addr value-stack) <- address stack-storage
+ 72   initialize-value-stack stack, 0x10
+ 73   print-string-to-real-screen "> "
+ 74   $repl:loop: {
+ 75     var key/eax: grapheme <- read-key-from-real-keyboard
+ 76     print-grapheme-to-real-screen key
+ 77     compare key, 4  # ctrl-d
+ 78     break-if-=
+ 79     compare key, 0xa  # newline
+ 80     {
+ 81       break-if-!=
+ 82       evaluate-environment env, stack
+ 83       var empty?/eax: boolean <- value-stack-empty? stack
+ 84       {
+ 85         compare empty?, 0  # false
+ 86         break-if-!=
+ 87         var result/eax: int <- pop-int-from-value-stack stack
+ 88         print-int32-decimal-to-real-screen result
+ 89         print-string-to-real-screen "\n"
+ 90       }
+ 91       # clear line
+ 92       var cursor-word-ah/ecx: (addr handle word) <- get env, cursor-word
+ 93       var program-ah/eax: (addr handle program) <- get env, program
+ 94       var _program/eax: (addr program) <- lookup *program-ah
+ 95       var program/esi: (addr program) <- copy _program
+ 96       var sandbox-ah/esi: (addr handle sandbox) <- get program, sandboxes
+ 97       var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+ 98       var line-ah/eax: (addr handle line) <- get sandbox, data
+ 99       var _line/eax: (addr line) <- lookup *line-ah
+100       var line/esi: (addr line) <- copy _line
+101       initialize-line line, cursor-word-ah
+102       print-string-to-real-screen "> "
+103       loop $repl:loop
+104     }
+105     process env, key
+106     loop
+107   }
+108   enable-keyboard-type-mode
+109 }
+
+ + + -- cgit 1.4.1-2-gfad0