Search in sources :

Example 1 with SLStringLiteralNode

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

the class SLNodeFactory method createRead.

/**
 * Returns a {@link SLReadLocalVariableNode} if this read is a local variable or a
 * {@link SLFunctionLiteralNode} if this read is global. In SL, the only global names are
 * functions.
 *
 * @param nameNode The name of the variable/function being read
 * @return either:
 *         <ul>
 *         <li>A SLReadLocalVariableNode representing the local variable being read.</li>
 *         <li>A SLFunctionLiteralNode representing the function definition.</li>
 *         <li>null if nameNode is null.</li>
 *         </ul>
 */
public SLExpressionNode createRead(SLExpressionNode nameNode) {
    if (nameNode == null) {
        return null;
    }
    String name = ((SLStringLiteralNode) nameNode).executeGeneric(null);
    final SLExpressionNode result;
    final FrameSlot frameSlot = lexicalScope.locals.get(name);
    if (frameSlot != null) {
        /* Read of a local variable. */
        result = SLReadLocalVariableNodeGen.create(frameSlot);
    } else {
        /* Read of a global name. In our language, the only global names are functions. */
        result = new SLFunctionLiteralNode(language, name);
    }
    result.setSourceSection(nameNode.getSourceCharIndex(), nameNode.getSourceLength());
    return result;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLFunctionLiteralNode(com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLStringLiteralNode(com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)

Example 2 with SLStringLiteralNode

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

the class SLNodeFactory method createAssignment.

/**
 * Returns an {@link SLWriteLocalVariableNode} for the given parameters.
 *
 * @param nameNode The name of the variable being assigned
 * @param valueNode The value to be assigned
 * @return An SLExpressionNode for the given parameters. null if nameNode or valueNode is null.
 */
public SLExpressionNode createAssignment(SLExpressionNode nameNode, SLExpressionNode valueNode) {
    if (nameNode == null || valueNode == null) {
        return null;
    }
    String name = ((SLStringLiteralNode) nameNode).executeGeneric(null);
    FrameSlot frameSlot = frameDescriptor.findOrAddFrameSlot(name);
    lexicalScope.locals.put(name, frameSlot);
    final SLExpressionNode result = SLWriteLocalVariableNodeGen.create(valueNode, frameSlot);
    if (valueNode.hasSource()) {
        final int start = nameNode.getSourceCharIndex();
        final int length = valueNode.getSourceEndIndex() - start;
        result.setSourceSection(start, length);
    }
    return result;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLStringLiteralNode(com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)

Example 3 with SLStringLiteralNode

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

the class SLNodeFactory method createStringLiteral.

public SLExpressionNode createStringLiteral(Token literalToken, boolean removeQuotes) {
    /* Remove the trailing and ending " */
    String literal = literalToken.val;
    if (removeQuotes) {
        assert literal.length() >= 2 && literal.startsWith("\"") && literal.endsWith("\"");
        literal = literal.substring(1, literal.length() - 1);
    }
    final SLStringLiteralNode result = new SLStringLiteralNode(literal.intern());
    srcFromToken(result, literalToken);
    return result;
}
Also used : SLStringLiteralNode(com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)

Aggregations

SLStringLiteralNode (com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)2 SLFunctionLiteralNode (com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode)1