about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-12 10:10:31 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-12 10:10:31 -0700
commit598f942624cb162132b7f7c2b7858516d95e73c4 (patch)
tree7297deaa106fc59ba00a739c4d725c71f68125a6
parent855431280d047000c8f90868603025631a0f3c5b (diff)
downloadmu-598f942624cb162132b7f7c2b7858516d95e73c4.tar.gz
7010
A new example that better demonstrates the value of named arguments.
-rw-r--r--apps/tile/data.mu43
-rw-r--r--apps/tile/environment.mu2
2 files changed, 44 insertions, 1 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index adf9ac6a..b7ed36d6 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -177,7 +177,7 @@ fn create-primitive-functions _self: (addr handle function) {
   var next/esi: (addr handle function) <- get f, next
   allocate next
   var _f/eax: (addr function) <- lookup *next
-  var f/ecx: (addr function) <- copy _f
+  var f/esi: (addr function) <- copy _f
   var name-ah/eax: (addr handle array byte) <- get f, name
   populate-text-with name-ah, "2+"
   var args-ah/eax: (addr handle word) <- get f, args
@@ -214,6 +214,47 @@ fn create-primitive-functions _self: (addr handle function) {
   prev-word-ah <- get tmp, prev
   copy-object curr-word-ah, prev-word-ah
   tmp <- lookup *prev-word-ah
+  # x square = x x *
+  var next/esi: (addr handle function) <- get f, next
+  allocate next
+  var _f/eax: (addr function) <- lookup *next
+  var f/esi: (addr function) <- copy _f
+  var name-ah/eax: (addr handle array byte) <- get f, name
+  populate-text-with name-ah, "square"
+  var args-ah/eax: (addr handle word) <- get f, args
+  allocate args-ah
+  var args/eax: (addr word) <- lookup *args-ah
+  initialize-word-with args, "x"
+  var body-ah/eax: (addr handle line) <- get f, body
+  allocate body-ah
+  var body/eax: (addr line) <- lookup *body-ah
+  initialize-line body
+  var curr-word-ah/ecx: (addr handle word) <- get body, data
+  # *curr-word = "x"
+  allocate curr-word-ah
+  var tmp/eax: (addr word) <- lookup *curr-word-ah
+  var curr-word/edx: (addr word) <- copy tmp
+  initialize-word-with curr-word, "x"
+  # *curr-word->next = "x"
+  var next-word-ah/ebx: (addr handle word) <- get curr-word, next
+  allocate next-word-ah
+  tmp <- lookup *next-word-ah
+  initialize-word-with tmp, "x"
+  # *curr-word->next->prev = curr-word
+  var prev-word-ah/edi: (addr handle word) <- get tmp, prev
+  copy-object curr-word-ah, prev-word-ah
+  # curr-word = curr-word->next
+  curr-word-ah <- copy next-word-ah
+  curr-word <- copy tmp
+  # *curr-word->next = "*"
+  next-word-ah <- get curr-word, next
+  allocate next-word-ah
+  tmp <- lookup *next-word-ah
+  initialize-word-with tmp, "*"
+  # *curr-word->next->prev = curr-word
+  prev-word-ah <- get tmp, prev
+  copy-object curr-word-ah, prev-word-ah
+  tmp <- lookup *prev-word-ah
 }
 
 fn function-body functions: (addr handle function), _word: (addr handle word), out: (addr handle line) {
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index c0cdb2f7..58168673 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -868,6 +868,8 @@ fn clear-canvas _env: (addr environment) {
   print-string screen, "x 1+ = x 1 +"
   move-cursor screen, 5, 2
   print-string screen, "x 2+ = x 1+ 1+"
+  move-cursor screen, 6, 2
+  print-string screen, "x square = x x *"
 }
 
 fn real-grapheme? g: grapheme -> result/eax: boolean {