Skip to content
Permalink
Browse files

Replace use of p6bool by hllbool and hllboolfor

hllbool is less magic than p6bool so a couple of places have to convert
the values to an int64 first, but that seems to make the code more
explicit anyway.
  • Loading branch information...
niner committed Aug 14, 2018
1 parent 20feda7 commit 170ffd40ca36abd75c1de4c80c275124b918eec8
Showing with 345 additions and 338 deletions.
  1. +5 βˆ’5 lib/Telemetry.pm6
  2. +4 βˆ’4 src/Perl6/Actions.nqp
  3. +18 βˆ’17 src/Perl6/Metamodel/BOOTSTRAP.nqp
  4. +4 βˆ’3 src/Perl6/Metamodel/DefiniteHOW.nqp
  5. +1 βˆ’1 src/Perl6/Metamodel/MROBasedTypeChecking.nqp
  6. +5 βˆ’5 src/Perl6/Metamodel/SubsetHOW.nqp
  7. +6 βˆ’6 src/Perl6/Optimizer.nqp
  8. +1 βˆ’1 src/Perl6/World.nqp
  9. +3 βˆ’3 src/core/Any.pm6
  10. +1 βˆ’1 src/core/Argfiles.pm6
  11. +1 βˆ’1 src/core/Backtrace.pm6
  12. +5 βˆ’5 src/core/Baggy.pm6
  13. +7 βˆ’7 src/core/Bool.pm6
  14. +11 βˆ’11 src/core/Buf.pm6
  15. +4 βˆ’4 src/core/Capture.pm6
  16. +3 βˆ’3 src/core/Cool.pm6
  17. +1 βˆ’1 src/core/Enumeration.pm6
  18. +1 βˆ’1 src/core/Failure.pm6
  19. +2 βˆ’2 src/core/Hash.pm6
  20. +4 βˆ’4 src/core/IO/CatHandle.pm6
  21. +3 βˆ’3 src/core/IO/Handle.pm6
  22. +4 βˆ’4 src/core/IO/Path.pm6
  23. +1 βˆ’1 src/core/IO/Spec/Cygwin.pm6
  24. +3 βˆ’3 src/core/IO/Spec/Unix.pm6
  25. +2 βˆ’2 src/core/IO/Spec/Win32.pm6
  26. +15 βˆ’15 src/core/Int.pm6
  27. +5 βˆ’5 src/core/Junction.pm6
  28. +5 βˆ’5 src/core/List.pm6
  29. +1 βˆ’1 src/core/Main.pm6
  30. +6 βˆ’5 src/core/Map.pm6
  31. +1 βˆ’1 src/core/Match.pm6
  32. +1 βˆ’1 src/core/Metamodel/Primitives.pm6
  33. +9 βˆ’9 src/core/Mu.pm6
  34. +15 βˆ’15 src/core/Num.pm6
  35. +2 βˆ’2 src/core/Numeric.pm6
  36. +1 βˆ’1 src/core/Pair.pm6
  37. +13 βˆ’13 src/core/Parameter.pm6
  38. +1 βˆ’1 src/core/Promise.pm6
  39. +1 βˆ’1 src/core/PseudoStash.pm6
  40. +2 βˆ’2 src/core/REPL.pm6
  41. +3 βˆ’3 src/core/Rakudo/Internals.pm6
  42. +16 βˆ’16 src/core/Rakudo/Iterator.pm6
  43. +1 βˆ’1 src/core/Rakudo/QuantHash.pm6
  44. +7 βˆ’7 src/core/Range.pm6
  45. +2 βˆ’2 src/core/Rational.pm6
  46. +1 βˆ’1 src/core/Regex.pm6
  47. +3 βˆ’3 src/core/Routine.pm6
  48. +1 βˆ’1 src/core/Scalar.pm6
  49. +1 βˆ’1 src/core/Semaphore.pm6
  50. +2 βˆ’2 src/core/Seq.pm6
  51. +1 βˆ’1 src/core/Set.pm6
  52. +5 βˆ’4 src/core/SetHash.pm6
  53. +4 βˆ’4 src/core/Setty.pm6
  54. +3 βˆ’3 src/core/Shaped1Array.pm6
  55. +2 βˆ’2 src/core/Shaped2Array.pm6
  56. +2 βˆ’2 src/core/Shaped3Array.pm6
  57. +1 βˆ’1 src/core/ShapedArray.pm6
  58. +2 βˆ’2 src/core/Signature.pm6
  59. +28 βˆ’28 src/core/Str.pm6
  60. +1 βˆ’1 src/core/Stringy.pm6
  61. +1 βˆ’1 src/core/Thread.pm6
  62. +1 βˆ’1 src/core/ThreadPoolScheduler.pm6
  63. +3 βˆ’3 src/core/Uni.pm6
  64. +3 βˆ’3 src/core/Version.pm6
  65. +1 βˆ’1 src/core/metaops.pm6
  66. +26 βˆ’26 src/core/native_array.pm6
  67. +34 βˆ’30 src/core/set_elem.pm6
  68. +1 βˆ’1 src/core/set_precedes.pm6
  69. +3 βˆ’3 src/core/set_proper_subset.pm6
  70. +1 βˆ’2 src/vm/moar/Perl6/Ops.nqp
  71. +7 βˆ’7 tools/build/makeNATIVE_SHAPED_ARRAY.p6
