什么是编译器的好处即服务 [英] What are the benefits of Compiler as a Service

查看:233
本文介绍了什么是编译器的好处即服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安德斯·海尔斯伯格的.NET 4.0 presentation他NET 5.0讨论(或将来的某个版本),他们正在研究一种编译器即服务的模式。

In Anders Hejlsberg's .NET 4.0 presentation he discussed in NET 5.0 ("or some future release") they are working on a "Compiler as a Service" model.

安德斯·海尔斯伯格的状态:[来源] [1] 我们要打开我们的编译器,使其成为一个API,你可以调用编译一张code和取回前pression树和/或IL,这使得场景,如应用程序一大堆可编程性,互动提示下,用户编写的重构和领域有C#嵌在其中的小岛屿特定的语言。

Anders Hejlsberg's states: [source][1] "We want to open up our compiler so it becomes an API you can call to compile a piece of code and get back expression trees and/or IL. This enables a whole host of scenarios, such as application programmability, an interactive prompt, user-written refactorings, and domain specific languages that have little islands of C# imbedded in them."

我在努力寻找一个现实世界的例子,这实际上可能是有用的。我失去了主要的概念在这里?或者这真的会受益的语言?

I'm struggling to find a real world example where this could actually be useful. Am I missing the major concept here? or is this really going to benefit the language?

[1]:http://www.simple-talk.com/opinion/geek-of-the-week/anders-hejlsberg-geek-of-the-week/编译器即服务

[1]: http://www.simple-talk.com/opinion/geek-of-the-week/anders-hejlsberg-geek-of-the-week/ Compiler as a Service

推荐答案

有关的一些问题,它更容易编写一个程序,它可以生成一个程序,解决实际问题。一个领域,这是特别有用的,是建设解析器编译器。

For some problems, it is easier to write a program that can generate a program that will solve the actual problem. One area where this is particular useful is for building parsers for compilers.

在其他情况下,可以生成code的,可以与特定的数据类型,工作时进行调整以提供最佳的性能飞关于其属性,你刚刚得知在运行时反映在它的元数据。一个例子,我可以给你的是我的 Modelshredder 项目。它通常做的是获取对象的所有字段和属性和包装的价值为一个对象数组。

In other cases, you can generate code on the fly which can be tailored to provide optimum performance when working with a particular data type, about whose properties you just learned at runtime by reflecting over its metadata. One example I can give you for that is my Modelshredder project. What it basically does is taking all the fields and properties of an object and packs their value into an object array.

我的第一个方法,这个问题是一方面codeD MSIL注射用 Reflection.Emit的。第二种方法是多了几分活力,依靠前pression树,它可以有效地构建并编译在运行时提供相同的功能我的手codeD MSIL注射。你可以看到,实现了MoreLinq干线(只要看看在Modelshredder网站,有一个链接,这一点)。有编译器作为一种服务实际上让我提高抽象级别,放出C#code,这将随后被编译为MSIL。

My first approach to that problem was hand coded MSIL injection using Reflection.Emit. The second approach was a little more dynamic and relied on Expression Trees, which can effectively be constructed and compiled at runtime to provide the same functionality as my hand coded MSIL injection. You can see that realised in the MoreLinq trunk (just have a look at the Modelshredder site, there's a link for that). Having Compiler as a Service would actually allow me to raise abstraction level and emit C# code which will then get compiled to MSIL.

已经作出的案例领域专用语言,我也认为命令式语言,如C#是不是非常适合的命令行的情况,但是,而不是更大的脚本。 有基于一个F#DSL称为 FAKE ,一个整洁的化妆系统,它借用了很多概念的编译器即服务。类似的概念是由F#交互窗口内的VisualStudio采用(叫呀?)。

The case for Domain Specific Languages has already been made, also I think that an imperative language like C# is not well-suited for the "command line" scenario but rather than for bigger scripts. There's a neat make system based on an F# DSL called FAKE, which borrows a lot of concepts of Compiler as a Service. Similar concepts are employed by the F# Interactive Window (is it called that way?) inside VisualStudio.

这篇关于什么是编译器的好处即服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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