A peer-to-peer stack for code collaboration
ghcjs: Fix build and repl (#215)
Alexander Simmerl921788353e22
diff --git a/docs/source/reference.rst b/docs/source/reference.rstindex 1e19ac6..6b4ee82 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -472,6 +472,11 @@ Documentation and testingFunctions for creating and querying documentation of variables in scope,and testing functions.+``help``+~~~~~~~~++Default help text.+``doc``~~~~~~~diff --git a/exe/Server/GHCJS.hs b/exe/GHCJS.hssimilarity index 74%rename from exe/Server/GHCJS.hsrename to exe/GHCJS.hsindex f84f8df..defde04 100644--- a/exe/Server/GHCJS.hs+++ b/exe/GHCJS.hs@@ -4,6 +4,7 @@ module GHCJS whereimport Protolude hiding (TypeError)import API+import Control.Monad.Catch (MonadThrow)import Data.IORefimport qualified Data.JSString as JSSimport Data.Scientific (floatingOrInteger)@@ -15,8 +16,9 @@ import GHCJS.Typesimport JavaScript.Object (getProp, setProp)import JavaScript.Object.Internal (Object(..))import Radicle-import Servant.API ((:<|>)(..))+import Radicle.Internal.PrimFns (allDocs)import Servant.Client.Ghcjs+import Servant.Client.Internal.XhrClient (runClientMOrigin)import System.Console.Haskeline (InputT, defaultSettings, runInputT)main :: IO ()@@ -66,35 +68,39 @@ bindings :: Bindings (PrimFns (InputT IO))bindings = e { bindingsPrimFns = bindingsPrimFns e <> primops }wheree :: Bindings (PrimFns (InputT IO))- e = pureEnv+ e = replBindingsprimops :: PrimFns (InputT IO)-primops = PrimFns (fromList [sendPrimop, receivePrimop]) <> replPrimFns+primops = fromList $ allDocs [sendPrimop, receivePrimop]wheresendPrimop =- ( unsafeToIdent "send!"+ ( "send!"+ , "Given a URL (string) and a vector of value, sends the value `v` to the\+ \ remote chain located at the URL for evaluation.", \case- [String name, v] -> do- res <- liftIO $ runClientM (submit $ List $ [String name, v])+ [String name, Vec v] -> do+ res <- liftIO $ runClientM' name (submit $ toList v)case res ofLeft e -> throwErrorHere . OtherError$ "send!: failed:" <> show e- Right () -> pure $ List []+ Right _ -> pure $ List [][_, _] -> throwErrorHere $ TypeError "send!: first argument should be a string"xs -> throwErrorHere $ WrongNumberOfArgs "send!" 2 (length xs))receivePrimop =- ( unsafeToIdent "receive!"+ ( "receive!"+ , "Given a URL (string) and a integral number `n`, queries the remote chain\+ \ for the last `n` inputs that have been evaluated.", \case[String name, Number n] -> docase floatingOrInteger n ofLeft (_ :: Float) -> throwErrorHere . OtherError$ "receive!: expecting int argument"Right r -> do- liftIO (runClientM (since name r)) >>= \case+ liftIO (runClientM' name (since r)) >>= \caseLeft err -> throwErrorHere . OtherError$ "receive!: request failed:" <> show err- Right v' -> pure $ List v'+ Right v' -> pure v'[String _, _] -> throwErrorHere $ TypeError "receive!: expecting number as second arg"[_, _] -> throwErrorHere $ TypeError "receive!: expecting string as first arg"xs -> throwErrorHere $ WrongNumberOfArgs "receive!" 2 (length xs)@@ -107,6 +113,13 @@ identV = Keyword . unsafeToIdent-- * Client functions-submit :: Value -> ClientM ()-since :: Text -> Int -> ClientM [Value]-submit :<|> since :<|> _ = client api+submit :: [Value] -> ClientM Value+submit = client chainSubmitEndpoint . Values++since :: Int -> ClientM Value+since = client chainSinceEndpoint++runClientM' :: (MonadThrow m, MonadIO m) => Text -> ClientM a -> m (Either ServantError a)+runClientM' baseUrl endpoint = do+ url <- parseBaseUrl $ T.unpack baseUrl+ liftIO $ runClientMOrigin endpoint $ ClientEnv urldiff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hsindex 8cfa9e8..5603df4 100644--- a/exe/ReferenceDoc.hs+++ b/exe/ReferenceDoc.hs@@ -91,7 +91,7 @@ main = do, "map-values", "modify-map"]structs = ["member?"]refs = ["ref", "read-ref", "write-ref", "modify-ref"]- docs = ["doc", "doc!", "apropos!", "document", "is-test-env"]+ docs = ["help", "doc", "doc!", "apropos!", "document", "is-test-env"]io =["print!", "get-line!", "load!", "read-file!", "read-code!", "send-code!", "send-prelude!", "subscribe-to!", "uuid!", "read-line!", "exit!"]@@ -111,7 +111,7 @@ main = dotyp s = "Functions for manipulating " <> s <> "."-- Functions which shouldn't be in the reference docs.- doNotInclude = ["head-shots", "get-head-shot", "eval__", "kim-trans", "pr-thread", "pr-trans"]+ doNotInclude = ["head-shots", "get-head-shot", "eval__", "kim-trans", "pr-thread", "pr-trans", "_initial-prompt-text"]allFns =basics ++ maths ++ evalFns ++ envStuff ++ seqs ++ lists ++ vecsdiff --git a/package.yaml b/package.yamlindex 44a46c5..560ccd4 100644--- a/package.yaml+++ b/package.yaml@@ -116,7 +116,7 @@ executables:radicle-client-ghcjs:main: GHCJS.hs- source-dirs: exe/Server+ source-dirs: exeother-modules: APIdependencies:- radicle@@ -132,7 +132,13 @@ executables:buildable: trueelse:buildable: false- ghc-options: -main-is GHCJS -threaded+ # XXX(xla): We need to remove the debug linking as it produces output js of+ # aroud 27MB.+ # We force debug linking as without it we encounter a runtime exception+ # in ghcjs due to the metadata initializer only supporting objects with up+ # to 100+ # fields: https://github.com/ghcjs/ghcjs/issues/498#issuecomment-230725647+ ghc-options: -main-is GHCJS -threaded -debugradicle-doc:main: Doc.hsdiff --git a/rad/prelude.rad b/rad/prelude.radindex ed5a6ba..df1501f 100644--- a/rad/prelude.rad+++ b/rad/prelude.rad@@ -54,4 +54,16 @@{:next-will-be (fn [] (+ 1 (read-ref i))):next (fn [] (modify-ref i (fn [x] (+ x 1))))}))+(def _initial-prompt-text+ "Text used for greeting in the repl."+ "Welcome to radicle. Type (help) for help.")++(def help+ "Default help text."+ (fn []+ "radicle is a LISP-like language intended for programming chains, and interacting with those chains.++ Type (doc '<name>) for further documentation of <name>."))++(load! "rad/chains/issues.rad") ;; send-prelude! must be defined alreadydiff --git a/rad/repl.rad b/rad/repl.radindex c08c266..eda4638 100644--- a/rad/repl.rad+++ b/rad/repl.rad@@ -2,15 +2,6 @@;; The Repl--(def _initial_prompt-text- "Welcome to radicle. Type (help) for help.")--(def help (fn []- "radicle is a LISP-like language intended for programming chains, and interacting with those chains.-- Type (doc '<name>) for further documentation of <name>."))-(def read-line-or-exit! (fn [](def line (get-line!))(if (eq? line nil)diff --git a/src/Radicle/Internal/Effects/Capabilities.hs b/src/Radicle/Internal/Effects/Capabilities.hsindex 238d345..ec495f1 100644--- a/src/Radicle/Internal/Effects/Capabilities.hs+++ b/src/Radicle/Internal/Effects/Capabilities.hs@@ -69,7 +69,7 @@ class (Monad m) => ReadFile m whereinstance ReadFile (InputT IO) wherereadFileS = lift . requestFilewhere- requestFile :: Text -> IO Text+ requestFile :: Text -> IO (Either Text Text)requestFile filename = doreq <- newXMLHttpRequestopenSimple req ("GET" :: Text) filenamediff --git a/stack-ghcjs.yaml b/stack-ghcjs.yamlindex 9c1686e..483d571 100644--- a/stack-ghcjs.yaml+++ b/stack-ghcjs.yaml@@ -26,3 +26,4 @@ extra-deps:- ghcjs-dom-0.9.2.0- terminfo-0.4.1.2- ghcjs-dom-jsffi-0.9.2.0+- uuid-1.3.13