diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-02-01 00:15:43 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-02-01 00:15:43 -0800 |
commit | 7d2c2d55e83325a5efb66af0a033b94583fca70e (patch) | |
tree | 0bade19ad9230f2aa6076440548b50456c9f6fd8 | |
parent | 48a74397fb1a967fffa67ffb80005d94ed2ac60c (diff) | |
download | mu-7d2c2d55e83325a5efb66af0a033b94583fca70e.tar.gz |
690 - convention: '$' commands for debugging only
Swap printing generalized objects using arc's infrastructure to be the $-prefixed debug helper, while the erstwhile $print-key-to-host becomes the primitive print-character to host.
-rw-r--r-- | buffered-stdin.mu | 7 | ||||
-rw-r--r-- | callcc.mu | 2 | ||||
-rw-r--r-- | channel.mu | 8 | ||||
-rw-r--r-- | chessboard.mu | 37 | ||||
-rw-r--r-- | color-repl.mu | 97 | ||||
-rw-r--r-- | counters.mu | 6 | ||||
-rw-r--r-- | factorial.mu | 4 | ||||
-rw-r--r-- | generic.mu | 4 | ||||
-rw-r--r-- | graphics.mu | 15 | ||||
-rw-r--r-- | mu.arc | 199 | ||||
-rw-r--r-- | repl.mu | 12 | ||||
-rw-r--r-- | stdin.mu | 19 | ||||
-rw-r--r-- | tangle.mu | 4 |
13 files changed, 206 insertions, 208 deletions
diff --git a/buffered-stdin.mu b/buffered-stdin.mu index 3f4030b9..66ad4aca 100644 --- a/buffered-stdin.mu +++ b/buffered-stdin.mu @@ -3,7 +3,6 @@ (function main [ (default-space:space-address <- new space:literal 30:literal) (cursor-mode) ;? 1 - (clear-screen) ;? 1 ; hook up stdin (stdin:channel-address <- init-channel 1:literal) (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address) @@ -17,9 +16,9 @@ { begin (x:tagged-value buffered-stdin:channel-address/deref <- read buffered-stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) -;? (print-primitive-to-host (("AAA " literal))) ;? 1 -;? (print-primitive-to-host c:character) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("AAA " literal))) ;? 1 +;? ($print c:character) ;? 1 +;? ($print (("\n" literal))) ;? 1 (print-character nil:literal/terminal c:character) (line-done?:boolean <- equal c:character ((#\newline literal))) (loop-unless line-done?:boolean) diff --git a/callcc.mu b/callcc.mu index c0c48ef6..20dffeff 100644 --- a/callcc.mu +++ b/callcc.mu @@ -5,7 +5,7 @@ (function g [ (c:continuation <- current-continuation) ; <-- loop back to here - (print-primitive-to-host (("a" literal))) + (print-character nil:literal/terminal ((#\a literal))) (reply c:continuation) ]) diff --git a/channel.mu b/channel.mu index 88055398..61151833 100644 --- a/channel.mu +++ b/channel.mu @@ -8,9 +8,9 @@ (done?:boolean <- less-than n:integer 5:literal) (break-unless done?:boolean) ; other threads might get between these prints - (print-primitive-to-host (("produce: " literal))) + ($print (("produce: " literal))) (print-integer nil:literal/terminal n:integer) - (print-primitive-to-host (("\n" literal))) + ($print (("\n" literal))) ; 'box' n into a dynamically typed 'tagged value' because that's what ; channels take (n2:integer <- copy n:integer) @@ -31,9 +31,9 @@ ; unbox the tagged value into an integer (n2:integer <- maybe-coerce x:tagged-value integer:literal) ; other threads might get between these prints - (print-primitive-to-host (("consume: " literal))) + ($print (("consume: " literal))) (print-integer nil:literal/terminal n2:integer) - (print-primitive-to-host (("\n" literal))) + ($print (("\n" literal))) (loop) } ]) diff --git a/chessboard.mu b/chessboard.mu index b26401ab..9c7c737d 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -128,14 +128,14 @@ (default-space:space-address <- new space:literal 30:literal) (stdin:channel-address <- next-input) (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address) -;? (print-primitive-to-host x:tagged-value) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print x:tagged-value) ;? 1 +;? ($print (("\n" literal))) ;? 1 (a:character <- copy ((#\a literal))) (file-base:integer <- character-to-integer a:character) (c:character <- maybe-coerce x:tagged-value character:literal) -;? (print-primitive-to-host (("AAA " literal))) ;? 1 -;? (print-primitive-to-host c:character) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("AAA " literal))) ;? 1 +;? ($print c:character) ;? 1 +;? ($print (("\n" literal))) ;? 1 { begin (quit:boolean <- equal c:character ((#\q literal))) (break-unless quit:boolean) @@ -156,9 +156,9 @@ (stdin:channel-address <- next-input) (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) -;? (print-primitive-to-host (("BBB " literal))) ;? 1 -;? (print-primitive-to-host c:character) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("BBB " literal))) ;? 1 +;? ($print c:character) ;? 1 +;? ($print (("\n" literal))) ;? 1 { begin (quit:boolean <- equal c:character ((#\q literal))) (break-unless quit:boolean) @@ -224,32 +224,29 @@ ; buffer stdin (buffered-stdin:channel-address <- init-channel 1:literal) (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address) + ($print (("Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves." literal))) + (cursor-to-next-line nil:literal/terminal) { begin - ; print any stray characters from keyboard *before* clearing screen - (clear-screen nil:literal/terminal) - (print-primitive-to-host (("Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves." literal))) - (cursor-to-next-line nil:literal/terminal) (cursor-to-next-line nil:literal/terminal) (print-board nil:literal/terminal b:board-address) (cursor-to-next-line nil:literal/terminal) - (print-primitive-to-host (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>." literal))) + ($print (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>." literal))) (cursor-to-next-line nil:literal/terminal) - (print-primitive-to-host (("Hit 'q' to exit." literal))) + ($print (("Hit 'q' to exit." literal))) (cursor-to-next-line nil:literal/terminal) - (print-primitive-to-host (("move: " literal))) + ($print (("move: " literal))) (m:move-address <- read-move buffered-stdin:channel-address) ;? (retro-mode) ;? 1 -;? (print-primitive-to-host stdin:channel-address) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 -;? (print-primitive-to-host buffered-stdin:channel-address) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print stdin:channel-address) ;? 1 +;? ($print (("\n" literal))) ;? 1 +;? ($print buffered-stdin:channel-address) ;? 1 +;? ($print (("\n" literal))) ;? 1 ;? ($dump-memory) ;? 1 ;? (cursor-mode) ;? 1 (break-unless m:move-address) (b:board-address <- make-move b:board-address m:move-address) (loop) } - (cursor-to-next-line) ]) ; todo: diff --git a/color-repl.mu b/color-repl.mu index a2ae9ab3..9dabac3b 100644 --- a/color-repl.mu +++ b/color-repl.mu @@ -45,9 +45,9 @@ (default-space:space-address/names:read-expression <- next-input) (c:character <- next-input) (len:integer-address <- get-address result:buffer-address/deref length:offset) -;? (print-primitive-to-host 1:literal) ;? 2 +;? ($print 1:literal) ;? 2 (maybe-cancel-this-expression c:character abort:continuation) -;? (print-primitive-to-host 2:literal) ;? 2 +;? ($print 2:literal) ;? 2 ; check for ctrl-d and exit { begin (eof?:boolean <- equal c:character ((ctrl-d literal))) @@ -57,14 +57,14 @@ (s:string-address-address/deref <- copy nil:literal) (reply t:literal) } -;? (print-primitive-to-host 3:literal) ;? 2 +;? ($print 3:literal) ;? 2 ; check for backspace ; test: 3<backspace>4<enter> ; todo: backspace past newline { begin (backspace?:boolean <- equal c:character ((#\backspace literal))) (break-unless backspace?:boolean) - ($print-key-to-host c:character) + (print-character-to-host c:character) { begin ; delete last character if any (zero?:boolean <- lesser-or-equal len:integer-address/deref 0:literal) @@ -125,7 +125,7 @@ { begin (done?:boolean <- lesser-or-equal len:integer-address/deref 0:literal) (break-if done?:boolean) - ($print-key-to-host ((#\backspace literal))) + (print-character-to-host ((#\backspace literal))) (len:integer-address/deref <- subtract len:integer-address/deref 1:literal) (loop) } @@ -138,31 +138,31 @@ (current-history-index:integer <- subtract current-history-index:integer 1:literal) (curr-history:string-address <- buffer-index history:buffer-address current-history-index:integer) (curr-history-len:integer <- length curr-history:string-address/deref) -;? (print-primitive-to-host curr-history-len:integer) ;? 2 +;? ($print curr-history-len:integer) ;? 2 ;? (cursor-to-next-line) ;? 1 ;? ($quit) ;? 1 ;? ($dump-trace "before-retype") ;? 1 ; and retype it into the current expression (i:integer <- copy 0:literal) { begin -;? (print-primitive-to-host i:integer) ;? 1 +;? ($print i:integer) ;? 1 ;? (cursor-to-next-line) ;? 1 (done?:boolean <- greater-or-equal i:integer curr-history-len:integer) (break-if done?:boolean) -;? (print-primitive-to-host i:integer) ;? 1 +;? ($print i:integer) ;? 1 ;? (cursor-to-next-line) ;? 1 ;? ($dump-trace "retype-iter") ;? 1 -;? (print-primitive-to-host (("aaa: " literal))) ;? 1 -;? (print-primitive-to-host curr-history:string-address) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("aaa: " literal))) ;? 1 +;? ($print curr-history:string-address) ;? 1 +;? ($print (("\n" literal))) ;? 1 ;? ($dump-memory) ;? 1 ;? ($start-tracing) ;? 1 ; no more access to current character (c:character <- index curr-history:string-address/deref i:integer) ;? ($quit) ;? 1 ;? ($dump-trace "retype-iter2") ;? 1 -;? (print-primitive-to-host c:character) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print c:character) ;? 1 +;? ($print (("\n" literal))) ;? 1 ; recursive calls to process-key can clobber any local state except i, ; which we won't touch because history strings are guaranteed to only ; have printable characters, never <up> or <down> @@ -182,32 +182,32 @@ { begin (newline?:boolean <- equal c:character ((#\newline literal))) (break-unless newline?:boolean) - ($print-key-to-host c:character) + (print-character-to-host c:character) (at-top-level?:boolean <- lesser-or-equal open-parens:integer 0:literal) (end-expression?:boolean <- and at-top-level?:boolean not-empty?:boolean) (reply end-expression?:boolean) } -;? (print-primitive-to-host 4:literal) ;? 2 +;? ($print 4:literal) ;? 2 ; printable character; save -;? (print-primitive-to-host (("append\n" literal))) ;? 2 +;? ($print (("append\n" literal))) ;? 2 (result:buffer-address <- append result:buffer-address c:character) -;? (print-primitive-to-host (("done\n" literal))) ;? 2 +;? ($print (("done\n" literal))) ;? 2 ; if it's backslash, read, save and print one additional character ; test: (prn #\() -;? (print-primitive-to-host 5:literal) ;? 2 +;? ($print 5:literal) ;? 2 { begin (backslash?:boolean <- equal c:character ((#\\ literal))) (break-unless backslash?:boolean) - ($print-key-to-host c:character 7:literal/white) + (print-character-to-host c:character 7:literal/white) (result:buffer-address escapes:buffer-address <- slurp-escaped-character result:buffer-address 7:literal/white escapes:buffer-address abort:continuation) (reply nil:literal) } -;? (print-primitive-to-host 6:literal) ;? 2 +;? ($print 6:literal) ;? 2 ; if it's a semi-colon, parse a comment { begin (comment?:boolean <- equal c:character ((#\; literal))) (break-unless comment?:boolean) - ($print-key-to-host c:character 4:literal/fg/blue) + (print-character-to-host c:character 4:literal/fg/blue) (comment-read?:boolean <- slurp-comment result:buffer-address escapes:buffer-address abort:continuation) ; return if comment was read (i.e. consumed a newline) ; test: ;a<backspace><backspace> (shouldn't end command until <enter>) @@ -224,7 +224,7 @@ (end-expression?:boolean <- and at-top-level?:boolean not-empty?:boolean) (reply end-expression?:boolean) } -;? (print-primitive-to-host 7:literal) ;? 2 +;? ($print 7:literal) ;? 2 ; if it's not whitespace, set not-empty? and continue { begin (space?:boolean <- equal c:character ((#\space literal))) @@ -236,16 +236,16 @@ (not-empty?:boolean <- copy t:literal) ; fall through } -;? (print-primitive-to-host 8:literal) ;? 2 +;? ($print 8:literal) ;? 2 ; if it's a quote, parse a string { begin (string-started?:boolean <- equal c:character ((#\" literal))) ; for vim: " (break-unless string-started?:boolean) - ($print-key-to-host c:character 6:literal/fg/cyan) + (print-character-to-host c:character 6:literal/fg/cyan) (slurp-string result:buffer-address escapes:buffer-address abort:continuation) (reply nil:literal) } -;? (print-primitive-to-host 9:literal) ;? 2 +;? ($print 9:literal) ;? 2 ; color parens by depth, so they're easy to balance ; test: (+ 1 1)<enter> ; test: (def foo () (+ 1 (* 2 3)))<enter> @@ -254,25 +254,25 @@ (break-unless open-paren?:boolean) (_ color-code:integer <- divide-with-remainder open-parens:integer 3:literal) ; 3 distinct colors for parens (color-code:integer <- add color-code:integer 1:literal) - ($print-key-to-host c:character color-code:integer) + (print-character-to-host c:character color-code:integer) (open-parens:integer <- add open-parens:integer 1:literal) -;? (print-primitive-to-host open-parens:integer) ;? 2 +;? ($print open-parens:integer) ;? 2 (reply nil:literal) } -;? (print-primitive-to-host 10:literal) ;? 2 +;? ($print 10:literal) ;? 2 { begin (close-paren?:boolean <- equal c:character ((#\) literal))) (break-unless close-paren?:boolean) (open-parens:integer <- subtract open-parens:integer 1:literal) (_ color-code:integer <- divide-with-remainder open-parens:integer 3:literal) ; 3 distinct colors for parens (color-code:integer <- add color-code:integer 1:literal) - ($print-key-to-host c:character color-code:integer) -;? (print-primitive-to-host open-parens:integer) ;? 2 + (print-character-to-host c:character color-code:integer) +;? ($print open-parens:integer) ;? 2 (reply nil:literal) } -;? (print-primitive-to-host 11:literal) ;? 2 +;? ($print 11:literal) ;? 2 ; if all else fails, print the character without color - ($print-key-to-host c:character) + (print-character-to-host c:character) ; todo: error on space outside parens, like python ; todo: [] ; todo: history on up/down @@ -291,7 +291,7 @@ next-key-in-comment (c:character <- $wait-for-key-from-host) (maybe-cancel-this-expression c:character abort:continuation) ; test: check needs to come before print - ($print-key-to-host c:character 4:literal/fg/blue) + (print-character-to-host c:character 4:literal/fg/blue) ; handle backspace ; test: ; abc<backspace><backspace>def<enter> ; todo: how to exit comment? @@ -323,7 +323,7 @@ next-key-in-string (c:character <- $wait-for-key-from-host) (maybe-cancel-this-expression c:character abort:continuation) ; test: check needs to come before print - ($print-key-to-host c:character 6:literal/fg/cyan) + (print-character-to-host c:character 6:literal/fg/cyan) ; handle backspace ; test: "abc<backspace>d" ; todo: how to exit string? @@ -336,7 +336,7 @@ ; if we erase start of string, return ; test: "<backspace>34 (string-deleted?:boolean <- backspaced-over-unescaped? in:buffer-address ((#\" literal)) escapes:buffer-address) ; " -;? (print-primitive-to-host string-deleted?:boolean) ;? 1 +;? ($print string-deleted?:boolean) ;? 1 (jump-if string-deleted?:boolean end:offset) (jump next-key-in-string:offset) } @@ -365,10 +365,10 @@ (abort:continuation <- next-input) (c:character <- $wait-for-key-from-host) (maybe-cancel-this-expression c:character abort:continuation) ; test: check needs to come before print - ($print-key-to-host c:character color-code:integer) + (print-character-to-host c:character color-code:integer) (len:integer-address <- get-address in:buffer-address/deref length:offset) (escapes:buffer-address <- append escapes:buffer-address len:integer-address/deref) -;? (print-primitive-to-host (("+" literal))) ;? 1 +;? ($print (("+" literal))) ;? 1 ; handle backspace ; test: "abc\<backspace>def" ; test: #\<backspace> @@ -379,7 +379,7 @@ (len:integer-address/deref <- subtract len:integer-address/deref 1:literal) (elen:integer-address <- get-address escapes:buffer-address/deref length:offset) (elen:integer-address/deref <- subtract elen:integer-address/deref 1:literal) -;? (print-primitive-to-host (("-" literal))) ;? 1 +;? ($print (("-" literal))) ;? 1 (reply in:buffer-address/same-as-arg:0 escapes:buffer-address/same-as-arg:2) } ; if not backspace, save and return @@ -403,8 +403,8 @@ { begin (most-recent-escape:integer <- last escapes:buffer-address) (last-idx:integer <- get in:buffer-address/deref length:offset) -;? (print-primitive-to-host most-recent-escape:integer) ;? 1 -;? (print-primitive-to-host last-idx:integer) ;? 1 +;? ($print most-recent-escape:integer) ;? 1 +;? ($print last-idx:integer) ;? 1 (was-unescaped?:boolean <- not-equal last-idx:integer most-recent-escape:integer) (break-if was-unescaped?:boolean) (reply nil:literal) @@ -436,8 +436,9 @@ { begin (interrupt?:boolean <- equal c:character ((ctrl-g literal))) (break-unless interrupt?:boolean) - ($print-key-to-host (("^G" literal))) - ($print-key-to-host ((#\newline literal))) + (print-character-to-host ((#\^ literal))) + (print-character-to-host ((#\G literal))) + (print-character-to-host ((#\newline literal))) (continue-from abort:continuation) } ]) @@ -445,7 +446,7 @@ (function main [ (default-space:space-address <- new space:literal 30:literal) (cursor-mode) - (print-primitive-to-host (("connected to anarki! type in an expression, then hit enter. ctrl-d exits. ctrl-g clears the current expression." literal))) + ($print (("connected to anarki! type in an expression, then hit enter. ctrl-d exits. ctrl-g clears the current expression." literal))) (print-character nil:literal/terminal ((#\newline literal))) (abort:continuation <- current-continuation) (history:buffer-address <- init-buffer 5:literal) ; buffer of buffers of strings, one per expression typed in @@ -453,17 +454,17 @@ (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 +;? ($print x:integer) ;? 1 +;? ($print ((#\newline literal))) ;? 1 (history:buffer-address <- append history:buffer-address s:string-address) ;? (len:integer <- get history:buffer-address/deref length:offset) ;? 1 -;? (print-primitive-to-host len:integer) ;? 1 -;? (print-primitive-to-host ((#\newline literal))) ;? 1 +;? ($print len:integer) ;? 1 +;? ($print ((#\newline literal))) ;? 1 (retro-mode) ; print errors cleanly ;? (print-string nil:literal/terminal s:string-address) ;? 1 (t:string-address <- $eval s:string-address) (cursor-mode) - (print-primitive-to-host (("=> " literal))) + ($print (("=> " literal))) (print-string nil:literal/terminal t:string-address) (print-character nil:literal/terminal ((#\newline literal))) (print-character nil:literal/terminal ((#\newline literal))) ; empty line separates each expression and result diff --git a/counters.mu b/counters.mu index 0b7a4882..0e414513 100644 --- a/counters.mu +++ b/counters.mu @@ -23,11 +23,11 @@ (bres:integer <- increment-counter b:space-address 2:literal) (ares:integer <- increment-counter a:space-address 1:literal) ; check results - (print-primitive-to-host (("Contents of counters a: " literal))) + ($print (("Contents of counters a: " literal))) (print-integer nil:literal/terminal ares:integer) - (print-primitive-to-host ((" b: " literal))) + ($print ((" b: " literal))) (print-integer nil:literal/terminal bres:integer) - (print-primitive-to-host (("\n" literal))) + ($print (("\n" literal))) ]) ; compare http://www.paulgraham.com/accgen.html diff --git a/factorial.mu b/factorial.mu index 67448595..96a28fd3 100644 --- a/factorial.mu +++ b/factorial.mu @@ -16,7 +16,7 @@ (function main [ (1:integer <- factorial 5:literal) - (print-primitive-to-host (("result: " literal))) + ($print (("result: " literal))) (print-integer nil:literal/terminal 1:integer) - (print-primitive-to-host (("\n" literal))) + ($print (("\n" literal))) ]) diff --git a/generic.mu b/generic.mu index 4c2cd958..1c4b9bb0 100644 --- a/generic.mu +++ b/generic.mu @@ -24,7 +24,7 @@ (function main [ (1:integer <- factorial 5:literal) - (print-primitive-to-host (("result: " literal))) + ($print (("result: " literal))) (print-integer nil:literal/terminal 1:integer) - (print-primitive-to-host (("\n" literal))) + ($print (("\n" literal))) ]) diff --git a/graphics.mu b/graphics.mu index 191e5d8e..f25395ef 100644 --- a/graphics.mu +++ b/graphics.mu @@ -7,15 +7,16 @@ (loop-unless click?:boolean) (x:integer <- get pos:integer-integer-pair 0:offset) (y:integer <- get pos:integer-integer-pair 1:offset) -;? (print-primitive-to-host (("AAA " literal))) -;? (print-primitive-to-host x:integer) -;? (print-primitive-to-host ((", " literal))) -;? (print-primitive-to-host y:integer) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("AAA " literal))) +;? ($print x:integer) +;? ($print ((", " literal))) +;? ($print y:integer) +;? ($print (("\n" literal))) (print-integer nil:literal/terminal x:integer) - (print-primitive-to-host ((", " literal))) + (print-character nil:literal/terminal ((#\, literal))) + (print-character nil:literal/terminal ((#\space literal))) (print-integer nil:literal/terminal y:integer) - (print-primitive-to-host (("\n" literal))) + (print-character nil:literal/terminal ((#\newline literal))) (loop) } (window-off) diff --git a/mu.arc b/mu.arc index fadae49a..929ebcbd 100644 --- a/mu.arc +++ b/mu.arc @@ -685,8 +685,9 @@ (do1 nil ($.charterm-cursor (m arg.0) (m arg.1))) cursor-on-host-to-next-line (do1 nil ($.charterm-newline)) - print-primitive-to-host + print-character-to-host (do1 nil + (assert (isa (m arg.0) 'char)) ;? (write (m arg.0)) (pr " => ") (prn (type (m arg.0))) (if (no ($.current-charterm)) (pr (m arg.0)) @@ -703,7 +704,20 @@ (do ($.close-charterm) (die "interrupted")) ;else - ($.charterm-display x))) + (if (len> arg 2) + (do + ($.foreground (m arg.1)) + ($.background (m arg.2)) + (pr x) + ($.reset)) + (len> arg 1) + (do + ($.foreground (m arg.1)) + (pr x) + ($.reset)) +;? (print-with-fg x (m arg.1)) ;? 1 + :else + ($.charterm-display x)))) ) read-key-from-host (if ($.current-charterm) @@ -806,7 +820,7 @@ backspace (= result #\backspace) ))) - $print-key-to-host + $print (do1 nil ;? (write (m arg.0)) (pr " => ") (prn (type (m arg.0))) (if (no ($.current-charterm)) @@ -824,20 +838,7 @@ (do ($.close-charterm) (die "interrupted")) ;else - (if (len> arg 2) - (do - ($.foreground (m arg.1)) - ($.background (m arg.2)) - (pr x) - ($.reset)) - (len> arg 1) - (do - ($.foreground (m arg.1)) - (pr x) - ($.reset)) -;? (print-with-fg x (m arg.1)) ;? 1 - :else - ($.charterm-display x)))) + ($.charterm-display x))) ) $eval (new-string:repr:eval:read:to-arc-string (m arg.0)) @@ -1754,7 +1755,7 @@ ;? (reply 0:literal) ;? } ;? ; else return 1+length(curr.cdr) -;? ;? (print-primitive-to-host (("recurse\n" literal))) +;? ;? ($print (("recurse\n" literal))) ;? (next:list-address <- list-next curr:list-address) ;? (sub:integer <- list-length next:list-address) ;? (result:integer <- add sub:integer 1:literal) @@ -1767,8 +1768,8 @@ (break-unless t1:tagged-value-address) ; ++result (result:integer <- add result:integer 1:literal) -;? (print-primitive-to-host result:integer) -;? (print-primitive-to-host (("\n" literal))) +;? ($print result:integer) +;? ($print (("\n" literal))) ; curr = curr.cdr (curr:list-address <- list-next curr:list-address) (loop) @@ -1937,19 +1938,19 @@ ; while arg received (a:string-address arg-received?:boolean <- next-input) (break-unless arg-received?:boolean) -;? (print-primitive-to-host ("arg now: " literal)) -;? (print-primitive-to-host a:string-address) -;? (print-primitive-to-host "@":literal) -;? (print-primitive-to-host a:string-address/deref) ; todo: test (m on scoped array) -;? (print-primitive-to-host "\n":literal) +;? ($print ("arg now: " literal)) +;? ($print a:string-address) +;? ($print "@":literal) +;? ($print a:string-address/deref) ; todo: test (m on scoped array) +;? ($print "\n":literal) ;? ;? (assert nil:literal) ; result-len = result-len + arg.length - 1 (for the 'underscore' being replaced) (a-len:integer <- length a:string-address/deref) (result-len:integer <- add result-len:integer a-len:integer) (result-len:integer <- subtract result-len:integer 1:literal) -;? (print-primitive-to-host ("result-len now: " literal)) -;? (print-primitive-to-host result-len:integer) -;? (print-primitive-to-host "\n":literal) +;? ($print ("result-len now: " literal)) +;? ($print result-len:integer) +;? ($print "\n":literal) (loop) } ; rewind to start of non-template args @@ -1981,9 +1982,9 @@ (result-idx:integer <- add result-idx:integer 1:literal) (loop) } -;? (print-primitive-to-host ("i now: " literal)) -;? (print-primitive-to-host i:integer) -;? (print-primitive-to-host "\n":literal) +;? ($print ("i now: " literal)) +;? ($print i:integer) +;? ($print "\n":literal) ; copy 'a' into result (j:integer <- copy 0:literal) { begin @@ -1992,11 +1993,11 @@ (break-if arg-done?:boolean) ; result[result-idx] = a[j] (in:byte <- index a:string-address/deref j:integer) -;? (print-primitive-to-host ("copying: " literal)) -;? (print-primitive-to-host in:byte) -;? (print-primitive-to-host (" at: " literal)) -;? (print-primitive-to-host result-idx:integer) -;? (print-primitive-to-host "\n":literal) +;? ($print ("copying: " literal)) +;? ($print in:byte) +;? ($print (" at: " literal)) +;? ($print result-idx:integer) +;? ($print "\n":literal) (out:byte-address <- index-address result:string-address/deref result-idx:integer) (out:byte-address/deref <- copy in:byte) ; ++j @@ -2007,9 +2008,9 @@ } ; skip '_' in template (i:integer <- add i:integer 1:literal) -;? (print-primitive-to-host ("i now: " literal)) -;? (print-primitive-to-host i:integer) -;? (print-primitive-to-host "\n":literal) +;? ($print ("i now: " literal)) +;? ($print i:integer) +;? ($print "\n":literal) (loop) ; interpolate next arg } ; done with holes; copy rest of template directly into result @@ -2019,11 +2020,11 @@ (break-if tem-done?:boolean) ; result[result-idx] = template[i] (in:byte <- index template:string-address/deref i:integer) -;? (print-primitive-to-host ("copying: " literal)) -;? (print-primitive-to-host in:byte) -;? (print-primitive-to-host (" at: " literal)) -;? (print-primitive-to-host result-idx:integer) -;? (print-primitive-to-host "\n":literal) +;? ($print ("copying: " literal)) +;? ($print in:byte) +;? ($print (" at: " literal)) +;? ($print result-idx:integer) +;? ($print "\n":literal) (out:byte-address <- index-address result:string-address/deref result-idx:integer) (out:byte-address/deref <- copy in:byte) ; ++i @@ -2074,9 +2075,9 @@ (loop) } ; allocate space -;? (print-primitive-to-host (("alloc: " literal))) -;? (print-primitive-to-host count:integer) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("alloc: " literal))) +;? ($print count:integer) +;? ($print (("\n" literal))) (result:string-address-array-address <- new string-address-array:literal count:integer) ; repeatedly copy slices (start..end) until delimiter into result[curr-result] (curr-result:integer <- copy 0:literal) @@ -2086,13 +2087,13 @@ (done?:boolean <- greater-or-equal start:integer len:integer) (break-if done?:boolean) (end:integer <- find-next s:string-address delim:character start:integer) -;? (print-primitive-to-host (("i: " literal))) -;? (print-primitive-to-host start:integer) -;? (print-primitive-to-host (("-" literal))) -;? (print-primitive-to-host end:integer) -;? (print-primitive-to-host ((" => " literal))) -;? (print-primitive-to-host curr-result:integer) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("i: " literal))) +;? ($print start:integer) +;? ($print (("-" literal))) +;? ($print end:integer) +;? ($print ((" => " literal))) +;? ($print curr-result:integer) +;? ($print (("\n" literal))) ; compute length of slice (slice-len:integer <- subtract end:integer start:integer) ; allocate result[curr-result] @@ -2153,7 +2154,7 @@ ; later we'll need ways to suppress this { begin (break-unless c:character) - (print-primitive-to-host c:character) + (print-character-to-host c:character) } (reply c:character) ) @@ -2192,10 +2193,10 @@ (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) (assert c:character) -;? (print-primitive-to-host line:buffer-address) ;? 2 -;? (print-primitive-to-host (("\n" literal))) ;? 2 -;? (print-primitive-to-host c:character) ;? 2 -;? (print-primitive-to-host (("\n" literal))) ;? 2 +;? ($print line:buffer-address) ;? 2 +;? ($print (("\n" literal))) ;? 2 +;? ($print c:character) ;? 2 +;? ($print (("\n" literal))) ;? 2 ; handle backspace { begin (backspace?:boolean <- equal c:character ((#\backspace literal))) @@ -2203,9 +2204,9 @@ (len:integer-address <- get-address line:buffer-address/deref length:offset) ; but only if we need to { begin -;? (print-primitive-to-host (("backspace: " literal))) ;? 1 -;? (print-primitive-to-host len:integer-address/deref) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("backspace: " literal))) ;? 1 +;? ($print len:integer-address/deref) ;? 1 +;? ($print (("\n" literal))) ;? 1 (zero?:boolean <- lesser-or-equal len:integer-address/deref 0:literal) (break-if zero?:boolean) (len:integer-address/deref <- subtract len:integer-address/deref 1:literal) @@ -2223,9 +2224,9 @@ (i:integer <- copy 0:literal) (line-contents:string-address <- get line:buffer-address/deref data:offset) (max:integer <- get line:buffer-address/deref length:offset) -;? (print-primitive-to-host (("len: " literal))) ;? 1 -;? (print-primitive-to-host max:integer) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print (("len: " literal))) ;? 1 +;? ($print max:integer) ;? 1 +;? ($print (("\n" literal))) ;? 1 { begin (done?:boolean <- greater-or-equal i:integer max:integer) (break-if done?:boolean) @@ -2233,11 +2234,11 @@ (curr:tagged-value <- save-type c:character) ;? ($dump-channel 1093:literal) ;? 1 ;? ($start-tracing) ;? 1 -;? (print-primitive-to-host (("bufferout: " literal))) ;? 2 -;? (print-primitive-to-host c:character) ;? 1 +;? ($print (("bufferout: " literal))) ;? 2 +;? ($print c:character) ;? 1 ;? (x:integer <- character-to-integer c:character) ;? 1 -;? (print-primitive-to-host x:integer) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 2 +;? ($print x:integer) ;? 1 +;? ($print (("\n" literal))) ;? 2 (buffered-stdin:channel-address/deref <- write buffered-stdin:channel-address curr:tagged-value) ;? ($stop-tracing) ;? 1 ;? ($dump-channel 1093:literal) ;? 1 @@ -2254,7 +2255,7 @@ (x:terminal-address <- next-input) { begin (break-unless x:terminal-address) -;? (print-primitive-to-host (("AAA" literal))) +;? ($print (("AAA" literal))) (buf:string-address <- get x:terminal-address/deref data:offset) (max:integer <- length buf:string-address/deref) (i:integer <- copy 0:literal) @@ -2293,12 +2294,12 @@ { begin (break-unless x:terminal-address) (row:integer-address <- get-address x:terminal-address/deref cursor-row:offset) -;? (print-primitive-to-host row:integer-address/deref) -;? (print-primitive-to-host (("\n" literal))) +;? ($print row:integer-address/deref) +;? ($print (("\n" literal))) (row:integer-address/deref <- add row:integer-address/deref 1:literal) (col:integer-address <- get-address x:terminal-address/deref cursor-col:offset) -;? (print-primitive-to-host col:integer-address/deref) -;? (print-primitive-to-host (("\n" literal))) +;? ($print col:integer-address/deref) +;? ($print (("\n" literal))) (col:integer-address/deref <- copy 0:literal) (reply) } @@ -2309,10 +2310,10 @@ (default-space:space-address <- new space:literal 30:literal) (x:terminal-address <- next-input) (c:character <- next-input) -;? (print-primitive-to-host (("printing character to screen " literal))) -;? (print-primitive-to-host c:character) +;? ($print (("printing character to screen " literal))) +;? ($print c:character) ;? (reply) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("\n" literal))) { begin (break-unless x:terminal-address) (row:integer-address <- get-address x:terminal-address/deref cursor-row:offset) @@ -2328,7 +2329,7 @@ ; maybe die if we go out of screen bounds? (reply) } - (print-primitive-to-host c:character) + (print-character-to-host c:character) ) (init-fn print-string @@ -2336,9 +2337,9 @@ (x:terminal-address <- next-input) (s:string-address <- next-input) (len:integer <- length s:string-address/deref) -;? (print-primitive-to-host (("print/string: len: " literal))) -;? (print-primitive-to-host len:integer) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("print/string: len: " literal))) +;? ($print len:integer) +;? ($print (("\n" literal))) (i:integer <- copy 0:literal) { begin (done?:boolean <- greater-or-equal i:integer len:integer) @@ -2355,10 +2356,10 @@ (x:terminal-address <- next-input) (n:integer <- next-input) ; todo: other bases besides decimal -;? (print-primitive-to-host (("AAA " literal))) -;? (print-primitive-to-host n:integer) +;? ($print (("AAA " literal))) +;? ($print n:integer) (s:string-address <- integer-to-decimal-string n:integer) -;? (print-primitive-to-host s:string-address) +;? ($print s:string-address) (print-string x:terminal-address s:string-address) ) @@ -2379,9 +2380,9 @@ ; double buffer size (x:string-address-address <- get-address in:buffer-address/deref data:offset) (oldlen:integer <- length x:string-address-address/deref/deref) -;? (print-primitive-to-host oldlen:integer) ;? 1 +;? ($print oldlen:integer) ;? 1 (newlen:integer <- multiply oldlen:integer 2:literal) -;? (print-primitive-to-host newlen:integer) ;? 1 +;? ($print newlen:integer) ;? 1 (olddata:string-address <- copy x:string-address-address/deref) (x:string-address-address/deref <- new string:literal newlen:integer) ; copy old contents @@ -2443,9 +2444,9 @@ (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 +;? ($print (("a: " literal))) ;? 1 +;? ($print foo:integer) ;? 1 +;? ($print ((#\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) @@ -2458,15 +2459,15 @@ (default-space:space-address <- new space:literal 30:literal) (in:buffer-address <- next-input) (c:character <- next-input) -;? (print-primitive-to-host c:character) ;? 1 +;? ($print c:character) ;? 1 { begin ; grow buffer if necessary (full?:boolean <- buffer-full? in:buffer-address) -;? (print-primitive-to-host (("aa\n" literal))) ;? 1 +;? ($print (("aa\n" literal))) ;? 1 (break-unless full?:boolean) -;? (print-primitive-to-host (("bb\n" literal))) ;? 1 +;? ($print (("bb\n" literal))) ;? 1 (in:buffer-address <- grow-buffer in:buffer-address) -;? (print-primitive-to-host (("cc\n" literal))) ;? 1 +;? ($print (("cc\n" literal))) ;? 1 } (len:integer-address <- get-address in:buffer-address/deref length:offset) (s:string-address <- get in:buffer-address/deref data:offset) @@ -2507,7 +2508,7 @@ { begin (negative?:boolean <- less-than n:integer 0:literal) (break-unless negative?:boolean) -;? (print-primitive-to-host (("is negative " literal))) +;? ($print (("is negative " literal))) (negate-result:boolean <- copy t:literal) (n:integer <- multiply n:integer -1:literal) } @@ -2562,12 +2563,12 @@ (c:character <- maybe-coerce x:tagged-value character:literal) (done?:boolean <- equal c:character ((#\null literal))) (break-if done?:boolean) -;? (print-primitive-to-host (("printing " literal))) ;? 1 -;? (print-primitive-to-host i:integer) ;? 1 -;? (print-primitive-to-host ((" -- " literal))) ;? 1 +;? ($print (("printing " literal))) ;? 1 +;? ($print i:integer) ;? 1 +;? ($print ((" -- " literal))) ;? 1 ;? (x:integer <- character-to-integer c:character) ;? 1 -;? (print-primitive-to-host x:integer) ;? 1 -;? (print-primitive-to-host (("\n" literal))) ;? 1 +;? ($print x:integer) ;? 1 +;? ($print (("\n" literal))) ;? 1 ;? (i:integer <- add i:integer 1:literal) ;? 1 (print-character screen:terminal-address c:character) (loop) diff --git a/repl.mu b/repl.mu index 6d223f19..3cb3cd16 100644 --- a/repl.mu +++ b/repl.mu @@ -10,9 +10,9 @@ (x:tagged-value in:channel-address/deref <- read in:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) (assert c:character "read-expression: non-character in stdin") -;? (print-primitive-to-host (("key: " literal))) ;? 1 -;? (print-primitive-to-host c:character) ;? 2 -;? (print-primitive-to-host (("$\n" literal))) ;? 2 +;? ($print (("key: " literal))) ;? 1 +;? ($print c:character) ;? 2 +;? ($print (("$\n" literal))) ;? 2 (result:buffer-address <- append result:buffer-address c:character) ; parse comment { begin @@ -43,7 +43,7 @@ { begin (newline?:boolean <- equal c:character ((#\newline literal))) (break-unless newline?:boolean) -;? (print-primitive-to-host (("AAA" literal))) ;? 1 +;? ($print (("AAA" literal))) ;? 1 (end-expression?:boolean <- lesser-or-equal open-parens:integer 0:literal) (break-if end-expression?:boolean 2:blocks) } @@ -52,7 +52,7 @@ ; don't return if there's no non-whitespace in result (loop) } -;? (print-primitive-to-host (("BAA" literal))) ;? 1 +;? ($print (("BAA" literal))) ;? 1 (s:string-address <- get result:buffer-address/deref data:offset) (reply s:string-address) ]) @@ -93,7 +93,7 @@ (buffered-stdin:channel-address <- init-channel 1:literal) (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address) { begin - (print-primitive-to-host (("anarki> " literal))) + ($print (("anarki> " literal))) (s:string-address <- read-expression buffered-stdin:channel-address) (retro-mode) ; print errors cleanly (t:string-address <- $eval s:string-address) diff --git a/stdin.mu b/stdin.mu index 4ffded52..87598667 100644 --- a/stdin.mu +++ b/stdin.mu @@ -4,23 +4,22 @@ (function main [ (default-space:space-address <- new space:literal 30:literal) (cursor-mode) - (clear-screen) ; hook up stdin (stdin:channel-address <- init-channel 1:literal) -;? (print-primitive-to-host (("main: stdin is " literal))) -;? (print-primitive-to-host stdin:channel-address) -;? (print-primitive-to-host (("\n" literal))) +;? ($print (("main: stdin is " literal))) +;? ($print stdin:channel-address) +;? ($print (("\n" literal))) (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address) ; now read characters from stdin until a 'q' is typed - (print-primitive-to-host (("? " literal))) + ($print (("? " literal))) { begin (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) -;? (print-primitive-to-host (("main: stdin is " literal))) -;? (print-primitive-to-host stdin:channel-address) -;? (print-primitive-to-host (("\n" literal))) -;? (print-primitive-to-host (("check: " literal))) -;? (print-primitive-to-host c:character) +;? ($print (("main: stdin is " literal))) +;? ($print stdin:channel-address) +;? ($print (("\n" literal))) +;? ($print (("check: " literal))) +;? ($print c:character) (done?:boolean <- equal c:character ((#\q literal))) (break-if done?:boolean) (loop) diff --git a/tangle.mu b/tangle.mu index 720b531f..3e73dd89 100644 --- a/tangle.mu +++ b/tangle.mu @@ -29,7 +29,7 @@ (function main [ (1:integer <- factorial 5:literal) - (print-primitive-to-host (("result: " literal))) + ($print (("result: " literal))) (print-integer nil:literal/terminal 1:integer) - (print-primitive-to-host (("\n" literal))) + (print-character nil:literal/terminal ((#\newline literal))) ]) |