Feb 5, 2010 at 5:28 AM
Edited Feb 5, 2010 at 5:54 AM
This is an issue that sprung to my mind several times since I thought of switching from a compiler based on CCI-Metadata only to a compiler based on CCI-AST.
When you have to compile, say, a instance method invocation, you may have a MethodInvocation object in your compiler's AST with target expression, method name and actual arguments.
Using CCI-Metadata you would look-up for the type of the object instance, find all methods with that name, pick the one that is appropriate and then you will generate the CIL code.
Using CCI-AST you would just map your MethodInvocation the corresponding CCI-AST and all the details that require a knowledge of the actual type is carried out by CCI-AST itself. Maybe a little of help is required to perform the binding but nothing more.
Now what happens if you are generating something that is close to a MethodInvocation but it's not quite the same?
Let's call it CoolMethodInvocation. The CIL code emitted for CoolMethodInvocation is the same of a normal method invocation but there is "some more" (maybe before or after).
Now the point is: what if that "something more" depends on the actual type's metadata, for example the actual method called?
What would you do working with CCI-AST?
Of course 99% of the times it's easy to map that "something more" to some other CCI-AST objects. Let's make it 100%. That's not the problem.
But in order be able to choose what to do that you have to perform the binding yourself, map your objects to CCI-AST object, including the usual CCI-AST method invocation object.
At the end you performed the binding of a method two times with two different part of the compiler.
This is only an example but the problem is a more general. If this happens only once - for example your compiler only implements that CoolMethodInvocation - this is not a big problem. In other cases - for example if the language you are implementing includes
some metaprogramming features - the same problem emerges more and more often.
Am I missing something? Is this something that the current version of CCI-AST was not designed for? What's the best way to approach this kind of problems? For example in this case what would be the way to ask CCI-AST to perform the method binding the way
it would do it when compiling the normal method call. Is it exposed? (I'll try and follow the code but I wouldn't mind a hint!)
I'm sure I still don't understand all the architecture some I have overlooked something.