Skip to content

Commit

Permalink
add: codegen utility file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol committed Dec 4, 2024
1 parent 00544c3 commit a149fb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions glados.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library
Ast.Tokenizer
Ast.Types
Codegen.Codegen
Codegen.Utils
Misc

build-depends:
Expand Down
11 changes: 11 additions & 0 deletions lib/Codegen/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Codegen.Utils where

import qualified Data.ByteString.Short as BS

-- | Converts a string to a `ByteString`.
stringToByteString :: String -> BS.ShortByteString
stringToByteString = BS.pack . map (fromIntegral . fromEnum)

-- | Converts a `ByteString` to a string.
byteStringToString :: BS.ShortByteString -> String
byteStringToString = map (toEnum . fromIntegral) . BS.unpack

0 comments on commit a149fb8

Please # to comment.