Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Nov 8, 2014
2 parents 7192c00 + 1fe2e27 commit b6a91af
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 123 deletions.
32 changes: 31 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/core/ClassNodes.java
Expand Up @@ -9,13 +9,16 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyString;
Expand All @@ -26,18 +29,45 @@
@CoreClass(name = "Class")
public abstract class ClassNodes {

@CoreMethod(names = "allocate")
public abstract static class AllocateNode extends CoreMethodNode {

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

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

public abstract RubyBasicObject executeAllocate(VirtualFrame frame, RubyClass rubyClass);

@Specialization
public RubyBasicObject allocate(RubyClass rubyClass) {
if (rubyClass.isSingleton()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("can't create instance of singleton class", this));
}
return rubyClass.newInstance(this);
}

}

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

@Child protected AllocateNode allocateNode;
@Child protected DispatchHeadNode initialize;

public NewNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
allocateNode = ClassNodesFactory.AllocateNodeFactory.create(context, sourceSection, new RubyNode[]{null});
initialize = DispatchHeadNode.onSelf(context);
}

public NewNode(NewNode prev) {
super(prev);
allocateNode = prev.allocateNode;
initialize = prev.initialize;
}

Expand All @@ -52,7 +82,7 @@ public RubyBasicObject newInstance(VirtualFrame frame, RubyClass rubyClass, Obje
}

private RubyBasicObject doNewInstance(VirtualFrame frame, RubyClass rubyClass, Object[] args, RubyProc block) {
final RubyBasicObject instance = rubyClass.newInstance(this);
final RubyBasicObject instance = allocateNode.executeAllocate(frame, rubyClass);
initialize.call(frame, instance, "initialize", block, args);
return instance;
}
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Expand Up @@ -1094,23 +1094,23 @@ public MethodsNode(MethodsNode prev) {
}

