• Advertisement
Sign in to follow this  

F# to C++ Translator, feedback requested

This topic is 1431 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

 

I am in the process of making a library to convert F# to C++.

Here is an example:

[<ReflectedDefinition>] 
module Functions =

    //must declare delegate with same name as let bound function
    type Add = delegate of int * int -> int      
    let Add(a,b) = a + b

open Functions
module Host =
    let main() =
        //get function pointer to exported C++ function
        let m = FunctionPointer<Add>
        Assert.AreEqual(m.Invoke(1,2),Add(1,2))

As you can see it is quite straight forward to use.

 

So how does this work?

F# allows you to read the definition of a function / member at runtime so in the above example it reads an AST of the form "let Add(a,b) = a + b".

Within the FunctionPointer definition that AST is transformed into a C++ AST and  then outputs the code into a template project, runs MSBuild, copies the dll to the program folder, dynamically loads the dll and gets the exported function.

 

I can then call this function directly from F#.

I am not finished.

 

Why am I doing this?

1. It is fun.

2. Maybe it will be useful.

 

Does anyone here think this is useful?

If so what would you use it for?

What functionality would make it more useful for you?

 

Thank you for your time.

Kind Regards

James

Edited by RivieraKid

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement