Skip to content
Permalink
Browse files

Merge PR #163: Restructure directories / sub-packages for clarity

  • Loading branch information...
cwgoes committed Nov 8, 2019
1 parent 1dd7c5f commit 4a0358f9af6febdec8eed081dd4f9a80b2707c86
Showing with 410 additions and 427 deletions.
  1. +11 −11 app/Interactive.hs
  2. +24 −23 package.yaml
  3. +1 −0 src/Juvix/Backends.hs
  4. +1 −0 src/Juvix/Backends/LLVM.hs
  5. +4 −4 src/Juvix/{ → Backends}/LLVM/Codegen/Block.hs
  6. +1 −1 src/Juvix/{ → Backends}/LLVM/Codegen/Constants.hs
  7. +4 −4 src/Juvix/{ → Backends}/LLVM/Codegen/Graph.hs
  8. +2 −2 src/Juvix/{ → Backends}/LLVM/Codegen/Shared.hs
  9. +4 −4 src/Juvix/{ → Backends}/LLVM/Codegen/Sum.hs
  10. +7 −7 src/Juvix/{ → Backends}/LLVM/Codegen/Types.hs
  11. +0 −23 src/Juvix/Bohm.hs
  12. +1 −2 src/Juvix/Core/EAC/ConstraintGen.hs
  13. +3 −3 src/Juvix/Core/EAC/Parser.hs
  14. +6 −6 src/Juvix/Core/EAC/Types.hs
  15. +4 −4 src/Juvix/Core/Erased/Evaluator.hs
  16. +2 −2 src/Juvix/Core/Erased/Types.hs
  17. +3 −3 src/Juvix/Core/Erasure/Algorithm.hs
  18. +0 −1 src/Juvix/Core/Erasure/Types.hs
  19. +1 −1 src/Juvix/Encoding/Encoding.hs
  20. +1 −1 src/Juvix/Encoding/Mendler.hs
  21. +1 −1 src/Juvix/Encoding/Scott.hs
  22. +1 −1 src/Juvix/Encoding/Types.hs
  23. +1 −0 src/Juvix/Interpreter.hs
  24. +23 −0 src/Juvix/Interpreter/InteractionNet.hs
  25. +2 −2 src/Juvix/{ → Interpreter/InteractionNet}/Backends/Env.hs
  26. +4 −5 src/Juvix/{ → Interpreter/InteractionNet}/Backends/Graph.hs
  27. +2 −2 src/Juvix/{ → Interpreter/InteractionNet}/Backends/Interface.hs
  28. +4 −4 src/Juvix/{ → Interpreter/InteractionNet}/Backends/Maps.hs
  29. +20 −20 src/Juvix/{Bohm → Interpreter/InteractionNet}/Default.hs
  30. +5 −6 src/Juvix/{ → Interpreter/InteractionNet}/Nets/Combinators.hs
  31. +6 −7 src/Juvix/{Nets/Bohm.hs → Interpreter/InteractionNet/Nets/Default.hs}
  32. +1 −1 src/Juvix/{ → Interpreter/InteractionNet}/NodeInterface.hs
  33. +34 −35 src/Juvix/{Bohm → Interpreter/InteractionNet}/Parser.hs
  34. +1 −1 src/Juvix/{Bohm → Interpreter/InteractionNet}/Shared.hs
  35. +103 −103 src/Juvix/{Bohm → Interpreter/InteractionNet}/Translation.hs
  36. +18 −18 src/Juvix/{Bohm → Interpreter/InteractionNet}/Type.hs
  37. +29 −0 src/Juvix/Library.hs
  38. +2 −2 src/Juvix/{Utility → Library}/HashMap.hs
  39. +2 −2 src/Juvix/{Utility → Library}/PrettyPrint.hs
  40. +0 −10 src/Juvix/Utility.hs
  41. +0 −25 src/Juvix/Utility/Helper.hs
  42. +4 −5 src/Juvix/Visualize/Dot.hs
  43. +0 −1 test/EAC.hs
  44. +1 −1 test/EAC2.hs
  45. +2 −7 test/Erasure.hs
  46. +41 −42 test/{Bohm.hs → INet.hs}
  47. +0 −19 test/Nets/Bohm.hs
  48. +4 −5 test/Nets/Combinators.hs
  49. +19 −0 test/Nets/Default.hs
