diff graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TypeSystemTest.java @ 11195:4f52b08bd2f9

Truffle-DSL: Implemented specialization grouping for generic cases.
author Christian Humer <christian.humer@gmail.com>
date Thu, 01 Aug 2013 20:53:54 +0200
parents 79041ab43660
children d6a5ab791b0d
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TypeSystemTest.java	Thu Aug 01 20:53:05 2013 +0200
+++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TypeSystemTest.java	Thu Aug 01 20:53:54 2013 +0200
@@ -32,6 +32,22 @@
 
     @TypeSystem({int.class, boolean.class, String.class, Str.class, CallTarget.class, Object[].class})
     static class SimpleTypes {
+
+        static int intCheck;
+        static int intCast;
+
+        @TypeCheck
+        public boolean isInteger(Object value) {
+            intCheck++;
+            return value instanceof Integer;
+        }
+
+        @TypeCast
+        public int asInteger(Object value) {
+            intCast++;
+            return (int) value;
+        }
+
     }
 
     @TypeSystemReference(SimpleTypes.class)
@@ -126,6 +142,16 @@
             return frame.getArguments(TestArguments.class).get(index);
         }
 
+        @Override
+        public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
+            // avoid casts for some tests
+            Object o = frame.getArguments(TestArguments.class).get(index);
+            if (o instanceof Integer) {
+                return (int) o;
+            }
+            throw new UnexpectedResultException(o);
+        }
+
     }
 
 }