Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cfda684f1aa7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6bfb18af3bf9
Choose a head ref
  • 8 commits
  • 9 files changed
  • 1 contributor

Commits on May 27, 2015

  1. Copy the full SHA
    b0bf634 View commit details
  2. Copy the full SHA
    6c0ed3a View commit details
  3. Copy the full SHA
    b797e13 View commit details
  4. Copy the full SHA
    c8ef428 View commit details
  5. Copy the full SHA
    7ab8afd View commit details
  6. Copy the full SHA
    831d490 View commit details
  7. 4
    Copy the full SHA
    b4670bb View commit details
  8. Copy the full SHA
    6bfb18a View commit details
Original file line number Diff line number Diff line change
@@ -23,12 +23,16 @@
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;

/**
* Take a Symbol or some object accepting #to_str
* and convert it to a Java String.
*/
@NodeChild(value = "child", type = RubyNode.class)
public abstract class SymbolOrToStrNode extends RubyNode {
public abstract class NameToJavaStringNode extends RubyNode {

@Child private CallDispatchHeadNode toStr;

public SymbolOrToStrNode(RubyContext context, SourceSection sourceSection) {
public NameToJavaStringNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStr = DispatchHeadNodeFactory.createMethodCall(context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 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.coerce;

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.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;

/**
* Take a Symbol or some object accepting #to_str
* and convert it to a RubySymbol or a RubyString.
*/
@NodeChild(value = "child", type = RubyNode.class)
public abstract class NameToSymbolOrStringNode extends RubyNode {

@Child private CallDispatchHeadNode toStr;

public NameToSymbolOrStringNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStr = DispatchHeadNodeFactory.createMethodCall(context);
}

public abstract RubyBasicObject executeToSymbolOrString(VirtualFrame frame, Object name);

@Specialization
public RubySymbol coerceRubySymbol(RubySymbol symbol) {
return symbol;
}

@Specialization
public RubyString coerceRubyString(RubyString string) {
return string;
}

@Specialization(guards = { "!isRubySymbol(object)", "!isRubyString(object)" })
public RubyString coerceObject(VirtualFrame frame, Object object) {
final Object coerced;

try {
coerced = toStr.call(frame, object, "to_str", null);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this));
} else {
throw e;
}
}

if (coerced instanceof RubyString) {
return (RubyString) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
}
}
}
Original file line number Diff line number Diff line change
@@ -16,10 +16,13 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyConstant;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.util.IdUtil;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
@@ -59,15 +62,24 @@ protected Object autoloadConstant(VirtualFrame frame, RubyModule module, String

@Specialization(guards = "constant == null")
protected Object missingConstant(VirtualFrame frame, RubyModule module, String name, Object constant,
@Cached("isValidConstantName(name)") boolean isValidConstantName,
@Cached("createConstMissingNode()") CallDispatchHeadNode constMissingNode,
@Cached("getContext().getSymbol(name)") RubySymbol symbolName) {
if (!isValidConstantName) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("wrong constant name %s", name), name, this));
}
return constMissingNode.call(frame, module, "const_missing", null, symbolName);
}

protected RequireNode createRequireNode() {
return KernelNodesFactory.RequireNodeFactory.create(getContext(), getSourceSection(), new RubyNode[] {});
}

protected boolean isValidConstantName(String name) {
return IdUtil.isValidConstantName19(name);
}

protected CallDispatchHeadNode createConstMissingNode() {
return DispatchHeadNodeFactory.createMethodCall(getContext());
}
Original file line number Diff line number Diff line change
@@ -27,22 +27,24 @@

/**
* Defines the method on the singleton class.
* needsSelf is always false.
* {@link needsSelf} is always false.
* */
boolean onSingleton() default false;

/**
* Like {@link #onSingleton()} but with {@link #needsSelf()} always true.
*/
boolean constructor() default false;

/**
* Defines the method as public on the singleton class
* and as a private instance method.
* needsSelf is always false.
* {@link needsSelf} is always false.
*/
boolean isModuleFunction() default false;

boolean needsSelf() default true;

