[svn] r6265: nemerle/trunk/ncc: CompilationOptions.n Makefile generation/DecisionTreeCompiler.n generation...

nazgul svnadmin at nemerle.org
Sat May 13 15:17:53 CEST 2006


Log:
Remove old matching code

Author: nazgul
Date: Sat May 13 15:17:47 2006
New Revision: 6265

Removed:
   nemerle/trunk/ncc/generation/MatchingCompiler.n
   nemerle/trunk/ncc/temp/
Modified:
   nemerle/trunk/ncc/CompilationOptions.n
   nemerle/trunk/ncc/Makefile
   nemerle/trunk/ncc/generation/DecisionTreeCompiler.n
   nemerle/trunk/ncc/generation/Typer3.n
   nemerle/trunk/ncc/typing/DecisionTreeBuilder.n
   nemerle/trunk/ncc/typing/Typer.n

Modified: nemerle/trunk/ncc/CompilationOptions.n
==============================================================================
--- nemerle/trunk/ncc/CompilationOptions.n	(original)
+++ nemerle/trunk/ncc/CompilationOptions.n	Sat May 13 15:17:47 2006
@@ -40,7 +40,6 @@
     public mutable PrintExpressionsType : bool;
     public mutable DumpNamedMethod : string;
     public mutable DumpDecisionTree : bool;
-    public mutable NewMatchingCompiler : bool;
     public mutable BuildDecisionDAG : bool;
     public mutable AdditionalDebug : bool;
     public mutable TargetIsLibrary : bool;
@@ -118,7 +117,6 @@
       DumpNamedMethod = "";
       AdditionalDebug = false;
       PersistentLibraries = false;
-      NewMatchingCompiler = true;
       BuildDecisionDAG = true;
       DumpDecisionTree = false;
       IndentationSyntax = false;
@@ -456,11 +454,6 @@
                      help = "Enable general tail call optimization (programs are slower on MS.NET, but faster on Mono)",
                      handler = fun () { Options.GeneralTailCallOpt = true }),
 
-        Getopt.CliOption.Boolean (name = "-new-matching",
-                     aliases = [],
-                     help = "NOHELP",
-                     handler = fun (val) { Options.NewMatchingCompiler = val }),
-
         Getopt.CliOption.Flag (name = "-disable-decision-dag-opt",
                      aliases = ["-no-dag"],
                      help = "NOHELP",

Modified: nemerle/trunk/ncc/Makefile
==============================================================================
--- nemerle/trunk/ncc/Makefile	(original)
+++ nemerle/trunk/ncc/Makefile	Sat May 13 15:17:47 2006
@@ -87,7 +87,6 @@
 	generation/HierarchyEmitter.n	 \
 	generation/ILEmitter.n		 \
 	generation/ImplementsWrapperMaker.n \
-	generation/MatchingCompiler.n	 \
 	generation/DecisionTreeCompiler.n \
 	generation/Typer3.n		 \
 	generation/Typer4.n		 \

Modified: nemerle/trunk/ncc/generation/DecisionTreeCompiler.n
==============================================================================
--- nemerle/trunk/ncc/generation/DecisionTreeCompiler.n	(original)
+++ nemerle/trunk/ncc/generation/DecisionTreeCompiler.n	Sat May 13 15:17:47 2006
@@ -180,20 +180,20 @@
     {
       | Success (res_id) => effects [res_id] ()
 
-      | Failure => MatchingCompiler.ThrowMatchFailure ()
+      | Failure => ThrowMatchFailure ()
 
       | Assign (path, decl, dtree) =>
         def path_expr = get_path_expression (path);
         def assign_expr = TExpr.Assign (TExpr.LocalRef (decl.Type, decl), 
-                                        MatchingCompiler.Cast (path_expr, decl.Type));
+                                        Cast (path_expr, decl.Type));
         def expr = compile (dtree);
-        MatchingCompiler.Sequence (assign_expr, expr)
+        Sequence (assign_expr, expr)
 
       | IfEq (_, DecisionTreeBuilder.Con.Guard, 
               Decision.Success (res_id) as if_true, if_false) =>
         def true_expr = compile (if_true);
         def false_expr = compile (if_false);
-        MatchingCompiler.If (guards [res_id], true_expr, false_expr)
+        If (guards [res_id], true_expr, false_expr)
 
       | IfEq (path, con, if_true, if_false) => 
         def path_expr = get_path_expression (path);
@@ -204,7 +204,7 @@
           | Variant (ti) =>
             def constant_object =
               if (ti.GetConstantObject () != null)
-                MatchingCompiler.get_constant_object (ti, path_expr.Type)
+                get_constant_object (ti, path_expr.Type)
               else
                 None ();
 
@@ -213,20 +213,20 @@
                 def sref = TExpr.StaticRef (from, from, field, []);
                 def cond = TExpr.Call (InternalType.Boolean, TExpr.OpCode ("==.ref"),
                                        [Parm (path_expr), Parm (sref)], false);
-                MatchingCompiler.If (cond, true_expr, false_expr)
+                If (cond, true_expr, false_expr)
 
               | None =>
-                def has_type_expr = MatchingCompiler.HasType (path_expr, ti);
-                MatchingCompiler.If (has_type_expr, true_expr, false_expr)
+                def has_type_expr = HasType (path_expr, ti);
+                If (has_type_expr, true_expr, false_expr)
             }
 
           | Lit (lit) =>
