Search in sources :

Example 1 with PascalRuntimeException

use of cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException in project TrufflePascal by Aspect26.

the class WithNode method executeVoid.

@Override
public void executeVoid(VirtualFrame frame) {
    try {
        for (FrameSlot recordSlot : this.recordSlots) {
            RecordValue record = (RecordValue) frame.getObject(recordSlot);
            frame = record.getFrame();
        }
        innerStatement.executeVoid(frame);
    } catch (FrameSlotTypeException e) {
        throw new PascalRuntimeException("Unexpected accessing of non record type");
    }
}
Also used : FrameSlotTypeException(com.oracle.truffle.api.frame.FrameSlotTypeException) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) RecordValue(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.RecordValue) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)

Example 2 with PascalRuntimeException

use of cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException in project TrufflePascal by Aspect26.

the class LexicalScope method registerBuiltinSubroutine.

public void registerBuiltinSubroutine(String identifier, SubroutineDescriptor descriptor) {
    try {
        this.localIdentifiers.addSubroutine(identifier, descriptor);
        PascalLanguage.INSTANCE.findContext().updateSubroutine(this.name, identifier, descriptor.getRootNode());
    } catch (LexicalException e) {
        throw new PascalRuntimeException("Could not register builtin subroutine: " + identifier);
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)

Example 3 with PascalRuntimeException

use of cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException in project TrufflePascal by Aspect26.

the class StringBuiltinUnit method importTo.

@Override
public void importTo(UnitLexicalScope scope) {
    super.importTo(scope);
    try {
        scope.registerType("pchar", new PointerDescriptor(PCharDesriptor.getInstance()));
    } catch (LexicalException e) {
        throw new PascalRuntimeException("Could not import string unit: " + e.getMessage());
    }
    scope.markAllIdentifiersPublic();
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException) PointerDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)

Example 4 with PascalRuntimeException

use of cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException in project TrufflePascal by Aspect26.

the class ReadBuiltinNode method readChar.

private char readChar(FileValue file) throws IOException {
    if (file == null) {
        Pattern delimiterPattern = this.input.delimiter();
        this.input.useDelimiter("");
        char value = this.input.next().charAt(0);
        this.input.useDelimiter(delimiterPattern);
        return value;
    } else {
        try {
            Object obj = file.read();
            return (char) obj;
        } catch (ClassCastException e) {
            // TODO: custom exception?
            throw new PascalRuntimeException("Object in a file is not a character");
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)

Example 5 with PascalRuntimeException

use of cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException in project TrufflePascal by Aspect26.

the class ReadBuiltinNode method readOneToReference.

private void readOneToReference(FileValue file, Reference reference) {
    try {
        switch(reference.getFrameSlot().getKind()) {
            case Int:
                int intValue = readInt(file);
                this.setReferenceInt(reference, intValue);
                break;
            case Byte:
                char charValue = readChar(file);
                this.setReferenceChar(reference, charValue);
                break;
            case Double:
                double doubleValue = readDouble(file);
                this.setReferenceDouble(reference, doubleValue);
                break;
            case Long:
                long longValue = readLong(file);
                this.setReferenceLong(reference, longValue);
                break;
            case Object:
                Object objectValue = readObject(file, reference);
                this.setReferenceObject(reference, objectValue);
                break;
            default:
                throw new PascalRuntimeException("Wrong value passed to read.");
        }
    } catch (IOException e) {
        throw new CantReadInputException(e);
    }
}
Also used : CantReadInputException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.CantReadInputException) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException) IOException(java.io.IOException)

Aggregations

PascalRuntimeException (cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)8 FrameSlotTypeException (com.oracle.truffle.api.frame.FrameSlotTypeException)3 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)1 EnumValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.EnumValue)1 FileValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.FileValue)1 RecordValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.RecordValue)1 CantReadInputException (cz.cuni.mff.d3s.trupple.language.runtime.exceptions.CantReadInputException)1 PointerDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)1 AssignSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.AssignSubroutineDescriptor)1 RandomSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomSubroutineDescriptor)1 RandomizeSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomizeSubroutineDescriptor)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1