<commit_before>%
% (c) The University of Glasgow, 2000
%
\section[CmLink]{Linker for GHCI}

\begin{code}
module CmLink ( Linkable(..),  Unlinked(..),
		filterModuleLinkables, 
		modname_of_linkable, is_package_linkable,
		LinkResult(..),
                link, 
                PersistentLinkerState{-abstractly!-}, emptyPLS )
where


import Interpreter
import CmStaticInfo	( PackageConfigInfo )
import Module		( ModuleName, PackageName )
import Outputable	( SDoc )
import Digraph		( SCC(..), flattenSCC )
import Outputable
import Panic		( panic )

#include "HsVersions.h"
\end{code}

\begin{code}
data PersistentLinkerState 
   = PersistentLinkerState {

#ifdef GHCI
	-- Current global mapping from RdrNames to closure addresses
        closure_env :: ClosureEnv,

	-- the current global mapping from RdrNames of DataCons to 
	-- info table addresses.
	-- When a new Unlinked is linked into the running image, or an existing
	-- module in the image is replaced, the itbl_env must be updated
	-- appropriately.
        itbl_env    :: ItblEnv

	-- notionally here, but really lives in the C part of the linker:
	--            object_symtab :: FiniteMap String Addr
#else
	dummy :: ()	--  sigh, can't have an empty record
#endif

     }

data LinkResult 
   = LinkOK   PersistentLinkerState
   | LinkErrs PersistentLinkerState [SDoc]

data Unlinked
   = DotO FilePath
   | DotA FilePath
   | DotDLL FilePath
   | Trees [UnlinkedIBind] ItblEnv  -- bunch of interpretable bindings, +
				    -- a mapping from DataCons to their itbls

instance Outputable Unlinked where
   ppr (DotO path)   = text "DotO" <+> text path
   ppr (DotA path)   = text "DotA" <+> text path
   ppr (DotDLL path) = text "DotDLL" <+> text path
   ppr (Trees binds _) = text "Trees" <+> ppr binds


isObject (DotO _) = True
isObject (DotA _) = True
isObject (DotDLL _) = True
isObject _ = False

isInterpretable (Trees _ _) = True
isInterpretable _ = False

data Linkable
   = LM ModuleName [Unlinked]
   | LP PackageName

instance Outputable Linkable where
   ppr (LM mod_nm unlinkeds) = text "LinkableM" <+> ppr mod_nm <+> ppr unlinkeds
   ppr (LP package_nm)       = text "LinkableP" <+> ptext package_nm

emptyPLS :: IO PersistentLinkerState
emptyPLS = return (PersistentLinkerState { closure_env = emptyClosureEnv, 
                                           itbl_env    = emptyItblEnv })
\end{code}

\begin{code}
link :: PackageConfigInfo 
     -> [SCC Linkable] 
     -> PersistentLinkerState 
     -> IO LinkResult

#ifndef GHCI_NOTYET
--link = panic "CmLink.link: not implemented"<commit_msg>[project @ 2000-11-08 15:14:03 by simonmar] fix heavy-handed merge-o :(<commit_after>%
% (c) The University of Glasgow, 2000
%
\section[CmLink]{Linker for GHCI}

\begin{code}
module CmLink ( Linkable(..),  Unlinked(..),
		filterModuleLinkables, 
		modname_of_linkable, is_package_linkable,
		LinkResult(..),
                link, 
                PersistentLinkerState{-abstractly!-}, emptyPLS )
where


import Interpreter
import CmStaticInfo	( PackageConfigInfo )
import Module		( ModuleName, PackageName )
import Outputable	( SDoc )
import Digraph		( SCC(..), flattenSCC )
import Outputable
import Panic		( panic )

#include "HsVersions.h"
\end{code}

\begin{code}
data PersistentLinkerState 
   = PersistentLinkerState {

#ifdef GHCI
	-- Current global mapping from RdrNames to closure addresses
        closure_env :: ClosureEnv,

	-- the current global mapping from RdrNames of DataCons to 
	-- info table addresses.
	-- When a new Unlinked is linked into the running image, or an existing
	-- module in the image is replaced, the itbl_env must be updated
	-- appropriately.
        itbl_env    :: ItblEnv

	-- notionally here, but really lives in the C part of the linker:
	--            object_symtab :: FiniteMap String Addr
#else
	dummy :: ()	--  sigh, can't have an empty record
#endif

     }

data LinkResult 
   = LinkOK   PersistentLinkerState
   | LinkErrs PersistentLinkerState [SDoc]

data Unlinked
   = DotO FilePath
   | DotA FilePath
   | DotDLL FilePath
   | Trees [UnlinkedIBind] ItblEnv  -- bunch of interpretable bindings, +
				    -- a mapping from DataCons to their itbls

instance Outputable Unlinked where
   ppr (DotO path)   = text "DotO" <+> text path
   ppr (DotA path)   = text "DotA" <+> text path
   ppr (DotDLL path) = text "DotDLL" <+> text path
   ppr (Trees binds _) = text "Trees" <+> ppr binds


isObject (DotO _) = True
isObject (DotA _) = True
isObject (DotDLL _) = True
isObject _ = False

isInterpretable (Trees _ _) = True
isInterpretable _ = False

data Linkable
   = LM ModuleName [Unlinked]
   | LP PackageName

instance Outputable Linkable where
   ppr (LM mod_nm unlinkeds) = text "LinkableM" <+> ppr mod_nm <+> ppr unlinkeds
   ppr (LP package_nm)       = text "LinkableP" <+> ptext package_nm

emptyPLS :: IO PersistentLinkerState
#ifdef GHCI
emptyPLS = return (PersistentLinkerState { closure_env = emptyFM, 
                                           itbl_env    = emptyFM })
#else
emptyPLS = return (PersistentLinkerState {})
#endif
\end{code}

\begin{code}
link :: PackageConfigInfo 
     -> [SCC Linkable] 
     -> PersistentLinkerState 
     -> IO LinkResult

#ifndef GHCI_NOTYET
--link = panic "CmLink.link: not implemented"
{'fraction_non_alphanumeric': 0.09191246431969553, 'fraction_numerical': 0.0041864890580399616, 'mean_word_length': 3.115896632732968, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7126319', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1709, 'n_words': 530}