// Path: lang/src/main/java/mumbler/truffle/node/MumblerRootNode.java
// public class MumblerRootNode extends RootNode {
//     @Children private final MumblerNode[] bodyNodes;
//     @CompilationFinal public String name;
// 
//     public MumblerRootNode(MumblerLanguage lang, MumblerNode[] bodyNodes,
//             FrameDescriptor frameDescriptor) {
//         super(lang, frameDescriptor);
//         this.bodyNodes = bodyNodes;
//     }
// 
//     @Override
//     @ExplodeLoop
//     public Object execute(VirtualFrame virtualFrame) {
//         int last = this.bodyNodes.length - 1;
//         CompilerAsserts.compilationConstant(last);
//         for (int i=0; i<last; i++) {
//             this.bodyNodes[i].execute(virtualFrame);
//         }
//         return this.bodyNodes[last].execute(virtualFrame);
//     }
// 
//     public static MumblerRootNode create(MumblerLanguage lang, FrameSlot[] argumentNames,
//             MumblerNode[] bodyNodes, FrameDescriptor frameDescriptor) {
//         MumblerNode[] allNodes = new MumblerNode[argumentNames.length
//                                                  + bodyNodes.length];
//         for (int i=0; i<argumentNames.length; i++) {
//             allNodes[i] = DefineNodeGen.create(
//                     new ReadArgumentNode(i), argumentNames[i]);
//         }
//         System.arraycopy(bodyNodes, 0, allNodes,
//                 argumentNames.length, bodyNodes.length);
//         return new MumblerRootNode(lang, allNodes, frameDescriptor);
//     }
// 
//     public void setName(String name) {
//         if (this.name == null) {
//             this.name = name;
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return Arrays.toString(this.bodyNodes);
//     }
// }


import java.util.ArrayList;
import java.util.List;
import mumbler.truffle.node.MumblerRootNode;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
package mumbler.truffle;




/**
 * The base exception for any runtime errors.
 *
 */
public class MumblerException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    public MumblerException(String message) {
        super(message);
    }

    @Override
    public Throwable fillInStackTrace() {
        CompilerAsserts.neverPartOfCompilation();
        return fillInMumblerStackTrace(this);
    }

    public static Throwable fillInMumblerStackTrace(Throwable t) {
        final List<StackTraceElement> stackTrace = new ArrayList<>();
        Truffle.getRuntime().iterateFrames((FrameInstanceVisitor<Void>) frame -> {
            Node callNode = frame.getCallNode();
            if (callNode == null) {
                return null;
            }
            RootNode root = callNode.getRootNode();

            /*
             * There should be no RootNodes other than SLRootNodes on the stack. Just for the
             * case if this would change.
             */
            String methodName = "$unknownFunction";
            if (root instanceof MumblerRootNode) {
// Path: lang/src/main/java/mumbler/truffle/node/MumblerRootNode.java
// public class MumblerRootNode extends RootNode {
//     @Children private final MumblerNode[] bodyNodes;
//     @CompilationFinal public String name;
// 
//     public MumblerRootNode(MumblerLanguage lang, MumblerNode[] bodyNodes,
//             FrameDescriptor frameDescriptor) {
//         super(lang, frameDescriptor);
//         this.bodyNodes = bodyNodes;
//     }
// 
//     @Override
//     @ExplodeLoop
//     public Object execute(VirtualFrame virtualFrame) {
//         int last = this.bodyNodes.length - 1;
//         CompilerAsserts.compilationConstant(last);
//         for (int i=0; i<last; i++) {
//             this.bodyNodes[i].execute(virtualFrame);
//         }
//         return this.bodyNodes[last].execute(virtualFrame);
//     }
// 
//     public static MumblerRootNode create(MumblerLanguage lang, FrameSlot[] argumentNames,
//             MumblerNode[] bodyNodes, FrameDescriptor frameDescriptor) {
//         MumblerNode[] allNodes = new MumblerNode[argumentNames.length
//                                                  + bodyNodes.length];
//         for (int i=0; i<argumentNames.length; i++) {
//             allNodes[i] = DefineNodeGen.create(
//                     new ReadArgumentNode(i), argumentNames[i]);
//         }
//         System.arraycopy(bodyNodes, 0, allNodes,
//                 argumentNames.length, bodyNodes.length);
//         return new MumblerRootNode(lang, allNodes, frameDescriptor);
//     }
// 
//     public void setName(String name) {
//         if (this.name == null) {
//             this.name = name;
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return Arrays.toString(this.bodyNodes);
//     }
// }


// Path: lang/src/main/java/mumbler/truffle/MumblerException.java
import java.util.ArrayList;
import java.util.List;
import mumbler.truffle.node.MumblerRootNode;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

package mumbler.truffle;




/**
 * The base exception for any runtime errors.
 *
 */
public class MumblerException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    public MumblerException(String message) {
        super(message);
    }

    @Override
    public Throwable fillInStackTrace() {
        CompilerAsserts.neverPartOfCompilation();
        return fillInMumblerStackTrace(this);
    }

    public static Throwable fillInMumblerStackTrace(Throwable t) {
        final List<StackTraceElement> stackTrace = new ArrayList<>();
        Truffle.getRuntime().iterateFrames((FrameInstanceVisitor<Void>) frame -> {
            Node callNode = frame.getCallNode();
            if (callNode == null) {
                return null;
            }
            RootNode root = callNode.getRootNode();

            /*
             * There should be no RootNodes other than SLRootNodes on the stack. Just for the
             * case if this would change.
             */
            String methodName = "$unknownFunction";
            if (root instanceof MumblerRootNode) {
                methodName = ((MumblerRootNode) root).name;