on master help sign in
Make REPL print stuff out again
45bdd0dEvan Czaplicki
builder/src/Elm/Project.hs+5−2
@@ -11,8 +11,10 @@ module Elm.Project
11
11
12
12
13import qualified Data.ByteString as BS
13import qualified Data.ByteString as BS
14+import Data.Map ((!))
14import System.FilePath ((</>))
15import System.FilePath ((</>))
15
16
17+import qualified Elm.Compiler as Compiler
16import qualified Elm.Docs as Docs
18import qualified Elm.Docs as Docs
17import qualified Elm.Name as N
19import qualified Elm.Name as N
18import qualified Elm.Project.Root as Root
20import qualified Elm.Project.Root as Root
@@ -67,8 +69,9 @@ compileForRepl source maybeName =
67 graph <- Crawl.crawlFromSource summary source
69 graph <- Crawl.crawlFromSource summary source
68 (dirty, ifaces) <- Plan.plan Nothing summary graph
70 (dirty, ifaces) <- Plan.plan Nothing summary graph
69 answers <- Compile.compile project Nothing ifaces dirty
71 answers <- Compile.compile project Nothing ifaces dirty
70− _results <- Artifacts.write root answers
72+ results <- Artifacts.write root answers
73+ let (Compiler.Artifacts elmi _ _) = results ! "Elm_Repl"
71− traverse (Output.generateReplFile summary graph) maybeName
74+ traverse (Output.generateReplFile summary graph elmi) maybeName
72
75
73
76
74
77
builder/src/Generate/Output.hs+5−4
@@ -21,6 +21,7 @@ import System.FilePath ((</>))
21
21
22import qualified Elm.Compiler.Module as Module
22import qualified Elm.Compiler.Module as Module
23import qualified Elm.Compiler.Objects as Obj
23import qualified Elm.Compiler.Objects as Obj
24+import qualified Elm.Interface as I
24import qualified Elm.Name as N
25import qualified Elm.Name as N
25import qualified Elm.Package as Pkg
26import qualified Elm.Package as Pkg
26
27
@@ -93,13 +94,13 @@ generateMonolith (Options debug target output_) summary@(Summary.Summary _ proje
93-- GENERATE REPL MONOLITH
94-- GENERATE REPL MONOLITH
94
95
95
96
96−generateReplFile :: Summary.Summary -> Crawl.Result -> N.Name -> Task.Task FilePath
97+generateReplFile :: Summary.Summary -> Crawl.Result -> I.Interface -> N.Name -> Task.Task FilePath
97−generateReplFile summary@(Summary.Summary _ project _ ifaces _) graph name =
98+generateReplFile summary@(Summary.Summary _ project _ _ _) graph iface name =
98 do
99 do
99 objectGraph <- organize summary graph
100 objectGraph <- organize summary graph
100
101
101− let home = Module.Canonical (Project.getName project) "ElmRepl"
102+ let home = Module.Canonical (Project.getName project) "Elm_Repl"
102− let builder = Obj.generateForRepl ifaces objectGraph home name
103+ let builder = Obj.generateForRepl objectGraph iface home name
103
104
104 liftIO $ IO.writeBuilder Paths.temp $
105 liftIO $ IO.writeBuilder Paths.temp $
105 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
106 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
compiler/src/Generate/JavaScript.hs+9−9
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript
2module Generate.JavaScript
4 ( Mode(..)
3 ( Mode(..)
@@ -19,6 +18,7 @@ import qualified Data.Text as Text
19import qualified Data.Text.Encoding as Text
18import qualified Data.Text.Encoding as Text
20import qualified Text.PrettyPrint.ANSI.Leijen as P
19import qualified Text.PrettyPrint.ANSI.Leijen as P
21
20
21+import qualified AST.Canonical as Can
22import qualified AST.Optimized as Opt
22import qualified AST.Optimized as Opt
23import qualified AST.Module.Name as ModuleName
23import qualified AST.Module.Name as ModuleName
24import qualified Data.Index as Index
24import qualified Data.Index as Index
@@ -74,25 +74,25 @@ toRealMode mode target fields =
74-- GENERATE FOR REPL
74-- GENERATE FOR REPL
75
75
76
76
77−generateForRepl :: I.Interfaces -> Opt.Graph -> ModuleName.Canonical -> N.Name -> B.Builder
77+generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
78−generateForRepl interfaces (Opt.Graph _ graph _) home name =
78+generateForRepl (Opt.Graph _ graph _) iface home name =
79 let
79 let
80 mode = Name.Debug Name.Server
80 mode = Name.Debug Name.Server
81− eval = addGlobal mode graph emptyState (Opt.Global home name)
81+ debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
82+ evalState = addGlobal mode graph debugState (Opt.Global home name)
82 in
83 in
83− stateToBuilder eval <> print interfaces home name
84+ stateToBuilder evalState <> print home name (I._types iface ! name)
84
85
85
86
86−print :: I.Interfaces -> ModuleName.Canonical -> N.Name -> B.Builder
87+print :: ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
87−print interfaces home name =
88+print home name annotation =
88 let
89 let
89 value = Name.toBuilder (Name.fromGlobal home name)
90 value = Name.toBuilder (Name.fromGlobal home name)
90 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
91 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
91− annotation = I._types (interfaces ! home) ! name
92 tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
92 tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
93 in
93 in
94 "var _value = " <> toString <> "(" <> value <> ");\n" <>
94 "var _value = " <> toString <> "(" <> value <> ");\n" <>
95− "var _type = '" <> B.stringUtf8 (show tipe) <> "';\n\
95+ "var _type = " <> B.stringUtf8 (show tipe) <> ";\n\
96 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
96 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
97 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
97 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
98 \} else {\n\
98 \} else {\n\
ui/terminal/src/Repl.hs+2−2
@@ -228,7 +228,7 @@ compile :: Output -> State -> Task.Task (Maybe FilePath)
228compile output (State count imports types defs tricks) =
228compile output (State count imports types defs tricks) =
229 let
229 let
230 elmSourceCode =
230 elmSourceCode =
231− (<>) "module ElmRepl exposing (..)\n\n" $
231+ (<>) "module Elm_Repl exposing (..)\n\n" $
232 addLines imports $ addLines types $ addLines defs $
232 addLines imports $ addLines types $ addLines defs $
233 List.foldr (<>) mempty (map Text.encodeUtf8Builder tricks)
233 List.foldr (<>) mempty (map Text.encodeUtf8Builder tricks)
234 in
234 in
@@ -253,7 +253,7 @@ compile output (State count imports types defs tricks) =
253
253
254addLines :: Map.Map N.Name Text.Text -> B.Builder -> B.Builder
254addLines :: Map.Map N.Name Text.Text -> B.Builder -> B.Builder
255addLines dict builder =
255addLines dict builder =
256− Map.foldr (\text b -> Text.encodeUtf8Builder text <> b) builder dict
256+ Map.foldr (\text b -> Text.encodeUtf8Builder text <> "\n" <> b) builder dict
257
257
258
258
259evaluate :: B.Builder -> Maybe N.Name -> Task.Task (Maybe FilePath)
259evaluate :: B.Builder -> Maybe N.Name -> Task.Task (Maybe FilePath)