]> hydra-www.ietfng.org Git - dyna2/commitdiff
Adjust variable naming convention slightly
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 10 Dec 2012 22:57:28 +0000 (17:57 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 10 Dec 2012 22:57:28 +0000 (17:57 -0500)
src/Dyna/Analysis/ANF.hs
src/Dyna/Backend/Python.hs

index eda63cedbcec7f2b3c9973c027a43570df77be7d..93581e95193f08681e556549ae4cce73b720a2e5 100644 (file)
@@ -72,6 +72,7 @@ module Dyna.Analysis.ANF (
 import           Control.Monad.Reader
 import           Control.Monad.State
 import           Control.Unification
+import qualified Data.ByteString.Char8      as BC
 import qualified Data.ByteString.UTF8       as BU
 import qualified Data.ByteString            as B
 import qualified Data.Map                   as M
@@ -228,7 +229,10 @@ dynaFunctorSelfDispositions x = case x of
 -- flattened representation.
 --
 -- The ANFState ensures that variables are unique; we additionally give them
--- \"semi-meaningful\" prefixes, but these should not be relied upon.
+-- \"semi-meaningful\" prefixes, but these should not be relied upon for
+-- anything actually meaningful (but they serve as great debugging aids!).
+-- While here, we stick a prefix on user variables to ensure that they are
+-- disjoint from the variables we generate and use internally.
 --
 -- XXX This sheds span information entirely, which is probably not what we
 -- actually want.  Note that we're careful to keep a stack of contexts
@@ -242,10 +246,13 @@ normTerm_ :: (Functor m, MonadState ANFState m, MonadReader ANFDict m)
 
 -- Variables only evaluate in explicit context
 --
--- While here, replace bare underscores with unique names.
+-- While here, replace bare underscores with unique names and rename all
+-- remaining user variables to ensure that they do not collide with internal
+-- names.
+--
 -- XXX is this the right place for that?
 normTerm_ c _ (P.TVar v) = do
-    v' <- if v == "_" then nextVar "_w" else return v
+    v' <- if v == "_" then nextVar "_w" else return (BC.cons 'u' v)
     case c of
        (ECExplicit,ADEval) -> NTVar `fmap` newEval "_v" (Left v')
        _                   -> return $ NTVar v'
index 38b02c6d5810787f06f689344ad57e5fdfe11071..b7152af03aadd3bfc9b5a24b396ae2000f6bdb19 100644 (file)
@@ -18,7 +18,7 @@ import qualified Control.Arrow              as A
 import           Control.Exception
 import           Control.Monad
 import qualified Data.ByteString            as B
-import qualified Data.ByteString.Char8      as BC
+import qualified Data.ByteString.UTF8       as BU
 import           Data.Char
 -- import           Data.Either
 import qualified Data.List                  as L
@@ -121,7 +121,7 @@ combinePlans = go (M.empty)
 
 py (cruxf,cruxa) (FRule h _ _ r span _) dope =
            "@register" <> (parens $ dquotes $ pretty cruxf <> "/" <> (text $ show cruxa))
-   `above` "def _(_H, _V):"
+   `above` "def _(_h, _v):"
    `above` (indent 4 $ go dope)
 
  where
@@ -174,8 +174,8 @@ processFile_ fileName fh = do
 --            hPutStrLn fh ""
 
  where
-  headVar = "_H"
-  valVar  = "_V"
+  headVar = "_h"
+  valVar  = "_v"
 
 
 -- TEST: processFile "examples/cky.dyna"