@Specialization
public RubyArray methods(RubyObject self, boolean includeInherited) {
notDesignedForCompilation();

if (!includeInherited) {
getContext().getRuntime().getWarnings().warn(IRubyWarnings.ID.TRUFFLE, Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getSource().getName(), Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getStartLine(), "Object#methods always returns inherited methods at the moment");
}

return methods(self, UndefinedPlaceholder.INSTANCE);
public RubyArray methods(RubyObject self, @SuppressWarnings("unused") UndefinedPlaceholder unused) {
return methods(self, true);
}

@Specialization
public RubyArray methods(RubyObject self, @SuppressWarnings("unused") UndefinedPlaceholder includeInherited) {
public RubyArray methods(RubyObject self, boolean includeInherited) {
notDesignedForCompilation();

final RubyArray array = new RubyArray(self.getContext().getCoreLibrary().getArrayClass());

final Map<String, RubyMethod> methods = ModuleOperations.getAllMethods(self.getMetaClass());
Map<String, RubyMethod> methods;

if (includeInherited) {
methods = ModuleOperations.getAllMethods(self.getMetaClass());
} else {
methods = self.getMetaClass().getMethods();
}

for (RubyMethod method : methods.values()) {
if (method.getVisibility() == Visibility.PUBLIC || method.getVisibility() == Visibility.PROTECTED) {
Expand Down
20 changes: 11 additions & 9 deletions core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Expand Up @@ -37,6 +37,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@CoreClass(name = "Module")
public abstract class ModuleNodes {
Expand Down Expand Up @@ -1112,28 +1113,29 @@ public InstanceMethodsNode(InstanceMethodsNode prev) {
public RubyArray instanceMethods(RubyModule module, UndefinedPlaceholder argument) {
notDesignedForCompilation();

return instanceMethods(module, false);
return instanceMethods(module, true);
}

@Specialization
public RubyArray instanceMethods(RubyModule module, boolean includeAncestors) {
notDesignedForCompilation();

final List<RubyMethod> methods = new ArrayList<>(module.getMethods().values());
Map<String, RubyMethod> methods;

if (includeAncestors) {
for (RubyModule parent : module.parentAncestors()) {
methods.addAll(parent.getMethods().values());
}
methods = ModuleOperations.getAllMethods(module);
} else {
methods = module.getMethods();
}

final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
for (RubyMethod method : methods) {
if (method.getVisibility() != Visibility.PRIVATE){
RubySymbol m = getContext().newSymbol(method.getName());
for (RubyMethod method : methods.values()) {
if (method.getVisibility() != Visibility.PRIVATE && !method.isUndefined()) {
// TODO(CS): shoudln't be using this
array.slowPush(m);
array.slowPush(getContext().newSymbol(method.getName()));
}
}

return array;
}
}
Expand Down
Expand Up @@ -11,7 +11,6 @@

import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;
Expand Down Expand Up @@ -49,7 +48,7 @@ public Object execute(VirtualFrame frame) {
} else if (superClassObject instanceof RubyString.RubyStringClass) {
definingClass = new RubyString.RubyStringClass(superClassObject);
} else {
definingClass = new RubyClass(this, lexicalParent, superClassObject, name);
definingClass = new RubyClass(lexicalParent, superClassObject, name);
}

lexicalParent.setConstant(this, name, definingClass);
Expand Down
61 changes: 31 additions & 30 deletions core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
Expand Up @@ -21,7 +21,6 @@
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ArrayNodes;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
Expand Down Expand Up @@ -121,70 +120,72 @@ public void initialize() {
// Create the cyclic classes and modules

classClass = new RubyClass.RubyClassClass(context);
basicObjectClass = new RubyClass(null, context, classClass, null, null, "BasicObject");
objectClass = new RubyClass(null, null, basicObjectClass, "Object");
basicObjectClass = RubyClass.createBootClass(context, classClass, "BasicObject");
objectClass = RubyClass.createBootClass(context, classClass, "Object");
moduleClass = new RubyModule.RubyModuleClass(context);

// Close the cycles

moduleClass.unsafeSetLogicalClass(classClass);
classClass.unsafeSetSuperclass(null, moduleClass);
moduleClass.unsafeSetSuperclass(null, objectClass);
classClass.unsafeSetLogicalClass(classClass);
moduleClass.unsafeSetLogicalClass(classClass);

objectClass.unsafeSetSuperclass(basicObjectClass);
moduleClass.unsafeSetSuperclass(objectClass);
classClass.unsafeSetSuperclass(moduleClass);

// Create all other classes and modules

numericClass = new RubyClass(null, null, objectClass, "Numeric");
integerClass = new RubyClass(null, null, numericClass, "Integer");
numericClass = new RubyClass(null, objectClass, "Numeric");
integerClass = new RubyClass(null, numericClass, "Integer");

exceptionClass = new RubyException.RubyExceptionClass(objectClass, "Exception");
standardErrorClass = new RubyException.RubyExceptionClass(exceptionClass, "StandardError");

ioClass = new RubyClass(null, null, objectClass, "IO");
ioClass = new RubyClass(null, objectClass, "IO");

argumentErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "ArgumentError");
arrayClass = new RubyArray.RubyArrayClass(objectClass);
bignumClass = new RubyClass(null, null, integerClass, "Bignum");
bindingClass = new RubyClass(null, null, objectClass, "Binding");
bignumClass = new RubyClass(null, integerClass, "Bignum");
bindingClass = new RubyClass(null, objectClass, "Binding");
comparableModule = new RubyModule(moduleClass, null, "Comparable");
configModule = new RubyModule(moduleClass, null, "Config");
continuationClass = new RubyClass(null, null, objectClass, "Continuation");
dirClass = new RubyClass(null, null, objectClass, "Dir");
continuationClass = new RubyClass(null, objectClass, "Continuation");
dirClass = new RubyClass(null, objectClass, "Dir");
encodingClass = new RubyEncoding.RubyEncodingClass(objectClass);
errnoModule = new RubyModule(moduleClass, null, "Errno");
enumerableModule = new RubyModule(moduleClass, null, "Enumerable");
falseClass = new RubyClass(null, null, objectClass, "FalseClass");
falseClass = new RubyClass(null, objectClass, "FalseClass");
fiberClass = new RubyFiber.RubyFiberClass(objectClass);
fileClass = new RubyClass(null, null, ioClass, "File");
fixnumClass = new RubyClass(null, null, integerClass, "Fixnum");
floatClass = new RubyClass(null, null, numericClass, "Float");
fileClass = new RubyClass(null, ioClass, "File");
fixnumClass = new RubyClass(null, integerClass, "Fixnum");
floatClass = new RubyClass(null, numericClass, "Float");
gcModule = new RubyModule(moduleClass, null, "GC");
hashClass = new RubyHash.RubyHashClass(objectClass);
kernelModule = new RubyModule(moduleClass, null, "Kernel");
loadErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "LoadError");
localJumpErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "LocalJumpError");
matchDataClass = new RubyClass(null, null, objectClass, "MatchData");
matchDataClass = new RubyClass(null, objectClass, "MatchData");
mathModule = new RubyModule(moduleClass, null, "Math");
nameErrorClass = new RubyClass(null, null, standardErrorClass, "NameError");
nilClass = new RubyClass(null, null, objectClass, "NilClass");
nameErrorClass = new RubyClass(null, standardErrorClass, "NameError");
nilClass = new RubyClass(null, objectClass, "NilClass");
noMethodErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "NoMethodError");
objectSpaceModule = new RubyModule(moduleClass, null, "ObjectSpace");
procClass = new RubyProc.RubyProcClass(objectClass);
processClass = new RubyClass(null, null, objectClass, "Process");
rangeClass = new RubyClass(null, null, objectClass, "Range");
processClass = new RubyClass(null, objectClass, "Process");
rangeClass = new RubyClass(null, objectClass, "Range");
rangeErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "RangeError");
regexpClass = new RubyRegexp.RubyRegexpClass(objectClass);
rubyTruffleErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "RubyTruffleError");
runtimeErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "RuntimeError");
signalModule = new RubyModule(moduleClass, null, "Signal");
stringClass = new RubyString.RubyStringClass(objectClass);
symbolClass = new RubyClass(null, null, objectClass, "Symbol");
symbolClass = new RubyClass(null, objectClass, "Symbol");
syntaxErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "SyntaxError");
systemCallErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "SystemCallError");
systemExitClass = new RubyException.RubyExceptionClass(exceptionClass, "SystemExit");
threadClass = new RubyThread.RubyThreadClass(objectClass);
timeClass = new RubyTime.RubyTimeClass(objectClass);
trueClass = new RubyClass(null, null, objectClass, "TrueClass");
trueClass = new RubyClass(null, objectClass, "TrueClass");
truffleModule = new RubyModule(moduleClass, null, "Truffle");
truffleDebugModule = new RubyModule(moduleClass, null, "Debug");
typeErrorClass = new RubyException.RubyExceptionClass(standardErrorClass, "TypeError");
Expand Down Expand Up @@ -330,12 +331,12 @@ public void initialize() {
fileClass.setConstant(null, "PATH_SEPARATOR", RubyString.fromJavaString(stringClass, File.pathSeparator));
fileClass.setConstant(null, "FNM_SYSCASE", 0);

errnoModule.setConstant(null, "ENOENT", new RubyClass(null, null, systemCallErrorClass, "ENOENT"));
errnoModule.setConstant(null, "EPERM", new RubyClass(null, null, systemCallErrorClass, "EPERM"));
errnoModule.setConstant(null, "ENOTEMPTY", new RubyClass(null, null, systemCallErrorClass, "ENOTEMPTY"));
errnoModule.setConstant(null, "EEXIST", new RubyClass(null, null, systemCallErrorClass, "EEXIST"));
errnoModule.setConstant(null, "EXDEV", new RubyClass(null, null, systemCallErrorClass, "EXDEV"));
errnoModule.setConstant(null, "EACCES", new RubyClass(null, null, systemCallErrorClass, "EACCES"));
errnoModule.setConstant(null, "ENOENT", new RubyClass(null, systemCallErrorClass, "ENOENT"));
errnoModule.setConstant(null, "EPERM", new RubyClass(null, systemCallErrorClass, "EPERM"));
errnoModule.setConstant(null, "ENOTEMPTY", new RubyClass(null, systemCallErrorClass, "ENOTEMPTY"));
errnoModule.setConstant(null, "EEXIST", new RubyClass(null, systemCallErrorClass, "EEXIST"));
errnoModule.setConstant(null, "EXDEV", new RubyClass(null, systemCallErrorClass, "EXDEV"));
errnoModule.setConstant(null, "EACCES", new RubyClass(null, systemCallErrorClass, "EACCES"));

globalVariablesObject.setInstanceVariable("$DEBUG", context.getRuntime().isDebug());
globalVariablesObject.setInstanceVariable("$VERBOSE", context.getRuntime().warningsEnabled() ? context.getRuntime().isVerbose() : nilObject);
Expand Down
Expand Up @@ -15,8 +15,6 @@
import org.jruby.truffle.nodes.core.ArrayAllocationSite;
import org.jruby.truffle.runtime.subsystems.ObjectSpaceManager;
import org.jruby.truffle.runtime.util.ArrayUtils;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.util.cli.Options;

import java.util.Arrays;
Expand All @@ -31,7 +29,7 @@ public final class RubyArray extends RubyObject {
public static class RubyArrayClass extends RubyClass {

public RubyArrayClass(RubyClass objectClass) {
super(null, null, objectClass, "Array");
super(null, objectClass, "Array");
}

@Override
Expand Down
Expand Up @@ -69,8 +69,8 @@ public RubyClass getSingletonClass(Node currentNode) {

final RubyClass logicalClass = metaClass;

metaClass = new RubyClass(currentNode, null, logicalClass,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()), true);
metaClass = RubyClass.createSingletonClassOfObject(getContext(), logicalClass,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()));

return metaClass;
}
Expand Down
Expand Up @@ -66,4 +66,8 @@ public boolean equals(Object obj) {
return true;
}

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

0 comments on commit b6a91af

Please sign in to comment.