about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-12 17:03:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-12 17:03:29 -0700
commit43867ac84972c4b031c49dcec3246411def72143 (patch)
tree0ad251e0516272712580e8c4303cd80ba8feba9b
parentfeb8a5b7805d6f28bbe19ec6e66f6ce24b75b155 (diff)
downloadmu-43867ac84972c4b031c49dcec3246411def72143.tar.gz
895
-rw-r--r--mu.arc18
-rw-r--r--trace.mu20
2 files changed, 37 insertions, 1 deletions
diff --git a/mu.arc b/mu.arc
index d5b98b97..ff5de4a6 100644
--- a/mu.arc
+++ b/mu.arc
@@ -2470,6 +2470,14 @@
   (reply result:stream-address)
 )
 
+(init-fn rewind-stream
+  (default-space:space-address <- new space:literal 30:literal)
+  (in:stream-address <- next-input)
+  (x:integer-address <- get-address in:stream-address/deref pointer:offset)
+  (x:integer-address/deref <- copy 0:literal)
+  (reply in:stream-address/same-as-arg:0)
+)
+
 (init-fn read-line
   (default-space:space-address <- new space:literal 30:literal)
   (in:stream-address <- next-input)
@@ -2490,6 +2498,16 @@
   (reply result:string-address)
 )
 
+(init-fn read-character
+  (default-space:space-address <- new space:literal 30:literal)
+  (in:stream-address <- next-input)
+  (idx:integer-address <- get-address in:stream-address/deref pointer:offset)
+  (s:string-address <- get in:stream-address/deref data:offset)
+  (c:character <- index s:string-address/deref idx:integer-address/deref)
+  (idx:integer-address/deref <- add idx:integer-address/deref 1:literal)
+  (reply c:character)
+)
+
 (init-fn end-of-stream?
   (default-space:space-address <- new space:literal 30:literal)
   (in:stream-address <- next-input)
diff --git a/trace.mu b/trace.mu
index 09664092..ad8c306c 100644
--- a/trace.mu
+++ b/trace.mu
@@ -21,6 +21,23 @@
   (default-space:space-address <- new space:literal 30:literal)
 ;?   ($print (("parse-traces\n" literal))) ;? 2
   (in:stream-address <- next-input)
+  ; check input size
+  (n:integer <- copy 0:literal)
+  { begin
+    (done?:boolean <- end-of-stream? in:stream-address)
+    (break-if done?:boolean)
+    (c:character <- read-character in:stream-address)
+    { begin
+      (newline?:boolean <- equal c:character ((#\newline literal)))
+      (break-unless newline?:boolean)
+      (n:integer <- add n:integer 1:literal)
+    }
+    (loop)
+  }
+  ($print n:integer)
+  ($print ((" lines\n" literal)))
+  (in:stream-address <- rewind-stream in:stream-address)
+  ; prepare result
   (result:buffer-address <- init-buffer 30:literal)
   (curr-tail:instruction-trace-address <- copy nil:literal)
   (ch:buffer-address <- init-buffer 5:literal)  ; accumulator for traces between instructions
@@ -1012,9 +1029,10 @@
 
 (function browse-trace [
   (default-space:space-address <- new space:literal 30:literal/capacity)
-  ($print (("parsing trace... (might take a while, depending on how long the trace is\n" literal)))
+  ($print (("parsing trace... (might take a while, depending on how long the trace is)\n" literal)))
   (x:string-address <- next-input)
   (screen-height:integer <- next-input)
+;?   (print-string nil:literal/terminal x:string-address) ;? 1
   (s:stream-address <- init-stream x:string-address)
   (traces:instruction-trace-address-array-address <- parse-traces s:stream-address)
   (0:space-address/names:browser-state <- browser-state traces:instruction-trace-address-array-address screen-height:integer)