Search in sources :

Example 11 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class SLException method typeError.

/**
 * Provides a user-readable message for run-time type errors. SL is strongly typed, i.e., there
 * are no automatic type conversions of values.
 */
@TruffleBoundary
public static SLException typeError(Node operation, Object... values) {
    StringBuilder result = new StringBuilder();
    result.append("Type error");
    if (operation != null) {
        SourceSection ss = operation.getEncapsulatingSourceSection();
        if (ss != null && ss.isAvailable()) {
            result.append(" at ").append(ss.getSource().getName()).append(" line ").append(ss.getStartLine()).append(" col ").append(ss.getStartColumn());
        }
    }
    result.append(": operation");
    if (operation != null) {
        NodeInfo nodeInfo = SLContext.lookupNodeInfo(operation.getClass());
        if (nodeInfo != null) {
            result.append(" \"").append(nodeInfo.shortName()).append("\"");
        }
    }
    result.append(" not defined for");
    String sep = " ";
    for (int i = 0; i < values.length; i++) {
        Object value = values[i];
        result.append(sep);
        sep = ", ";
        if (value instanceof Long || value instanceof SLBigNumber) {
            result.append("Number ").append(value);
        } else if (value instanceof Boolean) {
            result.append("Boolean ").append(value);
        } else if (value instanceof String) {
            result.append("String \"").append(value).append("\"");
        } else if (value instanceof SLFunction) {
            result.append("Function ").append(value);
        } else if (value == SLNull.SINGLETON) {
            result.append("NULL");
        } else if (value == null) {
            // value is not evaluated because of short circuit evaluation
            result.append("ANY");
        } else {
            result.append(value);
        }
    }
    return new SLException(result.toString(), operation);
}
Also used : SLBigNumber(com.oracle.truffle.sl.runtime.SLBigNumber) NodeInfo(com.oracle.truffle.api.nodes.NodeInfo) SourceSection(com.oracle.truffle.api.source.SourceSection) SLFunction(com.oracle.truffle.sl.runtime.SLFunction) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 12 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class DynamicObjectImpl method delete.

/**
 * @since 0.17 or earlier
 */
@Override
@TruffleBoundary
public boolean delete(Object key) {
    ShapeImpl oldShape = getShape();
    Property existing = oldShape.getProperty(key);
    if (existing != null) {
        oldShape.getLayout().getStrategy().objectRemoveProperty(this, existing, oldShape);
        return true;
    } else {
        return false;
    }
}
Also used : Property(com.oracle.truffle.api.object.Property) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 13 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method lookup.

@Substitute
@TruffleBoundary
static long lookup(@SuppressWarnings("unused") long nativeContext, long library, String name) {
    // clear previous error
    Dlfcn.dlerror();
    PointerBase ret;
    if (library == 0) {
        ret = PosixUtils.dlsym(Dlfcn.RTLD_DEFAULT(), name);
    } else {
        ret = PosixUtils.dlsym(WordFactory.pointer(library), name);
    }
    if (ret.equal(WordFactory.zero())) {
        CompilerDirectives.transferToInterpreter();
        String error = PosixUtils.dlerror();
        if (error != null) {
            throw new UnsatisfiedLinkError(error);
        }
    }
    return ret.rawValue();
}
Also used : PointerBase(org.graalvm.word.PointerBase) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 14 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class TruffleNFISupport method utf8ToJavaString.

@TruffleBoundary
static String utf8ToJavaString(CCharPointer str) {
    if (str.equal(WordFactory.zero())) {
        return null;
    } else {
        UnsignedWord len = SubstrateUtil.strlen(str);
        ByteBuffer buffer = SubstrateUtil.wrapAsByteBuffer(str, (int) len.rawValue());
        return UTF8.decode(buffer).toString();
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) ByteBuffer(java.nio.ByteBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 15 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class LocalNativeScope method pinArray.

@TruffleBoundary
PointerBase pinArray(Object arr) {
    PinnedObject ret = PinnedObject.create(arr);
    pinned[pinCount++] = ret;
    return ret.addressOfArrayElement(0);
}
Also used : PinnedObject(org.graalvm.nativeimage.PinnedObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)49 RootNode (com.oracle.truffle.api.nodes.RootNode)6 Property (com.oracle.truffle.api.object.Property)6 Specialization (com.oracle.truffle.api.dsl.Specialization)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)5 BigInteger (java.math.BigInteger)4 Node (com.oracle.truffle.api.nodes.Node)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 ByteBuffer (java.nio.ByteBuffer)3 Substitute (com.oracle.svm.core.annotate.Substitute)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)2 Source (com.oracle.truffle.api.source.Source)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Assumption (com.oracle.truffle.api.Assumption)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1