<commit_before>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
\section[ConFold]{Constant Folder}

ToDo:
   check boundaries before folding, e.g. we can fold the Float addition
   (i1 + i2) only if it results	in a valid Float.

\begin{code}
module PrelRules ( primOpRule, builtinRules ) where

#include "HsVersions.h"

import CoreSyn
import Rules		( ProtoCoreRule(..) )
import Id		( idUnfolding, mkWildId, isDataConId_maybe )
import Literal		( Literal(..), isLitLitLit, mkMachInt, mkMachWord
			, inIntRange, inWordRange, literalType
			, word2IntLit, int2WordLit, char2IntLit, int2CharLit
			, float2IntLit, int2FloatLit, double2IntLit, int2DoubleLit
			, addr2IntLit, int2AddrLit, float2DoubleLit, double2FloatLit
			)
import PrimOp		( PrimOp(..), primOpOcc )
import TysWiredIn	( trueDataConId, falseDataConId )
import TyCon		( tyConDataCons, isEnumerationTyCon, isNewTyCon )
import DataCon		( DataCon, dataConTag, dataConRepArity, dataConTyCon, dataConId, fIRST_TAG )
import CoreUnfold	( maybeUnfoldingTemplate )
import CoreUtils	( exprIsValue, cheapEqExpr, exprIsConApp_maybe )
import Type		( splitTyConApp_maybe )
import OccName		( occNameUserString)
import ThinAir		( unpackCStringFoldrId )
import Maybes		( maybeToBool )
import Char		( ord, chr )
import Bits		( Bits(..) )
import PrelAddr		( wordToInt )
import Word		( Word64 )
import Outputable

#if __GLASGOW_HASKELL__ > 404
import PrelAddr ( intToWord )
#else
import PrelAddr ( Word(..) )
import PrelGHC  ( int2Word# )
intToWord :: Int -> Word
intToWord (I# i#) = W# (int2Word# i#)
#endif
\end{code}



\begin{code}
primOpRule :: PrimOp -> CoreRule
primOpRule op 
  = BuiltinRule (primop_rule op)
  where
    op_name = _PK_ (occNameUserString (primOpOcc op))
    op_name_case = op_name _APPEND_ SLIT("case")

    -- ToDo:	something for integer-shift ops?
    --		NotOp

    primop_rule SeqOp	    = seqRule
    primop_rule TagToEnumOp = tagToEnumRule
    primop_rule DataToTagOp = dataToTagRule

	-- Int operations
    primop_rule IntAddOp    = twoLits (intOp2  (+)  op_name)
    primop_rule IntSubOp    = twoLits (intOp2  (-)  op_name)
    primop_rule IntMulOp    = twoLits (intOp2  (*)  op_name)
    primop_rule IntQuotOp   = twoLits (intOp2Z quot op_name)<commit_msg>[project @ 2000-05-12 12:44:09 by rrt] Upped minimum version of GHC required to use new PrelAddr to 405.<commit_after>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
\section[ConFold]{Constant Folder}

ToDo:
   check boundaries before folding, e.g. we can fold the Float addition
   (i1 + i2) only if it results	in a valid Float.

\begin{code}
module PrelRules ( primOpRule, builtinRules ) where

#include "HsVersions.h"

import CoreSyn
import Rules		( ProtoCoreRule(..) )
import Id		( idUnfolding, mkWildId, isDataConId_maybe )
import Literal		( Literal(..), isLitLitLit, mkMachInt, mkMachWord
			, inIntRange, inWordRange, literalType
			, word2IntLit, int2WordLit, char2IntLit, int2CharLit
			, float2IntLit, int2FloatLit, double2IntLit, int2DoubleLit
			, addr2IntLit, int2AddrLit, float2DoubleLit, double2FloatLit
			)
import PrimOp		( PrimOp(..), primOpOcc )
import TysWiredIn	( trueDataConId, falseDataConId )
import TyCon		( tyConDataCons, isEnumerationTyCon, isNewTyCon )
import DataCon		( DataCon, dataConTag, dataConRepArity, dataConTyCon, dataConId, fIRST_TAG )
import CoreUnfold	( maybeUnfoldingTemplate )
import CoreUtils	( exprIsValue, cheapEqExpr, exprIsConApp_maybe )
import Type		( splitTyConApp_maybe )
import OccName		( occNameUserString)
import ThinAir		( unpackCStringFoldrId )
import Maybes		( maybeToBool )
import Char		( ord, chr )
import Bits		( Bits(..) )
import PrelAddr		( wordToInt )
import Word		( Word64 )
import Outputable

#if __GLASGOW_HASKELL__ > 405
import PrelAddr ( intToWord )
#else
import PrelAddr ( Word(..) )
import PrelGHC  ( int2Word# )
intToWord :: Int -> Word
intToWord (I# i#) = W# (int2Word# i#)
#endif
\end{code}



\begin{code}
primOpRule :: PrimOp -> CoreRule
primOpRule op 
  = BuiltinRule (primop_rule op)
  where
    op_name = _PK_ (occNameUserString (primOpOcc op))
    op_name_case = op_name _APPEND_ SLIT("case")

    -- ToDo:	something for integer-shift ops?
    --		NotOp

    primop_rule SeqOp	    = seqRule
    primop_rule TagToEnumOp = tagToEnumRule
    primop_rule DataToTagOp = dataToTagRule

	-- Int operations
    primop_rule IntAddOp    = twoLits (intOp2  (+)  op_name)
    primop_rule IntSubOp    = twoLits (intOp2  (-)  op_name)
    primop_rule IntMulOp    = twoLits (intOp2  (*)  op_name)
    primop_rule IntQuotOp   = twoLits (intOp2Z quot op_name)
{'fraction_non_alphanumeric': 0.08993669504475005, 'fraction_numerical': 0.018118314778432655, 'mean_word_length': 4.248568155784651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6325237', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1698, 'n_words': 431}