Search in sources :

Example 1 with EnumValue

use of cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue in project TrufflePascal by Aspect26.

the class ForNode method createEnumControlInterface.

private ControlInterface createEnumControlInterface(VirtualFrame frame) {
    return new ControlInterface() {

        @Override
        public void increaseControlVariable() throws FrameSlotTypeException {
            EnumValue controlValue = (EnumValue) frame.getObject(controlSlot);
            frame.setObject(controlSlot, controlValue.getNext());
        }

        @Override
        public void decreaseControlVariable() throws FrameSlotTypeException {
            EnumValue controlValue = (EnumValue) frame.getObject(controlSlot);
            frame.setObject(controlSlot, controlValue.getNext());
        }
    };
}
Also used : EnumValue(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue)

Example 2 with EnumValue

use of cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue in project TrufflePascal by Aspect26.

the class ForNode method executeVoid.

@Override
public void executeVoid(VirtualFrame frame) {
    try {
        ControlInterface controlInterface = null;
        switch(controlSlot.getKind()) {
            case Int:
                controlInterface = this.createIntControlInterface(frame);
                break;
            case Long:
                controlInterface = this.createLongControlInterface(frame);
                break;
            case Byte:
                controlInterface = this.createCharControlInterface(frame);
                break;
            case Object:
                Object controlValue = frame.getObject(controlSlot);
                if (controlValue instanceof EnumValue) {
                    controlInterface = this.createEnumControlInterface(frame);
                    break;
                } else {
                    throw new PascalRuntimeException("Unsupported control variable type");
                }
        }
        this.execute(frame, controlInterface, ascending);
    } catch (FrameSlotTypeException | UnexpectedResultException e) {
        throw new PascalRuntimeException("Something went wrong.");
    }
}
Also used : FrameSlotTypeException(com.oracle.truffle.api.frame.FrameSlotTypeException) UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) EnumValue(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)

Aggregations

EnumValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue)2 FrameSlotTypeException (com.oracle.truffle.api.frame.FrameSlotTypeException)1 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)1 PascalRuntimeException (cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)1