when the "Test suite rlp-test: PASS" hits

i'm like atlas and the world is writing two lines of code
This commit is contained in:
crumbtoo
2024-01-21 14:02:28 -07:00
parent 257d02da87
commit 1a881399ab
11 changed files with 112 additions and 79 deletions

View File

@@ -15,12 +15,12 @@ import Core.Syntax
import Core.TH
----------------------------------------------------------------------------------
fac3 = undefined
sumList = undefined
constDivZero = undefined
idCase = undefined
-- fac3 = undefined
-- sumList = undefined
-- constDivZero = undefined
-- idCase = undefined
{--
---
letrecExample :: Program'
letrecExample = [coreProg|

View File

@@ -25,6 +25,7 @@ import Control.Monad (foldM, void)
import Control.Monad.Errorful (Errorful, addFatal)
import Control.Monad.State
import Control.Monad.Utils (mapAccumLM)
import Text.Printf
import Core.Syntax
----------------------------------------------------------------------------------
@@ -48,8 +49,20 @@ data TypeError
| TyErrMissingTypeSig Name
deriving (Show, Eq)
-- TODO:
instance IsRlpcError TypeError where
liftRlpcError = \case
-- todo: use anti-parser instead of show
TyErrCouldNotUnify t u -> Text
[ T.pack $ printf "Could not match type `%s' with `%s'."
(show t) (show u)
, "Expected: " <> tshow t
, "Got: " <> tshow u
]
TyErrRecursiveType t x -> Text
[ T.pack $ printf "recursive type error lol"
]
where tshow = T.pack . show
-- | Synonym for @Errorful [TypeError]@. This means an @HMError@ action may
-- throw any number of fatal or nonfatal errors. Run with @runErrorful@.
@@ -87,10 +100,10 @@ checkCoreProg p = scDefs
where scname = sc ^. _lhs._1
-- | @checkCoreProgR p@ returns @p@ if @p@ successfully typechecks.
-- checkCoreProgR :: Program' -> RLPC Program'
checkCoreProgR = undefined
{-# WARNING checkCoreProgR "unimpl" #-}
checkCoreProgR :: Program' -> RLPC Program'
checkCoreProgR p = do
liftErrorful (checkCoreProg p)
pure p
-- | Infer the type of an expression under some context.
--

View File

@@ -169,17 +169,13 @@ lexWith f (AlexPn _ y x,_,_,s) l = pure $ Located y x l (f $ T.take l s)
-- | The main lexer driver.
lexCore :: Text -> RLPC [Located CoreToken]
lexCore s = case m of
Left e -> undefined
Left e -> error "core lex error"
Right ts -> pure ts
where
m = runAlex s lexStream
{-# WARNING lexCore "unimpl" #-}
lexCoreR :: Text -> RLPC [Located CoreToken]
lexCoreR t = undefined
{-# WARNING lexCoreR "unimpl" #-}
lexCoreR = lexCore
-- | @lexCore@, but the tokens are stripped of location info. Useful for
-- debugging
@@ -200,9 +196,11 @@ data ParseError = ParErrLexical String
-- TODO:
instance IsRlpcError SrcError where
liftRlpcError = Text . pure . T.pack . show
-- TODO:
instance IsRlpcError ParseError where
liftRlpcError = Text . pure . T.pack . show
alexEOF :: Alex (Located CoreToken)
alexEOF = Alex $ \ st@(AlexState { alex_pos = AlexPn _ y x }) ->

View File

@@ -189,7 +189,9 @@ Con : '(' consym ')' { $2 }
{
parseError :: [Located CoreToken] -> RLPC a
parseError (Located y x l _ : _) = undefined
parseError (Located y x l t : _) =
error $ show y <> ":" <> show x
<> ": parse error at token `" <> show t <> "'"
{-# WARNING parseError "unimpl" #-}
@@ -217,9 +219,7 @@ singletonScDef :: (Hashable b) => ScDef b -> Program b
singletonScDef sc = insScDef sc mempty
parseCoreProgR :: [Located CoreToken] -> RLPC Program'
parseCoreProgR a = undefined
{-# WARNING parseCoreProgR "unimpl" #-}
parseCoreProgR = parseCoreProg
happyBind :: RLPC a -> (a -> RLPC b) -> RLPC b
happyBind m k = m >>= k

View File

@@ -6,7 +6,6 @@ module Core.TH
( coreExpr
, coreProg
, coreProgT
, core
)
where
----------------------------------------------------------------------------------
@@ -14,65 +13,38 @@ import Language.Haskell.TH
import Language.Haskell.TH.Syntax hiding (Module)
import Language.Haskell.TH.Quote
import Control.Monad ((>=>))
import Control.Monad.IO.Class
import Control.Arrow ((>>>))
import Compiler.RLPC
import Data.Default.Class (def)
import Data.Text (Text)
import Data.Text qualified as T
import Core.Parse
import Core.Lex
import Core.Syntax (Expr(Var))
import Core.Syntax
import Core.HindleyMilner (checkCoreProgR)
----------------------------------------------------------------------------------
-- TODO: write in terms of a String -> QuasiQuoter
core :: QuasiQuoter
core = QuasiQuoter
{ quoteExp = qCore
, quotePat = error "core quasiquotes may only be used in expressions"
, quoteType = error "core quasiquotes may only be used in expressions"
, quoteDec = error "core quasiquotes may only be used in expressions"
}
coreProg :: QuasiQuoter
coreProg = QuasiQuoter
{ quoteExp = qCoreProg
, quotePat = error "core quasiquotes may only be used in expressions"
, quoteType = error "core quasiquotes may only be used in expressions"
, quoteDec = error "core quasiquotes may only be used in expressions"
}
coreProg = mkqq $ lexCoreR >=> parseCoreProgR
coreExpr :: QuasiQuoter
coreExpr = QuasiQuoter
{ quoteExp = qCoreExpr
, quotePat = error "core quasiquotes may only be used in expressions"
, quoteType = error "core quasiquotes may only be used in expressions"
, quoteDec = error "core quasiquotes may only be used in expressions"
}
coreExpr = mkqq $ lexCoreR >=> parseCoreExpr
-- | Type-checked @coreProg@
coreProgT :: QuasiQuoter
coreProgT = QuasiQuoter
{ quoteExp = qCoreProgT
coreProgT = mkqq $ lexCoreR >=> parseCoreProgR >=> checkCoreProgR
mkqq :: (Lift a) => (Text -> RLPC a) -> QuasiQuoter
mkqq p = QuasiQuoter
{ quoteExp = mkq p
, quotePat = error "core quasiquotes may only be used in expressions"
, quoteType = error "core quasiquotes may only be used in expressions"
, quoteDec = error "core quasiquotes may only be used in expressions"
}
qCore :: String -> Q Exp
qCore s = undefined
{-# WARNING qCore "unimpl" #-}
qCoreExpr :: String -> Q Exp
qCoreExpr s = undefined
{-# WARNING qCoreExpr "unimpl" #-}
qCoreProg :: String -> Q Exp
qCoreProg s = undefined
{-# WARNING qCoreProg "unimpl" #-}
qCoreProgT :: String -> Q Exp
qCoreProgT s = undefined
mkq :: (Lift a) => (Text -> RLPC a) -> String -> Q Exp
mkq parse s = case evalRLPC def (parse $ T.pack s) of
(Just a, _) -> lift a
(Nothing, _) -> error "todo: aaahhbbhjhbdjhabsjh"