about summary refs log tree commit diff stats
path: root/060string.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-27 14:56:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-27 14:56:01 -0700
commit7199af30e8fdcdc0848a2e2b90014b98f97998b3 (patch)
tree056cf4c6499071133a5010e3f869c6044ba8096f /060string.mu
parent70763af34945192d04605029339b58b3f3434371 (diff)
downloadmu-7199af30e8fdcdc0848a2e2b90014b98f97998b3.tar.gz
1485 - start of a repl tool
Doesn't actually work interactively yet; for some reason it prints in
color, enter doesn't work, etc.

It'll be interesting to try to add color and history as separate
'layers' using before/after.

I'll also likely have to delete traces for its tests at some point as
they inevitably explode in size.
Diffstat (limited to '060string.mu')
-rw-r--r--060string.mu28
1 files changed, 28 insertions, 0 deletions
diff --git a/060string.mu b/060string.mu
index 480f7db5..227115ad 100644
--- a/060string.mu
+++ b/060string.mu
@@ -279,6 +279,34 @@ recipe integer-to-decimal-string [
   reply result:address:array:character
 ]
 
+recipe buffer-to-array [
+  default-space:address:array:character <- new location:type, 30:literal
+  in:address:buffer <- next-ingredient
+  len:number <- get in:address:buffer/deref, length:offset
+#?   $print [size ], len:number, [ 
+#? ] #? 1
+  s:address:array:character <- get in:address:buffer/deref, data:offset
+  {
+    # propagate null buffer
+    break-if s:address:array:character
+    reply 0:literal
+  }
+  # we can't just return s because it is usually the wrong length
+  result:address:array:character <- new character:type, len:number
+  i:number <- copy 0:literal
+  {
+#?     $print i:number #? 1
+    done?:boolean <- greater-or-equal i:number, len:number
+    break-if done?:boolean
+    src:character <- index s:address:array:character/deref, i:number
+    dest:address:character <- index-address result:address:array:character/deref, i:number
+    dest:address:character/deref <- copy src:character
+    i:number <- add i:number, 1:literal
+    loop
+  }
+  reply result:address:array:character
+]
+
 scenario integer-to-decimal-digit-zero [
   run [
     1:address:array:character/raw <- integer-to-decimal-string 0:literal