On 9/28/05, Daniel Grunwald <daniel-c/LZLyLxtvmTUrhO6CyE8bNAH6kLmebB@xxxxxxxxxxxxxxxx> wrote:
3 is fine. How about methods with a special attribute that get run at
compile-type given their arguments as AST expressions and that can modify
the AST? This would be an easy way for _expression_ macros; they could either
be global in a module or in an extension class (public extensions class
System.Delegate: ...)
Hm... Interesting. Meta extension methods. See, we are ahead of C# 3 already.
If I understand you correctly the compiler would see:
spam.BeginInvoke()
Then it would fail to find a method with the proper signature inside
the specific callable type and fall back to an extension method
(defined elsewhere). Since the extension method is flagged as a meta
extension method somehow the compiler knows it must be executed during
compilation. The compiler will then execute code similar to the
following:
newExpression = Elsewhere.BeginInvoke(ast { spam.BeginInvoke() })
The extension method receives the entire method invocation _expression_
tree with all the types already resolved and then decide what should
be used in its place.
Is that what you were thinking?
These methods would not be easy to write though because to have decent
power they should be run during _expression_ resolution and be able to
properly emit error messages and type system bound nodes (maybe not).
A possible implementation of BeginInvoke could be:
class System.Delegate:
[MetaMethod]
def BeginInvoke(invocation as MethodInvocationExpression):
"""
Completes a BeginInvoke invocation by appending 'null' arguments.
"""
memberRef = invocation.Target as MemberReferenceExpression
assert memberRef is not null
type = memberRef.Target.ExpressionType as ICallableType
assert type is not null
expected = len(type.GetSignature().Parameters) + 2
existing = len(invocation.Arguments)
for i in range(expected - existing):
invocation.Arguments.Add(NullLiteralExpression())
# bind and resolve left as exercise to the reader
bind(invocation.Target, resolve(type, "BeginInvoke"))
return invocation
Even if most users won't be implementing meta methods they would allow
us to simplify the compiler I guess.
Hey Daniel, I liked it, thanks!
--
bamboo
http://blogs.codehaus.org/people/bamboo/
Got objects? http://www.db4o.com/