Skip to content

Commit

Permalink
Replace use of p6bool by hllbool and hllboolfor
Browse files Browse the repository at this point in the history
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 17, 2018
1 parent 16eab40 commit dbca2ee
Show file tree
Hide file tree
Showing 71 changed files with 341 additions and 334 deletions.
10 changes: 5 additions & 5 deletions lib/Telemetry.pm6
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Perl6/Actions.nqp
Expand Up @@ -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(
Expand Down Expand Up @@ -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) )
));
}
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 18 additions & 17 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -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),
Expand All @@ -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);
Expand All @@ -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),
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/Perl6/Metamodel/DefiniteHOW.nqp
Expand Up @@ -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"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/MROBasedTypeChecking.nqp
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/Perl6/Metamodel/SubsetHOW.nqp
Expand Up @@ -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) {
Expand All @@ -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")
}
}
12 changes: 6 additions & 6 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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'))
Expand All @@ -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];
}
Expand Down Expand Up @@ -2125,7 +2125,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;
}
Expand Down Expand Up @@ -2528,7 +2528,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<dispatcher> := $obj;
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/World.nqp
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/core/Any.pm6
Expand Up @@ -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 {*}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion src/core/Argfiles.pm6
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/core/Backtrace.pm6
Expand Up @@ -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::")
Expand Down

0 comments on commit dbca2ee

Please sign in to comment.