Author: cesar
Date: 2005-02-28 22:10:41 -0500 (Mon, 28 Feb 2005)
New Revision: 41305

Modified:
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ForIn.cs
Log:
2005-02-28  Cesar Lopez Nataren  <[EMAIL PROTECTED]>

        * ForIn.cs: Initial implementation of ForIn stm.

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-03-01 01:22:09 UTC (rev 41304)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-03-01 03:10:41 UTC (rev 41305)
@@ -1,3 +1,7 @@
+2005-02-28  Cesar Lopez Nataren  <[EMAIL PROTECTED]>
+
+       * ForIn.cs: Initial implementation of ForIn stm.
+
 2005-02-27  Cesar Lopez Nataren  <[EMAIL PROTECTED]>
 
        * VariableStatement.cs (PopulateContext): Do not add the symbol to

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ForIn.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ForIn.cs        
2005-03-01 01:22:09 UTC (rev 41304)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ForIn.cs        
2005-03-01 03:10:41 UTC (rev 41305)
@@ -30,6 +30,7 @@
 
 using System;
 using System.Collections;
+using System.Reflection.Emit;
 
 namespace Microsoft.JScript {
 
@@ -53,12 +54,82 @@
 
                internal override bool Resolve (IdentificationTable context)
                {
-                       throw new NotImplementedException ();
+                       bool r = true;
+                       if (lhs != null)
+                               if (lhs is VariableStatement)
+                                       ((VariableStatement) 
lhs).PopulateContext (context);
+                               else
+                                       r &= lhs.Resolve (context);
+                       if (obj != null)
+                               r &= obj.Resolve (context);
+
+                       if (body != null)
+                               r &= body.Resolve (context);
+                       return r;
                }
 
                internal override void Emit (EmitContext ec)
                {
-                       throw new NotImplementedException ();
+                       ILGenerator ig;
+                       
+                       if (lhs is VariableStatement) {
+                               VariableStatement stm = (VariableStatement) lhs;
+                               stm.EmitVariableDecls (ec);
+                               ig = ec.ig;
+                               ig.Emit (OpCodes.Ldnull);
+                               object var = TypeManager.Get 
(((VariableDeclaration) stm.var_decls [0]).id);
+                               set_builder (ig, var);
+
+                               if (obj != null)
+                                       obj.Emit (ec);
+
+                               CodeGenerator.load_engine (InFunction, ig);
+
+                               Type convert = typeof (Convert);
+                               ig.Emit (OpCodes.Call, convert.GetMethod 
("ToForInObject"));
+                               ig.Emit (OpCodes.Call, typeof (ForIn).GetMethod 
("JScriptGetEnumerator"));
+                               Type ienumerator = typeof (IEnumerator);
+                               LocalBuilder iter = ig.DeclareLocal 
(ienumerator);
+                               LocalBuilder current = ig.DeclareLocal (typeof 
(object));
+
+                               ig.Emit (OpCodes.Stloc, iter);
+                               
+                               Label init_loop = ig.DefineLabel ();
+                               Label move_next = ig.DefineLabel ();
+                               Label exit = ig.DefineLabel ();
+                                                               
+                               ig.Emit (OpCodes.Br, move_next);
+                               ig.MarkLabel (init_loop);
+
+                               if (body != null)
+                                       body.Emit (ec);
+
+                               ig.MarkLabel (move_next);
+
+                               ig.Emit (OpCodes.Ldloc, iter);
+                               ig.Emit (OpCodes.Callvirt, 
ienumerator.GetMethod ("MoveNext"));
+                               
+                               ig.Emit (OpCodes.Brfalse, exit);
+
+                               ig.Emit (OpCodes.Ldloc, iter);
+                               ig.Emit (OpCodes.Callvirt, 
ienumerator.GetProperty ("Current").GetGetMethod ());
+                               ig.Emit (OpCodes.Stloc, current);
+                               ig.Emit (OpCodes.Ldloc, current);
+
+                               set_builder (ig, var);
+
+                               ig.Emit (OpCodes.Br, init_loop);
+                               ig.MarkLabel (exit);
+                       } else
+                               throw new NotImplementedException ();
                }
+
+               void set_builder (ILGenerator ig, object builder)
+               {
+                       if (builder is FieldBuilder)
+                               ig.Emit (OpCodes.Stsfld, (FieldBuilder) 
builder);
+                       else if (builder is LocalBuilder)
+                               ig.Emit (OpCodes.Stloc, (LocalBuilder) builder);
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to