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;
}
Aggregations