Search in sources :

Example 6 with SLStatementNode

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;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) LinkedHashMap(java.util.LinkedHashMap) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 7 with SLStatementNode

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;
}
Also used : SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode)

Example 8 with SLStatementNode

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;
}
Also used : SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode)

Example 9 with SLStatementNode

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;
}
Also used : SLFunctionBodyNode(com.oracle.truffle.sl.nodes.controlflow.SLFunctionBodyNode) SourceSection(com.oracle.truffle.api.source.SourceSection) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode)

Aggregations

SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)9 SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)3 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)2 ArrayList (java.util.ArrayList)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 Node (com.oracle.truffle.api.nodes.Node)1 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)1 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)1 SLFunctionBodyNode (com.oracle.truffle.sl.nodes.controlflow.SLFunctionBodyNode)1 LinkedHashMap (java.util.LinkedHashMap)1