[Haskell-cafe] GHC Api typechecking

Phyx lonetiger at gmail.com
Sat Apr 17 13:49:07 EDT 2010


Hi all, I was wondering if someone knows how to do the following:

 

I’m looking to typecheck a string using the GHC Api, where I run into
problems is that I need to construct a Target, but the TargetId only seem to
reference physical files.

 

Ofcourse I can write the string to a file and typecheck that file, but I
would like to do it all in memory and avoid IO if possible.

 

Does anyone know if this is possible?

 

For the record I’m trying to create the target as follows

 

createTarget :: String -> IO Target

createTarget content = 

 do clock  <- getClockTime

    buffer <- stringToStringBuffer content

    return $ Target { targetId           = TargetModule (mkModuleName
"string:internal") ß problem

                    , targetAllowObjCode = True

                    , targetContents     = Just (buffer,clock)

                    }

 

typeCheckStringOnly :: String -> IO (ApiResults Bool)

typeCheckStringOnly contents = handleSourceError processErrors $

runGhc (Just libdir) $ do

    dflags <- getSessionDynFlags

    setSessionDynFlags dflags

    target <- liftIO $ createTarget contents

    addTarget target

    load LoadAllTargets

    let modName = mkModuleName "string:internal" ß problem again, don’t know
how to create the dependency graph then.

    graph <- depanal [modName] True

    (\a->setSession $ a { hsc_mod_graph = graph }) =<< getSession

    value <- fmap typecheckedSource (typeCheck modName)

    return $ ApiOk True

 

Cheers,

Phyx

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100417/2b37d55c/attachment.html


More information about the Haskell-Cafe mailing list