<commit_before>-- | Insertion of effects into the expression/declaration tree
--
--   We rely on the fact that we run after typechecking and after
--   the InsertMembers analysis, so that collection annotation effects
--   are present in the expression tree
--
--  TODO: handle cyclic scope properly
--        cyclic scope can create loops
--
--  TODO: switch symbol gensym to use monad

module Language.K3.Analysis.Effects.InsertEffects (
  runAnalysis
)
where

import Control.Arrow ( (&&&), second )

import Lanague.K3.Analysis.Effects.Core
import Lanague.K3.Analysis.Effects.Constructors

data Env = Env {
                globalEnv :: Map Identfier (K3 Symbol),
                count :: Int,
                bindEnv :: Map Identifier [K3 Symbol]
               }

startEnv :: Env
startEnv = Env {
             globalEnv=Map.empty,
             count = 1,
             bindEnv=Map.empty
           }

insertGlobal :: Identifier -> Effect -> Env -> Env
insertGlobal id e env = env {globalEnv=Map.insert id e globalEnv env}

getId :: Env -> (Int, Env)
getId env = (count env, env {count = 1 + count env})

insertBind :: Identifier -> Maybe (K3 Effect) -> K3 Symbol -> Env -> Env
insertBind id e s env =
  env {bindEnv=Map.insertWith (++) id [(e, s)] $ bindEnv env}<commit_msg>Fix misspelled imports in InsertEffects.<commit_after>-- | Insertion of effects into the expression/declaration tree
--
--   We rely on the fact that we run after typechecking and after
--   the InsertMembers analysis, so that collection annotation effects
--   are present in the expression tree
--
--  TODO: handle cyclic scope properly
--        cyclic scope can create loops
--
--  TODO: switch symbol gensym to use monad

module Language.K3.Analysis.Effects.InsertEffects (
  runAnalysis
)
where

import Control.Arrow ( (&&&), second )

import Language.K3.Core.Annotation

import Language.K3.Analysis.Effects.Core
import Language.K3.Analysis.Effects.Constructors

data Env = Env {
                globalEnv :: Map Identfier (K3 Symbol),
                count :: Int,
                bindEnv :: Map Identifier [K3 Symbol]
               }

startEnv :: Env
startEnv = Env {
             globalEnv=Map.empty,
             count = 1,
             bindEnv=Map.empty
           }

insertGlobal :: Identifier -> Effect -> Env -> Env
insertGlobal id e env = env {globalEnv=Map.insert id e globalEnv env}

getId :: Env -> (Int, Env)
getId env = (count env, env {count = 1 + count env})

insertBind :: Identifier -> Maybe (K3 Effect) -> K3 Symbol -> Env -> Env
insertBind id e s env =
  env {bindEnv=Map.insertWith (++) id [(e, s)] $ bindEnv env}
{'fraction_non_alphanumeric': 0.10317157050057317, 'fraction_numerical': 0.0072602216278181125, 'mean_word_length': 2.5474254742547426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '669483', 'n_tokens_mistral': 751, 'n_tokens_neox': 739, 'n_words': 273}