# HG changeset patch
# User Christian Humer
Object execute*(VirtualFrame, Object)
.
- */
- String[] executeWith() default {};
-}
diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeChildren.java
--- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeChildren.java Mon Jul 01 20:32:20 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +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.api.codegen;
-
-import java.lang.annotation.*;
-
-@Retention(RetentionPolicy.CLASS)
-@Target({ElementType.TYPE})
-public @interface NodeChildren {
-
- NodeChild[] value() default {};
-
-}
diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeContainer.java
--- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeContainer.java Mon Jul 01 20:32:20 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +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.api.codegen;
-
-import java.lang.annotation.*;
-
-import com.oracle.truffle.api.nodes.*;
-
-/**
- * A node container can be used to enable Truffle-DSL in classes which do not extend {@link Node}.
- * Compared to normal {@link Node} implementation the nodes are not identified by a class but by
- * their method name. There are cases were method signatures are matching exactly but should be in
- * the same {@link Node}. In this case use {@link NodeId} to disambiguate such cases.
- */
-@Retention(RetentionPolicy.CLASS)
-@Target({ElementType.TYPE})
-public @interface NodeContainer {
-
- /** The node class to use as base class for {@link Node} definitions grouped by method names. */
- Class extends Node> value();
-
-}
diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeFactory.java
--- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/NodeFactory.java Mon Jul 01 20:32:20 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +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.api.codegen;
-
-import java.util.*;
-
-import com.oracle.truffle.api.nodes.*;
-
-/**
- * Enables the dynamic creation of generated nodes. It provides an convenient way to instantiate
- * generated node classes without using reflection.
- */
-public interface NodeFactory- * Provides a way to define a custom type check for a defined type. The name of the annotated method - * must fit to the pattern is${typeName} (eg. isInteger), where ${typeName} must be a valid type - * defined in the parent {@link TypeSystem}. The annotated method must have exactly one argument - * where the type of the argument is the generic type {@link Object} or a more specific one from the - * {@link TypeSystem}. You can define multiple overloaded {@link TypeCheck} methods for the same - * type. This can be used to reduce the boxing overhead in type conversions. - *
- * - *- * By default the system generates type checks for all types in the parent {@link TypeSystem} which - * look like the follows: - * - *
- * {@literal @}TypeCheck - * boolean is${typeName}(Object value) { - * return value instanceof ${typeName}; - * } - *- * - * - * - * Example: - *
- * A type check for BigInteger with one overloaded optimized variant to reduce boxing. - *
- * - *- * - * - * {@literal @}TypeSystem(types = {int.class, BigInteger.class, String.class}, nodeBaseClass = TypedNode.class) - * public abstract class Types { - * - * {@literal @}TypeCheck - * public boolean isBigInteger(Object value) { - * return value instanceof Integer || value instanceof BigInteger; - * } - * - * {@literal @}TypeCheck - * public boolean isBigInteger(int value) { - * return true; - * } - * - * } - *- * - * - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD}) -public @interface TypeCheck { - -} diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java Mon Jul 01 20:32:20 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +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.api.codegen; - -import java.lang.annotation.*; - -import com.oracle.truffle.api.nodes.*; - -/** - *
- * Each {@link Node} has one {@link TypeSystem} at its root to define the types that can be used - * throughout the system. Multiple {@link TypeSystem}s are allowed, but they cannot be mixed inside - * a single {@link Node} hierarchy. A {@link TypeSystem} defines a list of types as its child - * elements, in which every type precedes its super types.The latter condition ensures that the most - * concrete type is found first when searching the list sequentially for the type of a given generic - * value. - *
- * - *
- * Each {@link #value()} is represented as a java type. A type can specify two annotations:
- * {@link TypeCheck} and {@link TypeCast}. The {@link TypeCheck} checks whether a given generic
- * value matches to the current type. The {@link TypeCast} casts a generic type value to the current
- * type. If the {@link TypeCheck} and {@link TypeCast} annotations are not declared in the
- * {@link TypeSystem} the a default implementation is provided. The default implementation of
- * {@link TypeCheck} returns true
only on an exact type match and {@link TypeCast} is
- * only a cast to this type. Specified methods with {@link TypeCheck} and {@link TypeCast} may be
- * used to extend the definition of a type in the language. In our example, the
- * isInteger
and asInteger
methods are defined in a way so that they
- * accept also {@link Integer} values, implicitly converting them to {@link Double} . This example
- * points out how we express implicit type conversions.
- *
- * Example: The {@link TypeSystem} contains the types {@link Boolean}, {@link Integer}, and - * {@link Double}. The type {@link Object} is always used implicitly as the generic type represent - * all values. - * - *
- * - * {@literal @}TypeSystem(types = {boolean.class, int.class, double.class}) - * public abstract class ExampleTypeSystem { - * - * {@literal @}TypeCheck - * public boolean isInteger(Object value) { - * return value instanceof Integer || value instanceof Double; - * } - * - * {@literal @}TypeCast - * public double asInteger(Object value) { - * return ((Number)value).doubleValue(); - * } - * } - *- * - * - * - * @see TypeCast - * @see TypeCheck - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.TYPE}) -public @interface TypeSystem { - - /** - * The list of types as child elements of the {@link TypeSystem}. Each precedes its super type. - */ - Class[] value(); - -} diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystemReference.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystemReference.java Mon Jul 01 20:32:20 2013 +0200 +++ /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.api.codegen; - -import java.lang.annotation.*; - -import com.oracle.truffle.api.nodes.*; - -/** - * References a {@link TypeSystem} on a node. Must be applied on a {@link Node} class. At least one - * {@link TypeSystem} must be referenced in a {@link Node}'s type hierarchy. - * - * @see TypeSystem - * @see Node - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.TYPE}) -public @interface TypeSystemReference { - - /** The {@link TypeSystem} java type. */ - Class> value(); - -} diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/AssumptionsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/AssumptionsTest.java Mon Jul 01 20:58:32 2013 +0200 @@ -0,0 +1,139 @@ +/* + * 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.api.dsl.test; + +import org.junit.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.DerivedAssumptionNodeFactory; +import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.DerivedAssumptionRedeclaredNodeFactory; +import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.MultipleAssumptionsNodeFactory; +import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.SingleAssumptionNodeFactory; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; + +public class AssumptionsTest { + + @Test + public void testSingleAssumption() { + Assumption assumption = Truffle.getRuntime().createAssumption(); + TestRootNode> root = TestHelper.createRoot(SingleAssumptionNodeFactory.getInstance(), assumption); + + Assert.assertEquals(42, TestHelper.executeWith(root)); + assumption.invalidate(); + Assert.assertEquals("42", TestHelper.executeWith(root)); + } + + @NodeAssumptions("assumption") + abstract static class SingleAssumptionNode extends ValueNode { + + @Specialization(order = 0, assumptions = "assumption") + int doInt() { + return 42; + } + + @Specialization + Object doObject() { + return "42"; + } + } + + @Test + public void testMultipleAssumption() { + Assumption assumption1 = Truffle.getRuntime().createAssumption(); + Assumption assumption2 = Truffle.getRuntime().createAssumption(); + TestRootNode> root = TestHelper.createRoot(MultipleAssumptionsNodeFactory.getInstance(), assumption1, assumption2); + + Assert.assertEquals(42, TestHelper.executeWith(root)); + assumption2.invalidate(); + Assert.assertEquals("42", TestHelper.executeWith(root)); + assumption1.invalidate(); + Assert.assertEquals("43", TestHelper.executeWith(root)); + } + + @NodeAssumptions({"assumption1", "assumption2"}) + abstract static class MultipleAssumptionsNode extends ValueNode { + + @Specialization(assumptions = {"assumption1", "assumption2"}) + int doInt() { + return 42; + } + + @Specialization(assumptions = "assumption1") + Object doObject() { + return "42"; + } + + @Generic + Object doGeneric() { + return "43"; + } + } + + @Test + public void testDerivedAssumption() { + Assumption additionalAssumption = Truffle.getRuntime().createAssumption(); + Assumption assumption = Truffle.getRuntime().createAssumption(); + TestRootNode> root = TestHelper.createRoot(DerivedAssumptionNodeFactory.getInstance(), assumption, additionalAssumption); + + Assert.assertEquals(42, TestHelper.executeWith(root)); + assumption.invalidate(); + Assert.assertEquals(43, TestHelper.executeWith(root)); + additionalAssumption.invalidate(); + Assert.assertEquals("42", TestHelper.executeWith(root)); + } + + @NodeAssumptions({"additionalAssumption"}) + abstract static class DerivedAssumptionNode extends SingleAssumptionNode { + + @Specialization(order = 1, assumptions = "additionalAssumption") + int doIntDerived() { + return 43; + } + } + + @Test + public void testDerivedAssumptionRedeclared() { + Assumption additionalAssumption = Truffle.getRuntime().createAssumption(); + Assumption assumption = Truffle.getRuntime().createAssumption(); + TestRootNode> root = TestHelper.createRoot(DerivedAssumptionRedeclaredNodeFactory.getInstance(), additionalAssumption, assumption); + + Assert.assertEquals(42, TestHelper.executeWith(root)); + assumption.invalidate(); + Assert.assertEquals(43, TestHelper.executeWith(root)); + additionalAssumption.invalidate(); + Assert.assertEquals("42", TestHelper.executeWith(root)); + } + + @NodeAssumptions({"additionalAssumption", "assumption"}) + abstract static class DerivedAssumptionRedeclaredNode extends SingleAssumptionNode { + + @Specialization(order = 1, assumptions = "additionalAssumption") + int doIntDerived() { + return 43; + } + + } + +} diff -r f43eb2f1bbbc -r 79041ab43660 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/BinaryNodeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/BinaryNodeTest.java Mon Jul 01 20:58:32 2013 +0200 @@ -0,0 +1,79 @@ +/* + * 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.api.dsl.test; + +import static com.oracle.truffle.api.dsl.test.TestHelper.*; +import static org.junit.Assert.*; + +import org.junit.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.dsl.test.BinaryNodeTestFactory.AddNodeFactory; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; + +public class BinaryNodeTest { + + @Test + public void testAdd() { + TestRootNode