How to use multiple languages in a single program?

Asked

Viewed 4,801 times

5

I saw that Google Chrome is made in Python, C++ and Assembly and came to mind, like programming using multiple languages in a SINGLE program?

  • 3

    Name the source where it says this.

  • Did the answer solve your problem? Do you think you can accept it now? See [tour] to understand how it works. It would be helpful to indicate to everyone that the solution was useful and satisfactory for you. You can also vote on any question or answer you find useful on the entire site.

2 answers

7

C++, simply speaking, is a language that always generates binary executable code for a processor after passing through compiler. Assembly does the same after going through assembler. They may be linked together without any problem. Everything becomes a single executable because everything is executable code, it makes no difference in which language the source code was originally written, what matters here is the target code that is specific to a processor, is something the computer understands. The source code written in a language is something for the programmer to understand.

Python is a little different. It usually rotates in an interpreted or semi-interpreted way (roughly speaking). That is, you need a virtual machine that behaves as if it were a processor to execute the language instructions. This virtual machine is software like any other. The best known Pyhton virtual machine is written in C, which also generates binary code, and can be linked together with the code generated by C++ and Assembly.

Already the code written in Pyhton same, or stays in an auxiliary file, or is attached to the executable as a resource of the executable file or even a vector of bytes. Ali may contain either the Python font or the bytecode of that virtual machine that will be generated from the source in Pyhton by a compiler.

This technique is known as embedded virtual machine and can be done with several other languages such as Moon and Harbour, just to name a few.

Note that I don’t know if Chrome is a single program at all. It is possible to do this, but there is no guarantee that it has been done. Before I say I’m sure that’s true, there’s a lot of misguided information out there. What I can tell you is that the basis of the Chrome code is C++. It is very likely to use anything in Assembly. Nothing indicates to me that Python is actually used in it. I actually did some research, and not only did I find anything about it, but I even found someone claiming they don’t. Putting my observation together with someone else stating, makes me believe that this is really misinformation. I just can’t guarantee.

In some cases a language like Python is used to scripts development and testing, which is different from what is dealt with here.

It is possible to use Python in some implementation that generates executable and link along with direct C++ code, but this doesn’t usually happen. I don’t know how much the implementation that does this is always up to date.

  • C/C++ programs do not generate an assembly code, and from this assembly code the binary code is generated?

  • It depends on the compiler. In general they do not produce Assembly no, they can generate some other intermediate code more abstract than Assembly. But nothing prevents you from doing this either. I just don’t see the point for the compiler to do this. Of course a very simple compiler can delegate to an assembler to generate the executable, then yes it would generate an Assembly font.

0

In the development of a system you use several programming languages (C#, Javascript, Jquery). Each one, as explained in reply of Maniero, has his "specialty".

As a matter of curiosity, according to this forum, browsers have been developed:

Firefox

  • Rendering: Gecko, C++
  • Javascript engine: Spidermonkey, C
  • User Interface: Mostly XUL (a custom XML dialect), CSS, and Javascript, with some C++.

Chrome

  • Rendering: Webcore, C++
  • Javascript engine: V8, C++
  • User interface: Mainly C, although the mac port uses Objective-C, and some features in HTML, CSS and Javascript.

Safari

  • Rendering: Webcore, C++ (shared with Chrome)
  • Javascript engine: Javascriptcore, C++
  • User interface: probably Objective-C with HTML

Internet Explorer

  • All in C++

Opera

  • Opera switched to Webkit and V8, but the rendering was written in C++

Browser other questions tagged

You are not signed in. Login or sign up in order to post.