on master help sign in
Add Transform module; make implicit args lazy
commit6e699c730bbf1e7ba3fb2bfd2ffd475e2a845f07 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateThu 12 Jan 2012, 20:46 (15 years ago) parentae47b8f
4 files changed+47−2
idris.cabal+1−1 src/Idris/AbsSyntax.hs+1−1 src/Idris/Compiler.hs+1 src/Idris/Transforms.hs+44
idris.cabal+1−1
@@ -61,7 +61,7 @@ Executable idris
6161 Idris.Delaborate, Idris.Primitives, Idris.Imports,
6262 Idris.Compiler, Idris.Prover, Idris.ElabTerm,
6363 Idris.Coverage, Idris.IBC, Idris.Unlit,
64− Idris.DataOpts
64+ Idris.DataOpts, Idris.Transforms,
6565
6666 Paths_idris
6767
src/Idris/AbsSyntax.hs+1−1
@@ -521,7 +521,7 @@ data PArg' t = PImp { priority :: Int,
521521deriving instance Binary PArg'
522522!-}
523523
524−pimp = PImp 0 False
524+pimp = PImp 0 True
525525pexp = PExp 0 False
526526pconst = PConstraint 0 False
527527
src/Idris/Compiler.hs+1
@@ -3,6 +3,7 @@
33module Idris.Compiler where
44
55import Idris.AbsSyntax
6+import Idris.Transforms
67
78import Core.TT
89import Core.Evaluate
src/Idris/Transforms.hsnew file+44
@@ -0,0 +1,44 @@
1+{-# LANGUAGE PatternGuards #-}
2+
3+module Idris.Transforms where
4+
5+import Idris.AbsSyntax
6+import Core.CaseTree
7+import Core.TT
8+
9+class Transform a where
10+ transform :: (a -> a) -> a -> a
11+
12+instance Transform (TT Name) where
13+ transform t x = t (trans' x) where
14+ trans' (Bind n b sc) = Bind n (fmap (transform t) b) (transform t sc)
15+ trans' (App f a) = App (transform t f) (transform t a)
16+ trans' x = x
17+
18+type TTOpt = TT Name -> TT Name
19+
20+optimisations :: [TTOpt]
21+optimisations = [zero, suc]
22+
23+instance Transform SC where
24+ transform t x = t (trans' x) where
25+ trans' (Case n alts) = Case n (map transAlt alts)
26+ trans' t = t
27+
28+ transAlt (ConCase n i as sc) = ConCase n i as (trans' sc)
29+ transAlt (ConstCase c sc) = ConstCase c (trans' sc)
30+ transAlt (DefaultCase sc) = DefaultCase (trans' sc)
31+
32+type CaseOpt = SC -> SC
33+
34+zero :: TTOpt
35+zero (P _ n _) | n == NS (UN "O") ["nat","prelude"]
36+ = Constant (BI 0)
37+zero x = x
38+
39+suc :: TTOpt
40+suc (App (P _ s _) a) | s == NS (UN "S") ["nat","prelude"]
41+ = mkApp (P Ref (UN "prim__addBigInt") Erased) [Constant (BI 1), a]
42+suc x = x
43+
44+