ghc api / calling functions?
Dear all, 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. Kind regards, Maarten ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghc api / calling functions?
On 5/16/06, Maarten [EMAIL PROTECTED] wrote: Dear all, 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 -- Friendly, Lemmih ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghc api / calling functions?
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 [EMAIL PROTECTED] 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 ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghc api / calling functions?
On 5/16/06, Maarten [EMAIL PROTECTED] wrote: 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? :) The code is from here: http://darcs.haskell.org/hIDE/packages/hidePlugin/src/Hide/Plugin/LoaderMidLevel.hs There isn't much to test yet, unfortunately. -- Friendly, Lemmih ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghc api / calling functions?
Lemmih wrote: On 5/16/06, Maarten [EMAIL PROTECTED] wrote: The code is from here: http://darcs.haskell.org/hIDE/packages/hidePlugin/src/Hide/Plugin/LoaderMidLevel.hs Found it. Thanks! I will check that out tomorrow. There isn't much to test yet, unfortunately. For me, there is more than enough to test... :) Thanks. Maarten ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users