This commit is contained in:
crumbtoo
2024-02-07 15:18:47 -07:00
parent 719d5a4089
commit 98bed84807
2 changed files with 23 additions and 3 deletions

View File

@@ -143,7 +143,11 @@ Type1 :: { RlpType' RlpcPs }
Type :: { RlpType' RlpcPs } Type :: { RlpType' RlpcPs }
: Type '->' Type { FunT <<~ $1 <~> $3 } : Type '->' Type { FunT <<~ $1 <~> $3 }
| Type1 { $1 } | TypeApp { $1 }
TypeApp :: { RlpType' RlpcPs }
: Type1 { $1 }
| TypeApp Type1 { AppT <<~ $1 <~> $2 }
FunDecl :: { Decl' RlpcPs } FunDecl :: { Decl' RlpcPs }
FunDecl : Var Params '=' Expr { $4 =>> \e -> FunDecl : Var Params '=' Expr { $4 =>> \e ->
@@ -173,7 +177,11 @@ Expr :: { RlpExpr' RlpcPs }
OAppE (extract o) $1 $3 } OAppE (extract o) $1 $3 }
| LetExpr { $1 } | LetExpr { $1 }
| CaseExpr { $1 } | CaseExpr { $1 }
| Expr1 { $1 } | ExprApp { $1 }
ExprApp :: { RlpExpr' RlpcPs }
: Expr1 { $1 }
| ExprApp Expr1 { AppE <<~ $1 <~> $2 }
LetExpr :: { RlpExpr' RlpcPs } LetExpr :: { RlpExpr' RlpcPs }
: let layout1(Binding) in Expr { $1 \$> LetE $2 $4 } : let layout1(Binding) in Expr { $1 \$> LetE $2 $4 }

View File

@@ -1,7 +1,8 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE DeriveTraversable #-}
module Rlp2Core module Rlp2Core
( rlpProgToCore ( desugarRlpProg
, desugarRlpExpr
) )
where where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@@ -23,6 +24,7 @@ import Data.Foldable
import Data.Fix import Data.Fix
import Data.Maybe (fromJust, fromMaybe) import Data.Maybe (fromJust, fromMaybe)
import Data.Functor.Bind import Data.Functor.Bind
import Data.Function (on)
import Debug.Trace import Debug.Trace
import Effectful.State.Static.Local import Effectful.State.Static.Local
import Effectful.Labeled import Effectful.Labeled
@@ -51,6 +53,14 @@ type Rose = Fix Branch
deriveShow1 ''Branch deriveShow1 ''Branch
--------------------------------------------------------------------------------
desugarRlpProg :: RlpProgram RlpcPs -> Program'
desugarRlpProg = rlpProgToCore
desugarRlpExpr :: RlpExpr RlpcPs -> Expr'
desugarRlpExpr = runPureEff . runNameSupply "anon" . exprToCore
-- the rl' program is desugared by desugaring each declaration as a separate -- the rl' program is desugared by desugaring each declaration as a separate
-- program, and taking the monoidal product of the lot :3 -- program, and taking the monoidal product of the lot :3
@@ -95,6 +105,8 @@ exprToCore :: (NameSupply :> es) => RlpExpr RlpcPs -> Eff es Expr'
exprToCore (VarE n) = pure $ Var (dsNameToName n) exprToCore (VarE n) = pure $ Var (dsNameToName n)
exprToCore (AppE a b) = (liftA2 App `on` exprToCore . unXRec) a b
exprToCore (CaseE (unXRec -> e) as) = do exprToCore (CaseE (unXRec -> e) as) = do
e' <- exprToCore e e' <- exprToCore e
Case e' <$> caseAltToCore `traverse` as Case e' <$> caseAltToCore `traverse` as