@@ -294,9 +294,11 @@ codegenJS_all target definitions includes filename outputType = do
294 main = compileJS $
294 main = compileJS $
295 JSAlloc "main" $ Just $ JSFunction [] (
295 JSAlloc "main" $ Just $ JSFunction [] (
296 JSSeq [ JSAlloc "vm" (Just $ JSNew "i$VM" [])
296 JSSeq [ JSAlloc "vm" (Just $ JSNew "i$VM" [])
298+ JSIdent (translateName (sMN 0 "runMain"))
297− , JSApp (JSIdent "mrunMain0") [ JSIdent "vm"
299+ ) [ JSIdent "vm"
298− , JSNum (JSInt 0)
300+ , JSNum (JSInt 0)
@@ -387,92 +389,11 @@ translateChar ch
387 '\BS', '\HT', '\LF', '\VT', '\FF', '\CR', '\SO', '\SI',
389 '\BS', '\HT', '\LF', '\VT', '\FF', '\CR', '\SO', '\SI',
388 '\DLE', '\DC1', '\DC2', '\DC3', '\DC4', '\NAK', '\SYN', '\ETB',
390 '\DLE', '\DC1', '\DC2', '\DC3', '\DC4', '\NAK', '\SYN', '\ETB',
389 '\CAN', '\EM', '\SUB', '\ESC', '\FS', '\GS', '\RS', '\US']
391 '\CAN', '\EM', '\SUB', '\ESC', '\FS', '\GS', '\RS', '\US']
390−translateIdentifier :: String -> String
391−translateIdentifier =
392− replaceReserved . concatMap replaceBadChars
393− where replaceBadChars :: Char -> String
397− | isDigit c = '_' : show (ord c)
398− | not (isLetter c && isAscii c) = '_' : show (ord c)
401− | s `elem` reserved = '_' : s
405− reserved = [ "break"
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
457translateName :: Name -> String
393translateName :: Name -> String
458−translateName (UN name) = 'u' : translateIdentifier (str name)
394+translateName n = "_idris_" ++ concatMap cchar (showCG n)
459−translateName (NS name _) = 'n' : translateName name
395+ where cchar x | isAlpha x || isDigit x = [x]
460−translateName (MN i name) = 'm' : translateIdentifier (str name) ++ show i
396+ | otherwise = "_" ++ show (fromEnum x) ++ "_"
461−translateName (SN name) = 's' : translateSpecialName name
462−translateName NErased = "e"
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
475− 'c' : translateName n
477jsASSIGN :: Reg -> Reg -> JS
398jsASSIGN :: Reg -> Reg -> JS
478jsASSIGN r1 r2 = JSAssign (translateReg r1) (translateReg r2)
399jsASSIGN r1 r2 = JSAssign (translateReg r1) (translateReg r2)
@@ -589,7 +510,6 @@ jsBigInt js = JSNum $ JSInteger $ JSBigIntExpr js
589jsUnPackBits :: JS -> JS
510jsUnPackBits :: JS -> JS
590jsUnPackBits js = JSIndex js $ JSNum (JSInt 0)
511jsUnPackBits js = JSIndex js $ JSNum (JSInt 0)
593jsPackUBits8 :: JS -> JS
513jsPackUBits8 :: JS -> JS
594jsPackUBits8 js = JSNew "Uint8Array" [JSArray [js]]
514jsPackUBits8 js = JSNew "Uint8Array" [JSArray [js]]
@@ -608,7 +528,6 @@ jsPackSBits16 js = JSNew "Int16Array" [JSArray [js]]
608jsPackSBits32 :: JS -> JS
528jsPackSBits32 :: JS -> JS
609jsPackSBits32 js = JSNew "Int32Array" [JSArray [js]]
529jsPackSBits32 js = JSNew "Int32Array" [JSArray [js]]
612jsCASE :: Bool -> Reg -> [(Int, [BC])] -> Maybe [BC] -> JS
531jsCASE :: Bool -> Reg -> [(Int, [BC])] -> Maybe [BC] -> JS
613jsCASE safe reg cases def =
532jsCASE safe reg cases def =
614 JSSwitch (tag safe $ translateReg reg) (
533 JSSwitch (tag safe $ translateReg reg) (