[Git][ghc/ghc][wip/T23479] JS: aligned lits

Serge S. Gulin (@gulin.serge) gitlab at gitlab.haskell.org
Fri Oct 11 19:23:54 UTC 2024



Serge S. Gulin pushed to branch wip/T23479 at Glasgow Haskell Compiler / GHC


Commits:
1d61ba90 by Serge S. Gulin at 2024-10-11T22:23:43+03:00
JS: aligned lits

- - - - -


2 changed files:

- compiler/GHC/StgToJS/Literal.hs
- compiler/GHC/StgToJS/Types.hs


Changes:

=====================================
compiler/GHC/StgToJS/Literal.hs
=====================================
@@ -18,8 +18,8 @@ import GHC.StgToJS.Ids
 import GHC.StgToJS.Monad
 import GHC.StgToJS.Symbols
 import GHC.StgToJS.Types
+import GHC.StgToJS.Linker.Utils (decodeModifiedUTF8)
 
-import GHC.Data.FastString
 import GHC.Types.Literal
 import GHC.Types.Basic
 import GHC.Types.RepType
@@ -95,9 +95,10 @@ genLit = \case
 genStaticLit :: Literal -> G [StaticLit]
 genStaticLit = \case
   LitChar c                -> return [ IntLit (fromIntegral $ ord c) ]
-  LitString str
-    | True                 -> return [ StringLit (mkFastStringByteString str), IntLit 0]
-    -- \|  invalid UTF8         -> return [ BinLit str, IntLit 0]
+  LitString str -> case decodeModifiedUTF8 str of
+    Just t                 -> return [ StringLit t, IntLit 0]
+    -- invalid UTF8
+    Nothing                -> return [ BinLit str, IntLit 0]
   LitNullAddr              -> return [ NullLit, IntLit 0 ]
   LitNumber nt v           -> case nt of
     LitNumInt     -> return [ IntLit v ]


=====================================
compiler/GHC/StgToJS/Types.hs
=====================================
@@ -284,8 +284,8 @@ instance ToJExpr StaticLit where
   toJExpr (IntLit i)            = toJExpr i
   toJExpr NullLit               = null_
   toJExpr (DoubleLit d)         = toJExpr (unSaneDouble d)
-  toJExpr (StringLit t)         = app hdStrStr [toJExpr t]
-  toJExpr (BinLit b)            = app hdRawStr [toJExpr (map toInteger (BS.unpack b))]
+  toJExpr (StringLit t)         = app hdEncodeModifiedUtf8Str [toJExpr t]
+  toJExpr (BinLit b)            = app hdRawStringDataStr      [toJExpr (map toInteger (BS.unpack b))]
   toJExpr (LabelLit _isFun lbl) = global lbl
 
 -- | A foreign reference to some JS code



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d61ba90ab4f5a6725de185791ddb03e00d706dd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d61ba90ab4f5a6725de185791ddb03e00d706dd
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241011/64571aaa/attachment-0001.html>


More information about the ghc-commits mailing list