on master help sign in
Get rid of logging and add Int, Float, Char, Bool to the global environment
3f96acfEvan Czaplicki
compiler/Transform/Canonicalize.hs+5−25
@@ -15,19 +15,8 @@ import qualified SourceSyntax.Type as Type
15import qualified Transform.SortDefinitions as SD
15import qualified Transform.SortDefinitions as SD
16import Text.PrettyPrint
16import Text.PrettyPrint
17
17
18−-- todo: remove these
19−import System.IO.Unsafe
20−import SourceSyntax.PrettyPrint
21−
22interface :: String -> ModuleInterface -> ModuleInterface
18interface :: String -> ModuleInterface -> ModuleInterface
23interface moduleName iface =
19interface moduleName iface =
24− let f x = unsafePerformIO $ do
25− putStrLn "----------------------\ncanonicalize interface"
26− putStr "iface " >> print iface
27− putStr "canons " >> print canons
28− putStr "iface' " >> print x
29− return x
30− in f $
31 ModuleInterface {
20 ModuleInterface {
32 iTypes = Map.mapKeys prefix (Map.map renameType' (iTypes iface)),
21 iTypes = Map.mapKeys prefix (Map.map renameType' (iTypes iface)),
33 iAdts = map (both prefix renameCtors) (iAdts iface),
22 iAdts = map (both prefix renameCtors) (iAdts iface),
@@ -60,12 +49,7 @@ renameType rename tipe =
60
49
61metadataModule :: Interfaces -> MetadataModule t v -> Either [Doc] (MetadataModule t v)
50metadataModule :: Interfaces -> MetadataModule t v -> Either [Doc] (MetadataModule t v)
62metadataModule ifaces modul =
51metadataModule ifaces modul =
63− do let f x = unsafePerformIO $ do
64− print realImports
65− print ifaces
66− putStr "initialEnv " >> print initialEnv
67− return x
68− program' <- f $ rename initialEnv (program modul)
52+ do program' <- rename initialEnv (program modul)
69 return $ modul { program = program' }
53 return $ modul { program = program' }
70 where
54 where
71 get1 (a,_,_) = a
55 get1 (a,_,_) = a
@@ -79,18 +63,14 @@ metadataModule ifaces modul =
79 As alias -> map (pair (alias ++ ".")) allNames
63 As alias -> map (pair (alias ++ ".")) allNames
80 Hiding vars -> map (pair "") $ filter (flip Set.notMember vs) allNames
64 Hiding vars -> map (pair "") $ filter (flip Set.notMember vs) allNames
81 where vs = Set.fromList vars
65 where vs = Set.fromList vars
82− Importing vars -> f $ map (pair "") $ filter (flip Set.member vs) allNames
66+ Importing vars -> map (pair "") $ filter (flip Set.member vs) allNames
83 where vs = Set.fromList $ map (\v -> name ++ "." ++ v) vars
67 where vs = Set.fromList $ map (\v -> name ++ "." ++ v) vars
84− f y = unsafePerformIO $ do
85− print vs
86− print allNames
87− print y
88− return y
89
68
90 pair n = (n,n)
69 pair n = (n,n)
91 localEnv = concat [ map (pair . get1) (aliases modul)
70 localEnv = concat [ map (pair . get1) (aliases modul)
92 , map (pair . get1) (datatypes modul) ]
71 , map (pair . get1) (datatypes modul) ]
93− globalEnv = map pair $ [ saveEnvName, "::", "[]" ] ++ map (\n -> "_Tuple" ++ show n) [0..9]
72+ globalEnv = map pair $ ["_List",saveEnvName,"::","[]","Int","Float","Char","Bool"] ++
73+ map (\n -> "_Tuple" ++ show n) [0..9]
94 realImports = filter (not . List.isPrefixOf "Native." . fst) (imports modul)
74 realImports = filter (not . List.isPrefixOf "Native." . fst) (imports modul)
95 initialEnv = Map.fromList (concatMap canon realImports ++ localEnv ++ globalEnv)
75 initialEnv = Map.fromList (concatMap canon realImports ++ localEnv ++ globalEnv)
96
76
@@ -139,7 +119,7 @@ rename env lexpr@(L t s expr) =
139 frnm (f,e) = (,) f `liftM` rename env e
119 frnm (f,e) = (,) f `liftM` rename env e
140
120
141 Binop op e1 e2 ->
121 Binop op e1 e2 ->
142− do op' <- if isOp op then return op else format (replace env op)
122+ do op' <- format (replace env op)
143 Binop op' `liftM` rnm e1 `ap` rnm e2
123 Binop op' `liftM` rnm e1 `ap` rnm e2
144
124
145 Lambda pattern e ->
125 Lambda pattern e ->