Search in sources :

Example 16 with SLExpressionNode

use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.

the class SLNodeFactory method createBinary.

/**
 * Returns the corresponding subclass of {@link SLExpressionNode} for binary expressions. </br>
 * These nodes are currently not instrumented.
 *
 * @param opToken The operator of the binary expression
 * @param leftNode The left node of the expression
 * @param rightNode The right node of the expression
 * @return A subclass of SLExpressionNode using the given parameters based on the given opToken.
 *         null if either leftNode or rightNode is null.
 */
public SLExpressionNode createBinary(Token opToken, SLExpressionNode leftNode, SLExpressionNode rightNode) {
    if (leftNode == null || rightNode == null) {
        return null;
    }
    final SLExpressionNode leftUnboxed;
    if (leftNode instanceof SLBinaryNode) {
        // SLBinaryNode never returns boxed value
        leftUnboxed = leftNode;
    } else {
        leftUnboxed = SLUnboxNodeGen.create(leftNode);
    }
    final SLExpressionNode rightUnboxed;
    if (rightNode instanceof SLBinaryNode) {
        // SLBinaryNode never returns boxed value
        rightUnboxed = rightNode;
    } else {
        rightUnboxed = SLUnboxNodeGen.create(rightNode);
    }
    final SLExpressionNode result;
    switch(opToken.val) {
        case "+":
            result = SLAddNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "*":
            result = SLMulNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "/":
            result = SLDivNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "-":
            result = SLSubNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "<":
            result = SLLessThanNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "<=":
            result = SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case ">":
            result = SLLogicalNotNodeGen.create(SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case ">=":
            result = SLLogicalNotNodeGen.create(SLLessThanNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case "==":
            result = SLEqualNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "!=":
            result = SLLogicalNotNodeGen.create(SLEqualNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case "&&":
            result = new SLLogicalAndNode(leftUnboxed, rightUnboxed);
            break;
        case "||":
            result = new SLLogicalOrNode(leftUnboxed, rightUnboxed);
            break;
        default:
            throw new RuntimeException("unexpected operation: " + opToken.val);
    }
    int start = leftNode.getSourceCharIndex();
    int length = rightNode.getSourceEndIndex() - start;
    result.setSourceSection(start, length);
    return result;
}
Also used : SLLogicalAndNode(com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLLogicalOrNode(com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode) SLBinaryNode(com.oracle.truffle.sl.nodes.SLBinaryNode)

Example 17 with SLExpressionNode

use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.

the class SLNodeFactory method createWriteProperty.

/**
 * Returns an {@link SLWritePropertyNode} for the given parameters.
 *
 * @param receiverNode The receiver object of the property assignment
 * @param nameNode The name of the property being assigned
 * @param valueNode The value to be assigned
 * @return An SLExpressionNode for the given parameters. null if receiverNode, nameNode or
 *         valueNode is null.
 */
public SLExpressionNode createWriteProperty(SLExpressionNode receiverNode, SLExpressionNode nameNode, SLExpressionNode valueNode) {
    if (receiverNode == null || nameNode == null || valueNode == null) {
        return null;
    }
    final SLExpressionNode result = SLWritePropertyNodeGen.create(receiverNode, nameNode, valueNode);
    final int start = receiverNode.getSourceCharIndex();
    final int length = valueNode.getSourceEndIndex() - start;
    result.setSourceSection(start, length);
    return result;
}
Also used : SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode)

Example 18 with SLExpressionNode

use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.

the class SLNodeFactory method createNumericLiteral.

public SLExpressionNode createNumericLiteral(Token literalToken) {
    SLExpressionNode result;
    try {
        /* Try if the literal is small enough to fit into a long value. */
        result = new SLLongLiteralNode(Long.parseLong(literalToken.val));
    } catch (NumberFormatException ex) {
        /* Overflow of long value, so fall back to BigInteger. */
        result = new SLBigIntegerLiteralNode(new BigInteger(literalToken.val));
    }
    srcFromToken(result, literalToken);
    return result;
}
Also used : SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) BigInteger(java.math.BigInteger) SLLongLiteralNode(com.oracle.truffle.sl.nodes.expression.SLLongLiteralNode) SLBigIntegerLiteralNode(com.oracle.truffle.sl.nodes.expression.SLBigIntegerLiteralNode)

Example 19 with SLExpressionNode

use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.

the class SLNodeFactory method createCall.

/**
 * Returns an {@link SLInvokeNode} for the given parameters.
 *
 * @param functionNode The function being called
 * @param parameterNodes The parameters of the function call
 * @param finalToken A token used to determine the end of the sourceSelection for this call
 * @return An SLInvokeNode for the given parameters. null if functionNode or any of the
 *         parameterNodes are null.
 */
public SLExpressionNode createCall(SLExpressionNode functionNode, List<SLExpressionNode> parameterNodes, Token finalToken) {
    if (functionNode == null || containsNull(parameterNodes)) {
        return null;
    }
    final SLExpressionNode result = new SLInvokeNode(functionNode, parameterNodes.toArray(new SLExpressionNode[parameterNodes.size()]));
    final int startPos = functionNode.getSourceCharIndex();
    final int endPos = finalToken.charPos + finalToken.val.length();
    result.setSourceSection(startPos, endPos - startPos);
    return result;
}
Also used : SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLInvokeNode(com.oracle.truffle.sl.nodes.call.SLInvokeNode)

Aggregations

SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)19 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 SLStringLiteralNode (com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)2 SLReadArgumentNode (com.oracle.truffle.sl.nodes.local.SLReadArgumentNode)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 SLBinaryNode (com.oracle.truffle.sl.nodes.SLBinaryNode)1 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)1 SLInvokeNode (com.oracle.truffle.sl.nodes.call.SLInvokeNode)1 SLBigIntegerLiteralNode (com.oracle.truffle.sl.nodes.expression.SLBigIntegerLiteralNode)1 SLFunctionLiteralNode (com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode)1 SLLogicalAndNode (com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode)1 SLLogicalOrNode (com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode)1 SLLongLiteralNode (com.oracle.truffle.sl.nodes.expression.SLLongLiteralNode)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1