Search in sources :

Example 1 with SLFunction

use of com.oracle.truffle.sl.runtime.SLFunction 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 2 with SLFunction

use of com.oracle.truffle.sl.runtime.SLFunction in project graal by oracle.

the class SLCallFunctionsWithBuiltin method runTests.

@Specialization
public SLNull runTests(String startsWith, SLFunction harness) {
    boolean found = false;
    for (SLFunction function : getContext().getFunctionRegistry().getFunctions()) {
        if (function.getName().startsWith(startsWith) && getSource(function) == getSource(harness) && getSource(function) != null) {
            indirectCall.call(harness.getCallTarget(), new Object[] { function });
            found = true;
        }
    }
    if (!found) {
        throw new SLAssertionError("No tests found to execute.", this);
    }
    return SLNull.SINGLETON;
}
Also used : SLFunction(com.oracle.truffle.sl.runtime.SLFunction) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

SLFunction (com.oracle.truffle.sl.runtime.SLFunction)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 NodeInfo (com.oracle.truffle.api.nodes.NodeInfo)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 SLBigNumber (com.oracle.truffle.sl.runtime.SLBigNumber)1