
This seems to work fine. Thanks. Couldn't find the source snippet in the hide sources online. I take it the source is from the ghc port you are working on right now? Are the sources available or do you need anybody to test? :) Thanks again. Lemmih wrote:
On 5/16/06, Maarten
wrote: Is there a way to use the ghc api to call functions directly instead of evaluating statements (more or less similar to hs-plugins)?
So far, thanks to some info pages, I have been able to load sessions and make modules, however there seems to be little or no documentation on calling functions directly. Any info/pointers appreciated. Thanks.
Here's some code from hIDE:
compileSymbol :: Session -> String -> IO (HValue, Type) compileSymbol session symbol = do name <- fmap expectOneName (GHC.parseName session symbol) Just tything <- GHC.lookupName session name let globalId = getGlobalId tything hscEnv <- GHC.sessionHscEnv session unlinked <- coreExprToBCOs (hsc_dflags hscEnv) (Var globalId) hvalue <- linkExpr hscEnv unlinked return (hvalue, idType globalId) where getGlobalId (AnId id) | isGlobalId id = id getGlobalId (AnId _) = error $ symbol ++ ": not a global id" getGlobalId (ADataCon _) = error $ symbol ++ ": is a data constructor" getGlobalId (ATyCon _) = error $ symbol ++ ": is a type constructor" getGlobalId (AClass _) = error $ symbol ++ ": is a class" expectOneName [x] = x expectOneName [] = error $ "No such symbol in plugin: " ++ symbol expectOneName _ = error $ "Ambiguous symbol in plugin: " ++ symbol