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 Dec 6, 2014
2 parents 4917d7d + 3cbe259 commit 13285c6
Show file tree
Hide file tree
Showing 36 changed files with 412 additions and 130 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ before_script:
- unset GEM_PATH GEM_HOME IRBRC JRUBY_OPTS
- "export PATH=`pwd`/bin:$PATH"
- "export JAVA_OPTS='-XX:+TieredCompilation -XX:TieredStopAtLevel=1'"
- echo $HOME

jdk:
- openjdk7
Expand Down
1 change: 1 addition & 0 deletions BUILDING.md
Expand Up @@ -6,6 +6,7 @@ Prerequisites:
* A Java 7-compatible (or higher) Java development kit (JDK)
* Maven 3+
* Apache Ant 1.8+ (see https://github.com/jruby/jruby/issues/2236)
* make and a C++ compiler for installing the jruby-launcher gem

JRuby uses Maven for building and bootstrapping itself, along with Rake,
RSpec, and MSpec for running integration tests.
Expand Down
35 changes: 6 additions & 29 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1715,23 +1715,6 @@ public Operand buildDefs(DefsNode node, IRScope s) { // Class method
return new Symbol(method.getName());
}

protected int receiveOptArgs(final ArgsNode argsNode, IRScope s, int opt, int argIndex) {
ListNode optArgs = argsNode.getOptArgs();
for (int j = 0; j < opt; j++, argIndex++) {
// Jump to 'l' if this arg is not null. If null, fall through and build the default value!
Label l = s.getNewLabel();
LocalAsgnNode n = (LocalAsgnNode)optArgs.get(j);
String argName = n.getName();
Variable av = s.getLocalVariable(argName, 0);
if (s instanceof IRMethod) ((IRMethod)s).addArgDesc(IRMethodArgs.ArgType.opt, argName);
addInstr(s, new ReceiveOptArgInstr(av, argIndex-j, argIndex-j, j));
addInstr(s, BNEInstr.create(av, UndefinedValue.UNDEFINED, l)); // if 'av' is not undefined, go to default
build(n, s);
addInstr(s, new LabelInstr(l));
}
return argIndex;
}

protected LocalVariable getArgVariable(IRScope s, String name, int depth) {
// For non-loops, this name will override any name that exists in outer scopes
return s instanceof IRFor ? s.getLocalVariable(name, depth) : s.getNewLocalVariable(name, 0);
Expand Down Expand Up @@ -2041,17 +2024,6 @@ public void receiveBlockArgs(final IterNode node, IRScope s) {
}
}

public String buildType(Node typeNode) {
switch (typeNode.getNodeType()) {
case CONSTNODE:
return ((ConstNode)typeNode).getName();
case SYMBOLNODE:
return ((SymbolNode)typeNode).getName();
default:
return "unknown_type";
}
}

public Operand buildDot(final DotNode dotNode, IRScope s) {
Variable res = s.createTemporaryVariable();
addInstr(s, new BuildRangeInstr(res, build(dotNode.getBeginNode(), s), build(dotNode.getEndNode(), s), dotNode.isExclusive()));
Expand Down Expand Up @@ -3510,7 +3482,12 @@ private Operand[] adjustVariableDepth(Operand[] args, int depthFromSuper) {
Operand[] newArgs = new Operand[args.length];

for (int i = 0; i < args.length; i++) {
newArgs[i] = ((DepthCloneable) args[i]).cloneForDepth(depthFromSuper);
// Because of keyword args, we can have a keyword-arg hash in the call args.
if (args[i] instanceof Hash) {
newArgs[i] = ((Hash) args[i]).cloneForLVarDepth(depthFromSuper);
} else {
newArgs[i] = ((DepthCloneable) args[i]).cloneForDepth(depthFromSuper);
}
}

return newArgs;
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/Hash.java
Expand Up @@ -71,6 +71,14 @@ public void addUsedVariables(List<Variable> l) {
}
}

public Operand cloneForLVarDepth(int newDepth) {
List<KeyValuePair<Operand, Operand>> newPairs = new java.util.ArrayList<KeyValuePair<Operand, Operand>>();
for (KeyValuePair<Operand, Operand> pair : pairs) {
newPairs.add(new KeyValuePair(pair.getKey(), ((DepthCloneable) pair.getValue()).cloneForDepth(newDepth)));
}
return new Hash(newPairs, isKWArgsHash);
}

@Override
public Operand cloneForInlining(CloneInfo ii) {
if (hasKnownValue())
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Expand Up @@ -173,15 +173,20 @@ public Node newline_node(Node node, ISourcePosition position) {
return node instanceof NewlineNode ? node : new NewlineNode(position, node);
}

public Node addRootNode(Node topOfAST, ISourcePosition position) {
position = topOfAST != null ? topOfAST.getPosition() : position;

public Node addRootNode(Node topOfAST) {
if (result.getBeginNodes().isEmpty()) {
if (topOfAST == null) topOfAST = NilImplicitNode.NIL;
ISourcePosition position;
if (topOfAST == null) {
topOfAST = NilImplicitNode.NIL;
position = lexer.getPosition();
} else {
position = topOfAST.getPosition();
}

return new RootNode(position, result.getScope(), topOfAST);
}


ISourcePosition position = topOfAST != null ? topOfAST.getPosition() : result.getBeginNodes().get(0).getPosition();
BlockNode newTopOfAST = new BlockNode(position);
for (Node beginNode: result.getBeginNodes()) {
appendToBlock(newTopOfAST, beginNode);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/parser/RubyParser.java
Expand Up @@ -44,6 +44,7 @@
import org.jruby.ast.BlockNode;
import org.jruby.ast.BlockPassNode;
import org.jruby.ast.BreakNode;
import org.jruby.ast.CallNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarNode;
import org.jruby.ast.ClassVarAsgnNode;
Expand Down Expand Up @@ -1694,7 +1695,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
support.checkUselessStatement(((Node)yyVals[0+yyTop]));
}
}
support.getResult().setAST(support.addRootNode(((Node)yyVals[0+yyTop]), support.getPosition(((Node)yyVals[0+yyTop]))));
support.getResult().setAST(support.addRootNode(((Node)yyVals[0+yyTop])));
return yyVal;
}
};
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Expand Up @@ -309,7 +309,7 @@ program : {
support.checkUselessStatement($2);
}
}
support.getResult().setAST(support.addRootNode($2, support.getPosition($2)));
support.getResult().setAST(support.addRootNode($2));
}

