com.oracle.truffle.sl.runtime.SLObjectMessageResolutionForeign Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-sl Show documentation
Show all versions of truffle-sl Show documentation
Truffle SL is an example language implemented using the Truffle API.
package com.oracle.truffle.sl.runtime;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.ForeignAccess.Factory;
import com.oracle.truffle.api.interop.ForeignAccess.StandardFactory;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.RootNode;
import java.util.List;
/**
* This foreign access factory is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution}.
* You are supposed to use it for the receiver object {@link com.oracle.truffle.sl.runtime.SLObjectType}.
*/
public final class SLObjectMessageResolutionForeign implements StandardFactory, Factory {
public static final ForeignAccess ACCESS = ForeignAccess.create(new SLObjectMessageResolutionForeign(), null);
@Deprecated public static ForeignAccess createAccess() { return ForeignAccess.create(new SLObjectMessageResolutionForeign(), null); }
private SLObjectMessageResolutionForeign() { }
@Override
public boolean canHandle(TruffleObject obj) {
return com.oracle.truffle.sl.runtime.SLObjectType.isInstance(obj);
}
@Override
public CallTarget accessIsNull() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessIsExecutable() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessIsInstantiable() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessIsBoxed() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessHasKeys() {
return Truffle.getRuntime().createCallTarget(SLForeignHasPropertiesSubNode.createRoot());
}
@Override
public CallTarget accessHasSize() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessGetSize() {
return null;
}
@Override
public CallTarget accessUnbox() {
return null;
}
@Override
public CallTarget accessRead() {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignReadSubNode.createRoot());
}
@Override
public CallTarget accessWrite() {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignWriteSubNode.createRoot());
}
@Override
public CallTarget accessRemove() {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignRemoveSubNode.createRoot());
}
@Override
public CallTarget accessExecute(int argumentsLength) {
return null;
}
@Override
public CallTarget accessInvoke(int argumentsLength) {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignInvokeSubNode.createRoot());
}
@Override
public CallTarget accessNew(int argumentsLength) {
return null;
}
@Override
public CallTarget accessKeyInfo() {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignPropertyInfoSubNode.createRoot());
}
@Override
public CallTarget accessKeys() {
return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignPropertiesSubNode.createRoot());
}
@Override
public CallTarget accessIsPointer() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
}
@Override
public CallTarget accessAsPointer() {
return null;
}
@Override
public CallTarget accessToNative() {
return null;
}
@Override
public CallTarget accessMessage(Message unknown) {
return null;
}
/**
* This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignWriteNode}.
*/
public abstract static class SLForeignWriteSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignWriteNode {
public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
@Specialization
protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.Object name, java.lang.Object value) {
return access(receiver, name, value);
}
private static final class WriteRootNode extends RootNode {
protected WriteRootNode() {
super(null);
}
@Child private SLForeignWriteSubNode node = com.oracle.truffle.sl.runtime.SLObjectMessageResolutionForeignFactory.SLForeignWriteSubNodeGen.create();
@Override
public Object execute(VirtualFrame frame) {
Object receiver = ForeignAccess.getReceiver(frame);
Object identifier = ForeignAccess.getArguments(frame).get(0);
Object value = ForeignAccess.getArguments(frame).get(1);
try {
return node.executeWithTarget(frame, receiver, identifier, value);
} catch (UnsupportedSpecializationException e) {
if (e.getNode() instanceof SLForeignWriteSubNode) {
throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
} else {
throw e;
}
}
}
}
public static RootNode createRoot() {
return new WriteRootNode();
}
}
/**
* This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignInvokeNode}.
*/
public abstract static class SLForeignInvokeSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignInvokeNode {
public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
@Specialization
protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.String name, java.lang.Object[] arguments) {
return access(receiver, name, arguments);
}
private static final class INVOKERootNode extends RootNode {
protected INVOKERootNode() {
super(null);
}
@Child private SLForeignInvokeSubNode node = com.oracle.truffle.sl.runtime.SLObjectMessageResolutionForeignFactory.SLForeignInvokeSubNodeGen.create();
@Override
public Object execute(VirtualFrame frame) {
try {
Object receiver = ForeignAccess.getReceiver(frame);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy