Skip to content
Permalink
Browse files
[Truffle] All Struct specs passing.
  • Loading branch information
chrisseaton committed Dec 18, 2014
1 parent c045332 commit a8e53233307f6ed7f13a818aaffe8d513057de9c
Showing with 412 additions and 624 deletions.
  1. +10 −3 core/src/main/java/org/jruby/truffle/nodes/WriteConstantNode.java
  2. +19 −17 core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  3. +19 −1 core/src/main/java/org/jruby/truffle/nodes/core/ExceptionNodes.java
  4. +28 −4 core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
  5. +17 −21 core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  6. +71 −23 core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  7. +1 −1 core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  8. +1 −1 core/src/main/java/org/jruby/truffle/runtime/core/RubyClass.java
  9. +14 −7 core/src/main/java/org/jruby/truffle/runtime/core/RubyModule.java
  10. +2 −2 core/src/main/java/org/jruby/truffle/runtime/objectstorage/ObjectLayout.java
  11. +9 −1 core/src/main/java/org/jruby/truffle/runtime/objectstorage/ObjectStorage.java
  12. +1 −1 core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  13. +8 −0 core/src/main/ruby/jruby/truffle/core.rb
  14. +9 −6 core/src/main/ruby/jruby/truffle/core/rubinius/README.md
  15. +33 −0 core/src/main/ruby/jruby/truffle/core/rubinius/api/shims/enumerator.rb
  16. +11 −0 core/src/main/ruby/jruby/truffle/core/rubinius/api/shims/lookuptable.rb
  17. +19 −0 core/src/main/ruby/jruby/truffle/core/rubinius/api/shims/thread.rb
  18. +25 −0 core/src/main/ruby/jruby/truffle/core/rubinius/api/shims/type.rb
  19. +23 −0 core/src/main/ruby/jruby/truffle/core/rubinius/api/shims/undefined.rb
  20. +57 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/array.rb
  21. +0 −498 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/time.rb
  22. +33 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/undefined.rb
  23. +2 −0 spec/truffle/tags/core/kernel/eval_tags.txt
  24. +0 −2 spec/truffle/tags/core/struct/each_pair_tags.txt
  25. +0 −2 spec/truffle/tags/core/struct/each_tags.txt
  26. +0 −2 spec/truffle/tags/core/struct/element_reference_tags.txt
  27. +0 −1 spec/truffle/tags/core/struct/element_set_tags.txt
  28. +0 −4 spec/truffle/tags/core/struct/eql_tags.txt
  29. +0 −4 spec/truffle/tags/core/struct/equal_value_tags.txt
  30. +0 −3 spec/truffle/tags/core/struct/hash_tags.txt
  31. +0 −2 spec/truffle/tags/core/struct/initialize_tags.txt
  32. +0 −2 spec/truffle/tags/core/struct/inspect_tags.txt
  33. +0 −1 spec/truffle/tags/core/struct/instance_variables_tags.txt
  34. +0 −6 spec/truffle/tags/core/struct/new_tags.txt
  35. +0 −1 spec/truffle/tags/core/struct/select_tags.txt
  36. +0 −2 spec/truffle/tags/core/struct/struct_tags.txt
  37. +0 −2 spec/truffle/tags/core/struct/to_h_tags.txt
  38. +0 −2 spec/truffle/tags/core/struct/to_s_tags.txt
  39. +0 −2 spec/truffle/tags/core/struct/values_at_tags.txt
