{-# LANGUAGE FlexibleContexts #-}

-- |
-- Module      : Jikka.Core.Language.Lint
-- Description : verifies various conditions (e.g. well-typed) of exprs of our core language. / core 言語の式の種々の条件 (例: 型付け可能性) を検査します。
-- Copyright   : (c) Kimiyuki Onaka, 2020
-- License     : Apache License 2.0
-- Maintainer  : kimiyuki95@gmail.com
-- Stability   : experimental
-- Portability : portable
--
-- `Jikka.Core.Language.Lint` module checks the invariants of data types. Mainly, this checks types of `Expr`.
module Jikka.Core.Language.Lint where

import Jikka.Common.Error
import Jikka.Core.Language.Expr
import Jikka.Core.Language.TypeCheck

precondition :: MonadError Error m => m a -> m a
precondition :: m a -> m a
precondition = String -> m a -> m a
forall (m :: * -> *) a. MonadError Error m => String -> m a -> m a
wrapError' String
"precondition"

postcondition :: MonadError Error m => m a -> m a
postcondition :: m a -> m a
postcondition = String -> m a -> m a
forall (m :: * -> *) a. MonadError Error m => String -> m a -> m a
wrapError' String
"postcondition"

-- | TODO: implement this
ensureEagerlyEvaluatable :: MonadError Error m => Program -> m ()
ensureEagerlyEvaluatable :: Program -> m ()
ensureEagerlyEvaluatable Program
_ = String -> m () -> m ()
forall (m :: * -> *) a. MonadError Error m => String -> m a -> m a
wrapError' String
"Jikka.Core.Language.Lint.ensureEagerlyEvaluatable" (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
  () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

ensureWellTyped :: MonadError Error m => Program -> m ()
ensureWellTyped :: Program -> m ()
ensureWellTyped Program
prog = String -> m () -> m ()
forall (m :: * -> *) a. MonadError Error m => String -> m a -> m a
wrapError' String
"Jikka.Core.Language.Lint.ensureWellTyped" (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
  Type
_ <- Program -> m Type
forall (m :: * -> *). MonadError Error m => Program -> m Type
typecheckProgram Program
prog
  () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()