about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--apps/tile/data.mu73
-rw-r--r--apps/tile/environment.mu40
-rw-r--r--apps/tile/rpn.mu27
3 files changed, 104 insertions, 36 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
new file mode 100644
index 00000000..c9988ed3
--- /dev/null
+++ b/apps/tile/data.mu
@@ -0,0 +1,73 @@
+type program {
+  defs: (handle function)
+  sandboxes: (handle sandbox)
+}
+
+type sandbox {
+  setup: (handle line)
+  data: (handle line)
+  next: (handle sandbox)
+  prev: (handle sandbox)
+}
+
+type function {
+  args: (handle word)
+  body: (handle line)
+  # some sort of indication of spatial location
+  next: (handle function)
+}
+
+type line {
+  name: (handle array byte)
+  data: (handle word)
+  result: (handle result)  # might be cached
+  next: (handle line)
+  prev: (handle line)
+}
+
+#? type word {
+#?   # at most one of these will be non-null
+#?   scalar-data: (handle gap-buffer)
+#?   box-data: (handle line)  # recurse
+#?   left: (handle word)
+#?   right: (handle word)
+#? }
+
+type result {
+  data: (handle word-stack)
+  error: (handle array byte)  # single error message for now
+}
+
+# if 'out' is non-null, save the first word of the program there
+fn initialize-program _program: (addr program), out: (addr handle word) {
+  var program/esi: (addr program) <- copy _program
+  var sandbox-ah/eax: (addr handle sandbox) <- get program, sandboxes
+  allocate sandbox-ah
+  var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+  initialize-sandbox sandbox, out
+}
+
+# if 'out' is non-null, save the first word of the sandbox there
+fn initialize-sandbox _sandbox: (addr sandbox), out: (addr handle word) {
+  var sandbox/esi: (addr sandbox) <- copy _sandbox
+  var line-ah/eax: (addr handle line) <- get sandbox, data
+  allocate line-ah
+  var line/eax: (addr line) <- lookup *line-ah
+  initialize-line line, out
+}
+
+# initialize line with a single empty word
+# if 'out' is non-null, save the word there as well
+fn initialize-line _line: (addr line), out: (addr handle word) {
+  var line/esi: (addr line) <- copy _line
+  var word-ah/eax: (addr handle word) <- get line, data
+  allocate word-ah
+  {
+    compare out, 0
+    break-if-=
+    var dest/edi: (addr handle word) <- copy out
+    copy-object word-ah, dest
+  }
+  var word/eax: (addr word) <- lookup *word-ah
+  initialize-word word
+}
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index b86c898a..846bec98 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -1,5 +1,6 @@
 type environment {
   screen: (handle screen)
+  program: (handle program)
   cursor-word: (handle word)
   nrows: int
   ncols: int
@@ -8,11 +9,12 @@ type environment {
 
 fn initialize-environment _env: (addr environment) {
   var env/esi: (addr environment) <- copy _env
-  var cursor-word-ah/eax: (addr handle word) <- get env, cursor-word
-  allocate cursor-word-ah
-  var cursor-word/eax: (addr word) <- lookup *cursor-word-ah
-  initialize-word cursor-word
-  #
+  var program-ah/eax: (addr handle program) <- get env, program
+  allocate program-ah
+  var program/eax: (addr program) <- lookup *program-ah
+  var cursor-word-ah/ecx: (addr handle word) <- get env, cursor-word
+  initialize-program program, cursor-word-ah
+  # initialize screen
   var screen-ah/eax: (addr handle screen) <- get env, screen
   var _screen/eax: (addr screen) <- lookup *screen-ah
   var screen/edi: (addr screen) <- copy _screen
@@ -167,14 +169,25 @@ fn render _env: (addr environment) {
   var repl-col/ecx: int <- copy *_repl-col
   repl-col <- add 2  # repl-margin-left
   # cursor-word
-  var cursor-word-ah/esi: (addr handle word) <- get env, cursor-word
+  var cursor-word-ah/ebx: (addr handle word) <- get env, cursor-word
   var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
   var cursor-word/ebx: (addr word) <- copy _cursor-word
+  # program
+  var program-ah/eax: (addr handle program) <- get env, program
+  var _program/eax: (addr program) <- lookup *program-ah
+  var program/esi: (addr program) <- copy _program
+  # defs
+  var defs-ah/edx: (addr handle function) <- get program, defs
+  var _defs/eax: (addr function) <- lookup *defs-ah
+  var defs/edx: (addr function) <- copy _defs
+  # line
+  var sandbox-ah/esi: (addr handle sandbox) <- get program, sandboxes
+  var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
+  var line-ah/eax: (addr handle line) <- get sandbox, data
+  var _line/eax: (addr line) <- lookup *line-ah
+  var line/esi: (addr line) <- copy _line
   # curr-word
   var curr-word/eax: (addr word) <- first-word cursor-word
-  # first-word
-  var first-word: (addr word)
-  copy-to first-word, curr-word
   # cursor-col
   var cursor-col: int
   var cursor-col-a: (addr int)
@@ -182,13 +195,14 @@ fn render _env: (addr environment) {
     var tmp/ecx: (addr int) <- address cursor-col
     copy-to cursor-col-a, tmp
   }
-  # curr-col
+  # loop-carried dependency
   var curr-col/ecx: int <- copy repl-col  # input-col
+  #
   {
     compare curr-word, 0
     break-if-=
     move-cursor screen, 3, curr-col  # input-row
-    curr-col <- render-column screen, first-word, curr-word, curr-col, cursor-word, cursor-col-a
+    curr-col <- render-column screen, defs, line, curr-word, curr-col, cursor-word, cursor-col-a
     var next-word-ah/edx: (addr handle word) <- get curr-word, next
     curr-word <- lookup *next-word-ah
     loop
@@ -206,7 +220,7 @@ fn render _env: (addr environment) {
 # - Return the farthest column written.
 # - If final-word is same as cursor-word, do some additional computation to set
 #   cursor-col-a.
-fn render-column screen: (addr screen), first-word: (addr word), final-word: (addr word), left-col: int, cursor-word: (addr word), cursor-col-a: (addr int) -> right-col/ecx: int {
+fn render-column screen: (addr screen), defs: (addr function), scratch: (addr line), final-word: (addr word), left-col: int, cursor-word: (addr word), cursor-col-a: (addr int) -> right-col/ecx: int {
   var max-width/ecx: int <- copy 0
   {
     # render stack for all but final column
@@ -222,7 +236,7 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
     var stack: int-stack
     var stack-addr/edi: (addr int-stack) <- address stack
     initialize-int-stack stack-addr, 0x10  # max-words
-    evaluate first-word, final-word, stack-addr
+    evaluate defs, scratch, final-word, stack-addr
     # render stack
     var curr-row/edx: int <- copy 6  # input-row 3 + stack-margin-top 3
     var _justify-threshold/eax: int <- max-stack-justify-threshold stack-addr
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 4fec403c..79339918 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -1,5 +1,7 @@
-fn evaluate start: (addr word), end: (addr word), out: (addr int-stack) {
-  var curr/eax: (addr word) <- copy start
+fn evaluate defs: (addr function), scratch: (addr line), end: (addr word), out: (addr int-stack) {
+  var line/eax: (addr line) <- copy scratch
+  var word-ah/eax: (addr handle word) <- get line, data
+  var curr/eax: (addr word) <- lookup *word-ah
   var curr-text-storage: (stream byte 0x10)
   var curr-text/edi: (addr stream byte) <- address curr-text-storage
   clear-int-stack out
@@ -61,27 +63,6 @@ fn evaluate start: (addr word), end: (addr word), out: (addr int-stack) {
   }
 }
 
-fn test-evaluate {
-  # input = [1, 2, +]
-  var w: (handle word)
-  var wah/eax: (addr handle word) <- address w
-  allocate wah
-  var wa/eax: (addr word) <- lookup w
-  initialize-word-with wa, "1"
-  append-word-with w, "2"
-  var next/ecx: (addr handle word) <- get wa, next
-  append-word-with *next, "+"
-  # initialize output
-  var stack-storage: int-stack
-  var stack/edx: (addr int-stack) <- address stack-storage
-  initialize-int-stack stack, 0x10
-  #
-  evaluate wa, 0, stack
-  # check output
-  var x/eax: int <- pop-int-stack stack
-  check-ints-equal x, 3, "F - test-evaluate"
-}
-
 # Copy of 'simplify' that just tracks the maximum stack depth needed
 # Doesn't actually need to simulate the stack, since every word has a predictable effect.
 fn max-stack-depth first-word: (addr word), final-word: (addr word) -> result/edi: int {