Search code examples
c#javaphpmetaprogrammingcross-compiling

Meta-programming: write in one language X, cross-compile in multiple languages like C#, PHP, Java, C


In all projects I've done through the years I never came across a requirement like this, though it seems so easy on paper: write a plugin for many well-known CMS's.

Obviously, each plugin-system (or extension system) is different and this requires specific bridging code through an adapter pattern. But the core should be written once. I don't expect WordPress users to use a PHP-Java bridge, and I don't expect DotNetNuke users to use a .NET-Native bridge (though that's easier conceived).

The way I see it, the core should be compilable in three main domains that cover most CMS systems:

  • native, intermediate language could be C, or C++. Target can be used as PHP extension.
  • MSIL/CIL for .NET based languages
  • Java byte code for Java based systems

C# and Java translate pretty well to and from each other, but C and C# is much harder. Ultimately, it would be nice to possibly add other targets, so as not to force a WordPress or WikiMedia user to install an extension prior to using a plugin.

I'm sure this has come up with other too. What's a common way of tackling such problems? Should I define a DSL first and use DMS or similar to transform? Other options?


Solution

  • Haxe is a sort of meta-language that compiles for different platforms:

    • JavaScript
    • C++
    • C#
    • HashLink
    • Java
    • Lua
    • PHP
    • Python 3
    • NekoVM
    • Flash
    • ActionScript 3