Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Work on singleton specs.
  • Loading branch information
chrisseaton committed Oct 9, 2014
1 parent b28b994 commit ff2d675
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
Expand Up @@ -447,6 +447,10 @@ public RubyException typeError(String message, Node currentNode) {
return new RubyException(typeErrorClass, context.makeString(message), RubyCallStack.getBacktrace(currentNode));
}

public RubyException typeErrorCantDefineSingleton(Node currentNode) {
return typeError("can't define singleton", currentNode);
}

public RubyException typeErrorShouldReturn(String object, String method, String expectedType, Node currentNode) {
return typeError(String.format("%s#%s should return %s", object, method, expectedType), currentNode);
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.objectstorage.ObjectLayout;
import org.jruby.truffle.runtime.objectstorage.ObjectStorage;
import org.jruby.truffle.runtime.subsystems.ObjectSpaceManager;
Expand All @@ -40,7 +41,11 @@ public RubyBasicObject(RubyClass rubyClass) {
}
}

public boolean isImmediate() {
public boolean hasNoSingleton() {
return false;
}

public boolean hasClassAsSingleton() {
return false;
}

Expand All @@ -51,7 +56,11 @@ public RubyClass getMetaClass() {
public RubyClass getSingletonClass(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();

if (isImmediate() || metaClass.isSingleton()) {
if (hasNoSingleton()) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(currentNode));
}

if (hasClassAsSingleton() || metaClass.isSingleton()) {
return metaClass;
}

Expand Down
Expand Up @@ -87,7 +87,7 @@ public void initCopy(RubyModule other) {
public RubyClass getSingletonClass(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();

if (isImmediate() || metaClass.isSingleton()) {
if (hasClassAsSingleton() || metaClass.isSingleton()) {
return metaClass;
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public boolean isTrue() {
}

@Override
public boolean isImmediate() {
public boolean hasClassAsSingleton() {
return true;
}

Expand Down
Expand Up @@ -254,7 +254,7 @@ public boolean equals(Object other) {
}

@Override
public boolean isImmediate() {
public boolean hasNoSingleton() {
return true;
}

Expand Down
Expand Up @@ -58,7 +58,7 @@ public boolean isTrue() {
}

@Override
public boolean isImmediate() {
public boolean hasClassAsSingleton() {
return true;
}

Expand Down
Expand Up @@ -141,7 +141,7 @@ public ConcurrentHashMap<ByteList, RubySymbol> getSymbolsTable(){
}

@Override
public boolean isImmediate() {
public boolean hasNoSingleton() {
return true;
}

Expand Down
Expand Up @@ -65,7 +65,7 @@ public int hashCode() {
}

@Override
public boolean isImmediate() {
public boolean hasClassAsSingleton() {
return true;
}

Expand Down
4 changes: 1 addition & 3 deletions spec/truffle/tags/language/singleton_class_tags.txt
Expand Up @@ -11,6 +11,4 @@ fails(inherited):Class methods of a singleton class for a singleton class includ
fails:Instantiating a singleton class raises a TypeError when new is called
fails:Instantiating a singleton class raises a TypeError when allocate is called
fails:A constant on a singleton class is not defined in the singleton class opener's scope
fails:A singleton class raises a TypeError for Fixnum's
fails:A singleton class raises a TypeError for symbols
fails:
fails:A constant on a singleton class is not preserved when the object is duped

0 comments on commit ff2d675

Please sign in to comment.