diff graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java @ 18776:c0fb70634640

Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 01:31:08 +0100
parents a069a87b9a02
children ae827362559d
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java	Mon Jan 05 01:31:08 2015 +0100
+++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java	Mon Jan 05 01:31:08 2015 +0100
@@ -23,26 +23,28 @@
 package com.oracle.truffle.api.dsl.test;
 
 import com.oracle.truffle.api.dsl.*;
+import com.oracle.truffle.api.dsl.internal.*;
+import com.oracle.truffle.api.frame.*;
 import com.oracle.truffle.api.nodes.*;
 
 public class ExecuteMethodTest {
 
-    private static final String NO_EXECUTE = "No accessible and overridable generic execute method found. Generic execute methods usually have the signature 'public abstract {Type} "
-                    + "executeGeneric(VirtualFrame)' and must not throw any checked exceptions.";
+    private static final String ERROR_NO_EXECUTE = "No accessible and overridable generic execute method found. Generic execute methods usually have the signature 'public abstract {Type} "
+                    + "execute(VirtualFrame)' and must not throw any checked exceptions.";
 
-    @TypeSystem({int.class, Object[].class})
-    static class ExecuteTypeSystem {
-
+    @TypeSystem({int.class})
+    @DSLOptions(useNewLayout = true)
+    static class ExecuteMethodTypes {
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    abstract static class ValidChildNode extends Node {
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    abstract static class ChildNoFrame extends Node {
         abstract Object execute();
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
-    @ExpectError(NO_EXECUTE)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError(ERROR_NO_EXECUTE)
     abstract static class ExecuteThis1 extends Node {
 
         @Specialization
@@ -51,9 +53,9 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
-    @ExpectError(NO_EXECUTE)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError(ERROR_NO_EXECUTE)
     abstract static class ExecuteThis2 extends Node {
 
         abstract Object execute() throws UnexpectedResultException;
@@ -64,9 +66,9 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
-    @ExpectError(NO_EXECUTE)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError(ERROR_NO_EXECUTE)
     abstract static class ExecuteThis3 extends Node {
 
         abstract int execute() throws UnexpectedResultException;
@@ -77,8 +79,8 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
     abstract static class ExecuteThis4 extends Node {
 
         protected abstract Object execute();
@@ -89,8 +91,8 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
     abstract static class ExecuteThis5 extends Node {
 
         public abstract Object execute();
@@ -101,9 +103,9 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
-    @ExpectError(NO_EXECUTE)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError(ERROR_NO_EXECUTE)
     abstract static class ExecuteThis6 extends Node {
 
         @SuppressWarnings({"unused", "static-method"})
@@ -117,9 +119,9 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
-    @ExpectError(NO_EXECUTE)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError(ERROR_NO_EXECUTE)
     abstract static class ExecuteThis7 extends Node {
 
         @SuppressWarnings("static-method")
@@ -133,8 +135,8 @@
         }
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
     @ExpectError("Multiple accessible and overridable generic execute methods found [executeInt(), executeObject()]. Remove all but one or mark all but one as final.")
     abstract static class ExecuteThis8 extends Node {
 
@@ -149,8 +151,8 @@
 
     }
 
-    @TypeSystemReference(ExecuteTypeSystem.class)
-    @NodeChild(value = "a", type = ValidChildNode.class)
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
     abstract static class ExecuteThis9 extends Node {
 
         abstract int executeInt();
@@ -166,4 +168,270 @@
         }
     }
 
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteThisVoid1 extends Node {
+
+        abstract void executeVoid();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteThisVoid2 extends Node {
+
+        // allow one execute void
+        abstract void executeVoid();
+
+        abstract Object executeObject();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError("Multiple accessible and overridable generic execute methods found [executeObject(), executeVoid1(), executeVoid2()]. Remove all but one or mark all but one as final.")
+    abstract static class ExecuteThisVoid3 extends Node {
+
+        // allow only one execute void
+        abstract void executeVoid1();
+
+        abstract void executeVoid2();
+
+        abstract Object executeObject();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrame1 extends Node {
+
+        // no frame in execute. no parameter in specializations
+        abstract Object executeNoFrame();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrame2 extends Node {
+
+        // frame in execute also usable in specialization
+        abstract Object executeWithFrame(VirtualFrame frame);
+
+        @Specialization
+        int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrame3 extends Node {
+
+        abstract Object executeWithFrame(Frame frame);
+
+        @Specialization
+        int doInt(@SuppressWarnings("unused") Frame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ExecuteWithFrame4.class)
+    abstract static class ExecuteWithFrame4 extends Node {
+
+        abstract Object executeWithFrame(MaterializedFrame frame);
+
+        @Specialization
+        int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrameError1 extends Node {
+
+        abstract Object executeNoFrame();
+
+        @Specialization
+        @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
+        int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrameError2 extends Node {
+
+        abstract Object executeFrame(MaterializedFrame frame);
+
+        @Specialization
+        @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
+        int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteWithFrameError3 extends Node {
+
+        abstract Object executeFrame(VirtualFrame frame);
+
+        @Specialization
+        @ExpectError("Method signature (MaterializedFrame, int) does not match to the expected signature:%")
+        int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError("Invalid inconsistent frame types [MaterializedFrame, VirtualFrame] found for the declared execute methods.%")
+    abstract static class ExecuteWithFrameError4 extends Node {
+
+        abstract Object execute(VirtualFrame frame);
+
+        abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    @ExpectError("Invalid inconsistent frame types [MaterializedFrame, void] found for the declared execute methods.%")
+    abstract static class ExecuteWithFrameError5 extends Node {
+
+        abstract Object execute();
+
+        abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    abstract static class ChildVirtualFrame extends Node {
+        abstract Object execute(VirtualFrame frame);
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    abstract static class ChildMaterializedFrame extends Node {
+        abstract Object execute(MaterializedFrame frame);
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    abstract static class ChildFrame extends Node {
+        abstract Object execute(Frame frame);
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildNoFrame.class)
+    abstract static class ExecuteChildFrame1 extends Node {
+
+        abstract Object execute(VirtualFrame frame);
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildFrame.class)
+    abstract static class ExecuteChildFrame2 extends Node {
+
+        abstract Object execute(VirtualFrame frame);
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildFrame.class)
+    abstract static class ExecuteChildFrame3 extends Node {
+
+        abstract Object execute(MaterializedFrame frame);
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildFrame.class)
+    abstract static class ExecuteChildFrame4 extends Node {
+
+        abstract Object execute(Frame frame);
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [com.oracle.truffle.api.frame.Frame].")
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildVirtualFrame.class)
+    abstract static class ExecuteChildFrameError1 extends Node {
+
+        abstract Object execute(Frame frame);
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildFrame and frame types [].")
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildFrame.class)
+    abstract static class ExecuteChildFrameError2 extends Node {
+
+        abstract Object execute();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
+    @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [].")
+    @TypeSystemReference(ExecuteMethodTypes.class)
+    @NodeChild(value = "a", type = ChildVirtualFrame.class)
+    abstract static class ExecuteChildFrameError3 extends Node {
+
+        abstract Object execute();
+
+        @Specialization
+        int doInt(int a) {
+            return a;
+        }
+    }
+
 }