@@ -17,21 +17,43 @@ desugar :: SyntaxInfo -> IState -> PTerm -> PTerm
1717desugar syn i t = let t' = expandDo (dsl_info syn) t in
1818 t' -- addImpl i t'
1919
20+mkTTName :: FC -> Name -> PTerm
21+mkTTName fc n =
22+ let mkList fc [] = PRef fc (sNS (sUN "Nil") ["List", "Prelude"])
23+ mkList fc (x:xs) = PApp fc (PRef fc (sNS (sUN "::") ["List", "Prelude"]))
24+ [ pexp (stringC x)
25+ , pexp (mkList fc xs)]
26+ stringC = PConstant . Str . str
27+ intC = PConstant . I
28+ reflm n = sNS (sUN n) ["Reflection", "Language"]
29+ in case n of
30+ UN nm -> PApp fc (PRef fc (reflm "UN")) [ pexp (stringC nm)]
31+ NS nm ns -> PApp fc (PRef fc (reflm "NS")) [ pexp (mkTTName fc nm)
32+ , pexp (mkList fc ns)]
33+ MN i nm -> PApp fc (PRef fc (reflm "MN")) [ pexp (intC i)
34+ , pexp (stringC nm)]
35+ otherwise -> PRef fc $ reflm "NErased"
36+
2037expandDo :: DSL -> PTerm -> PTerm
2138expandDo dsl (PLam fc n ty tm)
2239 | Just lam <- dsl_lambda dsl
23− = let sc = PApp fc lam [pexp (var dsl n tm 0)] in
24− expandDo dsl sc
40+ = let sc = PApp fc lam [ pexp (mkTTName fc n)
41+ , pexp (var dsl n tm 0)]
42+ in expandDo dsl sc
2543expandDo dsl (PLam fc n ty tm) = PLam fc n (expandDo dsl ty) (expandDo dsl tm)
2644expandDo dsl (PLet fc n ty v tm)
2745 | Just letb <- dsl_let dsl
28− = let sc = PApp (fileFC "(dsl)") letb [pexp v, pexp (var dsl n tm 0)] in
29− expandDo dsl sc
46+ = let sc = PApp (fileFC "(dsl)") letb [ pexp (mkTTName fc n)
47+ , pexp v
48+ , pexp (var dsl n tm 0)]
49+ in expandDo dsl sc
3050expandDo dsl (PLet fc n ty v tm) = PLet fc n (expandDo dsl ty) (expandDo dsl v) (expandDo dsl tm)
3151expandDo dsl (PPi p n ty tm)
3252 | Just pi <- dsl_pi dsl
33− = let sc = PApp (fileFC "(dsl)") pi [pexp ty, pexp (var dsl n tm 0)] in
34− expandDo dsl sc
53+ = let sc = PApp (fileFC "(dsl)") pi [ pexp (mkTTName (fileFC "(dsl)") n)
54+ , pexp ty
55+ , pexp (var dsl n tm 0)]
56+ in expandDo dsl sc
3557expandDo dsl (PPi p n ty tm) = PPi p n (expandDo dsl ty) (expandDo dsl tm)
3658expandDo dsl (PApp fc t args) = PApp fc (expandDo dsl t)
3759 (map (fmap (expandDo dsl)) args)