Hi Russell,
The Call pattern represents any invocation (in CTP, the thing that is being called is represented as a standard .NET MethodInfo object, which represents information about method). The first argument (ex) is an instance of an object if the call is a method call (or None for an ordinary function call). The second argument is MethodInfo and the last argument is the list of arguments.

To extract the quotation of a function with "ReflectedDefnition" attribute, you can use MethodWithReflectedDefinition pattern. The Call case for your code would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
    | Call(inst, meth, l) ->
        // extract the body - 
        //  for ReflectedDefinition, extract the lambda expression representing the function
        //  otherwise, we just return the name of the function/method
        let body =
          match meth with 
          | MethodWithReflectedDefinition(expr) ->
              sprintf "(%s)" (interpretInner expr)
          | _ -> meth.Name
          
        // Convert all arguments to string and separate them with spaces
        let args = l |> List.fold_left (fun s ex -> 
          sprintf "%s (%s)" s (interpretInner ex) ) ""
        
        // Extract the instance (returns either "obj." or just empty string)
        let instance = 
          match inst with
          | Some(e) -> (interpretInner e) + "."
          | _ -> ""
          
        sprintf "%s%s %s" instance body args

Hope this helps!
T.

By on 9/3/2008 4:23 PM ()

Thanks Tomáลก! I appreciated your help.

Now, I would like, as a learning exercise again, to transform the F# AST in a procedural code, something like C++ or Java.
What are the best practices for this kind of task ?

Many thanks.

Russell

By on 9/10/2008 3:41 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper