Author: cesar
Date: 2005-03-16 20:22:31 -0500 (Wed, 16 Mar 2005)
New Revision: 41925

Modified:
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionExpression.cs
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeManager.cs
   trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs
Log:
2005-03-16  Cesar Lopez Nataren  <[EMAIL PROTECTED]>

        * FunctionExpression.cs: Update to TypeManager new API.

        * TypeManager.cs: Keep both MethodBuilder and LocalBuilder around.

        * FunctionDeclaration.cs: In some contexts we need the
        MethodBuilder and LocalBuilder, so we must keep both around.

        * expression.cs: (load_script_func) Take care if bounded variable
        was declared in a nested context. (emit_create_instance) Handle
        the FunctionConstructor case.

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-03-17 00:31:49 UTC (rev 41924)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog       
2005-03-17 01:22:31 UTC (rev 41925)
@@ -1,3 +1,16 @@
+2005-03-16  Cesar Lopez Nataren  <[EMAIL PROTECTED]>
+
+       * FunctionExpression.cs: Update to TypeManager new API.
+
+       * TypeManager.cs: Keep both MethodBuilder and LocalBuilder around.
+
+       * FunctionDeclaration.cs: In some contexts we need the
+       MethodBuilder and LocalBuilder, so we must keep both around.
+
+       * expression.cs: (load_script_func) Take care if bounded variable
+       was declared in a nested context. (emit_create_instance) Handle
+       the FunctionConstructor case.
+
 2005-02-28  Cesar Lopez Nataren  <[EMAIL PROTECTED]>
 
        * ForIn.cs: Initial implementation of ForIn stm.

Modified: 
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs  
2005-03-17 00:31:49 UTC (rev 41924)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs  
2005-03-17 01:22:31 UTC (rev 41925)
@@ -96,6 +96,8 @@
                        MethodBuilder method_builder = type.DefineMethod 
(full_name, func_obj.attr, HandleReturnType,
                                                                  
func_obj.params_types ());
                        MethodBuilder tmp = (MethodBuilder) TypeManager.Get 
(name);
+
+
                        if (tmp == null)
                                TypeManager.Add (name, method_builder);
                        else 
@@ -109,7 +111,7 @@
                                                  FieldAttributes.Public | 
FieldAttributes.Static);
                        else {
                                local_func = ig.DeclareLocal (typeof 
(Microsoft.JScript.ScriptFunction));
-                               TypeManager.Add (name, local_func);
+                               TypeManager.AddLocal (name, local_func);
                        }
                        build_closure (ec, full_name);
                }

Modified: 
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionExpression.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionExpression.cs   
2005-03-17 00:31:49 UTC (rev 41924)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionExpression.cs   
2005-03-17 01:22:31 UTC (rev 41925)
@@ -86,6 +86,8 @@
 
                internal override void Emit (EmitContext ec)
                {
+                       TypeManager.BeginScope ();
+
                        string name = func_obj.name;
                        string full_name;
                        TypeBuilder type = ec.type_builder;
@@ -106,6 +108,11 @@
                        MethodBuilder method_builder = type.DefineMethod 
(full_name, func_obj.attr, 
                                                                          
HandleReturnType,
                                                                          
func_obj.params_types ());
+                       MethodBuilder tmp = (MethodBuilder) TypeManager.Get 
(name);
+                       if (tmp == null)
+                               TypeManager.Add (name, method_builder);
+                       else 
+                               TypeManager.Set (name, method_builder);
                        set_custom_attr (method_builder);
                        EmitContext new_ec = new EmitContext (ec.type_builder, 
ec.mod_builder,
                                                              
method_builder.GetILGenerator ());
@@ -125,6 +132,8 @@
                        build_closure (ec, full_name);
                        func_obj.body.Emit (new_ec);
                        new_ec.ig.Emit (OpCodes.Ret);
+
+                       TypeManager.EndScope ();
                }
 
                internal void build_closure (EmitContext ec, string full_name)

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeManager.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeManager.cs  
2005-03-17 00:31:49 UTC (rev 41924)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeManager.cs  
2005-03-17 01:22:31 UTC (rev 41925)
@@ -17,20 +17,24 @@
        internal class TypeManager {
 
                static IdentificationTable infos;
+               static IdentificationTable locals;
 
                static TypeManager ()
                {
                        infos = new IdentificationTable ();
+                       locals = new IdentificationTable ();
                }
 
                internal static void BeginScope ()
                {
                        infos.BeginScope ();
+                       locals.BeginScope ();
                }
 
                internal static void EndScope ()
                {
                        infos.EndScope ();
+                       locals.EndScope ();
                }
 
                internal static void Add (string name, object o)
@@ -38,11 +42,21 @@
                        infos.Enter (Symbol.CreateSymbol (name), o);
                }
 
