From d4dadf5278c1e9ba81d7397a48019b85167bfa9b Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 10 Dec 2012 17:57:28 -0500 Subject: [PATCH] Adjust variable naming convention slightly --- src/Dyna/Analysis/ANF.hs | 13 ++++++++++--- src/Dyna/Backend/Python.hs | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Dyna/Analysis/ANF.hs b/src/Dyna/Analysis/ANF.hs index eda63ce..93581e9 100644 --- a/src/Dyna/Analysis/ANF.hs +++ b/src/Dyna/Analysis/ANF.hs @@ -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' diff --git a/src/Dyna/Backend/Python.hs b/src/Dyna/Backend/Python.hs index 38b02c6..b7152af 100644 --- a/src/Dyna/Backend/Python.hs +++ b/src/Dyna/Backend/Python.hs @@ -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" -- 2.50.1