Example #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));
 }
            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)));
            }
            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(Global.CreateSyntaxError(Expr.Left, "Invalid assignment left-hand side.")));
                }
                r.Value = _right.Result;
                return(SetResult(r.Value));
            }
            protected override PExpr DoVisit()
            {
                if (IsPendingOrSignal(ref _operand, Expr.Operand))
                {
                    return(PendingOrSignal(_operand));
                }
                RefRuntimeObj r = _operand.Result as RefRuntimeObj;

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

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

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

                r.Value = newValue;
                return(result);
            }
 public Entry(Entry n, RefRuntimeObj o)
 {
     Debug.Assert(o != null);
     Next = n;
     O    = o;
 }
Example #6
0
 /// <summary>
 /// Initializes a new <see cref="Closure"/>.
 /// </summary>
 /// <param name="v">The variable declaration.</param>
 /// <param name="r">The bound reference.</param>
 public Closure(AccessorLetExpr v, RefRuntimeObj r)
 {
     Variable = v;
     Ref      = r;
 }
Example #7
0
 public Entry( Entry n, RefRuntimeObj o )
 {
     Debug.Assert( o != null );
     Next = n;
     O = o;
 }