@@ -34,12 +34,12 @@ import Data.List
3434import Data.Maybe
3535import Debug.Trace
3636
37−data DExp = DV LVar
37+data DExp = DV Name
3838 | DApp Bool Name [DExp] -- True = tail call
3939 | DLet Name DExp DExp -- name just for pretty printing
4040 | DUpdate Name DExp -- eval expression, then update var with it
4141 | DProj DExp Int
42− | DC (Maybe LVar) Int Name [DExp]
42+ | DC (Maybe Name) Int Name [DExp]
4343 | DCase CaseType DExp [DAlt]
4444 | DChkCase DExp [DAlt] -- a case where the type is unknown (for EVAL/APPLY)
4545 | DConst Const
@@ -90,27 +90,27 @@ addApps defs (n, LFun _ _ args e)
9090 return (n, DFun n args e')
9191 where
9292 aa :: [Name] -> LExp -> State ([Name], [(Name, Int)]) DExp
93− aa env (LV (Glob n)) | n `elem` env = return $ DV (Glob n)
94− | otherwise = aa env (LApp False (LV (Glob n)) [])
95− aa env (LApp tc (LV (Glob n)) args)
93+ aa env (LV n) | n `elem` env = return $ DV n
94+ | otherwise = aa env (LApp False (LV n) [])
95+ aa env (LApp tc (LV n) args)
9696 = do args' <- mapM (aa env) args
9797 case lookupCtxtExact n defs of
9898 Just (LConstructor _ i ar) -> return $ DApp tc n args'
9999 Just (LFun _ _ as _) -> let arity = length as in
100100 fixApply tc n args' arity
101− Nothing -> return $ chainAPPLY (DV (Glob n)) args'
101+ Nothing -> return $ chainAPPLY (DV n) args'
102102 aa env (LLazyApp n args)
103103 = do args' <- mapM (aa env) args
104104 case lookupCtxtExact n defs of
105105 Just (LConstructor _ i ar) -> return $ DApp False n args'
106106 Just (LFun _ _ as _) -> let arity = length as in
107107 fixLazyApply n args' arity
108− Nothing -> return $ chainAPPLY (DV (Glob n)) args'
109− aa env (LForce (LLazyApp n args)) = aa env (LApp False (LV (Glob n)) args)
108+ Nothing -> return $ chainAPPLY (DV n) args'
109+ aa env (LForce (LLazyApp n args)) = aa env (LApp False (LV n) args)
110110 aa env (LForce e) = liftM eEVAL (aa env e)
111111 aa env (LLet n v sc) = liftM2 (DLet n) (aa env v) (aa (n : env) sc)
112112 aa env (LCon loc i n args) = liftM (DC loc i n) (mapM (aa env) args)
113− aa env (LProj t@(LV (Glob n)) i)
113+ aa env (LProj t@(LV n) i)
114114 | n `elem` env = do t' <- aa env t
115115 return $ DProj (DUpdate n t') i
116116 aa env (LProj t i) = do t' <- aa env t
@@ -170,7 +170,7 @@ addApps defs (n, LFun _ _ args e)
170170
171171 preEval [] t = t
172172 preEval (x : xs) t
173− | needsEval x t = DLet x (DV (Glob x)) (preEval xs t)
173+ | needsEval x t = DLet x (DV x) (preEval xs t)
174174 | otherwise = preEval xs t
175175
176176 needsEval x (DApp _ _ args) = any (needsEval x) args
@@ -188,7 +188,7 @@ addApps defs (n, LFun _ _ args e)
188188 | otherwise = needsEval x v || needsEval x e
189189 needsEval x (DForeign _ _ args) = any (needsEval x) (map snd args)
190190 needsEval x (DOp op args) = any (needsEval x) args
191− needsEval x (DProj (DV (Glob x')) _) = x == x'
191+ needsEval x (DProj (DV x') _) = x == x'
192192 needsEval x _ = False
193193
194194eEVAL x = DApp False (sMN 0 "EVAL") [x]
@@ -207,7 +207,7 @@ toCons ns (n, i)
207207 EvalCase (\tlarg ->
208208 (DConCase (-1) (mkFnCon n) (take i (genArgs 0))
209209 (dupdate tlarg
210− (DApp False n (map (DV . Glob) (take i (genArgs 0))))))))
210+ (DApp False n (map DV (take i (genArgs 0))))))))
211211 : [] -- mkApplyCase n 0 i
212212 | otherwise = []
213213 where dupdate tlarg x = DUpdate tlarg x
@@ -219,7 +219,7 @@ toConsA ns (n, i)
219219-- EvalCase (\tlarg ->
220220-- (DConCase (-1) (mkFnCon n) (take i (genArgs 0))
221221-- (dupdate tlarg
222−-- (DApp False n (map (DV . Glob) (take i (genArgs 0))))))))
222+-- (DApp False n (map DV (take i (genArgs 0))))))))
223223 = mkApplyCase n ar i
224224 | otherwise = []
225225 where dupdate tlarg x = x
@@ -229,13 +229,13 @@ mkApplyCase fname n ar
229229 = let nm = mkUnderCon fname (ar - n) in
230230 (nm, n, ApplyCase (DConCase (-1) nm (take n (genArgs 0))
231231 (DApp False (mkUnderCon fname (ar - (n + 1)))
232− (map (DV . Glob) (take n (genArgs 0) ++
232+ (map DV (take n (genArgs 0) ++
233233 [sMN 0 "arg"])))))
234234 :
235235 if (ar - (n + 2) >=0 )
236236 then (nm, n, Apply2Case (DConCase (-1) nm (take n (genArgs 0))
237237 (DApp False (mkUnderCon fname (ar - (n + 2)))
238− (map (DV . Glob) (take n (genArgs 0) ++
238+ (map DV (take n (genArgs 0) ++
239239 [sMN 0 "arg0", sMN 0 "arg1"])))))
240240 :
241241 mkApplyCase fname (n + 1) ar
@@ -243,9 +243,9 @@ mkApplyCase fname n ar
243243
244244mkEval :: [(Name, Int, EvalApply DAlt)] -> (Name, DDecl)
245245mkEval xs = (sMN 0 "EVAL", DFun (sMN 0 "EVAL") [sMN 0 "arg"]
246− (mkBigCase (sMN 0 "EVAL") 256 (DV (Glob (sMN 0 "arg")))
246+ (mkBigCase (sMN 0 "EVAL") 256 (DV (sMN 0 "arg"))
247247 (mapMaybe evalCase xs ++
248− [DDefaultCase (DV (Glob (sMN 0 "arg")))])))
248+ [DDefaultCase (DV (sMN 0 "arg"))])))
249249 where
250250 evalCase (n, t, EvalCase x) = Just (x (sMN 0 "arg"))
251251 evalCase _ = Nothing
@@ -256,7 +256,7 @@ mkApply xs = (sMN 0 "APPLY", DFun (sMN 0 "APPLY") [sMN 0 "fn", sMN 0 "arg"]
256256 [] -> DNothing
257257 cases ->
258258 mkBigCase (sMN 0 "APPLY") 256
259− (DV (Glob (sMN 0 "fn")))
259+ (DV (sMN 0 "fn"))
260260 (cases ++
261261 [DDefaultCase DNothing])))
262262 where
@@ -269,14 +269,14 @@ mkApply2 xs = (sMN 0 "APPLY2", DFun (sMN 0 "APPLY2") [sMN 0 "fn", sMN 0 "arg0",
269269 [] -> DNothing
270270 cases ->
271271 mkBigCase (sMN 0 "APPLY") 256
272− (DV (Glob (sMN 0 "fn")))
272+ (DV (sMN 0 "fn"))
273273 (cases ++
274274 [DDefaultCase
275275 (DApp False (sMN 0 "APPLY")
276276 [DApp False (sMN 0 "APPLY")
277− [DV (Glob (sMN 0 "fn")),
278− DV (Glob (sMN 0 "arg0"))],
279− DV (Glob (sMN 0 "arg1"))])
277+ [DV (sMN 0 "fn"),
278+ DV (sMN 0 "arg0")],
279+ DV (sMN 0 "arg1")])
280280 ])))
281281 where
282282 applyCase (n, t, Apply2Case x) = Just x
@@ -297,8 +297,7 @@ mkUnderCon n missing = sMN missing ("U_" ++ show n)
297297
298298instance Show DExp where
299299 show e = show' [] e where
300− show' env (DV (Loc i)) = "var " ++ env!!i
301− show' env (DV (Glob n)) = "GLOB " ++ show n
300+ show' env (DV n) = show n
302301 show' env (DApp _ e args) = show e ++ "(" ++
303302 showSep ", " (map (show' env) args) ++")"
304303 show' env (DLet n v e) = "let " ++ show n ++ " = " ++ show' env v ++ " in " ++