wantoknow
wantoknow

Reputation: 559

Compiling multiple languages together to make them run on different platforms

I would like to start with a THANK YOU to all those that answered my previous question on Compiling multiple languages together. Now I want to know whether or not it's possible to Compile multiple languages together so that they would run on different platforms.

Upvotes: -1

Views: 372

Answers (4)

John R. Strohm
John R. Strohm

Reputation: 7667

There's another approach that I heard about just recently.

Instead of distributing your application as machine binary (or bytecodes), you distribute it in "mostly-compiled" form, in the compiler's intermediate language. As long as all of your compilers for all of your languages use a common intermediate form, and all of your back-end code generators use that common intermediate form, you can install the particular back end you need on the target, and then distribute the intermediates.

MacOberon used this approach to target the 680x0 and PowerPC MAC hardware simultaneously. They called in "slim binaries". The exact same "binary" was distributed to either flavor of machine, and the back end essentially finished the compilation by generating the appropriate code.

Interestingly enough, this method is not significantly slower than the traditional method, because the cost of physically reading the "binary" from the disk into memory absolutely dominates the startup time of the application.

Upvotes: 0

Chip Uni
Chip Uni

Reputation: 7504

Yes, it is possible to compile multiple languages together so that they work on multiple platforms. There's a few ways:

Virtual machine

Scala and Java both compile to the JVM, which runs on many platforms. Another example is .NET, which includes many languages and can be run on Windows or Linux through the Mono Project.

Fat binaries

Some file formats are fat binaries that run on several platforms. Apple has used them to transfer between hardware implementations, on two occasions.

Upvotes: 0

John R. Strohm
John R. Strohm

Reputation: 7667

If you compile to machine-independent bytecode (or something similar), and then interpret the bytecodes on each target machine, it is relatively easy, as it is the same problem as compiling multiple languages to run on a single machine. Lots of people have solved this problem, to varying degrees of goodness of solution.

If you want to compile to absolute machine code, you have to include the machine code for every machine it will run on, and then the loader for each target machine has to know how to select the appropriate machine code.

Apple tried this with "fat binaries", in the days when PowerPC Macs and 68K Macs had to coexist peacefully. It worked, but it was not exactly a howling success.

Upvotes: 2

danben
danben

Reputation: 83320

I think that whether you are compiling one or multiple languages, the answer to whether your compiled code will run on different platforms depends on the existence of a virtual machine, like the JVM (Java Virtual Machine) or CLR (Common Language Runtime) that can interpret instructions and execute them on different platforms. Since different machine architectures support different instruction sets (here an instruction set refers to assembly), it isn't possible to compile your code to machine language in such a way that it will run on different platforms. As indicated in a response to your last question, multiple languages will compile to Java bytecode (for example), which can be linked together and run on any machine that has a JVM. Because there are implementations of the JVM for many different machine architectures, your Java bytecode can be run on any of those architectures.

Upvotes: 1

Related Questions