about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-20 01:03:39 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-20 01:07:21 -0700
commitc2d537c46b234f03d683f967aafbca20914a72e1 (patch)
tree4c31db55a98a4187605f13284dcfd6550ec4dfe3 /apps
parent0cdbfff25664d2bd3257220ca1509e7bfbd84c75 (diff)
downloadmu-c2d537c46b234f03d683f967aafbca20914a72e1.tar.gz
7080
Constructing new functions with ctrl-d is now working right. But the call
seems exactly flipped.
Diffstat (limited to 'apps')
-rw-r--r--apps/tile/environment.mu48
-rw-r--r--apps/tile/gap-buffer.mu10
-rw-r--r--apps/tile/grapheme-stack.mu19
-rw-r--r--apps/tile/word.mu8
4 files changed, 79 insertions, 6 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 4bfc4cdc..53e7bc63 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -634,18 +634,16 @@ $process-sandbox-define:body: {
 }
 
 # extract from the body of the first function in 'functions' all words that
-# aren't defined in the rest of 'functions'. Append them in order.
+# aren't defined in the rest of 'functions'. Prepend them in reverse order.
 # Assumes function body is a single line for now.
 fn copy-unbound-words-to-args _functions: (addr handle function) {
   # target
   var target-ah/eax: (addr handle function) <- copy _functions
   var _target/eax: (addr function) <- lookup *target-ah
   var target/esi: (addr function) <- copy _target
-  var dest/edi: (addr handle word) <- get target, args
+  var dest-ah/edi: (addr handle word) <- get target, args
   # next
-  var functions-ah/eax: (addr handle function) <- get target, next
-  var _functions/eax: (addr function) <- lookup *functions-ah
-  var functions/ecx: (addr function) <- copy _functions
+  var functions-ah/edx: (addr handle function) <- get target, next
   # src
   var line-ah/eax: (addr handle line) <- get target, body
   var line/eax: (addr line) <- lookup *line-ah
@@ -654,13 +652,51 @@ fn copy-unbound-words-to-args _functions: (addr handle function) {
   {
     compare curr, 0
     break-if-=
-    # HERE
+    {
+      var bound?/ebx: boolean <- bound? curr, functions-ah
+      compare bound?, 0  # false
+      break-if-!=
+      # push copy of curr before dest-ah
+      var rest-h: (handle word)
+      var rest-ah/ecx: (addr handle word) <- address rest-h
+      copy-object dest-ah, rest-ah
+      copy-word curr, dest-ah
+      var dest/eax: (addr word) <- lookup *dest-ah
+      var next-ah/eax: (addr handle word) <- get dest, next
+      copy-object rest-ah, next-ah
+    }
     var next-ah/ecx: (addr handle word) <- get curr, next
     curr <- lookup *next-ah
     loop
   }
 }
 
+fn bound? w: (addr word), functions-ah: (addr handle function) -> result/ebx: boolean {
+  result <- copy 1  # true
+  # if is-decimal-number(w) return true
+  var subresult/eax: boolean <- word-is-decimal-integer? w
+  compare subresult, 0  # false
+  break-if-!=
+  # if w == "+" return true
+  subresult <- word-equal? w, "+"
+  compare subresult, 0  # false
+  break-if-!=
+  # if w == "-" return true
+  subresult <- word-equal? w, "-"
+  compare subresult, 0  # false
+  break-if-!=
+  # if w == "*" return true
+  subresult <- word-equal? w, "*"
+  compare subresult, 0  # false
+  break-if-!=
+  # return w in functions
+  var out-h: (handle function)
+  var out/eax: (addr handle function) <- address out-h
+  callee functions-ah, w, out
+  var found?/eax: (addr function) <- lookup *out
+  result <- copy found?
+}
+
 # construct a call to `f` with copies of exactly its args
 fn construct-call _f-ah: (addr handle function), out: (addr handle word) {
   var f-ah/eax: (addr handle function) <- copy _f-ah
diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu
index a6d6a85e..e694da08 100644
--- a/apps/tile/gap-buffer.mu
+++ b/apps/tile/gap-buffer.mu
@@ -306,3 +306,13 @@ fn copy-gap-buffer _src-ah: (addr handle gap-buffer), _dest-ah: (addr handle gap
   dest <- get dest-a, right
   copy-grapheme-stack src, dest
 }
+
+fn gap-buffer-is-decimal-integer? _self: (addr gap-buffer) -> result/eax: boolean {
+  var self/esi: (addr gap-buffer) <- copy _self
+  var curr/ecx: (addr grapheme-stack) <- get self, left
+  result <- grapheme-stack-is-decimal-integer? curr
+  compare result, 0  # false
+  break-if-=
+  curr <- get self, right
+  result <- grapheme-stack-is-decimal-integer? curr
+}
diff --git a/apps/tile/grapheme-stack.mu b/apps/tile/grapheme-stack.mu
index 3b8d95f9..620e2eda 100644
--- a/apps/tile/grapheme-stack.mu
+++ b/apps/tile/grapheme-stack.mu
@@ -180,3 +180,22 @@ $suffix-match?:body: {
   result <- copy 1   # true
 }
 }
+
+fn grapheme-stack-is-decimal-integer? _self: (addr grapheme-stack) -> result/eax: boolean {
+  var self/esi: (addr grapheme-stack) <- copy _self
+  var data-ah/eax: (addr handle array grapheme) <- get self, data
+  var _data/eax: (addr array grapheme) <- lookup *data-ah
+  var data/edx: (addr array grapheme) <- copy _data
+  var top-addr/ecx: (addr int) <- get self, top
+  var i/ebx: int <- copy 0
+  $grapheme-stack-is-integer?:loop: {
+    compare i, *top-addr
+    break-if->=
+    var g/edx: (addr grapheme) <- index data, i
+    result <- is-decimal-digit? *g
+    compare result, 0  # false
+    break-if-=
+    i <- increment
+    loop
+  }
+}
diff --git a/apps/tile/word.mu b/apps/tile/word.mu
index e9101eb2..e6167820 100644
--- a/apps/tile/word.mu
+++ b/apps/tile/word.mu
@@ -284,6 +284,7 @@ fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) {
   allocate dest-ah
   var _dest-a/eax: (addr word) <- lookup *dest-ah
   var dest-a/eax: (addr word) <- copy _dest-a
+  initialize-word dest-a
   var dest/edi: (addr handle gap-buffer) <- get dest-a, scalar-data
   var src-a/eax: (addr word) <- copy _src-a
   var src/eax: (addr handle gap-buffer) <- get src-a, scalar-data
@@ -346,3 +347,10 @@ fn word-to-string _self: (addr word), out: (addr handle array byte) {
   var data/eax: (addr gap-buffer) <- lookup *data-ah
   gap-buffer-to-string data, out
 }
+
+fn word-is-decimal-integer? _self: (addr word) -> result/eax: boolean {
+  var self/eax: (addr word) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  result <- gap-buffer-is-decimal-integer? data
+}