@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript
2module Generate.JavaScript
@@ -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+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
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 =
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)
83− stateToBuilder eval <> print interfaces home name
84+ stateToBuilder evalState <> print home name (I._types iface ! name)
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 =
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))) ""
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\