Search in sources :

Example 1 with ReferenceDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor in project TrufflePascal by Aspect26.

the class NodeFactory method createReadVariableFromScope.

private ExpressionNode createReadVariableFromScope(String identifier, LexicalScope scope) {
    // TODO: check if it is a constant or a variable
    FrameSlot variableSlot = scope.getLocalSlot(identifier);
    TypeDescriptor type = scope.getIdentifierDescriptor(identifier);
    boolean isLocal = scope == currentLexicalScope;
    boolean isReference = type instanceof ReferenceDescriptor;
    boolean isConstant = type instanceof ConstantDescriptor;
    if (isConstant) {
        ConstantDescriptor constantType = (ConstantDescriptor) type;
        return ReadConstantNodeGen.create(constantType.getValue(), constantType);
    } else if (isLocal) {
        if (isReference) {
            return ReadReferenceVariableNodeGen.create(variableSlot, type);
        } else {
            return ReadLocalVariableNodeGen.create(variableSlot, type);
        }
    } else {
        return ReadGlobalVariableNodeGen.create(variableSlot, type);
    }
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReferenceDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor)

Example 2 with ReferenceDescriptor

use of cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor in project TrufflePascal by Aspect26.

the class NodeFactory method createSimpleAssignment.

private StatementNode createSimpleAssignment(Token identifierToken, ExpressionNode valueNode) {
    String variableIdentifier = this.getIdentifierFromToken(identifierToken);
    FrameSlot frameSlot = this.doLookup(variableIdentifier, LexicalScope::getLocalSlot, true);
    TypeDescriptor targetType = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor, true);
    this.checkTypesAreCompatible(valueNode.getType(), targetType);
    return (targetType instanceof ReferenceDescriptor) ? AssignReferenceNodeGen.create(valueNode, frameSlot) : SimpleAssignmentNodeGen.create(valueNode, frameSlot);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReferenceDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)2 ReferenceDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.ReferenceDescriptor)2