aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/Plugin.purs
blob: c9f01333e2683b271a9a19dae3a8ef2079dbf011 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module PursLoader.Plugin
  ( Result()
  , Compile()
  , Context()
  , ImmutableMap()
  , DependencyGraph()
  , get
  , dependenciesOf
  ) where

import Prelude (Unit())

import Control.Monad.Eff (Eff())
import Control.Monad.Eff.Exception (Error())

import Data.Either (Either(..))
import Data.Function (Fn4(), runFn4)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable())

type Result = { srcMap :: ImmutableMap String String, ffiMap :: ImmutableMap String String, graph :: DependencyGraph, output :: String }

type Compile eff = Nullable Error -> Result -> Eff eff Unit

type Context eff = { compile :: Compile eff -> Eff eff Unit }

get :: forall key value. ImmutableMap key value -> key -> Maybe value
get = runFn4 getFn Nothing Just

dependenciesOf :: DependencyGraph -> String -> Either Error (Array String)
dependenciesOf = runFn4 dependenciesOfFn Left Right

foreign import data ImmutableMap :: * -> * -> *

foreign import data DependencyGraph :: *

foreign import getFn
  :: forall key value. Fn4 (Maybe value)
                           (value -> Maybe value)
                           (ImmutableMap key value)
                           key
                           (Maybe value)

foreign import dependenciesOfFn
  :: Fn4 (Error -> Either Error (Array String))
         (Array String -> Either Error (Array String))
         DependencyGraph
         String
         (Either Error (Array String))