use of com.oracle.truffle.sl.nodes.SLEvalRootNode in project graal by oracle.
the class SLLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source source = request.getSource();
Map<String, RootCallTarget> functions;
/*
* Parse the provided source. At this point, we do not have a SLContext yet. Registration of
* the functions with the SLContext happens lazily in SLEvalRootNode.
*/
if (request.getArgumentNames().isEmpty()) {
functions = Parser.parseSL(this, source);
} else {
StringBuilder sb = new StringBuilder();
sb.append("function main(");
String sep = "";
for (String argumentName : request.getArgumentNames()) {
sb.append(sep);
sb.append(argumentName);
sep = ",";
}
sb.append(") { return ");
sb.append(request.getSource().getCharacters());
sb.append(";}");
Source decoratedSource = Source.newBuilder(sb.toString()).mimeType(request.getSource().getMimeType()).name(request.getSource().getName()).build();
functions = Parser.parseSL(this, decoratedSource);
}
RootCallTarget main = functions.get("main");
RootNode evalMain;
if (main != null) {
/*
* We have a main function, so "evaluating" the parsed source means invoking that main
* function. However, we need to lazily register functions into the SLContext first, so
* we cannot use the original SLRootNode for the main function. Instead, we create a new
* SLEvalRootNode that does everything we need.
*/
evalMain = new SLEvalRootNode(this, main, functions);
} else {
/*
* Even without a main function, "evaluating" the parsed source needs to register the
* functions into the SLContext.
*/
evalMain = new SLEvalRootNode(this, null, functions);
}
return Truffle.getRuntime().createCallTarget(evalMain);
}
use of com.oracle.truffle.sl.nodes.SLEvalRootNode in project graal by oracle.
the class SLLexicalScope method createScope.
// The parameter node should not be assigned
@SuppressWarnings("all")
public static SLLexicalScope createScope(Node node) {
SLBlockNode block = getParentBlock(node);
if (block == null) {
// We're in the root.
block = findChildrenBlock(node);
if (block == null) {
// Corrupted SL AST, no block was found
assert node.getRootNode() instanceof SLEvalRootNode : "Corrupted SL AST under " + node;
return new SLLexicalScope(null, null, (SLBlockNode) null);
}
// node is above the block
node = null;
}
// Test if there is a parent block. If not, we're in the root scope.
SLBlockNode parentBlock = getParentBlock(block);
if (parentBlock == null) {
return new SLLexicalScope(node, block, block.getRootNode());
} else {
return new SLLexicalScope(node, block, parentBlock);
}
}
Aggregations