on master help sign in
Make REPL print stuff out again
commit45bdd0d115457079da357526fb65e3b3beed804f authorEvan Czaplicki <evancz@users.noreply.github.com> dateSun 1 Apr 2018, 15:48 (9 years ago) parent7ecefe8
4 files changed+21−17
builder/src/Elm/Project.hs+5−2 builder/src/Generate/Output.hs+5−4 compiler/src/Generate/JavaScript.hs+9−9 ui/terminal/src/Repl.hs+2−2
builder/src/Elm/Project.hs+5−2
@@ -11,8 +11,10 @@ module Elm.Project
1111
1212
1313import qualified Data.ByteString as BS
14+import Data.Map ((!))
1415import System.FilePath ((</>))
1516
17+import qualified Elm.Compiler as Compiler
1618import qualified Elm.Docs as Docs
1719import qualified Elm.Name as N
1820import qualified Elm.Project.Root as Root
@@ -67,8 +69,9 @@ compileForRepl source maybeName =
6769 graph <- Crawl.crawlFromSource summary source
6870 (dirty, ifaces) <- Plan.plan Nothing summary graph
6971 answers <- Compile.compile project Nothing ifaces dirty
70− _results <- Artifacts.write root answers
71− traverse (Output.generateReplFile summary graph) maybeName
72+ results <- Artifacts.write root answers
73+ let (Compiler.Artifacts elmi _ _) = results ! "Elm_Repl"
74+ traverse (Output.generateReplFile summary graph elmi) maybeName
7275
7376
7477
builder/src/Generate/Output.hs+5−4
@@ -21,6 +21,7 @@ import System.FilePath ((</>))
2121
2222import qualified Elm.Compiler.Module as Module
2323import qualified Elm.Compiler.Objects as Obj
24+import qualified Elm.Interface as I
2425import qualified Elm.Name as N
2526import qualified Elm.Package as Pkg
2627
@@ -93,13 +94,13 @@ generateMonolith (Options debug target output_) summary@(Summary.Summary _ proje
9394-- GENERATE REPL MONOLITH
9495
9596
96−generateReplFile :: Summary.Summary -> Crawl.Result -> N.Name -> Task.Task FilePath
97−generateReplFile summary@(Summary.Summary _ project _ ifaces _) graph name =
97+generateReplFile :: Summary.Summary -> Crawl.Result -> I.Interface -> N.Name -> Task.Task FilePath
98+generateReplFile summary@(Summary.Summary _ project _ _ _) graph iface name =
9899 do
99100 objectGraph <- organize summary graph
100101
101− let home = Module.Canonical (Project.getName project) "ElmRepl"
102− let builder = Obj.generateForRepl ifaces objectGraph home name
102+ let home = Module.Canonical (Project.getName project) "Elm_Repl"
103+ let builder = Obj.generateForRepl objectGraph iface home name
103104
104105 liftIO $ IO.writeBuilder Paths.temp $
105106 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
compiler/src/Generate/JavaScript.hs+9−9
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
32module Generate.JavaScript
43 ( Mode(..)
@@ -19,6 +18,7 @@ import qualified Data.Text as Text
1918import qualified Data.Text.Encoding as Text
2019import qualified Text.PrettyPrint.ANSI.Leijen as P
2120
21+import qualified AST.Canonical as Can
2222import qualified AST.Optimized as Opt
2323import qualified AST.Module.Name as ModuleName
2424import qualified Data.Index as Index
@@ -74,25 +74,25 @@ toRealMode mode target fields =
7474-- GENERATE FOR REPL
7575
7676
77−generateForRepl :: I.Interfaces -> Opt.Graph -> ModuleName.Canonical -> N.Name -> B.Builder
78−generateForRepl interfaces (Opt.Graph _ graph _) home name =
77+generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
78+generateForRepl (Opt.Graph _ graph _) iface home name =
7979 let
8080 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)
8283 in
83− stateToBuilder eval <> print interfaces home name
84+ stateToBuilder evalState <> print home name (I._types iface ! name)
8485
8586
86−print :: I.Interfaces -> ModuleName.Canonical -> N.Name -> B.Builder
87−print interfaces home name =
87+print :: ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
88+print home name annotation =
8889 let
8990 value = Name.toBuilder (Name.fromGlobal home name)
9091 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
91− annotation = I._types (interfaces ! home) ! name
9292 tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
9393 in
9494 "var _value = " <> toString <> "(" <> value <> ");\n" <>
95− "var _type = '" <> B.stringUtf8 (show tipe) <> "';\n\
95+ "var _type = " <> B.stringUtf8 (show tipe) <> ";\n\
9696 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
9797 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
9898 \} else {\n\
ui/terminal/src/Repl.hs+2−2
@@ -228,7 +228,7 @@ compile :: Output -> State -> Task.Task (Maybe FilePath)
228228compile output (State count imports types defs tricks) =
229229 let
230230 elmSourceCode =
231− (<>) "module ElmRepl exposing (..)\n\n" $
231+ (<>) "module Elm_Repl exposing (..)\n\n" $
232232 addLines imports $ addLines types $ addLines defs $
233233 List.foldr (<>) mempty (map Text.encodeUtf8Builder tricks)
234234 in
@@ -253,7 +253,7 @@ compile output (State count imports types defs tricks) =
253253
254254addLines :: Map.Map N.Name Text.Text -> B.Builder -> B.Builder
255255addLines 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
257257
258258
259259evaluate :: B.Builder -> Maybe N.Name -> Task.Task (Maybe FilePath)