Skip to content

Commit

Permalink
Showing 2 changed files with 30 additions and 24 deletions.
50 changes: 27 additions & 23 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -980,50 +980,54 @@ public boolean isInstanceVariableDefinedSymbol(DynamicObject object, DynamicObje
}

@CoreMethod(names = "instance_variable_get", required = 1)
public abstract static class InstanceVariableGetNode extends CoreMethodArrayArgumentsNode {
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "object"),
@NodeChild(type = RubyNode.class, value = "name")
})
public abstract static class InstanceVariableGetNode extends CoreMethodNode {

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

@TruffleBoundary
@Specialization(guards = "isRubyString(name)")
public Object instanceVariableGetString(DynamicObject object, DynamicObject name) {
return instanceVariableGet(object, name.toString());
@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@TruffleBoundary
@Specialization(guards = "isRubySymbol(name)")
public Object instanceVariableGetSymbol(DynamicObject object, DynamicObject name) {
return instanceVariableGet(object, Layouts.SYMBOL.getString(name));
}

private Object instanceVariableGet(DynamicObject object, String name) {
return object.get(RubyContext.checkInstanceVariableName(getContext(), name, this), nil());
@Specialization
public Object instanceVariableGetString(DynamicObject object, String name) {
final String ivar = RubyContext.checkInstanceVariableName(getContext(), name, this);
return object.get(ivar, nil());
}

}

@CoreMethod(names = { "instance_variable_set", "__instance_variable_set__" }, raiseIfFrozenSelf = true, required = 2)
public abstract static class InstanceVariableSetNode extends CoreMethodArrayArgumentsNode {
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "object"),
@NodeChild(type = RubyNode.class, value = "name"),
@NodeChild(type = RubyNode.class, value = "value")
})
public abstract static class InstanceVariableSetNode extends CoreMethodNode {

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

// TODO CS 4-Mar-15 this badly needs to be cached

@TruffleBoundary
@Specialization(guards = "isRubyString(name)")
public Object instanceVariableSetString(DynamicObject object, DynamicObject name, Object value) {
object.define(RubyContext.checkInstanceVariableName(getContext(), name.toString(), this), value, 0);
return value;
@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

// TODO CS 4-Mar-15 this badly needs to be cached

@TruffleBoundary
@Specialization(guards = "isRubySymbol(name)")
public Object instanceVariableSetSymbol(DynamicObject object, DynamicObject name, Object value) {
object.define(RubyContext.checkInstanceVariableName(getContext(), Layouts.SYMBOL.getString(name), this), value, 0);
@Specialization
public Object instanceVariableSetString(DynamicObject object, String name, Object value) {
final String ivar = RubyContext.checkInstanceVariableName(getContext(), name, this);
object.define(ivar, value, 0);
return value;
}

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.RubyThread.Status;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyGuards;
@@ -55,7 +56,8 @@ public static void initialize(final DynamicObject thread, RubyContext context, N
initialize(thread, context, currentNode, info, new Runnable() {
@Override
public void run() {
Layouts.THREAD.setValue(thread, ProcNodes.rootCall(block, arguments));
final Object value = ProcNodes.rootCall(block, arguments);
Layouts.THREAD.setValue(thread, value);
}
});
}

0 comments on commit 8a77dfa

Please sign in to comment.