[svn] r5834: nemerle/trunk/ncc: generation/ILEmitter.n testsuite/positive/generic-struct.n testsuite/posit...

malekith svnadmin at nemerle.org
Wed Oct 19 22:57:15 CEST 2005


Log:
Excercise generic structs a bit, improve their handling. Add workaround for mono #76484 -- resolves #531.

Author: malekith
Date: Wed Oct 19 22:57:13 2005
New Revision: 5834

Added:
   nemerle/trunk/ncc/testsuite/positive/generic-struct.n
Modified:
   nemerle/trunk/ncc/generation/ILEmitter.n
   nemerle/trunk/ncc/testsuite/positive/generics.n

Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n	Wed Oct 19 22:57:13 2005
@@ -49,6 +49,7 @@
   {
     private _module_builder : ModuleBuilder;
     private _ilg : ILGenerator;    
+    private _parent_type_builder : Nemerle.Compiler.TypeBuilder;
 
     private _this_is_value_type : bool;
     private _type_of_this : System.Type;
@@ -65,6 +66,26 @@
     static MS_NET_RuntimeType : System.Type 
       = typeof (object).Assembly.GetType ("System.RuntimeType");
 
+    // mono #76484
+    workaround_mono_bug (type_ : Nemerle.Compiler.TypeBuilder) : void
+    {
+      def type_of_this = type_.GetMemType ().SystemType;
+
+      def is_proper_method (_) {
+        | m is IMethod =>
+          m.DeclaringType.Equals (type_) && ! m.IsStatic && m.Name != ".ctor"
+        | _ => false
+      }
+
+      when (type_.TyparmsCount > 0)
+        match (type_.GetMembers ().Find (is_proper_method)) {
+          | Some (m) =>
+            _ = TypeBuilder.GetMethod (type_of_this, 
+                                       m.GetHandle () :> Emit.MethodBuilder);
+          | None => {}
+        }
+    }
+
     /**
      * Creates and executes a code generator for a method
      */
@@ -75,11 +96,14 @@
 
       _ilg = method_builder.GetILGenerator ();
       _module_builder = method_builder.Module :> ModuleBuilder;
+      _parent_type_builder = type_;
 
       _method_name = method_builder.DeclaringType.FullName + "::" + method_builder.Name;
       _method_is_static = method_builder.IsStatic;
       _this_is_value_type = type_.IsValueType;
-      _type_of_this = type_.SystemType;
+      _type_of_this = type_.GetMemType ().SystemType;
+
+      workaround_mono_bug (type_);
     }
 
 
@@ -93,12 +117,15 @@
 
       _ilg = constructor_builder.GetILGenerator ();
       _module_builder = constructor_builder.Module :> ModuleBuilder;
+      _parent_type_builder = type_;
 
       _method_name = constructor_builder.DeclaringType.FullName + "::"
                       + constructor_builder.Name;
       _method_is_static = constructor_builder.IsStatic;
       _this_is_value_type = type_.IsValueType;
-      _type_of_this = type_.SystemType;
+      _type_of_this = type_.GetMemType ().SystemType;
+
+      workaround_mono_bug (type_);
     }
 
     public Run () : void
@@ -940,7 +967,7 @@
           
           // it actually IS the proper way to do it --
           // if this is our method, then we do not need to box
-          unless (th.SystemType : object == _type_of_this) {
+          unless (th.MType.Equals (_parent_type_builder.GetMemType ())) {
             _ilg.Emit (OpCodes.Ldobj, _type_of_this);
             _ilg.Emit (OpCodes.Box, _type_of_this);
           }

Added: nemerle/trunk/ncc/testsuite/positive/generic-struct.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/positive/generic-struct.n	Wed Oct 19 22:57:13 2005
@@ -0,0 +1,30 @@
+struct C[T] {
+  public mutable x : int;
+  public foo () : void
+  {
+    x++;
+  }
+  public bar () : void
+  {
+    foo ();
+  }
+  public baz (other : C[T]) : void
+  {
+        this = other;
+  }
+}
+
+def c = C ();
+assert (c.x == 0);
+c.bar();
+assert (c.x == 1);
+c.bar();
+assert (c.x == 2);
+def q = C ();
+q.baz (c);
+assert (q.x == 2);
+
+/*
+BEGIN-OUTPUT
+END-OUTPUT
+*/

Modified: nemerle/trunk/ncc/testsuite/positive/generics.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/generics.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/generics.n	Wed Oct 19 22:57:13 2005
@@ -136,6 +136,16 @@
   }
 }
 
+public class Bug531['a] {
+    public Nothing():void {}
+
+    public Fun():void {
+        try {
+        } finally {
+          Nothing ();
+        }
+    }
+}
 
 /*
 BEGIN-OUTPUT



More information about the svn mailing list