Beispiel #1
0
        void InitialCall(Executable exe)
        {
            _callStack.Clear();
            _dataStack.Clear();

            Constants = exe.Constants;

            // 为了防止用户在Executable new之后添加其他的函数
            // 所以链接过程在第一次调用时, 虽然耗时
            _entryList = exe.GenEntryList();

            // 将指令中所有的entry互相链接
            exe.LinkEntryPoint();

            // 依赖包按依赖顺序初始化
            for (int i = 0; i < exe.PackageCount; i++)
            {
                var pkg = exe.GetPackage(i);

                // 已经创建过了
                if (i < _package.Count)
                {
                    continue;
                }

                var rtPkg = new RuntimePackage(pkg);

                _package.Add(rtPkg);

                if (pkg.InitEntry != null)
                {
                    // 执行包的全局入口( 只会还行一次)
                    ExecuteFunc(exe, rtPkg, pkg.InitEntry, 0, 0);
                }
            }
        }
 internal virtual void OnSerializeDone(Executable exe)
 {
 }
Beispiel #3
0
 internal override void OnSerializeDone(Executable exe)
 {
     Parent = exe.FindClassByPersistantID(ParentID);
 }
Beispiel #4
0
        public static void Serialize(Stream stream, ref Executable exe, bool loading)
        {
            var bs = new BinarySerializer(stream, loading);

            bs.Serialize <Executable>(ref exe);
        }
Beispiel #5
0
 public Parser(Executable exe, ContentLoader loader, ScopeManager scopemgr)
 {
     _exe      = exe;
     _loader   = loader;
     _scopemgr = scopemgr;
 }
Beispiel #6
0
        public void Execute(Executable exe)
        {
            _exe = exe;

            InitialCall(exe);
        }
Beispiel #7
0
        internal void ExecuteFunc(Executable exe, RuntimePackage rtpkg, ValuePhoFunc func, int argCount, int retValueCount)
        {
            if (func.Commands.Count == 0)
            {
                return;
            }

            if (ShowDebugInfo)
            {
                Logger.DebugLine(string.Format("============ Run '{0}' ============", func.Name));
            }

            rtpkg.Reg.SetCount(func.RegCount);

            EnterFrame(func);

            CurrFrame.ReceiverCount = retValueCount;

            // 数据栈转寄存器
            if (argCount > 0)
            {
                MoveArgStack2Local(argCount);
                _dataStack.Clear();
            }

            int currSrcLine = 0;

            _state = State.Running;

            while (true)
            {
                var cmd = CurrFrame.GetCurrCommand();
                if (cmd == null)
                {
                    break;
                }

                if (ShowDebugInfo)
                {
                    Logger.DebugLine("{0}|{1}", cmd.CodePos, exe.QuerySourceLine(cmd.CodePos));
                    Logger.DebugLine("---------------------");
                    Logger.DebugLine("{0,5} {1,2}| {2} {3}", _currFrame.Func.Name, _currFrame.PC, cmd.Op.ToString(), _insset.InstructToString(cmd));
                }

                // 源码行有变化时
                if (currSrcLine == 0 || currSrcLine != cmd.CodePos.Line)
                {
                    if (currSrcLine != 0)
                    {
                        CallHook(DebugHook.SourceLine);
                    }

                    currSrcLine = cmd.CodePos.Line;
                }


                // 每条指令执行前
                CallHook(DebugHook.AssemblyLine);

                if (_insset.ExecCode(this, cmd))
                {
                    if (_currFrame == null)
                    {
                        break;
                    }

                    _currFrame.PC++;
                }

                // 打印执行完后的信息
                if (ShowDebugInfo)
                {
                    rtpkg.Reg.DebugPrint();

                    // 寄存器信息
                    LocalReg.DebugPrint();


                    // 数据栈信息
                    DataStack.DebugPrint();

                    Logger.DebugLine("");
                }
            }


            if (ShowDebugInfo)
            {
                Logger.DebugLine("============ VM End ============");
            }
        }
Beispiel #8
0
 internal static void Register(Executable exe)
 {
     exe.RegisterNativeClass(Assembly.GetExecutingAssembly(), "Photon.ArrayWrapper", "Builtin");
 }
Beispiel #9
0
 internal virtual void DebugPrint(Executable exe)
 {
 }