3627 - selective dumping a single label
Follow-up to commit 3516.
2 files changed, 10 insertions, 2 deletions
diff --git a/003trace.cc b/003trace.cc
index e874d04f..c4344f2c 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -89,9 +89,11 @@ struct trace_line {
:(before "End Globals")
bool Hide_errors = false;
bool Dump_trace = false;
+string Dump_label = "";
:(before "End Setup")
Hide_errors = false;
Dump_trace = false;
+Dump_label = "";
:(before "End Types")
// Pre-define some global constants that trace_stream needs to know about.
@@ -137,7 +139,9 @@ void trace_stream::newline() {
string curr_contents = curr_stream->str();
if (!curr_contents.empty()) {
past_lines.push_back(trace_line(curr_depth, trim(curr_label), curr_contents)); // preserve indent in contents
- if (Dump_trace || (!Hide_errors && curr_label == "error"))
+ if ((!Hide_errors && curr_label == "error")
+ || Dump_trace
+ || (!Dump_label.empty() && curr_label == Dump_label))
cerr << curr_label << ": " << curr_contents << '\n';
}
delete curr_stream;
diff --git a/html/003trace.cc.html b/html/003trace.cc.html
index a5523956..4cfee97a 100644
--- a/html/003trace.cc.html
+++ b/html/003trace.cc.html
@@ -122,9 +122,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Delimiter">:(before "End Globals")</span>
<span class="Normal">bool</span> Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Normal">bool</span> Dump_trace = <span class="Constant">false</span><span class="Delimiter">;</span>
+string Dump_label = <span class="Constant">""</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Setup")</span>
Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span>
Dump_trace = <span class="Constant">false</span><span class="Delimiter">;</span>
+Dump_label = <span class="Constant">""</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Types")</span>
<span class="Comment">// Pre-define some global constants that trace_stream needs to know about.</span>
@@ -170,7 +172,9 @@ Dump_trace = <span class="Constant">false</span><span class="Delimiter">;</span>
string curr_contents = curr_stream<span class="Delimiter">-></span>str<span class="Delimiter">();</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!curr_contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
past_lines<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>trace_line<span class="Delimiter">(</span>curr_depth<span class="Delimiter">,</span> trim<span class="Delimiter">(</span>curr_label<span class="Delimiter">),</span> curr_contents<span class="Delimiter">));</span> <span class="Comment">// preserve indent in contents</span>
- <span class="Normal">if</span> <span class="Delimiter">(</span>Dump_trace || <span class="Delimiter">(</span>!Hide_errors && curr_label == <span class="Constant">"error"</span><span class="Delimiter">))</span>
+ <span class="Normal">if</span> <span class="Delimiter">((</span>!Hide_errors && curr_label == <span class="Constant">"error"</span><span class="Delimiter">)</span>
+ || Dump_trace
+ || <span class="Delimiter">(</span>!Dump_label<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> &ghlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */;; data structure: board
(primitive square)
(address square-address (square)) ; pointer. verbose but sadly necessary for now
(array file (square)) ; ranks and files are arrays of squares
(address file-address (file))
(address file-address-address (file-address)) ; pointer to a pointer
(array board (file-address))
(address board-address (board))
(function read-board [
(default-scope:scope-address <- new scope:literal 30:literal)
(initial-position:list-address <- init-list R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal
N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal
B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal
Q:literal P:literal _:literal _:literal _:literal _:literal p:literal q:literal
K:literal P:literal _:literal _:literal _:literal _:literal p:literal k:literal
B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal
N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal
R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal)
; assert(length(initial-position) == 64)
(len:integer <- list-length initial-position:list-address)
(correct-length?:boolean <- equal len:integer 64:literal)
(assert correct-length?:boolean (("chessboard had incorrect size" literal)))
(b:board-address <- new board:literal 8:literal)
(col:integer <- copy 0:literal)
(curr:list-address <- copy initial-position:list-address)
{ begin
(done?:boolean <- equal col:integer 8:literal)
(break-if done?:boolean)
(file:file-address-address <- index-address b:board-address/deref col:integer)
(file:file-address-address/deref curr:list-address <- read-file curr:list-address)
(col:integer <- add col:integer 1:literal)
(loop)
}
(reply b:board-address)
])
(function read-file [
(default-scope:scope-address <- new scope:literal 30:literal)
(cursor:list-address <- next-input)
(result:file-address <- new file:literal 8:literal)
(row:integer <- copy 0:literal)
{ begin
(done?:boolean <- equal row:integer 8:literal)
(break-if done?:boolean)
(src:tagged-value-address <- list-value-address cursor:list-address)
(dest:square-address <- index-address result:file-address/deref row:integer)
(dest:square-address/deref <- get src:tagged-value-address/deref payload:offset) ; unsafe typecast
(cursor:list-address <- list-next cursor:list-address)
(row:integer <- add row:integer 1:literal)
(loop)
}
(reply result:file-address cursor:list-address)
])
(function print-board [
(default-scope:scope-address <- new scope:literal 30:literal)
(b:board-address <- next-input)
(row:integer <- copy 7:literal)
; print each row
{ begin
(done?:boolean <- less-than row:integer 0:literal)
(break-if done?:boolean)
; print rank number as a legend
(rank:integer <- add row:integer 1:literal)
(print-primitive rank:integer)
(print-primitive ((" | " literal)))
; print each square in the row
(col:integer <- copy 0:literal)
{ begin
(done?:boolean <- equal col:integer 8:literal)
(break-if done?:boolean)
(f:file-address <- index b:board-address/deref col:integer)
(s:square <- index f:file-address/deref row:integer)
(print-primitive s:square)
(print-primitive ((" " literal)))
(col:integer <- add col:integer 1:literal)
(loop)
}
(row:integer <- subtract row:integer 1:literal)
(cursor-to-next-line)
(loop)
}
; print file letters as legend
(print-primitive ((" +----------------" literal)))
(cursor-to-next-line)
(print-primitive ((" a b c d e f g h" literal)))
(cursor-to-next-line)
])
;; data structure: move
(and-record move [
from:integer-integer-pair
to:integer-integer-pair
])
(address move-address (move))
(function read-move [
(a:character <- copy ((#\a literal)))
(file-base:integer <- character-to-integer a:character)
(one:character <- copy ((#\1 literal)))
(rank-base:integer <- character-to-integer one:character)
; get from-file
(c:character <- wait-for-key)
(print-primitive c:character)
{ begin
(quit:boolean <- equal c:character ((#\q literal)))
(break-unless quit:boolean)
(reply)
}
(from-file:integer <- character-to-integer c:character)
(from-file:integer <- subtract from-file:integer file-base:integer)
; assert('a' <= from-file <= 'h')
(above-min:boolean <- greater-or-equal from-file:integer 0:literal)
(assert above-min:boolean (("from-file too low" literal)))
(below-max:boolean <- lesser-or-equal from-file:integer 7:literal)
(assert below-max:boolean (("from-file too high" literal)))
; get from-rank
(c:character <- wait-for-key)
(print-primitive c:character)
(from-rank:integer <- character-to-integer c:character)
(from-rank:integer <- subtract from-rank:integer rank-base:integer)
; assert('1' <= from-rank <= '8')
(above-min:boolean <- greater-or-equal from-rank:integer 0:literal)
(assert above-min:boolean (("from-rank too low" literal)))
(below-max:boolean <- lesser-or-equal from-rank:integer 7:literal)
(assert below-max:boolean (("from-rank too high" literal)))
; slurp hyphen
(c:character <- wait-for-key)
(print-primitive c:character)
(hyphen?:boolean <- equal c:character ((#\- literal)))
(assert hyphen?:boolean (("expected hyphen" literal)))
; get to-file
(c:character <- wait-for-key)
(print-primitive c:character)
(to-file:integer <- character-to-integer c:character)
(to-file:integer <- subtract to-file:integer file-base:integer)
; assert('a' <= to-file <= 'h')
(above-min:boolean <- greater-or-equal to-file:integer 0:literal)
(assert above-min:boolean (("to-file too low" literal)))
(below-max:boolean <- lesser-or-equal to-file:integer 7:literal)
(assert below-max:boolean (("to-file too high" literal)))
; get to-rank
(c:character <- wait-for-key)
(print-primitive c:character)
(to-rank:integer <- character-to-integer c:character)
(to-rank:integer <- subtract to-rank:integer rank-base:integer)
; assert('1' <= to-rank <= '8')
(above-min:boolean <- greater-or-equal to-rank:integer 0:literal)
(assert above-min:boolean (("to-rank too low" literal)))
(below-max:boolean <- lesser-or-equal to-rank:integer 7:literal)
(assert below-max:boolean (("to-rank too high" literal)))
; construct the move object
(result:move-address <- new move:literal)
(f:integer-integer-pair-address <- get-address result:move-address/deref from:offset)
(dest:integer-address <- get-address f:integer-integer-pair-address/deref 0:offset)
(dest:integer-address/deref <- copy from-file:integer)
(dest:integer-address <- get-address f:integer-integer-pair-address/deref 1:offset)
(dest:integer-address/deref <- copy from-rank:integer)
(t0:integer-integer-pair-address <- get-address result:move-address/deref to:offset)
(dest:integer-address <- get-address t0:integer-integer-pair-address/deref 0:offset)
(dest:integer-address/deref <- copy to-file:integer)
(dest:integer-address <- get-address t0:integer-integer-pair-address/deref 1:offset)
(dest:integer-address/deref <- copy to-rank:integer)
(reply result:move-address)
])
(function make-move [
(default-scope:scope-address <- new scope:literal 30:literal)
(b:board-address <- next-input)
(m:move-address <- next-input)
(x:integer-integer-pair <- get m:move-address/deref from:offset)
(from-file:integer <- get x:integer-integer-pair 0:offset)
(from-rank:integer <- get x:integer-integer-pair 1:offset)
(f:file-address <- index b:board-address/deref from-file:integer)
(src:square-address <- index-address f:file-address/deref from-rank:integer)
(x:integer-integer-pair <- get m:move-address/deref to:offset)
(to-file:integer <- get x:integer-integer-pair 0:offset)
(to-rank:integer <- get x:integer-integer-pair 1:offset)
(f:file-address <- index b:board-address/deref to-file:integer)
(dest:square-address <- index-address f:file-address/deref to-rank:integer)
(dest:square-address/deref <- copy src:square-address/deref)
(src:square-address/deref <- copy _:literal)
(reply b:board-address)
])
(function main [
(default-scope:scope-address <- new scope:literal 30:literal)
(b:board-address <- read-board)
(console-on)
{ begin
(clear-screen)
(print-primitive (("Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves." literal)))
(cursor-to-next-line)
(cursor-to-next-line)
(print-board b:board-address)
(cursor-to-next-line)
(print-primitive (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Currently very unforgiving of typos; exactly five letters, no <Enter>, no uppercase." literal)))
(cursor-to-next-line)
(print-primitive (("Hit 'q' to exit." literal)))
(cursor-to-next-line)
(print-primitive (("move: " literal)))
(m:move-address <- read-move)
(break-unless m:move-address)
(b:board-address <- make-move b:board-address m:move-address)
(loop)
}
(console-off)
])
; tests todo:
; print board
; accept move
; print move
; board updates on move
; die on invalid move
; 'q' exits
; 'q' exits anywhere in move
; 'q' exits on second move -- FAIL
;
; backspace, ctrl-u
|