Skip to content

Commit

Permalink
[Truffle] Implement Regexp#source.
Browse files Browse the repository at this point in the history
* RubyRegexp.source should obviously be a String.
  • Loading branch information
eregon committed Oct 31, 2014
1 parent 7bce91f commit 4256190
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Expand Up @@ -172,4 +172,22 @@ public Object match(RubyRegexp regexp, RubyString string) {

}

@CoreMethod(names = "source")
public abstract static class SourceNode extends CoreMethodNode {

public SourceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public SourceNode(SourceNode prev) {
super(prev);
}

@Specialization
public Object source(RubyRegexp regexp) {
return getContext().makeString(regexp.getSource());
}

}

}
Expand Up @@ -51,7 +51,7 @@ public RubyBasicObject newInstance(RubyNode currentNode) {
}

@CompilationFinal private Regex regex;
@CompilationFinal private Object source;
@CompilationFinal private String source;

public RubyRegexp(RubyClass regexpClass) {
super(regexpClass);
Expand Down Expand Up @@ -81,6 +81,10 @@ public Regex getRegex() {
return regex;
}

public String getSource() {
return source;
}

@CompilerDirectives.SlowPath
public Object matchOperator(String string) {
// TODO(CS) merge with match
Expand Down

0 comments on commit 4256190

Please sign in to comment.