2003-12-18 Cesar Lopez Nataren <cesar@ciencias.unam.mx>
authorCésar Natarén <cesar@mono-cvs.ximian.com>
Thu, 18 Dec 2003 08:25:45 +0000 (08:25 -0000)
committerCésar Natarén <cesar@mono-cvs.ximian.com>
Thu, 18 Dec 2003 08:25:45 +0000 (08:25 -0000)
* jscript-lexer-parser.g: Keep track of parent for numeric_literal.

* VariableDeclaration.cs: now I handle initialization (ex. var x =
2; or function f () { var x = 4; }) at global scope or at
function's body.

* Literal.cs: Added parent param to NumericLiteral constructor.

* FunctionDeclaration.cs: Added Ret opcode for all function declaration bodies.

svn path=/trunk/mcs/; revision=21306

mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
mcs/class/Microsoft.JScript/Microsoft.JScript/FunctionDeclaration.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/Literal.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/VariableDeclaration.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/jscript-lexer-parser.g

index 6009690f8b68afc23f69cac610016a0b9360dcaf..c66e9f75704c0ec13711a650b07902441ab7169b 100644 (file)
@@ -1,3 +1,15 @@
+2003-12-18  Cesar Lopez Nataren  <cesar@ciencias.unam.mx>
+
+       * jscript-lexer-parser.g: Keep track of parent for numeric_literal.
+
+       * VariableDeclaration.cs: now I handle initialization (ex. var x =
+       2; or function f () { var x = 4; }) at global scope or at
+       function's body.
+
+       * Literal.cs: Added parent param to NumericLiteral constructor.
+
+       * FunctionDeclaration.cs: Added Ret opcode for all function declaration bodies.
+
 2003-12-17  Cesar Lopez Nataren  <cesar@ciencias.unam.mx>
 
        * CodeGenerator.cs: Added IL emittion for ldnull on default ending code for 'Global Code'.
index ee0ee841bc4c756fcc97f2d5ace7fca9c6dcf4b7..9e7c4da0322be66b176340cc9f204fa0ab4ad032 100644 (file)
@@ -83,9 +83,9 @@ namespace Microsoft.JScript {
                                                    Function.return_type,
                                                    Function.params_types ());
        
-                       ec.ig = method.GetILGenerator ();
-               
+                       ec.ig = method.GetILGenerator ();               
                        Function.body.Emit (ec);
+                       ec.ig.Emit (OpCodes.Ret);
                }
 
                internal override bool Resolve (IdentificationTable context)
index 11f0799e5b1966af7a2414ec7d737815ab1394d2..9375d33075e5bdd43170e4fbbd9dcdbd06dcbfec 100644 (file)
@@ -67,8 +67,9 @@ namespace Microsoft.JScript {
 
                double val;
 
-               internal NumericLiteral (double val)
+               internal NumericLiteral (AST parent, double val)
                {
+                       this.parent = parent;
                        this.val = val;
                }
 
index 67b320f50b18227871b304896d3718480cb60ef9..0d1ffd6e197558baa3f151a79340513595bf0c6b 100644 (file)
@@ -76,8 +76,19 @@ namespace Microsoft.JScript {
                                field = type.DefineField (id, Type,
                                                          FieldAttributes.Public |
                                                          FieldAttributes.Static);
-                       } else
-                               ec.ig.DeclareLocal (Type);
+                               if (val != null) {
+                                       val.Emit (ec);
+                                       ec.gc_ig.Emit (OpCodes.Stsfld, field);
+                               }
+                       } else {
+                               ILGenerator ig = ec.ig;
+                               LocalBuilder lb = ig.DeclareLocal (Type);
+
+                               if (val != null) {
+                                       val.Emit (ec);
+                                       ig.Emit (OpCodes.Stloc, lb);
+                               }
+                       }
                }
 
                internal override bool Resolve (IdentificationTable context)
index 420d01852b4bd562e411043d91049ca661eaa15d..22067c6e1b7e52d50e7a29ee688afa89ae595d6d 100644 (file)
@@ -881,7 +881,7 @@ literal [AST parent] returns [AST l]
                  StringLiteral str = new StringLiteral (s.getText ());
                  l = str;
          }      
-       | l = numeric_literal
+       | l = numeric_literal [parent]
        ;
 
 property_name_and_value_list
@@ -889,18 +889,18 @@ property_name_and_value_list
        ;
 
 property_name
-       : (IDENTIFIER | STRING_LITERAL | numeric_literal) 
+       : (IDENTIFIER | STRING_LITERAL | numeric_literal [null]
        ;
 
 array_literal
        : OPEN_BRACKET (primary_expr [null] (COMMA primary_expr [null])* | ) CLOSE_BRACKET
        ;       
 
-numeric_literal returns [NumericLiteral num_lit]
+numeric_literal [AST parent] returns [NumericLiteral num_lit]
 {
        num_lit = null;
 }
-       : d:DECIMAL_LITERAL { num_lit = new NumericLiteral (Convert.ToSingle (d.getText ())); }
+       : d:DECIMAL_LITERAL { num_lit = new NumericLiteral (parent, Convert.ToSingle (d.getText ())); }
        | HEX_INTEGER_LITERAL
        ;