Skip to content
Permalink
Browse files
[Truffle] Move Class#=== to Module and simplify assignableTo.
  • Loading branch information
eregon committed Nov 4, 2014
1 parent 18b74c8 commit 82ce077b8c0d2176e131bdf016fbf29af68a2427
Showing 3 changed files with 32 additions and 38 deletions.
@@ -26,32 +26,6 @@
@CoreClass(name = "Class")
public abstract class ClassNodes {

@CoreMethod(names = "===", required = 1)
public abstract static class ContainsInstanceNode extends CoreMethodNode {

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

public ContainsInstanceNode(ContainsInstanceNode prev) {
super(prev);
}

@Specialization
public boolean containsInstance(RubyClass rubyClass, RubyBasicObject instance) {
notDesignedForCompilation();

return ModuleOperations.assignableTo(instance.getLogicalClass(), rubyClass);
}

@Specialization
public boolean containsInstance(RubyClass rubyClass, Object instance) {
notDesignedForCompilation();

return ModuleOperations.assignableTo(getContext().getCoreLibrary().box(instance).getLogicalClass(), rubyClass);
}
}

@CoreMethod(names = "new", needsBlock = true, argumentsAsArray = true)
public abstract static class NewNode extends CoreMethodNode {

@@ -41,6 +41,32 @@
@CoreClass(name = "Module")
public abstract class ModuleNodes {

@CoreMethod(names = "===", required = 1)
public abstract static class ContainsInstanceNode extends CoreMethodNode {

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

public ContainsInstanceNode(ContainsInstanceNode prev) {
super(prev);
}

@Specialization
public boolean containsInstance(RubyModule module, RubyBasicObject instance) {
notDesignedForCompilation();

return ModuleOperations.includesModule(instance.getMetaClass(), module);
}

@Specialization
public boolean containsInstance(RubyModule module, Object instance) {
notDesignedForCompilation();

return ModuleOperations.includesModule(getContext().getCoreLibrary().box(instance).getMetaClass(), module);
}
}

@CoreMethod(names = "<=", required = 1)
public abstract static class IsSubclassOfNode extends CoreMethodNode {

@@ -30,6 +30,12 @@ public static boolean includesModule(RubyModule module, RubyModule other) {
return false;
}

public static boolean assignableTo(RubyClass thisClass, RubyClass otherClass) {
RubyNode.notDesignedForCompilation();

return includesModule(thisClass, otherClass);
}

public static Map<String, RubyConstant> getAllConstants(RubyModule module) {
CompilerAsserts.neverPartOfCompilation();

@@ -216,16 +222,4 @@ public static void setClassVariable(RubyModule module, String name, Object value
module.getClassVariables().put(name, value);
}

public static boolean assignableTo(RubyClass thisClass, RubyClass otherClass) {
RubyNode.notDesignedForCompilation();

for (RubyModule ancestor : thisClass.ancestors()) {
if (ancestor == otherClass) {
return true;
}
}

return false;
}

}

0 comments on commit 82ce077

Please sign in to comment.