@@ -3,17 +3,17 @@ module Interactive where
import Config
import Control.Monad.IO.Class
import qualified Data.Text as T
import qualified Juvix.Backends.Env as Env
import qualified Juvix.Backends.Graph as Graph
import qualified Juvix.Backends.Maps as Maps ()
import qualified Juvix.Bohm as Bohm
import qualified Juvix.Core as Core
import qualified Juvix.Core.Erased as Erased
import qualified Juvix.Core.HR as HR
import qualified Juvix.Core.HR as Core
import Juvix.Core.Parameterisations.Naturals
import qualified Juvix.Interpreter.InteractionNet as INet
import qualified Juvix.Interpreter.InteractionNet.Backends.Env as Env
import qualified Juvix.Interpreter.InteractionNet.Backends.Graph as Graph
import qualified Juvix.Interpreter.InteractionNet.Backends.Maps as Maps ()
import qualified Juvix.Interpreter.InteractionNet.Nets.Default as INet
import Juvix.Library
import qualified Juvix.Nets.Bohm as Bohm
import Monad
import Options
import qualified System.Console.Haskeline as H
@@ -86,16 +86,16 @@ handleSpecial str cont = do

transformAndEvaluateErasedCore primVal. Bool Erased.Term primVal H.InputT IO ()
transformAndEvaluateErasedCore debug term = do
let bohm = Bohm.erasedCoreToBohm term
when debug $ H.outputStrLn ("Converted to BOHM: " <> show bohm)
let net Graph.FlipNet Bohm.Lang
net = Bohm.astToNet bohm Bohm.defaultEnv
let ast = INet.erasedCoreToInteractionNetAST term
when debug $ H.outputStrLn ("Converted to AST: " <> show ast)
let net Graph.FlipNet INet.Lang
net = INet.astToNet ast INet.defaultEnv
when debug $ H.outputStrLn ("Translated to net: " <> show net)
let reduced = Graph.runFlipNet (Bohm.reduceAll 1000000) net
let reduced = Graph.runFlipNet (INet.reduceAll 1000000) net
info = Env.info reduced
res = Env.net reduced
when debug $ H.outputStrLn ("Reduced net: " <> show res)
let readback = Bohm.netToAst res
let readback = INet.netToAst res
when debug $ H.outputStrLn ("Reduction info: " <> show info)
H.outputStrLn ("Read-back term: " <> show readback)

