If I wanted to turn a Java game into Lua, how could I do it? I'm thinking that you could have a program read the assembly language behind two programming languages, find the patterns, attach them to functions, and then convert the code accordingly. Has it been done, attempted, or theorized? What would be required to achieve this?
If I understand you correctly, you suggest a tool such that if you have a compiler which compiles from A to B, and a compiler which compiles from C to B, then the tool could analyze the behavior of both compilers and from this resolve how to translate from A to C.
This sounds fascinating, but I never heard about anything remotely like this, and I'm unsure if it could even work. You probably have to invent it yourself!
In reality, if you want to translate code from one high level language into another, it is done manually by humans who knows both languages. There are some examples of tools which translate from one high-level languages into another, but this is only possible for languages which are semantically closely related (like from C# to VB.Net). For example it is simply not possible to make an automatic translator from C to Python, because a lot of things you can do in C is (deliberately) not possible in Python.
Of course a compiler is itself an automatic translator from one language to another, but they usually only go from a high-level language to a lover-level language, an the generated code is not designed to be human readable and therefore not usually practical to use as source code for further development.
There are lots of compiler that do these kinds of conversions:
- Haxe Haxe -> Just About Anything
- TioPort Java -> D
- RPython Python (Subset) -> C
In general, these compilers produce a second program that will do exactly the same thing as the first one. However, the second program will very difficult to read.
I'm thinking that you could have a program read the assembly language behind two programming languages, find the patterns, attach them to functions, and then convert the code accordingly.
That's not really how it works. Generally, they begin with your source, not your resulting assembly. For each construct in your source language: class, function, assignement, etc. it produces the equivalent construct in the target language. So if you write a function in your source language, it will add a function in the target language that does the same thing.