Search in sources :

Example 1 with SLFunctionLiteralNode

use of com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode 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)

Aggregations

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