# HG changeset patch # User Christian Humer # Date 1358512154 -3600 # Node ID 31da1716950f681fbb811b46df6eef4f5e4fc2b2 # Parent 6343a09b2ec1ca840c4967ee4b4e186d02af1e4f Updated truffle-sl for the changed operation code generation. diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.test; + +import org.junit.*; + +public class DivTest extends AbstractTest { + + private static String[] INPUT = new String[] { +"function main { ", +" print 4 / 2; ", +" print 4 / 4000000000000; ", +" print 3000000000000 / 3; ", +" print 3000000000000 / 3000000000000; ", +"} ", + }; + + private static String[] OUTPUT = new String[] { +"2", +"0", +"1000000000000", +"1", + }; + + @Test + public void test() { + executeSL(INPUT, OUTPUT, true); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.test; + +import org.junit.*; + +public class SubTest extends AbstractTest { + + private static String[] INPUT = new String[] { +"function main { ", +" print 3 - 4; ", +" print 3 - 4000000000000; ", +" print 3000000000000 - 4; ", +" print 3000000000000 - 4000000000000; ", +"} ", + }; + + private static String[] OUTPUT = new String[] { +"-1", +"-3999999999997", +"2999999999996", +"-1000000000000", + }; + + @Test + public void test() { + executeSL(INPUT, OUTPUT, true); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java Fri Jan 18 13:29:14 2013 +0100 @@ -30,8 +30,8 @@ "function main { ", " i = 0; ", " sum = 0; ", -" while (i < 1000) { ", -" sum = sum + 100000000; ", +" while (i < 100000) { ", +" sum = sum + 1000000; ", " i = i + 1; ", " } ", " return sum; ", diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java Fri Jan 18 13:29:14 2013 +0100 @@ -28,8 +28,7 @@ import com.oracle.truffle.api.frame.*; import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.ops.*; -import com.oracle.truffle.sl.types.*; +import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.*; public class NodeFactory { @@ -49,7 +48,7 @@ } public void startFunction() { - frameDescriptor = new FrameDescriptor(TypesGen.TYPES); + frameDescriptor = new FrameDescriptor(SLTypesGen.SLTYPES); } public void createFunction(StatementNode body, String name) { @@ -57,19 +56,28 @@ } public TypedNode createLocal(String name) { - return ReadLocalOpFactory.create(frameDescriptor.findOrAddFrameSlot(name)); + return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name)); } public TypedNode createStringLiteral(String value) { - return StringLiteralFactory.create(value); + return StringLiteralNodeFactory.create(value); } public StatementNode createAssignment(String name, TypedNode right) { - return WriteLocalOpFactory.create(right, frameDescriptor.findOrAddFrameSlot(name)); + return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name), right); } public StatementNode createPrint(List expressions) { - return new PrintNode(expressions, printOutput); + if (expressions.size() >= 1) { + StatementNode[] nodes = new StatementNode[expressions.size() + 1]; + for (int i = 0; i < expressions.size(); i++) { + nodes[i] = PrintNodeFactory.create(expressions.get(i), printOutput); + } + nodes[expressions.size()] = new PrintLineNode(printOutput); + return new BlockNode(nodes); + } else { + return new BlockNode(new StatementNode[]{new PrintLineNode(printOutput)}); + } } public StatementNode createWhile(ConditionNode condition, StatementNode body) { @@ -83,13 +91,17 @@ public TypedNode createBinary(String operation, TypedNode left, TypedNode right) { switch (operation) { case "+": - return AddOpFactory.create(left, right); + return AddNodeFactory.create(left, right); case "*": - return MulOpFactory.create(left, right); + return MulNodeFactory.create(left, right); + case "/": + return DivNodeFactory.create(left, right); + case "-": + return SubNodeFactory.create(left, right); case "<": - return LessThanOpFactory.create(left, right); + return LessThanNodeFactory.create(left, right); case "&&": - return LogicalAndOpFactory.create(left, right); + return LogicalAndNodeFactory.create(left, right); default: throw new RuntimeException("unexpected operation: " + operation); } @@ -97,22 +109,22 @@ public TypedNode createNumericLiteral(String value) { try { - return IntegerLiteralFactory.create(Integer.parseInt(value)); + return IntegerLiteralNodeFactory.create(Integer.parseInt(value)); } catch (NumberFormatException ex) { - return BigIntegerLiteralFactory.create(new BigInteger(value)); + return BigIntegerLiteralNodeFactory.create(new BigInteger(value)); } } public TypedNode createTime() { - return TimeOpFactory.create(); + return TimeNodeFactory.create(); } public StatementNode createReturn(TypedNode value) { FrameSlot slot = frameDescriptor.findOrAddFrameSlot(""); if (returnValue == null) { - returnValue = ReadLocalOpFactory.create(slot); + returnValue = ReadLocalNodeFactory.create(slot); } - StatementNode write = WriteLocalOpFactory.create(value, slot); + StatementNode write = WriteLocalNodeFactory.create(slot, value); return new ReturnNode(write); } } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.nodes.*; + +@TypeSystemReference(SLTypes.class) +public class SLNode extends Node { + + @Override + public String toString() { + return NodeUtil.printTreeToString(this); + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLTypes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLTypes.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; + +@TypeSystem({int.class, BigInteger.class, boolean.class, String.class}) +public class SLTypes { + + @TypeCheck + public boolean isInteger(Object value) { + return value instanceof Integer || (value instanceof BigInteger && ((BigInteger) value).bitLength() < Integer.SIZE); + } + + @TypeCast + public int asInteger(Object value) { + assert isInteger(value); + if (value instanceof Integer) { + return (int) value; + } else { + int result = ((BigInteger) value).intValue(); + assert BigInteger.valueOf(result).equals(value) : "Loosing precision"; + return result; + } + } + + @TypeCheck + public boolean isBigInteger(Object value) { + return value instanceof Integer || value instanceof BigInteger; + } + + @TypeCast + public BigInteger asBigInteger(Object value) { + if (value instanceof Integer) { + return BigInteger.valueOf((int) value); + } else { + return (BigInteger) value; + } + } + + @TypeCast + public BigInteger asBigInteger(int value) { + return BigInteger.valueOf(value); + } + + @TypeCheck + public boolean isBigInteger(@SuppressWarnings("unused") int value) { + return true; + } +} + diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SimpleLanguage.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SimpleLanguage.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SimpleLanguage.java Fri Jan 18 13:29:14 2013 +0100 @@ -25,9 +25,9 @@ import java.io.*; import com.oracle.truffle.api.*; +import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.sl.nodes.*; import com.oracle.truffle.sl.parser.*; -import com.oracle.truffle.sl.tools.*; public class SimpleLanguage { @@ -45,7 +45,7 @@ FunctionDefinitionNode rootNode = factory.findFunction("main"); if (log) { - GraphPrinter.print(rootNode); + NodeUtil.printTree(System.out, rootNode); } try { @@ -67,7 +67,7 @@ } finally { if (log) { - GraphPrinter.print(rootNode); + NodeUtil.printTree(System.out, rootNode); } } } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.intrinsics.*; + +public abstract class ArithmeticNode extends BinaryNode { + + public ArithmeticNode(TypedNode left, TypedNode right) { + super(left, right); + } + + protected ArithmeticNode(ArithmeticNode node) { + super(node); + } + + @Generic + public Object doGeneric(Object left, Object right) { + throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); + } + + public abstract static class AddNode extends ArithmeticNode { + public AddNode(TypedNode left, TypedNode right) { + super(left, right); + } + protected AddNode(AddNode node) { + super(node); + } + + @Specialization + @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") + int doInteger(int left, int right) { + return ExactMath.addExact(left, right); + } + + @Specialization + BigInteger doBigInteger(BigInteger left, BigInteger right) { + return left.add(right); + } + + @Specialization + String doStringDirect(String left, String right) { + return left + right; + } + + @Specialization + @SpecializationGuard(methodName = "isString") + String doString(Object left, Object right) { + return left.toString() + right.toString(); + } + } + + public abstract static class SubNode extends ArithmeticNode { + public SubNode(TypedNode left, TypedNode right) { + super(left, right); + } + protected SubNode(SubNode node) { + super(node); + } + + @Specialization + @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") + int doInteger(int left, int right) { + return ExactMath.subtractExact(left, right); + } + + @Specialization + BigInteger doBigInteger(BigInteger left, BigInteger right) { + return left.subtract(right); + } + } + + public abstract static class DivNode extends ArithmeticNode { + public DivNode(TypedNode left, TypedNode right) { + super(left, right); + } + protected DivNode(DivNode node) { + super(node); + } + + @Specialization + @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") + int doInteger(int left, int right) { + return left / right; + } + + @Specialization + BigInteger doBigInteger(BigInteger left, BigInteger right) { + return left.divide(right); + } + } + + public abstract static class MulNode extends ArithmeticNode { + + public MulNode(TypedNode left, TypedNode right) { + super(left, right); + } + protected MulNode(MulNode node) { + super(node); + } + + @Specialization + @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") + int doInteger(int left, int right) { + return ExactMath.multiplyExact(left, right); + } + + @Specialization + BigInteger doBigInteger(BigInteger left, BigInteger right) { + return left.multiply(right); + } + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; + +public abstract class BigIntegerLiteralNode extends TypedNode { + + private final BigInteger value; + + public BigIntegerLiteralNode(BigInteger value) { + this.value = value; + } + + @Specialization + public BigInteger doBigInteger() { + return value; + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BinaryNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BinaryNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.codegen.*; + +@ExecuteChildren({"leftNode", "rightNode"}) +public abstract class BinaryNode extends TypedNode { + + @Child + protected TypedNode leftNode; + + @Child + protected TypedNode rightNode; + + public BinaryNode(TypedNode left, TypedNode right) { + this.leftNode = adoptChild(left); + this.rightNode = adoptChild(right); + } + + public BinaryNode(BinaryNode node) { + this(node.leftNode, node.rightNode); + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -27,4 +27,5 @@ public abstract class ConditionNode extends StatementNode { public abstract boolean executeCondition(VirtualFrame frame); + } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionalNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; + +@SuppressWarnings("unused") +@ExecuteChildren({"conditionNode", "ifPartNode", "elsePartNode"}) +public abstract class ConditionalNode extends TypedNode { + + @Child + protected ConditionNode conditionNode; + + @Child + protected TypedNode ifPartNode; + + @Child + protected TypedNode elsePartNode; + + public ConditionalNode(ConditionNode condition, TypedNode ifPart, TypedNode elsePart) { + this.conditionNode = adoptChild(condition); + this.ifPartNode = adoptChild(ifPart); + this.elsePartNode = adoptChild(elsePart); + } + + public ConditionalNode(ConditionalNode condition) { + this(condition.conditionNode, condition.ifPartNode, condition.elsePartNode); + } + + @ShortCircuit("ifPartNode") + public boolean needsIfPart(boolean condition) { + return condition; + } + + @ShortCircuit("ifPartNode") + public boolean needsIfPart(Object condition) { + throw new RuntimeException("operation not defined for type " + condition.getClass().getSimpleName()); + } + + @ShortCircuit("elsePartNode") + public boolean needsElsePart(Object condition, boolean hasIfPart, Object ifPart) { + return !hasIfPart; + } + + @ShortCircuit("elsePartNode") + public boolean needsElsePart(boolean condition, boolean hasIfPart, int ifPart) { + return !hasIfPart; + } + + @ShortCircuit("elsePartNode") + public boolean needsElsePart(boolean condition, boolean hasIfPart, BigInteger ifPart) { + return !hasIfPart; + } + + @Specialization + public int doInteger(boolean condition, boolean hasIfPart, int ifPart, boolean hasElsePart, int elsePart) { + return hasIfPart ? ifPart : elsePart; + } + + @Specialization + public BigInteger doBigInteger(boolean condition, boolean hasIfPart, BigInteger ifPart, boolean hasElsePart, BigInteger elsePart) { + return hasIfPart ? ifPart : elsePart; + } + + @Generic + public Object doGeneric(boolean condition, boolean hasIfPart, Object ifPart, boolean hasElsePart, Object elsePart) { + return hasIfPart ? ifPart : elsePart; + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FrameSlotNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FrameSlotNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.frame.*; + +public abstract class FrameSlotNode extends TypedNode implements FrameSlotTypeListener { + + protected final FrameSlot slot; + + public FrameSlotNode(FrameSlot slot) { + this.slot = slot; + slot.registerOneShotTypeListener(this); + } + + @Override + public void typeChanged(FrameSlot changedSlot, Class< ? > oldType) { + if (getParent() != null) { + replace(specialize(changedSlot.getType())); + } + } + + protected abstract FrameSlotNode specialize(Class< ? > clazz); +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionDefinitionNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionDefinitionNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionDefinitionNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -24,16 +24,17 @@ import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.types.*; public class FunctionDefinitionNode extends RootNode { + @Child + private StatementNode body; + + @Child + private TypedNode returnValue; + private final FrameDescriptor frameDescriptor; private final String name; - @Child - private StatementNode body; - @Child - private TypedNode returnValue; public FunctionDefinitionNode(StatementNode body, FrameDescriptor frameDescriptor, String name, TypedNode returnValue) { this.body = adoptChild(body); @@ -42,6 +43,7 @@ this.returnValue = adoptChild(returnValue); } + @Override public Object execute(VirtualFrame frame) { try { diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IfNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IfNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IfNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -22,29 +22,38 @@ */ package com.oracle.truffle.sl.nodes; +import com.oracle.truffle.api.codegen.*; import com.oracle.truffle.api.frame.*; -public class IfNode extends StatementNode { +@ExecuteChildren("conditionNode") +public abstract class IfNode extends StatementNode { @Child - private ConditionNode condition; + protected ConditionNode conditionNode; + @Child - private StatementNode thenPart; + private StatementNode thenPartNode; + @Child - private StatementNode elsePart; + private StatementNode elsePartNode; public IfNode(ConditionNode condition, StatementNode thenPart, StatementNode elsePart) { - this.condition = adoptChild(condition); - this.thenPart = adoptChild(thenPart); - this.elsePart = adoptChild(elsePart); + this.conditionNode = adoptChild(condition); + this.thenPartNode = adoptChild(thenPart); + this.elsePartNode = adoptChild(elsePart); + } + + protected IfNode(IfNode node) { + this(node.conditionNode, node.thenPartNode, node.elsePartNode); } - @Override - public void executeVoid(VirtualFrame frame) { - if (condition.executeCondition(frame)) { - thenPart.executeVoid(frame); - } else if (elsePart != null) { - elsePart.executeVoid(frame); + @Specialization + public void doVoid(VirtualFrame frame, boolean condition) { + if (condition) { + thenPartNode.executeVoid(frame); + } else { + elsePartNode.executeVoid(frame); } } + } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.codegen.*; + +public abstract class IntegerLiteralNode extends TypedNode { + + private final int value; + + public IntegerLiteralNode(int value) { + this.value = value; + } + + @Specialization + protected int doInteger() { + return this.value; + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; + +public abstract class LessThanNode extends BinaryNode { + + public LessThanNode(TypedNode left, TypedNode right) { + super(left, right); + } + + public LessThanNode(LessThanNode node) { + this(node.leftNode, node.rightNode); + } + + @Specialization + public boolean doInteger(int left, int right) { + return left < right; + } + + @Specialization + public boolean doBigInteger(BigInteger left, BigInteger right) { + return left.compareTo(right) < 0; + } + + @Specialization + @SpecializationGuard(methodName = "isString") + public boolean doString(Object left, Object right) { + return left.toString().compareTo(right.toString()) < 0; + } + + @Generic + public boolean doGeneric(Object left, Object right) { + throw new RuntimeException("comparison not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LogicalAndNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LogicalAndNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.codegen.*; + +@SuppressWarnings("unused") +public abstract class LogicalAndNode extends BinaryNode { + + public LogicalAndNode(TypedNode leftNode, TypedNode rightNode) { + super(leftNode, rightNode); + } + + public LogicalAndNode(LogicalAndNode node) { + this(node.leftNode, node.rightNode); + } + + @ShortCircuit("rightNode") + public boolean needsRightNode(boolean left) { + return left; + } + + @ShortCircuit("rightNode") + public boolean needsRightNode(Object left) { + return left instanceof Boolean && (Boolean) left; + } + + @Specialization + public boolean doBoolean(boolean left, boolean hasRight, boolean right) { + return hasRight && right; + } + + @Generic + public Object doGeneric(Object left, boolean hasRight, Object right) { + throw new RuntimeException("operation not defined for type " + left.getClass().getSimpleName()); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/PrintLineNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/PrintLineNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.io.*; + +import com.oracle.truffle.api.frame.*; + +public class PrintLineNode extends StatementNode { + + private final PrintStream output; + + public PrintLineNode(PrintStream output) { + this.output = output; + } + + @Override + public void executeVoid(VirtualFrame frame) { + output.println(); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/PrintNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/PrintNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/PrintNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -23,30 +23,42 @@ package com.oracle.truffle.sl.nodes; import java.io.*; -import java.util.*; + +import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.types.*; +public abstract class PrintNode extends StatementNode { -public class PrintNode extends StatementNode { - - @Children - private final TypedNode[] expressions; + @Child + protected TypedNode expression; private final PrintStream output; - public PrintNode(List expressions, PrintStream output) { - this.expressions = adoptChildren(expressions.toArray(new TypedNode[expressions.size()])); + public PrintNode(TypedNode expression, PrintStream output) { + this.expression = adoptChild(expression); this.output = output; } - @ExplodeLoop - @Override - public void executeVoid(VirtualFrame frame) { - for (TypedNode expression : expressions) { - output.print(expression.executeGeneric(frame)); - } - output.println(); + public PrintNode(PrintNode node) { + this(node.expression, node.output); + } + + @Specialization + public void doInt(int value) { + output.print(value); + } + + @Specialization + public void doBoolean(boolean value) { + output.print(value); + } + + @Specialization + public void doString(String value) { + output.print(value); + } + + @Generic + public void doGeneric(Object value) { + output.print(value.toString()); } } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadLocalNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.frame.*; + +public abstract class ReadLocalNode extends FrameSlotNode { + + public ReadLocalNode(FrameSlot slot) { + super(slot); + } + + public ReadLocalNode(ReadLocalNode specialized) { + this(specialized.slot); + } + + @Specialization + public int doInteger(VirtualFrame frame) { + return frame.getInt(slot); + } + + @Specialization + public BigInteger doBigInteger(VirtualFrame frame) { + return (BigInteger) frame.getObject(slot); + } + + @Specialization + public boolean doBoolean(VirtualFrame frame) { + return frame.getBoolean(slot); + } + + @Specialization + public String doString(VirtualFrame frame) { + return (String) frame.getObject(slot); + } + + @Generic + public Object doGeneric(VirtualFrame frame) { + return frame.getObject(slot); + } + + @Override + protected FrameSlotNode specialize(Class< ? > clazz) { + return ReadLocalNodeFactory.createSpecialized(this, clazz); + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StatementNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StatementNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StatementNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -23,9 +23,10 @@ package com.oracle.truffle.sl.nodes; import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.*; -public abstract class StatementNode extends Node { +public abstract class StatementNode extends SLNode { public abstract void executeVoid(VirtualFrame frame); + } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.codegen.*; + +public abstract class StringLiteralNode extends TypedNode { + + private final String value; + + public StringLiteralNode(String value) { + this.value = value; + } + + @Specialization + protected String doString() { + return value; + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TimeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TimeNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import com.oracle.truffle.api.codegen.*; + +public abstract class TimeNode extends TypedNode { + + public static final long START_TIME = System.currentTimeMillis(); + + @Specialization + public int doInt() { + return (int) (System.currentTimeMillis() - START_TIME); + } +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; + +public abstract class TypedNode extends ConditionNode { + + @Override + public final boolean executeCondition(VirtualFrame frame) { + try { + return executeBoolean(frame); + } catch (UnexpectedResultException ex) { + throw new RuntimeException("Illegal type for condition: " + ex.getResult().getClass().getSimpleName()); + } + } + + public abstract boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException; + + public abstract int executeInteger(VirtualFrame frame) throws UnexpectedResultException; + + public abstract BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException; + + public abstract String executeString(VirtualFrame frame) throws UnexpectedResultException; + + public abstract Object executeGeneric(VirtualFrame frame); + + @GuardCheck + public boolean isString(Object a, Object b) { + return a instanceof String || b instanceof String; + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -28,6 +28,7 @@ @Child private ConditionNode condition; + @Child private StatementNode body; diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java Fri Jan 18 13:29:14 2013 +0100 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.frame.*; + +public abstract class WriteLocalNode extends FrameSlotNode { + + @Child protected TypedNode rightNode; + + public WriteLocalNode(FrameSlot slot, TypedNode right) { + super(slot); + this.rightNode = adoptChild(right); + } + + public WriteLocalNode(WriteLocalNode node) { + this(node.slot, node.rightNode); + } + + @Specialization + public int doInteger(VirtualFrame frame, int right) { + frame.setInt(slot, right); + return right; + } + + @Specialization + public BigInteger doBigInteger(VirtualFrame frame, BigInteger right) { + frame.setObject(slot, right); + return right; + } + + @Specialization + public boolean doBoolean(VirtualFrame frame, boolean right) { + frame.setBoolean(slot, right); + return right; + } + + @Specialization + public String doString(VirtualFrame frame, String right) { + frame.setObject(slot, right); + return right; + } + + @Generic + public Object doGeneric(VirtualFrame frame, Object right) { + frame.setObject(slot, right); + return right; + } + + @SpecializationListener + protected void onSpecialize(VirtualFrame frame, Object value) { + slot.setType(value.getClass()); + frame.updateToLatestVersion(); + } + + @Override + protected FrameSlotNode specialize(Class< ? > clazz) { + return WriteLocalNodeFactory.createSpecialized(this, clazz); + } + +} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/AddOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/AddOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.intrinsics.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, values = {"left", "right"}) -public class AddOp { - - @Specialization - @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") - public int doInteger(int left, int right) { - return ExactMath.addExact(left, right); - } - - @Specialization - public BigInteger doBigInteger(BigInteger left, BigInteger right) { - return left.add(right); - } - - @Specialization - public String doStringDirect(String left, String right) { - return left + right; - } - - @Specialization - @SpecializationGuard(methodName = "isString") - public String doString(Object left, Object right) { - return left.toString() + right.toString(); - } - - @Generic - public Object doGeneric(Object left, Object right) { - throw new RuntimeException("addition not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/BigIntegerLiteral.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/BigIntegerLiteral.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class) -public class BigIntegerLiteral { - - private final BigInteger value; - - public BigIntegerLiteral(BigInteger value) { - this.value = value; - } - - @Specialization - public BigInteger doBigInteger() { - return value; - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/IfOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/IfOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@SuppressWarnings("unused") -@Operation(typeSystem = Types.class, values = {"condition"}, shortCircuitValues = {"ifPart", "elsePart"}) -public class IfOp { - - @ShortCircuit("ifPart") - public boolean needsIfPart(boolean condition) { - return condition; - } - - @ShortCircuit("ifPart") - public boolean needsIfPart(Object condition) { - if (TypesGen.TYPES.isBoolean(condition)) { - return TypesGen.TYPES.asBoolean(condition); - } - throw new RuntimeException("operation not defined for type " + condition.getClass().getSimpleName()); - } - - @ShortCircuit("elsePart") - public boolean needsElsePart(Object condition, boolean hasIfPart, Object ifPart) { - return !hasIfPart; - } - - @ShortCircuit("elsePart") - public boolean needsElsePart(boolean condition, boolean hasIfPart, int ifPart) { - return !hasIfPart; - } - - @ShortCircuit("elsePart") - public boolean needsElsePart(boolean condition, boolean hasIfPart, BigInteger ifPart) { - return !hasIfPart; - } - - @Specialization - public int doInteger(boolean condition, boolean hasIfPart, int ifPart, boolean hasElsePart, int elsePart) { - return hasIfPart ? ifPart : elsePart; - } - - @Specialization - public BigInteger doBigInteger(boolean condition, boolean hasIfPart, BigInteger ifPart, boolean hasElsePart, BigInteger elsePart) { - return hasIfPart ? ifPart : elsePart; - } - - @Generic - public Object doGeneric(Object condition, boolean hasIfPart, Object ifPart, boolean hasElsePart, Object elsePart) { - return hasIfPart ? ifPart : elsePart; - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/IntegerLiteral.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/IntegerLiteral.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class) -public class IntegerLiteral { - - private final int value; - - public IntegerLiteral(int value) { - this.value = value; - } - - @Specialization - protected int doInteger() { - return this.value; - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/LessThanOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/LessThanOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, values = {"left", "right"}) -public class LessThanOp { - - @Specialization - public boolean doInteger(int left, int right) { - return left < right; - } - - @Specialization - public boolean doBigInteger(BigInteger left, BigInteger right) { - return left.compareTo(right) < 0; - } - - @Specialization - @SpecializationGuard(methodName = "isString") - public boolean doString(Object left, Object right) { - return left.toString().compareTo(right.toString()) < 0; - } - - @Generic - public boolean doGeneric(Object left, Object right) { - throw new RuntimeException("comparison not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/LogicalAndOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/LogicalAndOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@SuppressWarnings("unused") -@Operation(typeSystem = Types.class, values = {"left"}, shortCircuitValues = {"right"}) -public class LogicalAndOp { - - @ShortCircuit(value = "right") - public boolean needsRight(boolean left) { - return left; - } - - @ShortCircuit(value = "right") - public boolean needsRight(Object left) { - return TypesGen.TYPES.asBoolean(left); - } - - @Specialization - public boolean doBoolean(boolean left, boolean hasRight, boolean right) { - return hasRight && right; - } - - @Generic - public Object doGeneric(Object left, boolean hasRight, Object right) { - throw new RuntimeException("operation not defined for type " + left.getClass().getSimpleName()); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/MulOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/MulOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.intrinsics.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, values = {"left", "right"}) -public class MulOp { - - @Specialization - @SpecializationThrows(javaClass = ArithmeticException.class, transitionTo = "doBigInteger") - public int doInteger(int left, int right) { - return ExactMath.multiplyExact(left, right); - } - - @Specialization - public BigInteger doBigInteger(BigInteger left, BigInteger right) { - return left.multiply(right); - } - - @Generic - public Object doGeneric(Object left, Object right) { - throw new RuntimeException("multiplication not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/ReadLocalOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/ReadLocalOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, baseClass = FrameSlotNode.class) -public class ReadLocalOp { - - @Specialization(order = 2) - public int doInteger(VirtualFrame frame, FrameSlot slot) { - return frame.getInt(slot); - } - - @Specialization - public BigInteger doBigInteger(VirtualFrame frame, FrameSlot slot) { - return (BigInteger) frame.getObject(slot); - } - - @Specialization - public boolean doBoolean(VirtualFrame frame, FrameSlot slot) { - return frame.getBoolean(slot); - } - - @Specialization - public String doString(VirtualFrame frame, FrameSlot slot) { - return (String) frame.getObject(slot); - } - - @Generic - public Object doGeneric(VirtualFrame frame, FrameSlot slot) { - return frame.getObject(slot); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/StringLiteral.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/StringLiteral.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class) -public class StringLiteral { - - private final String value; - - public StringLiteral(String value) { - this.value = value; - } - - @Specialization - protected String doString() { - return value; - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/TimeOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/TimeOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, baseClass = TypedNode.class) -public class TimeOp { - - public static final long START_TIME = System.currentTimeMillis(); - - @Specialization - public int doInt() { - return (int) (System.currentTimeMillis() - START_TIME); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/WriteLocalOp.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/ops/WriteLocalOp.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.ops; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.sl.types.*; - -@Operation(typeSystem = Types.class, baseClass = FrameSlotNode.class, values = "right") -public class WriteLocalOp { - - @Specialization - public int doInteger(VirtualFrame frame, int right, FrameSlot slot) { - frame.setInt(slot, right); - return right; - } - - @Specialization - public BigInteger doBigInteger(VirtualFrame frame, BigInteger right, FrameSlot slot) { - frame.setObject(slot, right); - return right; - } - - @Specialization - public boolean doBoolean(VirtualFrame frame, boolean right, FrameSlot slot) { - frame.setBoolean(slot, right); - return right; - } - - @Specialization - public String doString(VirtualFrame frame, String right, FrameSlot slot) { - frame.setObject(slot, right); - return right; - } - - @Generic - public Object doGeneric(VirtualFrame frame, Object right, FrameSlot slot) { - frame.setObject(slot, right); - return right; - } - - @SpecializationListener - protected void onSpecialize(VirtualFrame frame, Object value, FrameSlot slot) { - slot.setType(value.getClass()); - frame.updateToLatestVersion(); - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame Fri Jan 18 13:29:14 2013 +0100 @@ -30,7 +30,6 @@ import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.types.*; // Checkstyle: stop public class Parser { @@ -46,7 +45,7 @@ public final Scanner scanner; public final Errors errors; private final NodeFactory factory; - -->declarations + -->declarations public Parser(Scanner scanner, NodeFactory factory) { this.scanner = scanner; this.factory = factory; diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java Fri Jan 18 13:29:14 2013 +0100 @@ -28,7 +28,6 @@ import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.types.*; // Checkstyle: stop public class Parser { @@ -49,7 +48,7 @@ public final Scanner scanner; public final Errors errors; private final NodeFactory factory; - + public Parser(Scanner scanner, NodeFactory factory) { this.scanner = scanner; this.factory = factory; @@ -129,29 +128,29 @@ void Function() { Expect(4); - factory.startFunction(); + factory.startFunction(); Expect(1); - String name = t.val; + String name = t.val; StatementNode body = Block(); - factory.createFunction(body, name); + factory.createFunction(body, name); } StatementNode Block() { StatementNode result; - List statements = new ArrayList<>(); + List statements = new ArrayList<>(); Expect(5); while (StartOf(1)) { StatementNode statement = Statement(); - statements.add(statement); + statements.add(statement); } Expect(6); - result = factory.createBlock(statements); + result = factory.createBlock(statements); return result; } StatementNode Statement() { StatementNode result; - result = null; + result = null; if (la.kind == 7) { result = WhileStatement(); } else if (la.kind == 1) { @@ -171,31 +170,31 @@ ConditionNode condition = Expression(); Expect(9); StatementNode body = Block(); - result = factory.createWhile(condition, body); + result = factory.createWhile(condition, body); return result; } StatementNode AssignmentStatement() { StatementNode result; Expect(1); - String name = t.val; + String name = t.val; Expect(10); TypedNode rvalue = Expression(); Expect(11); - result = factory.createAssignment(name, rvalue); + result = factory.createAssignment(name, rvalue); return result; } StatementNode OutputStatement() { StatementNode result; - List expressions = new ArrayList<>(); + List expressions = new ArrayList<>(); Expect(12); while (StartOf(2)) { TypedNode value = Expression(); - expressions.add(value); + expressions.add(value); } Expect(11); - result = factory.createPrint(expressions); + result = factory.createPrint(expressions); return result; } @@ -204,7 +203,7 @@ Expect(13); TypedNode value = Expression(); Expect(11); - result = factory.createReturn(value); + result = factory.createReturn(value); return result; } @@ -238,9 +237,9 @@ break; } } - String op = t.val; + String op = t.val; TypedNode right = ValueExpression(); - result = factory.createBinary(op, result, right); + result = factory.createBinary(op, result, right); } return result; } @@ -254,9 +253,9 @@ } else { Get(); } - String op = t.val; + String op = t.val; TypedNode right = Term(); - result = factory.createBinary(op, result, right); + result = factory.createBinary(op, result, right); } return result; } @@ -270,16 +269,16 @@ } else { Get(); } - String op = t.val; + String op = t.val; TypedNode right = Factor(); - result = factory.createBinary(op, result, right); + result = factory.createBinary(op, result, right); } return result; } TypedNode Factor() { TypedNode result; - result = null; + result = null; if (la.kind == 24) { result = TimeRef(); } else if (la.kind == 1) { @@ -299,28 +298,28 @@ TypedNode TimeRef() { TypedNode result; Expect(24); - result = factory.createTime(); + result = factory.createTime(); return result; } TypedNode VariableRef() { TypedNode result; Expect(1); - result = factory.createLocal(t.val); + result = factory.createLocal(t.val); return result; } TypedNode StringLiteral() { TypedNode result; Expect(2); - result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); + result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); return result; } TypedNode NumericLiteral() { TypedNode result; Expect(3); - result = factory.createNumericLiteral(t.val); + result = factory.createNumericLiteral(t.val); return result; } diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.frame --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.frame Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.frame Fri Jan 18 13:29:14 2013 +0100 @@ -403,7 +403,7 @@ NextCh(); } } - + -->comments void CheckLiteral() { @@ -418,7 +418,7 @@ Token NextToken() { while (ch == ' ' || -->scan1 - ) NextCh(); + ) NextCh(); -->scan2 int recKind = noSym; int recEnd = pos; diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Fri Jan 18 13:28:12 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Fri Jan 18 13:29:14 2013 +0100 @@ -28,7 +28,7 @@ = Function { - Function + Function } . @@ -86,7 +86,7 @@ } ";" (. result = factory.createPrint(expressions); .) . - + ReturnStatement = "return" @@ -97,8 +97,8 @@ = ValueExpression [ - ("<" | ">" | "<=" | ">=" | "==" | "!=" ) (. String op = t.val; .) - ValueExpression (. result = factory.createBinary(op, result, right); .) + ("<" | ">" | "<=" | ">=" | "==" | "!=" ) (. String op = t.val; .) + ValueExpression (. result = factory.createBinary(op, result, right); .) ] . diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/tools/GraphPrinter.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/tools/GraphPrinter.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.tools; - -import com.oracle.truffle.api.nodes.*; - -public class GraphPrinter { - - public static void print(Node root) { - print(root, 0); - } - - private static void print(Node node, int level) { - for (int i = 0; i < level; i++) { - System.out.print(" "); - } - System.out.println(node == null ? "empty" : node.getClass().getSimpleName()); - if (node != null) { - for (Node child : node.getChildren()) { - print(child, level + 1); - } - } - } -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/FrameSlotNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/FrameSlotNode.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.types; - -import com.oracle.truffle.api.frame.*; - -public abstract class FrameSlotNode extends TypedNode implements FrameSlotTypeListener { - - protected final FrameSlot slot; - - public FrameSlotNode(FrameSlot slot) { - this.slot = slot; - slot.registerOneShotTypeListener(this); - } - - @Override - public void typeChanged(FrameSlot changedSlot, Class< ? > oldType) { - if (getParent() != null) { - specialize(changedSlot.getType()); - } - } - - protected abstract void specialize(Class< ? > clazz); -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/TypedNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/TypedNode.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.types; - -import java.math.*; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.nodes.*; - -public abstract class TypedNode extends ConditionNode { - - @Override - public final boolean executeCondition(VirtualFrame frame) { - try { - return executeBoolean(frame); - } catch (UnexpectedResultException ex) { - throw new RuntimeException("Illegal type for condition: " + ex.getResult().getClass().getSimpleName()); - } - } - - public abstract boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException; - - public abstract int executeInteger(VirtualFrame frame) throws UnexpectedResultException; - - public abstract BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException; - - public abstract String executeString(VirtualFrame frame) throws UnexpectedResultException; - - public abstract Object executeGeneric(VirtualFrame frame); -} diff -r 6343a09b2ec1 -r 31da1716950f graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/Types.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/types/Types.java Fri Jan 18 13:28:12 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.sl.types; - -import java.math.*; - -import com.oracle.truffle.api.codegen.*; - -@TypeSystem(types = {int.class, BigInteger.class, boolean.class, String.class}, nodeBaseClass = TypedNode.class, hasVoid = true) -public class Types { - - @TypeCheck - public boolean isInteger(Object value) { - return value instanceof Integer || (value instanceof BigInteger && ((BigInteger) value).bitLength() < Integer.SIZE); - } - - @TypeCast - public int asInteger(Object value) { - assert isInteger(value); - if (value instanceof Integer) { - return (int) value; - } else { - int result = ((BigInteger) value).intValue(); - assert BigInteger.valueOf(result).equals(value) : "Loosing precision"; - return result; - } - } - - @GuardCheck - public boolean isString(Object a, Object b) { - return a instanceof String || b instanceof String; - } - - @TypeCheck - public boolean isBigInteger(Object value) { - return value instanceof Integer || value instanceof BigInteger; - } - - @TypeCast - public BigInteger asBigInteger(Object value) { - if (value instanceof Integer) { - return BigInteger.valueOf((int) value); - } else { - return (BigInteger) value; - } - } - - @TypeCast - public BigInteger asBigInteger(int value) { - return BigInteger.valueOf(value); - } - - @TypeCheck - public boolean isBigInteger(@SuppressWarnings("unused") int value) { - return true; - } - -}