Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handling for 2 and 3 arg version of substr.
  • Loading branch information
jnthn committed Jul 21, 2012
1 parent 6ad982a commit 0cf1ec5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/QAST/Operations.nqp
Expand Up @@ -1141,11 +1141,20 @@ QAST::Operations.add_core_pirop_mapping('chr', 'chr', 'Si');
QAST::Operations.add_core_pirop_mapping('ord', 'ord', 'Isi');
QAST::Operations.add_core_pirop_mapping('lc', 'downcase', 'Ss');
QAST::Operations.add_core_pirop_mapping('uc', 'upcase', 'Ss');
QAST::Operations.add_core_pirop_mapping('substr', 'substr', 'Ssii');
QAST::Operations.add_core_pirop_mapping('x', 'repeat', 'Ssi');
QAST::Operations.add_core_pirop_mapping('iscclass', 'is_cclass', 'Iisi');
QAST::Operations.add_core_pirop_mapping('sprintf', 'sprintf', 'SsP');

# substr can take 2 or 3 args, so needs special handling.
QAST::Operations.add_core_pirop_mapping('substr2', 'substr', 'Ssi');
QAST::Operations.add_core_pirop_mapping('substr3', 'substr', 'Ssii');
QAST::Operations.add_core_op('substr', -> $qastcomp, $op {
my @operands := $op.list;
$qastcomp.as_post(+@operands == 2
?? QAST::Op.new( :op('substr2'), |@operands )
!! QAST::Op.new( :op('substr3'), |@operands ));
});

# relational opcodes
QAST::Operations.add_core_pirop_mapping('cmp_i', 'cmp', 'Iii');
QAST::Operations.add_core_pirop_mapping('iseq_i', 'iseq', 'Iii');
Expand Down

0 comments on commit 0cf1ec5

Please sign in to comment.