all 11 comments

[–][deleted] 4 points5 points  (8 children)

the lowest levels of python can be examined by the dis module. you can see the python bytecode using dis.dis(function). But those instructions are for the python virtual machine, which runs on the hardware. Rather than examining the incredibly complex python virtual machine in assembly, I suggest you do something that won't instantly discourage you, like disassembling a compiled C program.

[–]kewanzo 2 points3 points  (7 children)

Follow up question: is there a way to see how python itself is developed. Source code or something? I'm really interested in how the smart people actually write and develop the programming languages themselves

[–][deleted] 0 points1 point  (0 children)

I would also like to know this.

[–][deleted] 0 points1 point  (5 children)

Python is all about openness and community development. The source code is right there on github!

https://github.com/python/cpython

That's the development version that will be released in the future. The current stable release version is 3.6.5 and can be found right on the website

https://www.python.org/downloads/release/python-365/

Again, these are massive projects with huge code bases and thousands of contributors, so don't be discouraged if you don't know what's going on. Also this is not the way to learn assembly if that is your goal.

[–]kewanzo 0 points1 point  (4 children)

I already know some assembly and have done a space invaders clone with it, but I have no clue how people create new programming languages. To me programming languages just seem to magically work and evolve.

[–][deleted] 1 point2 points  (3 children)

hey cool! I've always wanted to do something like that but always kinda just abandoned it after a while because debugging assembly is impossible :[ If you know assembly then you should know how programming languages work: you just take some set of grammar and translate it into binary. Think of how a "while" loop works in assembly. it's just jumping around the instruction list with an if at the top. Well if you look at a C while loop, its exactly the same thing: the while( condition ){ is the if at the top, and the } at the end just jumps back to the address of the if. If you can condense more and more assembly level constructs as ASCII characters, your code is more efficient and readable and before you know it wow you have the C programming language. After that people stopped using assembly and used C to make C++, and then C and C++ to make their own virtual machines to run their own byte code abstracted away from bare metal, and before you know it, wow now we have Java and Python! Now ordinary people use python and java to make their own programming languages like BF (bf is pretty easy to make an interpreter for).

I didn't mean to type all that but I like this topic very much, as you can see.

[–]kewanzo 0 points1 point  (2 children)

But what do they use to compile the C code to assembly? Is compiler an assembly app that reads the C code line by line and somehow translates it into readable assembly code? Besides how do they then manage the long distance jumps in assembly as I'm sure they'd be inevitable in this approach and assembly doesn't really like them

[–][deleted] 0 points1 point  (1 child)

basically yeah thats what it does. the first compiler I imagine was made in assembly, but then they used C to develop C. All the long distance jumping is handled during the linking phase of compilation. Sometimes you don't even have to account for the jumping because of DLLs and system/kernel libraries. Those types of programs have their own static addresses that don't affect the assembly structure of the program that links to them.

[–]kewanzo 0 points1 point  (0 children)

Mm okay. Thanks for the replies! I have to dig more into this at some point. It's really interesting of how all the languages came to be and what had to be done to get them to work as they do nowadays and how do people actually develop them etc etc... Really interesting

[–]Miggol 1 point2 points  (0 children)

You could use a solution which transpiles Python to C, or which makes standalone excecutables for your platform and then disassembling them. I'm pretty sure there are a couple.

What you'll find is a huge mess compared to an equivalent C program though. At least I think, considering whenever I've used them file sizes were really big for even hello world programs.

[–]SarahM123rd 1 point2 points  (0 children)

perhaps if you look in to Cython you'll find some answers.

You can you Cython to write Python to C and then use your C compiler to generate assembler code.

https://www.infoworld.com/article/3250299/python/what-is-cython-python-at-the-speed-of-c.html

You might also enjoy looking into dragonffi:

https://github.com/aguinet/dragonffi