+               internal static void AddLocal (string name, object o)
+               {
+                       locals.Enter (Symbol.CreateSymbol (name), o);
+               }
+
                internal static object Get (string name)
                {
                        return infos.Get (Symbol.CreateSymbol (name));
                }
 
+               internal static object GetLocal (string name)
+               {
+                       return locals.Get (Symbol.CreateSymbol (name));
+               }
+
                internal static void Set (string name, object o)
                {
                        object obj = Get (name);

Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs   
2005-03-17 00:31:49 UTC (rev 41924)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/expression.cs   
2005-03-17 01:22:31 UTC (rev 41925)
@@ -997,7 +997,7 @@
                        else if (binding is FunctionDeclaration)
                                load_script_func (ec, (FunctionDeclaration) 
binding);
                        else if (binding == null) // it got referenced before 
was declared and initialized
-                               Console.WriteLine ("Identifier.Emit, binding == 
null? {0}", binding == null);
+                               Console.WriteLine ("id = {0}, Identifier.Emit, 
binding == null? {1}", name.Value, binding == null);
                        if (!assign && no_effect)
                                ig.Emit (OpCodes.Pop);                          
                }
@@ -1038,12 +1038,21 @@
 
                void load_script_func (EmitContext ec, FunctionDeclaration 
binding)
                {
-                       if (InFunction && (TypeManager.Get 
(binding.func_obj.name) != null))
-                               ec.ig.Emit (OpCodes.Ldloc, (LocalBuilder) 
TypeManager.Get (binding.func_obj.name));
-                       else {
-                               TypeBuilder type = ec.type_builder;
-                               FieldInfo method = type.GetField 
(binding.func_obj.name);
-                               ec.ig.Emit (OpCodes.Ldsfld, method);
+                       object bind = TypeManager.Get (binding.func_obj.name);
+                                                      
+                       if (bind != null) {
+                               if (bind is MethodBuilder) {
+                                       TypeBuilder type = ec.type_builder;
+                                       if (binding.InFunction) {
+                                               LocalBuilder local_meth = 
(LocalBuilder) TypeManager.GetLocal (binding.func_obj.name);
+                                               ec.ig.Emit (OpCodes.Ldloc, 
local_meth);
+                                       } else {
+                                               FieldInfo method = 
type.GetField (binding.func_obj.name);
+                                               ec.ig.Emit (OpCodes.Ldsfld, 
method);
+                                       }
+                               } else if (bind is LocalBuilder)
+                                       ec.ig.Emit (OpCodes.Ldloc, 
(LocalBuilder) bind);
+                               else throw new Exception ("load_script_func");
                        }
                }
 
@@ -1550,6 +1559,9 @@
                                case "Boolean":
                                        type = typeof (BooleanConstructor);
                                        break;
+                               case "Function":
+                                       type = typeof (FunctionConstructor);
+                                       break;
                                }
                                if (type != null)
                                        ig.Emit (OpCodes.Call, type.GetMethod 
("CreateInstance"));

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

Reply via email to