Skip to content

Commit

Permalink
[Truffle] Use a node directly for MatchData @source.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Feb 17, 2015
1 parent 3482b59 commit e44268c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Expand Up @@ -10,11 +10,14 @@
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.joni.exception.ValueException;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
Expand Down Expand Up @@ -262,8 +265,9 @@ public RubyArray valuesAt(RubyMatchData matchData, Object[] args) {

}

@CoreMethod(names = "__rubinius_source__", visibility = Visibility.PRIVATE)
public abstract static class RubiniusSourceNode extends CoreMethodNode {
// Not a core method, used to simulate Rubinius @source.
@NodeChild(value = "self")
public abstract static class RubiniusSourceNode extends RubyNode {

public RubiniusSourceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Expand Up @@ -118,8 +118,6 @@ public void pauseAllThreadsAndExecuteFromNonRubyThread(Consumer<RubyThread> acti
}

private synchronized void pauseAllThreadsAndExecute(boolean holdsGlobalLock, Consumer<RubyThread> action) {
CompilerDirectives.transferToInterpreter();

This comment has been minimized.

Copy link
@eregon

eregon Feb 17, 2015

Author Member

Unintended change ...

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Feb 17, 2015

Contributor

It's probably not important - I'd say this is more notDesigned at the moment anyway.

this.action = action;

/* this is a potential cause for race conditions,
Expand Down
Expand Up @@ -1544,13 +1544,9 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/regexp.rb")) {
if (nameWithoutSigil.equals("@source")) {
return new RubyCallNode(context, sourceSection,
"__rubinius_source__",
new SelfNode(context, sourceSection),
null,
false,
true,
false);
return MatchDataNodesFactory.RubiniusSourceNodeFactory.create(
context, sourceSection,
new SelfNode(context, sourceSection));
} else if (nameWithoutSigil.equals("@full")) {
return new RubyCallNode(context, sourceSection,
"full",
Expand Down

3 comments on commit e44268c

@chrisseaton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I get the idea and it works well in this case. The only thing I'm not sure about is having nodes that aren't @CoreMethod in a @CoreClass - that might be confusing. But I'm nitpicking.

@eregon
Copy link
Member Author

@eregon eregon commented on e44268c Feb 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I'd rather keep nodes with a given receiver type together than split them in a third hypothetical hierarchy :)

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. And I like keeping it grouped with the receiver. If we want a new namespace, I'd shove them into another inner class named "RubiniusHelpers" or something.

Please sign in to comment.