Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created November 12, 2020 14:37
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/9959976cabaa8c22649550d7ebfe708c to your computer and use it in GitHub Desktop.
Save MasterDuke17/9959976cabaa8c22649550d7ebfe708c to your computer and use it in GitHub Desktop.
diff --git src/Perl6/Actions.nqp src/Perl6/Actions.nqp
index f7b640f6f..df03c7e3c 100644
--- src/Perl6/Actions.nqp
+++ src/Perl6/Actions.nqp
@@ -2310,10 +2310,52 @@ class Perl6::Actions is HLL::Actions does STDActions {
check_smartmatch($<xblock>,$sm_exp);
# Handle the smart-match.
- my $match_past := QAST::Op.new( :op('callmethod'), :name('ACCEPTS'),
- $sm_exp,
- WANTED(QAST::Var.new( :name('$_'), :scope('lexical') ),'when')
- );
+ my $match_past;
+ if nqp::istype($sm_exp, QAST::WVal) && !nqp::isconcrete($sm_exp.value) {
+ $match_past := QAST::Op.new( :op('istype'),
+ WANTED(QAST::Var.new( :name('$_'), :scope('lexical') ),'when'),
+ $sm_exp);
+ }
+ elsif nqp::istype($sm_exp, QAST::Want) {
+ my $op_type;
+ my $method;
+ if nqp::istype($sm_exp[2], QAST::IVal) {
+ $op_type := 'i';
+ $method := 'Numeric';
+ }
+ elsif nqp::istype($sm_exp[2], QAST::SVal) {
+ $op_type := 's';
+ $method := 'Stringy';
+ }
+ elsif nqp::istype($sm_exp[2], QAST::NVal) {
+ $op_type := 'n';
+ $method := 'Numeric';
+ }
+ else {
+ die("Unknown QAST::Want type");
+ }
+
+ my $is_eq := QAST::Op.new( :op("iseq_$op_type"),
+ $sm_exp[2],
+ WANTED(QAST::Op.new( :op('callmethod'), :name($method), QAST::Var.new( :name('$_'), :scope('lexical') )),'when'));
+ fatalize($is_eq);
+
+ $match_past := QAST::Op.new(
+ :op('handle'),
+
+ # Success path evaluates to the block.
+ $is_eq,
+
+ # On failure, just evaluate to False
+ 'CATCH',
+
+ QAST::WVal.new( :value( $*W.find_single_symbol('False') ) ) );
+ }
+ else {
+ $match_past := QAST::Op.new( :op('callmethod'), :name('ACCEPTS'),
+ $sm_exp,
+ WANTED(QAST::Var.new( :name('$_'), :scope('lexical') ),'when'));
+ }
# Use the smartmatch result as the condition for running the block,
# and ensure continue/succeed handlers are in place and that a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment