<commit_before>{-|
Module      : Graphics.Sudbury.Object
Description : Wayland object handling
Copyright   : (c) <NAME>, 2015
License     : MIT
Maintainer  : <EMAIL>
Stability   : experimental

This module can generate Haskell types which will represent Wayland objects,
and can marshal/demarshal values into/out of them.
-}
{-# LANGUAGE Trustworthy #-}
-- Simply importing Language.Haskell.TH is already considered unsafe.
-- The fact that we only generate some data in a pure way does not matter here.
module Graphics.Sudbury.Object where

import Language.Haskell.TH

import Graphics.Sudbury.Protocol.Types

generatePlainType :: String -> [String] -> Dec
generatePlainType name constrs =
  DataD [] (mkName name) [] (map (flip NormalC [] . mkName) constrs) []

protocolTypeData :: WLProtocol -> (String , [String])
protocolTypeData prot = (protocolName prot , map interfaceName (protocolInterfaces prot))<commit_msg>Further Object.hs work<commit_after>{-|
Module      : Graphics.Sudbury.Object
Description : Wayland object handling
Copyright   : (c) <NAME>, 2015
License     : MIT
Maintainer  : <EMAIL>
Stability   : experimental

This module can generate Haskell types which will represent Wayland objects,
and can marshal/demarshal values into/out of them.
-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- Simply importing Language.Haskell.TH is already considered unsafe.
-- The fact that we only generate some data in a pure way does not matter here.
module Graphics.Sudbury.Object where

import Language.Haskell.TH
import Data.Typeable
import Data.Word
import Data.Char

import Graphics.Sudbury.Protocol.Types

generatePlainType :: String -> [String] -> Dec
generatePlainType name constrs =
  DataD [] (mkName $ capitalize name) [] (map (flip NormalC [] . mkName . capitalize) constrs) []

protocolTypeData :: WLProtocol -> (String , [String])
protocolTypeData prot = (protocolName prot , map interfaceName (protocolInterfaces prot))

class ObjectPackClass (a :: k) where
  data ObjectPack a :: *
instance ObjectPackClass a where
  data ObjectPack a = Pack Word32
-- This instance does not print quite the right type information
-- But at least it gets us some output.
-- IOW, find something neater later.
instance Typeable a => Show (ObjectPack a) where
  show (Pack n) = "<" ++ show (typeRep (Proxy :: Proxy a)) ++ "@" ++ show n ++ ">"

capitalize :: String -> String
capitalize []       = []
capitalize (c : cs) = toUpper c : cs
{'fraction_non_alphanumeric': 0.10265556876734047, 'fraction_numerical': 0.003963535473642489, 'mean_word_length': 4.204123711340206, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651331', 'n_tokens_mistral': 757, 'n_tokens_neox': 713, 'n_words': 270}