-            def cmp_expr = MatchingCompiler.emit_compare_with (path_expr, lit);
-            MatchingCompiler.If (cmp_expr, true_expr, false_expr)
+            def cmp_expr = emit_compare_with (path_expr, lit);
+            If (cmp_expr, true_expr, false_expr)
 
           | Type (t) => 
             def has_type_expr = TExpr.HasType (path_expr, t);
-            MatchingCompiler.If (has_type_expr, true_expr, false_expr)
+            If (has_type_expr, true_expr, false_expr)
 
           | _ => assert (false);
         }
@@ -253,7 +253,7 @@
           if (f.DeclaringType.GetTydecl () is TypeDeclaration.VariantOption) {
             def ty = f.DeclaringType.GetFreshType ();
             p_expr.Type.ForceProvide (ty);
-            MatchingCompiler.Cast (p_expr, ty)
+            Cast (p_expr, ty)
           } else p_expr;
 
         if (TupleType.IsTupleMember (f)) {
@@ -261,7 +261,7 @@
           mutable pos = int ();
           Nemerle.IO.sscanf (f.Name, "field%i", pos);
           TExpr.TupleIndexer (path.Type, val, pos, len)
-        } else MatchingCompiler.build_record_field_ref (path.Type, val, f)
+        } else build_record_field_ref (path.Type, val, f)
     }
 
     static get_stats (decision : Decision) : string
@@ -354,5 +354,108 @@
       }
       "\n" + to_string (decision, "")
     }
