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