@@ -24,12 +24,14 @@
public class WriteConstantNode extends RubyNode {

private final String name;
private final LexicalScope lexicalScope;
@Child protected RubyNode module;
@Child protected RubyNode rhs;

public WriteConstantNode(RubyContext context, SourceSection sourceSection, String name, RubyNode module, RubyNode rhs) {
public WriteConstantNode(RubyContext context, SourceSection sourceSection, String name, LexicalScope lexicalScope, RubyNode module, RubyNode rhs) {
super(context, sourceSection);
this.name = name;
this.lexicalScope = lexicalScope;
this.module = module;
this.rhs = rhs;
}
@@ -41,8 +43,13 @@ public Object execute(VirtualFrame frame) {
// Evaluate RHS first.
final Object rhsValue = rhs.execute(frame);

assert rhsValue != null;
assert !(rhsValue instanceof String);
if (rhsValue instanceof RubyModule) {
final RubyModule setModule = (RubyModule) rhsValue;
if (setModule.getName() == null) {
setModule.setLexicalScope(lexicalScope);
setModule.setName(name);
}
}

final Object receiverObject = module.execute(frame);

@@ -21,6 +21,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.RubyFixnum;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -1769,6 +1770,24 @@ public RubyArray flatten(RubyArray array) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodNode {

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

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

@Specialization
public long hashNumber(RubyArray array) {
return array.hashCode();
}

}

@CoreMethod(names = "include?", required = 1)
public abstract static class IncludeNode extends ArrayCoreMethodNode {

@@ -3657,21 +3676,4 @@ public RubyArray zipObjectObject(RubyArray array, RubyArray other) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodNode {

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

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

@Specialization
public long hashNumber(RubyArray array) {
return array.hashCode();
}

}
}
@@ -65,7 +65,7 @@ public RubyArray backtrace(RubyException exception) {

}

@CoreMethod(names = {"message", "to_s"})
@CoreMethod(names = "message")
public abstract static class MessageNode extends CoreMethodNode {

public MessageNode(RubyContext context, SourceSection sourceSection) {
@@ -83,4 +83,22 @@ public RubyString message(RubyException exception) {

}

@CoreMethod(names = "to_s")
public abstract static class ToSNode extends CoreMethodNode {

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

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

@Specialization
public RubyString toS(RubyException exception) {
return getContext().makeString(exception.getLogicalClass().getName());
}

}

}
@@ -139,7 +139,7 @@ public RubyHash construct(Object[] args) {
if (store.length <= HashOperations.SMALL_HASH_SIZE) {
smallPackedArray.enter();

final int size = store.length;
final int size = array.getSize();
final Object[] newStore = new Object[HashOperations.SMALL_HASH_SIZE * 2];

for (int n = 0; n < HashOperations.SMALL_HASH_SIZE; n++) {
@@ -168,15 +168,39 @@ public RubyHash construct(Object[] args) {
return new RubyHash(getContext().getCoreLibrary().getHashClass(), null, null, newStore, size, null);
} else {
largePackedArray.enter();
throw new UnsupportedOperationException();

final List<KeyValue> keyValues = new ArrayList<>();

final int size = array.getSize();

for (int n = 0; n < size; n++) {
final Object pair = store[n];

if (!(pair instanceof RubyArray)) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
}

final RubyArray pairArray = (RubyArray) pair;

if (!(pairArray.getStore() instanceof Object[])) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException();
}

final Object[] pairStore = (Object[]) pairArray.getStore();
keyValues.add(new KeyValue(pairStore[0], pairStore[1]));
}

return HashOperations.verySlowFromEntries(getContext(), keyValues);
}
} else {
otherArray.enter();
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("other array");
}
} else {
singleOther.enter();
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("single other");
}
} else {
keyValues.enter();
@@ -1035,7 +1035,7 @@ public RubyArray instanceVariables(RubyBasicObject self) {
final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());

for (String name : instanceVariableNames) {
array.slowPush(RubyString.fromJavaString(getContext().getCoreLibrary().getStringClass(), name));
array.slowPush(getContext().getSymbolTable().getSymbol(name));
}

return array;
@@ -1096,7 +1096,12 @@ public Object integer(RubyString value) {

@Specialization
public Object integer(VirtualFrame frame, Object value) {
return toInt.call(frame, value, "to_int", null);
if (toInt.doesRespondTo(frame, "to_int", value)) {
return toInt.call(frame, value, "to_int", null);
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(value, getContext().getCoreLibrary().getIntegerClass(), this));
}
}

}
@@ -1546,6 +1551,11 @@ public Object raise(VirtualFrame frame, RubyClass exceptionClass, RubyString mes
throw new RaiseException(exception);
}

@Specialization
public Object raise(RubyException exception, UndefinedPlaceholder undefined1, Object undefined2) {
throw new RaiseException(exception);
}

}

@CoreMethod(names = "rand", isModuleFunction = true, optional = 1)
@@ -2060,6 +2070,11 @@ public RubyString toS(VirtualFrame frame, Object self) {
notDesignedForCompilation();

String className = classNode.executeGetClass(frame, self).getName();

if (className == null) {
className = "Class";
}

Object id = idNode.executeObjectID(frame, self);
String hexID = toHexStringNode.executeToHexString(id);

@@ -2068,23 +2083,4 @@ public RubyString toS(VirtualFrame frame, Object self) {

}

// Rubinius API
@CoreMethod(names = "undefined", isModuleFunction = true)
public abstract static class UndefinedNode extends CoreMethodNode {

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

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

@Specialization
public UndefinedPlaceholder undefined() {
return UndefinedPlaceholder.INSTANCE;
}

}

}
@@ -34,6 +34,7 @@
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.methods.*;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.util.IdUtil;

import java.util.ArrayList;
import java.util.List;
@@ -677,18 +678,33 @@ public ConstSetNode(ConstSetNode prev) {
@Specialization
public RubyModule setConstant(RubyModule module, RubyString name, Object object) {
notDesignedForCompilation();

module.setConstant(this, name.toString(), object);
setConstant(module, name.toString(), object);
return module;
}

@Specialization
public RubyModule setConstant(RubyModule module, RubySymbol name, Object object) {
notDesignedForCompilation();

module.setConstant(this, name.toString(), object);
setConstant(module, name.toString(), object);
return module;
}

public void setConstant(RubyModule module, String name, Object object) {
if (!IdUtil.isConstant(name)) {
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("wrong constant name %s", name), this));
}

if (object instanceof RubyModule) {
final RubyModule setModule = (RubyModule) object;
if (setModule.getName() == null) {
setModule.setLexicalScope(new LexicalScope(null, module));
setModule.setName(name);
}
}

module.setConstant(this, name, object);
}

}

