]> hydra-www.ietfng.org Git - dyna2/commitdiff
Add special handling for = and ==.
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sun, 30 Jun 2013 22:26:15 +0000 (18:26 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sun, 30 Jun 2013 22:26:15 +0000 (18:26 -0400)
Their evaluation has been inlined, increasing the number of modes supported.

src/Dyna/Analysis/RuleMode.hs
src/Dyna/Term/SurfaceSyntax.hs

index e3f14a8f7943319569463cf3379d9209675e3525..0dffa4d027417b0c4810547fbae21ee08eb57cc6 100644 (file)
@@ -56,6 +56,7 @@ import           Dyna.Analysis.Mode.Execution.Context
 import           Dyna.Analysis.Mode.Execution.Functions
 import           Dyna.Term.TTerm
 import           Dyna.Term.Normalized
+import           Dyna.Term.SurfaceSyntax
 import           Dyna.Main.Exception
 import           Dyna.XXX.DataUtils(argmin,mapInOrCons,mapMinRepView)
 import           Dyna.XXX.MonadContext
@@ -216,6 +217,32 @@ possible fp bcs co lf cr =
     -- XXX Indirect evaluation is not yet supported
     Left (_, CEval _ _) -> throwError UFExDomain
 
+    -- Evaluation of unification.  The distinction between the unification
+    -- operators has, at this point, been eliminated through ANF, so they
+    -- both execute the same way.
+    --
+    -- XXX Special casing ought not be necessary!
+    Left (_, CCall vo [va,vb] funct) | funct `elem` dynaUnifOpers -> do
+      pfx <- fgn vo (return (OPWrap vo [] dynaUnitTerm))
+                    (return (OPPeel [] vo dynaUnitTerm DetSemi))
+                    (throwError UFExDomain)
+      unif <- fgn va (fgn vb (throwError UFExDomain)
+                             (bind va >> return [OPAsgn va (NTVar vb)])
+                             (throwError UFExDomain))
+                     (fgn vb (bind vb >> return [OPAsgn vb (NTVar va)])
+                             (gencall)
+                             (throwError UFExDomain))
+                     (throwError UFExDomain)
+      return (pfx:unif)
+
+     where
+      gencall = do
+        is <- mapM mkMV [va,vb]
+        o  <- mkMV vo
+        case fp (funct,is,o) of
+          Right (BAct a m) -> runbact m >> return a
+          Left _ -> dynacPanic "Backend failed to generate unification call"
+
     -- Evaluation
     Left (_, CCall vo vis funct) -> do
       is <- mapM mkMV vis 
@@ -248,10 +275,7 @@ possible fp bcs co lf cr =
         Left True        -> throwError UFExDomain
 
           -- Builtin called in accessible mode; apply bindings and return
-        Right (BAct a m) -> do forM_ m $ \(v,vn) ->
-                                 runReaderT (unifyUnaliasedNV vn v)
-                                           (UnifParams (lf v) True)
-                               return a
+        Right (BAct a m) -> runbact m >> return a
  where
      mf = nHide IFree
      mo = nHide (IUniv UShared)
@@ -265,6 +289,9 @@ possible fp bcs co lf cr =
                            (throwError UFExDomain)
      bind x = runReaderT (unifyVU x) (UnifParams (lf x) False)
 
+     runbact m = forM_ m $ \(v,vn) -> runReaderT (unifyUnaliasedNV vn v)
+                                                 (UnifParams (lf v) True)
+
 ------------------------------------------------------------------------}}}
 -- Costing Plans                                                        {{{
 
index fc325fe2400cd31541f8d3ae85822a0d42013ea5..be4155a7ab93f588a4c8ca79bafc98599c73b0c1 100644 (file)
@@ -42,6 +42,9 @@ dynaRevConjOpers = ["whenever","for"]
 dynaUnitTerm :: (IsString s) => s
 dynaUnitTerm = "true"
 
+dynaUnifOpers :: (IsString s) => [s]
+dynaUnifOpers = [ "=", "==" ]
+
 ------------------------------------------------------------------------}}}
 -- Operators                                                            {{{