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: ff5fb6814ac4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d0cb6db994ed
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Jun 1, 2015

  1. Copy the full SHA
    be8f712 View commit details
  2. Copy the full SHA
    d0cb6db View commit details
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/module/const_missing_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/module/method_removed_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/module/method_undefined_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/module/undef_method_tags.txt

This file was deleted.

82 changes: 55 additions & 27 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import jnr.posix.Passwd;

import org.jcodings.Encoding;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
@@ -41,6 +43,8 @@
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetMethodVisibilityNodeGen;
import org.jruby.truffle.nodes.core.ModuleNodesFactory.SetVisibilityNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -928,15 +932,24 @@ boolean isScoped(RubyString name) {
}

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

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

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

@Specialization
public Object methodMissing(RubyModule module, RubySymbol name) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorUninitializedConstant(module, name.toString(), this));
public Object methodMissing(RubyModule module, String name) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorUninitializedConstant(module, name, this));
}

}
@@ -1723,29 +1736,36 @@ public abstract static class RemoveMethodNode extends CoreMethodArrayArgumentsNo

@Child NameToJavaStringNode nameToJavaStringNode;
@Child RaiseIfFrozenNode raiseIfFrozenNode;
@Child CallDispatchHeadNode methodRemovedNode;

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

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

if (module.getMethods().containsKey(name)) {
module.removeMethod(name);
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorMethodNotDefinedIn(module, name, this));
}
public RubyModule removeMethods(VirtualFrame frame, RubyModule module, Object[] names) {
for (Object name : names) {
removeMethod(frame, module, nameToJavaStringNode.executeToJavaString(frame, name));
}
return module;
}

private void removeMethod(VirtualFrame frame, RubyModule module, String name) {
raiseIfFrozenNode.execute(frame);

CompilerDirectives.transferToInterpreter();
if (module.getMethods().containsKey(name)) {
module.removeMethod(name);
methodRemovedNode.call(frame, module, "method_removed", null, getContext().getSymbol(name));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorMethodNotDefinedIn(module, name, this));
}
}

}

@CoreMethod(names = { "to_s", "inspect" })
@@ -1764,32 +1784,40 @@ public RubyBasicObject toS(RubyModule module) {

}

@CoreMethod(names = "undef_method", required = 1)
@CoreMethod(names = "undef_method", argumentsAsArray = true, visibility = Visibility.PRIVATE)
public abstract static class UndefMethodNode extends CoreMethodArrayArgumentsNode {

@Child NameToJavaStringNode nameToJavaStringNode;
@Child RaiseIfFrozenNode raiseIfFrozenNode;
@Child CallDispatchHeadNode methodUndefinedNode;

public UndefMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
this.nameToJavaStringNode = NameToJavaStringNodeGen.create(context, sourceSection, null);
this.raiseIfFrozenNode = new RaiseIfFrozenNode(new SelfNode(context, sourceSection));
this.methodUndefinedNode = DispatchHeadNodeFactory.createMethodCallOnSelf(context);
}

@Specialization
public RubyModule undefMethod(RubyModule module, RubyString name) {
return undefMethod(module, name.toString());
}

@Specialization
public RubyModule undefMethod(RubyModule module, RubySymbol name) {
return undefMethod(module, name.toString());
public RubyModule undefMethods(VirtualFrame frame, RubyModule module, Object[] names) {
for (Object name : names) {
undefMethod(frame, module, nameToJavaStringNode.executeToJavaString(frame, name));
}
return module;
}

private RubyModule undefMethod(RubyModule module, String name) {
CompilerDirectives.transferToInterpreter();
private void undefMethod(VirtualFrame frame, RubyModule module, String name) {
raiseIfFrozenNode.execute(frame);

final InternalMethod method = ModuleOperations.lookupMethod(module, name);
if (method == null) {

if (method != null) {
module.undefMethod(this, method);
methodUndefinedNode.call(frame, module, "method_undefined", null, getContext().getSymbol(name));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().noMethodErrorOnModule(name, module, this));
}
module.undefMethod(this, method);
return module;
}

}
Original file line number Diff line number Diff line change
@@ -15,7 +15,9 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import jnr.constants.platform.Errno;

import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.transcode.EConvFlags;
@@ -920,7 +922,13 @@ public RubyException nameErrorConstantNotDefined(RubyModule module, String name,

public RubyException nameErrorUninitializedConstant(RubyModule module, String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return nameError(String.format("uninitialized constant %s::%s", module.getName(), name), name, currentNode);
final String message;
if (module == objectClass) {
message = String.format("uninitialized constant %s", name);
} else {
message = String.format("uninitialized constant %s::%s", module.getName(), name);
}
return nameError(message, name, currentNode);
}

public RubyException nameErrorUninitializedClassVariable(RubyModule module, String name, Node currentNode) {
8 changes: 8 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/module.rb
Original file line number Diff line number Diff line change
@@ -60,4 +60,12 @@ def method_added(name)
end
private :method_added

def method_removed(name)
end
private :method_removed

def method_undefined(name)
end
private :method_undefined

end