Пример #1
0
 internal override object Evaluate(NameEnvironment environment)
 {
     object e1 = sliceStart.Evaluate(environment);
     object e2 = sliceStop.Evaluate(environment);
     object e3 = sliceStep.Evaluate(environment);
     return Ops.MakeSlice(e1, e2, e3);
 }
Пример #2
0
        public override object Execute(NameEnvironment environment)
        {
            object ret = Statement.NextStatement;

            IEnumerator i = Ops.GetEnumerator(list.Evaluate(environment));

            while (i.MoveNext()) {
                lhs.Assign(i.Current, environment);
                ret = body.Execute(environment);
                if (ret != NextStatement) return ret;
            }

            return ret;
            //			if (else_ != null) {
            //				else_.exec(env);
            //			}
        }
Пример #3
0
 public override object Execute(NameEnvironment environment)
 {
     return NextStatement;
 }
Пример #4
0
 public virtual object Execute(NameEnvironment environment)
 {
     throw new NotImplementedException("execute: " + this);
 }
Пример #5
0
 public override object Execute(NameEnvironment environment)
 {
     object ret = NextStatement;
     while (Ops.IsTrue(test.Evaluate(environment))) {
         ret = body.Execute(environment);
         if (ret != NextStatement) break;
     }
     return ret;
     //			if (else_ != null) {
     //				else_.exec(env);
     //			}
 }
Пример #6
0
 public object MakeFunction(NameEnvironment environment)
 {
     string[] names = SymbolTable.IdsToStrings(makeNames(parameters));
     object[] defaults = Expression.Evaluate(this.defaults, environment);
     return new InterpFunction(names, defaults, Body, environment.Globals);
 }
Пример #7
0
 public override object Execute(NameEnvironment environment)
 {
     return expr.Evaluate(environment);
 }
Пример #8
0
 internal override object Evaluate(NameEnvironment environment)
 {
     return value;
 }
Пример #9
0
 internal override object Evaluate(NameEnvironment environment)
 {
     IDictionary<object, object> dict = Ops.MakeDict(items.Length);
     foreach (SliceExpression s in items) {
         dict[s.SliceStart.Evaluate(environment)] = s.SliceStop.Evaluate(environment);
     }
     return dict;
 }
Пример #10
0
        internal override object Evaluate(NameEnvironment environment)
        {
            object callee = target.Evaluate(environment);

            object[] cargs = new object[args.Length];
            int index = 0;
            foreach (Arg arg in args) {
                if (arg.Name != SymbolTable.Empty) throw new NotImplementedException("keywords");
                cargs[index++] = arg.Expression.Evaluate(environment);
            }

            switch (cargs.Length) {
                case 0: return Ops.Call(callee);
                default: return Ops.Call(callee, cargs);
            }
        }
Пример #11
0
 internal override object Evaluate(NameEnvironment environment)
 {
     object ret = testExpr.Evaluate(environment);
     if (Ops.IsTrue(ret))
         return trueExpr.Evaluate(environment);
     else
         return falseExpr.Evaluate(environment);
 }
Пример #12
0
        internal override object Evaluate(NameEnvironment environment)
        {
            object l = left.Evaluate(environment);
            object r = right.Evaluate(environment);

            return op.Evaluate(l, r);
        }
Пример #13
0
 internal override object Evaluate(NameEnvironment environment)
 {
     return Ops.Repr(expr.Evaluate(environment));
 }
Пример #14
0
 internal override object Evaluate(NameEnvironment environment)
 {
     return Ops.MakeTuple(Evaluate(Items, environment));
 }
Пример #15
0
 internal override object Evaluate(NameEnvironment environment)
 {
     object t = target.Evaluate(environment);
     object i = index.Evaluate(environment);
     return Ops.GetIndex(t, i);
 }
Пример #16
0
 internal static object[] Evaluate(IList<Expression> items, NameEnvironment environment)
 {
     object[] ret = new object[items.Count];
     for (int i = 0; i < items.Count; i++) {
         ret[i] = items[i].Evaluate(environment);
     }
     return ret;
 }
