dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Jsc ForIn.cs,1.1,1.2 Numeric


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Jsc ForIn.cs,1.1,1.2 NumericBinary.cs,1.1,1.2 NumericUnary.cs,1.1,1.2
Date: Tue, 21 Jan 2003 17:11:51 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/JScript/Jsc
In directory subversions:/tmp/cvs-serv20060/JScript/Jsc

Modified Files:
        ForIn.cs NumericBinary.cs NumericUnary.cs 
Log Message:


Implement function calls; "for-in" statements; variable declarations;
property enums.


Index: ForIn.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Jsc/ForIn.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ForIn.cs    13 Jan 2003 10:53:19 -0000      1.1
--- ForIn.cs    21 Jan 2003 22:11:49 -0000      1.2
***************
*** 35,41 ****
        public static IEnumerator JScriptGetEnumerator(Object coll)
                        {
!                               // TODO
!                               return null;
                        }
  
  }; // class ForIn
--- 35,105 ----
        public static IEnumerator JScriptGetEnumerator(Object coll)
                        {
!                               if(coll is IEnumerator)
!                               {
!                                       return (IEnumerator)coll;
!                               }
!                               else if(coll is ScriptObject)
!                               {
!                                       return 
((ScriptObject)coll).GetPropertyEnumerator();
!                               }
!                               else if(coll is Array)
!                               {
!                                       Array array = (Array)coll;
!                                       return new 
ArrayIndexEnumerator(array.GetLowerBound(0),
!                                                                               
                        array.GetUpperBound(0));
!                               }
!                               else if(coll is IEnumerable)
!                               {
!                                       IEnumerator e = 
((IEnumerable)coll).GetEnumerator();
!                                       if(e == null)
!                                       {
!                                               return new NullEnumerator();
!                                       }
!                                       else
!                                       {
!                                               return e;
!                                       }
!                               }
!                               else
!                               {
!                                       throw new 
JScriptException(JSError.NotCollection);
!                               }
                        }
+ 
+       // Enumerator class for indexes in an array range.
+       private sealed class ArrayIndexEnumerator : IEnumerator
+       {
+               // Internal state.
+               private int lower;
+               private int upper;
+               private int current;
+ 
+               // Constructor.
+               public ArrayIndexEnumerator(int lower, int upper)
+                               {
+                                       this.lower = lower;
+                                       this.upper = upper;
+                                       this.current = lower - 1;
+                               }
+ 
+               // Implement the IEnumerator interface.
+               public bool MoveNext()
+                               {
+                                       ++current;
+                                       return (current <= upper);
+                               }
+               public void Reset()
+                               {
+                                       current = lower - 1;
+                               }
+               public Object Current
+                               {
+                                       get
+                                       {
+                                               return current;
+                                       }
+                               }
+ 
+       }; // class ArrayIndexEnumerator
  
  }; // class ForIn

Index: NumericBinary.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Jsc/NumericBinary.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** NumericBinary.cs    13 Jan 2003 10:53:20 -0000      1.1
--- NumericBinary.cs    21 Jan 2003 22:11:49 -0000      1.2
***************
*** 38,43 ****
        public Object EvaluateNumericBinary(Object v1, Object v2)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 38,42 ----
        public Object EvaluateNumericBinary(Object v1, Object v2)
                        {
!                               return DoOp(v1, v2, operatorTok);
                        }
  
***************
*** 45,50 ****
        public static Object DoOp(Object v1, Object v2, JSToken operatorTok)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 44,76 ----
        public static Object DoOp(Object v1, Object v2, JSToken operatorTok)
                        {
!                               double n1 = Convert.ToNumber(v1);
!                               double n2 = Convert.ToNumber(v2);
!                               switch(operatorTok)
!                               {
!                                       case JSToken.Minus:
!                                       {
!                                               return (n1 - n2);
!                                       }
!                                       // Not reached.
!                       
!                                       case JSToken.Multiply:
!                                       {
!                                               return (n1 * n2);
!                                       }
!                                       // Not reached.
!                       
!                                       case JSToken.Divide:
!                                       {
!                                               return (n1 / n2);
!                                       }
!                                       // Not reached.
!                       
!                                       case JSToken.Modulo:
!                                       {
!                                               return (n1 % n2);
!                                       }
!                                       // Not reached.
!                               }
!                               throw new 
JScriptException(JSError.InternalError);
                        }
  

Index: NumericUnary.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Jsc/NumericUnary.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** NumericUnary.cs     13 Jan 2003 10:53:20 -0000      1.1
--- NumericUnary.cs     21 Jan 2003 22:11:49 -0000      1.2
***************
*** 38,43 ****
        public Object EvaluateUnary(Object v)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 38,68 ----
        public Object EvaluateUnary(Object v)
                        {
!                               switch(operatorTok)
!                               {
!                                       case JSToken.BitwiseNot:
!                                       {
!                                               return ~(Convert.ToInt32(v));
!                                       }
!                                       // Not reached.
! 
!                                       case JSToken.LogicalNot:
!                                       {
!                                               return !(Convert.ToBoolean(v));
!                                       }
!                                       // Not reached.
! 
!                                       case JSToken.Minus:
!                                       {
!                                               return -(Convert.ToNumber(v));
!                                       }
!                                       // Not reached.
! 
!                                       case JSToken.Plus:
!                                       {
!                                               return Convert.ToNumber(v);
!                                       }
!                                       // Not reached.
!                               }
!                               throw new 
JScriptException(JSError.InternalError);
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]