diff truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/MaxMinObject.java @ 22046:e7c2d36daf72

TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 30 Jul 2015 17:36:34 +0200
parents 5bc7f7b867ab
children 78c3d3d8d86e
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/MaxMinObject.java	Thu Jul 30 17:16:59 2015 +0200
+++ b/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/MaxMinObject.java	Thu Jul 30 17:36:34 2015 +0200
@@ -47,16 +47,10 @@
 
     @Override
     public ForeignAccess getForeignAccess() {
-        return ForeignAccess.create(MaxMinObject.class, new AF(max));
+        return ForeignAccess.create(MaxMinObject.class, new AF());
     }
 
     static final class AF implements ForeignAccess.Factory10 {
-        private final boolean max;
-
-        public AF(boolean max) {
-            this.max = max;
-        }
-
         @Override
         public CallTarget accessIsNull() {
             return null;
@@ -100,7 +94,7 @@
         @Override
         public CallTarget accessExecute(int argumentsLength) {
             if (argumentsLength == 2) {
-                MaxMinNode maxNode = MaxMinObjectFactory.MaxMinNodeGen.create(max, MaxMinObjectFactory.UnboxNodeGen.create(new ReadArgNode(0)),
+                MaxMinNode maxNode = MaxMinObjectFactory.MaxMinNodeGen.create(new ReadReceiverNode(), MaxMinObjectFactory.UnboxNodeGen.create(new ReadArgNode(0)),
                                 MaxMinObjectFactory.UnboxNodeGen.create(new ReadArgNode(1)));
                 return Truffle.getRuntime().createCallTarget(maxNode);
             }
@@ -130,6 +124,12 @@
         }
     }
 
+    static class ReadReceiverNode extends Node {
+        public Object execute(VirtualFrame frame) {
+            return ForeignAccess.getReceiver(frame);
+        }
+    }
+
     @NodeChildren({@NodeChild(value = "valueNode", type = ReadArgNode.class)})
     abstract static class UnboxNode extends Node {
         @Child private Node unbox;
@@ -171,28 +171,26 @@
 
     }
 
-    @NodeChildren({@NodeChild(value = "firstNode", type = UnboxNode.class), @NodeChild(value = "secondNode", type = UnboxNode.class)})
+    @NodeChildren({@NodeChild(value = "receiver", type = ReadReceiverNode.class), @NodeChild(value = "firstNode", type = UnboxNode.class), @NodeChild(value = "secondNode", type = UnboxNode.class)})
     abstract static class MaxMinNode extends RootNode {
-        private final boolean max;
 
-        MaxMinNode(boolean max) {
+        MaxMinNode() {
             super(MMLanguage.class, null, null);
-            this.max = max;
         }
 
         @Specialization
-        public int execute(int first, int second) {
-            return max ? Math.max(first, second) : Math.min(first, second);
+        public int execute(MaxMinObject receiver, int first, int second) {
+            return receiver.max ? Math.max(first, second) : Math.min(first, second);
         }
 
         @Specialization
-        public long execute(long first, long second) {
-            return max ? Math.max(first, second) : Math.min(first, second);
+        public long execute(MaxMinObject receiver, long first, long second) {
+            return receiver.max ? Math.max(first, second) : Math.min(first, second);
         }
 
         @Specialization
-        public double execute(double first, double second) {
-            return max ? Math.max(first, second) : Math.min(first, second);
+        public double execute(MaxMinObject receiver, double first, double second) {
+            return receiver.max ? Math.max(first, second) : Math.min(first, second);
         }
     }