Skip to content

Commit

Permalink
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.jruby.truffle.nodes.methods.locals.WriteAbstractFrameSlotNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBinding;
import org.jruby.truffle.runtime.core.RubyProc;
@@ -71,23 +72,34 @@ public LocalVariableGetNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization(guards = {
"!isLastLine(symbol)",
"getFrameDescriptor(binding) == cachedFrameDescriptor",
"symbol == cachedSymbol"
"symbol == cachedSymbol",
"!isLastLine(cachedSymbol)",
"getFrameDescriptor(binding) == cachedFrameDescriptor"

})
public Object localVariableGetCached(RubyBinding binding, RubySymbol symbol,
@Cached("symbol") RubySymbol cachedSymbol,
@Cached("getFrameDescriptor(binding)") FrameDescriptor cachedFrameDescriptor,
@Cached("createReadNode(findFrameSlot(cachedFrameDescriptor, symbol))") ReadAbstractFrameSlotNode readLocalVariableNode) {
return readLocalVariableNode.executeRead(binding.getFrame());
@Cached("findFrameSlot(cachedFrameDescriptor, symbol)") FrameSlot cachedFrameSlot,
@Cached("createReadNode(cachedFrameSlot)") ReadAbstractFrameSlotNode readLocalVariableNode) {
if (cachedFrameSlot == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(symbol.toString(), binding, this));
} else {
return readLocalVariableNode.executeRead(binding.getFrame());
}
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "!isLastLine(symbol)")
public Object localVariableGetUncached(RubyBinding binding, RubySymbol symbol) {
final MaterializedFrame frame = binding.getFrame();
final FrameSlot frameSlot = frame.getFrameDescriptor().findFrameSlot(symbol.toString());

if (frameSlot == null) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(symbol.toString(), binding, this));
}

return frame.getValue(frameSlot);
}

@@ -96,6 +108,11 @@ public Object localVariableGetUncached(RubyBinding binding, RubySymbol symbol) {
public Object localVariableGetLastLine(RubyBinding binding, RubySymbol symbol) {
final MaterializedFrame frame = binding.getFrame();
final FrameSlot frameSlot = frame.getFrameDescriptor().findFrameSlot(symbol.toString());

if (frameSlot == null) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(symbol.toString(), binding, this));
}

final Object value = frame.getValue(frameSlot);
return GetFromThreadLocalNode.get(getContext(), value);
}
Original file line number Diff line number Diff line change
@@ -854,6 +854,11 @@ public RubyException nameErrorPrivateMethod(String name, RubyModule module, Node
return nameError(String.format("method `%s' for %s is private", name, module.getName()), name, currentNode);
}

public RubyException nameErrorLocalVariableNotDefined(String name, RubyBinding binding, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return nameError(String.format("local variable `%s' not defined for %s", name, binding.toString()), name, currentNode);
}

public RubyException noMethodError(String message, String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
RubyException noMethodError = new RubyException(context.getCoreLibrary().getNoMethodErrorClass(), context.makeString(message), RubyCallStack.getBacktrace(currentNode));

0 comments on commit c957028

Please sign in to comment.