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 Jan 5, 2015
2 parents e898e9c + 7179a58 commit 672834f
Show file tree
Hide file tree
Showing 108 changed files with 2,700 additions and 580 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -94,11 +94,12 @@ nbproject/private
# Eclipse files
/.metadata
/.recommenders
core/.apt_generated
core/.classpath
core/.gitignore
core/.project
core/.settings
core/.apt_generated
core/build.eclipse

# Truffle findbugs
truffle-findbugs-report.html
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyTime.java
Expand Up @@ -151,7 +151,7 @@ public static DateTimeZone getLocalTimeZone(Ruby runtime) {
}
}

private static DateTimeZone getTimeZoneFromTZString(Ruby runtime, String zone) {
public static DateTimeZone getTimeZoneFromTZString(Ruby runtime, String zone) {
DateTimeZone cachedZone = runtime.getTimezoneCache().get(zone);
if (cachedZone != null) {
return cachedZone;
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1034,7 +1034,14 @@ public Operand buildCase(CaseNode caseNode, IRScope s) {
Variable eqqResult = s.createTemporaryVariable();
labels.add(bodyLabel);
Operand v1, v2;
if (whenNode.getExpressionNodes() instanceof ListNode) {
if (whenNode.getExpressionNodes() instanceof DNode) {
// DNode produces a proper result, so we don't want the special ListNode handling below
// FIXME: This is obviously gross, and we need a better way to filter out non-expression ListNode here
// See GH #2423
s.addInstr(new EQQInstr(eqqResult, build(whenNode.getExpressionNodes(), s), value));
v1 = eqqResult;
v2 = manager.getTrue();
} else if (whenNode.getExpressionNodes() instanceof ListNode) {
// Note about refactoring:
// - BEQInstr has a quick implementation when the second operand is a boolean literal
// If it can be fixed to do this even on the first operand, we can switch around
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -195,7 +195,7 @@ public void addInstr(Instr i) {
// FIXME: This lost encoding information when name was converted to string earlier in IRBuilder
keywordArgs.add(new KeyValuePair<Operand, Operand>(new Symbol(rkai.argName, USASCIIEncoding.INSTANCE), rkai.getResult()));
} else if (i instanceof ReceiveRestArgInstr) {
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult()));
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult(), true));
} else if (i instanceof ReceiveArgBase) {
blockArgs.add(((ReceiveArgBase) i).getResult());
}
Expand Down
Expand Up @@ -92,7 +92,6 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, StringNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, SymbolNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ThreadNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TimeNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrueClassNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleDebugNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrufflePrimitiveNodesFactory.getFactories());
Expand Down
Expand Up @@ -82,7 +82,7 @@ public RubyCallNode(RubyContext context, SourceSection section, String methodNam
this.isSplatted = isSplatted;
this.isVCall = isVCall;

dispatchHead = new DispatchHeadNode(context, ignoreVisibility, false, rubiniusPrimitive, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
dispatchHead = new DispatchHeadNode(context, ignoreVisibility, false, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
respondToMissing = new DispatchHeadNode(context, true, Dispatch.MissingBehavior.RETURN_MISSING);
respondToMissingCast = BooleanCastNodeFactory.create(context, section, null);

Expand Down
Expand Up @@ -314,7 +314,7 @@ public abstract static class SendNode extends CoreMethodNode {
public SendNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);

dispatchNode = new DispatchHeadNode(context, true, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), false, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
dispatchNode = new DispatchHeadNode(context, true, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), Dispatch.MissingBehavior.CALL_METHOD_MISSING);

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
dispatchNode.forceUncached();
Expand Down
104 changes: 73 additions & 31 deletions core/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
Expand Down Expand Up @@ -191,7 +191,7 @@ public RubyBignum pow(RubyBignum a, RubyBignum b) {

}

@CoreMethod(names = "/", required = 1)
@CoreMethod(names = {"/", "__slash__"}, required = 1)
public abstract static class DivNode extends BignumCoreMethodNode {

public DivNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -245,36 +245,9 @@ public Object mod(RubyBignum a, long b) {
return fixnumOrBignum(a.mod(b));
}

}

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

@Child protected GeneralDivModNode divModNode;

public DivModNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
divModNode = new GeneralDivModNode(context, sourceSection);
}

public DivModNode(DivModNode prev) {
super(prev);
divModNode = prev.divModNode;
}

@Specialization
public RubyArray divMod(RubyBignum a, int b) {
return divModNode.execute(a, b);
}

@Specialization
public RubyArray divMod(RubyBignum a, long b) {
return divModNode.execute(a, b);
}

@Specialization
public RubyArray divMod(RubyBignum a, RubyBignum b) {
return divModNode.execute(a, b);
public Object mod(RubyBignum a, RubyBignum b) {
return fixnumOrBignum(a.mod(b));
}

}
Expand Down Expand Up @@ -602,6 +575,75 @@ public Object leftShift(RubyBignum a, int b) {

}

@CoreMethod(names = "abs")
public abstract static class AbsNode extends BignumCoreMethodNode {

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

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

@Specialization
public RubyBignum abs(RubyBignum value) {
return value.abs();
}

}

@CoreMethod(names = "even?")
public abstract static class EvenNode extends BignumCoreMethodNode {

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

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

@CompilerDirectives.TruffleBoundary
@Specialization
public boolean even(RubyBignum value) {
return value.bigIntegerValue().getLowestSetBit() != 0;
}

}

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

@Child protected GeneralDivModNode divModNode;

public DivModNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
divModNode = new GeneralDivModNode(context, sourceSection);
}

public DivModNode(DivModNode prev) {
super(prev);
divModNode = prev.divModNode;
}

@Specialization
public RubyArray divMod(RubyBignum a, int b) {
return divModNode.execute(a, b);
}

@Specialization
public RubyArray divMod(RubyBignum a, long b) {
return divModNode.execute(a, b);
}

@Specialization
public RubyArray divMod(RubyBignum a, RubyBignum b) {
return divModNode.execute(a, b);
}

}

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

