Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add nqp::flip op with a simple test for 59-nqpops
  • Loading branch information
timo committed Apr 10, 2013
1 parent 445f1ac commit e92eff1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/QAST/Operations.nqp
Expand Up @@ -1684,6 +1684,19 @@ QAST::Operations.add_core_pirop_mapping('findnotcclass', 'find_not_cclass', 'Iis
QAST::Operations.add_core_pirop_mapping('sprintf', 'sprintf', 'SsP', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('escape', 'escape', 'Ss', :inlinable(1));

QAST::Operations.add_core_op('flip', :inlinable(1), -> $qastcomp, $op {
if +@($op) != 1 {
nqp::die('flip requires one operand');
}
$qastcomp.as_post(
QAST::VM.new( :pirop('set__SP'),
QAST::Op.new( :op('callmethod'),
:name('reverse'),
QAST::VM.new( :pirop('box__PS'), $op[0] ) ) )
);
});


# substr can take 2 or 3 args, so needs special handling.
QAST::Operations.add_core_pirop_mapping('substr2', 'substr', 'Ssi', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('substr3', 'substr', 'Ssii', :inlinable(1));
Expand Down
3 changes: 2 additions & 1 deletion t/nqp/59-nqpop.t
Expand Up @@ -2,7 +2,7 @@

# Test nqp::op pseudo-functions.

plan(123);
plan(124);


ok( nqp::add_i(5,2) == 7, 'nqp::add_i');
Expand All @@ -24,6 +24,7 @@ ok( nqp::chr(120) eq 'x', 'nqp::chr');
ok( nqp::ord('xyz') eq 120, 'nqp::ord');
ok( nqp::lc('Hello World') eq 'hello world', 'nqp::downcase');
ok( nqp::uc("Don't Panic") eq "DON'T PANIC", 'nqp::upcase');
ok( nqp::flip("foo") eq "oof", "nqp::flip");

my @items := nqp::split(' ', 'a little lamb');
ok( nqp::elems(@items) == 3 && @items[0] eq 'a' && @items[1] eq 'little' && @items[2] eq 'lamb', 'nqp::split');
Expand Down

0 comments on commit e92eff1

Please sign in to comment.