(and-record trace [ label:string-address contents:string-address ]) (address trace-address (trace)) (array trace-address-array (trace-address)) (address trace-address-array-address (trace-address-array)) (address trace-address-array-address-address (trace-address-array-address)) (and-record instruction-trace [ call-stack:string-address-array-address pc:string-address ; should be integer? instruction:string-address children:trace-address-array-address ]) (address instruction-trace-address (instruction-trace)) (array instruction-trace-address-array (instruction-trace-address)) (address instruction-trace-address-array-address (instruction-trace-address-array)) (function parse-traces [ ; stream-address -> instruction-trace-address-array-address (default-space:space-address <- new space:literal 30:literal) ;? ($print (("parse-traces\n" literal))) ;? 2 (in:stream-address <- next-input) ; check input size ($print (("counting lines\n" literal))) (n:integer <- copy 0:literal) { begin (done?:boolean <- end-of-stream? in:stream-address) (break-if done?:boolean) ;? ($start-tracing) ;? 1 (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) { begin ;? (print?:boolean <- divides? n:integer 100:literal) ;? (break-unless print?:boolean) ($print ((" " literal))) ($print n:integer) ($print (("\n" literal))) } } ;? ($quit) ;? 1 (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 (run:string-address/const <- new "run") ($print (("parsing\n" literal))) (n:integer <- copy 0:literal) ; reading each line from 'in' { begin next-line (done?:boolean <- end-of-stream? in:stream-address) ;? ($print done?:boolean) ;? 1 ;? ($print (("\n" literal))) ;? 1 (break-if done?:boolean) ; parse next line as a generic trace (line:string-address <- read-line in:stream-address) { begin (n:integer <- add n:integer 1:literal) (print?:boolean <- divides? n:integer 100:literal) (break-unless print?:boolean) ($print ((" " literal))) ($print n:integer) ($print (("\n" literal))) } ;? (print-string nil:literal/terminal line:string-address) ;? 1 (f:trace-address <- parse-trace line:string-address) (l:string-address <- get f:trace-address/deref label:offset) { begin ; if it's an instruction trace with label 'run' (inst?:boolean <- string-equal l:string-address run:string-address/const) (break-unless inst?:boolean) ; add accumulated traces to curr-tail { begin (break-unless curr-tail:instruction-trace-address) (c:trace-address-array-address-address <- get-address curr-tail:instruction-trace-address/deref children:offset) (c:trace-address-array-address-address/deref <- to-array ch:buffer-address) ; clear 'ch' (ch:buffer-address <- init-buffer 5:literal) } ; append a new curr-tail to result (curr-tail:instruction-trace-address <- parse-instruction-trace f:trace-address) (result:buffer-address <- append result:buffer-address curr-tail:instruction-trace-address) (jump next-line:offset) ; loop } ; otherwise accumulate trace (loop-unless curr-tail:instruction-trace-address) (ch:buffer-address <- append ch:buffer-address f:trace-address) (loop) } ; add accumulated traces to final curr-tail ; todo: test { begin (break-unless curr-tail:instruction-trace-address) (c:trace-address-array-address-address <- get-address curr-tail:instruction-trace-address/deref children:offset) (c:trace-address-array-address-address/deref <- to-array ch:buffer-address) } (s:instruction-trace-address-array-address <- to-array result:buffer-address) (reply s:instruction-trace-address-array-address) ]) (function parse-instruction-trace [ ; trace-address -> instruction-trace-address (default-space:space-address <- new space:literal 30:literal) ;? ($print (("parse-instruction-trace\n" literal))) ;? 1 (in:trace-address <- next-input) (buf:string-address <- get in:trace-address/deref contents:offset) ;? (print-string nil:literal buf:string-address) ;? 1 ;? ($print (("\n" literal))) ;? 1 (result:instruction-trace-address <- new instruction-trace:literal) (f1:string-address rest:string-address <- split-first buf:string-address ((#\space literal))) ;? ($print (("call-stack: " literal))) ;? 1 ;? (print-string nil:literal f1:string-address) ;? 1 ;? ($print (("\n" literal))) ;? 1 (cs:string-address-array-address-address <- get-address result:instruction-trace-address/deref call-stack:offset) (cs:string-address-array-address-address/deref <- split
getwtxt
*.log
local/
*.db/