top_compstmt : top_stmts opt_terms {
Expand Down Expand Up @@ -2099,7 +2099,7 @@ var_ref : /*mri:user_variable*/ tIDENTIFIER {
support.getConfiguration().getRuntime().getEncodingService().getLocaleEncoding()));
}
| k__LINE__ {
$$ = new FixnumNode(lexer.getPosition(), lexer.tokline.getStartLine()+1);
$$ = new FixnumNode(lexer.getPosition(), lexer.tokline.getLine()+1);
}
| k__ENCODING__ {
$$ = new EncodingNode(lexer.getPosition(), lexer.getEncoding());
Expand Down
194 changes: 162 additions & 32 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Expand Up @@ -10,6 +10,7 @@
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
Expand Down Expand Up @@ -214,68 +215,197 @@ public static void notDesignedForCompilation() {
CompilerAsserts.neverPartOfCompilation();
}

public static boolean isNil(Object o) {
return o instanceof RubyNilClass;
public boolean isTrue(boolean value) {
return value;
}

public static boolean isTrue(boolean b) {
return b;
public RubyBignum bignum(int value) {
return bignum((long) value);
}

public static boolean isModule(RubyBasicObject o) {
return o instanceof RubyModule;
public RubyBignum bignum(long value) {
return bignum(BigInteger.valueOf(value));
}

public static boolean isArray(Object o) {
return o instanceof RubyArray;
public RubyBignum bignum(BigInteger value) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), value);
}

public static boolean isFixnum(Object o) {
return o instanceof Integer || o instanceof Long;
// Copied from RubyTypesGen

@SuppressWarnings("static-method")
public boolean isDispatchAction(Object value) {
return value instanceof Dispatch.DispatchAction;
}

public static boolean isBignum(Object o) {
return o instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isLexicalScope(Object value) {
return value instanceof LexicalScope;
}

public static boolean isFloat(Object o) {
return o instanceof Double;
@SuppressWarnings("static-method")
public boolean isUndefinedPlaceholder(Object value) {
return value instanceof UndefinedPlaceholder;
}

public static boolean isFirstFixnum(Object o) {
return o instanceof Integer || o instanceof Long;
@SuppressWarnings("static-method")
public boolean isBoolean(Object value) {
return value instanceof Boolean;
}

public static boolean isFirstBignum(Object o) {
return o instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isInteger(Object value) {
return value instanceof Integer;
}

public static boolean isFirstFloat(Object o) {
return o instanceof Double;
@SuppressWarnings("static-method")
public boolean isLong(Object value) {
return value instanceof Long;
}

public static boolean isSecondFixnum(Object a, Object b) {
return b instanceof Integer || b instanceof Long;
@SuppressWarnings("static-method")
public boolean isDouble(Object value) {
return value instanceof Double;
}

public static boolean isSecondBignum(Object a, Object b) {
return b instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isString(Object value) {
return value instanceof String;
}

public static boolean isSecondFloat(Object a, Object b) {
return b instanceof Double;
@SuppressWarnings("static-method")
public boolean isRubyBignum(Object value) {
return value instanceof RubyBignum;
}

public RubyBignum bignum(int value) {
return bignum((long) value);
@SuppressWarnings("static-method")
public boolean isIntegerFixnumRange(Object value) {
return value instanceof RubyRange.IntegerFixnumRange;
}

public RubyBignum bignum(long value) {
return bignum(BigInteger.valueOf(value));
@SuppressWarnings("static-method")
public boolean isLongFixnumRange(Object value) {
return value instanceof RubyRange.LongFixnumRange;
}

public RubyBignum bignum(BigInteger value) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), value);
@SuppressWarnings("static-method")
public boolean isObjectRange(Object value) {
return value instanceof RubyRange.ObjectRange;
}

@SuppressWarnings("static-method")
public boolean isRubyArray(Object value) {
return value instanceof RubyArray;
}

@SuppressWarnings("static-method")
public boolean isRubyBinding(Object value) {
return value instanceof RubyBinding;
}

@SuppressWarnings("static-method")
public boolean isRubyClass(Object value) {
return value instanceof RubyClass;
}

@SuppressWarnings("static-method")
public boolean isRubyException(Object value) {
return value instanceof RubyException;
}

@SuppressWarnings("static-method")
public boolean isRubyFiber(Object value) {
return value instanceof RubyFiber;
}

@SuppressWarnings("static-method")
public boolean isRubyFile(Object value) {
return value instanceof RubyFile;
}

@SuppressWarnings("static-method")
public boolean isRubyHash(Object value) {
return value instanceof RubyHash;
}

@SuppressWarnings("static-method")
public boolean isRubyMatchData(Object value) {
return value instanceof RubyMatchData;
}

@SuppressWarnings("static-method")
public boolean isRubyModule(Object value) {
return value instanceof RubyModule;
}

@SuppressWarnings("static-method")
public boolean isRubyNilClass(Object value) {
return value instanceof RubyNilClass;
}

@SuppressWarnings("static-method")
public boolean isRubyProc(Object value) {
return value instanceof RubyProc;
}

@SuppressWarnings("static-method")
public boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

@SuppressWarnings("static-method")
public boolean isRubyRegexp(Object value) {
return value instanceof RubyRegexp;
}

@SuppressWarnings("static-method")
public boolean isRubyString(Object value) {
return value instanceof RubyString;
}

@SuppressWarnings("static-method")
public boolean isRubyEncoding(Object value) {
return value instanceof RubyEncoding;
}

@SuppressWarnings("static-method")
public boolean isRubySymbol(Object value) {
return value instanceof RubySymbol;
}

@SuppressWarnings("static-method")
public boolean isRubyThread(Object value) {
return value instanceof RubyThread;
}

@SuppressWarnings("static-method")
public boolean isRubyTime(Object value) {
return value instanceof RubyTime;
}

@SuppressWarnings("static-method")
public boolean isRubiniusChannel(Object value) {
return value instanceof RubiniusChannel;
}

@SuppressWarnings("static-method")
public boolean isRubiniusByteArray(Object value) {
return value instanceof RubiniusByteArray;
}

@SuppressWarnings("static-method")
public boolean isRubyEncodingConverter(Object value) {
return value instanceof RubyEncodingConverter;
}

@SuppressWarnings("static-method")
public boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
}

@SuppressWarnings("static-method")
public boolean isObjectArray(Object value) {
return value instanceof Object[];
}

}

0 comments on commit 13285c6

Please sign in to comment.