about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--color-repl.mu8
-rw-r--r--mu.arc37
2 files changed, 41 insertions, 4 deletions
diff --git a/color-repl.mu b/color-repl.mu
index 69ca7651..c5686484 100644
--- a/color-repl.mu
+++ b/color-repl.mu
@@ -10,7 +10,7 @@
   (default-space:space-address <- new space:literal 30:literal)
   (abort:continuation <- next-input)
   (history:buffer-address <- next-input)  ; buffer of strings
-  (result:buffer-address <- init-buffer 3:literal)  ; string to maybe add to
+  (result:buffer-address <- init-buffer 10:literal)  ; string to maybe add to
   (open-parens:integer <- copy 0:literal)  ; for balancing parens and tracking nesting depth
   ; we can change color when backspacing over parens or comments or strings,
   ; but we need to know that they aren't escaped
@@ -24,7 +24,8 @@
     (c:character <- $wait-for-key-from-host)
     (done?:boolean <- process-key default-space:space-address c:character)
   }
-  (s:string-address <- get result:buffer-address/deref data:offset)
+  ; test: 3<enter> => size of s is 2
+  (s:string-address <- to-array result:buffer-address)
   (reply s:string-address)
 ])
 
@@ -370,6 +371,9 @@
   { begin
     (s:string-address <- read-expression abort:continuation history:buffer-address)
     (break-unless s:string-address)
+;?     (x:integer <- length s:string-address/deref) ;? 1
+;?     (print-primitive-to-host x:integer) ;? 1
+;?     (print-primitive-to-host ((#\newline literal))) ;? 1
     (history:buffer-address <- append history:buffer-address s:string-address)
     (len:integer <- get history:buffer-address/deref length:offset)
     (print-primitive-to-host len:integer)
diff --git a/mu.arc b/mu.arc
index 7d195bb7..5ff72949 100644
--- a/mu.arc
+++ b/mu.arc
@@ -160,6 +160,8 @@
               character-address (obj size 1  address t  elem '(character))
               ; a buffer makes it easy to append to a string/array
               ; todo: make this generic
+              ; data isn't a 'real' array: its length is stored outside it,
+              ; so for example, 'print-string' won't work on it.
               buffer (obj size 2  and-record t  elems '((integer) (string-address))  fields '(length data))
               buffer-address (obj size 1  address t  elem '(buffer))
               ; isolating function calls
@@ -447,6 +449,8 @@
   (cdr operand.0))
 
 (def literal? (operand)
+  (unless (acons ty.operand)
+    (err "no type in operand @operand"))
   (in ty.operand.0 'literal 'offset 'fn))
 
 (def typeinfo (operand)
@@ -2392,6 +2396,35 @@
   (reply result:boolean)
 )
 
+(init-fn to-array  ; from buffer
+  (default-space:space-address <- new space:literal 30:literal)
+  (in:buffer-address <- next-input)
+  (len:integer <- get in:buffer-address/deref length:offset)
+  (s:string-address <- get in:buffer-address/deref data:offset)
+  { begin
+    ; test: ctrl-d -> s is nil -> to-array returns nil -> read-expression returns t -> exit repl
+    (break-if s:string-address)
+    (reply nil:literal)
+  }
+  ; we can't just return s because it is usually the wrong length
+  (result:string-address <- new string:literal len:integer)
+  (i:integer <- copy 0:literal)
+  { begin
+    (done?:boolean <- greater-or-equal i:integer len:integer)
+    (break-if done?:boolean)
+    (src:byte <- index s:string-address/deref i:integer)
+;?     (foo:integer <- character-to-integer src:byte) ;? 1
+;?     (print-primitive-to-host (("a: " literal))) ;? 1
+;?     (print-primitive-to-host foo:integer) ;? 1
+;?     (print-primitive-to-host ((#\newline literal))) ;? 1
+    (dest:byte-address <- index-address result:string-address/deref i:integer)
+    (dest:byte-address/deref <- copy src:byte)
+    (i:integer <- add i:integer 1:literal)
+    (loop)
+  }
+  (reply result:string-address)
+)
+
 (init-fn append
   (default-space:space-address <- new space:literal 30:literal)
   (in:buffer-address <- next-input)
@@ -2546,11 +2579,11 @@
 ;? (new-trace "main") ;? 4
 (awhen (pos "--" argv)
   (map add-code:readfile (cut argv (+ it 1)))
-;?   (= dump-trace* (obj whitelist '("run")))
+;?   (= dump-trace* (obj whitelist '("run"))) ;? 1
 ;?   (= dump-trace* (obj whitelist '("schedule")))
 ;?   (= dump-trace* (obj whitelist '("run" "continuation"))) ;? 1
 ;?   (= dump-trace* (obj whitelist '("cn0" "cn1")))
-;?   (set dump-trace*) ;? 1
+;?   (set dump-trace*) ;? 2
 ;?   (freeze function*)
 ;?   (prn function*!factorial)
   (run 'main)