git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
fix https://github.com/purescript/purescrit/issues/531 and https://github.com/purescript/purescript/issues/530
376fdebBenjamin Kovach]
psci/Main.hs+17−16
@@ -66,7 +66,7 @@ data PSCiState = PSCiState
66 { psciImportedFilenames :: [FilePath]
66 { psciImportedFilenames :: [FilePath]
67 , psciImportedModuleNames :: [P.ModuleName]
67 , psciImportedModuleNames :: [P.ModuleName]
68 , psciLoadedModules :: [(FilePath, P.Module)]
68 , psciLoadedModules :: [(FilePath, P.Module)]
69− , psciLetBindings :: [P.Expr -> P.Expr]
69+ , psciLetBindings :: [P.Value -> P.Value]
70 }
70 }
71
71
72-- State helpers
72-- State helpers
@@ -92,7 +92,7 @@ updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modu
92-- |
92-- |
93-- Updates the state to have more let bindings.
93-- Updates the state to have more let bindings.
94--
94--
95−updateLets :: (P.Expr -> P.Expr) -> PSCiState -> PSCiState
95+updateLets :: (P.Value -> P.Value) -> PSCiState -> PSCiState
96updateLets name st = st { psciLetBindings = name : psciLetBindings st }
96updateLets name st = st { psciLetBindings = name : psciLetBindings st }
97
97
98-- File helpers
98-- File helpers
@@ -242,11 +242,11 @@ mkdirp = createDirectoryIfMissing True . takeDirectory
242-- |
242-- |
243-- Makes a volatile module to execute the current expression.
243-- Makes a volatile module to execute the current expression.
244--
244--
245−createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
245+createTemporaryModule :: Bool -> PSCiState -> P.Value -> P.Module
246createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} value =
246createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} value =
247 let
247 let
248− moduleName = P.ModuleName [P.ProperName "Main"]
248+ moduleName = P.ModuleName [P.ProperName "$PSCI"]
249− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
249+ importDecl m = P.ImportDeclaration m Nothing Nothing
250 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
250 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
251 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
251 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
252 itValue = foldl (\x f -> f x) value lets
252 itValue = foldl (\x f -> f x) value lets
@@ -263,8 +263,8 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
263createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
263createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
264createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
264createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
265 let
265 let
266− moduleName = P.ModuleName [P.ProperName "Main"]
266+ moduleName = P.ModuleName [P.ProperName "$PSCI"]
267− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
267+ importDecl m = P.ImportDeclaration m Nothing Nothing
268 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
268 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
269 in
269 in
270 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
270 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
@@ -278,15 +278,15 @@ indexFile = ".psci_modules" ++ pathSeparator : "index.js"
278-- |
278-- |
279-- Takes a value declaration and evaluates it with the current state.
279-- Takes a value declaration and evaluates it with the current state.
280--
280--
281−handleDeclaration :: P.Expr -> PSCI ()
281+handleDeclaration :: P.Value -> PSCI ()
282handleDeclaration value = do
282handleDeclaration value = do
283 st <- PSCI $ lift get
283 st <- PSCI $ lift get
284 let m = createTemporaryModule True st value
284 let m = createTemporaryModule True st value
285− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
285+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
286 case e of
286 case e of
287 Left err -> PSCI $ outputStrLn err
287 Left err -> PSCI $ outputStrLn err
288 Right _ -> do
288 Right _ -> do
289− psciIO $ writeFile indexFile $ "require('Main').main();"
289+ psciIO $ writeFile indexFile $ "require('$PSCI').main();"
290 process <- psciIO findNodeProcess
290 process <- psciIO findNodeProcess
291 result <- psciIO $ traverse (\node -> readProcessWithExitCode node [indexFile] "") process
291 result <- psciIO $ traverse (\node -> readProcessWithExitCode node [indexFile] "") process
292 case result of
292 case result of
@@ -297,15 +297,15 @@ handleDeclaration value = do
297-- |
297-- |
298-- Takes a value and prints its type
298-- Takes a value and prints its type
299--
299--
300−handleTypeOf :: P.Expr -> PSCI ()
300+handleTypeOf :: P.Value -> PSCI ()
301handleTypeOf value = do
301handleTypeOf value = do
302 st <- PSCI $ lift get
302 st <- PSCI $ lift get
303 let m = createTemporaryModule False st value
303 let m = createTemporaryModule False st value
304− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
304+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
305 case e of
305 case e of
306 Left err -> PSCI $ outputStrLn err
306 Left err -> PSCI $ outputStrLn err
307 Right env' ->
307 Right env' ->
308− case M.lookup (P.ModuleName [P.ProperName "Main"], P.Ident "it") (P.names env') of
308+ case M.lookup (P.ModuleName [P.ProperName "$PSCI"], P.Ident "it") (P.names env') of
309 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
309 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
310 Nothing -> PSCI $ outputStrLn "Could not find type"
310 Nothing -> PSCI $ outputStrLn "Could not find type"
311
311
@@ -316,8 +316,8 @@ handleKindOf :: P.Type -> PSCI ()
316handleKindOf typ = do
316handleKindOf typ = do
317 st <- PSCI $ lift get
317 st <- PSCI $ lift get
318 let m = createTemporaryModuleForKind st typ
318 let m = createTemporaryModuleForKind st typ
319− mName = P.ModuleName [P.ProperName "Main"]
319+ mName = P.ModuleName [P.ProperName "$PSCI"]
320− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
320+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)])
321 case e of
321 case e of
322 Left err -> PSCI $ outputStrLn err
322 Left err -> PSCI $ outputStrLn err
323 Right env' ->
323 Right env' ->
@@ -325,7 +325,7 @@ handleKindOf typ = do
325 Just (_, typ') -> do
325 Just (_, typ') -> do
326 let chk = P.CheckState env' 0 0 (Just mName)
326 let chk = P.CheckState env' 0 0 (Just mName)
327 k = L.runStateT (P.unCheck (P.kindOf mName typ')) chk
327 k = L.runStateT (P.unCheck (P.kindOf mName typ')) chk
328− case k of
328+ case k of
329 Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
329 Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
330 Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
330 Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
331 Nothing -> PSCI $ outputStrLn "Could not find kind"
331 Nothing -> PSCI $ outputStrLn "Could not find kind"
@@ -340,6 +340,7 @@ getCommand = do
340 firstLine <- getInputLine "> "
340 firstLine <- getInputLine "> "
341 case firstLine of
341 case firstLine of
342 Nothing -> return (Right Nothing)
342 Nothing -> return (Right Nothing)
343+ Just "" -> return (Right Nothing)
343 Just s@ (':' : _) -> return . either Left (Right . Just) $ parseCommand s -- The start of a command
344 Just s@ (':' : _) -> return . either Left (Right . Just) $ parseCommand s -- The start of a command
344 Just s -> either Left (Right . Just) . parseCommand <$> go [s]
345 Just s -> either Left (Right . Just) . parseCommand <$> go [s]
345 where
346 where