Skip to content

Commit

Permalink
[Truffle] Put most of MatchDataNodes behind a boundary.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Sep 22, 2015
1 parent 7b4cee8 commit f4cd59c
Showing 1 changed file with 15 additions and 19 deletions.
Expand Up @@ -277,10 +277,9 @@ public GetIndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object getIndex(RubyBasicObject matchData, int index, NotProvided length) {
CompilerDirectives.transferToInterpreter();

final Object[] values = getValues(matchData);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);

Expand All @@ -291,20 +290,19 @@ public Object getIndex(RubyBasicObject matchData, int index, NotProvided length)
}
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object getIndex(RubyBasicObject matchData, int index, int length) {
CompilerDirectives.transferToInterpreter();
// TODO BJF 15-May-2015 Need to handle negative indexes and lengths and out of bounds
final Object[] values = getValues(matchData);
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);
final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
return createArray(store, length);
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubySymbol(index)")
public Object getIndexSymbol(RubyBasicObject matchData, RubyBasicObject index, NotProvided length) {
CompilerDirectives.transferToInterpreter();

try {
final int i = getBackrefNumber(matchData, SymbolNodes.getByteList(index));

Expand All @@ -317,10 +315,9 @@ public Object getIndexSymbol(RubyBasicObject matchData, RubyBasicObject index, N
}
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(index)")
public Object getIndexString(RubyBasicObject matchData, RubyBasicObject index, NotProvided length) {
CompilerDirectives.transferToInterpreter();

try {
final int i = getBackrefNumber(matchData, StringNodes.getByteList(index));

Expand All @@ -336,8 +333,6 @@ public Object getIndexString(RubyBasicObject matchData, RubyBasicObject index, N

@Specialization(guards = {"!isRubySymbol(index)", "!isRubyString(index)", "!isIntegerFixnumRange(index)"})
public Object getIndex(VirtualFrame frame, RubyBasicObject matchData, Object index, NotProvided length) {
CompilerDirectives.transferToInterpreter();

if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
Expand All @@ -346,6 +341,7 @@ public Object getIndex(VirtualFrame frame, RubyBasicObject matchData, Object ind
return getIndex(matchData, toIntNode.doInt(frame, index), NotProvided.INSTANCE);
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isIntegerFixnumRange(range)")
public Object getIndex(RubyBasicObject matchData, RubyBasicObject range, NotProvided len) {
final Object[] values = getValues(matchData);
Expand All @@ -369,10 +365,9 @@ public BeginNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object begin(RubyBasicObject matchData, int index) {
CompilerDirectives.transferToInterpreter();

if (badIndexProfile.profile((index < 0) || (index >= getNumberOfRegions(matchData)))) {
CompilerDirectives.transferToInterpreter();

Expand All @@ -393,10 +388,9 @@ public CapturesNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyBasicObject toA(RubyBasicObject matchData) {
CompilerDirectives.transferToInterpreter();

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), getCaptures(matchData));
}
}
Expand All @@ -410,10 +404,9 @@ public EndNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object end(RubyBasicObject matchData, int index) {
CompilerDirectives.transferToInterpreter();

if (badIndexProfile.profile((index < 0) || (index >= getNumberOfRegions(matchData)))) {
CompilerDirectives.transferToInterpreter();

Expand Down Expand Up @@ -465,6 +458,7 @@ public LengthNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public int length(RubyBasicObject matchData) {
return getValues(matchData).length;
Expand All @@ -482,6 +476,7 @@ public PreMatchNode(RubyContext context, SourceSection sourceSection) {
taintResultNode = new TaintResultNode(getContext(), getSourceSection());
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object preMatch(RubyBasicObject matchData) {
return taintResultNode.maybeTaint(getSource(matchData), getPre(matchData));
Expand All @@ -499,6 +494,7 @@ public PostMatchNode(RubyContext context, SourceSection sourceSection) {
taintResultNode = new TaintResultNode(getContext(), getSourceSection());
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object postMatch(RubyBasicObject matchData) {
return taintResultNode.maybeTaint(getSource(matchData), getPost(matchData));
Expand All @@ -513,10 +509,9 @@ public ToANode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyBasicObject toA(RubyBasicObject matchData) {
CompilerDirectives.transferToInterpreter();

return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), getValues(matchData));
}
}
Expand All @@ -528,10 +523,9 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyBasicObject toS(RubyBasicObject matchData) {
CompilerDirectives.transferToInterpreter();

final ByteList bytes = StringNodes.getByteList(getGlobal(matchData)).dup();
return createString(bytes);
}
Expand All @@ -544,6 +538,7 @@ public RegexpNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyBasicObject regexp(RubyBasicObject matchData) {
return getRegexp(matchData);
Expand All @@ -558,6 +553,7 @@ public RubiniusSourceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyBasicObject rubiniusSource(RubyBasicObject matchData) {
return getSource(matchData);
Expand Down

0 comments on commit f4cd59c

Please sign in to comment.