From d0453b7b7731ee09aef164c45e81c031911e7b25 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 12 Jan 2018 20:13:48 -0600 Subject: [PATCH] consolidate True/False typing to one location --- src/Perl6/Pod.nqp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/Perl6/Pod.nqp b/src/Perl6/Pod.nqp index c426640521d..47d90006170 100644 --- a/src/Perl6/Pod.nqp +++ b/src/Perl6/Pod.nqp @@ -160,6 +160,14 @@ class Perl6::Pod { my $val := $*W.add_constant('Num', 'num', $i).compile_time_value; @arr.push($val); } + #=== booleans =================================================================== + elsif $s ~~ /^ True | False $/ { + # consolidate all True/False boolean handling here + say(" element type is boolean") if $debugp; + my $truth := $s ~~ /True/ ?? 1 !! 0; + my $val := $*W.add_constant('Bool', 'int', $truth).compile_time_value; + @arr.push($val); + } #=== strings ==================================================================== else { say(" element type is Str") if $debugp; @@ -301,29 +309,11 @@ class Perl6::Pod { my @arr := string2array($st); if nqp::elems(@arr) > 1 { - # build the array object anew to handle bools - my @arr2 := nqp::list(); - for @arr -> $v { - my $val := $v; - if nqp::isstr($val) { - if $val ~~ /^ True | False $/ { - my $truth := $val ~~ /True/ ?? 1 !! 0; - $val := $*W.add_constant('Bool', 'int', $truth).compile_time_value; - } - } - nqp::push(@arr2, $val); - } - return serialize_object('Array', |@arr2).compile_time_value; + return serialize_object('Array', |@arr).compile_time_value; } else { # convert a single-element list to a single value my $val := @arr[0]; - if nqp::isstr($val) { - if $val ~~ /^ True | False $/ { - my $truth := $val ~~ /True/ ?? 1 !! 0; - $val := $*W.add_constant('Bool', 'int', $truth).compile_time_value; - } - } return $val; } } @@ -343,13 +333,6 @@ class Perl6::Pod { my str $key := $k; my $val := $v; say("DEBUG hash: '$key' => '$val'") if $debugp; - - # special handling for a boolean - if $val ~~ /^ True | False $/ { - my $truth := $val ~~ /True/ ?? 1 !! 0; - $val := $*W.add_constant('Bool', 'int', $truth).compile_time_value; - } - @pairs.push( serialize_object( 'Pair', :key($key), :value($val)