// TODO CS 3-Mar-15 needsSelf() gets ignored in some cases - see CoreMethodNodeManager#addMethod
boolean reallyDoesNeedSelf() default false;

int required() default 0;

int optional() default 0;
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.nodes.objects.SelfNode;
import org.jruby.truffle.nodes.objects.SingletonClassNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.TruffleFatalException;
import org.jruby.truffle.runtime.core.CoreSourceSection;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyModule;
@@ -89,35 +88,31 @@ private void addCoreMethod(MethodDetails methodDetails) {

assert module != null : fullName;

final CoreMethod anno = methodDetails.getMethodAnnotation();
final CoreMethod method = methodDetails.getMethodAnnotation();

final List<String> names = Arrays.asList(anno.names());
final List<String> names = Arrays.asList(method.names());
assert names.size() >= 1;

final Visibility visibility = anno.visibility();
final Visibility visibility = method.visibility();

if (anno.isModuleFunction()) {
if (method.isModuleFunction()) {
if (visibility != Visibility.PUBLIC) {
System.err.println("WARNING: visibility ignored when isModuleFunction in " + methodDetails.getIndicativeName());
}
if (anno.onSingleton()) {
if (method.onSingleton()) {
System.err.println("WARNING: Either onSingleton or isModuleFunction for " + methodDetails.getIndicativeName());
}
if (!module.isOnlyAModule()) {
System.err.println("WARNING: Using isModuleFunction on a Class for " + methodDetails.getIndicativeName());
}
}

// Do not use needsSelf=true in module functions, it is either the module/class or the instance.
// Usage of needsSelf is quite rare for singleton methods (except constructors).
final boolean needsSelf = !anno.isModuleFunction() && !anno.onSingleton() && anno.needsSelf() || anno.reallyDoesNeedSelf();

final RubyRootNode rootNode = makeGenericMethod(context, methodDetails, needsSelf);
final RubyRootNode rootNode = makeGenericMethod(context, methodDetails);

if (anno.isModuleFunction()) {
if (method.isModuleFunction()) {
addMethod(module, rootNode, names, Visibility.PRIVATE);
addMethod(getSingletonClass(module), rootNode, names, Visibility.PUBLIC);
} else if (anno.onSingleton()) {
} else if (method.onSingleton()) {
addMethod(getSingletonClass(module), rootNode, names, visibility);
} else {
addMethod(module, rootNode, names, visibility);
@@ -140,94 +135,99 @@ private static void addMethod(RubyModule module, RubyRootNode rootNode, List<Str
}
}

private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails, boolean needsSelf) {
final CoreSourceSection sourceSection = new CoreSourceSection(methodDetails.getClassAnnotation().name(), methodDetails.getMethodAnnotation().names()[0]);
private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails) {
final CoreMethod method = methodDetails.getMethodAnnotation();

final int required = methodDetails.getMethodAnnotation().required();
final CoreSourceSection sourceSection = new CoreSourceSection(methodDetails.getClassAnnotation().name(), method.names()[0]);

final int required = method.required();
final int optional;

if (methodDetails.getMethodAnnotation().argumentsAsArray()) {
if (method.argumentsAsArray()) {
optional = 0;
} else {
optional = methodDetails.getMethodAnnotation().optional();
optional = method.optional();
}

final Arity arity = new Arity(required, optional, methodDetails.getMethodAnnotation().argumentsAsArray(), false, false, 0);
final Arity arity = new Arity(required, optional, method.argumentsAsArray(), false, false, 0);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, arity, methodDetails.getIndicativeName(), false, null, true);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, LexicalScope.NONE, arity, methodDetails.getIndicativeName(), false, null, true);

final List<RubyNode> argumentsNodes = new ArrayList<>();

// Do not use needsSelf=true in module functions, it is either the module/class or the instance.
// Usage of needsSelf is quite rare for singleton methods (except constructors).
final boolean needsSelf = method.constructor() || (!method.isModuleFunction() && !method.onSingleton() && method.needsSelf());

if (needsSelf) {
RubyNode readSelfNode = new SelfNode(context, sourceSection);

if (methodDetails.getMethodAnnotation().lowerFixnumSelf()) {
if (method.lowerFixnumSelf()) {
readSelfNode = new FixnumLowerNode(readSelfNode);
}

if (methodDetails.getMethodAnnotation().raiseIfFrozenSelf()) {
if (method.raiseIfFrozenSelf()) {
readSelfNode = new RaiseIfFrozenNode(readSelfNode);
}

argumentsNodes.add(readSelfNode);
}

if (methodDetails.getMethodAnnotation().argumentsAsArray()) {
if (method.argumentsAsArray()) {
argumentsNodes.add(new ReadAllArgumentsNode(context, sourceSection));
} else {
for (int n = 0; n < arity.getRequired() + arity.getOptional(); n++) {
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehaviour.UNDEFINED);

if (ArrayUtils.contains(methodDetails.getMethodAnnotation().lowerFixnumParameters(), n)) {
if (ArrayUtils.contains(method.lowerFixnumParameters(), n)) {
readArgumentNode = new FixnumLowerNode(readArgumentNode);
}

if (ArrayUtils.contains(methodDetails.getMethodAnnotation().raiseIfFrozenParameters(), n)) {
if (ArrayUtils.contains(method.raiseIfFrozenParameters(), n)) {
readArgumentNode = new RaiseIfFrozenNode(readArgumentNode);
}

argumentsNodes.add(readArgumentNode);
}
}

if (methodDetails.getMethodAnnotation().needsBlock()) {
if (method.needsBlock()) {
argumentsNodes.add(new ReadBlockNode(context, sourceSection, UndefinedPlaceholder.INSTANCE));
}

RubyNode methodNode = null;
final NodeFactory<?> nodeFactory = methodDetails.getNodeFactory();
final RubyNode methodNode;
final NodeFactory<? extends RubyNode> nodeFactory = methodDetails.getNodeFactory();
List<List<Class<?>>> signatures = nodeFactory.getNodeSignatures();
assert !signatures.isEmpty();

for (List<Class<?>> signature : signatures) {
if (signature.size() >= 1 && signature.get(0) != RubyContext.class && signature.get(0) != nodeFactory.getNodeClass()) {
throw new TruffleFatalException("Copy constructor with wrong type for previous in "+nodeFactory.getNodeClass()+" : "+signature.get(0), null);
} else if (signature.size() >= 3 && signature.get(2) == RubyNode[].class) {
methodNode = methodDetails.getNodeFactory().createNode(context, sourceSection, argumentsNodes.toArray(new RubyNode[argumentsNodes.size()]));
} else {
Object[] args = new Object[2 + argumentsNodes.size()];
args[0] = context;
args[1] = sourceSection;
System.arraycopy(argumentsNodes.toArray(new RubyNode[argumentsNodes.size()]), 0, args, 2, argumentsNodes.size());
methodNode = methodDetails.getNodeFactory().createNode(args);
}

assert signatures.size() == 1;
List<Class<?>> signature = signatures.get(0);

if (signature.size() >= 3 && signature.get(2) == RubyNode[].class) {
Object[] args = argumentsNodes.toArray(new RubyNode[argumentsNodes.size()]);
methodNode = nodeFactory.createNode(context, sourceSection, args);
} else {
Object[] args = new Object[2 + argumentsNodes.size()];
args[0] = context;
args[1] = sourceSection;
System.arraycopy(argumentsNodes.toArray(new RubyNode[argumentsNodes.size()]), 0, args, 2, argumentsNodes.size());
methodNode = nodeFactory.createNode(args);
}

final CheckArityNode checkArity = new CheckArityNode(context, sourceSection, arity);
RubyNode sequence = SequenceNode.sequence(context, sourceSection, checkArity, methodNode);

if (methodDetails.getMethodAnnotation().returnsEnumeratorIfNoBlock()) {
if (method.returnsEnumeratorIfNoBlock()) {
// TODO BF 3-18-2015 Handle multiple method names correctly
sequence = new ReturnEnumeratorIfNoBlockNode(methodDetails.getMethodAnnotation().names()[0], sequence);
sequence = new ReturnEnumeratorIfNoBlockNode(method.names()[0], sequence);
}

if (methodDetails.getMethodAnnotation().taintFromSelf() || methodDetails.getMethodAnnotation().taintFromParameter() != -1) {
sequence = new TaintResultNode(methodDetails.getMethodAnnotation().taintFromSelf(),
methodDetails.getMethodAnnotation().taintFromParameter(),
if (method.taintFromSelf() || method.taintFromParameter() != -1) {
sequence = new TaintResultNode(method.taintFromSelf(),
method.taintFromParameter(),
sequence);
}

final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, sequence, methodDetails.getMethodAnnotation().unsupportedOperationBehavior());
final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, sequence, method.unsupportedOperationBehavior());

return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
}
119 changes: 68 additions & 51 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -11,15 +11,14 @@

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.Node.Child;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
@@ -35,21 +34,18 @@
import org.jruby.truffle.nodes.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
import org.jruby.truffle.nodes.coerce.SymbolOrToStrNode;
import org.jruby.truffle.nodes.coerce.SymbolOrToStrNodeGen;
import org.jruby.truffle.nodes.coerce.NameToJavaStringNode;
import org.jruby.truffle.nodes.coerce.NameToSymbolOrStringNodeGen;
import org.jruby.truffle.nodes.coerce.ToStrNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeGen;
import org.jruby.truffle.nodes.coerce.NameToJavaStringNodeGen;
import org.jruby.truffle.nodes.constants.GetConstantNode;
import org.jruby.truffle.nodes.constants.GetConstantNodeGen;
import org.jruby.truffle.nodes.constants.LookupConstantNodeGen;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.KernelNodes.BindingNode;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetMethodVisibilityNodeGen;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetVisibilityNodeGen;
import org.jruby.truffle.nodes.dispatch.DispatchAction;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.literal.LiteralNode;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -305,12 +301,12 @@ public AliasMethodNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("newName")
public RubyNode coercetNewNameToString(RubyNode newName) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), newName);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), newName);
}

@CreateCast("oldName")
public RubyNode coerceOldNameToString(RubyNode oldName) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), oldName);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), oldName);
}

