Jump to content

  • Log In with Google      Sign In   
  • Create Account


F# to C++ Translator, feedback requested


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 RivieraKid   Members   -  Reputation: 373

Like
1Likes
Like

Posted 22 February 2014 - 06:03 AM

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, 22 February 2014 - 06:09 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS