2006-08-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mbas / codegen.cs
index 84c25f440e7af833f18ac5b894f96d5a3b20f016..163ad3c866d9af02cfb5fc20c0d70c34952f0e04 100644 (file)
@@ -44,6 +44,7 @@ namespace Mono.MonoBASIC {
 
                public static AssemblyClass Assembly;
                public static ModuleClass Module;
+               public static ArrayList ArrListVersion = new ArrayList();//keeps the version's 4 numbers
 
                static public ISymbolWriter SymbolWriter;
 
@@ -174,6 +175,12 @@ namespace Mono.MonoBASIC {
                        an = new AssemblyName ();
                        an.Name = TrimExt (Basename (name));
                        current_domain = AppDomain.CurrentDomain;
+                       
+                       if (ArrListVersion.Count < 4)//4 -> Major, Minor,Version, Build
+                       for(int i=ArrListVersion.Count-1;i<4;i++)
+                               ArrListVersion.Add(0);
+                       an.Version = new Version (Convert.ToInt32(ArrListVersion[0]), Convert.ToInt32(ArrListVersion[1]), Convert.ToInt32(ArrListVersion[2]), Convert.ToInt32(ArrListVersion[3]));
+       
                        AssemblyBuilder = current_domain.DefineDynamicAssembly (
                                an, AssemblyBuilderAccess.RunAndSave, Dirname (name));
 
@@ -185,6 +192,7 @@ namespace Mono.MonoBASIC {
                        // If the third argument is true, the ModuleBuilder will dynamically
                        // load the default symbol writer.
                        //
+                       
                        ModuleBuilder = AssemblyBuilder.DefineDynamicModule (
                                Basename (name), Basename (output), want_debugging_support);
 
@@ -235,9 +243,13 @@ namespace Mono.MonoBASIC {
                {
                        foreach (Attribute attr in attrs) {
                                if (attr.IsAssemblyAttribute)
+                               {
                                        Assembly.AddAttribute (attr);
+                               }
                                else if (attr.IsModuleAttribute)
+                               {
                                        Module.AddAttribute (attr);
+                               }
                        }
                }
 
@@ -245,6 +257,7 @@ namespace Mono.MonoBASIC {
                {
                        //Assembly.Emit (Tree.Types);
                        //Module.Emit (Tree.Types);
+                       
 
                }
        }
@@ -254,9 +267,11 @@ namespace Mono.MonoBASIC {
        ///   properties bodies, indexer bodies or constructor bodies)
        /// </summary>
        public class EmitContext {
+               
                public DeclSpace DeclSpace;
                public TypeContainer TypeContainer;
                public ILGenerator   ig;
+       
 
                /// <summary>
                ///   This variable tracks the `checked' state of the compilation,
@@ -335,6 +350,16 @@ namespace Mono.MonoBASIC {
                /// </summary>
                public bool HasReturnLabel;
 
+               /// <summary>
+               ///   The location where to exit
+               /// </summary>
+               public Label ExitLabel;
+
+               /// <summary>
+               ///   If we already defined the ExitLabel
+               /// </summary>
+               public bool HasExitLabel;
+
                /// <summary>
                ///   Whether we are in a Finally block
                /// </summary>
@@ -390,7 +415,6 @@ namespace Mono.MonoBASIC {
                                    Type return_type, int code_flags, bool is_constructor)
                {
                        this.ig = ig;
-
                        TypeContainer = parent;
                        DeclSpace = ds;
                        CheckState = RootContext.Checked;
@@ -596,6 +620,14 @@ namespace Mono.MonoBASIC {
                                }
                        }
 
+                       if (HasReturnLabel)
+                               ig.MarkLabel (ReturnLabel);
+                       if (return_value != null){
+                               ig.Emit (OpCodes.Ldloc, return_value);
+                               ig.Emit (OpCodes.Ret);
+                               return;
+                       }
+
                        if (ReturnType != null && !has_ret){
                                //
                                // mcs here would report an error (and justly so), but functions without
@@ -613,16 +645,11 @@ namespace Mono.MonoBASIC {
                                return;
                        }
 
-                       if (HasReturnLabel)
-                               ig.MarkLabel (ReturnLabel);
-                       if (return_value != null){
-                               ig.Emit (OpCodes.Ldloc, return_value);
-                               ig.Emit (OpCodes.Ret);
-                       } else {
-                               if (!InTry){
-                                       if (!has_ret || HasReturnLabel)
-                                               ig.Emit (OpCodes.Ret);
-                               }
+                       if (!InTry){
+                               if (!has_ret)
+                                       ig.Emit (OpCodes.Ret);
+                               else if (ReturnType == null)
+                                       ig.Emit (OpCodes.Ret);
                        }
                }
 
@@ -754,8 +781,8 @@ namespace Mono.MonoBASIC {
                {
                        if (OptAttributes == null)
                                return;
-                       EmitContext ec = new EmitContext (tc, Location.Null, null, null, 0, false);
-
+                       EmitContext ec = new EmitContext (tc, Location.Null, null, null, 0, false);
+                       
                        if (OptAttributes != null)
                                OptAttributes.Emit (ec, this);
                }
@@ -775,7 +802,7 @@ namespace Mono.MonoBASIC {
                
                public override void Emit (TypeContainer tc)
                {
-                       base.Emit (tc);
+                       base.Emit (tc);
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
@@ -810,3 +837,5 @@ namespace Mono.MonoBASIC {
                }
        }
 }
+
+