diff --git a/Makefile_happysrcs b/Makefile_happysrcs index e0dc43e..1d32855 100644 --- a/Makefile_happysrcs +++ b/Makefile_happysrcs @@ -8,8 +8,8 @@ CABAL_BUILD = dist-newstyle/build/x86_64-osx/ghc-9.6.2/rlp-0.1.0.0/build all: parsers lexers -parsers: $(CABAL_BUILD)/Rlp/Parse.hs -lexers: $(CABAL_BUILD)/Rlp/Lex.hs +parsers: $(CABAL_BUILD)/Rlp/Parse.hs $(CABAL_BUILD)/Core/Parse.hs +lexers: $(CABAL_BUILD)/Rlp/Lex.hs $(CABAL_BUILD)/Core/Lex.hs $(CABAL_BUILD)/Rlp/Parse.hs: $(SRC)/Rlp/Parse.y $(HAPPY) $(HAPPY_OPTS) $< -o $@ @@ -17,3 +17,9 @@ $(CABAL_BUILD)/Rlp/Parse.hs: $(SRC)/Rlp/Parse.y $(CABAL_BUILD)/Rlp/Lex.hs: $(SRC)/Rlp/Lex.x $(ALEX) $(ALEX_OPTS) $< -o $@ +$(CABAL_BUILD)/Core/Parse.hs: $(SRC)/Core/Parse.y + $(HAPPY) $(HAPPY_OPTS) $< -o $@ + +$(CABAL_BUILD)/Core/Lex.hs: $(SRC)/Core/Lex.x + $(ALEX) $(ALEX_OPTS) $< -o $@ + diff --git a/src/Compiler/JustRun.hs b/src/Compiler/JustRun.hs index c3178f3..6a0d4ca 100644 --- a/src/Compiler/JustRun.hs +++ b/src/Compiler/JustRun.hs @@ -26,22 +26,23 @@ import Data.Function ((&)) import GM ---------------------------------------------------------------------------------- --- justLexSrc :: String -> Either RlpcError [CoreToken] +justLexSrc :: String -> Either [MsgEnvelope RlpcError] [CoreToken] justLexSrc s = lexCoreR (T.pack s) & fmap (map $ \ (Located _ _ _ t) -> t) & rlpcToEither --- justParseSrc :: String -> Either RlpcError Program' +justParseSrc :: String -> Either [MsgEnvelope RlpcError] Program' justParseSrc s = parse (T.pack s) & rlpcToEither where parse = lexCoreR >=> parseCoreProgR --- justTypeCheckSrc :: String -> Either RlpcError Program' +justTypeCheckSrc :: String -> Either [MsgEnvelope RlpcError] Program' justTypeCheckSrc s = typechk (T.pack s) & rlpcToEither where typechk = lexCoreR >=> parseCoreProgR >=> checkCoreProgR -rlpcToEither = undefined - -{-# WARNING rlpcToEither "unimpl" #-} +rlpcToEither :: RLPC a -> Either [MsgEnvelope RlpcError] a +rlpcToEither r = case evalRLPC def r of + (Just a, _) -> Right a + (Nothing, es) -> Left es diff --git a/src/Core/Parse.y b/src/Core/Parse.y index a084ebf..b8a0cf3 100644 --- a/src/Core/Parse.y +++ b/src/Core/Parse.y @@ -98,6 +98,8 @@ ScDefs : ScDef ';' ScDefs { $1 : $3 } ScDef :: { ScDef Name } ScDef : Var ParList '=' Expr { ScDef $1 $2 $4 } + -- hack to allow constructors to be compiled into scs + | Con ParList '=' Expr { ScDef $1 $2 $4 } Type :: { Type } Type : Type1 { $1 }