@@ -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\