<commit_before>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-2000
%
\section[StgInterp]{Translates STG syntax to interpretable form, and run it}

\begin{code}

module StgInterp ( runStgI ) where

#include "HsVersions.h"

import StgSyn
import Id 		( Id, idPrimRep )
import Panic		( panic )
import Outputable
import Var
import PrimOp		( PrimOp(..) )
import PrimRep		( PrimRep(..) )
import Literal		( Literal(..) )
import Type		( Type, typePrimRep, deNoteType, repType, funResultTy )
import DataCon		( DataCon, dataConTag, dataConRepArgTys )
import TyCon		( TyCon, isDataTyCon, tyConFamilySize, tyConDataCons )
import ClosureInfo	( mkVirtHeapOffsets )
import Class		( Class, classTyCon )

#ifdef GHCI
-- giga-hack
import {-# SOURCE #-} MCI_make_constr
#endif

import PrelGHC		--( unsafeCoerce#, dataToTag#,
			--  indexPtrOffClosure#, indexWordOffClosure# )
import IO		( hPutStr, stderr )
import PrelAddr 	( Addr(..) )
import Addr		( intToAddr, addrToInt )
import Storable
import Addr		-- again ...
import Word
import Bits


runStgI :: [TyCon] -> [Class] -> [StgBinding] -> IO Int

#ifndef GHCI
runStgI tycons classes stgbinds
   = panic "runStgI called in non-GHCI build"

#else

-- the bindings need to have a binding for stgMain, and the
-- body of it had better represent something of type Int# -> Int#
runStgI tycons classes stgbinds
   = do itbl_env <- mkITbls (tycons ++ map classTyCon classes)
        let binds = concatMap (stg2bind itbl_env) stgbinds
        let dbg_txt 
               = "-------------------- Binds --------------------\n" 
                 ++ showSDoc (vcat (map (\bind -> pprBind bind $$ char ' ') binds))

        hPutStr stderr dbg_txt

        let stgMain
               = case [rhs | Bind v rhs <- binds, showSDoc (ppr v) == "stgMain"] of
                    (b:_) -> b
                    []    -> error "\n\nCan't find `stgMain'.  Giving up.\n\n"        
        let result 
               = I# (evalI (AppII stgMain (LitI 0#))
                           (mkInitialSEnv binds){-initial se (never changes)-}<commit_msg>[project @ 2000-09-14 09:10:35 by simonmar] extend the scope of #ifdef GHCI so we can compile this with pre-4.08 compilers.<commit_after>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-2000
%
\section[StgInterp]{Translates STG syntax to interpretable form, and run it}

\begin{code}

module StgInterp ( runStgI ) where

#include "HsVersions.h"

import StgSyn
import Id 		( Id, idPrimRep )
import Panic		( panic )
import Outputable
import Var
import PrimOp		( PrimOp(..) )
import PrimRep		( PrimRep(..) )
import Literal		( Literal(..) )
import Type		( Type, typePrimRep, deNoteType, repType, funResultTy )
import DataCon		( DataCon, dataConTag, dataConRepArgTys )
import TyCon		( TyCon, isDataTyCon, tyConFamilySize, tyConDataCons )
import ClosureInfo	( mkVirtHeapOffsets )
import Class		( Class, classTyCon )

#ifdef GHCI
-- giga-hack
import {-# SOURCE #-} MCI_make_constr

import PrelGHC		--( unsafeCoerce#, dataToTag#,
			--  indexPtrOffClosure#, indexWordOffClosure# )
import IO		( hPutStr, stderr )
import PrelAddr 	( Addr(..) )
import Addr		( intToAddr, addrToInt )
import Storable
import Addr		-- again ...
import Word
import Bits
#endif


runStgI :: [TyCon] -> [Class] -> [StgBinding] -> IO Int

#ifndef GHCI
runStgI tycons classes stgbinds
   = panic "runStgI called in non-GHCI build"

#else

-- the bindings need to have a binding for stgMain, and the
-- body of it had better represent something of type Int# -> Int#
runStgI tycons classes stgbinds
   = do itbl_env <- mkITbls (tycons ++ map classTyCon classes)
        let binds = concatMap (stg2bind itbl_env) stgbinds
        let dbg_txt 
               = "-------------------- Binds --------------------\n" 
                 ++ showSDoc (vcat (map (\bind -> pprBind bind $$ char ' ') binds))

        hPutStr stderr dbg_txt

        let stgMain
               = case [rhs | Bind v rhs <- binds, showSDoc (ppr v) == "stgMain"] of
                    (b:_) -> b
                    []    -> error "\n\nCan't find `stgMain'.  Giving up.\n\n"        
        let result 
               = I# (evalI (AppII stgMain (LitI 0#))
                           (mkInitialSEnv binds){-initial se (never changes)-}
{'fraction_non_alphanumeric': 0.12446858762399622, 'fraction_numerical': 0.008738781294284365, 'mean_word_length': 2.5262281432139884, 'pattern_counts': {'":': 0, '<': 7, '<?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': '501836', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1446, 'n_words': 439}