Example #1
0
        private ScriptResult _EvaluateExpression(IExpr expr, bool createTempScope, bool hardTerminal = false)
        {
            if (null == expr)
            {
                LogError("Cannot evaluate null expression.");
                return(null);
            }

            StackState stackState = defaultContext.stack.GetState();

            if (createTempScope)
            {
                if (!defaultContext.stack.PushTerminalScope("<Evaluate>", defaultContext, hardTerminal))
                {
                    LogError("_EvaluateExpression: stack overflow");
                    return(null);
                }
            }

            ScriptResult result = new ScriptResult();

            result.value = expr.Evaluate(defaultContext);

            if (defaultContext.IsRuntimeErrorSet())
            {
                defaultContext.stack.RestoreState(stackState);
                if (logCompileErrors)
                {
                    LogError(defaultContext.GetRuntimeErrorString());
                }
                result.runtimeError = defaultContext.control.runtimeError;
                result.success      = false;
                defaultContext.control.Clear();
            }
            else
            {
                result.success = true;
                if (createTempScope)
                {
                    defaultContext.stack.RestoreState(stackState);
                    defaultContext.control.Clear();
                }
            }

            return(result);
        }
Example #2
0
        public bool RestoreState(StackState state)
        {
#if PEBBLE_DEBUG
            Pb.Assert(state.varCount <= _varCount || state.callCount <= _callCount, "TODO: StackState invalid.");
#endif

            while (_varCount > state.varCount)
            {
                Variable var = _varStack[_varCount - 1];
                if (null != var)
                {
                    if (var.unique)
                    {
                        _varStack[_varCount - 1] = null;
                    }
                    else
                    {
                        var.value = null;
                        var.name  = "<deleted>";
                    }
                }
                --_varCount;
            }

            while (state.callCount < _callCount)
            {
                PopScope();
            }

#if PEBBLE_DEBUG
            Pb.Assert(state.callCount == _callCount, "whoops, call count different.");
#endif

#if PEBBLE_TRACESTACK
            TraceLog("RestoreState");
            TraceLog("");
#endif
            return(true);
        }
Example #3
0
        // This clears all variables from the stack and pops all calls.
        // Global variables are not affected.
        public void ClearStack()
        {
            StackState state = new StackState(0, 0);

            RestoreState(state);
        }