|
43 | 43 | module Main (main, specMain) where |
44 | 44 |
|
45 | 45 | #if __GLASGOW_HASKELL__ >= 906 |
| 46 | +import StaticNamed |
46 | 47 | import GHC.StaticPtr |
47 | 48 | import Language.Haskell.TH (TExp, examineCode) |
48 | 49 | import Control.Monad |
@@ -546,6 +547,41 @@ lookg :: Gar env t -> env -> TH.Code Q t |
546 | 547 | lookg (ZGar slot) (_, x) = [|| $$slot $$x ||] |
547 | 548 | lookg (SGar v) (env, _) = lookg v env |
548 | 549 |
|
| 550 | +-------------------------------------------------------------------------------- |
| 551 | +-- StaticPtr-based TH support |
| 552 | + |
| 553 | +-- $((>>= TH.stringE . show . TH.ppr) $ TH.unTypeCode $ compl () $ AppS (LamS (SarS (ZSar [|| id ||]))) $ LitS staticTup) |
| 554 | +-- "(\\x_0 -> GHC.Internal.Base.id x_0) (GHC.Internal.StaticPtr.deRefStaticPtr (StaticNamed.grab GHC.Internal.Base.$ Data.Text.unpackCStringLen# \"<binary data>\" (GHC.Types.I# 42#)))" |
| 555 | +-- |
| 556 | +-- ghci> $$(compl () $ AppS (LamS (SarS (ZSar [|| id ||]))) $ LitS staticTup) |
| 557 | +-- () |
| 558 | + |
| 559 | +data Serm g t where |
| 560 | + SarS :: Sar g t -> Serm g t |
| 561 | + LamS :: Serm (g, TH.Code Q a) b -> Serm g (a -> b) |
| 562 | + AppS :: Serm g (s -> t) -> Serm g s -> Serm g t |
| 563 | + LitS :: StaticPtr a -> Serm g a |
| 564 | + |
| 565 | +data Sar g t where |
| 566 | + ZSar :: TH.Code Q (t -> a) -> Sar (h, TH.Code Q t) a |
| 567 | + SSar :: Sar h t -> Sar (h, s) t |
| 568 | + |
| 569 | +-- This is the complr. Type-safe and total. |
| 570 | +compl :: env -> Serm env t -> TH.Code Q t |
| 571 | +compl env (SarS v) = looks v env |
| 572 | +compl env (LamS e) = [|| \x -> $$(compl (env, [||x||]) e) ||] |
| 573 | +compl env (AppS e1 e2) = [|| $$(compl env e1) $$(compl env e2) ||] |
| 574 | +compl _env (LitS a) = [|| deRefStaticPtr a ||] |
| 575 | + |
| 576 | +-- Type-safe, total lookup. The final @slot@ determines which slot of |
| 577 | +-- a given tuple to pick out. |
| 578 | +looks :: Sar env t -> env -> TH.Code Q t |
| 579 | +looks (ZSar slot) (_, x) = [|| $$slot $$x ||] |
| 580 | +looks (SSar v) (env, _) = looks v env |
| 581 | + |
| 582 | +staticTup :: StaticPtr () |
| 583 | +staticTup = static () |
| 584 | + |
549 | 585 | -------------------------------------------------------------------------------- |
550 | 586 | -- Typed AST support for eval |
551 | 587 | -- |
|
0 commit comments