Exemple #1
0
 protected override PExpr DoVisit()
 {
     if (_nativeEnum == null)
     {
         if (IsPendingOrSignal(ref _generator, Expr.Generator))
         {
             return(PendingOrSignal(_generator));
         }
         var a = _generator.Result.ToNative(Global) as IEnumerable;
         if (a == null)
         {
             return(new PExpr(new RuntimeError(Expr.Generator, "foreach generator is not an IEnumerable.")));
         }
         try
         {
             _nativeEnum = a.GetEnumerator();
         }
         catch (Exception ex)
         {
             return(new PExpr(new RuntimeError(Expr.Generator, ex.Message)));
         }
     }
     for ( ; ;)
     {
         if (_currentVariable == null)
         {
             bool hasNext;
             try
             {
                 hasNext = _nativeEnum.MoveNext();
             }
             catch (Exception ex)
             {
                 return(new PExpr(new RuntimeError(Expr.Generator, ex.Message)));
             }
             if (!hasNext)
             {
                 break;
             }
             _currentVariable = Visitor.ScopeManager.Register(Expr.Variable, _index++);
             _currentVariable.SetValue(Expr.Variable, Global.Create(_nativeEnum.Current));
         }
         if (IsPendingOrSignal(ref _code, Expr.Code))
         {
             return(PendingOrSignal(_code));
         }
         _code = new PExpr();
         Visitor.ScopeManager.Unregister(Expr.Variable);
         _currentVariable = null;
     }
     _nativeEnum = null;
     return(SetResult(RuntimeObj.Undefined));
 }
Exemple #2
0
            protected override PExpr DoVisit()
            {
                if (IsPendingOrSignal(ref _operand, Expr.Operand))
                {
                    return(PendingOrSignal(_operand));
                }
                RefRuntimeObj r = _operand.Result as RefRuntimeObj;

                if (r == null)
                {
                    return(SetResult(new RuntimeError(Expr.Operand, "Invalid increment or decrement operand.")));
                }

                var newValue = DoubleObj.Create(_operand.Result.ToDouble() + (Expr.Plus ? 1.0 : -1.0));

                if (Expr.Prefix)
                {
                    return(SetResult(r.SetValue(Expr, newValue)));
                }
                var result = SetResult(r.Value);

                r.SetValue(Expr, newValue);
                return(result);
            }
            protected override PExpr DoVisit()
            {
                if (IsPendingOrSignal(ref _right, Expr.Right))
                {
                    return(PendingOrSignal(_right));
                }
                if (IsPendingOrSignal(ref _left, Expr.Left))
                {
                    return(PendingOrSignal(_left));
                }
                RefRuntimeObj r = _left.Result as RefRuntimeObj;

                if (r == null)
                {
                    return(SetResult(new RuntimeError(Expr.Left, "Invalid assignment left-hand side.")));
                }
                return(SetResult(r.SetValue(Expr, _right.Result)));
            }