Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meta programming into several output languages

I'm looking for a way to have to write and maintain a certain algorithm (a graphics rendering sub-module of my code, actually) only once. I need the algorithm in C++, PHP and Javascript. Theoretically I could write it in C++ and wrap it into a PHP extension; but that has many issues of itself and doesn't solve the Javascript link.

What I'm looking for, I think, is a tool that converts from a language (doesn't matter which one) into the three (or two, if the source language is one of the three) output languages I'm targetting. I've found MetaL (http://www.meta-language.net/) which seems to do what I want but also looks dead (no updates since 2007) and only targets one of the three languages I need. It needs to be quite flexible and allow me to update the results - for example, I use Cairo in my C++ and PHP rendering, and HTML Canvas on the Javascript side. So I need to customize to the API for certain effects.

Alternatively, I'd settle for a PHP parser and lexer that would give me an AST with enough information for me to write generators for C++ and Javascript as an alternative backend.

Any ideas? Thanks.

like image 488
Roel Avatar asked Apr 18 '11 08:04

Roel


1 Answers

You could take a look at Haxe. Haxe is an open source programming language. It can be compiled to JavaScript, Flash/ActionScript, PHP, C++, Java, C#, Python and Lua.

like image 84
Yi Zhao Avatar answered Sep 23 '22 00:09

Yi Zhao