Skip to content

Commit

Permalink
Showing 15 changed files with 185 additions and 409 deletions.
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.locals.ReadLevelVariableNodeGen;
import org.jruby.truffle.nodes.locals.ReadDeclarationVariableNode;
import org.jruby.truffle.nodes.objects.IsFrozenNode;
import org.jruby.truffle.nodes.objects.IsFrozenNodeGen;
import org.jruby.truffle.nodes.objects.TaintNode;
@@ -2496,7 +2496,7 @@ public MaxBlock(RubyContext context) {
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
ReadLevelVariableNodeGen.create(context, sourceSection, frameSlot, 1),
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
}
@@ -2598,7 +2598,7 @@ public MinBlock(RubyContext context) {
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
ReadLevelVariableNodeGen.create(context, sourceSection, frameSlot, 1),
new ReadDeclarationVariableNode(context, sourceSection, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
})));
}
Original file line number Diff line number Diff line change
@@ -16,12 +16,13 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyArguments;

public class LevelFlipFlopStateNode extends FlipFlopStateNode {
public class DeclarationFlipFlopStateNode extends FlipFlopStateNode {

private final int level;
private final FrameSlot frameSlot;

public LevelFlipFlopStateNode(SourceSection sourceSection, int level, FrameSlot frameSlot) {
public DeclarationFlipFlopStateNode(SourceSection sourceSection, int level,
FrameSlot frameSlot) {
super(sourceSection);
this.level = level;
this.frameSlot = frameSlot;
Original file line number Diff line number Diff line change
@@ -24,7 +24,9 @@ public class FlipFlopNode extends RubyNode {

private final boolean exclusive;

public FlipFlopNode(RubyContext context, SourceSection sourceSection, RubyNode begin, RubyNode end, FlipFlopStateNode stateNode, boolean exclusive) {
public FlipFlopNode(RubyContext context, SourceSection sourceSection,
RubyNode begin, RubyNode end, FlipFlopStateNode stateNode,
boolean exclusive) {
super(context, sourceSection);
this.begin = BooleanCastNodeGen.create(context, sourceSection, begin);
this.end = BooleanCastNodeGen.create(context, sourceSection, end);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ public class InitFlipFlopSlotNode extends RubyNode {

private final FrameSlot frameSlot;

public InitFlipFlopSlotNode(RubyContext context, SourceSection sourceSection, FrameSlot frameSlot) {
public InitFlipFlopSlotNode(RubyContext context, SourceSection sourceSection,
FrameSlot frameSlot) {
super(context, sourceSection);
this.frameSlot = frameSlot;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.locals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.translator.ReadNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.translator.Translator;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ReadDeclarationVariableNode extends RubyNode implements ReadNode {

private final int frameDepth;

@Child private ReadFrameSlotNode readFrameSlotNode;

public ReadDeclarationVariableNode(RubyContext context, SourceSection sourceSection,
int frameDepth, FrameSlot slot) {
super(context, sourceSection);
readFrameSlotNode = ReadFrameSlotNodeGen.create(slot);
this.frameDepth = frameDepth;
}

@Override
public Object execute(VirtualFrame frame) {
return readFrameSlotNode.executeRead(RubyArguments.getDeclarationFrame(frame, frameDepth));
}

@Override
public RubyNode makeWriteNode(RubyNode rhs) {
return new WriteDeclarationVariableNode(getContext(), getSourceSection(),
rhs, frameDepth, readFrameSlotNode.getFrameSlot());
}

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

@Override
public Object isDefined(VirtualFrame frame) {
CompilerDirectives.transferToInterpreter();

if (Translator.FRAME_LOCAL_GLOBAL_VARIABLES.contains(readFrameSlotNode.getFrameSlot().getIdentifier())) {
if (ALWAYS_DEFINED_GLOBALS.contains(readFrameSlotNode.getFrameSlot().getIdentifier())
|| readFrameSlotNode.executeRead(RubyArguments.getDeclarationFrame(frame, frameDepth)) != nil()) {
return getContext().makeString("global-variable");
} else {
return nil();
}
} else {
return getContext().makeString("local-variable");
}
}

}
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.nodes.locals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.Node;
@@ -26,74 +25,37 @@ public ReadFrameSlotNode(FrameSlot slot) {
public abstract Object executeRead(Frame frame);

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

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public int doFixnum(Frame frame) throws FrameSlotTypeException {
return getFixnum(frame);
public int readInteger(Frame frame) throws FrameSlotTypeException {
return frame.getInt(frameSlot);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public long doLongFixnum(Frame frame) throws FrameSlotTypeException {
return getLongFixnum(frame);
public long readLong(Frame frame) throws FrameSlotTypeException {
return frame.getLong(frameSlot);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public double doFloat(Frame frame) throws FrameSlotTypeException {
return getFloat(frame);
public double readDouble(Frame frame) throws FrameSlotTypeException {
return frame.getDouble(frameSlot);
}

@Specialization(rewriteOn = {FrameSlotTypeException.class})
public Object doObject(Frame frame) throws FrameSlotTypeException {
return getObject(frame);
public Object readObject(Frame frame) throws FrameSlotTypeException {
return frame.getObject(frameSlot);
}

@Specialization
public Object doValue(Frame frame) {
return getValue(frame);
return frame.getValue(frameSlot);
}

public final FrameSlot getFrameSlot() {
return frameSlot;
}

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

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

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);
}

protected final Object getValue(Frame frame) {
return frame.getValue(frameSlot);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -9,25 +9,21 @@
*/
package org.jruby.truffle.nodes.locals;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.FrameSlotTypeException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.translator.ReadNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.translator.BodyTranslator;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.jruby.truffle.translator.Translator;

public class ReadLocalVariableNode extends RubyNode implements ReadNode {

@Child private ReadFrameSlotNode readFrameSlotNode;

public ReadLocalVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot slot) {
public ReadLocalVariableNode(RubyContext context, SourceSection sourceSection,
FrameSlot slot) {
super(context, sourceSection);
readFrameSlotNode = ReadFrameSlotNodeGen.create(slot);
}
@@ -39,16 +35,17 @@ public Object execute(VirtualFrame frame) {

@Override
public RubyNode makeWriteNode(RubyNode rhs) {
return new WriteLocalVariableNode(getContext(), getSourceSection(), rhs, readFrameSlotNode.getFrameSlot());
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(readFrameSlotNode.getFrameSlot().getIdentifier())) {
if (ALWAYS_DEFINED_GLOBALS.contains(readFrameSlotNode.getFrameSlot().getIdentifier()) || readFrameSlotNode.executeRead(frame) != nil()) {
CompilerDirectives.transferToInterpreter();

if (Translator.FRAME_LOCAL_GLOBAL_VARIABLES.contains(readFrameSlotNode.getFrameSlot().getIdentifier())) {
if (Translator.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
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.locals;

import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.translator.WriteNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;

public class WriteDeclarationVariableNode extends RubyNode implements WriteNode {

@Child private RubyNode valueNode;
@Child private WriteFrameSlotNode writeFrameSlotNode;

private final int frameDepth;

public WriteDeclarationVariableNode(RubyContext context, SourceSection sourceSection,
RubyNode valueNode, int frameDepth, FrameSlot frameSlot) {
super(context, sourceSection);
this.valueNode = valueNode;
writeFrameSlotNode = WriteFrameSlotNodeGen.create(frameSlot);
this.frameDepth = frameDepth;
}

@Override
public Object execute(VirtualFrame frame) {
final MaterializedFrame declarationFrame = RubyArguments.getDeclarationFrame(frame, frameDepth);
return writeFrameSlotNode.executeWrite(declarationFrame, valueNode.execute(frame));
}

@Override
public RubyNode makeReadNode() {
return new ReadDeclarationVariableNode(getContext(), getSourceSection(), frameDepth, writeFrameSlotNode.getFrameSlot());
}

@Override
public Object isDefined(VirtualFrame frame) {
return getContext().makeString("assignment");
}

}
Original file line number Diff line number Diff line change
@@ -26,80 +26,48 @@ public WriteFrameSlotNode(FrameSlot frameSlot) {
public abstract Object executeWrite(Frame frame, Object value);

@Specialization(guards = "isBooleanKind(frame)")
public boolean doFixnum(Frame frame, boolean value) {
setBoolean(frame, value);
public boolean writeBoolean(Frame frame, boolean value) {
frame.setBoolean(frameSlot, value);
return value;
}

@Specialization(guards = "isFixnumKind(frame)")
public int doFixnum(Frame frame, int value) {
setFixnum(frame, value);
@Specialization(guards = "isIntegerKind(frame)")
public int writeInteger(Frame frame, int value) {
frame.setInt(frameSlot, value);
return value;
}

@Specialization(guards = "isLongFixnumKind(frame)")
public long doLongFixnum(Frame frame, long value) {
setLongFixnum(frame, value);
@Specialization(guards = "isLongKind(frame)")
public long writeLong(Frame frame, long value) {
frame.setLong(frameSlot, value);
return value;
}

@Specialization(guards = "isFloatKind(frame)")
public double doFloat(Frame frame, double value) {
setFloat(frame, value);
@Specialization(guards = "isDoubleKind(frame)")
public double writeDouble(Frame frame, double value) {
frame.setDouble(frameSlot, value);
return value;
}

@Specialization(guards = "isObjectKind(frame)")
public Object doObject(Frame frame, Object value) {
setObject(frame, value);
return value;
}

public final FrameSlot getFrameSlot() {
return frameSlot;
}

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) {
public Object writeObject(Frame frame, Object value) {
frame.setObject(frameSlot, value);
}

protected final Object getObject(Frame frame) throws FrameSlotTypeException {
return frame.getObject(frameSlot);
}

protected final Object getValue(Frame frame) {
return frame.getValue(frameSlot);
return value;
}

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

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

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

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

@@ -112,7 +80,11 @@ protected final boolean isObjectKind(Frame frame) {
}

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

private boolean initialSetKind(FrameSlotKind kind) {
@@ -124,4 +96,8 @@ private boolean initialSetKind(FrameSlotKind kind) {
return false;
}

public final FrameSlot getFrameSlot() {
return frameSlot;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -111,7 +111,6 @@ public class BodyTranslator extends Translator {
debugIgnoredCalls.add("upto");
}

public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$+", "$&", "$`", "$'"));
public static final Set<String> THREAD_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$~", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$!")); // "$_"

public BodyTranslator(com.oracle.truffle.api.nodes.Node currentNode, RubyContext context, BodyTranslator parent, TranslatorEnvironment environment, Source source, boolean topLevel) {
@@ -1208,7 +1207,7 @@ protected FlipFlopStateNode createFlipFlopState(SourceSection sourceSection, int
if (depth == 0) {
return new LocalFlipFlopStateNode(sourceSection, frameSlot);
} else {
return new LevelFlipFlopStateNode(sourceSection, depth, frameSlot);
return new DeclarationFlipFlopStateNode(sourceSection, depth, frameSlot);
}
}

@@ -2156,8 +2155,8 @@ private RubyNode translateDummyAssignment(org.jruby.ast.Node dummyAssignment, Ru
} else if (dummyAssignment instanceof org.jruby.ast.DAsgnNode) {
final RubyNode dummyTranslated = dummyAssignment.accept(this);

if (dummyTranslated.getNonProxyNode() instanceof WriteLevelVariableNode) {
translated = ((ReadNode) ((WriteLevelVariableNode) dummyTranslated.getNonProxyNode()).makeReadNode()).makeWriteNode(rhs);
if (dummyTranslated.getNonProxyNode() instanceof WriteDeclarationVariableNode) {
translated = ((ReadNode) ((WriteDeclarationVariableNode) dummyTranslated.getNonProxyNode()).makeReadNode()).makeWriteNode(rhs);
} else {
translated = ((ReadNode) ((WriteLocalVariableNode) dummyTranslated.getNonProxyNode()).makeReadNode()).makeWriteNode(rhs);
}
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ public abstract class Translator extends org.jruby.ast.visitor.AbstractNodeVisit
public static final Set<String> PRINT_AST_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_AST.load().split(",")));
public static final Set<String> PRINT_FULL_AST_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_FULL_AST.load().split(",")));
public static final Set<String> PRINT_PARSE_TREE_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_PARSE_TREE.load().split(",")));
public static final Set<String> ALWAYS_DEFINED_GLOBALS = new HashSet<>(Arrays.asList("$~"));
public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$+", "$&", "$`", "$'"));

protected final Node currentNode;
protected final RubyContext context;
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
import com.oracle.truffle.api.frame.FrameSlot;
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.ReadDeclarationVariableNode;
import org.jruby.truffle.nodes.locals.ReadLocalVariableNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
@@ -152,7 +152,7 @@ public RubyNode findLocalVarNode(String name, SourceSection sourceSection) {
if (level == 0) {
return new ReadLocalVariableNode(context, sourceSection, slot);
} else {
return ReadLevelVariableNodeGen.create(context, sourceSection, slot, level);
return new ReadDeclarationVariableNode(context, sourceSection, level, slot);
}
}

0 comments on commit 28a9776

Please sign in to comment.