Example #1
0
        public object Evaluate(int line, Context context, object[] args)
        {
            object result = null;

            if (args.Length != m_argNames.Length)
                throw new EvaluateException(line, "{0} method takes {1}, not {2}.", Name, DoGetArgsStr(m_argNames.Length), DoGetArgsStr(args.Length));

            int depth = context.PushLocals();
            if (depth > 256)
                throw new EvaluateException(line, "Method calls have recursed more than 256 times");

            for (int i = 0; i < args.Length; ++i)
                context.AddLocal(m_argNames[i], args[i]);

            foreach (Statement statement in m_statements)
            {
                try
                {
                    result = statement.Evaluate(context);
                }
                catch (ReturnException e)
                {
                    result = e.Result;
                    break;
                }
            }

            context.PopLocals();

            return result;
        }
Example #2
0
        public override object Evaluate(Context context)
        {
            Log.WriteLine("Refactor Evaluate", "{0}: Let", Line);

            for (int i = 0; i < m_locals.Length; ++i)
            {
                object value = m_values[i].Evaluate(context);
                context.AddLocal(m_locals[i], value);
            }

            object result = null;
            foreach (Statement statement in m_block)
            {
                result = statement.Evaluate(context);
            }

            for (int i = 0; i < m_locals.Length; ++i)
            {
                context.RemoveLocal(m_locals[i]);
            }

            return result;
        }
Example #3
0
        public override object Evaluate(Context context)
        {
            Log.WriteLine("Refactor Evaluate", "{0}: For", Line);

            object result = m_elements.Evaluate(context);

            object[] elements = (object[]) result;
            if (elements == null && result != null)
                throw new EvaluateException(m_elements.Line, "For statement should return a Sequence, but was a {0}.", RefactorType.GetName(result.GetType()));

            result = null;
            if (elements != null)
            {
                foreach (object element in elements)
                {
                    context.AddLocal(m_local, element);

                    if (DoIsValidElement(context))
                    {
                        foreach (Statement statement in m_block)
                        {
                            result = statement.Evaluate(context);
                        }
                    }

                    context.RemoveLocal(m_local);
                }
            }

            return result;
        }