Skip to content

Commit

Permalink
Fixes to JIT of regexp named-group captured vars.
Browse files Browse the repository at this point in the history
* Store result to complete SetCapturedVar.
* Get name using depth and offset during IR build of captured var.

Fixes #1993.
  • Loading branch information
headius committed Sep 20, 2014
1 parent 7ef5314 commit 8782912
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2573,20 +2573,26 @@ public Operand buildMatch2(Match2Node matchNode, IRScope s) {
addInstr(s, new Match2Instr(result, receiver, value));
if (matchNode instanceof Match2CaptureNode) {
Match2CaptureNode m2c = (Match2CaptureNode)matchNode;
String[] vars = s.getStaticScope().getVariables();
for (int slot: m2c.getScopeOffsets()) {
// Static scope scope offsets store both depth and offset
int depth = slot >> 16;
int offset = slot & 0xffff;

// For now, we'll continue to implicitly reference "$~"
String var = vars[offset];
String var = getVarNameFromScopeTree(s, depth, offset);
addInstr(s, new SetCapturedVarInstr(s.getLocalVariable(var, depth), result, var));
}
}
return result;
}

private String getVarNameFromScopeTree(IRScope scope, int depth, int offset) {
if (depth == 0) {
return scope.getStaticScope().getVariables()[offset];
}
return getVarNameFromScopeTree(scope.getLexicalParent(), depth - 1, offset);
}

public Operand buildMatch3(Match3Node matchNode, IRScope s) {
Operand receiver = build(matchNode.getReceiverNode(), s);
Operand value = build(matchNode.getValueNode(), s);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ public void SetCapturedVarInstr(SetCapturedVarInstr instr) {
visit(instr.getMatch2Result());
jvmAdapter().ldc(instr.getVarName());
jvmMethod().invokeIRHelper("setCapturedVar", sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, String.class));
jvmStoreLocal(instr.getResult());
}

@Override
Expand Down

0 comments on commit 8782912

Please sign in to comment.