扩展Mono C#编译器:有没有任何文档或先例? [英] Extending the Mono C# compiler: is there any documentation or precedent?

查看:196
本文介绍了扩展Mono C#编译器:有没有任何文档或先例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在参与一些有趣的编程语言研究,到目前为止,围绕着扩展即将到来的Java 7.0编译器以及一些非常强大的基于程序员生产力的功能。该工作应该同样适用于相关的编程语言,如C#。



我目前正在规划一个C#端口的功能选项。我更喜欢开源选项,以便这项工作的成果可以与尽可能广泛的受众分享。因此,Mono C#编译器似乎是最明显的起点。我是一个有经验的C#开发人员所以编写代码不是问题。我主要关心以可维护和支持的方式扩展编译器。在有关主题的单一常见问题(链接)中,声明Mono已经用作尝试C#语言的新想法(有三个或四个编译器派生自Mono的C#编译器)的基础。不幸的是,没有进一步的指针,到目前为止,Google搜索没有任何东西。



我想知道是否有任何人有任何信息。具有标准扩展性模型 c c c ?具体来说,我将在程序的抽象语法树上执行一些有趣的转换。有没有标准的机制,用于在抽象语法树生成和类型检查器之间的编译器链中插入功能,然后代码生成?



到目前为止,我写了一些广告-hoc扩展代码(主要是在代码生成器),但这似乎不是一个可维护的解决方案,特别是考虑到我打算尽可能保持我的延迟更新与Mono的Git树干。此外,能够对我的扩展进行更新而不必每次进行更改都重新编译整个编译器将是很好的。我想能够将我所有的AST操作包装到一个.NET程序集,可以由 mcs / gmcs / dmcs 而不必直接攻击核心编译器代码。





更新(2010年10月23日)



响应回复对我的问题,我决定我将开始工作在Mono的一个分支,以便为编译器创建一个简单的扩展性模型。这是在它的早期阶段,但这里是在GitHub:



http://github.com/rcook/mono-extensibility



主要提交是: http://github.com/rcook/mono-extensibility/commit/a0456c852e48f6822e6bdad7b4d12a357ade0d01


解决方案

如果有人愿意合作这个项目,请告诉我们。我不能充分回答你的问题,但如果你看看Miguel de Icaza博客上的C#扩展的例子,你会注意到,他们都采取补丁的形式对编译器,而不是插件或扩展。这似乎表明没有这样的API。



请注意,所有这些示例的范围比您看起来工作的范围小得多:





这些都是本地化的语法糖,没有有趣的行为。例如,第四个补丁为 IEnumerable 实现Cω的语法糖,但没有任何Cω的语义使这个语法有趣。如果你看看补丁你可以看到它字面上做愚蠢的句法扩展〜T IEnumerable< T> ,而不是Cω,其中成员访问和方法调用通过流适当地解除。



Microsoft Research的Phoenix编译器管道曾经被明确称为解决这些扩展性问题,但现在看来主要关注代码生成后端中的IR级别的优化和分析。事实上,我甚至不确定项目是否还活着。


I am currently involved in some interesting programming language research which has, up until now, centred around extending the upcoming Java 7.0 compiler with some very powerful programmer-productivity-based features. The work should be equally applicable to related programming languages such as C#.

I'm currently scoping out the options for prototyping a C# port of the functionality. I would prefer open-source options so that the fruits of this work can be shared with the broadest-possible audience. Thus the Mono C# compiler seems to be the most obvious starting point. I'm an experienced C# developer so writing the code isn't the problem. I'm mainly concerned about extending the compiler in a maintainable and supported fashion. In the Mono FAQ on the subject (link) it is stated that "Mono has already been used as a foundation for trying out new ideas for the C# language (there are three or four compilers derived from Mono's C# compiler)". Unfortunately, there are no further pointers than this and, so far, Google searches have not turned anything up.

I'm wondering if anybody out there has any information on this. Do mcs/gmcs/dmcs have a standard extensibility model? Specifically, I will be performing some interesting transformations on a program's abstract syntax tree. Is there a standard mechanism for inserting functionality into the compiler chain between abstract syntax tree generation and the type checker and then code generation?

Up until now I've written some ad-hoc extensions to the code (primarily in the code generator) but this doesn't seem to be a maintainable solution especially given that I intend to keep my extensions up to date with the Git trunk of Mono as much as possible. Furthermore it would be nice to be able to make updates to my extensions without having to recompile the whole compiler every time I make a change. I would like to be able to wrap all my AST manipulations into a single .NET assembly that could be dynamically loaded by mcs/gmcs/dmcs without having to hack at the core compiler code directly.

Any thoughts or pointers on extending the Mono C# compiler would be gratefully received!

UPDATES (23 October 2010)

In response to the responses to my question, I decided that I would start working on a branch of Mono in order to create a simple extensibility model for the compiler. It's in its very early stages, but here it is at GitHub:

http://github.com/rcook/mono-extensibility

And the main commit is: http://github.com/rcook/mono-extensibility/commit/a0456c852e48f6822e6bdad7b4d12a357ade0d01

If anybody would be interested in collaborating on this project, please let me know!

解决方案

Unfortunately, I cannot adequately answer your question, but if you look at the examples of C# extensions on Miguel de Icaza's blog, you will notice that all of them take the form of patches to the compiler, not plugins or extensions. This seems to indicate that there is no such API.

Note that all of these examples are of much smaller scope than what you seem to be working on:

These are mostly localized syntactic sugar, with no "interesting" behavior. The fourth patch, for example, implements Cω's syntactic sugar for IEnumerables, but without any of Cω's semantics that make this syntax interesting. If you look at the patch you can see that it literally does stupid syntactical expansion of ~TIEnumerable<T>, as opposed to Cω, where member access and method invocation are properly lifted over streams.

Microsoft Research's Phoenix Compiler Pipeline was once explicitly touted as the solution to such extensibility problems, but it seems that it now focuses mostly on optimizations and analysis on the IR level in a code generation backend. In fact, I'm not even sure if the project is even still alive.

这篇关于扩展Mono C#编译器:有没有任何文档或先例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