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); }
public static object DeclareFunc(VarCtx curCtx, Function func) { var funcCtx = new FuncCtx { ParentScope = curCtx, FunctionProto = func }; return(funcCtx); }
public VarCtx(VarCtx parentOnStack, VarCtx parScope, Block block, Interpreter interp) { CurBlock = block; ParentOnStack = parentOnStack; ParentScope = parScope; Func = parScope?.Func; Interp = interp; }
FuncCtx CreateFunc(VarCtx scope, string name, Function func) { func.Name = name; var result = new FuncCtx { FunctionProto = func, ParentScope = scope }; return(result); }
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); }
public StackLocation(FuncCtx f, BuiltExpression e) { Func = f; PC = e; }
public void SetScript(FuncCtx func) { ScriptEntry = func; }
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); }
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)); }
public void AddExtVariable(FuncCtx root, string name, object variable) { var rc = root.ParentScope; rc.AddVar(name, variable); }
public void RegisterIrqHandler(long id, FuncCtx handler) { InterruptHandlers[id] = handler; }