on master help sign in
javascript: a few HLint adjustments
commit33d6d7013d8929bd30fe584422e6b77e5b3d1801 authorraichoo <raichoo@googlemail.com> dateSat 28 Jun 2014, 02:35 (12 years ago) parenta88c208
1 file changed+19−19
src/IRTS/CodegenJavaScript.hs+19−19
src/IRTS/CodegenJavaScript.hs+19−19
@@ -38,16 +38,16 @@ initCompileInfo bc =
3838 lookupBigInt = any (needsBigInt . snd)
3939 where
4040 needsBigInt :: [BC] -> Bool
41− needsBigInt bc = any id $ map testBCForBigInt bc
41+ needsBigInt bc = or $ map testBCForBigInt bc
4242 where
4343 testBCForBigInt :: BC -> Bool
4444 testBCForBigInt (ASSIGNCONST _ c) =
4545 testConstForBigInt c
4646
4747 testBCForBigInt (CONSTCASE _ c d) =
48− (maybe False needsBigInt d)
49− || (any id $ map (needsBigInt . snd) c)
50− || (any id $ map (testConstForBigInt . fst) c)
48+ maybe False needsBigInt d
49+ || (or $ map (needsBigInt . snd) c)
50+ || (or $ map (testConstForBigInt . fst) c)
5151
5252 testBCForBigInt _ = False
5353
@@ -165,7 +165,7 @@ ffi code args = let parsed = ffiParse code in
165165 | isDigit s =
166166 FFIArg (read $ s : takeWhile isDigit ss) : ffiParse (dropWhile isDigit ss)
167167 | otherwise =
168− [FFIError $ "FFI - Invalid positional argument"]
168+ [FFIError "FFI - Invalid positional argument"]
169169 ffiParse (s:ss) = FFICode s : ffiParse ss
170170
171171
@@ -177,8 +177,8 @@ ffi code args = let parsed = ffiParse code in
177177
178178 renderFFI :: [FFI] -> [String] -> String
179179 renderFFI [] _ = ""
180− renderFFI ((FFICode c) : fs) args = c : renderFFI fs args
181− renderFFI ((FFIArg i) : fs) args
180+ renderFFI (FFICode c : fs) args = c : renderFFI fs args
181+ renderFFI (FFIArg i : fs) args
182182 | i < length args && i >= 0 = args !! i ++ renderFFI fs args
183183 | otherwise = error "FFI - Argument index out of bounds"
184184
@@ -219,7 +219,7 @@ compileJS' indent (JSType ty)
219219compileJS' indent (JSSeq seq) =
220220 intercalate ";\n" (
221221 map (
222− ((replicate indent ' ') ++) . (compileJS' indent)
222+ (replicate indent ' ' ++) . (compileJS' indent)
223223 ) $ filter (/= JSNoop) seq
224224 ) ++ ";"
225225
@@ -321,7 +321,7 @@ compileJS' indent (JSSwitch val branches def) =
321321 "switch(" ++ compileJS' indent val ++ "){\n"
322322 ++ concatMap mkBranch branches
323323 ++ mkDefault def
324− ++ (replicate indent ' ') ++ "}"
324+ ++ replicate indent ' ' ++ "}"
325325 where
326326 mkBranch :: (JS, JS) -> String
327327 mkBranch (tag, code) =
@@ -400,9 +400,9 @@ codegenJS_all target definitions includes libs filename outputType = do
400400 )
401401 writeFile filename $ runtime ++ concat code ++ main ++ invokeMain
402402 setPermissions filename (emptyPermissions { readable = True
403− , executable = target == Node
404− , writable = True
405− })
403+ , executable = target == Node
404+ , writable = True
405+ })
406406 where
407407 includeLibs :: [String] -> String
408408 includeLibs =
@@ -490,15 +490,15 @@ splitFunction (JSAlloc name (Just (JSFunction args body@(JSSeq _)))) = do
490490 where
491491 processBranches :: [(JS,JS)] -> RWS () [(Int,JS)] Int [(JS,JS)]
492492 processBranches =
493− traverse (runKleisli (arr id *** (Kleisli splitSequence)))
493+ traverse (runKleisli (arr id *** Kleisli splitSequence))
494494
495495 splitSequence :: JS -> RWS () [(Int, JS)] Int JS
496− splitSequence js@(JSSeq seq) = do
496+ splitSequence js@(JSSeq seq) =
497497 let (pre,post) = break isCall seq in
498498 case post of
499499 [] -> JSSeq <$> traverse splitCondition seq
500500 [js@(JSCond _)] -> splitCondition js
501− [js@(JSSwitch _ _ _)] -> splitCondition js
501+ [js@(JSSwitch {})] -> splitCondition js
502502 [_] -> return js
503503 (call:rest) -> do
504504 depth <- get
@@ -568,7 +568,7 @@ translateDecl info (name@(MN 0 fun), bc)
568568
569569 isCase :: BC -> Bool
570570 isCase bc
571− | CASE _ _ _ _ <- bc = True
571+ | CASE {} <- bc = True
572572 | otherwise = False
573573
574574 defaultCase :: [BC] -> [BC]
@@ -647,7 +647,7 @@ translateChar ch
647647 | '\\' <- ch = "\\\\"
648648 | '\"' <- ch = "\\\""
649649 | '\'' <- ch = "\\\'"
650− | ch `elem` asciiTab = "\\u00" ++ fill (showIntAtBase 16 intToDigit (ord ch) "")
650+ | ch `elem` asciiTab = "\\u00" ++ fill (showHex (ord ch) "")
651651 | otherwise = [ch]
652652 where
653653 fill :: String -> String
@@ -663,8 +663,8 @@ translateChar ch
663663
664664translateName :: Name -> String
665665translateName n = "_idris_" ++ concatMap cchar (showCG n)
666− where cchar x | isAlpha x || isDigit x = [x]
667− | otherwise = "_" ++ show (fromEnum x) ++ "_"
666+ where cchar x | isAlphaNum x = [x]
667+ | otherwise = "_" ++ show (fromEnum x) ++ "_"
668668
669669jsASSIGN :: CompileInfo -> Reg -> Reg -> JS
670670jsASSIGN _ r1 r2 = JSAssign (translateReg r1) (translateReg r2)