use of com.oracle.truffle.sl.nodes.SLStatementNode in project graal by oracle.
the class SLLexicalScope method collectArgs.
private static Map<String, FrameSlot> collectArgs(Node block) {
// Arguments are pushed to frame slots at the beginning of the function block.
// To collect argument slots, search for SLReadArgumentNode inside of
// SLWriteLocalVariableNode.
Map<String, FrameSlot> args = new LinkedHashMap<>(4);
NodeUtil.forEachChild(block, new NodeVisitor() {
// The current write node containing a slot
private SLWriteLocalVariableNode wn;
@Override
public boolean visit(Node node) {
// When there is a write node, search for SLReadArgumentNode among its children:
if (node instanceof SLWriteLocalVariableNode) {
wn = (SLWriteLocalVariableNode) node;
boolean all = NodeUtil.forEachChild(node, this);
wn = null;
return all;
} else if (wn != null && (node instanceof SLReadArgumentNode)) {
FrameSlot slot = wn.getSlot();
String name = Objects.toString(slot.getIdentifier());
assert !args.containsKey(name) : name + " argument exists already.";
args.put(name, slot);
return true;
} else if (wn == null && (node instanceof SLStatementNode)) {
// A different SL node - we're done.
return false;
} else {
return NodeUtil.forEachChild(node, this);
}
}
});
return args;
}
use of com.oracle.truffle.sl.nodes.SLStatementNode in project graal by oracle.
the class FatalError method Statement.
SLStatementNode Statement(boolean inLoop) {
SLStatementNode result;
result = null;
switch(la.kind) {
case 14:
{
result = WhileStatement();
break;
}
case 10:
{
Get();
if (inLoop) {
result = factory.createBreak(t);
} else {
SemErr("break used outside of loop");
}
Expect(11);
break;
}
case 12:
{
Get();
if (inLoop) {
result = factory.createContinue(t);
} else {
SemErr("continue used outside of loop");
}
Expect(11);
break;
}
case 15:
{
result = IfStatement(inLoop);
break;
}
case 17:
{
result = ReturnStatement();
break;
}
case 1:
case 2:
case 3:
case 5:
{
result = Expression();
Expect(11);
break;
}
case 13:
{
Get();
result = factory.createDebugger(t);
Expect(11);
break;
}
default:
SynErr(35);
break;
}
return result;
}
use of com.oracle.truffle.sl.nodes.SLStatementNode in project graal by oracle.
the class FatalError method WhileStatement.
SLStatementNode WhileStatement() {
SLStatementNode result;
Expect(14);
Token whileToken = t;
Expect(5);
SLExpressionNode condition = Expression();
Expect(7);
SLStatementNode body = Block(true);
result = factory.createWhile(whileToken, condition, body);
return result;
}
use of com.oracle.truffle.sl.nodes.SLStatementNode in project graal by oracle.
the class SLNodeFactory method finishFunction.
public void finishFunction(SLStatementNode bodyNode) {
if (bodyNode == null) {
// a state update that would otherwise be performed by finishBlock
lexicalScope = lexicalScope.outer;
} else {
methodNodes.add(bodyNode);
final int bodyEndPos = bodyNode.getSourceEndIndex();
final SourceSection functionSrc = source.createSection(functionStartPos, bodyEndPos - functionStartPos);
final SLStatementNode methodBlock = finishBlock(methodNodes, functionBodyStartPos, bodyEndPos - functionBodyStartPos);
assert lexicalScope == null : "Wrong scoping of blocks in parser";
final SLFunctionBodyNode functionBodyNode = new SLFunctionBodyNode(methodBlock);
functionBodyNode.setSourceSection(functionSrc.getCharIndex(), functionSrc.getCharLength());
final SLRootNode rootNode = new SLRootNode(language, frameDescriptor, functionBodyNode, functionSrc, functionName);
allFunctions.put(functionName, Truffle.getRuntime().createCallTarget(rootNode));
}
functionStartPos = 0;
functionName = null;
functionBodyStartPos = 0;
parameterCount = 0;
frameDescriptor = null;
lexicalScope = null;
}
Aggregations