@@ -93,37 +93,38 @@ library:
- Juvix.Core.EAC.Parser
- Juvix.Core.EAC.Erasure
- Juvix.Core.Parameterisations.Unit
- Juvix.Utility
- Juvix.Utility.HashMap
- Juvix.Nets.Bohm
- Juvix.Nets.Combinators
- Juvix.Backends.Interface
- Juvix.Backends.Env
- Juvix.Backends.Graph
- Juvix.Backends.Maps
- Juvix.Bohm.Parser
- Juvix.Bohm.Translation
- Juvix.Bohm.Type
- Juvix.Bohm.Shared
- Juvix.Bohm.Default
- Juvix.Bohm
- Juvix.Interpreter
- Juvix.Interpreter.InteractionNet
- Juvix.Interpreter.InteractionNet.Nets.Default
- Juvix.Interpreter.InteractionNet.Nets.Combinators
- Juvix.Interpreter.InteractionNet.Backends.Interface
- Juvix.Interpreter.InteractionNet.Backends.Env
- Juvix.Interpreter.InteractionNet.Backends.Graph
- Juvix.Interpreter.InteractionNet.Backends.Maps
- Juvix.Interpreter.InteractionNet.Parser
- Juvix.Interpreter.InteractionNet.Translation
- Juvix.Interpreter.InteractionNet.Type
- Juvix.Interpreter.InteractionNet.Shared
- Juvix.Interpreter.InteractionNet.Default
- Juvix.Library
- Juvix.Library.HashMap
- Juvix.Library.PrettyPrint
- Juvix.Visualize.Dot
- Juvix.Visualize.Graph
- Juvix.Encoding.Encoding
- Juvix.Encoding.Mendler
- Juvix.Encoding.Scott
- Juvix.Encoding.Types
- Juvix.LLVM.Codegen.Constants
- Juvix.LLVM.Codegen.Sum
- Juvix.LLVM.Codegen.Types
- Juvix.LLVM.Codegen.Shared
- Juvix.LLVM.Codegen.Block
- Juvix.LLVM.Codegen.Graph
- Juvix.Backends
- Juvix.Backends.LLVM
- Juvix.Backends.LLVM.Codegen.Constants
- Juvix.Backends.LLVM.Codegen.Sum
- Juvix.Backends.LLVM.Codegen.Types
- Juvix.Backends.LLVM.Codegen.Shared
- Juvix.Backends.LLVM.Codegen.Block
- Juvix.Backends.LLVM.Codegen.Graph
other-modules:
- Juvix.NodeInterface
- Juvix.Utility.Helper
- Juvix.Utility.PrettyPrint
- Juvix.Interpreter.InteractionNet.NodeInterface
- Juvix.Core.Translate
- Juvix.Core.Pipeline
- Juvix.Core.Utility
@@ -0,0 +1 @@
module Juvix.Backends where
@@ -0,0 +1 @@
module Juvix.Backends.LLVM where
@@ -1,12 +1,12 @@
{-# LANGUAGE NamedFieldPuns #-}

module Juvix.LLVM.Codegen.Block where
module Juvix.Backends.LLVM.Codegen.Block where

import Data.ByteString.Short
import Juvix.LLVM.Codegen.Shared
import Juvix.LLVM.Codegen.Types as Types
import Juvix.Backends.LLVM.Codegen.Shared
import Juvix.Backends.LLVM.Codegen.Types as Types
import Juvix.Library hiding (Type, local)
import Juvix.Utility.HashMap as Map
import Juvix.Library.HashMap as Map
import LLVM.AST
import qualified LLVM.AST as AST
import LLVM.AST.AddrSpace
@@ -1,5 +1,5 @@
-- | Module for predefined constants
module Juvix.LLVM.Codegen.Constants where
module Juvix.Backends.LLVM.Codegen.Constants where

import Juvix.Library hiding (Type)
import qualified LLVM.AST.Type as Type
@@ -1,10 +1,10 @@
-- | Operations necessary to update nodes
module Juvix.LLVM.Codegen.Graph where
module Juvix.Backends.LLVM.Codegen.Graph where

import Juvix.LLVM.Codegen.Block as Block
import Juvix.LLVM.Codegen.Types as Types
import Juvix.Backends.LLVM.Codegen.Block as Block
import Juvix.Backends.LLVM.Codegen.Types as Types
import Juvix.Library hiding (Type, local)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import qualified LLVM.AST as AST
import qualified LLVM.AST.Constant as C
import qualified LLVM.AST.Name as Name
@@ -1,8 +1,8 @@
-- | Shared between Types and Sum
module Juvix.LLVM.Codegen.Shared where
module Juvix.Backends.LLVM.Codegen.Shared where

import Juvix.Library hiding (Type)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import LLVM.AST
import qualified LLVM.AST as AST ()
import qualified LLVM.AST.Constant as C ()
@@ -1,10 +1,10 @@
-- | Provides a mechanism for defining Sum types
module Juvix.LLVM.Codegen.Sum where
module Juvix.Backends.LLVM.Codegen.Sum where

import qualified Juvix.LLVM.Codegen.Constants as Constants
import Juvix.LLVM.Codegen.Shared
import qualified Juvix.Backends.LLVM.Codegen.Constants as Constants
import Juvix.Backends.LLVM.Codegen.Shared
import Juvix.Library hiding (Type)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import LLVM.AST
import qualified LLVM.AST.Type as Type
import LLVM.AST.Type
@@ -1,15 +1,15 @@
module Juvix.LLVM.Codegen.Types
( module Juvix.LLVM.Codegen.Types,
module Juvix.LLVM.Codegen.Shared,
module Juvix.Backends.LLVM.Codegen.Types
( module Juvix.Backends.LLVM.Codegen.Types,
module Juvix.Backends.LLVM.Codegen.Shared,
)
where

import Data.ByteString.Short
import qualified Juvix.LLVM.Codegen.Constants as Constants
import Juvix.LLVM.Codegen.Shared
import Juvix.LLVM.Codegen.Sum
import qualified Juvix.Backends.LLVM.Codegen.Constants as Constants
import Juvix.Backends.LLVM.Codegen.Shared
import Juvix.Backends.LLVM.Codegen.Sum
import Juvix.Library hiding (Type)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import LLVM.AST as AST
import LLVM.AST.AddrSpace
import LLVM.AST.DataLayout (DataLayout (..))

This file was deleted.

@@ -1,11 +1,10 @@
module Juvix.Core.EAC.ConstraintGen where

import Control.Arrow (left)
import qualified Juvix.Bohm.Type as BT
import Juvix.Core.EAC.Types
import Juvix.Core.Erased.Types
import Juvix.Library hiding (Type, link, reduce)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import Prelude (error)

-- TODO include actual results for RPRIM
@@ -3,7 +3,7 @@
module Juvix.Core.EAC.Parser
( parseEal,
parseEal',
parseBohmFile,
parseEalFile,
types,
)
where
@@ -109,8 +109,8 @@ parseEal = parseEal' ""
parseEal' SourceName String Either ParseError RPTO
parseEal' = runParser (whiteSpace *> expression <* eof) ()

parseBohmFile FilePath IO (Either ParseError RPTO)
parseBohmFile fname = do
parseEalFile FilePath IO (Either ParseError RPTO)
parseEalFile fname = do
input readFile fname
pure $ parseEal' fname (show input)

@@ -3,7 +3,7 @@ module Juvix.Core.EAC.Types where
import qualified Data.Text as T
import Juvix.Core.Erased.Types
import Juvix.Library hiding (Type)
import Juvix.Utility
import qualified Juvix.Library.HashMap as Map

-- Restricted pseudoterm (inner).
data RPTI primVal
@@ -35,7 +35,7 @@ data PType primTy
deriving (Show, Eq)

-- Parameterized type assignment (alias).
type ParamTypeAssignment primTy = HashMap Symbol (PType primTy)
type ParamTypeAssignment primTy = Map.Map Symbol (PType primTy)

-- Linear (in)equality constraint on parameters.
data Constraint
@@ -63,10 +63,10 @@ data Op
type Path = [Param]

-- Variable paths.
type VarPaths = HashMap Symbol Param
type VarPaths = Map.Map Symbol Param

-- Occurrence map.
type OccurrenceMap = HashMap Symbol Int
type OccurrenceMap = Map.Map Symbol Int

-- | Bracket Error Types
data BracketErrors
@@ -106,13 +106,13 @@ data Errors primTy primVal
newtype EnvError primTy primVal a = EnvError (ExceptT (TypeErrors primTy primVal) (State (Info primTy)) a)
deriving (Functor, Applicative, Monad)
deriving
(HasState "ctxt" (HashMap Symbol (Type primTy)))
(HasState "ctxt" (Map.Map Symbol (Type primTy)))
via Field "ctxt" () (MonadState (ExceptT (TypeErrors primTy primVal) (State (Info primTy))))
deriving
(HasThrow "typ" (TypeErrors primTy primVal))
via MonadError (ExceptT (TypeErrors primTy primVal) (State (Info primTy)))

data Info primTy = I {ctxt HashMap Symbol (Type primTy)} deriving (Show, Generic)
data Info primTy = I {ctxt Map.Map Symbol (Type primTy)} deriving (Show, Generic)

-- Environment for inference.
data Env primTy
@@ -5,20 +5,20 @@ where

import Juvix.Core.Erased.Types
import Juvix.Library hiding (Map, evaluate)
import Juvix.Utility
import qualified Juvix.Library.HashMap as Map

evaluate
primVal m.
( HasReader "apply" (primVal primVal Maybe primVal) m,
HasState "env" (Map Symbol (Term primVal)) m
HasState "env" (Map.Map Symbol (Term primVal)) m
)
Term primVal
m (Term primVal)
evaluate term =
case term of
Var s do
env get @"env"
case lookup s env of
case Map.lookup s env of
Just v pure v
Nothing pure (Var s)
Prim p pure (Prim p)
@@ -33,6 +33,6 @@ evaluate term =
Just r pure (Prim r)
Nothing undefined
(Lam s t, v) do
modify @"env" (insert s v)
modify @"env" (Map.insert s v)
evaluate t
_ pure (App f x)
@@ -1,7 +1,7 @@
module Juvix.Core.Erased.Types where

import Juvix.Library hiding (Type)
import Juvix.Utility
import qualified Juvix.Library.HashMap as Map

data Term primVal
= Var Symbol
@@ -18,4 +18,4 @@ data Type primTy
Pi (Type primTy) (Type primTy)
deriving (Show, Eq, Generic)

type TypeAssignment primTy = HashMap Symbol (Type primTy)
type TypeAssignment primTy = Map.Map Symbol (Type primTy)
@@ -9,7 +9,7 @@ import qualified Juvix.Core.HR.Types as Core
import qualified Juvix.Core.Types as Core
import qualified Juvix.Core.Usage as Core
import Juvix.Library hiding (empty)
import Juvix.Utility
import qualified Juvix.Library.HashMap as Map

erase Core.Parameterisation primTy primVal Core.Term primTy primVal Core.Usage Core.Term primTy primVal Either ErasureError (Erased.Term primVal, Erased.TypeAssignment primTy)
erase parameterisation term usage ty =
@@ -18,7 +18,7 @@ erase parameterisation term usage ty =
(erased, typeAssignment env)

exec EnvErasure primTy a (Either ErasureError a, Env primTy)
exec (EnvEra env) = runState (runExceptT env) (Env empty 0 [])
exec (EnvEra env) = runState (runExceptT env) (Env Map.empty 0 [])

eraseTerm
primTy primVal m.
@@ -43,7 +43,7 @@ eraseTerm parameterisation term usage ty =
let Core.Pi argUsage varTy retTy = ty
bodyUsage = Core.SNat 1
ty eraseType parameterisation varTy
modify @"typeAssignment" (insert name ty)
modify @"typeAssignment" (Map.insert name ty)
-- TODO resTy is a function, which we must deal with.
body eraseTerm parameterisation body bodyUsage retTy
-- If argument is not used, just return the erased body.
@@ -2,7 +2,6 @@ module Juvix.Core.Erasure.Types where

import qualified Juvix.Core.Erased as Erased
import Juvix.Library hiding (empty)
import Juvix.Utility

data Env primTy
= Env
@@ -4,7 +4,7 @@ module Juvix.Encoding.Encoding where

import Juvix.Encoding.Types
import Juvix.Library hiding (Product, Sum)
import qualified Juvix.Utility.HashMap as Map
import qualified Juvix.Library.HashMap as Map
import Prelude (error)

-- Generic Case expansion ------------------------------------------------------

0 comments on commit 4a0358f

Please sign in to comment.
You can’t perform that action at this time.