Skip to content

Commit

Permalink
Make pre-commit happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaprieto committed Feb 7, 2023
1 parent 49b9198 commit 488ca9e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
7 changes: 4 additions & 3 deletions app/Commands/Dev/Geb/Eval.hs
Expand Up @@ -40,8 +40,7 @@ evalAndPrint opts = \case
{ _envEvaluatorOptions = opts',
_envContext = Geb.emptyContext
}
nf <- runM . runError . runReader env $ Geb.nf morphism
case nf of
case Geb.nf' env morphism of
Left err -> exitJuvixError err
Right m -> renderStdOut (Geb.ppOut opts' m)
Geb.ExpressionObject _ -> error gebObjNoEvalMsg
Expand Down Expand Up @@ -69,6 +68,8 @@ runEval RunEvalArgs {..} =
{ _envEvaluatorOptions = _runEvalArgsEvaluatorOptions,
_envContext = Geb.emptyContext
}
Geb.ExpressionMorphism <$> Geb.nf' morphism env
case Geb.nf' env morphism of
Right m -> Right (Geb.ExpressionMorphism m)
Left err -> Left (JuvixError err)
Right _ -> Left (error @JuvixError gebObjNoEvalMsg)
Left err -> Left (JuvixError err)
3 changes: 0 additions & 3 deletions app/Commands/Dev/Geb/Repl/Colors.hs
Expand Up @@ -30,9 +30,6 @@ formatIntro =
Ansi.SetColor Ansi.Foreground Ansi.Dull promptColor
]

formatLoading :: String
formatLoading = formatIntro

formatPrompt :: String
formatPrompt =
Ansi.setSGRCode
Expand Down
10 changes: 8 additions & 2 deletions src/Juvix/Compiler/Backend/Geb/Evaluator.hs
Expand Up @@ -281,6 +281,12 @@ fromGebValue ty = \case
_ -> error "fromGebValue: type mismatch (pair). Expected a product"
GebValueClosure cls -> return $ MorphismLambda $ cls ^. valueClosureLambda

eval' ::
Env ->
Morphism ->
Either JuvixError GebValue
eval' env m = run . runError $ runReader env (eval m)

nf ::
Members '[Reader Env, Error JuvixError] r =>
Morphism ->
Expand All @@ -291,7 +297,7 @@ nf m = do
fromGebValue ty val

nf' ::
Morphism ->
Env ->
Morphism ->
Either JuvixError Morphism
nf' m env = run . runError $ runReader env (nf m)
nf' env m = run . runError $ runReader env (nf m)
Expand Up @@ -4,15 +4,8 @@ import Juvix.Compiler.Backend.Geb.Extra qualified as Geb
import Juvix.Compiler.Backend.Geb.Language qualified as Geb
import Juvix.Prelude

objectBinop :: Geb.Binop -> Geb.Object
objectBinop op = case op ^. Geb.binopOpcode of
Geb.OpAdd -> Geb.ObjectInteger
Geb.OpSub -> Geb.ObjectInteger
Geb.OpMul -> Geb.ObjectInteger
Geb.OpDiv -> Geb.ObjectInteger
Geb.OpMod -> Geb.ObjectInteger
Geb.OpEq -> Geb.objectBool
Geb.OpLt -> Geb.objectBool
inferObject' :: Geb.Morphism -> Either JuvixError Geb.Object
inferObject' = run . runError @JuvixError . inferObject

inferObject ::
Members '[Error JuvixError] r =>
Expand Down Expand Up @@ -66,11 +59,27 @@ inferObject = \case
Geb.MorphismBinop op -> do
aTy <- inferObject (op ^. Geb.binopLeft)
bTy <- inferObject (op ^. Geb.binopRight)
unless (aTy == bTy) (error "Binop arguments should have the same type")
return aTy
unless
(aTy == bTy)
(error "Arguments of a binary operation should have the same type")
return $ objectBinop op
Geb.MorphismVar {} ->
-- TODO: We should be able to infer the type of a variable.
error $ lackOfInformation <> " on a variable"
-- FIXME: Once https://github.com/anoma/geb/issues/53 is fixed, we should
-- modify the following cases.
Geb.MorphismLeft {} -> error $ lackOfInformation <> " on a left morphism"
Geb.MorphismRight {} -> error $ lackOfInformation <> " on a right morphism"
Geb.MorphismVar {} -> error $ lackOfInformation <> " on a variable"

lackOfInformation :: Text
lackOfInformation = "Not enough information to infer the type"
lackOfInformation = "Not enough information to infer the type"

objectBinop :: Geb.Binop -> Geb.Object
objectBinop op = case op ^. Geb.binopOpcode of
Geb.OpAdd -> Geb.ObjectInteger
Geb.OpSub -> Geb.ObjectInteger
Geb.OpMul -> Geb.ObjectInteger
Geb.OpDiv -> Geb.ObjectInteger
Geb.OpMod -> Geb.ObjectInteger
Geb.OpEq -> Geb.objectBool
Geb.OpLt -> Geb.objectBool

0 comments on commit 488ca9e

Please sign in to comment.