Skip to content

Commit

Permalink
Showing 9 changed files with 58 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.globals.GetFromThreadLocalNode;
import org.jruby.truffle.nodes.globals.WrapInThreadLocalNode;
import org.jruby.truffle.nodes.locals.ReadAbstractFrameSlotNode;
import org.jruby.truffle.nodes.locals.ReadAbstractFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.WriteAbstractFrameSlotNode;
import org.jruby.truffle.nodes.locals.WriteAbstractFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNode;
import org.jruby.truffle.nodes.locals.ReadFrameSlotNodeGen;
import org.jruby.truffle.nodes.locals.WriteFrameSlotNode;
import org.jruby.truffle.nodes.locals.WriteFrameSlotNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -84,7 +84,7 @@ public Object localVariableGetCached(RubyBinding binding, RubySymbol symbol,
@Cached("symbol") RubySymbol cachedSymbol,
@Cached("getFrameDescriptor(binding)") FrameDescriptor cachedFrameDescriptor,
@Cached("findFrameSlot(binding, symbol)") FrameSlot cachedFrameSlot,
@Cached("createReadNode(cachedFrameSlot)") ReadAbstractFrameSlotNode readLocalVariableNode) {
@Cached("createReadNode(cachedFrameSlot)") ReadFrameSlotNode readLocalVariableNode) {
if (cachedFrameSlot == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(symbol.toString(), binding, this));
@@ -142,11 +142,11 @@ protected FrameSlot findFrameSlot(RubyBinding binding, RubySymbol symbol) {
return null;
}

protected ReadAbstractFrameSlotNode createReadNode(FrameSlot frameSlot) {
protected ReadFrameSlotNode createReadNode(FrameSlot frameSlot) {
if (frameSlot == null) {
return null;
} else {
return ReadAbstractFrameSlotNodeGen.create(frameSlot);
return ReadFrameSlotNodeGen.create(frameSlot);
}
}

@@ -174,7 +174,7 @@ public LocalVariableSetNode(RubyContext context, SourceSection sourceSection) {
public Object localVariableSetCached(RubyBinding binding, RubySymbol symbol, Object value,
@Cached("symbol") RubySymbol cachedSymbol,
@Cached("getFrameDescriptor(binding)") FrameDescriptor cachedFrameDescriptor,
@Cached("createWriteNode(findFrameSlot(binding, symbol))") WriteAbstractFrameSlotNode writeLocalVariableNode) {
@Cached("createWriteNode(findFrameSlot(binding, symbol))") WriteFrameSlotNode writeLocalVariableNode) {
return writeLocalVariableNode.executeWrite(binding.getFrame(), value);
}

@@ -218,8 +218,8 @@ protected FrameSlot findFrameSlot(RubyBinding binding, RubySymbol symbol) {
return binding.getFrame().getFrameDescriptor().addFrameSlot(symbolString);
}

protected WriteAbstractFrameSlotNode createWriteNode(FrameSlot frameSlot) {
return WriteAbstractFrameSlotNodeGen.create(frameSlot);
protected WriteFrameSlotNode createWriteNode(FrameSlot frameSlot) {
return WriteFrameSlotNodeGen.create(frameSlot);
}

protected boolean isLastLine(RubySymbol symbol) {
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.Node;

public abstract class ReadAbstractFrameSlotNode extends Node {
public abstract class ReadFrameSlotNode extends Node {

protected final FrameSlot frameSlot;

public ReadAbstractFrameSlotNode(FrameSlot slot) {
public ReadFrameSlotNode(FrameSlot slot) {
assert slot != null;
this.frameSlot = slot;
}
@@ -60,26 +60,14 @@ public final FrameSlot getFrameSlot() {
}

@Override
public ReadAbstractFrameSlotNode copy() {
return (ReadAbstractFrameSlotNode) super.copy();
public ReadFrameSlotNode copy() {
return (ReadFrameSlotNode) super.copy();
}

protected final void setBoolean(Frame frame, boolean value) {
frame.setBoolean(frameSlot, value);
}

protected final void setFixnum(Frame frame, int value) {
frame.setInt(frameSlot, value);
}

protected final void setLongFixnum(Frame frame, long value) {
frame.setLong(frameSlot, value);
}

protected final void setFloat(Frame frame, double value) {
frame.setDouble(frameSlot, value);
}

protected final void setObject(Frame frame, Object value) {
frame.setObject(frameSlot, value);
}
@@ -108,41 +96,4 @@ protected final Object getValue(Frame frame) {
return frame.getValue(frameSlot);
}

protected final boolean isBooleanKind(Frame frame) {
return isKind(FrameSlotKind.Boolean);
}

protected final boolean isFixnumKind(Frame frame) {
return isKind(FrameSlotKind.Int);
}

protected final boolean isLongFixnumKind(Frame frame) {
return isKind(FrameSlotKind.Long);
}

protected final boolean isFloatKind(Frame frame) {
return isKind(FrameSlotKind.Double);
}

protected final boolean isObjectKind(Frame frame) {
if (frameSlot.getKind() != FrameSlotKind.Object) {
CompilerDirectives.transferToInterpreter();
frameSlot.setKind(FrameSlotKind.Object);
}
return true;
}

private boolean isKind(FrameSlotKind kind) {
return frameSlot.getKind() == kind || initialSetKind(kind);
}

private boolean initialSetKind(FrameSlotKind kind) {
if (frameSlot.getKind() == FrameSlotKind.Illegal) {
CompilerDirectives.transferToInterpreter();
frameSlot.setKind(kind);
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -23,54 +23,32 @@
import java.util.HashSet;
import java.util.Set;

public abstract class ReadLocalVariableNode extends FrameSlotNode implements ReadNode {
public class ReadLocalVariableNode extends RubyNode implements ReadNode {

public ReadLocalVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot slot) {
super(context, sourceSection, slot);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public boolean doBoolean(VirtualFrame frame) throws FrameSlotTypeException {
return getBoolean(frame);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public int doFixnum(VirtualFrame frame) throws FrameSlotTypeException {
return getFixnum(frame);
}
@Child private ReadFrameSlotNode readFrameSlotNode;

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public long doLongFixnum(VirtualFrame frame) throws FrameSlotTypeException {
return getLongFixnum(frame);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public double doFloat(VirtualFrame frame) throws FrameSlotTypeException {
return getFloat(frame);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public Object doObject(VirtualFrame frame) throws FrameSlotTypeException {
return getObject(frame);
public ReadLocalVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot slot) {
super(context, sourceSection);
readFrameSlotNode = ReadFrameSlotNodeGen.create(slot);
}

@Specialization
public Object doValue(VirtualFrame frame) {
return getValue(frame);
@Override
public Object execute(VirtualFrame frame) {
return readFrameSlotNode.executeRead(frame);
}

@Override
public RubyNode makeWriteNode(RubyNode rhs) {
return WriteLocalVariableNodeGen.create(getContext(), getSourceSection(), frameSlot, rhs);
return new WriteLocalVariableNode(getContext(), getSourceSection(), rhs, readFrameSlotNode.getFrameSlot());
}

public static final Set<String> ALWAYS_DEFINED_GLOBALS = new HashSet<>(Arrays.asList("$~"));

@Override
public Object isDefined(VirtualFrame frame) {
// TODO(CS): copy and paste of ReadLevelVariableNode
if (BodyTranslator.FRAME_LOCAL_GLOBAL_VARIABLES.contains(frameSlot.getIdentifier())) {
if (ALWAYS_DEFINED_GLOBALS.contains(frameSlot.getIdentifier()) || doValue(frame) != nil()) {
if (BodyTranslator.FRAME_LOCAL_GLOBAL_VARIABLES.contains(readFrameSlotNode.getFrameSlot().getIdentifier())) {
if (ALWAYS_DEFINED_GLOBALS.contains(readFrameSlotNode.getFrameSlot().getIdentifier()) || readFrameSlotNode.executeRead(frame) != nil()) {
return getContext().makeString("global-variable");
} else {
return nil();
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.Node;

public abstract class WriteAbstractFrameSlotNode extends Node {
public abstract class WriteFrameSlotNode extends Node {

protected final FrameSlot frameSlot;

public WriteAbstractFrameSlotNode(FrameSlot frameSlot) {
public WriteFrameSlotNode(FrameSlot frameSlot) {
assert frameSlot != null;
this.frameSlot = frameSlot;
}
@@ -79,22 +79,6 @@ protected final void setObject(Frame frame, Object value) {
frame.setObject(frameSlot, value);
}

protected final boolean getBoolean(Frame frame) throws FrameSlotTypeException {
return frame.getBoolean(frameSlot);
}

protected final int getFixnum(Frame frame) throws FrameSlotTypeException {
return frame.getInt(frameSlot);
}

protected final long getLongFixnum(Frame frame) throws FrameSlotTypeException {
return frame.getLong(frameSlot);
}

protected final double getFloat(Frame frame) throws FrameSlotTypeException {
return frame.getDouble(frameSlot);
}

protected final Object getObject(Frame frame) throws FrameSlotTypeException {
return frame.getObject(frameSlot);
}
Original file line number Diff line number Diff line change
@@ -18,46 +18,25 @@
import org.jruby.truffle.translator.WriteNode;
import org.jruby.truffle.runtime.RubyContext;

@NodeChild(value = "rhs", type = RubyNode.class)
public abstract class WriteLocalVariableNode extends FrameSlotNode implements WriteNode {
public class WriteLocalVariableNode extends RubyNode implements WriteNode {

public WriteLocalVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot frameSlot) {
super(context, sourceSection, frameSlot);
}

@Specialization(guards = "isBooleanKind(frame)")
public boolean doFixnum(VirtualFrame frame, boolean value) {
setBoolean(frame, value);
return value;
}

@Specialization(guards = "isFixnumKind(frame)")
public int doFixnum(VirtualFrame frame, int value) {
setFixnum(frame, value);
return value;
}

@Specialization(guards = "isLongFixnumKind(frame)")
public long doLongFixnum(VirtualFrame frame, long value) {
setLongFixnum(frame, value);
return value;
}
@Child private RubyNode valueNode;
@Child private WriteFrameSlotNode writeFrameSlotNode;

@Specialization(guards = "isFloatKind(frame)")
public double doFloat(VirtualFrame frame, double value) {
setFloat(frame, value);
return value;
public WriteLocalVariableNode(RubyContext context, SourceSection sourceSection, RubyNode valueNode, FrameSlot frameSlot) {
super(context, sourceSection);
this.valueNode = valueNode;
writeFrameSlotNode = WriteFrameSlotNodeGen.create(frameSlot);
}

@Specialization(guards = "isObjectKind(frame)")
public Object doObject(VirtualFrame frame, Object value) {
setObject(frame, value);
return value;
@Override
public Object execute(VirtualFrame frame) {
return writeFrameSlotNode.executeWrite(frame, valueNode.execute(frame));
}

@Override
public RubyNode makeReadNode() {
return ReadLocalVariableNodeGen.create(getContext(), getSourceSection(), frameSlot);
return new ReadLocalVariableNode(getContext(), getSourceSection(), writeFrameSlotNode.getFrameSlot());
}

@Override
Original file line number Diff line number Diff line change
@@ -240,7 +240,7 @@ public RubyNode visitAttrAssignNodeExtraArgument(org.jruby.ast.AttrAssignNode no
argChildNodes.remove(argChildNodes.size() - 1);

// Evaluate the value and store it in a local variable
writeValue = WriteLocalVariableNodeGen.create(context, sourceSection, frameSlot, valueNode.accept(this));
writeValue = new WriteLocalVariableNode(context, sourceSection, valueNode.accept(this), frameSlot);

// Recreate the arguments array, reading that local instead of including the RHS for the last argument
argChildNodes.add(new ReadLocalDummyNode(node.getPosition(), sourceSection, frameSlot));
@@ -253,7 +253,7 @@ public RubyNode visitAttrAssignNodeExtraArgument(org.jruby.ast.AttrAssignNode no
final RubyNode valueNode = extraArgument;

// Evaluate the value and store it in a local variable
writeValue = WriteLocalVariableNodeGen.create(context, sourceSection, frameSlot, valueNode);
writeValue = new WriteLocalVariableNode(context, sourceSection, valueNode, frameSlot);

// Recreate the arguments array, reading that local instead of including the RHS for the last argument
final List<org.jruby.ast.Node> argChildNodes = new ArrayList<>();
@@ -305,7 +305,7 @@ public RubyNode visitAttrAssignNodeExtraArgument(org.jruby.ast.AttrAssignNode no
return SequenceNode.sequence(context, sourceSection,
writeValue,
actualCall,
ReadLocalVariableNodeGen.create(context, sourceSection, frameSlot));
new ReadLocalVariableNode(context, sourceSection, frameSlot));
}

@Override
@@ -2886,7 +2886,7 @@ protected String getIdentifier() {
public RubyNode visitOther(Node node) {
if (node instanceof ReadLocalDummyNode) {
final ReadLocalDummyNode readLocal = (ReadLocalDummyNode) node;
return ReadLocalVariableNodeGen.create(context, readLocal.getSourceSection(), readLocal.getFrameSlot());
return new ReadLocalVariableNode(context, readLocal.getSourceSection(), readLocal.getFrameSlot());
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@
import org.jruby.truffle.nodes.core.array.ArrayLiteralNode;
import org.jruby.truffle.nodes.arguments.*;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNodeGen;
import org.jruby.truffle.nodes.locals.WriteLocalVariableNodeGen;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNode;
import org.jruby.truffle.nodes.locals.WriteLocalVariableNode;
import org.jruby.truffle.runtime.RubyContext;

import java.util.*;
@@ -160,7 +160,7 @@ public RubyNode visitKeywordRestArgNode(org.jruby.ast.KeywordRestArgNode node) {
final RubyNode readNode = new ReadKeywordRestArgumentNode(context, sourceSection, required, excludedKeywords.toArray(new String[excludedKeywords.size()]), -countKwArgs - 1);
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(node.getName());

return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

@Override
@@ -215,7 +215,7 @@ public RubyNode visitKeywordArgNode(org.jruby.ast.KeywordArgNode node) {
final RubyNode readNode = new ReadKeywordArgumentNode(context, sourceSection, required, name, defaultValue, kwIndex - countKwArgs);
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(name);

return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

@Override
@@ -224,7 +224,7 @@ public RubyNode visitArgumentNode(org.jruby.ast.ArgumentNode node) {

final RubyNode readNode = readArgument(sourceSection);
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

private RubyNode readArgument(SourceSection sourceSection) {
@@ -260,7 +260,7 @@ public RubyNode visitRestArgNode(org.jruby.ast.RestArgNode node) {
}

final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

@Override
@@ -269,7 +269,7 @@ public RubyNode visitBlockArgNode(org.jruby.ast.BlockArgNode node) {

final RubyNode readNode = new ReadBlockNode(context, sourceSection, context.getCoreLibrary().getNilObject());
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

@Override
@@ -323,7 +323,7 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
}

final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(name);
return WriteLocalVariableNodeGen.create(context, sourceSection, slot, readNode);
return new WriteLocalVariableNode(context, sourceSection, readNode, slot);
}

@Override
@@ -430,11 +430,11 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnNode node) {
final RubyNode nil = SequenceNode.sequence(context, sourceSection, nilSequence);

return SequenceNode.sequence(context, sourceSection,
WriteLocalVariableNodeGen.create(context, sourceSection, arraySlot,
new WriteLocalVariableNode(context, sourceSection,
ArrayCastNodeGen.create(context, sourceSection,
readArgument(sourceSection))),
readArgument(sourceSection)), arraySlot),
new IfNode(context, sourceSection,
new IsNilNode(context, sourceSection, ReadLocalVariableNodeGen.create(context, sourceSection, arraySlot)),
new IsNilNode(context, sourceSection, new ReadLocalVariableNode(context, sourceSection, arraySlot)),
nil,
notNil == null ? new DefinedWrapperNode(context, sourceSection,
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
@@ -460,7 +460,7 @@ protected boolean useArray() {
}

protected RubyNode loadArray(SourceSection sourceSection) {
return ReadLocalVariableNodeGen.create(context, sourceSection, arraySlotStack.peek().getArraySlot());
return new ReadLocalVariableNode(context, sourceSection, arraySlotStack.peek().getArraySlot());
}

@Override
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@
import org.jruby.truffle.nodes.control.IfNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.locals.WriteLocalVariableNode;
import org.jruby.truffle.nodes.methods.*;
import org.jruby.truffle.nodes.arguments.CheckArityNode;
import org.jruby.truffle.nodes.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.arguments.ShouldDestructureNode;
import org.jruby.truffle.nodes.locals.FlipFlopStateNode;
import org.jruby.truffle.nodes.locals.WriteLocalVariableNodeGen;
import org.jruby.truffle.nodes.respondto.RespondToNode;
import org.jruby.truffle.nodes.supercall.GeneralSuperCallNode;
import org.jruby.truffle.nodes.supercall.GeneralSuperReCallNode;
@@ -119,7 +119,7 @@ public RubyNode compileFunctionNode(SourceSection sourceSection, String methodNa
final RubyNode readArrayNode = new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR);
final RubyNode castArrayNode = ArrayCastNodeGen.create(context, sourceSection, readArrayNode);
final FrameSlot arraySlot = environment.declareVar(environment.allocateLocalTemp("destructure"));
final RubyNode writeArrayNode = WriteLocalVariableNodeGen.create(context, sourceSection, arraySlot, castArrayNode);
final RubyNode writeArrayNode = new WriteLocalVariableNode(context, sourceSection, castArrayNode, arraySlot);

final LoadArgumentsTranslator destructureArgumentsTranslator = new LoadArgumentsTranslator(currentNode, context, source, isBlock, this);
destructureArgumentsTranslator.pushArraySlot(arraySlot);
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.locals.ReadLevelVariableNodeGen;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNodeGen;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
@@ -150,7 +150,7 @@ public RubyNode findLocalVarNode(String name, SourceSection sourceSection) {
FrameSlot slot = current.getFrameDescriptor().findFrameSlot(name);
if (slot != null) {
if (level == 0) {
return ReadLocalVariableNodeGen.create(context, sourceSection, slot);
return new ReadLocalVariableNode(context, sourceSection, slot);
} else {
return ReadLevelVariableNodeGen.create(context, sourceSection, slot, level);
}

0 comments on commit 999f19e

Please sign in to comment.