Ejemplo n.º 1
0
        public override DynValue Visit(PostIncrementationNode postIncrementationNode)
        {
            DynValue retVal = null;
            var      name   = postIncrementationNode.Variable.Name;

            if (CallStack.Count > 0)
            {
                var stackTop = CallStack.Peek();

                if (stackTop.ParameterScope.ContainsKey(name))
                {
                    retVal = stackTop.ParameterScope[name].Copy();
                    stackTop.ParameterScope[name] = new DynValue(retVal.Number + 1);
                }
                else if (stackTop.LocalVariableScope.ContainsKey(name))
                {
                    retVal = stackTop.LocalVariableScope[name].Copy();
                    stackTop.LocalVariableScope[name] = new DynValue(retVal.Number + 1);
                }
                else if (Environment.Globals.ContainsKey(name))
                {
                    retVal = Environment.Globals[name].Copy();
                    Environment.Globals[name] = new DynValue(retVal.Number + 1);
                }
                else
                {
                    throw new RuntimeException($"The referenced variable '{name}' was never defined.",
                                               postIncrementationNode.Line);
                }
            }
            else
            {
                if (!Environment.Globals.ContainsKey(name))
                {
                    throw new RuntimeException($"The referenced variable '{name}' was never defined.",
                                               postIncrementationNode.Line);
                }

                retVal = Environment.Globals[name].Copy();
                Environment.Globals[name] = new DynValue(retVal.Number + 1);
            }

            Debug.Assert(retVal != null, "PostIncrementation -- internal interpreter failure: retVal == null?!");
            return(retVal);
        }
Ejemplo n.º 2
0
 public abstract DynValue Visit(PostIncrementationNode postIncrementationNode);