[haskell-llvm] Beginner - Anonymous Functions

Elliott Pace etp20 at cam.ac.uk
Thu Nov 17 16:37:39 GMT 2011


Thanks again for the help. I realised I was perhaps rushing things too much
when I couldn't really think out the types.

A problem I'm having is that pointers seem to be well-typed, which causes
problems with my current representation of a function value. What's the
correct method of dealing with this?

So, my function value is: A pointer to a pair of pointers, one to a
function and one to a linked list of arguments. Therefore I would have
something like

type FunctionValue f = Ptr (Ptr f)
-- type FunctionValue[4] f = Ptr (LLNode a)

Now, trying to code my "call'" function, that given a pointer to a function
value and an argument, calls our function with argument and linked list as
needed:

call' :: Value (FunctionValue (LLNode a -> b -> IO c)) -> b ->
CodeGenFunction r c
call' fValue x = do
    f <- load fValue

    listPtr <- getElementPtr fValue (1 :: Word32, ())
    let _ = listPtr :: Value (Ptr (LLNode a))

    llNode <- load listPtr

    call f llNode x

This causes problems (amongst others present, but babysteps!). Another
problem is of course that my LLNode isn't always `a' (it can change as we
step through) which again comes back to my data not being so strongly
typed. How do I solve this?

Thanks.


On Wed, Nov 16, 2011 at 2:40 PM, Henning Thielemann <
lemming at henning-thielemann.de> wrote:

>
> On Wed, 16 Nov 2011, Elliott Pace wrote:
>
>  Thanks for the pointer in the right direction. I had a think and realised
>> I was going
>> about it completely the wrong way.
>>
>> My current attempt (at sum x y z = x + y + z) is that:
>>
>> A function value is a pointer to a pair of pointers. One pointer being
>> the code to
>> execute and one pointer being the head of a linked list of arguments
>> which will then be
>> walked when the body is finally evaluted (here at sum3).
>>
>> Here is my attempt:
>>
>> http://paste.ubuntu.com/**740212/ <http://paste.ubuntu.com/740212/>
>>
>
> Btw. you can assist me and you understanding the code by adding type
> signatures to the createFunction calls. You may even make them top-level
> functions.
>
> What I see is, that alloc2 returns a pointer to a number, that is, sum1'
> must be a pointer to a number. Then you try to 'call' this pointer like a
> function:
>
> 69      sum1' <- alloc2 sum1 nullptr
>
> 71      sum2' <- call' sum1' x
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://projects.haskell.org/pipermail/haskell-llvm/attachments/20111117/a447dd1d/attachment-0001.htm>


More information about the Haskell-llvm mailing list