Search in sources :

Example 26 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project TrufflePascal by Aspect26.

the class NodeFactory method createForLoop.

public StatementNode createForLoop(boolean ascending, Token variableToken, ExpressionNode startValue, ExpressionNode finalValue, StatementNode loopBody) {
    String iteratingIdentifier = this.getIdentifierFromToken(variableToken);
    FrameSlot controlSlot = this.doLookup(iteratingIdentifier, LexicalScope::getLocalSlot);
    if (controlSlot == null) {
        parser.SemErr("Unknown identifier: " + iteratingIdentifier);
    }
    if (startValue.getType() != finalValue.getType() && !startValue.getType().convertibleTo(finalValue.getType())) {
        parser.SemErr("Type mismatch in beginning and last value of for loop.");
    }
    SimpleAssignmentNode initialAssignment = this.createAssignmentNode(iteratingIdentifier, startValue);
    ExpressionNode readControlVariableNode = this.createReadVariableNode(variableToken);
    return new ForNode(ascending, initialAssignment, controlSlot, finalValue, readControlVariableNode, loopBody);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot)

Example 27 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project TrufflePascal by Aspect26.

the class NodeFactory method createInvokeNode.

private ExpressionNode createInvokeNode(String identifier, SubroutineDescriptor descriptor, LexicalScope subroutineScope, List<ExpressionNode> argumentNodes) {
    ExpressionNode[] arguments = argumentNodes.toArray(new ExpressionNode[argumentNodes.size()]);
    TypeDescriptor returnType = (descriptor instanceof FunctionDescriptor) ? ((FunctionDescriptor) descriptor).getReturnDescriptor() : null;
    if (subroutineScope instanceof UnitLexicalScope) {
        String unitIdentifier = subroutineScope.getName();
        return ContextInvokeNodeGen.create(identifier, unitIdentifier, arguments, returnType);
    } else {
        FrameSlot subroutineSlot = subroutineScope.getLocalSlot(identifier);
        return InvokeNodeGen.create(subroutineSlot, arguments, returnType);
    }
}
Also used : TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.FunctionDescriptor)

Example 28 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project TrufflePascal by Aspect26.

the class FatalError method WithStatement.

StatementNode WithStatement() {
    StatementNode statement;
    Expect(37);
    List<String> recordIdentifiers = IdentifiersList();
    LexicalScope initialScope = factory.getScope();
    List<FrameSlot> recordSlots = factory.stepIntoRecordsScope(recordIdentifiers);
    Expect(38);
    StatementNode innerStatement = Statement();
    factory.setScope(initialScope);
    statement = factory.createWithStatement(recordSlots, innerStatement);
    return statement;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) StatementNode(cz.cuni.mff.d3s.trupple.language.nodes.statement.StatementNode)

Example 29 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.

the class SLLexicalScope method collectVars.

private Map<String, FrameSlot> collectVars(Node varsBlock, Node currentNode) {
    // Variables are slot-based.
    // To collect declared variables, traverse the block's AST and find slots associated
    // with SLWriteLocalVariableNode. The traversal stops when we hit the current node.
    Map<String, FrameSlot> slots = new LinkedHashMap<>(4);
    NodeUtil.forEachChild(varsBlock, new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (node == currentNode) {
                return false;
            }
            // Do not enter any nested blocks.
            if (!(node instanceof SLBlockNode)) {
                boolean all = NodeUtil.forEachChild(node, this);
                if (!all) {
                    return false;
                }
            }
            // Write to a variable is a declaration unless it exists already in a parent scope.
            if (node instanceof SLWriteLocalVariableNode) {
                SLWriteLocalVariableNode wn = (SLWriteLocalVariableNode) node;
                String name = Objects.toString(wn.getSlot().getIdentifier());
                if (!hasParentVar(name)) {
                    slots.put(name, wn.getSlot());
                }
            }
            return true;
        }
    });
    return slots;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) 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) LinkedHashMap(java.util.LinkedHashMap) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 30 with FrameSlot

use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.

the class DebuggerSessionSnippets method clearFrame.

private static void clearFrame(MaterializedFrame frame) {
    FrameDescriptor descriptor = frame.getFrameDescriptor();
    Object value = descriptor.getDefaultValue();
    for (FrameSlot slot : descriptor.getSlots()) {
        frame.setObject(slot, value);
    }
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)47 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)12 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)10 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)7 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Type (com.oracle.truffle.llvm.runtime.types.Type)5 CallTarget (com.oracle.truffle.api.CallTarget)4 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)3 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Frame (com.oracle.truffle.api.frame.Frame)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2