Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created May 11, 2017 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/bc1c749cd9b33b41ff87d9228154956c to your computer and use it in GitHub Desktop.
Save MasterDuke17/bc1c749cd9b33b41ff87d9228154956c to your computer and use it in GitHub Desktop.
diff --git a/src/Perl6/Metamodel/BOOTSTRAP.nqp b/src/Perl6/Metamodel/BOOTSTRAP.nqp
index 57b9b91bd..1b38dfd80 100644
--- a/src/Perl6/Metamodel/BOOTSTRAP.nqp
+++ b/src/Perl6/Metamodel/BOOTSTRAP.nqp
@@ -261,9 +261,7 @@ my class Binder {
# Otherwise, incompatible native types.
else {
- if nqp::defined($error) {
- $error[0] := "Incompatible native type passed for '$varname'";
- }
+ $error[0] := "Incompatible native type passed for '$varname'" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
}
@@ -271,26 +269,22 @@ my class Binder {
# By this point, we'll either have an object that we might be able to
# bind if it passes the type check, or a native value that needs no
# further checking.
- my $nom_type;
unless $got_native || ($is_rw && $desired_native) {
# HLL-ize.
$oval := nqp::hllizefor($oval, 'perl6');
# Skip nominal type check if not needed.
unless $no_nom_type_check {
+ my $nom_type;
# Is the nominal type generic and in need of instantiation? (This
# can happen in (::T, T) where we didn't learn about the type until
# during the signature bind).
$nom_type := nqp::getattr($param, Parameter, '$!nominal_type');
- if $flags +& $SIG_ELEM_NOMINAL_GENERIC {
- $nom_type := $nom_type.HOW.instantiate_generic($nom_type, $lexpad);
- }
+ $nom_type := $nom_type.HOW.instantiate_generic($nom_type, $lexpad) if $flags +& $SIG_ELEM_NOMINAL_GENERIC;
# If the expected type is Positional, see if we need to do the
# positional bind failover.
- if nqp::istype($nom_type, $Positional) && nqp::istype($oval, $PositionalBindFailover) {
- $oval := $oval.cache;
- }
+ $oval := $oval.cache if nqp::istype($nom_type, $Positional) && nqp::istype($oval, $PositionalBindFailover);
# If not, do the check. If the wanted nominal type is Mu, then
# anything goes.
@@ -298,14 +292,11 @@ my class Binder {
# Type check failed; produce error if needed.
if nqp::defined($error) {
my %ex := nqp::gethllsym('perl6', 'P6EX');
- if nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::TypeCheck::Binding::Parameter') {
- $error[0] := "Nominal type check failed for parameter '" ~ $varname ~
- "'; expected " ~ $nom_type.HOW.name($nom_type) ~
- " but got " ~ $oval.HOW.name($oval);
- } else {
- $error[0] := { nqp::atkey(%ex, 'X::TypeCheck::Binding::Parameter')($oval,
- $nom_type.WHAT, $varname, $param) };
- }
+ $error[0] := nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::TypeCheck::Binding::Parameter')
+ ?? "Nominal type check failed for parameter '" ~ $varname ~
+ "'; expected " ~ $nom_type.HOW.name($nom_type) ~
+ " but got " ~ $oval.HOW.name($oval)
+ !! { nqp::atkey(%ex, 'X::TypeCheck::Binding::Parameter')($oval, $nom_type.WHAT, $varname, $param) };
}
# Report junction failure mode if it's a junction.
@@ -315,9 +306,9 @@ my class Binder {
}
# Also enforce definedness constraints.
- if $flags +& $SIG_ELEM_DEFINEDNES_CHECK {
- if (my $should_be_concrete := $flags +& $SIG_ELEM_DEFINED_ONLY && !nqp::isconcrete($oval)) ||
- $flags +& $SIG_ELEM_UNDEFINED_ONLY && nqp::isconcrete($oval)
+ if $flags +& $SIG_ELEM_DEFINEDNES_CHECK &&
+ ((my $should_be_concrete := $flags +& $SIG_ELEM_DEFINED_ONLY && !nqp::isconcrete($oval)) ||
+ $flags +& $SIG_ELEM_UNDEFINED_ONLY && nqp::isconcrete($oval))
{
if nqp::defined($error) {
my $method := nqp::getcodeobj(nqp::ctxcode($lexpad)).name;
@@ -340,7 +331,6 @@ my class Binder {
return $oval.WHAT =:= Junction && nqp::isconcrete($oval)
?? $BIND_RESULT_JUNCTION
!! $BIND_RESULT_FAIL;
- }
}
}
}
@@ -349,11 +339,8 @@ my class Binder {
my $type_caps := nqp::getattr($param, Parameter, '@!type_captures');
unless nqp::isnull($type_caps) {
my int $num_type_caps := nqp::elems($type_caps);
- my int $i := 0;
- while $i < $num_type_caps {
- nqp::bindkey($lexpad, nqp::atpos_s($type_caps, $i), $oval.WHAT);
- $i++;
- }
+ my int $i := -1;
+ nqp::bindkey($lexpad, nqp::atpos_s($type_caps, $i), $oval.WHAT) while ++$i < $num_type_caps;
}
# Do a coercion, if one is needed.
@@ -361,9 +348,7 @@ my class Binder {
unless nqp::isnull($coerce_type) {
# Coercing natives not possible - nothing to call a method on.
if $got_native {
- if nqp::defined($error) {
- $error[0] := "Unable to coerce natively typed parameter '$varname'";
- }
+ $error[0] := "Unable to coerce natively typed parameter '$varname'" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
@@ -383,11 +368,8 @@ my class Binder {
}
else {
# No coercion method available; whine and fail to bind.
- if nqp::defined($error) {
- $error[0] := "Unable to coerce value for '$varname' from " ~
- $oval.HOW.name($oval) ~
- " to $coerce_method; no coercion method defined";
- }
+ $error[0] := "Unable to coerce value for '$varname' from " ~ $oval.HOW.name($oval) ~
+ " to $coerce_method; no coercion method defined" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
}
@@ -418,12 +400,10 @@ my class Binder {
else {
if nqp::defined($error) {
my %ex := nqp::gethllsym('perl6', 'P6EX');
- if nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::Parameter::RW') {
- $error[0] := "Parameter '$varname' expected a writable container, but got an " ~
- ~ $oval.HOW.name($oval) ~ " value";
- } else {
- $error[0] := { nqp::atkey(%ex, 'X::Parameter::RW')($oval, $varname) };
- }
+ $error[0] := nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::Parameter::RW')
+ ?? "Parameter '$varname' expected a writable container, but got an " ~
+ ~ $oval.HOW.name($oval) ~ " value"
+ !! { nqp::atkey(%ex, 'X::Parameter::RW')($oval, $varname) };
}
return $BIND_RESULT_FAIL;
}
@@ -474,9 +454,7 @@ my class Binder {
}
# Is it the invocant? If so, also have to bind to self lexical.
- if $flags +& $SIG_ELEM_INVOCANT {
- nqp::bindkey($lexpad, 'self', nqp::decont($oval));
- }
+ nqp::bindkey($lexpad, 'self', nqp::decont($oval)) if $flags +& $SIG_ELEM_INVOCANT;
# Handle any constraint types (note that they may refer to the parameter by
# name, so we need to have bound it already).
@@ -487,9 +465,7 @@ my class Binder {
while $i < $n {
# Check we meet the constraint.
my $cons_type := nqp::atpos($post_cons, $i);
- if nqp::istype($cons_type, Code) {
- $cons_type := nqp::p6capturelexwhere($cons_type.clone());
- }
+ $cons_type := nqp::p6capturelexwhere($cons_type.clone()) if nqp::istype($cons_type, Code);
my $result;
my $bad_value;
if $got_native == 0 {
@@ -511,12 +487,10 @@ my class Binder {
unless $result {
if nqp::defined($error) {
my %ex := nqp::gethllsym('perl6', 'P6EX');
- if nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::TypeCheck::Binding::Parameter') {
- $error[0] := "Constraint type check failed for parameter '$varname'";
- } else {
- $error[0] := { nqp::atkey(%ex, 'X::TypeCheck::Binding::Parameter')(
+ $error[0] := nqp::isnull(%ex) || !nqp::existskey(%ex, 'X::TypeCheck::Binding::Parameter')
+ ?? "Constraint type check failed for parameter '$varname'"
+ !! { nqp::atkey(%ex, 'X::TypeCheck::Binding::Parameter')(
$bad_value, $cons_type, $varname, $param, 1) };
- }
}
return $BIND_RESULT_FAIL;
}
@@ -531,17 +505,13 @@ my class Binder {
if nqp::existskey($lexpad, 'self') {
$self := nqp::atkey($lexpad, 'self');
} else {
- if nqp::defined($error) {
- $error[0] := "Unable to bind attributive parameter '$varname'; could not find self";
- }
+ $error[0] := "Unable to bind attributive parameter '$varname'; could not find self" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
# Ensure it's not native; NYI.
if $got_native {
- if nqp::defined($error) {
- $error[0] := "Binding to natively typed attributive parameter '$varname' not supported";
- }
+ $error[0] := "Binding to natively typed attributive parameter '$varname' not supported" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
@@ -576,9 +546,7 @@ my class Binder {
$capture := $oval.Capture;
}
else {
- if nqp::defined($error) {
- $error[0] := "Could not turn argument into capture";
- }
+ $error[0] := "Could not turn argument into capture" if nqp::defined($error);
return $BIND_RESULT_FAIL;
}
}
@@ -590,9 +558,7 @@ my class Binder {
if $error && nqp::isstr($error[0]) {
# Note in the error message that we're in a sub-signature.
$error[0] := $error[0] ~ " in sub-signature";
- if $has_varname {
- $error[0] := $error[0] ~ " of parameter " ~ $varname;
- }
+ $error[0] := $error[0] ~ " of parameter " ~ $varname if $has_varname;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment