[alexandria-devel] [PATCH] PROG1-LET

Benjamin Saunders ralith at gmail.com
Sun Apr 8 20:40:26 UTC 2012


Meant to send this yesterday, but I appear to have bungled that:

On Sat, Apr 07, 2012 at 11:34:44PM +0300, Nikodemus Siivola wrote:
> Can you show an example or two of this pattern as you use it?

Certainly. I've been experimenting with a compiler backed by LLVM, and
using its IR builder, I often wish to create a function, define its
body, then return the function. This usually takes the form of:

(prog1-let (func (llvm:add-function ...))
 (setf (llvm:linkage func) :internal
       (llvm:function-calling-convention func) :fast)
 (llvm:with-object (local-builder builder)
   (llvm:position-builder-at-end local-builder
                                 (llvm:append-basic-block func
 "entry"))
   (loop :for (form . rest) :on body
         :for genned := (codegen module local-builder form)
         :unless rest :do (llvm:build-ret local-builder genned))))

Or when generating code for an if statement, where I wish to create a
phi instruction, specify its inputs, and then return it:

(prog1-let (phi (llvm:build-phi builder (llvm type) "result"))
 (llvm:add-incoming phi
                    (list then-result else-result)
                    (list then-block  else-block)))

I also use it within the module system to allocate a module object,
create the bindings implied by its import list, and return it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/alexandria-devel/attachments/20120408/6070f259/attachment.sig>


More information about the alexandria-devel mailing list