Skip to content
Snippets Groups Projects
Commit 90d34a18 authored by Florian Angerer's avatar Florian Angerer
Browse files

Implemented message resolution for ActiveBinding.

parent e4490194
Branches
No related tags found
No related merge requests found
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.engine.interop;
import com.oracle.truffle.api.interop.CanResolve;
import com.oracle.truffle.api.interop.MessageResolution;
import com.oracle.truffle.api.interop.Resolve;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.engine.TruffleRLanguage;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RContext.RCloseable;
import com.oracle.truffle.r.runtime.env.frame.ActiveBinding;
@MessageResolution(receiverType = ActiveBinding.class, language = TruffleRLanguage.class)
public class ActiveBindingMR {
@Resolve(message = "IS_BOXED")
public abstract static class ActiveBindingIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") ActiveBinding receiver) {
return true;
}
}
@Resolve(message = "HAS_SIZE")
public abstract static class ActiveBindingHasSizeNode extends Node {
protected Object access(@SuppressWarnings("unused") ActiveBinding receiver) {
return false;
}
}
@Resolve(message = "IS_NULL")
public abstract static class ActiveBindingIsNullNode extends Node {
protected Object access(@SuppressWarnings("unused") ActiveBinding receiver) {
return false;
}
}
@Resolve(message = "UNBOX")
public abstract static class ActiveBindingUnboxNode extends Node {
@Child private Node findContext = TruffleRLanguage.INSTANCE.actuallyCreateFindContextNode();
protected Object access(ActiveBinding receiver) {
try (RCloseable c = RContext.withinContext(TruffleRLanguage.INSTANCE.actuallyFindContext0(findContext))) {
return receiver.readValue();
}
}
}
@CanResolve
public abstract static class ActiveBindingCheck extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof ActiveBinding;
}
}
}
......@@ -49,6 +49,7 @@ import com.oracle.truffle.r.runtime.data.RTruffleObject;
import com.oracle.truffle.r.runtime.data.RUnboundValue;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.env.frame.ActiveBinding;
import com.oracle.truffle.r.runtime.ffi.CharSXPWrapper;
import com.oracle.truffle.r.runtime.ffi.DLL;
......@@ -119,6 +120,8 @@ public final class RForeignAccessFactoryImpl implements RForeignAccessFactory {
return RArgsValuesAndNamesMRForeign.ACCESS;
} else if (obj instanceof RLanguage) {
return RLanguageMRForeign.ACCESS;
} else if (obj instanceof ActiveBinding) {
return ActiveBindingMRForeign.ACCESS;
} else {
if (obj instanceof RAbstractVector) {
......
......@@ -29,13 +29,14 @@ import com.oracle.truffle.r.runtime.RType;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
import com.oracle.truffle.r.runtime.env.REnvironment;
/**
* Represent an active binding of a function. This requires special treatment when reading and
* writing variables.
*/
public class ActiveBinding {
public class ActiveBinding implements RTruffleObject {
private final RType expectedType;
private final RFunction function;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment