Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/truffle/runtime/objectstorage/ObjectLayout.java
	core/src/main/java/org/jruby/truffle/runtime/objectstorage/ObjectStorage.java
  • Loading branch information
chrisseaton committed Dec 18, 2014
2 parents 80f3952 + a8e5323 commit 3a11773
Show file tree
Hide file tree
Showing 37 changed files with 401 additions and 621 deletions.
13 changes: 10 additions & 3 deletions core/src/main/java/org/jruby/truffle/nodes/WriteConstantNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down
36 changes: 19 additions & 17 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
}

}

}
32 changes: 28 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down
38 changes: 17 additions & 21 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,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;
Expand Down Expand Up @@ -1095,7 +1095,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));
}
}

}
Expand Down Expand Up @@ -1545,6 +1550,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)
Expand Down Expand Up @@ -2059,6 +2069,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);

Expand All @@ -2067,23 +2082,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;
}

}

}
94 changes: 71 additions & 23 deletions core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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);
}

}
Expand Down
Loading

0 comments on commit 3a11773

Please sign in to comment.