示例#1
0
        protected override void Initialize()
        {
            base.Initialize();
            z_io = new Common.ZIO(this);
            z_frame = new ZMachine.Common.ZCallFrame(z_memory.Header.InitialPC);
            z_objtable = new v3.ZObjectTable(z_memory);
            z_dict = new v3.ZDictionary(z_memory as v3.ZMemory);
            z_instruct = new v3.ZInstruction(z_memory as v3.ZMemory);

            Initialized = true;
        }
示例#2
0
        protected virtual void Call(IZInstruction inst, bool store)
        {
            int newPC = UnpackAddress(inst.Operands[0]); // Unpack PC

            if (newPC == 0)
            {
                z_memory.PutVariable(inst.Result, 0);
                return;
            }

            int numArgs = inst.OperandCount - 1;

            // Store snapshot of locals array to be restored later
            z_frame.Locals = z_memory.Locals;

            short[] newLocals = new short[16];
            int numVars = z_memory.GetByte(newPC++);

            if (z_memory.Header.VersionNumber < 5)
            {
                for (int i = 0; i < numVars; i++)
                {
                    newLocals[i + 1] = z_memory.GetWord(newPC);
                    newPC += 2;
                }
            }

            for (int i = 1; i < inst.OperandCount; i++)
            {
                newLocals[i] = inst.Operands[i];
            }

            ZMachine.Common.ZCallFrame frame = new ZMachine.Common.ZCallFrame(newPC) { PrevCallFrame = z_frame, FrameNumber = z_frame.FrameNumber + 1 };

            if (store)
                frame.Result = inst.Result;

            if (numArgs > numVars)
                frame.ArgCount = numVars;
            else
                frame.ArgCount = numArgs;

            // Set z_frame variable to the newly created frame instance
            z_frame = frame;

            z_memory.Locals = newLocals;
        }