Expand Down
50 changes: 48 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
Expand All @@ -21,6 +21,8 @@
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyString;

import java.math.BigInteger;

@CoreClass(name = "Fixnum")
public abstract class FixnumNodes {

Expand Down Expand Up @@ -319,7 +321,7 @@ protected static boolean canShiftIntoInt(int a, int b) {

}

@CoreMethod(names = "/", required = 1)
@CoreMethod(names = {"/", "__slash__"}, required = 1)
public abstract static class DivNode extends CoreMethodNode {

private final BranchProfile bGreaterZero = BranchProfile.create();
Expand Down Expand Up @@ -545,6 +547,27 @@ public long mod(long a, long b) {
return mod;
}

@Specialization
public Object mod(int a, RubyBignum b) {
return mod((long) a, b);
}

@Specialization
public Object mod(long a, RubyBignum b) {
notDesignedForCompilation();

// TODO(CS): why are we getting this case?

long mod = BigInteger.valueOf(a).mod(b.bigIntegerValue()).longValue();

if (mod < 0 && b.bigIntegerValue().compareTo(BigInteger.ZERO) > 0 || mod > 0 && b.bigIntegerValue().compareTo(BigInteger.ZERO) < 0) {
adjustProfile.enter();
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), BigInteger.valueOf(mod).add(b.bigIntegerValue()));
}

return mod;
}

}

@CoreMethod(names = "divmod", required = 1)
Expand Down Expand Up @@ -1231,6 +1254,29 @@ public long abs(long n) {

}

@CoreMethod(names = "floor")
public abstract static class FloorNode extends CoreMethodNode {

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

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

@Specialization
public int floor(int n) {
return n;
}

@Specialization
public long floor(long n) {
return n;
}

}

@CoreMethod(names = "size", needsSelf = false)
public abstract static class SizeNode extends CoreMethodNode {

Expand Down
44 changes: 42 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
Expand Down Expand Up @@ -171,7 +171,7 @@ public double pow(double a, RubyBignum b) {

}

@CoreMethod(names = "/", required = 1)
@CoreMethod(names = {"/", "__slash__"}, required = 1)
public abstract static class DivNode extends CoreMethodNode {

public DivNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -507,6 +507,46 @@ public double abs(double n) {

}

@CoreMethod(names = "ceil")
public abstract static class CeilNode extends CoreMethodNode {

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

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

@Specialization
public double ceil(double n) {
return Math.ceil(n);
}

}

@CoreMethod(names = "floor")
public abstract static class FloorNode extends CoreMethodNode {

@Child protected FixnumOrBignumNode fixnumOrBignum;

public FloorNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
fixnumOrBignum = new FixnumOrBignumNode(context, sourceSection);
}

public FloorNode(FloorNode prev) {
super(prev);
fixnumOrBignum = prev.fixnumOrBignum;
}

@Specialization
public Object floor(double n) {
return fixnumOrBignum.fixnumOrBignum(Math.floor(n));
}

}

@CoreMethod(names = "infinite?")
public abstract static class InfiniteNode extends CoreMethodNode {

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
Expand Down Expand Up @@ -376,7 +376,7 @@ public ClassNode(ClassNode prev) {
super(prev);
}

public abstract RubyClass executeGetClass(VirtualFrame frame, Object value);
public abstract RubyClass executeGetClass(Object value);

@Specialization
public RubyClass getClass(boolean value) {
Expand Down Expand Up @@ -1673,6 +1673,8 @@ public RespondToNode(RespondToNode prev) {
dispatchIgnoreVisibility = prev.dispatchIgnoreVisibility;
}

public abstract boolean executeDoesRespondTo(VirtualFrame frame, Object object, Object name, boolean includePrivate);

@Specialization
public boolean doesRespondTo(VirtualFrame frame, Object object, RubyString name, UndefinedPlaceholder checkVisibility) {
return dispatch.doesRespondTo(frame, name, object);
Expand Down Expand Up @@ -1700,7 +1702,6 @@ public boolean doesRespondTo(VirtualFrame frame, Object object, RubySymbol name,
return dispatch.doesRespondTo(frame, name, object);
}
}

}

@CoreMethod(names = "respond_to_missing?", required = 1, optional = 1, visibility = Visibility.PRIVATE)
Expand Down Expand Up @@ -2154,7 +2155,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
public RubyString toS(VirtualFrame frame, Object self) {
notDesignedForCompilation();

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

if (className == null) {
className = "Class";
Expand Down

0 comments on commit 672834f

Please sign in to comment.