<div dir="ltr">Hello Tim,<div><br></div><div>I don't know the answers to your questions exactly, but I've played around with something that I think might be related, so I thought I'd share.   The example code is here:</div><div><br></div><div><a href="https://github.com/GaloisInc/galua/blob/master/galua-jit/src/Galua/Micro/Compile.hs">https://github.com/GaloisInc/galua/blob/master/galua-jit/src/Galua/Micro/Compile.hs</a><br></div><div><br></div><div>This module contains a function that compiles (at runtime) a Haskell module represented as a String to the value of whatever `main` happened to be defined in this module.</div><div>Actually, in this case the expression is taken as a `Doc` , which is the result of pretty printing something, but this doc is simply "show"-ed to make a string (see `modText`).</div><div><br></div><div>The function works in roughly two steps:</div><div>    1. Compile the module:</div><div>        1.1. Setup some compiler flags, this has to do with the dependencies of the module (i.e., what packages it depends on, etc)</div><div>        1.2. Define a "target":  this is what GHC will be compiling.  There is a bit of weirdness here:  GHC can take the input to compile either from a text file, or from an in-memory buffer.  The second is what we want here.  Unfortunately, for some reason GHC still insists on there being a file around (its contents is completely irrelevant) I think it just want to check when it was last modified :-)    This is why we create an empty file.     This is something that should probably be fixed in GHC.</div><div>        1.3 Load all the targets:  this is what will actually compile the module</div><div>    2. Get the value of `main` in this module:  this is done in the `Succeed` branch of the case, where we create an expression `M.main` and tell GHC to evaluate it.</div><div><br></div><div>Depending on how you need things to be setup, just the second step might be enough (i.e., call `compileExpr`).   You'd still need to do enough to tell GHC in what context it will be compiling the expression though.</div><div><br></div><div>I am not an expert on this topic, but I'd be happy to try to answer more questions if I can.</div><div><br></div><div>-Iavor</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 17, 2017 at 10:42 AM Matthew Pickering <<a href="mailto:matthewtpickering@gmail.com">matthewtpickering@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Tim,<br>
<br>
When you say "multi-stage programming language" do you have a specific<br>
calculus in mind? I think this can mean lots of different things to<br>
different people.<br>
<br>
This is a topic I have been interested in recently.<br>
<br>
Cheers,<br>
<br>
Matt<br>
<br>
On Fri, Nov 17, 2017 at 6:05 PM, Tim Sheard <<a href="mailto:sheard@pdx.edu" target="_blank">sheard@pdx.edu</a>> wrote:<br>
> After many years of hoping someone else would do this, I would like to<br>
> make GHC into a true multi-stage programming language. Here is how I<br>
> thought I might approach this.<br>
><br>
> 1) Use the GHC as a library module.<br>
> 2) Use the LLVM backend.<br>
><br>
> I have no experience with either of these tools.<br>
> Lets start simple, How would I write functions like<br>
><br>
> compile :: String -> IO PtrToLLVMCode  -- where the string is a small<br>
> Haskell program.<br>
> llvmCompile :: PtrToLLVMCode -> IO PtrToMachineCode<br>
> jumpTo:: PtrToMachineCode -> IO ans   -- where ans is the "type" of the<br>
> string.<br>
><br>
><br>
> Any thoughts on how to get started? What papers to read, examples to look<br>
> at?<br>
><br>
> I'd love to move to some more disciplined input type, a sort of (mono) typed<br>
> program<br>
> representation (with similar complexity) to Template Haskell Exp type.<br>
><br>
> where (Exp t) is a data structure representing a Haskell program of type t.<br>
><br>
> All offers of advice accepted. I'm trying to get started soon, and good<br>
> advice<br>
> about what to avoid is especially welcome.  If any one wanted to help with<br>
> this,<br>
> that would be great.<br>
><br>
> Tim Sheard<br>
><br>
> _______________________________________________<br>
> ghc-devs mailing list<br>
> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>