+    
+
+    // handle both IField and IProperty
+    static build_record_field_ref (ty : TyVar, val : TExpr, member : IMember) : TExpr
+    {
+      match (member) {
+        | field is IField =>
+          TExpr.FieldMember (ty, val, field)
+          
+        | prop is IProperty =>
+          def meth = prop.GetGetter ();
+          def methref =
+            TExpr.MethodRef (MType.ConstructFunctionType ([], ty), val, meth, [], false);
+          TExpr.Call (ty, methref, [], false)
+
+        | _ => Util.ice ()
+      }
+    }
+
+    
+    /**
+     * Emit comparison code with specific literal.
+     */
+    static emit_compare_with (compare_to : TExpr, literal : Literal) : TExpr
+    {
+      def method =
+        match (literal) {
+          | Literal.String => 
+            def meth = InternalType.String_opEquality;
+            TExpr.StaticRef (meth.GetMemType (), InternalType.String, meth, [])
+          | Literal.Decimal =>
+            def meth = InternalType.Decimal_opEquality;
+            TExpr.StaticRef (meth.GetMemType (), InternalType.Decimal, meth, [])
+          | _ => TExpr.OpCode ("==") 
+        };
+      assert (literal != null);
+      def (compare_to, lit) =
+        if (compare_to.SystemType.IsValueType)
+          (compare_to,
+           Cast (TExpr.Literal (literal), compare_to.Type))
+        else 
+          (Cast (compare_to, literal.GetInternalType ()),
+           TExpr.Literal (literal));
+      TExpr.Call (InternalType.Boolean, method, [Parm (compare_to), Parm (lit)], false)
+    }
+    
+    /**
+     * Returns the constant object for a parameterless variant constructor
+     */
+    static get_constant_object (variant_tycon : TypeInfo, 
+                                matched_value_type : TyVar) : option [MType.Class * IField]
+    {
+      def members = 
+        variant_tycon.LookupMember ("_N_constant_object");
+      
+      match (members) {
+        | [] => None ()
+        
+        | [constant_object_field is IField] =>
+          def ty = variant_tycon.GetFreshType ();
+          ty.ForceRequire (matched_value_type);
+          Some ((ty, constant_object_field))
+
+        | _ =>
+          Util.ice ("get_constant_object: expected zero or exactly one _N_constant_object fields")
+      }          
+    }
+    
+    static If (cond : TExpr, e1 : TExpr, e2 : TExpr) : TExpr
+    {
+      TExpr.If (cond.Location, e1.Type, cond, e1, e2)
+    }
+
+    static Cast (expr : TExpr, ty : TyVar) : TExpr
+    {
+      TExpr.TypeConversion (expr.Location, ty, expr, ty.Fix (), ConversionKind.IL (true))
+    }
+
+    static Sequence (e1 : TExpr, e2 : TExpr) : TExpr
+    {
+      TExpr.Sequence (e1.loc, e2.Type, e1, e2)
+    }
+
+    static HasType (e : TExpr, ti : TypeInfo) : TExpr
+    {
+      match (ti.GetFreshType ()) {
+        | MType.Class (_, []) as ty =>
+          TExpr.HasType (e, ty)
+        | ty =>
+          e.Type.ForceProvide (ty);
+          TExpr.HasType (e, ty)
+      }
+    }
+
+    static ThrowMatchFailure () : TExpr
+    {
+      def ctor = InternalType.NewMatchFailureException_ctor;
+      TExpr.Throw (Solver.FreshTyVar (),
+                   TExpr.Call (InternalType.MatchFailureException,
+                               TExpr.StaticRef (ctor.GetMemType (), 
+                                                InternalType.MatchFailureException, 
+                                                ctor, []), [], false))
+    }
   }
 }

Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n	(original)
+++ nemerle/trunk/ncc/generation/Typer3.n	Sat May 13 15:17:47 2006
@@ -1584,11 +1584,7 @@
         | _ => false
       }
 
-      def match_comp = 
-        if (Options.NewMatchingCompiler)
-          DecisionTreeCompiler.Run (m.Type, _, m.cases)
-        else 
-          MatchingCompiler.Run (m.Type, _, m.cases);
+      def match_comp = DecisionTreeCompiler.Run (m.Type, _, m.cases);
 
       def expr =
         match (m.cases) {

Modified: nemerle/trunk/ncc/typing/DecisionTreeBuilder.n
==============================================================================
--- nemerle/trunk/ncc/typing/DecisionTreeBuilder.n	(original)
+++ nemerle/trunk/ncc/typing/DecisionTreeBuilder.n	Sat May 13 15:17:47 2006
@@ -900,9 +900,5 @@
       def builder = DecisionTreeBuilder (cases);
       builder.CheckMatching ();
     }
-
- 
   }
-
-  
 }

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Sat May 13 15:17:47 2006
@@ -1649,7 +1649,7 @@
       def pats = TypePatterns (res, [pattern]);
       def case = Match_case (pats, null, true);
 
-      when (! Options.NewMatchingCompiler || messenger.SeenError) {
+      when (messenger.SeenError) {
         when (messenger.NeedMessage)
           DecisionTreeBuilder.CheckMatching ([case]);
         FixupMatchCase (case)
@@ -3032,7 +3032,7 @@
       } else {
         res = List.Rev (res);
 
-        when (! Options.NewMatchingCompiler || messenger.SeenError) {
+        when (messenger.SeenError) {
           when (! disable_warnings && messenger.NeedMessage)
             DecisionTreeBuilder.CheckMatching (res);
           List.Iter (res, FixupMatchCase)



More information about the svn mailing list