Skip to content

Commit

Permalink
fixup: rename evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
doyougnu committed Jan 14, 2024
1 parent 9d9a4a0 commit f26de76
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion klister.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ library
Core.Builder
Datatype
Env
CEKEvaluator
Evaluator
Expander
Expander.DeclScope
Expander.Error
Expand Down
2 changes: 1 addition & 1 deletion repl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import System.Exit (exitFailure, exitSuccess)
import System.IO
import System.Directory

import CEKEvaluator
import Evaluator
import Expander
import ModuleName
import Parser
Expand Down
35 changes: 17 additions & 18 deletions src/CEKEvaluator.hs → src/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The bird's eye view:
-}

module CEKEvaluator
module Evaluator
( EvalError (..)
, EvalResult (..)
, TypeError (..)
Expand Down Expand Up @@ -58,23 +58,6 @@ import Syntax.SrcLoc
import Type
import Value

-- -----------------------------------------------------------------------------
-- Top level API

evaluate :: Core -> Value
evaluate = evaluateIn mempty

evaluateIn :: VEnv -> Core -> Value
evaluateIn e = yield . until final step . start e . unCore
where
yield (Up v _ Halt) = v
yield _ = error "evaluate: completed impossibly"

evaluateWithExtendedEnv :: VEnv -> [(Ident, Var, Value)] -> Core -> Value
evaluateWithExtendedEnv env exts = evaluateIn (inserter exts)
where
inserter = foldl' (\acc (n,x,v) -> Env.insert x n v acc) env

-- -----------------------------------------------------------------------------
-- Interpreter Data Types

Expand Down Expand Up @@ -448,6 +431,9 @@ final _ = False
start :: VEnv -> CoreF TypePattern ConstructorPattern Core -> EState
start e c = Down c e Halt

yield :: EState -> Value
yield (Up v _ Halt) = v
yield _ = error "evaluate: completed impossibly"

extend :: Ident -> Var -> Value -> VEnv -> VEnv
extend i var = Env.insert var i
Expand Down Expand Up @@ -552,3 +538,16 @@ doDataCase loc v0 ((pat, rhs) : ps) env kont =
match fk sk ((PatternVar n x, tgt) : more) =
match fk (sk . extend n x tgt) more

-- -----------------------------------------------------------------------------
-- Top level API

evaluate :: Core -> Value
evaluate = evaluateIn mempty

evaluateIn :: VEnv -> Core -> Value
evaluateIn e = yield . until final step . start e . unCore

evaluateWithExtendedEnv :: VEnv -> [(Ident, Var, Value)] -> Core -> Value
evaluateWithExtendedEnv env exts = evaluateIn (inserter exts)
where
inserter = foldl' (\acc (n,x,v) -> Env.insert x n v acc) env
2 changes: 1 addition & 1 deletion src/Expander.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import Binding
import Core
import Datatype
import qualified Env
import CEKEvaluator
import Evaluator
import qualified Expander.Primitives as Prims
import Expander.DeclScope
import Expander.Syntax
Expand Down
2 changes: 1 addition & 1 deletion src/Expander/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Data.Foldable

import Core
import Datatype
import CEKEvaluator
import Evaluator
import Expander.Task
import Kind
import KlisterPath
Expand Down
2 changes: 1 addition & 1 deletion src/Expander/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ import Control.Lens.IORef
import Core
import Datatype
import Env
import CEKEvaluator
import Evaluator
import Expander.DeclScope
import Expander.Error
import Expander.Task
Expand Down
2 changes: 1 addition & 1 deletion src/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Binding.Info
import Core
import Datatype
import Env
import CEKEvaluator (EvalResult(..), EvalError(..), TypeError(..))
import Evaluator (EvalResult(..), EvalError(..), TypeError(..))
import Kind
import Module
import ModuleName
Expand Down
2 changes: 1 addition & 1 deletion src/World.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Maybe (fromMaybe)
import Core (MacroVar, Var)
import Datatype
import Env
import CEKEvaluator (EvalResult)
import Evaluator (EvalResult)
import Module
import ModuleName
import Phase
Expand Down
2 changes: 1 addition & 1 deletion tests/Golden.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import System.IO (Handle, openFile, hClose, IOMode(WriteMode))
import System.IO.Silently (hCapture_)
import System.Directory

import CEKEvaluator
import Evaluator
import Expander
import Expander.Monad
import ModuleName
Expand Down
2 changes: 1 addition & 1 deletion tests/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import qualified Hedgehog.Internal.Property as Prop (forAllT)
import Alpha
import Core
import Core.Builder
import CEKEvaluator (EvalResult(..))
import Evaluator (EvalResult(..))
import Expander
import Expander.Monad
import Module
Expand Down

0 comments on commit f26de76

Please sign in to comment.