<commit_before>{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances, GADTs #-}

{-| Make Type (see "AST") an instance of @Translatable@ (see
"CodeGen.Typeclasses"). -}

module CodeGen.Type where

import CodeGen.Typeclasses
import CodeGen.CCodeNames
import qualified CodeGen.Context as Ctx

import CCode.Main
import CCode.PrettyCCode
import Data.Char

import qualified Identifiers as ID
import qualified Types as Ty

translatePrimitive :: Ty.Type -> CCode Ty
translatePrimitive ty
    | Ty.isVoidType ty   = Ptr void
    | Ty.isIntType ty    = int
    | Ty.isRealType ty   = double
    | Ty.isBoolType ty   = bool
    | Ty.isStringType ty = Ptr char
    | otherwise = error $ show ty ++ " is not a primitive"

instance Translatable Ty.Type (CCode Ty) where
    translate ty
        | Ty.isPrimitive ty      = translatePrimitive ty
        | Ty.isActiveRefType ty  = Ptr pony_actor_t 
        | Ty.isPassiveRefType ty = Ptr $ Typ (show (data_rec_name ty))
        | Ty.isRefType ty        = error $ "Unknown activity of class '" ++ show ty ++ "'"
        | Ty.isArrowType ty      = closure
        | Ty.isTypeVar ty        = Ptr void
        | Ty.isFutureType ty     = future
        | Ty.isStreamType ty     = stream
        | otherwise = error $ "I don't know how to translate "++ show ty ++" to pony.c"

pony_arg_t_tag :: CCode Ty -> CCode Name
pony_arg_t_tag (Ptr _)         = Nam "p"
pony_arg_t_tag (Typ "int64_t") = Nam "i"
pony_arg_t_tag (Typ "double")  = Nam "d"
pony_arg_t_tag other           =
    error $ "Type.hs: no pony_arg_t_tag for " ++ show other
<commit_msg>Allow null to leak through to the backend (as void*)<commit_after>{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances, GADTs #-}

{-| Make Type (see "AST") an instance of @Translatable@ (see
"CodeGen.Typeclasses"). -}

module CodeGen.Type where

import CodeGen.Typeclasses
import CodeGen.CCodeNames
import qualified CodeGen.Context as Ctx

import CCode.Main
import CCode.PrettyCCode
import Data.Char

import qualified Identifiers as ID
import qualified Types as Ty

translatePrimitive :: Ty.Type -> CCode Ty
translatePrimitive ty
    | Ty.isVoidType ty   = Ptr void
    | Ty.isIntType ty    = int
    | Ty.isRealType ty   = double
    | Ty.isBoolType ty   = bool
    | Ty.isStringType ty = Ptr char
    | otherwise = error $ show ty ++ " is not a primitive"

instance Translatable Ty.Type (CCode Ty) where
    translate ty
        | Ty.isPrimitive ty      = translatePrimitive ty
        | Ty.isActiveRefType ty  = Ptr pony_actor_t 
        | Ty.isPassiveRefType ty = Ptr $ Typ (show (data_rec_name ty))
        | Ty.isRefType ty        = error $ "Unknown activity of class '" ++ show ty ++ "'"
        | Ty.isArrowType ty      = closure
        | Ty.isTypeVar ty        = Ptr void
        | Ty.isFutureType ty     = future
        | Ty.isStreamType ty     = stream
        | Ty.isNullType ty       = Ptr void
        | otherwise = error $ "I don't know how to translate "++ show ty ++" to pony.c"

pony_arg_t_tag :: CCode Ty -> CCode Name
pony_arg_t_tag (Ptr _)         = Nam "p"
pony_arg_t_tag (Typ "int64_t") = Nam "i"
pony_arg_t_tag (Typ "double")  = Nam "d"
pony_arg_t_tag other           =
    error $ "Type.hs: no pony_arg_t_tag for " ++ show other

{'fraction_non_alphanumeric': 0.09337808971620384, 'fraction_numerical': 0.0012206286237412267, 'mean_word_length': 2.7377423033067276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2193878', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1081, 'n_words': 333}