@@ -83,8 +83,8 @@ codegenJs conf ci =
8383 if optim then putStrLn "compiling width idris-js optimizations"
8484 else putStrLn "compiling widthout idris-js optimizations"
8585 else pure ()
86− let defs = addAlist (liftDecls ci) emptyContext
87− let used = used_decls defs [sMN 0 "runMain"]
86+ let defs = Map.fromList $ liftDecls ci
87+ let used = Map.elems $ used_defs defs [sMN 0 "runMain"]
8888 used `deepseq` if debug then
8989 do
9090 putStrLn $ "Finished calculating used"
@@ -137,7 +137,7 @@ doPartials x =
137137 in jsAst2Text $
138138 JsFun (jsPartialName p) vars1 $ JsReturn $ JsCurryLambda vars2 (JsApp (jsName n) (map JsVar (vars1 ++ vars2)) )
139139
140−doCodegen :: CGConf -> LDefs -> [LDecl] -> (Text, CGStats)
140+doCodegen :: CGConf -> Map Name LDecl -> [LDecl] -> (Text, CGStats)
141141doCodegen conf defs decls =
142142 let xs = map (doCodegenDecl conf defs) decls
143143 groupCGStats x y = CGStats {usedWriteStr = usedWriteStr x || usedWriteStr y
@@ -147,7 +147,7 @@ doCodegen conf defs decls =
147147 }
148148 in (T.intercalate "\n" $ map fst xs, foldl' groupCGStats emptyStats (map snd xs) )
149149
150−doCodegenDecl :: CGConf -> LDefs -> LDecl -> (Text, CGStats)
150+doCodegenDecl :: CGConf -> Map Name LDecl -> LDecl -> (Text, CGStats)
151151doCodegenDecl conf defs (LFun _ n args def) =
152152 let (ast, stats) = cgFun conf defs n args def
153153 in (jsAst2Text $ ast, stats)
@@ -159,7 +159,7 @@ seqJs [] = JsEmpty
159159seqJs (x:xs) = JsSeq x (seqJs xs)
160160
161161
162−data CGBodyState = CGBodyState { defs :: LDefs
162+data CGBodyState = CGBodyState { defs :: Map Name LDecl
163163 , lastIntName :: Int
164164 , currentFnNameAndArgs :: (Text, [Text])
165165 , usedArgsTailCallOptim :: Set (Text, Text)
@@ -195,7 +195,7 @@ getConsId :: Name -> State CGBodyState Int
195195getConsId n =
196196 do
197197 st <- get
198− case lookupCtxtExact n (defs st) of
198+ case Map.lookup n (defs st) of
199199 Just (LConstructor _ conId _) -> pure conId
200200 _ -> error $ "Internal JS Backend error " ++ showCG n ++ " is not a constructor."
201201
@@ -203,7 +203,7 @@ getArgList :: Name -> State CGBodyState (Maybe [Name])
203203getArgList n =
204204 do
205205 st <- get
206− case lookupCtxtExact n (defs st) of
206+ case Map.lookup n (defs st) of
207207 Just (LFun _ _ a _) -> pure $ Just a
208208 _ -> pure Nothing
209209
@@ -224,7 +224,7 @@ replaceVarsByProj n d z =
224224 Just i -> JsArrayProj (JsInt i) n
225225 f x = x
226226
227−cgFun :: CGConf -> LDefs -> Name -> [Name] -> LExp -> (JsAST, CGStats)
227+cgFun :: CGConf -> Map Name LDecl -> Name -> [Name] -> LExp -> (JsAST, CGStats)
228228cgFun cnf dfs n args def =
229229 let
230230 fnName = jsName n
@@ -295,10 +295,9 @@ cgBody rt (LV (Glob n)) =
295295 pure $ ([], addRT rt $ JsApp (jsName n) [])
296296 Just a ->
297297 do
298− --newNames <- getNewCGNames $ length a
299298 let part = Partial n 0 (length a)
300299 addPartial part
301− pure ([], addRT rt $ JsApp (jsPartialName part) []) --JsCurryLambda newNames (JsApp (jsName n) (map JsVar newNames)))
300+ pure ([], addRT rt $ JsApp (jsPartialName part) [])
302301 Nothing ->
303302 pure $ ([], addRT rt $ JsVar $ jsName n)
304303cgBody rt (LApp tailcall (LV (Glob fn)) args) =
@@ -315,10 +314,6 @@ cgBody rt (LApp tailcall (LV (Glob fn)) args) =
315314 modify (\x-> x {isTailRec = True})
316315 let ((y1,y2), y3) = tailCallOptimRefreshArgs (zip argN argVals) Set.empty
317316 addUsedArgsTailCallOptim y3
318− --vars <- getNewCGNames $ length argN --sequence $ map (\_->getNewCGName) argN
319− --let refreshArgs = JsSetVar "cgArgs2" (JsArray argVals)
320− --let calcs = map (\(n,v) -> JsDecVar n v) (zip vars argVals)
321− --let calcsToArgs = map (\(n,v) -> JsSetVar n (JsVar v)) (zip argN vars)
322317 pure (preDecs, y1 `JsSeq` y2)
323318 _ ->
324319 do
@@ -339,8 +334,7 @@ cgBody rt (LApp tailcall (LV (Glob fn)) args) =
339334 do
340335 let part = Partial fn lenArgs lenAgFn
341336 addPartial part
342− --newNames <- getNewCGNames $ lenAgFn - lenArgs
343− pure (preDecs, addRT rt $ JsApp (jsPartialName part) argVals ) -- JsCurryLambda newNames (JsApp fname (argVals ++ (map JsVar newNames) ) ) )
337+ pure (preDecs, addRT rt $ JsApp (jsPartialName part) argVals )
344338
345339cgBody rt (LForce (LLazyApp n args)) = cgBody rt (LApp False (LV (Glob n)) args)
346340cgBody rt (LLazyApp n args) =
@@ -431,7 +425,6 @@ cgAlts rt resName scrvar ((LConCase _ n args exp):r) =
431425 (d, v) <- cgBody (altsRT resName rt) exp
432426 (ar, def) <- cgAlts rt resName scrvar r
433427 conId <- getConsId n
434− -- let branchBody = JsSeq (conCaseToProjs 1 scrvar args) $ JsSeq (seqJs d) v
435428 let replace = replaceVarsByProj scrvar (Map.fromList $ zip (map jsName args) [1..])
436429 let branchBody = JsSeq (seqJs $ map replace d) (replace v)
437430 pure ((JsInt conId, branchBody) : ar, def)
@@ -454,7 +447,7 @@ cgForeignArg (FApp (UN "JS_FnT") [_,FApp (UN "JS_Fn") [_,_, a, FApp (UN "JS_FnIO
454447cgForeignArg (desc, _) =
455448 do
456449 st <- get
457− error $ "Foreign arg type " ++ show desc ++ " not supported yet. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
450+ error $ "Foreign arg type " ++ show desc ++ " not supported. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
458451
459452cgForeignRes :: FDesc -> JsAST -> State CGBodyState JsAST
460453cgForeignRes (FApp (UN "JS_IntT") _) x = pure x
@@ -466,7 +459,7 @@ cgForeignRes (FCon (UN "JS_Float")) x = pure x
466459cgForeignRes desc val =
467460 do
468461 st <- get
469− error $ "Foreign return type " ++ show desc ++ " not supported yet. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
462+ error $ "Foreign return type " ++ show desc ++ " not supported. While generating function " ++ (show $ fst $ currentFnNameAndArgs st)
470463
471464setUsedITBig :: State CGBodyState ()
472465setUsedITBig = modify (\s -> s {usedITBig = True})