diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-16 07:55:08 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-16 07:55:08 +0200 |
commit | 629f80cfeedd133f0ccca596dc33a4b54d2369eb (patch) | |
tree | d9ca178db2a59284106a262dc405f1fc04b88994 /prototypes | |
parent | de20e6bd0dc14e1f1d35a9e3d2ea3516cef6d1c3 (diff) |
next steps
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/LamMachine.hs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/prototypes/LamMachine.hs b/prototypes/LamMachine.hs index ccbe7517..b98f84e3 100644 --- a/prototypes/LamMachine.hs +++ b/prototypes/LamMachine.hs | |||
@@ -53,7 +53,7 @@ data MSt = MSt [(FreeVars, Exp)] -- TODO: use finger tree instead of list | |||
53 | --------------------------------------------------------------------- toolbox: pretty print | 53 | --------------------------------------------------------------------- toolbox: pretty print |
54 | 54 | ||
55 | instance PShow Exp where | 55 | instance PShow Exp where |
56 | pShow x = case pushUps x of | 56 | pShow x = case {-pushUps-} x of |
57 | Var i -> DVar i | 57 | Var i -> DVar i |
58 | App a b -> DApp (pShow a) (pShow b) | 58 | App a b -> DApp (pShow a) (pShow b) |
59 | Seq a b -> DOp "`seq`" (Infix 1) (pShow a) (pShow b) | 59 | Seq a b -> DOp "`seq`" (Infix 1) (pShow a) (pShow b) |
@@ -66,6 +66,7 @@ instance PShow Exp where | |||
66 | Op2 o x y -> text (show o) `DApp` pShow x `DApp` pShow y | 66 | Op2 o x y -> text (show o) `DApp` pShow x `DApp` pShow y |
67 | Y e -> "Y" `DApp` pShow e | 67 | Y e -> "Y" `DApp` pShow e |
68 | Case e xs -> DPreOp (-20) (ComplexAtom "case" (-10) (pShow e) (SimpleAtom "of")) $ foldr1 DSemi [DArr_ "->" (text a) (pShow b) | (a, b) <- xs] | 68 | Case e xs -> DPreOp (-20) (ComplexAtom "case" (-10) (pShow e) (SimpleAtom "of")) $ foldr1 DSemi [DArr_ "->" (text a) (pShow b) | (a, b) <- xs] |
69 | Ups u xs -> DPreOp (-20) (SimpleAtom $ show u) $ pShow xs | ||
69 | 70 | ||
70 | shLam_ usedVar b = DFreshName usedVar $ showLam (DVar 0) b | 71 | shLam_ usedVar b = DFreshName usedVar $ showLam (DVar 0) b |
71 | 72 | ||
@@ -123,9 +124,9 @@ dupCase f (getUs -> (a, ax)) (unzip -> (ss, unzip . map getUs -> (b, bx))) | |||
123 | dupLam f (Ups a ax) = Ups_ (ff a) $ Exp (shiftFreeVars (-1) $ getFreeVars ax') $ f ax' | 124 | dupLam f (Ups a ax) = Ups_ (ff a) $ Exp (shiftFreeVars (-1) $ getFreeVars ax') $ f ax' |
124 | where | 125 | where |
125 | ax' = case a of | 126 | ax' = case a of |
126 | Up 0 n: _ -> up (Up 0 n) ax | 127 | Up 0 n: _ -> up (Up 0 1) ax |
127 | _ -> ax | 128 | _ -> ax |
128 | ff (Up 0 n: us) = incUp (-1) <$> us | 129 | ff (Up 0 n: us) = insertUp (Up 0 $ n - 1) $ incUp (-1) <$> us |
129 | ff us = incUp (-1) <$> us | 130 | ff us = incUp (-1) <$> us |
130 | dupLam f x = f x | 131 | dupLam f x = f x |
131 | 132 | ||
@@ -169,7 +170,7 @@ pushUps e = e | |||
169 | showUps us = foldr f [] us where | 170 | showUps us = foldr f [] us where |
170 | f (Up l n) is = take n [l..] ++ map (n+) is | 171 | f (Up l n) is = take n [l..] ++ map (n+) is |
171 | 172 | ||
172 | sectUps' a b = sect (showUps a) (showUps b) -- sectUps 0 a 0 b | 173 | --sectUps' a b = sect (showUps a) (showUps b) -- sectUps 0 a 0 b |
173 | 174 | ||
174 | sect [] _ = [] | 175 | sect [] _ = [] |
175 | sect _ [] = [] | 176 | sect _ [] = [] |
@@ -224,6 +225,7 @@ diffUpsTest' = diffUpsTest [x,y] --diffUpsTest x y | |||
224 | x = [Up 1 2, Up 3 4, Up 8 2] | 225 | x = [Up 1 2, Up 3 4, Up 8 2] |
225 | y = [Up 2 2, Up 5 1, Up 6 2, Up 7 2] | 226 | y = [Up 2 2, Up 5 1, Up 6 2, Up 7 2] |
226 | 227 | ||
228 | insertUp u@(Up l 0) us = us | ||
227 | insertUp u@(Up l n) [] = [u] | 229 | insertUp u@(Up l n) [] = [u] |
228 | insertUp u@(Up l n) us_@(u'@(Up l' n'): us) | 230 | insertUp u@(Up l n) us_@(u'@(Up l' n'): us) |
229 | | l < l' = u: us_ | 231 | | l < l' = u: us_ |
@@ -282,7 +284,7 @@ down i x = Just $ down_ i x | |||
282 | down_ i e@(Exp s x) | 284 | down_ i e@(Exp s x) |
283 | | dbGE i s = e | 285 | | dbGE i s = e |
284 | down_ i (Ups us e) = f i us e where | 286 | down_ i (Ups us e) = f i us e where |
285 | f i [] e = down_ i e | 287 | f i [] e = error $ "-- - - -- " ++ show i ++ " " ++ ppShow e ++ "\n" ++ ppShow (pushUps e) --"show down_ i e |
286 | f i (u@(Up j n): us) e | 288 | f i (u@(Up j n): us) e |
287 | | i < j = addUp (Up (j-1) n) $ f i us e | 289 | | i < j = addUp (Up (j-1) n) $ f i us e |
288 | | i >= j + n = addUp u $ f (i-n) us e | 290 | | i >= j + n = addUp u $ f (i-n) us e |
@@ -350,8 +352,8 @@ instance MachineMonad Identity where | |||
350 | collectSizeStat _ = return () | 352 | collectSizeStat _ = return () |
351 | 353 | ||
352 | instance MachineMonad IO where | 354 | instance MachineMonad IO where |
353 | traceStep s = return () | 355 | -- traceStep s = return () |
354 | -- traceStep = putStrLn | 356 | traceStep = putStrLn |
355 | collectSizeStat s = return () | 357 | collectSizeStat s = return () |
356 | 358 | ||
357 | instance MachineMonad (Writer [Int]) where | 359 | instance MachineMonad (Writer [Int]) where |