Author: cesar
Date: 2005-02-27 01:51:41 -0500 (Sun, 27 Feb 2005)
New Revision: 41251
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Block.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ast.cs
Log:
2005-02-27 Cesar Lopez Nataren <[EMAIL PROTECTED]>
* ast.cs: Added protected field ig to class Function.
* Block.cs: Emit function's body in a later phase since free
ocurrences of functions - at the same level of it - can be handled
properly, since they must be defined and inited to the correct values.
* FunctionDeclaration.cs: Renamed Emit to create_closure. And make
Emit only generate the code of the body.
Fixes #73078.
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Block.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Block.cs
2005-02-27 06:13:44 UTC (rev 41250)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Block.cs
2005-02-27 06:51:41 UTC (rev 41251)
@@ -88,17 +88,17 @@
if (e is VariableStatement)
((VariableStatement)
e).EmitVariableDecls (ec);
}
-
+
//
- // Emit the function declarations before any
+ // Emit the function closure before any
// expression because the ScriptFunction and
// field created must be set properly before
- // any use.
+ // any use. The body gets emitted later.
//
for (i = 0; i < n; i++) {
e = elems [i];
if (e is FunctionDeclaration)
- ((FunctionDeclaration) e).Emit (ec);
+ ((FunctionDeclaration)
e).create_closure (ec);
}
//
@@ -106,8 +106,7 @@
//
for (i = 0; i < n; i++) {
e = elems [i];
- if (!(e is FunctionDeclaration))
- ((AST) e).Emit (ec);
+ ((AST) e).Emit (ec);
}
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-02-27 06:13:44 UTC (rev 41250)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-02-27 06:51:41 UTC (rev 41251)
@@ -1,3 +1,14 @@
+2005-02-27 Cesar Lopez Nataren <[EMAIL PROTECTED]>
+
+ * ast.cs: Added protected field ig to class Function.
+ * Block.cs: Emit function's body in a later phase since free
+ ocurrences of functions - at the same level of it - can be handled
+ properly, since they must be defined and inited to the correct values.
+ * FunctionDeclaration.cs: Renamed Emit to create_closure. And make
+ Emit only generate the code of the body.
+
+ Fixes #73078.
+
2005-02-22 Cesar Lopez Nataren <[EMAIL PROTECTED]>
* Block.cs: Report error JS5040. Reopened #72674, see last comment of
it.
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
2005-02-27 06:13:44 UTC (rev 41250)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
2005-02-27 06:51:41 UTC (rev 41251)
@@ -81,13 +81,13 @@
return func_obj.ToString ();
}
- internal override void Emit (EmitContext ec)
+ internal void create_closure (EmitContext ec)
{
string name = func_obj.name;
string full_name;
TypeBuilder type = ec.type_builder;
ILGenerator ig = ec.ig;
-
+
if (prefix == String.Empty)
full_name = name;
else
@@ -98,12 +98,12 @@
MethodBuilder tmp = TypeManager.GetMethod (name);
if (tmp == null)
TypeManager.AddMethod (name, method_builder);
- else
+ else
TypeManager.SetMethod (name, method_builder);
set_custom_attr (method_builder);
- EmitContext new_ec = new EmitContext (ec.type_builder,
ec.mod_builder,
-
method_builder.GetILGenerator ());
+ this.ig = method_builder.GetILGenerator ();
+
if (parent == null || parent.GetType () == typeof
(ScriptBlock))
type.DefineField (name, typeof
(Microsoft.JScript.ScriptFunction),
FieldAttributes.Public |
FieldAttributes.Static);
@@ -112,10 +112,18 @@
TypeManager.AddLocal (name, local_func);
}
build_closure (ec, full_name);
- func_obj.body.Emit (new_ec);
- new_ec.ig.Emit (OpCodes.Ret);
}
+
+ internal override void Emit (EmitContext ec)
+ {
+ ILGenerator old_ig = ec.ig;
+ ec.ig = this.ig;
+ func_obj.body.Emit (ec);
+ this.ig.Emit (OpCodes.Ret);
+ ec.ig = old_ig;
+ }
+
internal void build_closure (EmitContext ec, string full_name)
{
ILGenerator ig = ec.ig;
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ast.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ast.cs 2005-02-27
06:13:44 UTC (rev 41250)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ast.cs 2005-02-27
06:51:41 UTC (rev 41251)
@@ -108,9 +108,11 @@
internal AST [] locals;
internal LocalBuilder local_func;
-
+
protected bool not_void_return = false;
+ protected ILGenerator ig;
+
internal bool CheckThis {
get { return check_this; }
set { check_this = value; }
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches