Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
index and ord also work with varying numbers of arguments.
  • Loading branch information
jnthn committed Jul 21, 2012
1 parent 366f84f commit 939c9ff
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/QAST/Operations.nqp
Expand Up @@ -1150,9 +1150,7 @@ QAST::Operations.add_core_pirop_mapping('concat', 'concat', 'Sss');
QAST::Operations.add_core_pirop_mapping('concat_s', 'concat', 'Sss');
QAST::Operations.add_core_pirop_mapping('join', 'join', 'SsP');
QAST::Operations.add_core_pirop_mapping('split', 'split', 'Pss');
QAST::Operations.add_core_pirop_mapping('index', 'index', 'Issi');
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('x', 'repeat', 'Ssi');
Expand All @@ -1169,6 +1167,25 @@ QAST::Operations.add_core_op('substr', -> $qastcomp, $op {
!! QAST::Op.new( :op('substr3'), |@operands ));
});

# ord can be on a the first char in a string or at a particular char.
QAST::Operations.add_core_pirop_mapping('ordfirst', 'ord', 'Is');
QAST::Operations.add_core_pirop_mapping('ordat', 'ord', 'Isi');
QAST::Operations.add_core_op('ord', -> $qastcomp, $op {
my @operands := $op.list;
$qastcomp.as_post(+@operands == 1
?? QAST::Op.new( :op('ordfirst'), |@operands )
!! QAST::Op.new( :op('ordat'), |@operands ));
});

# index may or may not take a starting position
QAST::Operations.add_core_pirop_mapping('indexfrom', 'index', 'Issi');
QAST::Operations.add_core_op('index', -> $qastcomp, $op {
my @operands := $op.list;
$qastcomp.as_post(+@operands == 2
?? QAST::Op.new( :op('indexfrom'), |@operands, QAST::IVal.new( :value(0) ) )
!! QAST::Op.new( :op('indexfrom'), |@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 939c9ff

Please sign in to comment.