@CoreMethod(names = "define_method", needsBlock = true, required = 1, optional = 1)
@@ -837,6 +853,39 @@ public RubyNilClass include(VirtualFrame frame, RubyModule module, Object[] args
}
}

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

@Child protected DispatchHeadNode appendFeaturesNode;

public IncludePNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendFeaturesNode = new DispatchHeadNode(context);
}

public IncludePNode(IncludePNode prev) {
super(prev);
appendFeaturesNode = prev.appendFeaturesNode;
}

@Specialization
public boolean include(RubyModule module, RubyModule included) {
notDesignedForCompilation();

ModuleChain ancestor = module.getParentModule();

while (ancestor != null) {
if (ancestor.getActualModule() == included) {
return true;
}

ancestor = ancestor.getParentModule();
}

return false;
}
}

@CoreMethod(names = "method_defined?", required = 1, optional = 1)
public abstract static class MethodDefinedNode extends CoreMethodNode {

@@ -939,10 +988,26 @@ public NameNode(NameNode prev) {
}

@Specialization
public RubyString name(RubyModule module) {
public Object name(RubyModule module) {
notDesignedForCompilation();

return getContext().makeString(module.getName());
if (module.getName() == null) {
return getContext().getCoreLibrary().getNilObject();
}

final StringBuilder builder = new StringBuilder();

builder.append(module.getName());

LexicalScope lexicalScope = module.getLexicalScope();

while (lexicalScope != null && lexicalScope.getLiveModule() != getContext().getCoreLibrary().getObjectClass()) {
builder.insert(0, "::");
builder.insert(0, lexicalScope.getLiveModule().getName());
lexicalScope = lexicalScope.getParent();
}

return getContext().makeString(builder.toString());
}
}

@@ -1344,23 +1409,6 @@ public RubyModule removeMethod(RubyModule module, RubySymbol name) {

}

@CoreMethod(names = {"to_s", "inspect"})
public abstract static class ToSNode extends CoreMethodNode {

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

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

@Specialization
public RubyString toS(RubyModule module) {
return getContext().makeString(module.getName());
}
}

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

@@ -206,7 +206,7 @@ public void initialize() {
localJumpErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "LocalJumpError");
matchDataClass = new RubyClass(context, objectClass, objectClass, "MatchData");
mathModule = new RubyModule(context, objectClass, "Math");
nameErrorClass = new RubyClass(context, objectClass, standardErrorClass, "NameError");
nameErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "NameError");
nilClass = new RubyClass(context, objectClass, objectClass, "NilClass");
noMethodErrorClass = new RubyException.RubyExceptionClass(context, objectClass, nameErrorClass, "NoMethodError");
objectSpaceModule = new RubyModule(context, objectClass, "ObjectSpace");
@@ -41,7 +41,7 @@ public RubyClassClass(RubyContext context) {

@Override
public RubyBasicObject newInstance(RubyNode currentNode) {
return new RubyClass(getContext(), null, null, "(unnamed class)", false);
return new RubyClass(getContext(), null, null, null, false);
}

}

0 comments on commit a8e5323

Please sign in to comment.