@@ -294,9 +294,11 @@ codegenJS_all target definitions includes filename outputType = do
294294 main = compileJS $
295295 JSAlloc "main" $ Just $ JSFunction [] (
296296 JSSeq [ JSAlloc "vm" (Just $ JSNew "i$VM" [])
297− , JSApp (JSIdent "mrunMain0") [ JSIdent "vm"
298− , JSNum (JSInt 0)
299− ]
297+ , JSApp (
298+ JSIdent (translateName (sMN 0 "runMain"))
299+ ) [ JSIdent "vm"
300+ , JSNum (JSInt 0)
301+ ]
300302 ]
301303 )
302304
@@ -387,92 +389,11 @@ translateChar ch
387389 '\BS', '\HT', '\LF', '\VT', '\FF', '\CR', '\SO', '\SI',
388390 '\DLE', '\DC1', '\DC2', '\DC3', '\DC4', '\NAK', '\SYN', '\ETB',
389391 '\CAN', '\EM', '\SUB', '\ESC', '\FS', '\GS', '\RS', '\US']
390−translateIdentifier :: String -> String
391−translateIdentifier =
392− replaceReserved . concatMap replaceBadChars
393− where replaceBadChars :: Char -> String
394− replaceBadChars c
395− | ' ' <- c = "_"
396− | '_' <- c = "__"
397− | isDigit c = '_' : show (ord c)
398− | not (isLetter c && isAscii c) = '_' : show (ord c)
399− | otherwise = [c]
400− replaceReserved s
401− | s `elem` reserved = '_' : s
402− | otherwise = s
403−
404−
405− reserved = [ "break"
406− , "case"
407− , "catch"
408− , "continue"
409− , "debugger"
410− , "default"
411− , "delete"
412− , "do"
413− , "else"
414− , "finally"
415− , "for"
416− , "function"
417− , "if"
418− , "in"
419− , "instanceof"
420− , "new"
421− , "return"
422− , "switch"
423− , "this"
424− , "throw"
425− , "try"
426− , "typeof"
427− , "var"
428− , "void"
429− , "while"
430− , "with"
431−
432− , "class"
433− , "enum"
434− , "export"
435− , "extends"
436− , "import"
437− , "super"
438−
439− , "implements"
440− , "interface"
441− , "let"
442− , "package"
443− , "private"
444− , "protected"
445− , "public"
446− , "static"
447− , "yield"
448− ]
449−
450−translateNamespace :: Name -> String
451−translateNamespace (UN _) = idrNamespace
452−translateNamespace (NS _ ns) = idrNamespace ++ concatMap (translateIdentifier . str) ns
453−translateNamespace (MN _ _) = idrNamespace
454−translateNamespace (SN name) = idrNamespace ++ translateSpecialName name
455−translateNamespace NErased = idrNamespace
456392
457393translateName :: Name -> String
458−translateName (UN name) = 'u' : translateIdentifier (str name)
459−translateName (NS name _) = 'n' : translateName name
460−translateName (MN i name) = 'm' : translateIdentifier (str name) ++ show i
461−translateName (SN name) = 's' : translateSpecialName name
462−translateName NErased = "e"
463−
464−translateSpecialName :: SpecialName -> String
465−translateSpecialName name
466− | WhereN i m n <- name =
467− 'w' : translateName m ++ translateName n ++ show i
468− | InstanceN n s <- name =
469− 'i' : translateName n ++ concatMap (translateIdentifier . str) s
470− | ParentN n s <- name =
471− 'p' : translateName n ++ translateIdentifier (str s)
472− | MethodN n <- name =
473− 'm' : translateName n
474− | CaseN n <- name =
475− 'c' : translateName n
394+translateName n = "_idris_" ++ concatMap cchar (showCG n)
395+ where cchar x | isAlpha x || isDigit x = [x]
396+ | otherwise = "_" ++ show (fromEnum x) ++ "_"
476397
477398jsASSIGN :: Reg -> Reg -> JS
478399jsASSIGN r1 r2 = JSAssign (translateReg r1) (translateReg r2)
@@ -589,7 +510,6 @@ jsBigInt js = JSNum $ JSInteger $ JSBigIntExpr js
589510jsUnPackBits :: JS -> JS
590511jsUnPackBits js = JSIndex js $ JSNum (JSInt 0)
591512
592−
593513jsPackUBits8 :: JS -> JS
594514jsPackUBits8 js = JSNew "Uint8Array" [JSArray [js]]
595515
@@ -608,7 +528,6 @@ jsPackSBits16 js = JSNew "Int16Array" [JSArray [js]]
608528jsPackSBits32 :: JS -> JS
609529jsPackSBits32 js = JSNew "Int32Array" [JSArray [js]]
610530
611−-- TODO unsafe
612531jsCASE :: Bool -> Reg -> [(Int, [BC])] -> Maybe [BC] -> JS
613532jsCASE safe reg cases def =
614533 JSSwitch (tag safe $ translateReg reg) (