Chrome is written in C++, Assembly and Python. How were they able to write three different language… by @wimtenbrink
Answer by Wim ten Brink:
The Delphi application was the main executable and Delphi allows the use of Inline Assembly. This means I can combine Pascal with Assembly in a single source file.
The C++ code was used for creating a Shared Library, or a DLL file on Windows. A shared library exposes one or more functions to the outside through an interface that you can call from another module, like the executable I wrote in Delphi.
And this application ran as a service and was listening to port 80 so it would work as a simple web server. To create the web pages, I used PHP as the source for these web pages and called the PHP interpreter from my Delphi code while passing data as input and receiving the output of the PHP interpreter and collecting it as a string value. This string value thus became the response for each web request.
Basically, there are various techniques to combine multiple languages. The simplest method is when your compiler can actually handle two different languages. This is rare but some compilers will allow Assembly next to Pascal or C/C++.
A second technique is by linking the object files from one compiler with the object files of another compiler. This way, you could e.g. combine C++ and Pascal in a single executable, but both languages will cause conflicts in their runtime engines with one another if they are merged in this way due to memory management issues.
The third technique is by using Shared Objects. In these situations, each compiler generates a separate module that has it’s own runtime and will manage memory within it’s own context. There are some minor problems when you want to share memory between application and library because the allocated memory needs to be released again by the same language that allocated it!
And then you can just call a scripting engine for any scripted language. Most of those scripting engines are basically console applications with an input and output stream (and an error stream) which you can redirect within your code. Thus you would call the scripting engine to execute some script, send data over the input stream and read the output stream for the response. (And the error stream for possible errors.) This way, data goes back & forth between compiled code and scripting language.
There are even moresolutions, though. I can start explaining them all but that would be way too much typing! Just check the Wikipedia page I just mentioned…