Пример #17
0
 public override object Execute(NameEnvironment environment)
 {
     environment.Set(name.GetString(), MakeFunction(environment));
     return NextStatement;
 }
Пример #18
0
 internal virtual void Assign(object val, NameEnvironment environment)
 {
     throw new NotImplementedException("Assign: " + this);
 }
Пример #19
0
        public override object Execute(NameEnvironment environment)
        {
            Console.Out.Write("print> ");
            foreach (Expression e in exprs) {
                object val = e.Evaluate(environment);
                Ops.PrintComma(environment.Globals.SystemState, val);
            }
            if (!trailingComma) Ops.PrintNewline(environment.Globals.SystemState);

            return NextStatement;
        }
Пример #20
0
 internal virtual object Evaluate(NameEnvironment environment)
 {
     throw new NotImplementedException("Evaluate: " + this);
 }
Пример #21
0
 public override object Execute(NameEnvironment environment)
 {
     object v = rhs.Evaluate(environment);
     foreach (Expression e in lhs) {
         e.Assign(v, environment);
     }
     return NextStatement;
 }
Пример #22
0
 internal override void Assign(object val, NameEnvironment environment)
 {
     object t = target.Evaluate(environment);
     Ops.SetAttr(environment.Globals, t, SymbolTable.StringToId(name.GetString()), val);
 }
Пример #23
0
 public override object Execute(NameEnvironment environment)
 {
     object ret = Statement.NextStatement;
     foreach (Statement stmt in stmts) {
         ret = stmt.Execute(environment);
         if (ret != Statement.NextStatement) break;
     }
     return ret;
 }
Пример #24
0
 internal override object Evaluate(NameEnvironment environment)
 {
     object t = target.Evaluate(environment);
     return Ops.GetAttr(environment.Globals, t, SymbolTable.StringToId(name.GetString()));
 }
Пример #25
0
 public override object Execute(NameEnvironment environment)
 {
     expr.Evaluate(environment);
     return NextStatement;
 }
Пример #26
0
 internal override void Assign(object val, NameEnvironment environment)
 {
     object t = target.Evaluate(environment);
     object i = index.Evaluate(environment);
     Ops.SetIndex(t, i, val);
 }
Пример #27
0
        public override object Execute(NameEnvironment environment)
        {
            Ops.ImportFrom(environment.Globals, root.MakeString(), SymbolTable.IdsToStrings(names));

            return NextStatement;
        }
Пример #28
0
 internal override object Evaluate(NameEnvironment environment)
 {
     object ret = left.Evaluate(environment);
     if (Ops.IsTrue(ret)) return right.Evaluate(environment);
     else return ret;
 }
Пример #29
0
 public override object Execute(NameEnvironment environment)
 {
     foreach (IfStatementTest t in tests) {
         object val = t.Test.Evaluate(environment);
         if (Ops.IsTrue(val)) {
             return t.Body.Execute(environment);
         }
     }
     if (elseStmt != null) {
         return elseStmt.Execute(environment);
     }
     return NextStatement;
 }
Пример #30
0
        internal override void Assign(object val, NameEnvironment environment)
        {
            // Disallow "[] = l", "[], a = l, l", "[[]] = [l]", etc
            if (items.Length == 0) {
                throw Ops.SyntaxError("can't assign to " + EmptySequenceString, "<unknown>",
                    Start.Line, Start.Column, null, 0, IronPython.Hosting.Severity.Error);
            }

            IEnumerator ie = Ops.GetEnumerator(val);

            int leftCount = items.Length;
            object[] values = new object[leftCount];

            int rightCount = Ops.GetEnumeratorValues(ie, ref values);
            if (leftCount != rightCount)
                throw Ops.ValueErrorForUnpackMismatch(leftCount, rightCount);

            for (int i = 0; i < leftCount; i++)
                items[i].Assign(values[i], environment);
        }