@@ -205,7 +205,7 @@ HEADER
}

method EXISTS-KEY(Str:D $key) {
nqp::p6bool(nqp::existskey($dispatch,$key))
nqp::hllbool(nqp::existskey($dispatch,$key))
}

method !snap() is raw {
@@ -272,7 +272,7 @@ HEADER
}

method EXISTS-KEY(Str:D $key) {
nqp::p6bool(nqp::existskey($dispatch,$key))
nqp::hllbool(nqp::existskey($dispatch,$key))
}

method !snap() is raw { Thread.usage }
@@ -351,7 +351,7 @@ class Telemetry::Instrument::ThreadPool does Telemetry::Instrument {
}

method EXISTS-KEY(Str:D $key) {
nqp::p6bool(nqp::existskey($dispatch,$key))
nqp::hllbool(nqp::existskey($dispatch,$key))
}

method !snap() is raw {
@@ -435,7 +435,7 @@ class Telemetry::Instrument::AdHoc does Telemetry::Instrument {
}

method EXISTS-KEY(Str:D $key) {
nqp::p6bool(
nqp::hllbool(
nqp::existskey(
nqp::getattr(
$!instrument,Telemetry::Instrument::AdHoc,'$!dispatch'),
@@ -620,7 +620,7 @@ class Telemetry does Associative {
}

method EXISTS-KEY($key) {
nqp::p6bool(
nqp::hllbool(
nqp::existskey(
nqp::getattr($!sampler,Telemetry::Sampler,'$!dispatcher'),
$key
@@ -2042,7 +2042,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# Under "use fatal", re-write all calls to fatalize their return value
# unless we can see they are in a boolean context.
my %boolify_first_child_ops := nqp::hash(
'if', 1, 'unless', 1, 'defor', 1, 'p6bool', 1,
'if', 1, 'unless', 1, 'defor', 1, 'hllbool', 1,
'while', 1, 'until', 1, 'repeat_while', 1, 'repeat_until', 1,
);
my %boolify_first_child_calls := nqp::hash(
@@ -2953,7 +2953,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
else {
make make_pair($/,$*key, QAST::Op.new(
:op('p6bool'),
:op('hllbool'),
QAST::IVal.new( :value($*value) )
));
}
@@ -4344,7 +4344,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# Cannot inline things with custom invocation handler or phasers.
return 0 if nqp::can($code, 'CALL-ME');
my $phasers := nqp::getattr($code,$*W.find_symbol(['Block'], :setting-only),'$!phasers');
return 0 unless nqp::isnull($phasers) || !nqp::p6bool($phasers);
return 0 unless nqp::isnull($phasers) || !nqp::hllbool($phasers);

# Make sure the block has the common structure we expect
# (decls then statements).
@@ -5228,7 +5228,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# If we have a refinement, make sure it's thunked if needed. If none,
# just always true.
my $refinement := make_where_block($<EXPR>, $<EXPR> ?? $<EXPR>.ast !!
QAST::Op.new( :op('p6bool'), QAST::IVal.new( :value(1) ) ));
QAST::Op.new( :op('hllbool'), QAST::IVal.new( :value(1) ) ));

# Create the meta-object.
my $subset;
@@ -1455,28 +1455,28 @@ BEGIN {
Attribute, '$!auto_viv_container');
}));
Attribute.HOW.add_method(Attribute, 'has_accessor', nqp::getstaticcode(sub ($self) {
nqp::p6bool(nqp::getattr_i(nqp::decont($self),
Attribute, '$!has_accessor'));
nqp::hllboolfor(nqp::getattr_i(nqp::decont($self),
Attribute, '$!has_accessor'), "perl6");
}));
Attribute.HOW.add_method(Attribute, 'rw', nqp::getstaticcode(sub ($self) {
nqp::p6bool(nqp::getattr_i(nqp::decont($self),
Attribute, '$!rw'));
nqp::hllboolfor(nqp::getattr_i(nqp::decont($self),
Attribute, '$!rw'), "perl6");
}));
Attribute.HOW.add_method(Attribute, 'set_rw', nqp::getstaticcode(sub ($self) {
nqp::bindattr_i(nqp::decont($self),
Attribute, '$!rw', 1);
nqp::p6bool(1)
nqp::hllboolfor(1, "perl6")
}));
Attribute.HOW.add_method(Attribute, 'set_readonly', nqp::getstaticcode(sub ($self) {
nqp::bindattr_i(nqp::decont($self),
Attribute, '$!ro', 1);
nqp::p6bool(1)
nqp::hllboolfor(1, "perl6")
}));
Attribute.HOW.add_method(Attribute, 'set_required', nqp::getstaticcode(sub ($self, $value) {
$*W.add_object_if_no_sc($value);
nqp::bindattr(nqp::decont($self),
Attribute, '$!required', $value);
nqp::p6bool(1)
nqp::hllboolfor(1, "perl6")
}));
Attribute.HOW.add_method(Attribute, 'required', nqp::getstaticcode(sub ($self) {
nqp::getattr(nqp::decont($self),
@@ -1487,7 +1487,7 @@ BEGIN {
unless nqp::getattr_i($dcself, Attribute, '$!ro') {
nqp::bindattr_i($dcself, Attribute, '$!rw', 1);
}
nqp::p6bool(1)
nqp::hllboolfor(1, "perl6")
}));
Attribute.HOW.add_method(Attribute, 'set_build', nqp::getstaticcode(sub ($self, $closure) {
nqp::bindattr(nqp::decont($self), Attribute, '$!build_closure', $closure);
@@ -1500,7 +1500,7 @@ BEGIN {
Attribute.HOW.add_method(Attribute, 'set_box_target', nqp::getstaticcode(sub ($self) {
nqp::bindattr_i(nqp::decont($self),
Attribute, '$!box_target', 1);
nqp::p6bool(1)
nqp::hllboolfor(1, "perl6")
}));
Attribute.HOW.add_method(Attribute, 'box_target', nqp::getstaticcode(sub ($self) {
nqp::getattr_i(nqp::decont($self),
@@ -1524,7 +1524,7 @@ BEGIN {
Attribute, '$!package');
my $build := nqp::getattr(nqp::decont($dcself),
Attribute, '$!build_closure');
nqp::p6bool($type.HOW.archetypes.generic || $package.HOW.archetypes.generic || nqp::defined($build));
nqp::hllboolfor($type.HOW.archetypes.generic || $package.HOW.archetypes.generic || nqp::defined($build), "perl6");
}));
Attribute.HOW.add_method(Attribute, 'instantiate_generic', nqp::getstaticcode(sub ($self, $type_environment) {
my $dcself := nqp::decont($self);
@@ -1772,7 +1772,7 @@ BEGIN {
my $is_generic := $_.is_generic();
if $is_generic { return $is_generic }
}
return nqp::p6bool(0);
return nqp::hllboolfor(0, "perl6");
}));
Signature.HOW.add_method(Signature, 'instantiate_generic', nqp::getstaticcode(sub ($self, $type_environment) {
# Go through parameters, builidng new list. If any
@@ -1800,13 +1800,14 @@ BEGIN {
Signature, '$!returns', nqp::decont($type));
}));
Signature.HOW.add_method(Signature, 'has_returns', nqp::getstaticcode(sub ($self) {
nqp::p6bool(
nqp::hllboolfor(
nqp::not_i(
nqp::isnull(
nqp::getattr(nqp::decont($self),
Signature, '$!returns')
)
)
),
'perl6'
);
}));
Signature.HOW.compose_repr(Signature);
@@ -1843,8 +1844,8 @@ BEGIN {
# If nonimnal type or attr_package is generic, so are we.
my $type := nqp::getattr($self, Parameter, '$!nominal_type');
my $ap := nqp::getattr($self, Parameter, '$!attr_package');
nqp::p6bool($type.HOW.archetypes.generic ||
(!nqp::isnull($ap) && $ap.HOW.archetypes.generic))
nqp::hllboolfor($type.HOW.archetypes.generic ||
(!nqp::isnull($ap) && $ap.HOW.archetypes.generic), "perl6")
}));
Parameter.HOW.add_method(Parameter, 'instantiate_generic', nqp::getstaticcode(sub ($self, $type_environment) {
# Clone with the type instantiated.
@@ -2182,7 +2183,7 @@ BEGIN {
Routine.HOW.add_method(Routine, 'is_dispatcher', nqp::getstaticcode(sub ($self) {
my $dc_self := nqp::decont($self);
my $disp_list := nqp::getattr($dc_self, Routine, '@!dispatchees');
nqp::p6bool(nqp::defined($disp_list));
nqp::hllboolfor(nqp::defined($disp_list), "perl6");
}));
Routine.HOW.add_method(Routine, 'add_dispatchee', nqp::getstaticcode(sub ($self, $dispatchee) {
my $dc_self := nqp::decont($self);
@@ -3124,7 +3125,7 @@ BEGIN {
}));
Routine.HOW.add_method(Routine, 'rw', nqp::getstaticcode(sub ($self) {
my $dcself := nqp::decont($self);
nqp::p6bool(nqp::getattr_i($dcself, Routine, '$!rw'));
nqp::hllboolfor(nqp::getattr_i($dcself, Routine, '$!rw'), "perl6");
}));
Routine.HOW.add_method(Routine, 'set_inline_info', nqp::getstaticcode(sub ($self, $info) {
my $dcself := nqp::decont($self);
@@ -109,16 +109,17 @@ class Perl6::Metamodel::DefiniteHOW
# Do check when we're on LHS of smartmatch (e.g. Even ~~ Int).
method type_check($definite_type, $checkee) {
my $base_type := self.base_type($definite_type);
nqp::p6bool(nqp::istype($base_type, $checkee))
nqp::hllboolfor(nqp::istype($base_type, $checkee), "perl6")
}

# Here we check the value itself (when on RHS on smartmatch).
method accepts_type($definite_type, $checkee) {
my $base_type := self.base_type($definite_type);
my $definite := self.definite($definite_type);
nqp::p6bool(
nqp::hllboolfor(
nqp::istype($checkee, $base_type) &&
nqp::isconcrete($checkee) == $definite
nqp::isconcrete($checkee) == $definite,
"perl6"
)
}
}
@@ -8,7 +8,7 @@ role Perl6::Metamodel::MROBasedTypeChecking {
}

method does($obj, $type) {
nqp::p6bool(nqp::istype($obj, $type))
nqp::hllboolfor(nqp::istype($obj, $type), "perl6")
}

method type_check($obj, $checkee) {
@@ -59,7 +59,7 @@ class Perl6::Metamodel::SubsetHOW

method isa($obj, $type) {
$!refinee.isa($type)
|| nqp::p6bool(nqp::istrue($type.HOW =:= self))
|| nqp::hllboolfor(nqp::istrue($type.HOW =:= self), "perl6")
}

method nominalize($obj) {
@@ -77,14 +77,14 @@ class Perl6::Metamodel::SubsetHOW

# Do check when we're on LHS of smartmatch (e.g. Even ~~ Int).
method type_check($obj, $checkee) {
nqp::p6bool(nqp::istrue($checkee.HOW =:= self) ||
nqp::istype($!refinee, $checkee))
nqp::hllboolfor(nqp::istrue($checkee.HOW =:= self) ||
nqp::istype($!refinee, $checkee), "perl6")
}

# Here we check the value itself (when on RHS on smartmatch).
method accepts_type($obj, $checkee) {
nqp::p6bool(
nqp::hllboolfor(
nqp::istype($checkee, $!refinee) &&
nqp::istrue($!refinement.ACCEPTS($checkee)))
nqp::istrue($!refinement.ACCEPTS($checkee)), "perl6")
}
}
@@ -325,7 +325,7 @@ my class Problems {

%opts<pre> := nqp::box_s($pre, $!symbols.find_symbol(['Str']));
%opts<post> := nqp::box_s($post, $!symbols.find_symbol(['Str']));
%opts<is-compile-time> := nqp::p6bool(1);
%opts<is-compile-time> := nqp::hllboolfor(1, "perl6");

for %opts -> $p {
if nqp::islist($p.value) {
@@ -1317,7 +1317,7 @@ class Perl6::Optimizer {
my $last_stmt := get_last_stmt($value);
if nqp::istype($last_stmt, QAST::Op) {
my str $last_op := $last_stmt.op;
if $last_op eq 'p6bool' || nqp::eqat($last_op, 'I', -1) {
if $last_op eq 'hllbool' || nqp::eqat($last_op, 'I', -1) {
return $value;
}
if nqp::eqat($last_op, 'assign_', 0) {
@@ -1356,7 +1356,7 @@ class Perl6::Optimizer {
}

# Some ops have first boolean arg, and we may be able to get rid of
# a p6bool if there's already an integer result behind it. For if/unless,
# a hllbool if there's already an integer result behind it. For if/unless,
# we can only do that when we have the `else` branch, since otherwise we
# might return the no-longer-Bool value from the conditional.
elsif (+@($op) == 3 && ($optype eq 'if' || $optype eq 'unless'))
@@ -1367,7 +1367,7 @@ class Perl6::Optimizer {
$update := $target;
$target := $target[0];
}
if nqp::istype($target, QAST::Op) && $target.op eq 'p6bool' {
if nqp::istype($target, QAST::Op) && $target.op eq 'hllbool' {
if nqp::objprimspec($target[0].returns) == nqp::objprimspec(int) {
$update[0] := $target[0];
}
@@ -2127,7 +2127,7 @@ class Perl6::Optimizer {
}
else {
$!problems.add_exception(['X', 'Method', 'NotFound'], $op,
:private(nqp::p6bool(1)), :method($name),
:private(nqp::hllboolfor(1, "perl6")), :method($name),
:typename($pkg.HOW.name($pkg)), :invocant($pkg));
return 1;
}
@@ -2530,7 +2530,7 @@ class Perl6::Optimizer {
}

my %opts := nqp::hash();
%opts<protoguilt> := $protoguilt // nqp::p6bool(0);
%opts<protoguilt> := $protoguilt // nqp::hllboolfor(0, "perl6");
%opts<arguments> := @arg_names;
%opts<objname> := $obj.name;
%opts<signature> := nqp::can($obj, 'is_dispatcher') && $obj.is_dispatcher && !$protoguilt ??
@@ -4271,7 +4271,7 @@ class Perl6::World is HLL::World {
nqp::istype($val, QAST::Op)
# XXX TODO: the circumfix:<[ ]> path is a misparse of parameterization,
# e.g. List:D[Int]. When parse is fixed, the circumfix branch likely can be removed
?? $val.op eq 'p6bool' || $val.op eq 'call' && $val.name eq '&circumfix:<[ ]>'
?? $val.op eq 'hllbool' || $val.op eq 'call' && $val.name eq '&circumfix:<[ ]>'
?? nqp::null # not a coercer, but just got a regular DefiniteHOW
!! $val.name eq '&infix:<,>' && @($val) == 0
?? self.find_symbol: ['Any'], :setting-only # empty coercer source type
@@ -18,7 +18,7 @@ my class Any { # declared in BOOTSTRAP
multi method ACCEPTS(Any:D: Mu:D \a) { self === a }
multi method ACCEPTS(Any:D: Mu:U $ --> False) { }
multi method ACCEPTS(Any:U: Any \topic) { # use of Any on topic to force autothreading
nqp::p6bool(nqp::istype(topic, self)) # so that all(@foo) ~~ Type works as expected
nqp::hllbool(nqp::istype(topic, self)) # so that all(@foo) ~~ Type works as expected
}

proto method EXISTS-KEY(|) is nodal {*}
@@ -221,7 +221,7 @@ my class Any { # declared in BOOTSTRAP
}

multi method EXISTS-POS(Any:D: int \pos) {
nqp::p6bool(nqp::iseq_i(pos,0));
nqp::hllbool(nqp::iseq_i(pos,0));
}
multi method EXISTS-POS(Any:D: Int:D \pos) {
pos == 0;
@@ -454,7 +454,7 @@ Metamodel::ClassHOW.exclude_parent(Any);
proto sub infix:<===>($?, $?, *%) is pure {*}
multi sub infix:<===>($?) { Bool::True }
multi sub infix:<===>(\a, \b) {
nqp::p6bool(
nqp::hllbool(
nqp::eqaddr(nqp::decont(a),nqp::decont(b))
|| (nqp::eqaddr(a.WHAT,b.WHAT)
&& nqp::iseq_s(nqp::unbox_s(a.WHICH), nqp::unbox_s(b.WHICH)))
@@ -13,7 +13,7 @@ Rakudo::Internals.REGISTER-DYNAMIC: '$*ARGFILES', {
!! IO::ArgFiles.new:
(my $in := $*IN),
:nl-in($in.nl-in), :chomp($in.chomp), :encoding($in.encoding),
:bin(nqp::p6bool(nqp::isfalse($in.encoding)));
:bin(nqp::hllbool(nqp::isfalse($in.encoding)));
}

# vim: ft=perl6 expandtab sw=4
@@ -56,7 +56,7 @@ my class Backtrace::Frame {
?$!code.?is-hidden-from-backtrace
}
method is-routine(Backtrace::Frame:D:) {
nqp::p6bool(nqp::istype($!code,Routine))
nqp::hllbool(nqp::istype($!code,Routine))
}
method is-setting(Backtrace::Frame:D:) {
$!file.starts-with("SETTING::")

0 comments on commit 170ffd4

Please sign in to comment.
You can’t perform that action at this time.