Peachpie Open Source PHP to .NET Compiler |
Written by Nikos Vaggalis | |||
Monday, 24 October 2016 | |||
Page 2 of 2
Fast forward to the future, at a time that we can fully experience Roslyn's profound effects on compiler construction, by looking into the building of the Peachpie PHP compiler.
What does Jakub Míšek, a member of Peachpie's core developer team have to say about the advantages of using Roslyn?
That's about Roslyn, what about the DLR, where does it fit into the picture? DLR is still an important part or runtime, but Roslyn simplifies and improves the compiler implementation. The port of PHP on .NET uses the same mechanism as "dynamic" in C#, but in the future, classes will provide DLR interfaces for complete DLR compatibility. So while not yet fully compatible with the DLR, it generates the use of callsites and implements the callsites' binders. Roslyn has helper classes called ILBuilder and MetadataWriter, which in addition to their small footprint and much greater performance in comparison to old .NET ILBuilder, it allows for a more low-level emission of IL.Thanks to their low level features, it makes possible for a more efficient use of the call site objects. In the future, we'll generate class declarations that implement the IDynamicMetaObjectProvider interface, so that when every other dynamic language as well as C# use the 'dynamic' keyword they will treat PHP classes correctly, with PHP semantics. E.g. if I write dynamic x = new SomePhpClass(); x.SomeNonExistingFunction(); it will properly call 'SomePhpClass::__call()'
What is more interesting, using the /t:library argument, we can create a dynamically linked library file (dll), which can be referenced by a C# (or any other .NET) project. In other words, we have already managed to achieve one-way interoperability, enabling the calling of PHP from C#.
This is demonstrated by compiling the following PHP program into a library, a .dll, using the aforementioned switch.:
Checking the dll under ILSpy reveals that the PHP function has turned strongly typed!:
It returns a double and gets a long instead of a generic value.This of course brings up the typing system debate; strong vs weak, static vs. dynamic. A refresher on the type systems, can be found in our Type Systems Demystified series. In essence what Jakub describes is that Roslyn facilitated the construction of a high end and versatile compiler in Peachpie in the quickest way possible, enhanced with capabilities never thought possible before: PHP code compiled into MSIL, and .NET assemblies containing PHP objects? now it is possible.. But what could PHP gain as a fully qualified member of the .NET languages family? In its turn the .NET platform through the DLR would grant stellar performance to PHP, since the PHP code is now a candidate of full static compilation. This would be a good approach to take into consideration in RPerl's proceedings in forking a statically compiled version of Perl 5. Check RPerl - Running Perl 5 Faster for more on that. Then,
Peachpie while currently only capable of supporting a subset of the PHP language, has already implemented the following feature list :
More InformationRelated ArticlesPro DLR 4.0 in .NET book review IronJS - In Conversation with Fredrik Holmströmm Where is Perl Heading? Interview with Jonathan Worthington Niecza - Perl 6 Implemented in .NET C# Guru - An Interview With Eric Lippert
To be informed about new articles on I Programmer, sign up for our weekly newsletter,subscribe to the RSS feed and follow us on, Twitter, Facebook, Google+ or Linkedin.
{loadposition moreNEWS} {loadposition moreNEWSlist}
{loadposition comment} <ASIN:1430230681> <ASIN:B004EWGKXQ>
|
|||
Last Updated ( Monday, 24 October 2016 ) |