Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Compile uniprop (for /<:L>/ style things).
May need to do some massaging of the property names, but this basically
works.
  • Loading branch information
jnthn committed Feb 22, 2013
1 parent 9ded178 commit 7760d12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -4348,6 +4348,27 @@ class QAST::CompilerJAST {

$il;
}

method uniprop($node) {
my $il := JAST::InstructionList.new();

$il.append(JAST::PushSVal.new( :value($node[0]) ));
$il.append(JAST::Instruction.new( :op('aload'), %*REG<tgt> ));
$il.append(JAST::Instruction.new( :op('lload'), %*REG<pos> ));
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS,
"ischarprop", 'Long', $TYPE_STR, $TYPE_STR, 'Long' ));
$il.append(JAST::Instruction.new( :op('l2i') ));
$il.append(JAST::Instruction.new( :op($node.negate ?? 'ifne' !! 'ifeq'), %*REG<fail> ));

unless $node.subtype eq 'zerowidth' {
$il.append(JAST::Instruction.new( :op('lload'), %*REG<pos> ));
$il.append(JAST::PushIVal.new( :value(1) ));
$il.append(JAST::Instruction.new( :op('ladd') ));
$il.append(JAST::Instruction.new( :op('lstore'), %*REG<pos> ));
}

$il
}

# a :rxtype<ws> node is a normal subrule call
method ws($node) { self.subrule($node) }
Expand Down
5 changes: 5 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1884,6 +1884,11 @@ public static long findnotcclass(long cclass, String target, long offset, long c

return end;
}

public static long ischarprop(String propName, String target, long offset) {
String check = target.substring((int)offset, (int)offset + 1);
return check.matches("\\p{" + propName + "}") ? 1 : 0;
}

/* serialization context related opcodes */
public static String sha1(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
Expand Down

0 comments on commit 7760d12

Please sign in to comment.