changeset 8596:6ef9fc7375c7

Updated codegen tests for guards and builtins.
author Christian Humer <christian.humer@gmail.com>
date Mon, 01 Apr 2013 21:43:39 +0200
parents 8a1115c92271
children 19978b870b5f
files graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryNodeTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryOperationTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/GuardsTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/RuntimeStringTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TestHelper.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TypeSystemTest.java graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/package-info.java
diffstat 8 files changed, 538 insertions(+), 253 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryNodeTest.java	Mon Apr 01 21:43:39 2013 +0200
@@ -0,0 +1,98 @@
+/*
+ * 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.test;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.codegen.*;
+import com.oracle.truffle.api.codegen.test.BinaryNodeTestFactory.AddNodeFactory;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode;
+
+import static junit.framework.Assert.*;
+import static com.oracle.truffle.api.codegen.test.TestHelper.*;
+
+public class BinaryNodeTest {
+
+    @Test
+    public void testAdd() {
+        TestRootNode<AddNode> node = create(AddNodeFactory.getInstance());
+        assertEquals(42, executeWith(node, 19, 23));
+        assertEquals(42d, executeWith(node, 19d, 23d));
+        assertEquals(42d, executeWith(node, "19", "23"));
+        assertEquals(42, executeWith(node, 19, 23));
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testAddUnsupported() {
+        TestRootNode<AddNode> node = create(AddNodeFactory.getInstance());
+        executeWith(node, new Object(), new Object());
+    }
+
+    abstract static class BinaryNode extends ValueNode {
+
+        @Child protected ValueNode leftNode;
+        @Child protected ValueNode rightNode;
+
+        public BinaryNode(ValueNode left, ValueNode right) {
+            this.leftNode = left;
+            this.rightNode = right;
+        }
+
+        public BinaryNode(BinaryNode prev) {
+            this(prev.leftNode, prev.rightNode);
+        }
+    }
+
+    abstract static class AddNode extends BinaryNode {
+
+        public AddNode(ValueNode left, ValueNode right) {
+            super(left, right);
+        }
+
+        public AddNode(AddNode prev) {
+            super(prev);
+        }
+
+        @Specialization
+        int add(int left, int right) {
+            return left + right;
+        }
+
+        @Generic
+        Object add(Object left, Object right) {
+            return convertDouble(left) + convertDouble(right);
+        }
+
+        static double convertDouble(Object value) {
+            if (value instanceof Number) {
+                return ((Number) value).doubleValue();
+            } else if (value instanceof String) {
+                return Double.parseDouble((String) value);
+            }
+            throw new RuntimeException("Invalid datatype");
+        }
+
+    }
+
+}
--- a/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryOperationTest.java	Mon Apr 01 21:43:20 2013 +0200
+++ /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.api.codegen.test;
-
-import com.oracle.truffle.api.codegen.*;
-import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode;
-
-public class BinaryOperationTest {
-
-    static int convertInt(Object value) {
-        if (value instanceof Number) {
-            return ((Number) value).intValue();
-        } else if (value instanceof String) {
-            return Integer.parseInt((String) value);
-        }
-        throw new RuntimeException("Invalid datatype");
-    }
-
-    @NodeClass(BinaryNode.class)
-    abstract static class BinaryNode extends ValueNode {
-
-        @Child protected ValueNode leftNode;
-        @Child protected ValueNode rightNode;
-
-        public BinaryNode(ValueNode left, ValueNode right) {
-            this.leftNode = left;
-            this.rightNode = right;
-        }
-
-        public BinaryNode(BinaryNode prev) {
-            this(prev.leftNode, prev.rightNode);
-        }
-
-        @Specialization
-        int add(int left, int right) {
-            return left + right;
-        }
-
-        @Generic
-        int add(Object left, Object right) {
-            return convertInt(left) + convertInt(right);
-        }
-
-        @Specialization
-        int sub(int left, int right) {
-            return left + right;
-        }
-
-        @Generic
-        int sub(Object left, Object right) {
-            return convertInt(left) + convertInt(right);
-        }
-
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinTest.java	Mon Apr 01 21:43:39 2013 +0200
@@ -0,0 +1,188 @@
+/*
+ * 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.test;
+
+import static com.oracle.truffle.api.codegen.test.TestHelper.*;
+import static junit.framework.Assert.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.codegen.*;
+import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrAccessContextFactory;
+import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrConcatFactory;
+import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrLengthFactory;
+import com.oracle.truffle.api.codegen.test.BuiltinTestFactory.StrFactory.StrSubstrFactory;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.ChildrenNode;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode;
+
+public class BuiltinTest {
+
+    @Test
+    public void testConcat() {
+        TestRootNode<BuiltinNode> node = create(StrConcatFactory.getInstance(), new Context());
+        Str str1 = new Str("42");
+        Str str2 = new Str(" is the number.");
+        assertEquals(str1.concat(str2), executeWith(node, str1, str2));
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testConcatUnsupported() {
+        TestRootNode<BuiltinNode> node = create(StrConcatFactory.getInstance(), new Context());
+        executeWith(node, 42, new Str(" is the number."));
+    }
+
+    @Test
+    public void testSubstrSpecialized() {
+        TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context());
+        Str str = new Str("test 42");
+
+        assertEquals(str.substr(5, 7), executeWith(node, str, 5, 7));
+    }
+
+    @Test
+    public void testSubstrGeneric() {
+        TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context());
+        Str str = new Str("test 42");
+
+        assertEquals(Str.substr(str, "5", "7"), executeWith(node, str, "5", "7"));
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testSubstrUnsupported() {
+        TestRootNode<BuiltinNode> node = create(StrSubstrFactory.getInstance(), new Context());
+        executeWith(node, new Object(), "5", "7");
+    }
+
+    @Test
+    public void testLength() {
+        TestRootNode<BuiltinNode> node = create(StrLengthFactory.getInstance(), new Context());
+        Str testStr = new Str("test 42");
+        assertEquals(testStr.length(), executeWith(node, testStr));
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testLengthUnsupported() {
+        TestRootNode<BuiltinNode> node = create(StrLengthFactory.getInstance(), new Context());
+        executeWith(node, new Object());
+    }
+
+    @Test
+    public void testAccessContext() {
+        Context context = new Context();
+        TestRootNode<BuiltinNode> node = create(StrAccessContextFactory.getInstance(), context);
+        // accessible by node
+        assertSame(context, node.getNode().getContext());
+        // accessible by execution
+        assertSame(context, executeWith(node));
+    }
+
+    @NodeClass(BuiltinNode.class)
+    static class Str {
+
+        private final String internal;
+
+        public Str(String internal) {
+            this.internal = internal;
+        }
+
+        @Specialization
+        Str concat(Str s1) {
+            return new Str(internal + s1.internal);
+        }
+
+        @Specialization
+        Str substr(int beginIndex, int endIndex) {
+            return new Str(internal.substring(beginIndex, endIndex));
+        }
+
+        @Generic
+        static Str substr(Object thisValue, Object beginIndex, Object endIndex) {
+            if (!(thisValue instanceof Str)) {
+                throw new UnsupportedOperationException();
+            }
+            return ((Str) thisValue).substr(convertInt(beginIndex), convertInt(endIndex));
+        }
+
+        @Specialization
+        int length() {
+            return internal.length();
+        }
+
+        @Specialization
+        static Object accessContext(Context context) {
+            return context;
+        }
+
+        static int convertInt(Object value) {
+            if (value instanceof Number) {
+                return ((Number) value).intValue();
+            } else if (value instanceof String) {
+                return Integer.parseInt((String) value);
+            }
+            throw new RuntimeException("Invalid datatype");
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof Str) {
+                return internal.equals(((Str) obj).internal);
+            }
+            return super.equals(obj);
+        }
+
+        @Override
+        public String toString() {
+            return internal;
+        }
+
+        @Override
+        public int hashCode() {
+            return internal.hashCode();
+        }
+    }
+
+    abstract static class BuiltinNode extends ChildrenNode {
+
+        protected final Context context;
+
+        public BuiltinNode(BuiltinNode node) {
+            this(node.context, node.children);
+        }
+
+        public BuiltinNode(Context context, ValueNode... children) {
+            super(children);
+            this.context = context;
+        }
+
+        public Context getContext() {
+            return context;
+        }
+
+    }
+
+    static class Context {
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/GuardsTest.java	Mon Apr 01 21:43:39 2013 +0200
@@ -0,0 +1,125 @@
+/*
+ * 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.test;
+
+import static com.oracle.truffle.api.codegen.test.TestHelper.*;
+import static junit.framework.Assert.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.codegen.*;
+import com.oracle.truffle.api.codegen.test.GuardsTestFactory.GlobalFlagGuardFactory;
+import com.oracle.truffle.api.codegen.test.GuardsTestFactory.InvocationGuardFactory;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.ChildrenNode;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode;
+
+@SuppressWarnings("unused")
+public class GuardsTest {
+
+    private static final Object NULL = new Object();
+
+    @Test
+    public void testGuardInvocations() {
+        TestRootNode<InvocationGuard> root = create(InvocationGuardFactory.getInstance());
+
+        assertEquals(Integer.MAX_VALUE, executeWith(root, Integer.MAX_VALUE - 1, 1));
+        assertEquals(1, InvocationGuard.specializedInvocations);
+        assertEquals(0, InvocationGuard.genericInvocations);
+
+        assertEquals(42, executeWith(root, Integer.MAX_VALUE, 1));
+        assertEquals(1, InvocationGuard.specializedInvocations);
+        assertEquals(1, InvocationGuard.genericInvocations);
+    }
+
+    public abstract static class InvocationGuard extends ChildrenNode {
+
+        static int specializedInvocations = 0;
+        static int genericInvocations = 0;
+
+        public InvocationGuard(ValueNode... children) {
+            super(children);
+        }
+
+        public InvocationGuard(InvocationGuard node) {
+            super(node);
+        }
+
+        boolean guard(int value0, int value1) {
+            return value0 != Integer.MAX_VALUE;
+        }
+
+        @Specialization(guards = "guard")
+        int doSpecialized(int value0, int value1) {
+            specializedInvocations++;
+            return value0 + value1;
+        }
+
+        @Generic
+        int doGeneric(Object value0, Object value1) {
+            genericInvocations++;
+            return 42; // the generic answer to all questions
+        }
+    }
+
+    @Test
+    public void testGuardGlobal() {
+        TestRootNode<GlobalFlagGuard> root = create(GlobalFlagGuardFactory.getInstance());
+
+        assertEquals(42, executeWith(root, NULL));
+
+        GlobalFlagGuard.globalFlag = true;
+        assertEquals(41, executeWith(root, NULL));
+
+        GlobalFlagGuard.globalFlag = false;
+        assertEquals(42, executeWith(root, NULL));
+    }
+
+    public abstract static class GlobalFlagGuard extends ChildrenNode {
+
+        static boolean globalFlag = false;
+
+        public GlobalFlagGuard(ValueNode... children) {
+            super(children);
+        }
+
+        public GlobalFlagGuard(GlobalFlagGuard node) {
+            super(node);
+        }
+
+        static boolean globalFlagGuard() {
+            return globalFlag;
+        }
+
+        @Specialization(guards = "globalFlagGuard")
+        int doSpecialized(Object value0) {
+            return 41;
+        }
+
+        @Generic
+        int doGeneric(Object value0) {
+            return 42; // the generic answer to all questions
+        }
+    }
+
+}
--- a/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/RuntimeStringTest.java	Mon Apr 01 21:43:20 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +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.test;
-
-import org.junit.*;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.codegen.*;
-import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode;
-import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode;
-
-public class RuntimeStringTest {
-
-    @Test
-    public void testSubstr() {
-        executeAndAssert(new RuntimeString("es"), "substr", new RuntimeString("test"), 1, 3);
-    }
-
-    @Test
-    public void testConcat() {
-        executeAndAssert(new RuntimeString("concatconcat"), "concat", new RuntimeString("concat"), new RuntimeString("concat"));
-    }
-
-    @Test(expected = ArrayIndexOutOfBoundsException.class)
-    public void testConcatFail() {
-        executeAndAssert(new RuntimeString("concatconcat"), "concat", new RuntimeString("concat"));
-    }
-
-    @Test
-    public void testFindMethodByMethodName() {
-        // TODO
-    }
-
-    private static void executeAndAssert(Object expectedResult, String name, Object... argumentsArray) {
-        ArgNode[] args = new ArgNode[argumentsArray.length];
-        for (int i = 0; i < args.length; i++) {
-            args[i] = new ArgNode(argumentsArray, i);
-        }
-
-        BuiltinNode node = null;
-        for (NodeFactory<BuiltinNode> nodeFactory : RuntimeStringTestFactory.getFactories()) {
-            GeneratedBy generated = nodeFactory.getClass().getAnnotation(GeneratedBy.class);
-            Assert.assertNotNull(generated);
-            Assert.assertNotSame("", generated.methodName());
-            if (generated.methodName().equals(name)) {
-                node = nodeFactory.createNode((Object) args);
-                break;
-            }
-        }
-        Assert.assertNotNull("Node not found", node);
-        CallTarget target = Truffle.getRuntime().createCallTarget(new TestRootNode(node));
-        Assert.assertEquals(expectedResult, target.call());
-    }
-
-    static class ArgNode extends ValueNode {
-
-        final Object[] arguments;
-        final int index;
-
-        ArgNode(Object[] args, int index) {
-            this.arguments = args;
-            this.index = index;
-        }
-
-        @Override
-        public Object execute() {
-            return arguments[index];
-        }
-
-    }
-
-    abstract static class BuiltinNode extends ValueNode {
-
-        @Children ArgNode[] parameters;
-
-        BuiltinNode(ArgNode[] parameters) {
-            this.parameters = adoptChildren(parameters);
-        }
-
-        BuiltinNode(BuiltinNode prev) {
-            this(prev.parameters);
-        }
-
-    }
-
-    @NodeClass(BuiltinNode.class)
-    static class RuntimeString {
-
-        private final String internal;
-
-        public RuntimeString(String internal) {
-            this.internal = internal;
-        }
-
-        @Specialization
-        static RuntimeString concat(RuntimeString s1, RuntimeString s2) {
-            return new RuntimeString(s1.internal + s2.internal);
-        }
-
-        @Specialization
-        RuntimeString substr(int beginIndex, int endIndex) {
-            return new RuntimeString(internal.substring(beginIndex, endIndex));
-        }
-
-        @Generic
-        RuntimeString substr(Object beginIndex, Object endIndex) {
-            return substr(convertInt(beginIndex), convertInt(endIndex));
-        }
-
-        static int convertInt(Object value) {
-            if (value instanceof Number) {
-                return ((Number) value).intValue();
-            } else if (value instanceof String) {
-                return Integer.parseInt((String) value);
-            }
-            throw new RuntimeException("Invalid datatype");
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj instanceof RuntimeString) {
-                return internal.equals(((RuntimeString) obj).internal);
-            }
-            return super.equals(obj);
-        }
-
-        @Override
-        public int hashCode() {
-            return internal.hashCode();
-        }
-
-        @Override
-        public String toString() {
-            return internal;
-        }
-
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TestHelper.java	Mon Apr 01 21:43:39 2013 +0200
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 2013, 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.test;
+
+import java.util.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.codegen.*;
+import com.oracle.truffle.api.codegen.test.TypeSystemTest.*;
+
+/**
+ * Utility class to provide some test helper functions.
+ */
+class TestHelper {
+
+    private static ArgumentNode[] arguments(int count) {
+        ArgumentNode[] nodes = new ArgumentNode[count];
+        for (int i = 0; i < nodes.length; i++) {
+            nodes[i] = new ArgumentNode(i);
+        }
+        return nodes;
+    }
+
+    static <E extends ValueNode> TestRootNode<E> create(NodeFactory<E> factory, Object... constants) {
+        ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size());
+
+        List<Object> argumentList = new ArrayList<>();
+        argumentList.addAll(Arrays.asList(constants));
+        if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass())) {
+            argumentList.add(argumentNodes);
+        } else {
+            argumentList.addAll(Arrays.asList(argumentNodes));
+        }
+        return new TestRootNode<>(factory.createNode(argumentList.toArray(new Object[argumentList.size()])));
+    }
+
+    static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) {
+        return Truffle.getRuntime().createCallTarget(node).call(new TestArguments(values));
+    }
+
+}
--- a/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TypeSystemTest.java	Mon Apr 01 21:43:20 2013 +0200
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TypeSystemTest.java	Mon Apr 01 21:43:39 2013 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -22,49 +22,97 @@
  */
 package com.oracle.truffle.api.codegen.test;
 
