//
// InternalPorcEError.java -- Java class InternalPorcEError
// Project PorcE
//
// Copyright (c) 2017 The University of Texas at Austin. All rights reserved.
//
// Use and redistribution of this file is governed by the license terms in
// the LICENSE file found in the project's top-level directory and also found at
// URL: http://orc.csres.utexas.edu/license.shtml .
//

package orc.run.porce;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.UnexpectedResultException;

/** 
 * An exception representing an internal non-recoverable error in PorcE.
 * 
 * This class also has utility functions to throw the internal exceptions.
 * 
 * @author amp
 */
public class InternalPorcEError extends Error {
    private static final long serialVersionUID = 269299963113819157L;

    public InternalPorcEError(final Throwable e) {
        super(e);
    }

    public InternalPorcEError(final String msg, final Throwable e) {
        super(msg, e);
    }

    public InternalPorcEError(final String msg) {
        super(msg);
    }

    @TruffleBoundary
    public static InternalPorcEError typeError(final PorcENode n, final UnexpectedResultException e) {
        CompilerDirectives.transferToInterpreter();
        throw new InternalPorcEError("Received illegal value '" + e.getResult() + "' as some parameter in '" + n.porcNode() + "'.", e);
    }

    @TruffleBoundary
    public static InternalPorcEError typeError(final PorcENode n, final Exception e) {
        CompilerDirectives.transferToInterpreter();
        throw new InternalPorcEError("Received illegal value '" + e + "' as some parameter in '" + n.porcNode() + "'.", e);
    }

    @TruffleBoundary
    public static InternalPorcEError capturedLengthError(final int slotsLen, final int capturedsLen) {
        throw new InternalPorcEError("captureds array is the wrong length: expected len = " + slotsLen + ", provided len = " + capturedsLen);
    }

    @TruffleBoundary
    public static InternalPorcEError unreachable(final PorcENode n) {
        CompilerDirectives.transferToInterpreter();
        throw new InternalPorcEError("Code should be unreachable in " + n.porcNode() + "'.");
    }
}

@@ -576,18 +576,17 @@
 on;%0A%0A/**
- 
 %0A
+
  * An ex
@@ -648,25 +648,24 @@
 in PorcE.%0A *
- 
 %0A * This cla
@@ -730,17 +730,16 @@
 ions.%0A *
- 
 %0A * @aut
@@ -1121,37 +1121,16 @@
 %0A    %7D%0A%0A
-    @TruffleBoundary%0A
     publ
@@ -1419,37 +1419,16 @@
 %0A    %7D%0A%0A
-    @TruffleBoundary%0A
     publ
@@ -1689,37 +1689,16 @@
 %0A    %7D%0A%0A
-    @TruffleBoundary%0A
     publ
@@ -1788,24 +1788,76 @@
 uredsLen) %7B%0A
+        CompilerDirectives.transferToInterpreter();%0A
         thro
@@ -1997,29 +1997,8 @@
  %7D%0A%0A
-    @TruffleBoundary%0A
     

Improve total failure handling.