Example #1
0
        private void ExecuteInstruction(VMStackFrame frame)
        {
            var instruction = frame.GetCurrentInstruction();
            var opcode      = instruction.Opcode;

            if (opcode >= 256)
            {
                BHAV bhav = null;

                GameIffResource CodeOwner;
                if (opcode >= 8192)
                {
                    CodeOwner = frame.Callee.SemiGlobal.Resource;
                    bhav      = frame.Callee.SemiGlobal.Resource.Get <BHAV>(opcode);
                }
                else if (opcode >= 4096)
                {
                    /** Private sub-routine call **/
                    CodeOwner = frame.CalleePrivate;
                    bhav      = frame.CalleePrivate.Get <BHAV>(opcode);
                }
                else
                {
                    /** Global sub-routine call **/
                    CodeOwner = frame.Global.Resource;
                    bhav      = frame.Global.Resource.Get <BHAV>(opcode);
                }

                var operand = frame.GetCurrentOperand <VMSubRoutineOperand>();
                ExecuteSubRoutine(frame, bhav, CodeOwner, operand);
                NextInstruction();
                return;
            }


            var primitive = Context.GetPrimitive(opcode);

            if (primitive == null)
            {
                throw new Exception("Unknown primitive!");
                //HandleResult(frame, instruction, VMPrimitiveExitCode.GOTO_TRUE);
                //return;
                //Pop(VMPrimitiveExitCode.ERROR);
            }

            VMPrimitiveHandler handler = primitive.GetHandler();
            var result = handler.Execute(frame);

            HandleResult(frame, instruction, result);
        }
 public VMPrimitiveRegistration(VMPrimitiveHandler handler)
 {
     this.Handler = handler;
 }
 public VMPrimitiveRegistration(VMPrimitiveHandler handler)
 {
     this.Handler = handler;
 }