Beispiel #1
0
        VarCtx EnterInterpreter(FuncCtx entry, object[] args)
        {
            var resultHolder = new VarCtx(null, null, null, this);

            try
            {
                Result = Block.CallFunc(resultHolder, entry, args);
            }
            catch (Exception e)
            {
                resultHolder.Break           = VarCtx.BreakMode.Throw;
                resultHolder.ScriptException = new RuntimeException(e.Message, resultHolder);
            }
            if (resultHolder.Break == VarCtx.BreakMode.Throw)
            {
                if (OnException == null)
                {
                    SyncDebug("Unhandleded exception: " + resultHolder.ScriptException);
                }
                else
                {
                    SyncCtx.Send((d) => OnException(-1, resultHolder.ScriptException), null);
                }
            }
            return(resultHolder);
        }
Beispiel #2
0
        public static object DeclareFunc(VarCtx curCtx, Function func)
        {
            var funcCtx = new FuncCtx {
                ParentScope = curCtx, FunctionProto = func
            };

            return(funcCtx);
        }
Beispiel #3
0
 public VarCtx(VarCtx parentOnStack, VarCtx parScope, Block block, Interpreter interp)
 {
     CurBlock      = block;
     ParentOnStack = parentOnStack;
     ParentScope   = parScope;
     Func          = parScope?.Func;
     Interp        = interp;
 }
Beispiel #4
0
        FuncCtx CreateFunc(VarCtx scope, string name, Function func)
        {
            func.Name = name;
            var result = new FuncCtx
            {
                FunctionProto = func,
                ParentScope   = scope
            };

            return(result);
        }
Beispiel #5
0
        public object ContinueScript(int gas)
        {
            if (Terminate)
            {
                if (!firstLogAfterTerminate)
                {
                    firstLogAfterTerminate = true;
                    Debug.LogWarning($"CPU is terminated");
                }
                return(null);
            }
            Result = null;
            Gas    = gas;
            ResumeTask.Set();
            var waitResult = TaskPaused.WaitOne(1000);

            while (waitResult)
            {
                if (cb == null)
                {
                    break; // exit
                }
                // handle sync context
                try
                {
                    cb(state);
                }
                catch (Exception e)
                {
                    cbE = e;
                }
                cb = null;
                ResumeTask.Set();
                waitResult = TaskPaused.WaitOne(1000);
            }
            if (!waitResult)
            {
                Debug.LogError("Fatal: wait CPU FAILED, CPU will be stopped");
                ResumeTask.Set();
                Terminate = true;
            }
            ScriptEntry = null;
            if (Gas == 0)
            {
                return(null);
            }
            return(Result);
        }
Beispiel #6
0
 public StackLocation(FuncCtx f, BuiltExpression e)
 {
     Func = f;
     PC   = e;
 }
Beispiel #7
0
 public void SetScript(FuncCtx func)
 {
     ScriptEntry = func;
 }
Beispiel #8
0
        public void AddExtFunc(FuncCtx root, string name, Func <VarCtx, object[], object> func, bool synchronized)
        {
            var wrap = CreateFunc(root, name, func, synchronized);

            AddExtVariable(root, name, wrap);
        }
Beispiel #9
0
 public FuncCtx CreateFunc(FuncCtx root, string name, Func <VarCtx, object[], object> func, bool synchronized)
 {
     return(synchronized ? CreateSynchronizedFunc(root.ParentScope, name, func) : CreateFunc(root.ParentScope, name, func));
 }
Beispiel #10
0
        public void AddExtVariable(FuncCtx root, string name, object variable)
        {
            var rc = root.ParentScope;

            rc.AddVar(name, variable);
        }
Beispiel #11
0
 public void RegisterIrqHandler(long id, FuncCtx handler)
 {
     InterruptHandlers[id] = handler;
 }