changeset 21770:c76742cc2c6f

Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 08 Jun 2015 04:50:13 +0200
parents b6309a7d5a44
children ed3d7af510bd
files graal/com.oracle.truffle.api.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Execute.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccess.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccessArguments.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccessFactory.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignObjectAccessHeadNode.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/GetSize.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/HasSize.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/InteropPredicate.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsBoxed.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsExecutable.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsNull.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/KnownMessage.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Message.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ObjectAccessNode.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Read.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/TruffleObject.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/UnaryMessage.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Unbox.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Write.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/exception/UnsupportedMessageException.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/exception/UnsupportedTypeException.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/ReadOnlyArrayList.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/SymbolInvokerImpl.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/messages/Message.java graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/package-info.java graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/ObjectType.java graal/com.oracle.truffle.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/ForeignAccessArguments.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Argument.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Execute.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/GetSize.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/HasSize.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsBoxed.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsExecutable.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsNull.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/MessageUtil.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Read.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Receiver.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/UnaryMessage.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Unbox.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Write.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessHeadNode.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessNode.java graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ObjectAccessNode.java graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunction.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java mx/suite.py
diffstat 52 files changed, 1610 insertions(+), 1318 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,1 @@
+com.oracle.truffle.api.interop.impl.SymbolInvokerImpl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Execute.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class Execute extends KnownMessage {
+    public static final int HASH1 = 423430;
+    public static final int HASH2 = 423429;
+
+    private final int arity;
+    private final boolean invoke;
+
+    public static Execute create(boolean invoke, int arity) {
+        return new Execute(invoke, arity);
+    }
+
+    private Execute(boolean invoke, int arity) {
+        this.invoke = invoke;
+        this.arity = arity;
+    }
+
+    public int getArity() {
+        return arity;
+    }
+
+    @Override
+    public boolean equals(Object message) {
+        if (!(message instanceof Execute)) {
+            return false;
+        }
+        Execute m1 = this;
+        Execute m2 = (Execute) message;
+        return m1.invoke == m2.invoke;
+    }
+
+    @Override
+    public int hashCode() {
+        return invoke ? HASH1 : HASH2;
+    }
+
+    @Override
+    public String toString() {
+        return invoke ? "msgInvoke" : "msgExecute";
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccess.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+import com.oracle.truffle.api.CallTarget;
+import com.oracle.truffle.api.frame.Frame;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.interop.impl.ReadOnlyArrayList;
+import com.oracle.truffle.api.nodes.Node;
+import java.util.List;
+
+/**
+ * Encapsulates types of access to {@link TruffleObject}. If you want to expose your own objects to
+ * foreign language implementations, you need to implement {@link TruffleObject} and its
+ * {@link TruffleObject#getForeignAccess()} method. To create instance of <code>ForeignAccess</code>
+ * , use one of the factory methods available in this class.
+ */
+public final class ForeignAccess {
+    private final Factory factory;
+
+    private ForeignAccess(Factory faf) {
+        this.factory = faf;
+    }
+
+    /**
+     * Creates new instance of {@link ForeignAccess} that delegates to provided factory.
+     *
+     * @param baseClass the super class of all {@link TruffleObject}s handled by this factory (if
+     *            <code>null</code> than the second interface also needs to implement
+     *            {@link Factory})
+     * @param factory the factory that handles access requests to {@link Message}s known as of
+     *            version 1.0
+     * @return new instance wrapping <code>factory</code>
+     */
+    public static ForeignAccess create(final Class<? extends TruffleObject> baseClass, final Factory10 factory) {
+        if (baseClass == null) {
+            Factory f = (Factory) factory;
+            assert f != null;
+        }
+        class DelegatingFactory implements Factory {
+            @Override
+            public boolean canHandle(TruffleObject obj) {
+                if (baseClass == null) {
+                    return ((Factory) factory).canHandle(obj);
+                }
+                return baseClass.isInstance(obj);
+            }
+
+            @Override
+            public CallTarget accessMessage(Message msg) {
+                if (msg instanceof KnownMessage) {
+                    switch (msg.hashCode()) {
+                        case Execute.HASH1:
+                            return factory.accessInvoke(((Execute) msg).getArity());
+                        case Execute.HASH2:
+                            return factory.accessExecute(((Execute) msg).getArity());
+                        case GetSize.HASH:
+                            return factory.accessGetSize();
+                        case HasSize.HASH:
+                            return factory.accessHasSize();
+                        case IsBoxed.HASH:
+                            return factory.accessIsBoxed();
+                        case IsExecutable.HASH:
+                            return factory.accessIsExecutable();
+                        case IsNull.HASH:
+                            return factory.accessIsNull();
+                        case Read.HASH:
+                            return factory.accessRead();
+                        case Unbox.HASH:
+                            return factory.accessUnbox();
+                        case Write.HASH:
+                            return factory.accessWrite();
+                    }
+                }
+                return factory.accessMessage(msg);
+            }
+        }
+        return new ForeignAccess(new DelegatingFactory());
+    }
+
+    /**
+     * Creates new instance of {@link ForeignAccess} that delegates to provided factory.
+     *
+     * @param factory the factory that handles various access requests {@link Message}s.
+     * @return new instance wrapping <code>factory</code>
+     */
+    public static ForeignAccess create(Factory factory) {
+        return new ForeignAccess(factory);
+    }
+
+    /**
+     * Executes {@link Message#createNode() foreign node}.
+     * 
+     * @param foreignNode the createNode created by {@link Message#createNode()}
+     * @param frame the call frame
+     * @param receiver foreign object to receive the message passed to {@link Message#createNode()}
+     *            method
+     * @param arguments parameters for the receiver
+     * @return return value, if any
+     * @throws ClassCastException if the createNode has not been created by
+     *             {@link Message#createNode()} method.
+     */
+    public static Object execute(Node foreignNode, VirtualFrame frame, TruffleObject receiver, Object... arguments) {
+        ForeignObjectAccessHeadNode fn = (ForeignObjectAccessHeadNode) foreignNode;
+        return fn.executeForeign(frame, receiver, arguments);
+    }
+
+    /**
+     * Read only access to foreign call arguments inside of a frame.
+     *
+     * @param frame the frame that was called via
+     *            {@link #execute(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object...) }
+     * @return read-only list of parameters passed to the frame
+     */
+    public static List<Object> getArguments(Frame frame) {
+        final Object[] arr = frame.getArguments();
+        return ReadOnlyArrayList.asList(arr, 1, arr.length);
+    }
+
+    /**
+     * The foreign receiver in the frame.
+     *
+     * @param frame the frame that was called via
+     *            {@link #execute(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object...) }
+     * @return the receiver used when invoking the frame
+     */
+    public static TruffleObject getReceiver(Frame frame) {
+        return (TruffleObject) frame.getArguments()[ForeignAccessArguments.RECEIVER_INDEX];
+    }
+
+    CallTarget access(Message message) {
+        return factory.accessMessage(message);
+    }
+
+    boolean canHandle(TruffleObject receiver) {
+        return factory.canHandle(receiver);
+    }
+
+    /**
+     * Interface of a factory that produces AST snippets that can access a foreign
+     * {@code TruffleObject}. A Truffle language implementation accesses a {@code TruffleObject} via
+     * a {@code Message}. The {@code TruffleObject} instance provides a {@link ForeignAccess}
+     * instance (built via {@link #create(com.oracle.truffle.api.interop.ForeignAccess.Factory)})
+     * that provides an AST snippet for a given {@link Message}. Rather than using this generic
+     * {@code Factory}, consider implementing {@link Factory10} interface that captures the set of
+     * messages each language should implement as of Truffle version 1.0.
+     */
+    public interface Factory {
+
+        /**
+         * * Checks whether provided {@link TruffleObject} can be accessed using AST snippets
+         * produced by this {@link Factory}.
+         *
+         * @param obj the object to check
+         * @return true, if the object can be processed
+         */
+        boolean canHandle(TruffleObject obj);
+
+        /**
+         * Provides an AST snippet to access a {@code TruffleObject}.
+         *
+         * @param tree the {@code Message} that represents the access to a {@code TruffleObject}.
+         * @return the AST snippet for accessing the {@code TruffleObject}, wrapped as a
+         *         {@code CallTarget}.
+         */
+        CallTarget accessMessage(Message tree);
+    }
+
+    /**
+     * Specialized {@link Factory factory} that handles {@link Message messages} known as of release
+     * 1.0 of Truffle API.
+     *
+     */
+    public interface Factory10 {
+        /**
+         * Handles {@link Message#IS_NULL} message.
+         *
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessIsNull();
+
+        /**
+         * Handles {@link Message#IS_EXECUTABLE} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessIsExecutable();
+
+        /**
+         * Handles {@link Message#IS_BOXED} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessIsBoxed();
+
+        /**
+         * Handles {@link Message#HAS_SIZE} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessHasSize();
+
+        /**
+         * Handles {@link Message#GET_SIZE} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessGetSize();
+
+        /**
+         * Handles {@link Message#UNBOX} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessUnbox();
+
+        /**
+         * Handles {@link Message#READ} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessRead();
+
+        /**
+         * Handles {@link Message#WRITE} message.
+         * 
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessWrite();
+
+        /**
+         * Handles {@link Message#createExecute(int)} messages.
+         * 
+         * @param argumentsLength number of parameters the messages has been created for
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessExecute(int argumentsLength);
+
+        /**
+         * Handles {@link Message#createInvoke(int)} messages.
+         * 
+         * @param argumentsLength number of parameters the messages has been created for
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessInvoke(int argumentsLength);
+
+        /**
+         * Handles request for access to a message not known in version 1.0.
+         *
+         * @param unknown the message
+         * @return call target to handle the message or <code>null</code> if this message is not
+         *         supported
+         */
+        CallTarget accessMessage(Message unknown);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccessArguments.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class ForeignAccessArguments {
+    static final Object[] EMPTY_ARGUMENTS_ARRAY = new Object[0];
+    static final int RECEIVER_INDEX = 0;
+    static final int RUNTIME_ARGUMENT_COUNT = 1;
+
+    static Object[] create(Object receiver, Object... arguments) {
+        if (arguments.length == 0) {
+            return new Object[]{receiver};
+        }
+        Object[] objectArguments = new Object[RUNTIME_ARGUMENT_COUNT + arguments.length];
+        objectArguments[RECEIVER_INDEX] = receiver;
+        arraycopy(arguments, 0, objectArguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
+        return objectArguments;
+    }
+
+    private static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) {
+        for (int i = 0; i < length; i++) {
+            dest[destPos + i] = src[srcPos + i];
+        }
+    }
+
+}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignAccessFactory.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.interop.messages.*;
-
-/**
- * Interface of a factory that produces AST snippets that can access a foreign {@code TruffleObject}
- * . A Truffle language implementation accesses a {@code TruffleObject} via a {@code Message}. The
- * {@code TruffleObject} instance provides a {@code ForeignAccessFactory} instance that provides an
- * AST snippet for a given {@code Message}.
- */
-public interface ForeignAccessFactory {
-
-    /**
-     * Provides a {@code InteropPredicate} that tests whether a {@code TruffleObject} can be
-     * accessed using AST snippets, produced by this {@code ForeignAccessFactory}.
-     *
-     * @return the {@code InteropPredicate} that tests if a {@code TruffleObject} can be accessed by
-     *         AST snipptes, produces by this {@code ForeignAccessFactory}.
-     */
-    InteropPredicate getLanguageCheck();
-
-    /**
-     * Provides an AST snippet to access a {@code TruffleObject}.
-     *
-     * @param tree the {@code Message} that represents the access to a {@code TruffleObject}.
-     * @return the AST snippet for accessing the {@code TruffleObject}, wrapped as a
-     *         {@code CallTarget}.
-     */
-    CallTarget getAccess(Message tree);
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ForeignObjectAccessHeadNode.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.nodes.Node;
+
+final class ForeignObjectAccessHeadNode extends Node {
+
+    @Child private ObjectAccessNode first;
+    private final Message accessTree;
+
+    protected ForeignObjectAccessHeadNode(Message tree) {
+        this.accessTree = tree;
+        this.first = new UnresolvedObjectAccessNode();
+        adoptChildren();
+    }
+
+    protected Message getAccessTree() {
+        return accessTree;
+    }
+
+    protected ObjectAccessNode getFirst() {
+        return first;
+    }
+
+    public Object executeForeign(VirtualFrame frame, TruffleObject receiver, Object... arguments) {
+        return first.executeWith(frame, receiver, arguments);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/GetSize.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class GetSize extends UnaryMessage {
+    public static final int HASH = 423432;
+
+    static Message INSTANCE = new GetSize();
+
+    @Override
+    public String toString() {
+        return "msgGetSize";
+    }
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/HasSize.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class HasSize extends UnaryMessage {
+    public static final int HASH = 423433;
+    static Message INSTANCE = new HasSize();
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgHasSize";
+    }
+}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/InteropPredicate.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop;
-
-/**
- * Represents a predicate of a {@code TruffleObject} argument.
- */
-public interface InteropPredicate {
-
-    /**
-     * Evaluates the predicate on the given {@code TruffleObject}.
-     *
-     * @param object the input argument
-     * @return {@code true} if the {@code TruffleObject} argument matches the predicate, otherwise
-     *         {@code false}
-     */
-    boolean test(TruffleObject object);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsBoxed.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class IsBoxed extends UnaryMessage {
+    public static final int HASH = 423434;
+    static Message INSTANCE = new IsBoxed();
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgIsBoxed";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsExecutable.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class IsExecutable extends UnaryMessage {
+    public static final int HASH = 423435;
+    static Message INSTANCE = new IsExecutable();
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgIsExecutable";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/IsNull.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class IsNull extends UnaryMessage {
+    public static final int HASH = 423436;
+    static Message INSTANCE = new IsNull();
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgIsNull";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/KnownMessage.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+/**
+ * Marker class.
+ */
+abstract class KnownMessage extends Message {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Message.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.api.interop.ForeignAccess.Factory;
+
+/**
+ * Inter-operability is based on sending messages. Standard messages are defined as as constants
+ * like {@link #IS_NULL} or factory methods in this class, but one can always define their own,
+ * specialized messages.
+ */
+public abstract class Message {
+    /**
+     * Message to read a field.
+     */
+    public static final Message READ = Read.INSTANCE;
+
+    /**
+     * Converts {@link TruffleObject truffle value} to Java primitive type. Primitive types are
+     * subclasses of {@link Number}, {@link Boolean}, {@link Character} and {@link String}. Related
+     * to {@link #IS_BOXED} message.
+     */
+    public static final Message UNBOX = Unbox.INSTANCE;
+
+    /**
+     * Message to write a field.
+     */
+    public static Message WRITE = Write.INSTANCE;
+
+    /**
+     * Creates an execute message. All messages created by this method are
+     * {@link Object#equals(java.lang.Object) equal} to each other regardless of the value of
+     * <code>argumentsLength</code>.
+     *
+     * @param argumentsLength number of parameters to pass to the target
+     * @return execute message
+     */
+    public static Message createExecute(int argumentsLength) {
+        return Execute.create(false, argumentsLength);
+    }
+
+    /**
+     * Message to check for executability.
+     * <p>
+     * Calling {@link Factory#access(com.oracle.truffle.api.interop.Message) the target} created for
+     * this message should yield value of {@link Boolean}.
+     */
+    public static final Message IS_EXECUTABLE = IsExecutable.INSTANCE;
+
+    /**
+     * Creates an execute message. All messages created by this method are
+     * {@link Object#equals(java.lang.Object) equal} to each other regardless of the value of
+     * <code>argumentsLength</code>. The expected behavior of this message is to perform
+     * {@link #READ} first and on the result invoke {@link #createExecute(int)}.
+     *
+     * @param argumentsLength number of parameters to pass to the target
+     * @return read & execute message
+     */
+    public static Message createInvoke(int argumentsLength) {
+        return Execute.create(true, argumentsLength);
+    }
+
+    /**
+     * Check for <code>null</code> message. The Truffle languages are suggested to have their own
+     * object representing <code>null</code> like values in their languages. For purposes of
+     * inter-operability it is essential to canonicalize such values from time to time - sending
+     * this message is a way to recognize such <code>null</code> representing values.
+     * <p>
+     * Calling {@link Factory#access(com.oracle.truffle.api.interop.Message) the target} created for
+     * this message should yield value of {@link Boolean}.
+     */
+    public static final Message IS_NULL = IsNull.INSTANCE;
+
+    /**
+     * Message to check for having a size.
+     * <p>
+     * Calling {@link Factory#access(com.oracle.truffle.api.interop.Message) the target} created for
+     * this message should yield value of {@link Boolean}.
+     */
+    public static final Message HAS_SIZE = HasSize.INSTANCE;
+
+    /**
+     * Getter of the size. If {@link #HAS_SIZE supported}, this message allows to obtain a size (of
+     * an array).
+     * <p>
+     * Calling {@link Factory#access(com.oracle.truffle.api.interop.Message) the target} created for
+     * this message should yield value of {@link Integer}.
+     */
+    public static final Message GET_SIZE = GetSize.INSTANCE;
+
+    /**
+     * Check for value being boxed. Can you value be converted to one of the basic Java types? Many
+     * languages have a special representation for types like number, string, etc. To ensure
+     * inter-operability, these types should support unboxing - if they do, they should handle this
+     * message.
+     * <p>
+     * Calling {@link Factory#accessMessage(com.oracle.truffle.api.interop.Message) the target}
+     * created for this message should yield value of {@link Boolean}.
+     */
+    public static final Message IS_BOXED = IsBoxed.INSTANCE;
+
+    /**
+     * Compares types of two messages. Messages are encouraged to implement this method. All
+     * standard ones ({@link #IS_NULL}, {@link #READ}, etc.) do so. Messages obtained via the same
+     * {@link #createExecute(int) method} are equal, messages obtained by different methods or
+     * fields are not.
+     *
+     * @param message the object to compare to
+     * @return true, if the structure of the message is that same as of <code>this</code> one.
+     */
+    @Override
+    public abstract boolean equals(Object message);
+
+    /**
+     * When re-implementing {@link #equals(java.lang.Object)}, it is generally recommended to also
+     * implement <code>hashCode()</code>.
+     * 
+     * @return hash code
+     */
+    @Override
+    public abstract int hashCode();
+
+    /**
+     * Creates an AST node for this message. The node can be inserted into AST of your language and
+     * will handle communication with the foreign language.
+     *
+     * @return node to be inserted into your AST and passed back to
+     *         {@link ForeignAccess#execute(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object[])}
+     *         method.
+     */
+    public final Node createNode() {
+        return new ForeignObjectAccessHeadNode(this);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/ObjectAccessNode.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.nodes.*;
+
+abstract class ObjectAccessNode extends Node {
+
+    public abstract Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments);
+
+}
+
+class UnresolvedObjectAccessNode extends ObjectAccessNode {
+
+    private static final int CACHE_SIZE = 8;
+    private int cacheLength = 1;
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        CompilerDirectives.transferToInterpreterAndInvalidate();
+        ForeignObjectAccessHeadNode nthParent = (ForeignObjectAccessHeadNode) NodeUtil.getNthParent(this, cacheLength);
+        ObjectAccessNode first = nthParent.getFirst();
+        if (cacheLength < CACHE_SIZE) {
+            cacheLength++;
+            CachedObjectAccessNode createCachedAccess = createCachedAccess(receiver, nthParent.getAccessTree(), first);
+            return first.replace(createCachedAccess).executeWith(frame, receiver, arguments);
+        } else {
+            return first.replace(createGenericAccess(nthParent.getAccessTree())).executeWith(frame, receiver, arguments);
+        }
+    }
+
+    private static CachedObjectAccessNode createCachedAccess(TruffleObject receiver, Message accessTree, ObjectAccessNode next) {
+        ForeignAccess fa = receiver.getForeignAccess();
+        final CallTarget ct = fa.access(accessTree);
+        if (ct == null) {
+            throw new IllegalArgumentException("Message " + accessTree + " not recognized by " + fa);
+        }
+        return new CachedObjectAccessNode(Truffle.getRuntime().createDirectCallNode(ct), next, fa);
+    }
+
+    private static GenericObjectAccessNode createGenericAccess(Message access) {
+        return new GenericObjectAccessNode(access);
+    }
+}
+
+class GenericObjectAccessNode extends ObjectAccessNode {
+
+    private final Message access;
+    @Child private IndirectCallNode indirectCallNode;
+
+    public GenericObjectAccessNode(Message access) {
+        this.access = access;
+        indirectCallNode = Truffle.getRuntime().createIndirectCallNode();
+    }
+
+    public GenericObjectAccessNode(GenericObjectAccessNode prev) {
+        this(prev.access);
+    }
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject truffleObject, Object[] arguments) {
+        final ForeignAccess fa = truffleObject.getForeignAccess();
+        final CallTarget ct = fa.access(access);
+        if (ct == null) {
+            throw new IllegalStateException("Message " + access + " not recognized by " + fa);
+        }
+        return indirectCallNode.call(frame, ct, ForeignAccessArguments.create(truffleObject, arguments));
+    }
+}
+
+class CachedObjectAccessNode extends ObjectAccessNode {
+    @Child private DirectCallNode callTarget;
+    @Child private ObjectAccessNode next;
+
+    private final ForeignAccess languageCheck;
+
+    protected CachedObjectAccessNode(DirectCallNode callTarget, ObjectAccessNode next, ForeignAccess languageCheck) {
+        this.callTarget = callTarget;
+        this.next = next;
+        this.languageCheck = languageCheck;
+        this.callTarget.forceInlining();
+    }
+
+    protected CachedObjectAccessNode(CachedObjectAccessNode prev) {
+        this(prev.callTarget, prev.next, prev.languageCheck);
+    }
+
+    @Override
+    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        return doAccess(frame, receiver, arguments);
+    }
+
+    private Object doAccess(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        if (languageCheck.canHandle(receiver)) {
+            return callTarget.call(frame, ForeignAccessArguments.create(receiver, arguments));
+        } else {
+            return doNext(frame, receiver, arguments);
+        }
+    }
+
+    private Object doNext(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
+        return next.executeWith(frame, receiver, arguments);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Read.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class Read extends KnownMessage {
+    public static final int HASH = 423438;
+    static Message INSTANCE = new Read();
+
+    private Read() {
+    }
+
+    @Override
+    public boolean equals(Object message) {
+        return message instanceof Read;
+    }
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgRead";
+    }
+}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/TruffleObject.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/TruffleObject.java	Mon Jun 08 04:50:13 2015 +0200
@@ -34,5 +34,5 @@
      *
      * @return the {@code ForeignAccessFactory} instance for this {@code TruffleObject} instance.
      */
-    ForeignAccessFactory getForeignAccessFactory();
+    ForeignAccess getForeignAccess();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/UnaryMessage.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+abstract class UnaryMessage extends KnownMessage {
+    protected UnaryMessage() {
+    }
+
+    @Override
+    public boolean equals(Object message) {
+        if (message == null) {
+            return false;
+        }
+        return this.getClass() == message.getClass();
+    }
+
+    @Override
+    public abstract int hashCode();
+
+    @Override
+    public abstract String toString();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Unbox.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class Unbox extends UnaryMessage {
+    public static final int HASH = 423437;
+    static Message INSTANCE = new Unbox();
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgUnbox";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/Write.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop;
+
+final class Write extends KnownMessage {
+    public static final int HASH = 423431;
+
+    static Message INSTANCE = new Write();
+
+    @Override
+    public boolean equals(Object message) {
+        return message instanceof Write;
+    }
+
+    @Override
+    public int hashCode() {
+        return HASH;
+    }
+
+    @Override
+    public String toString() {
+        return "msgWrite";
+    }
+
+}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/exception/UnsupportedMessageException.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.exception;
-
-/**
- * An exception thrown if the receiver of a guest language implementation cannot resolve a message.
- */
-public final class UnsupportedMessageException extends RuntimeException {
-
-    private static final long serialVersionUID = -2014660135608964970L;
-
-    public UnsupportedMessageException(String reason) {
-        super(reason);
-    }
-
-}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/exception/UnsupportedTypeException.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.exception;
-
-/**
- * An exception thrown if a foreign type cannot be converted to a language-dependent regular type.
- */
-public class UnsupportedTypeException extends RuntimeException {
-
-    private static final long serialVersionUID = 5786411886196161509L;
-
-    public UnsupportedTypeException(String reason) {
-        super(reason);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/ReadOnlyArrayList.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop.impl;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+public final class ReadOnlyArrayList<T> implements List<T> {
+    private final T[] arr;
+    private final int first;
+    private final int last;
+
+    private ReadOnlyArrayList(T[] arr, int first, int last) {
+        this.arr = arr;
+        this.first = first;
+        this.last = last;
+    }
+
+    public static <T> List<T> asList(T[] arr, int first, int last) {
+        return new ReadOnlyArrayList<>(arr, first, last);
+    }
+
+    @Override
+    public int size() {
+        return last - first;
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return first == last;
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        for (int i = first; i < last; i++) {
+            if (o == arr[i] || (o != null && o.equals(arr[i]))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Iterator<T> iterator() {
+        return new LI(first);
+    }
+
+    @Override
+    public Object[] toArray() {
+        return toArray(new Object[size()]);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <A> A[] toArray(A[] b) {
+        A[] a;
+        if (b.length < size()) {
+            a = (A[]) Array.newInstance(b.getClass().getComponentType(), size());
+        } else {
+            a = b;
+        }
+        for (int i = 0, at = first; at < last; i++, at++) {
+            a[i] = (A) arr[at];
+        }
+        return a;
+    }
+
+    @Override
+    public boolean add(Object e) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        for (Object obj : c) {
+            if (!contains(obj)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends T> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean addAll(int index, Collection<? extends T> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public T get(int index) {
+        int at = first + index;
+        T ret = arr[at];
+        if (at >= last) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        return ret;
+    }
+
+    @Override
+    public T set(int index, Object element) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void add(int index, Object element) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public T remove(int index) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int indexOf(Object o) {
+        for (int i = first; i < last; i++) {
+            if (arr[i] == null) {
+                if (o == null) {
+                    return i - first;
+                }
+            } else {
+                if (arr[i].equals(o)) {
+                    return i - first;
+                }
+            }
+        }
+        return -1;
+    }
+
+    @Override
+    public int lastIndexOf(Object o) {
+        for (int i = last - 1; i >= first; i--) {
+            if (arr[i] == null) {
+                if (o == null) {
+                    return i - first;
+                }
+            } else {
+                if (arr[i].equals(o)) {
+                    return i - first;
+                }
+            }
+        }
+        return -1;
+    }
+
+    @Override
+    public ListIterator<T> listIterator() {
+        return new LI(first);
+    }
+
+    @Override
+    public ListIterator<T> listIterator(int index) {
+        return new LI(first + index);
+    }
+
+    @Override
+    public List<T> subList(int fromIndex, int toIndex) {
+        return new ReadOnlyArrayList<>(arr, first + fromIndex, first + toIndex);
+    }
+
+    private final class LI implements ListIterator<T>, Iterator<T> {
+        private int index;
+
+        public LI(int index) {
+            this.index = index;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return index < last;
+        }
+
+        @Override
+        public T next() {
+            if (index >= last) {
+                throw new NoSuchElementException();
+            }
+            return arr[index++];
+        }
+
+        @Override
+        public boolean hasPrevious() {
+            return index > first;
+        }
+
+        @Override
+        public T previous() {
+            if (first == index) {
+                throw new NoSuchElementException();
+            }
+            return arr[--index];
+        }
+
+        @Override
+        public int nextIndex() {
+            return index - first;
+        }
+
+        @Override
+        public int previousIndex() {
+            return index - 1 - first;
+        }
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void set(Object e) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void add(Object e) {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/SymbolInvokerImpl.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2014, 2015, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.interop.impl;
+
+import java.io.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.impl.*;
+import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.Message;
+import com.oracle.truffle.api.interop.TruffleObject;
+import com.oracle.truffle.api.nodes.*;
+
+public final class SymbolInvokerImpl extends SymbolInvoker {
+    static final FrameDescriptor UNUSED_FRAMEDESCRIPTOR = new FrameDescriptor();
+
+    @Override
+    protected Object invoke(Object symbol, Object... arr) throws IOException {
+        if (symbol instanceof String) {
+            return symbol;
+        }
+        if (symbol instanceof Number) {
+            return symbol;
+        }
+        if (symbol instanceof Boolean) {
+            return symbol;
+        }
+        Node executeMain = Message.createExecute(arr.length).createNode();
+        CallTarget callTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(executeMain, (TruffleObject) symbol, arr));
+        VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR);
+        Object ret = callTarget.call(frame);
+        if (ret instanceof TruffleObject) {
+            TruffleObject tret = (TruffleObject) ret;
+            Object isBoxedResult;
+            try {
+                Node isBoxed = Message.IS_BOXED.createNode();
+                CallTarget isBoxedTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isBoxed, tret));
+                isBoxedResult = isBoxedTarget.call(frame);
+            } catch (IllegalArgumentException ex) {
+                isBoxedResult = false;
+            }
+            if (Boolean.TRUE.equals(isBoxedResult)) {
+                Node unbox = Message.UNBOX.createNode();
+                CallTarget unboxTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(unbox, tret));
+                Object unboxResult = unboxTarget.call(frame);
+                return unboxResult;
+            } else {
+                try {
+                    Node isNull = Message.IS_NULL.createNode();
+                    CallTarget isNullTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isNull, tret));
+                    Object isNullResult = isNullTarget.call(frame);
+                    if (Boolean.TRUE.equals(isNullResult)) {
+                        return null;
+                    }
+                } catch (IllegalArgumentException ex) {
+                    // fallthrough
+                }
+            }
+        }
+        return ret;
+    }
+
+    private static class TemporaryRoot extends RootNode {
+        @Child private Node foreignAccess;
+        private final TruffleObject function;
+        private final Object[] args;
+
+        public TemporaryRoot(Node foreignAccess, TruffleObject function, Object... args) {
+            this.foreignAccess = foreignAccess;
+            this.function = function;
+            this.args = args;
+        }
+
+        @Override
+        public Object execute(VirtualFrame frame) {
+            return ForeignAccess.execute(foreignAccess, frame, function, args);
+        }
+    }
+
+}
--- a/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/messages/Message.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-public interface Message {
-    boolean matchStructure(Object message);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/package-info.java	Mon Jun 08 04:50:13 2015 +0200
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+/**
+ * Inter-operability between different languages is covered by this package.
+ * In case you are implementing own {@link com.oracle.truffle.api.TruffleLanguage} and you want
+ * to interact with other {@link com.oracle.truffle.api.TruffleLanguage language implementations}
+ * you need to use types from this package.
+ * <p>
+ * Different languages can exchange either wrappers of primitive Java
+ * types (like {@link Integer}, {@link Double}, {@link String}), or they
+ * can export their own types (if they implement {@link TruffleObject} interface).
+ * Btw. One can recognize foreign object if it implements {@link TruffleObject}.
+ * <p>
+ * To use {@link TruffleObject} from a different language one needs to ask
+ * the language to build appropriate AST for a given {@link Message}. To do
+ * so use {@link ForeignAccess#node(com.oracle.truffle.api.interop.Message)}
+ * and when calling it {@link ForeignAccess#execute(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object...)}.
+ */
+package com.oracle.truffle.api.interop;
+
--- a/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/ObjectType.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/ObjectType.java	Mon Jun 08 04:50:13 2015 +0200
@@ -24,11 +24,10 @@
  */
 package com.oracle.truffle.api.object;
 
+import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.interop.*;
-import com.oracle.truffle.api.interop.exception.*;
-import com.oracle.truffle.api.interop.messages.*;
 
 public class ObjectType {
     /**
@@ -72,16 +71,16 @@
     public void onPropertyAdded(Property property, Shape shapeBefore, Shape shapeAfter) {
     }
 
-    public ForeignAccessFactory getForeignAccessFactory() {
-        return new ForeignAccessFactory() {
+    public ForeignAccess getForeignAccessFactory() {
+        return ForeignAccess.create(new com.oracle.truffle.api.interop.ForeignAccess.Factory() {
 
-            public InteropPredicate getLanguageCheck() {
-                throw new UnsupportedMessageException(this.toString() + " cannot be shared");
+            public boolean canHandle(TruffleObject obj) {
+                throw new IllegalArgumentException(this.toString() + " cannot be shared");
             }
 
-            public CallTarget getAccess(Message tree) {
-                throw new UnsupportedMessageException(this.toString() + " cannot be shared; Message not possible: " + tree.toString());
+            public CallTarget accessMessage(Message tree) {
+                throw new IllegalArgumentException(this.toString() + " cannot be shared; Message not possible: " + tree.toString());
             }
-        };
+        });
     }
 }
--- a/graal/com.oracle.truffle.interop/src/META-INF/services/com.oracle.truffle.api.impl.SymbolInvoker	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-com.oracle.truffle.interop.SymbolInvokerImpl
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/ForeignAccessArguments.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop;
-
-import com.oracle.truffle.api.*;
-
-public final class ForeignAccessArguments {
-    public static final Object[] EMPTY_ARGUMENTS_ARRAY = new Object[0];
-    public static final int RECEIVER_INDEX = 0;
-    public static final int RUNTIME_ARGUMENT_COUNT = 1;
-
-    public static Object[] create(Object receiver) {
-        return new Object[]{receiver};
-    }
-
-    public static Object[] create(Object receiver, Object[] arguments) {
-        Object[] objectArguments = new Object[RUNTIME_ARGUMENT_COUNT + arguments.length];
-        objectArguments[RECEIVER_INDEX] = receiver;
-        arraycopy(arguments, 0, objectArguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
-        return objectArguments;
-    }
-
-    public static Object getArgument(Object[] arguments, int index) {
-        return arguments[RUNTIME_ARGUMENT_COUNT + index];
-    }
-
-    public static Object getReceiver(Object[] arguments) {
-        return arguments[RECEIVER_INDEX];
-    }
-
-    public static Object[] extractUserArguments(Object[] arguments) {
-        return copyOfRange(arguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
-    }
-
-    public static Object[] extractUserArguments(int skip, Object[] arguments) {
-        return copyOfRange(arguments, RUNTIME_ARGUMENT_COUNT + skip, arguments.length);
-    }
-
-    public static int getUserArgumentCount(Object[] arguments) {
-        return arguments.length - RUNTIME_ARGUMENT_COUNT;
-    }
-
-    private static Object[] copyOfRange(Object[] original, int from, int to) {
-        int newLength = to - from;
-        if (newLength < 0) {
-            CompilerDirectives.transferToInterpreter();
-            throw new IllegalArgumentException(from + " > " + to);
-        }
-        Object[] copy = new Object[newLength];
-        arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
-        return copy;
-    }
-
-    private static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) {
-        for (int i = 0; i < length; i++) {
-            dest[destPos + i] = src[srcPos + i];
-        }
-    }
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop;
-
-import java.io.*;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.impl.*;
-import com.oracle.truffle.api.interop.*;
-import com.oracle.truffle.api.interop.exception.UnsupportedMessageException;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.interop.messages.*;
-import com.oracle.truffle.interop.node.*;
-
-public final class SymbolInvokerImpl extends SymbolInvoker {
-    static final FrameDescriptor UNUSED_FRAMEDESCRIPTOR = new FrameDescriptor();
-
-    @Override
-    protected Object invoke(Object symbol, Object... arr) throws IOException {
-        if (symbol instanceof String) {
-            return symbol;
-        }
-        if (symbol instanceof Number) {
-            return symbol;
-        }
-        if (symbol instanceof Boolean) {
-            return symbol;
-        }
-        ForeignObjectAccessNode callMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length));
-        CallTarget callMainTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(callMain, (TruffleObject) symbol, arr));
-        VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR);
-        Object ret = callMainTarget.call(frame);
-        if (ret instanceof TruffleObject) {
-            TruffleObject tret = (TruffleObject) ret;
-            Object isBoxedResult;
-            try {
-                ForeignObjectAccessNode isBoxed = ForeignObjectAccessNode.getAccess(IsBoxed.create(Receiver.create()));
-                CallTarget isBoxedTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isBoxed, tret));
-                isBoxedResult = isBoxedTarget.call(frame);
-            } catch (UnsupportedMessageException ex) {
-                isBoxedResult = false;
-            }
-            if (Boolean.TRUE.equals(isBoxedResult)) {
-                ForeignObjectAccessNode unbox = ForeignObjectAccessNode.getAccess(Unbox.create(Receiver.create()));
-                CallTarget unboxTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(unbox, tret));
-                Object unboxResult = unboxTarget.call(frame);
-                return unboxResult;
-            } else {
-                try {
-                    ForeignObjectAccessNode isNull = ForeignObjectAccessNode.getAccess(IsNull.create(Receiver.create()));
-                    CallTarget isNullTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isNull, tret));
-                    Object isNullResult = isNullTarget.call(frame);
-                    if (Boolean.TRUE.equals(isNullResult)) {
-                        return null;
-                    }
-                } catch (UnsupportedMessageException ex) {
-                    // fallthrough
-                }
-            }
-        }
-        return ret;
-    }
-
-    private static class TemporaryRoot extends RootNode {
-        @Child private ForeignObjectAccessNode foreignAccess;
-        private final TruffleObject function;
-        private final Object[] args;
-
-        public TemporaryRoot(ForeignObjectAccessNode foreignAccess, TruffleObject function, Object... args) {
-            this.foreignAccess = foreignAccess;
-            this.function = function;
-            this.args = args;
-        }
-
-        @Override
-        public Object execute(VirtualFrame frame) {
-            return foreignAccess.executeForeign(frame, function, args);
-        }
-    }
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Argument.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-public final class Argument {
-    private Argument() {
-    }
-
-    public static Argument create() {
-        return new Argument();
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Argument");
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Execute.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class Execute implements Message {
-    private final Object receiver;
-    private final int arity;
-
-    public static Execute create(Receiver receiver, int arity) {
-        return new Execute(receiver, arity);
-    }
-
-    public static Execute create(Message receiver, int arity) {
-        return new Execute(receiver, arity);
-    }
-
-    private Execute(Object receiver, int arity) {
-        this.receiver = receiver;
-        this.arity = arity;
-    }
-
-    public Object getReceiver() {
-        return receiver;
-    }
-
-    public int getArity() {
-        return arity;
-    }
-
-    public boolean matchStructure(Object message) {
-        if (!(message instanceof Execute)) {
-            return false;
-        }
-        Execute m1 = this;
-        Execute m2 = (Execute) message;
-        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Execute(%s)", receiver.toString());
-    }
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/GetSize.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class GetSize extends UnaryMessage {
-
-    public static GetSize create(Receiver receiver) {
-        return new GetSize(receiver);
-    }
-
-    public static GetSize create(Message receiver) {
-        return new GetSize(receiver);
-    }
-
-    private GetSize(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("GetSize(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/HasSize.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class HasSize extends UnaryMessage {
-    public static HasSize create(Receiver receiver) {
-        return new HasSize(receiver);
-    }
-
-    public static HasSize create(Message receiver) {
-        return new HasSize(receiver);
-    }
-
-    private HasSize(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("HasSize(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsBoxed.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class IsBoxed extends UnaryMessage {
-    public static IsBoxed create(Receiver receiver) {
-        return new IsBoxed(receiver);
-    }
-
-    public static IsBoxed create(Message receiver) {
-        return new IsBoxed(receiver);
-    }
-
-    private IsBoxed(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("IsBoxed(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsExecutable.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class IsExecutable extends UnaryMessage {
-    public static IsExecutable create(Receiver receiver) {
-        return new IsExecutable(receiver);
-    }
-
-    public static IsExecutable create(Message receiver) {
-        return new IsExecutable(receiver);
-    }
-
-    private IsExecutable(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("IsExecutable(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/IsNull.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class IsNull extends UnaryMessage {
-    public static IsNull create(Receiver receiver) {
-        return new IsNull(receiver);
-    }
-
-    public static IsNull create(Message receiver) {
-        return new IsNull(receiver);
-    }
-
-    private IsNull(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("IsNull(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/MessageUtil.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-final class MessageUtil {
-
-    static boolean compareMessage(Object o1, Object o2) {
-        if (o1 instanceof Message && o2 instanceof Message) {
-            return ((Message) o1).matchStructure(o2);
-        } else if (o1 instanceof Receiver && o2 instanceof Receiver) {
-            return true;
-        }
-        return false;
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Read.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class Read implements Message {
-    private final Object receiver;
-    private final Argument id;
-
-    private Read(Object receiver, Argument id) {
-        this.receiver = receiver;
-        this.id = id;
-    }
-
-    public static Read create(Receiver receiver, Argument id) {
-        return new Read(receiver, id);
-    }
-
-    public static Read create(Message receiver, Argument id) {
-        return new Read(receiver, id);
-    }
-
-    public Argument getId() {
-        return id;
-    }
-
-    public Object getReceiver() {
-        return receiver;
-    }
-
-    public boolean matchStructure(Object message) {
-        if (!(message instanceof Read)) {
-            return false;
-        }
-        Read m1 = this;
-        Read m2 = (Read) message;
-        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Read(%s, %s)", receiver.toString(), id.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Receiver.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-public final class Receiver {
-
-    private Receiver() {
-
-    }
-
-    public static Receiver create() {
-        return new Receiver();
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Receiver");
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/UnaryMessage.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-abstract class UnaryMessage implements Message {
-    protected final Object receiver;
-
-    protected UnaryMessage(Object receiver) {
-        this.receiver = receiver;
-    }
-
-    public Object getReceiver() {
-        return receiver;
-    }
-
-    public boolean matchStructure(Object message) {
-        if (message == null) {
-            return false;
-        }
-        if (this.getClass() != message.getClass()) {
-            return false;
-        }
-        UnaryMessage m1 = this;
-        UnaryMessage m2 = (UnaryMessage) message;
-        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
-    }
-
-    @Override
-    public abstract String toString();
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Unbox.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class Unbox extends UnaryMessage {
-    public static Unbox create(Receiver receiver) {
-        return new Unbox(receiver);
-    }
-
-    public static Unbox create(Message receiver) {
-        return new Unbox(receiver);
-    }
-
-    private Unbox(Object receiver) {
-        super(receiver);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Unbox(%s)", receiver.toString());
-    }
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/messages/Write.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.messages;
-
-import com.oracle.truffle.api.interop.messages.*;
-
-public final class Write implements Message {
-    private final Object receiver;
-    private final Argument id;
-    private final Argument value;
-
-    private Write(Object receiver, Argument id, Argument value) {
-        this.receiver = receiver;
-        this.id = id;
-        this.value = value;
-    }
-
-    public static Write create(Receiver receiver, Argument id, Argument value) {
-        return new Write(receiver, id, value);
-    }
-
-    public static Write create(Message receiver, Argument id, Argument value) {
-        return new Write(receiver, id, value);
-    }
-
-    public Argument getId() {
-        return id;
-    }
-
-    public Object getReceiver() {
-        return receiver;
-    }
-
-    public Argument getValue() {
-        return value;
-    }
-
-    public boolean matchStructure(Object message) {
-        if (!(message instanceof Write)) {
-            return false;
-        }
-        Write m1 = this;
-        Write m2 = (Write) message;
-        return MessageUtil.compareMessage(m1.getReceiver(), m2.getReceiver());
-    }
-
-    @Override
-    public String toString() {
-        return String.format("Write(%s, %s, %s)", receiver.toString(), id.toString(), value.toString());
-    }
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessHeadNode.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.node;
-
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.interop.*;
-import com.oracle.truffle.api.interop.messages.*;
-
-final class ForeignObjectAccessHeadNode extends ForeignObjectAccessNode {
-
-    @Child private ObjectAccessNode first;
-    private final Message accessTree;
-
-    protected ForeignObjectAccessHeadNode(Message tree) {
-        this.accessTree = tree;
-        this.first = new UnresolvedObjectAccessNode();
-        adoptChildren();
-    }
-
-    protected Message getAccessTree() {
-        return accessTree;
-    }
-
-    protected ObjectAccessNode getFirst() {
-        return first;
-    }
-
-    @Override
-    public Object executeForeign(VirtualFrame frame, TruffleObject receiver, Object... arguments) {
-        return first.executeWith(frame, receiver, arguments);
-    }
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ForeignObjectAccessNode.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.node;
-
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.interop.*;
-import com.oracle.truffle.api.interop.messages.*;
-import com.oracle.truffle.api.nodes.*;
-
-public abstract class ForeignObjectAccessNode extends Node {
-
-    public static ForeignObjectAccessNode getAccess(Message tree) {
-        return new ForeignObjectAccessHeadNode(tree);
-    }
-
-    public abstract Object executeForeign(VirtualFrame frame, TruffleObject receiver, Object... arguments);
-
-}
--- a/graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/node/ObjectAccessNode.java	Sun Jun 07 16:59:03 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.interop.node;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.interop.*;
-import com.oracle.truffle.api.interop.messages.*;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.interop.*;
-
-abstract class ObjectAccessNode extends Node {
-
-    public abstract Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments);
-
-}
-
-class UnresolvedObjectAccessNode extends ObjectAccessNode {
-
-    private static final int CACHE_SIZE = 8;
-    private int cacheLength = 1;
-
-    @Override
-    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
-        CompilerDirectives.transferToInterpreterAndInvalidate();
-        ForeignObjectAccessHeadNode nthParent = (ForeignObjectAccessHeadNode) NodeUtil.getNthParent(this, cacheLength);
-        ObjectAccessNode first = nthParent.getFirst();
-        if (cacheLength < CACHE_SIZE) {
-            cacheLength++;
-            CachedObjectAccessNode createCachedAccess = createCachedAccess(receiver, nthParent.getAccessTree(), first);
-            return first.replace(createCachedAccess).executeWith(frame, receiver, arguments);
-        } else {
-            return first.replace(createGenericAccess(nthParent.getAccessTree())).executeWith(frame, receiver, arguments);
-        }
-    }
-
-    private static CachedObjectAccessNode createCachedAccess(TruffleObject receiver, Message accessTree, ObjectAccessNode next) {
-        ForeignAccessFactory accessFactory = receiver.getForeignAccessFactory();
-        return new CachedObjectAccessNode(Truffle.getRuntime().createDirectCallNode(accessFactory.getAccess(accessTree)), next, accessFactory.getLanguageCheck());
-    }
-
-    private static GenericObjectAccessNode createGenericAccess(Message access) {
-        return new GenericObjectAccessNode(access);
-    }
-}
-
-class GenericObjectAccessNode extends ObjectAccessNode {
-
-    private final Message access;
-    @Child private IndirectCallNode indirectCallNode;
-
-    public GenericObjectAccessNode(Message access) {
-        this.access = access;
-        indirectCallNode = Truffle.getRuntime().createIndirectCallNode();
-    }
-
-    public GenericObjectAccessNode(GenericObjectAccessNode prev) {
-        this(prev.access);
-    }
-
-    @Override
-    public Object executeWith(VirtualFrame frame, TruffleObject truffleObject, Object[] arguments) {
-        return indirectCallNode.call(frame, truffleObject.getForeignAccessFactory().getAccess(access), ForeignAccessArguments.create(truffleObject, arguments));
-    }
-}
-
-class CachedObjectAccessNode extends ObjectAccessNode {
-    @Child private DirectCallNode callTarget;
-    @Child private ObjectAccessNode next;
-
-    private final InteropPredicate languageCheck;
-
-    protected CachedObjectAccessNode(DirectCallNode callTarget, ObjectAccessNode next, InteropPredicate languageCheck) {
-        this.callTarget = callTarget;
-        this.next = next;
-        this.languageCheck = languageCheck;
-        this.callTarget.forceInlining();
-    }
-
-    protected CachedObjectAccessNode(CachedObjectAccessNode prev) {
-        this(prev.callTarget, prev.next, prev.languageCheck);
-    }
-
-    @Override
-    public Object executeWith(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
-        return doAccess(frame, receiver, arguments);
-    }
-
-    private Object doAccess(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
-        if (languageCheck.test(receiver)) {
-            return callTarget.call(frame, ForeignAccessArguments.create(receiver, arguments));
-        } else {
-            return doNext(frame, receiver, arguments);
-        }
-    }
-
-    private Object doNext(VirtualFrame frame, TruffleObject receiver, Object[] arguments) {
-        return next.executeWith(frame, receiver, arguments);
-    }
-}
--- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java	Mon Jun 08 04:50:13 2015 +0200
@@ -376,7 +376,8 @@
         ShapeProfiler.getInstance().track(obj);
     }
 
-    public ForeignAccessFactory getForeignAccessFactory() {
+    @Override
+    public ForeignAccess getForeignAccess() {
         return getShape().getForeignAccessFactory();
     }
 }
--- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Mon Jun 08 04:50:13 2015 +0200
@@ -1107,7 +1107,7 @@
     protected static final DebugCounter propertyListAllocCount = DebugCounter.create("Property lists allocated");
     protected static final DebugCounter propertyListShareCount = DebugCounter.create("Property lists shared");
 
-    public ForeignAccessFactory getForeignAccessFactory() {
+    public ForeignAccess getForeignAccessFactory() {
         return getObjectType().getForeignAccessFactory();
     }
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunction.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunction.java	Mon Jun 08 04:50:13 2015 +0200
@@ -98,7 +98,7 @@
      * foreign access implementation}.
      */
     @Override
-    public ForeignAccessFactory getForeignAccessFactory() {
+    public ForeignAccess getForeignAccess() {
         return SLFunctionForeignAccess.INSTANCE;
     }
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionForeignAccess.java	Mon Jun 08 04:50:13 2015 +0200
@@ -25,41 +25,37 @@
 import com.oracle.truffle.api.CallTarget;
 import com.oracle.truffle.api.Truffle;
 import com.oracle.truffle.api.frame.VirtualFrame;
-import com.oracle.truffle.api.interop.ForeignAccessFactory;
-import com.oracle.truffle.api.interop.InteropPredicate;
-import com.oracle.truffle.api.interop.exception.UnsupportedMessageException;
-import com.oracle.truffle.api.interop.messages.Message;
 import com.oracle.truffle.api.nodes.RootNode;
-import com.oracle.truffle.interop.ForeignAccessArguments;
-import com.oracle.truffle.interop.messages.Execute;
-import com.oracle.truffle.interop.messages.IsNull;
-import com.oracle.truffle.interop.messages.Receiver;
+import com.oracle.truffle.api.interop.TruffleObject;
+import com.oracle.truffle.api.interop.ForeignAccess;
+import com.oracle.truffle.api.interop.Message;
 import com.oracle.truffle.sl.nodes.call.SLDispatchNode;
 import com.oracle.truffle.sl.nodes.call.SLDispatchNodeGen;
 import java.math.BigInteger;
+import java.util.List;
 
 /**
- * Implementation of foreing access for {@link SLFunction}.
+ * Implementation of foreign access for {@link SLFunction}.
  */
-final class SLFunctionForeignAccess implements ForeignAccessFactory {
-    public static final ForeignAccessFactory INSTANCE = new SLFunctionForeignAccess();
+final class SLFunctionForeignAccess implements ForeignAccess.Factory {
+    public static final ForeignAccess INSTANCE = ForeignAccess.create(new SLFunctionForeignAccess());
 
     private SLFunctionForeignAccess() {
     }
 
     @Override
-    public InteropPredicate getLanguageCheck() {
-        return (com.oracle.truffle.api.interop.TruffleObject o) -> o instanceof SLFunction;
+    public boolean canHandle(TruffleObject o) {
+        return o instanceof SLFunction;
     }
 
     @Override
-    public CallTarget getAccess(Message tree) {
-        if (Execute.create(Receiver.create(), 0).matchStructure(tree)) {
+    public CallTarget accessMessage(Message tree) {
+        if (Message.createExecute(0).equals(tree)) {
             return Truffle.getRuntime().createCallTarget(new SLForeignCallerRootNode());
-        } else if (IsNull.create(Receiver.create()).matchStructure(tree)) {
+        } else if (Message.IS_NULL.equals(tree)) {
             return Truffle.getRuntime().createCallTarget(new SLForeignNullCheckNode());
         } else {
-            throw new UnsupportedMessageException(tree.toString() + " not supported");
+            throw new IllegalArgumentException(tree.toString() + " not supported");
         }
     }
 
@@ -68,24 +64,25 @@
 
         @Override
         public Object execute(VirtualFrame frame) {
-            SLFunction function = (SLFunction) ForeignAccessArguments.getReceiver(frame.getArguments());
+            SLFunction function = (SLFunction) ForeignAccess.getReceiver(frame);
             // the calling convention of interop passes the receiver of a
             // function call (the this object)
             // as an implicit 1st argument; we need to ignore this argument for SL
-            Object[] arguments = ForeignAccessArguments.extractUserArguments(1, frame.getArguments());
-            for (int i = 0; i < arguments.length; i++) {
-                if (arguments[i] instanceof Long) {
+            List<Object> args = ForeignAccess.getArguments(frame);
+            Object[] arr = args.subList(1, args.size()).toArray();
+            for (int i = 0; i < arr.length; i++) {
+                Object a = arr[i];
+                if (a instanceof Long) {
                     continue;
                 }
-                if (arguments[i] instanceof BigInteger) {
+                if (a instanceof BigInteger) {
                     continue;
                 }
-                if (arguments[i] instanceof Number) {
-                    arguments[i] = ((Number) arguments[i]).longValue();
+                if (a instanceof Number) {
+                    arr[i] = ((Number) a).longValue();
                 }
             }
-
-            return dispatch.executeDispatch(frame, function, arguments);
+            return dispatch.executeDispatch(frame, function, arr);
         }
 
     }
@@ -93,7 +90,7 @@
     private static class SLForeignNullCheckNode extends RootNode {
         @Override
         public Object execute(VirtualFrame frame) {
-            Object receiver = ForeignAccessArguments.getReceiver(frame.getArguments());
+            Object receiver = ForeignAccess.getReceiver(frame);
             return SLNull.SINGLETON == receiver;
         }
     }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java	Sun Jun 07 16:59:03 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java	Mon Jun 08 04:50:13 2015 +0200
@@ -22,7 +22,7 @@
  */
 package com.oracle.truffle.sl.runtime;
 
-import com.oracle.truffle.api.interop.ForeignAccessFactory;
+import com.oracle.truffle.api.interop.ForeignAccess;
 import com.oracle.truffle.api.interop.TruffleObject;
 
 /**
@@ -57,7 +57,7 @@
     }
 
     @Override
-    public ForeignAccessFactory getForeignAccessFactory() {
+    public ForeignAccess getForeignAccess() {
         return SLFunctionForeignAccess.INSTANCE;
     }
 }
--- a/mx/suite.py	Sun Jun 07 16:59:03 2015 +0200
+++ b/mx/suite.py	Mon Jun 08 04:50:13 2015 +0200
@@ -1114,15 +1114,6 @@
       "workingSets" : "API,Truffle",
     },
 
-    "com.oracle.truffle.interop" : {
-      "subDir" : "graal",
-      "sourceDirs" : ["src"],
-      "dependencies" : ["com.oracle.truffle.api.interop"],
-      "javaCompliance" : "1.7",
-      "workingSets" : "Truffle",
-      "checkstyle" : "com.oracle.truffle.api",
-    },
-
     "com.oracle.truffle.api.object" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],
@@ -1195,7 +1186,6 @@
       "sourceDirs" : ["src"],
       "dependencies" : [
         "com.oracle.truffle.api.dsl",
-        "com.oracle.truffle.interop",
         "com.oracle.truffle.api.object",
         "com.oracle.truffle.tools",
         "FINDBUGS"
@@ -1369,7 +1359,6 @@
       "dependencies" : [
         "com.oracle.truffle.api.dsl",
         "com.oracle.nfi",
-        "com.oracle.truffle.interop",
         "com.oracle.truffle.object.basic",
         "com.oracle.truffle.tools"
       ],