Skip to content

Commit

Permalink
[Truffle] Fix Module#remove_class_variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jul 10, 2015
1 parent fd47b9d commit 084efdb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/module/remove_class_variable_tags.txt

This file was deleted.

5 changes: 5 additions & 0 deletions tool/jt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def mspec(command, *args)
env_vars = command
command, *args = args
end

if ENV["JRUBY_ECLIPSE"] == "true"
args.unshift "-ttool/jruby_eclipse"
end

sh env_vars, 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args
end
end
Expand Down
24 changes: 13 additions & 11 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1740,24 +1740,26 @@ public RubyModule doProtected(VirtualFrame frame, RubyModule module, Object[] na
}

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

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

@TruffleBoundary
@Specialization(guards = "isRubyString(name)")
public RubyModule removeClassVariableString(RubyModule module, RubyBasicObject name) {
module.removeClassVariable(this, name.toString());
return module;
@CreateCast("name")
public RubyNode coerceToString(RubyNode name) {
return NameToJavaStringNodeGen.create(getContext(), getSourceSection(), name);
}

@TruffleBoundary
@Specialization(guards = "isRubySymbol(name)")
public RubyModule removeClassVariableSymbol(RubyModule module, RubyBasicObject name) {
module.removeClassVariable(this, SymbolNodes.getString(name));
return module;
@Specialization
public Object removeClassVariableString(RubyModule module, String name) {
RubyContext.checkClassVariableName(getContext(), name, this);
return module.removeClassVariable(this, name);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,11 @@ public RubyException nameErrorLocalVariableNotDefined(String name, RubyBasicObje
return nameError(String.format("local variable `%s' not defined for %s", name, binding.toString()), name, currentNode);
}

public RubyException nameErrorClassVariableNotDefined(String name, RubyModule module, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return nameError(String.format("class variable `%s' not defined for %s", name, module.getName()), name, currentNode);
}

public RubyException noMethodError(String message, String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
RubyException noMethodError = new RubyException(context.getCoreLibrary().getNoMethodErrorClass(), StringNodes.createString(context.getCoreLibrary().getStringClass(), message), RubyCallStack.getBacktrace(currentNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,15 @@ public void setClassVariable(Node currentNode, String variableName, Object value
}

@TruffleBoundary
public void removeClassVariable(Node currentNode, String variableName) {
public Object removeClassVariable(Node currentNode, String name) {
checkFrozen(currentNode);

classVariables.remove(variableName);
final Object found = classVariables.remove(name);
if (found == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreLibrary().nameErrorClassVariableNotDefined(name, this, currentNode));
}
return found;
}

@TruffleBoundary
Expand Down

0 comments on commit 084efdb

Please sign in to comment.