Skip to content

A peer-to-peer stack for code collaboration

Create rad-base for findModule and the rad source code to live in

Fintan Halpennye44b5fa76e9e
diff --git a/package.yaml b/package.yaml
index 014480e..4482d5e 100644
--- a/package.yaml
+++ b/package.yaml
@@ -37,9 +37,6 @@ ghc-options:
- -Wincomplete-uni-patterns
- -Wredundant-constraints
-data-files:
-- rad/**/*.rad
-
library:
source-dirs: src
dependencies:
diff --git a/rad-base/README.md b/rad-base/README.md
new file mode 100644
index 0000000..41d5c02
--- /dev/null
+++ b/rad-base/README.md
@@ -0,0 +1,19 @@
+# rad-base
+
+The `rad-base` provides a home for the `radicle` prelude functionality, living under the
+`rad` directory.
+
+As well as this, there is one module `Radicle.Path` that exports `findModule`. This allows
+`radicle-repl` to look up a module based on a path, using `rad` as a default.
+
+```haskell
+-- | Importing works as follows:
+--
+-- (1) If the RADPATH environment variable exists, search there
+-- (2) Otherwise search in data-dir
+-- (3) Finally we search in the current directory.
+--
+-- RADPATH should be a colon-separated list of directories (just like PATH).
+findModule :: FilePath -> IO (Maybe FilePath)
+findModule = ...
+```
diff --git a/rad-base/Setup.hs b/rad-base/Setup.hs
new file mode 100644
index 0000000..4467109
--- /dev/null
+++ b/rad-base/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/rad-base/package.yaml b/rad-base/package.yaml
new file mode 100644
index 0000000..d86f01b
--- /dev/null
+++ b/rad-base/package.yaml
@@ -0,0 +1,22 @@
+name: rad-base
+version: 0.1.0.0
+github: "githubuser/rad-base"
+license: BSD3
+author: "Author name here"
+maintainer: "[email protected]"
+copyright: "2019 Author name here"
+
+extra-source-files:
+- README.md
+
+dependencies:
+- base >= 4.7 && < 5
+
+data-files:
+- rad/**/*.rad
+
+library:
+ source-dirs: src
+ dependencies:
+ - directory
+ - filepath
diff --git a/rad-base/rad-base.cabal b/rad-base/rad-base.cabal
new file mode 100644
index 0000000..db21a32
--- /dev/null
+++ b/rad-base/rad-base.cabal
@@ -0,0 +1,82 @@
+-- This file has been generated from package.yaml by hpack version 0.28.2.
+--
+-- see: https://github.com/sol/hpack
+--
+-- hash: 07477c660d947749e9be5cd5231d92da2e1ab8a245cbc6ece7ea63a038b1044e
+
+name: rad-base
+version: 0.1.0.0
+homepage: https://github.com/githubuser/rad-base#readme
+bug-reports: https://github.com/githubuser/rad-base/issues
+author: Author name here
+maintainer: [email protected]
+copyright: 2019 Author name here
+license: BSD3
+build-type: Simple
+cabal-version: >= 1.10
+extra-source-files:
+ README.md
+data-files:
+ rad/currency.rad
+ rad/examples/counter.rad
+ rad/monadic/issue-remote.rad
+ rad/monadic/issue.rad
+ rad/monadic/issues-upgrade.rad
+ rad/monadic/items.rad
+ rad/monadic/names-remote.rad
+ rad/monadic/names-upgrade.rad
+ rad/monadic/names.rad
+ rad/monadic/patch-remote.rad
+ rad/monadic/patch.rad
+ rad/monadic/project-remote.rad
+ rad/monadic/project.rad
+ rad/prelude.rad
+ rad/prelude/auth.rad
+ rad/prelude/basic.rad
+ rad/prelude/bool.rad
+ rad/prelude/cmd-parsing.rad
+ rad/prelude/dict.rad
+ rad/prelude/error-messages.rad
+ rad/prelude/exception.rad
+ rad/prelude/http.rad
+ rad/prelude/io-utils.rad
+ rad/prelude/io.rad
+ rad/prelude/key-management.rad
+ rad/prelude/lens.rad
+ rad/prelude/list.rad
+ rad/prelude/machine-remote.rad
+ rad/prelude/machine.rad
+ rad/prelude/maybe.rad
+ rad/prelude/nonces.rad
+ rad/prelude/patterns.rad
+ rad/prelude/ref.rad
+ rad/prelude/seq.rad
+ rad/prelude/set.rad
+ rad/prelude/state-machine.rad
+ rad/prelude/strings.rad
+ rad/prelude/test-eval.rad
+ rad/prelude/test.rad
+ rad/prelude/time.rad
+ rad/prelude/track-newness.rad
+ rad/prelude/util.rad
+ rad/prelude/validation.rad
+ rad/self-amending-store.rad
+ rad/tests/stub-primitives.rad
+
+source-repository head
+ type: git
+ location: https://github.com/githubuser/rad-base
+
+library
+ exposed-modules:
+ Lib
+ Radicle.Path
+ other-modules:
+ Paths_rad_base
+ hs-source-dirs:
+ src
+ build-depends:
+ base >=4.7 && <5
+ , directory
+ , filepath
+ default-language: Haskell2010
diff --git a/rad/currency.rad b/rad-base/rad/currency.rad
similarity index 100%
rename from rad/currency.rad
rename to rad-base/rad/currency.rad
diff --git a/rad/examples/counter.rad b/rad-base/rad/examples/counter.rad
similarity index 100%
rename from rad/examples/counter.rad
rename to rad-base/rad/examples/counter.rad
diff --git a/rad/monadic/issue-remote.rad b/rad-base/rad/monadic/issue-remote.rad
similarity index 100%
rename from rad/monadic/issue-remote.rad
rename to rad-base/rad/monadic/issue-remote.rad
diff --git a/rad/monadic/issue.rad b/rad-base/rad/monadic/issue.rad
similarity index 100%
rename from rad/monadic/issue.rad
rename to rad-base/rad/monadic/issue.rad
diff --git a/rad/monadic/issues-upgrade.rad b/rad-base/rad/monadic/issues-upgrade.rad
similarity index 100%
rename from rad/monadic/issues-upgrade.rad
rename to rad-base/rad/monadic/issues-upgrade.rad
diff --git a/rad/monadic/items.rad b/rad-base/rad/monadic/items.rad
similarity index 100%
rename from rad/monadic/items.rad
rename to rad-base/rad/monadic/items.rad
diff --git a/rad/monadic/names-remote.rad b/rad-base/rad/monadic/names-remote.rad
similarity index 100%
rename from rad/monadic/names-remote.rad
rename to rad-base/rad/monadic/names-remote.rad
diff --git a/rad/monadic/names-upgrade.rad b/rad-base/rad/monadic/names-upgrade.rad
similarity index 100%
rename from rad/monadic/names-upgrade.rad
rename to rad-base/rad/monadic/names-upgrade.rad
diff --git a/rad/monadic/names.rad b/rad-base/rad/monadic/names.rad
similarity index 100%
rename from rad/monadic/names.rad
rename to rad-base/rad/monadic/names.rad
diff --git a/rad/monadic/patch-remote.rad b/rad-base/rad/monadic/patch-remote.rad
similarity index 100%
rename from rad/monadic/patch-remote.rad
rename to rad-base/rad/monadic/patch-remote.rad
diff --git a/rad/monadic/patch.rad b/rad-base/rad/monadic/patch.rad
similarity index 100%
rename from rad/monadic/patch.rad
rename to rad-base/rad/monadic/patch.rad
diff --git a/rad/monadic/project-remote.rad b/rad-base/rad/monadic/project-remote.rad
similarity index 100%
rename from rad/monadic/project-remote.rad
rename to rad-base/rad/monadic/project-remote.rad
diff --git a/rad/monadic/project.rad b/rad-base/rad/monadic/project.rad
similarity index 100%
rename from rad/monadic/project.rad
rename to rad-base/rad/monadic/project.rad
diff --git a/rad/prelude.rad b/rad-base/rad/prelude.rad
similarity index 100%
rename from rad/prelude.rad
rename to rad-base/rad/prelude.rad
diff --git a/rad/prelude/auth.rad b/rad-base/rad/prelude/auth.rad
similarity index 100%
rename from rad/prelude/auth.rad
rename to rad-base/rad/prelude/auth.rad
diff --git a/rad/prelude/basic.rad b/rad-base/rad/prelude/basic.rad
similarity index 100%
rename from rad/prelude/basic.rad
rename to rad-base/rad/prelude/basic.rad
diff --git a/rad/prelude/bool.rad b/rad-base/rad/prelude/bool.rad
similarity index 100%
rename from rad/prelude/bool.rad
rename to rad-base/rad/prelude/bool.rad
diff --git a/rad/prelude/cmd-parsing.rad b/rad-base/rad/prelude/cmd-parsing.rad
similarity index 100%
rename from rad/prelude/cmd-parsing.rad
rename to rad-base/rad/prelude/cmd-parsing.rad
diff --git a/rad/prelude/dict.rad b/rad-base/rad/prelude/dict.rad
similarity index 100%
rename from rad/prelude/dict.rad
rename to rad-base/rad/prelude/dict.rad
diff --git a/rad/prelude/error-messages.rad b/rad-base/rad/prelude/error-messages.rad
similarity index 100%
rename from rad/prelude/error-messages.rad
rename to rad-base/rad/prelude/error-messages.rad
diff --git a/rad/prelude/exception.rad b/rad-base/rad/prelude/exception.rad
similarity index 100%
rename from rad/prelude/exception.rad
rename to rad-base/rad/prelude/exception.rad
diff --git a/rad/prelude/http.rad b/rad-base/rad/prelude/http.rad
similarity index 100%
rename from rad/prelude/http.rad
rename to rad-base/rad/prelude/http.rad
diff --git a/rad/prelude/io-utils.rad b/rad-base/rad/prelude/io-utils.rad
similarity index 100%
rename from rad/prelude/io-utils.rad
rename to rad-base/rad/prelude/io-utils.rad
diff --git a/rad/prelude/io.rad b/rad-base/rad/prelude/io.rad
similarity index 100%
rename from rad/prelude/io.rad
rename to rad-base/rad/prelude/io.rad
diff --git a/rad/prelude/key-management.rad b/rad-base/rad/prelude/key-management.rad
similarity index 100%
rename from rad/prelude/key-management.rad
rename to rad-base/rad/prelude/key-management.rad
diff --git a/rad/prelude/lens.rad b/rad-base/rad/prelude/lens.rad
similarity index 100%
rename from rad/prelude/lens.rad
rename to rad-base/rad/prelude/lens.rad
diff --git a/rad/prelude/list.rad b/rad-base/rad/prelude/list.rad
similarity index 100%
rename from rad/prelude/list.rad
rename to rad-base/rad/prelude/list.rad
diff --git a/rad/prelude/machine-remote.rad b/rad-base/rad/prelude/machine-remote.rad
similarity index 100%
rename from rad/prelude/machine-remote.rad
rename to rad-base/rad/prelude/machine-remote.rad
diff --git a/rad/prelude/machine.rad b/rad-base/rad/prelude/machine.rad
similarity index 100%
rename from rad/prelude/machine.rad
rename to rad-base/rad/prelude/machine.rad
diff --git a/rad/prelude/maybe.rad b/rad-base/rad/prelude/maybe.rad
similarity index 100%
rename from rad/prelude/maybe.rad
rename to rad-base/rad/prelude/maybe.rad
diff --git a/rad/prelude/nonces.rad b/rad-base/rad/prelude/nonces.rad
similarity index 100%
rename from rad/prelude/nonces.rad
rename to rad-base/rad/prelude/nonces.rad
diff --git a/rad/prelude/patterns.rad b/rad-base/rad/prelude/patterns.rad
similarity index 100%
rename from rad/prelude/patterns.rad
rename to rad-base/rad/prelude/patterns.rad
diff --git a/rad/prelude/ref.rad b/rad-base/rad/prelude/ref.rad
similarity index 100%
rename from rad/prelude/ref.rad
rename to rad-base/rad/prelude/ref.rad
diff --git a/rad/prelude/seq.rad b/rad-base/rad/prelude/seq.rad
similarity index 100%
rename from rad/prelude/seq.rad
rename to rad-base/rad/prelude/seq.rad
diff --git a/rad/prelude/set.rad b/rad-base/rad/prelude/set.rad
similarity index 100%
rename from rad/prelude/set.rad
rename to rad-base/rad/prelude/set.rad
diff --git a/rad/prelude/state-machine.rad b/rad-base/rad/prelude/state-machine.rad
similarity index 100%
rename from rad/prelude/state-machine.rad
rename to rad-base/rad/prelude/state-machine.rad
diff --git a/rad/prelude/strings.rad b/rad-base/rad/prelude/strings.rad
similarity index 100%
rename from rad/prelude/strings.rad
rename to rad-base/rad/prelude/strings.rad
diff --git a/rad/prelude/test-eval.rad b/rad-base/rad/prelude/test-eval.rad
similarity index 100%
rename from rad/prelude/test-eval.rad
rename to rad-base/rad/prelude/test-eval.rad
diff --git a/rad/prelude/test.rad b/rad-base/rad/prelude/test.rad
similarity index 100%
rename from rad/prelude/test.rad
rename to rad-base/rad/prelude/test.rad
diff --git a/rad/prelude/time.rad b/rad-base/rad/prelude/time.rad
similarity index 100%
rename from rad/prelude/time.rad
rename to rad-base/rad/prelude/time.rad
diff --git a/rad/prelude/track-newness.rad b/rad-base/rad/prelude/track-newness.rad
similarity index 100%
rename from rad/prelude/track-newness.rad
rename to rad-base/rad/prelude/track-newness.rad
diff --git a/rad/prelude/util.rad b/rad-base/rad/prelude/util.rad
similarity index 100%
rename from rad/prelude/util.rad
rename to rad-base/rad/prelude/util.rad
diff --git a/rad/prelude/validation.rad b/rad-base/rad/prelude/validation.rad
similarity index 100%
rename from rad/prelude/validation.rad
rename to rad-base/rad/prelude/validation.rad
diff --git a/rad/self-amending-store.rad b/rad-base/rad/self-amending-store.rad
similarity index 100%
rename from rad/self-amending-store.rad
rename to rad-base/rad/self-amending-store.rad
diff --git a/rad/tests/stub-primitives.rad b/rad-base/rad/tests/stub-primitives.rad
similarity index 100%
rename from rad/tests/stub-primitives.rad
rename to rad-base/rad/tests/stub-primitives.rad
diff --git a/rad-base/src/Radicle/Path.hs b/rad-base/src/Radicle/Path.hs
new file mode 100644
index 0000000..40d5afb
--- /dev/null
+++ b/rad-base/src/Radicle/Path.hs
@@ -0,0 +1,28 @@
+
+module Radicle.Path where
+
+import Paths_rad_base
+import System.Directory (doesFileExist, setCurrentDirectory)
+import System.Environment (lookupEnv)
+import System.FilePath (splitSearchPath, (</>))
+
+-- | Importing works as follows:
+--
+-- (1) If the RADPATH environment variable exists, search there
+-- (2) Otherwise search in data-dir
+-- (3) Finally we search in the current directory.
+--
+-- RADPATH should be a colon-separated list of directories (just like PATH).
+findModule :: FilePath -> IO (Maybe FilePath)
+findModule file = do
+ mrp <- lookupEnv "RADPATH"
+ radPathDirs <- case mrp of
+ Nothing -> (\x -> [x </> "rad"]) <$> getDataDir
+ Just rp -> pure $ splitSearchPath rp
+ let searchPath = radPathDirs ++ ["."]
+ let doFind xs = case xs of
+ [] -> pure Nothing
+ x:xs' -> do
+ exists <- doesFileExist (x </> file)
+ if exists then pure (Just $ x </> file) else doFind xs'
+ doFind searchPath
diff --git a/rad/repl.rad b/rad/repl.rad
deleted file mode 120000
index 79599b5..0000000
--- a/rad/repl.rad
+++ /dev/null
@@ -1 +0,0 @@
-../bin/rad-repl
\ No newline at end of file
diff --git a/radicle-repl/package.yaml b/radicle-repl/package.yaml
index 4394e0a..46d9359 100644
--- a/radicle-repl/package.yaml
+++ b/radicle-repl/package.yaml
@@ -17,10 +17,10 @@ library:
- bytestring
- containers
- directory
- - filepath
- haskeline
- prettyprinter
- process
+ - rad-base
- text
- time
diff --git a/radicle-repl/radicle-repl.cabal b/radicle-repl/radicle-repl.cabal
index 5ea13c2..ec0dc8b 100644
--- a/radicle-repl/radicle-repl.cabal
+++ b/radicle-repl/radicle-repl.cabal
@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
--- hash: ad1738df0a3c59b1b5001716397023051155fa87b886c2884ca614fa32010328
+-- hash: decdff89017327ce1f45f0e49763d589d554f472327b26e9cc90b8eaca880c4e
name: radicle-repl
version: 0.0.1
@@ -33,11 +33,11 @@ library
, bytestring
, containers
, directory
- , filepath
, haskeline
, prettyprinter
, process
, protolude
+ , rad-base
, radicle-lang
, text
, time
diff --git a/radicle-repl/src/Radicle/Repl/Capabilities.hs b/radicle-repl/src/Radicle/Repl/Capabilities.hs
index b5e7713..577fdb6 100644
--- a/radicle-repl/src/Radicle/Repl/Capabilities.hs
+++ b/radicle-repl/src/Radicle/Repl/Capabilities.hs
@@ -9,13 +9,10 @@ import Protolude
import qualified Data.ByteString as BS
import Data.Text.Prettyprint.Doc (PageWidth)
import Data.Time
-import Paths_radicle_repl
import System.Console.ANSI (hSupportsANSI)
import System.Console.Haskeline hiding (catch)
-import System.Directory (doesFileExist, setCurrentDirectory)
-import System.Environment (lookupEnv)
+import System.Directory (setCurrentDirectory)
import System.Exit (ExitCode)
-import System.FilePath (splitSearchPath, (</>))
import System.IO
( BufferMode(LineBuffering)
, hClose
@@ -29,6 +26,7 @@ import System.Process
(CreateProcess, ProcessHandle, createProcess, waitForProcess)
import Radicle.Lang.Core
+import Radicle.Path
class (Monad m) => Stdin m where
getLineS :: m (Maybe Text) -- gives Nothing on EOF
@@ -163,24 +161,3 @@ putStrLnS t = putStrS t >> putStrS "\n"
modifyEnvS :: (GetEnv m r, SetEnv m r) => (Env r -> Env r) -> m ()
modifyEnvS f = getEnvS >>= setEnvS . f
-
--- | Importing works as follows:
---
--- (1) If the RADPATH environment variable exists, search there
--- (2) Otherwise search in data-dir
--- (3) Finally we search in the current directory.
---
--- RADPATH should be a colon-separated list of directories (just like PATH).
-findModule :: FilePath -> IO (Maybe FilePath)
-findModule file = do
- mrp <- lookupEnv "RADPATH"
- radPathDirs <- case mrp of
- Nothing -> (\x -> [x </> "rad"]) <$> getDataDir
- Just rp -> pure $ splitSearchPath rp
- let searchPath = radPathDirs ++ ["."]
- let doFind xs = case xs of
- [] -> pure Nothing
- x:xs' -> do
- exists <- doesFileExist (x </> file)
- if exists then pure (Just $ x </> file) else doFind xs'
- doFind searchPath
diff --git a/stack.yaml b/stack.yaml
index ed18a24..6f41eea 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -37,6 +37,7 @@ resolver: snapshot.yaml
# will not be run. This is useful for tweaking upstream packages.
packages:
- .
+- rad-base
- radicle-lang
- radicle-repl