on master help sign in
fix basic008
commit9ed63a99895068ad0657fd77838669a850c6b66f authorbe5invis <belleve@typeof.net> dateWed 24 May 2017, 17:57 (9 years ago) parenta1c729c
3 files changed+6−51
src/IRTS/JavaScript/AST.hs+2−2 src/IRTS/JavaScript/Codegen.hs+2−9 src/IRTS/JavaScript/Name.hs+2−40
src/IRTS/JavaScript/AST.hs+2−2
@@ -31,6 +31,7 @@ import Numeric
3131
3232data JsStmt
3333 = JsEmpty
34+ | JsComment Text
3435 | JsExprStmt JsExpr
3536 | JsFun Text
3637 [Text]
@@ -94,7 +95,6 @@ data JsExpr
9495 | JsForeign Text
9596 [JsExpr]
9697 | JsB2I JsExpr
97− | JsComment Text
9898 | JsForce JsExpr
9999 deriving (Show, Eq, Data, Typeable)
100100
@@ -152,6 +152,7 @@ jsSetVar n x = JsSet (JsVar n) x
152152
153153jsStmt2Text :: JsStmt -> Text
154154jsStmt2Text JsEmpty = ""
155+jsStmt2Text (JsComment c) = T.unlines $ map ("// " `T.append`) $ T.lines c
155156jsStmt2Text (JsExprStmt e) = T.concat [jsAst2Text e, ";"]
156157jsStmt2Text (JsReturn x) = T.concat ["return ", jsAst2Text x, ";"]
157158jsStmt2Text (JsDecVar name exp) =
@@ -283,7 +284,6 @@ jsAst2Text (JsForeign code args) =
283284 args_repl (T.replace ("%" `T.append` T.pack (show i)) (T.concat ["(", t, ")"]) c) (i + 1) r
284285 in T.concat ["(", args_repl code 0 (map jsAst2Text args), ")"]
285286jsAst2Text (JsB2I x) = jsAst2Text $ JsBinOp "+" x (JsInt 0)
286−jsAst2Text (JsComment c) = T.concat ["/*", c, "*/"]
287287jsAst2Text (JsForce e) = T.concat ["js_idris_force(", jsAst2Text e, ")"]
288288
289289jsLazy :: JsExpr -> JsExpr
src/IRTS/JavaScript/Codegen.hs+2−9
@@ -164,7 +164,7 @@ doCodegen conf defs decls =
164164doCodegenDecl :: CGConf -> Map Name LDecl -> LDecl -> (Text, CGStats)
165165doCodegenDecl conf defs (LFun _ n args def) =
166166 let (ast, stats) = cgFun conf defs n args def
167− in (jsStmt2Text $ ast, stats)
167+ in (T.concat [jsStmt2Text (JsComment $ T.pack $ show n), "\n", jsStmt2Text ast], stats)
168168doCodegenDecl conf defs (LConstructor n i sz) = ("", emptyStats)
169169
170170seqJs :: [JsStmt] -> JsStmt
@@ -347,14 +347,7 @@ cgBody' rt (LV (Glob n)) =
347347 do
348348 argsFn <- getArgList n
349349 case argsFn of
350− Just [] -> do
351− n' <- cgName n
352− pure $ ([], addRT rt n')
353− Just a ->
354− do
355− let part = Partial n 0 (length a)
356− addPartial part
357− pure ([], addRT rt $ jsAppN (jsNamePartial part) [])
350+ Just a -> cgBody' rt (LApp False (LV (Glob n)) [])
358351 Nothing -> do
359352 n' <- cgName n
360353 pure $ ([], addRT rt n')
src/IRTS/JavaScript/Name.hs+2−40
@@ -35,47 +35,9 @@ jsEscape = concatMap jschar
3535 | x == '.' = "__"
3636 | otherwise = "_" ++ show (fromEnum x) ++ "_"
3737
38−showCGJS :: Name -> String
39−showCGJS (UN n) = "u$" ++ jsEscape (T.unpack n)
40−showCGJS (NS n s) = "q_" ++ show (length s) ++ "$" ++ showSep "$" (map (jsEscape . T.unpack) (reverse s))
41− ++ "$" ++ showCGJS n
42−showCGJS (MN _ u) | u == txt "underscore" = "_"
43−showCGJS (MN i s) = "t$" ++ jsEscape (T.unpack s) ++ "$" ++ show i
44−showCGJS (SN s) = showCGJS' s
45− where
46− showCGJS' (WhereN i p c) =
47− "where$" ++ showCGJS p ++ "$" ++ showCGJS c ++ "$" ++ show i
48− showCGJS' (WithN i n) = "with$" ++ showCGJS n ++ "$" ++ show i
49− showCGJS' (ImplementationN cl impl) =
50− "impl_" ++ show (length impl) ++ "$" ++ showCGJS cl ++ "$"
51− ++ showSep "$" (map (jsEscape . T.unpack) impl)
52− showCGJS' (MethodN m) = "meth$" ++ showCGJS m
53− showCGJS' (ParentN p c) = "parent$" ++ showCGJS p ++ "$" ++ show c
54− showCGJS' (CaseN fc c) = "case$" ++ showCGJS c ++ "$" ++ showFC' fc
55− showCGJS' (ElimN sn) = "elim$" ++ showCGJS sn
56− showCGJS' (ImplementationCtorN n) = "ictor$" ++ showCGJS n
57− showCGJS' (MetaN parent meta) =
58− "meta$" ++ showCGJS parent ++ "$" ++ showCGJS meta
59− showFC' (FC' NoFC) = ""
60− showFC' (FC' (FileFC f)) = "_" ++ cgFN f
61− showFC' (FC' (FC f s e))
62− | s == e = "_" ++ cgFN f ++ "_" ++ show (fst s) ++ "_" ++ show (snd s)
63− | otherwise =
64− "_" ++
65− cgFN f ++
66− "_" ++
67− show (fst s) ++
68− "_" ++ show (snd s) ++ "_" ++ show (fst e) ++ "_" ++ show (snd e)
69− cgFN =
70− concatMap
71− (\c ->
72− if not (isDigit c || isLetter c)
73− then "__"
74− else [c])
75−showCGJS (SymRef i) = error "can't do codegen for a symbol reference"
76−
7738jsName :: Name -> Text
78−jsName n = T.pack $ showCGJS n
39+jsName (MN i u) = T.concat ["$_", T.pack (show i), "_", T.pack $ jsEscape $ T.unpack u]
40+jsName n = T.pack $ jsEscape $ showCG n
7941
8042jsNameGenerated :: Int -> Text
8143jsNameGenerated v = T.pack $ "$cg$" ++ show v