@Specialization
@@ -720,7 +716,7 @@ public ClassVariableGetNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -825,7 +821,7 @@ public ConstDefinedNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -859,47 +855,66 @@ public ConstGetNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToSymbolOrStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization(guards = "!isScoped(name)")
public Object getConstant(VirtualFrame frame, RubyModule module, String name, UndefinedPlaceholder inherit) {
// Symbol
@Specialization
public Object getConstant(VirtualFrame frame, RubyModule module, RubySymbol name, UndefinedPlaceholder inherit) {
return getConstant(frame, module, name, true);
}

@Specialization(guards = { "!isScoped(name)", "inherit" })
public Object getConstant(VirtualFrame frame, RubyModule module, String name, boolean inherit) {
return getConstantNode.executeGetConstant(frame, module, name);
@Specialization(guards = "inherit")
public Object getConstant(VirtualFrame frame, RubyModule module, RubySymbol name, boolean inherit) {
return getConstantNode.executeGetConstant(frame, module, name.toString());
}

@Specialization(guards = { "!isScoped(name)", "!inherit" })
public Object getConstantNoInherit(VirtualFrame frame, RubyModule module, String name, boolean inherit) {
CompilerDirectives.transferToInterpreter();
@Specialization(guards = "!inherit")
public Object getConstantNoInherit(VirtualFrame frame, RubyModule module, RubySymbol name, boolean inherit) {
return getConstantNoInherit(module, name.toString(), this);
}

RubyConstant constant = module.getConstants().get(name);
if (constant == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorUninitializedConstant(module, name, this));
} else {
return constant.getValue();
}
// String
@Specialization(guards = "!isScoped(name)")
public Object getConstant(VirtualFrame frame, RubyModule module, RubyString name, UndefinedPlaceholder inherit) {
return getConstant(frame, module, name, true);
}

@Specialization(guards = { "inherit", "!isScoped(name)" })
public Object getConstant(VirtualFrame frame, RubyModule module, RubyString name, boolean inherit) {
return getConstantNode.executeGetConstant(frame, module, name.toString());
}

@Specialization(guards = { "!inherit", "!isScoped(name)" })
public Object getConstantNoInherit(VirtualFrame frame, RubyModule module, RubyString name, boolean inherit) {
return getConstantNoInherit(module, name.toString(), this);
}

// Scoped String
@Specialization(guards = "isScoped(fullName)")
public Object getConstantScoped(VirtualFrame frame, RubyModule module, String fullName, UndefinedPlaceholder inherit) {
public Object getConstantScoped(VirtualFrame frame, RubyModule module, RubyString fullName, UndefinedPlaceholder inherit) {
return getConstantScoped(frame, module, fullName, true);
}

@Specialization(guards = "isScoped(fullName)")
public Object getConstantScoped(VirtualFrame frame, RubyModule module, String fullName, boolean inherit) {
CompilerDirectives.transferToInterpreter();
public Object getConstantScoped(VirtualFrame frame, RubyModule module, RubyString fullName, boolean inherit) {
return getConstantScoped(module, fullName.toString(), inherit);
}

Object fullNameObject = RubyArguments.getUserArgument(frame.getArguments(), 0);
if (fullNameObject instanceof RubySymbol && !IdUtil.isValidConstantName19(fullName)) {
@TruffleBoundary
private Object getConstantNoInherit(RubyModule module, String name, Node currentNode) {
final RubyConstant constant = ModuleOperations.lookupConstantWithInherit(getContext(), module, name, false, currentNode);

if (constant == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("wrong constant name %s", fullName), fullName, this));
throw new RaiseException(getContext().getCoreLibrary().nameErrorUninitializedConstant(module, name, this));
} else {
return constant.getValue();
}
}

@TruffleBoundary
private Object getConstantScoped(RubyModule module, String fullName, boolean inherit) {
RubyConstant constant = ModuleOperations.lookupScopedConstant(getContext(), module, fullName, inherit, this);
if (constant == null) {
CompilerDirectives.transferToInterpreter();
@@ -909,8 +924,10 @@ public Object getConstantScoped(VirtualFrame frame, RubyModule module, String fu
}
}

boolean isScoped(String name) {
return name.contains("::");
@TruffleBoundary
boolean isScoped(RubyString name) {
// TODO (eregon, 27 May 2015): Any way to make this efficient?
return name.toString().contains("::");
}

}
@@ -943,7 +960,7 @@ public ConstSetNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -975,7 +992,7 @@ public DefineMethodNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@CompilerDirectives.TruffleBoundary
@@ -1179,7 +1196,7 @@ public MethodDefinedNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1372,7 +1389,7 @@ public PrivateMethodDefinedNode(RubyContext context, SourceSection sourceSection

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1420,7 +1437,7 @@ public ProtectedMethodDefinedNode(RubyContext context, SourceSection sourceSecti

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1467,7 +1484,7 @@ public PublicInstanceMethodNode(RubyContext context, SourceSection sourceSection

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1524,7 +1541,7 @@ public PublicMethodDefinedNode(RubyContext context, SourceSection sourceSection)

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1571,7 +1588,7 @@ public InstanceMethodNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1690,7 +1707,7 @@ public RemoveConstNode(RubyContext context, SourceSection sourceSection) {

@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return SymbolOrToStrNodeGen.create(getContext(), getSourceSection(), name);
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@Specialization
@@ -1709,19 +1726,19 @@ Object removeConstant(RubyModule module, String name) {
@CoreMethod(names = "remove_method", argumentsAsArray = true, visibility = Visibility.PRIVATE)
public abstract static class RemoveMethodNode extends CoreMethodArrayArgumentsNode {

@Child SymbolOrToStrNode symbolOrToStrNode;
@Child NameToJavaStringNode nameToJavaStringNode;
@Child RaiseIfFrozenNode raiseIfFrozenNode;

public RemoveMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
this.symbolOrToStrNode = SymbolOrToStrNodeGen.create(context, sourceSection, null);
this.nameToJavaStringNode = NameToJavaStringNodeGen.create(context, sourceSection, null);
this.raiseIfFrozenNode = new RaiseIfFrozenNode(new SelfNode(context, sourceSection));
}

@Specialization
public RubyModule removeMethod(VirtualFrame frame, RubyModule module, Object[] args) {
for (Object arg : args) {
final String name = symbolOrToStrNode.executeToJavaString(frame, arg);
final String name = nameToJavaStringNode.executeToJavaString(frame, arg);
raiseIfFrozenNode.execute(frame);

if (module.getMethods().containsKey(name)) {
@@ -1855,20 +1872,20 @@ public abstract static class SetMethodVisibilityNode extends RubyNode {
private final Visibility visibility;

@Child SingletonClassNode singletonClassNode;
@Child SymbolOrToStrNode symbolOrToStrNode;
@Child NameToJavaStringNode nameToJavaStringNode;

public SetMethodVisibilityNode(RubyContext context, SourceSection sourceSection, Visibility visibility) {
super(context, sourceSection);
this.visibility = visibility;
this.symbolOrToStrNode = SymbolOrToStrNodeGen.create(context, sourceSection, null);
this.nameToJavaStringNode = NameToJavaStringNodeGen.create(context, sourceSection, null);
this.singletonClassNode = SingletonClassNodeGen.create(context, sourceSection, null);
}

public abstract RubyModule executeSetMethodVisibility(VirtualFrame frame, RubyModule module, Object name);

@Specialization
RubyModule setMethodVisibility(VirtualFrame frame, RubyModule module, Object name) {
final String methodName = symbolOrToStrNode.executeToJavaString(frame, name);
final String methodName = nameToJavaStringNode.executeToJavaString(frame, name);

final InternalMethod method = module.deepMethodSearch(methodName);

Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
@CoreClass(name = "Hash")
public abstract class HashNodes {

@CoreMethod(names = "[]", onSingleton = true, argumentsAsArray = true, reallyDoesNeedSelf = true)
@CoreMethod(names = "[]", constructor = true, argumentsAsArray = true)
@ImportStatic(HashGuards.class)
public abstract static class ConstructNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -570,9 +570,9 @@ public IOSelectPrimitiveNode(RubyContext context, SourceSection sourceSection) {

@CompilerDirectives.TruffleBoundary
@Specialization(guards = {"isNil(writables)", "isNil(errorables)"})
public Object select(VirtualFrame frame, RubyArray readables, RubyBasicObject writables, RubyBasicObject errorables, int timeout) {
public Object select(RubyArray readables, RubyBasicObject writables, RubyBasicObject errorables, int timeout) {
final Object[] readableObjects = readables.slowToArray();
final int[] readableFds = getFileDescriptors(frame, readables);
final int[] readableFds = getFileDescriptors(readables);

final FDSet readableSet = fdSetFactory.create();

@@ -602,7 +602,7 @@ public Integer block() throws InterruptedException {
RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass()));
}

private int[] getFileDescriptors(VirtualFrame frame, RubyArray fileDescriptorArray) {
private int[] getFileDescriptors(RubyArray fileDescriptorArray) {
final Object[] objects = fileDescriptorArray.slowToArray();

final int[] fileDescriptors = new int[objects.length];
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ public static RubyConstant lookupScopedConstant(RubyContext context, RubyModule
return lookupConstantWithInherit(context, module, lastSegment, inherit, currentNode);
}

private static RubyConstant lookupConstantWithInherit(RubyContext context, RubyModule module, String name, boolean inherit, Node currentNode) {
public static RubyConstant lookupConstantWithInherit(RubyContext context, RubyModule module, String name, boolean inherit, Node currentNode) {
if (!IdUtil.isValidConstantName19(name)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreLibrary().nameError(String.format("wrong constant name %s", name), name, currentNode));