Exemplo n.º 1
0
 public static object Iter(object func, object sentinel)
 {
     if (PythonOperator.IsCallable(func) == Ops.FALSE)
     {
         throw Ops.TypeError("iter(v, w): v must be callable");
     }
     return(new SentinelIterator(func, sentinel));
 }
Exemplo n.º 2
0
        public static object Eval(ICallerContext context, string expression, IDictionary <object, object> globals, object locals)
        {
            if (locals != null && PythonOperator.IsMappingType(context, locals) == Ops.FALSE)
            {
                throw Ops.TypeError("locals must be mapping");
            }

            CompilerContext cc = context.CreateCompilerContext();
            Parser          p  = Parser.FromString(context.SystemState, cc, expression.TrimStart(' ', '\t'));
            Expr            e  = p.ParseTestListAsExpression();

            PythonModule mod = new PythonModule("<eval>", globals, context.SystemState, null, context.ContextFlags);

            if (Options.FastEval)  //!!! experimenting with a HUGE (>100x) performance boost to simple evals
            {
                return(e.Evaluate(new NameEnv(mod, locals)));
            }
            else
            {
                Stmt      s  = new ReturnStmt(e);
                FrameCode fc = OutputGenerator.GenerateSnippet(cc, s, false);
                return(fc.Run(new Frame(mod, globals, locals)));
            }
        }