git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better let bindings in psci, fix #782
d64e060Phil Freeman
psci/Commands.hs+1−1
@@ -52,7 +52,7 @@ data Command
52 -- |
52 -- |
53 -- Binds a value to a name
53 -- Binds a value to a name
54 --
54 --
55− | Let (Expr -> Expr)
55+ | Let [Declaration]
56 -- |
56 -- |
57 -- Find the type of an expression
57 -- Find the type of an expression
58 --
58 --
psci/Main.hs+9−9
@@ -69,7 +69,7 @@ data PSCiState = PSCiState
69 { psciImportedFilenames :: [FilePath]
69 { psciImportedFilenames :: [FilePath]
70 , psciImportedModuleNames :: [P.ModuleName]
70 , psciImportedModuleNames :: [P.ModuleName]
71 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
71 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
72− , psciLetBindings :: [P.Expr -> P.Expr]
72+ , psciLetBindings :: [P.Declaration]
73 }
73 }
74
74
75-- State helpers
75-- State helpers
@@ -95,8 +95,8 @@ updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modu
95-- |
95-- |
96-- Updates the state to have more let bindings.
96-- Updates the state to have more let bindings.
97--
97--
98−updateLets :: (P.Expr -> P.Expr) -> PSCiState -> PSCiState
98+updateLets :: [P.Declaration] -> PSCiState -> PSCiState
99−updateLets name st = st { psciLetBindings = name : psciLetBindings st }
99+updateLets ds st = st { psciLetBindings = ds ++ psciLetBindings st }
100
100
101-- File helpers
101-- File helpers
102-- |
102-- |
@@ -348,13 +348,13 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
348 importDecl m = P.ImportDeclaration m P.Unqualified Nothing
348 importDecl m = P.ImportDeclaration m P.Unqualified Nothing
349 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
349 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
350 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
350 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
351− itValue = foldl (\x f -> f x) val lets
352 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
351 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
353− itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right itValue
352+ itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right val
354 mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] $ Right mainValue
353 mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] $ Right mainValue
355 decls = if exec then [itDecl, mainDecl] else [itDecl]
354 decls = if exec then [itDecl, mainDecl] else [itDecl]
356 in
355 in
357− P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
356+ P.Module moduleName ((importDecl `map` imports) ++ lets ++ decls) Nothing
357+
358
358
359-- |
359-- |
360-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
360-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
@@ -408,10 +408,10 @@ handleDeclaration val = do
408-- Takes a let declaration and updates the environment, then run a make. If the declaration fails,
408-- Takes a let declaration and updates the environment, then run a make. If the declaration fails,
409-- restore the pre-let environment.
409-- restore the pre-let environment.
410--
410--
411−handleLet :: (P.Expr -> P.Expr) -> PSCI ()
411+handleLet :: [P.Declaration] -> PSCI ()
412−handleLet l = do
412+handleLet ds = do
413 st <- PSCI $ lift get
413 st <- PSCI $ lift get
414− let st' = updateLets l st
414+ let st' = updateLets ds st
415 let m = createTemporaryModule False st' (P.ObjectLiteral [])
415 let m = createTemporaryModule False st' (P.ObjectLiteral [])
416 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st' ++ [(Left P.RebuildAlways, m)]) []
416 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st' ++ [(Left P.RebuildAlways, m)]) []
417 case e of
417 case e of
psci/Parser.hs+1−1
@@ -76,7 +76,7 @@ parseCommand cmdString =
76 -- we actually want the normal @let@.
76 -- we actually want the normal @let@.
77 --
77 --
78 psciLet :: P.TokenParser Command
78 psciLet :: P.TokenParser Command
79− psciLet = Let <$> (P.Let <$> (P.reserved "let" *> P.indented *> manyDecls))
79+ psciLet = Let <$> (P.reserved "let" *> P.indented *> manyDecls)
80 where
80 where
81 manyDecls :: P.TokenParser [P.Declaration]
81 manyDecls :: P.TokenParser [P.Declaration]
82 manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))
82 manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))