+import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.codegen.*;
-import com.oracle.truffle.api.codegen.test.RuntimeStringTest.RuntimeString;
+import com.oracle.truffle.api.codegen.test.BuiltinTest.Str;
 import com.oracle.truffle.api.frame.*;
 import com.oracle.truffle.api.nodes.*;
 
 public class TypeSystemTest {
 
-    @TypeSystem({int.class, RuntimeString.class})
+    @TypeSystem({int.class, Str.class})
     static class SimpleTypes {
     }
 
     @TypeSystemReference(SimpleTypes.class)
     abstract static class ValueNode extends Node {
 
-        int executeInt() throws UnexpectedResultException {
-            return SimpleTypesGen.SIMPLETYPES.expectInteger(execute());
+        int executeInt(VirtualFrame frame) throws UnexpectedResultException {
+            return SimpleTypesGen.SIMPLETYPES.expectInteger(execute(frame));
         }
 
-        RuntimeString executeString() {
-            return new RuntimeString(execute().toString());
+        Str executeStr(VirtualFrame frame) throws UnexpectedResultException {
+            return SimpleTypesGen.SIMPLETYPES.expectStr(execute(frame));
         }
 
-        @SuppressWarnings("static-method")
-        final long executeSpecial() {
-            return 42L;
-        }
-
-        abstract Object execute();
+        abstract Object execute(VirtualFrame frame);
     }
 
     @TypeSystemReference(SimpleTypes.class)
-    static class TestRootNode extends RootNode {
+    abstract static class ChildrenNode extends ValueNode {
+
+        @Children protected ValueNode[] children;
+
+        public ChildrenNode(ValueNode... children) {
+            this.children = adoptChildren(children);
+        }
 
-        @Child private ValueNode node;
+        public ChildrenNode(ChildrenNode node) {
+            this(node.children);
+        }
+
+    }
 
-        public TestRootNode(ValueNode node) {
+    @TypeSystemReference(SimpleTypes.class)
+    static class TestRootNode<E extends ValueNode> extends RootNode {
+
+        @Child private E node;
+
+        public TestRootNode(E node) {
             this.node = adoptChild(node);
         }
 
         @Override
         public Object execute(VirtualFrame frame) {
-            return node.execute();
+            return node.execute(frame);
+        }
+
+        public E getNode() {
+            return node;
         }
     }
 
+    static class TestArguments extends Arguments {
+
+        private final Object[] values;
+
+        public TestArguments(Object... values) {
+            this.values = values;
+        }
+
+        public Object[] getValues() {
+            return values;
+        }
+
+        public Object get(int index) {
+            return values[index];
+        }
+
+    }
+
+    static class ArgumentNode extends ValueNode {
+
+        final int index;
+
+        public ArgumentNode(int index) {
+            this.index = index;
+        }
+
+        @Override
+        Object execute(VirtualFrame frame) {
+            return ((TestArguments) frame.getArguments()).get(index);
+        }
+
+    }
+
 }
--- a/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/package-info.java	Mon Apr 01 21:43:20 2013 +0200
+++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/package-info.java	Mon Apr 01 21:43:39 2013 +0200
@@ -41,7 +41,7 @@
  *
  * <ul>
  * <li>What do I need to get started? {@link com.oracle.truffle.api.codegen.test.TypeSystemTest}</li>
- * <li>How would you generate function nodes for runtime objects? {@link com.oracle.truffle.api.codegen.test.RuntimeStringTest}</li>
+ * <li>How would you generate function nodes for runtime objects? {@link com.oracle.truffle.api.codegen.test.BuiltinTest}</li>
  * </ul>
  * </p>
  *