private void TopLevelDoOp(StageScriptOp op)
        {
            int jmpTo;

            switch (op.OpCode)
            {
            case OpCode.NoOp:
                Logger.DefaultLogger.WriteLine("NoOp called at {0}", this.Ptr);
                break;

            case OpCode.Debug:
                jmpTo = this.Stack.Pop().ArgI;
                switch (jmpTo)
                {
                case 0:
                    this.ThrowException("Debug breakpoint");
                    break;

                case 1:
                    this.ThrowException("Stack Dump\n" + this.Stack.ToString());
                    break;

                default:
                    this.ThrowException("Debug called with parameter = " + jmpTo.ToString());
                    break;
                }
                break;

            case OpCode.PushI:
            case OpCode.PushF:
                this.Stack.Push(op.Arg);
                break;

            case OpCode.Dup:
                this.Stack.Push(this.Stack.Top);
                break;

            case OpCode.Pop:
                this.Stack.Pop();
                break;

            case OpCode.Jmp:
                this.Ptr = this.Stack.Pop().ArgI - 1;
                break;

            case OpCode.Jz:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() == 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Jnz:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() != 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Jg:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() > 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Jge:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() >= 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Jl:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() < 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Jle:
                jmpTo = this.Stack.Pop().ArgI - 1;
                if (this.Stack.Cmp() <= 0)
                {
                    this.Ptr = jmpTo;
                }
                break;

            case OpCode.Inc:
                this.Stack.Inc();
                break;

            case OpCode.Dec:
                this.Stack.Dec();
                break;

            case OpCode.Neg:
                this.Stack.Neg();
                break;

            case OpCode.Add:
                this.Stack.Add();
                break;

            case OpCode.Sub:
                this.Stack.Sub();
                break;

            case OpCode.Mult:
                this.Stack.Mult();
                break;

            case OpCode.Div:
                this.Stack.Div();
                break;

            case OpCode.LoopSetup:
                this.LoopEntry = this.Stack.Pop().ArgI;
                this.LoopCount = this.Stack.Pop().ArgI;
                break;

            case OpCode.Loop:
                if (--this.LoopCount > 0)
                {
                    this.Ptr = this.LoopEntry - 1;
                }
                break;

            case OpCode.RandomI:
                this.Stack.Push(new ScriptStackEntry(this.RandI(), 0.0f, false));
                break;

            case OpCode.RandomF:
                this.Stack.Push(new ScriptStackEntry(0, this.RandF(), true));
                break;

            case OpCode.Wait:
                this.Wait = this.Stack.Pop().ArgI;
                break;

            default:
                this.DoOp(op);
                break;
            }
        }
 public StageScriptException(string message, StageScriptOp op, int where)
     : base(string.Format("instr #{0} ({1}): {2}", where, op, message))
 {
     this.Where = where;
 }
 protected abstract void DoOp(StageScriptOp op);