<commit_before>module Grin.Val(FromVal(..),ToVal(..),tn_2Tup,valToList,convertName,region_heap) where

import Atom
import Char
import Grin.Grin
import Name.VConsts
import Name.Names
import Name.Name
import Number

nil      = convertName dc_EmptyList
cons     = convertName dc_Cons
cChar    = convertName dc_Char
cInt     = convertName dc_Int
tn_2Tup  = convertName $ nameTuple DataConstructor 2
tn_Boolzh = convertName dc_Boolzh
tn_unit  = convertName dc_Unit

region_heap = Item (toAtom "heap") TyRegion

instance ConNames Val where
    vTrue  = NodeC tn_Boolzh [toUnVal (1 :: Int)]
    vFalse = NodeC tn_Boolzh [toUnVal (0 :: Int)]
    vUnit  = NodeC tn_unit []

class ToVal a where
    toVal :: a -> Val
    toUnVal :: a -> Val
    toUnVal x = toVal x

class FromVal a where
    fromVal :: Monad m => Val -> m a
    fromUnVal :: Monad m => Val -> m a
    fromUnVal x = fromVal x

instance ToVal () where
    toVal () = vUnit
    toUnVal () = unit

instance ToVal Bool where
    toVal True = vTrue
    toVal False = vFalse


instance ToVal a => ToVal [a] where
    toVal [] = NodeC nil []
    toVal (x:xs) =  NodeC cons [Const (toVal x),Const (toVal xs)]
instance  ToVal (Val,Val) where<commit_msg>add 'block' built in region<commit_after>module Grin.Val(FromVal(..),ToVal(..),tn_2Tup,valToList,convertName,region_heap) where

import Atom
import Char
import Grin.Grin
import Name.VConsts
import Name.Names
import Name.Name
import Number

nil      = convertName dc_EmptyList
cons     = convertName dc_Cons
cChar    = convertName dc_Char
cInt     = convertName dc_Int
tn_2Tup  = convertName $ nameTuple DataConstructor 2
tn_Boolzh = convertName dc_Boolzh
tn_unit  = convertName dc_Unit

-- This allocates data on the heap.
region_heap  = Item (toAtom "heap") TyRegion
-- This allocates data in the innermost enclosing region, including implicit regions.
region_block = Item (toAtom "block") TyRegion

instance ConNames Val where
    vTrue  = NodeC tn_Boolzh [toUnVal (1 :: Int)]
    vFalse = NodeC tn_Boolzh [toUnVal (0 :: Int)]
    vUnit  = NodeC tn_unit []

class ToVal a where
    toVal :: a -> Val
    toUnVal :: a -> Val
    toUnVal x = toVal x

class FromVal a where
    fromVal :: Monad m => Val -> m a
    fromUnVal :: Monad m => Val -> m a
    fromUnVal x = fromVal x

instance ToVal () where
    toVal () = vUnit
    toUnVal () = unit

instance ToVal Bool where
    toVal True = vTrue
    toVal False = vFalse


instance ToVal a => ToVal [a] where
    toVal [] = NodeC nil []
    toVal (x:xs) =  NodeC cons [Const (toVal x),Const (toVal xs)]
instance  ToVal (Val,Val) where
{'fraction_non_alphanumeric': 0.08904374758033294, 'fraction_numerical': 0.0038714672861014324, 'mean_word_length': 3.3283082077051924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4897307', 'n_tokens_mistral': 901, 'n_tokens_neox': 890, 'n_words': 299}