ghc-api

Global variables via unsafePerformIO in Haskell

丶灬走出姿态 提交于 2019-12-02 01:59:52
问题 The GHC API requires that some initialisation occurs before invocation. Specifically, parseStaticFlags can only be called once. I have functions that can call runGhc :: MaybeFilePath :: Ghc a -> IO a multiple times to run some GHC API methods. However, some of that initialisation should only occur the first time that function is called. I seem to remember from Yi source that it is possible to create a global variable something like ghcInitialised :: MVar (Bool,[String]) ghcInitialised =

Global variables via unsafePerformIO in Haskell

岁酱吖の 提交于 2019-12-01 22:16:45
The GHC API requires that some initialisation occurs before invocation. Specifically, parseStaticFlags can only be called once. I have functions that can call runGhc :: MaybeFilePath :: Ghc a -> IO a multiple times to run some GHC API methods. However, some of that initialisation should only occur the first time that function is called. I seem to remember from Yi source that it is possible to create a global variable something like ghcInitialised :: MVar (Bool,[String]) ghcInitialised = unsafePerformIO $ newMVar (False,[]) so that in the monadic action that calls runGhc we can have (init,flags

Importing a known function from an already-compiled binary, using GHC's API or Hint

旧街凉风 提交于 2019-11-30 20:59:43
I have a module Target , with a function Target.accessMe inside it. I compile this module in some way, then get rid of the source code. Now, what series of arcane incantations must I do to make a different program dynamically import Target.accessMe ? This program knows accessMe 's type in advance. Also, consider the fact that the source code of Target is not available. The plugins package manages to accomplish this, but seems to have serious issues with working on Windows. I've checked out plugins 's source, but am having trouble understanding it. I've tried using Hint , but can only find out

Need a tutorial for using GHC to parse and typecheck Haskell

。_饼干妹妹 提交于 2019-11-30 08:01:53
I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my own tool to analyze the runtime characteristics of Haskell code, so it's like I'm writing a different hlint. What I'm looking for is basically an expansion of the wiki page GHC As a library . Adam, this is pretty tough sledding. Ever since its launch in 2006, the

Importing a known function from an already-compiled binary, using GHC's API or Hint

烈酒焚心 提交于 2019-11-30 05:42:00
问题 I have a module Target , with a function Target.accessMe inside it. I compile this module in some way, then get rid of the source code. Now, what series of arcane incantations must I do to make a different program dynamically import Target.accessMe ? This program knows accessMe 's type in advance. Also, consider the fact that the source code of Target is not available. The plugins package manages to accomplish this, but seems to have serious issues with working on Windows. I've checked out

Need a tutorial for using GHC to parse and typecheck Haskell

∥☆過路亽.° 提交于 2019-11-29 11:24:56
问题 I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my own tool to analyze the runtime characteristics of Haskell code, so it's like I'm writing a different hlint. What I'm looking for is basically an expansion of the

Compiling to GHC Core

亡梦爱人 提交于 2019-11-28 04:06:40
问题 I would like to create a frontend for a simple language that would produce GHC Core. I would like to then take this output and run it through the normal GHC pipeline. According to this page, it is not directly possible from the ghc command. I am wondering if there is any way to do it. I am ideally expecting a few function calls to the ghc-api but I am also open to any suggestions that include (not-so-extensive) hacking in the source of GHC. Any pointers would help! 回答1: There's still no way

Using GHC API to compile Haskell sources to CORE and CORE to binary

北战南征 提交于 2019-11-27 02:36:19
问题 The Idea Hello! I want to create a program, that will generate Haskell Core and will use GHC API to compile it further into an executable. But before I will do it I want to construct a very basic example, showing how can we just compile Haskell sources into CORE and then into the binary file. The problem I have read a lot of documentation and tried many methods from GHC Api, but for now without success. I started with Official GHC Api introduction and successfully compiled the examples. The