 And will you join me in welcoming our speaker, Stefan Diertel in his talk about the Python interpreter? Yeah, thank you. I think I'm not in the good conference because, in fact, it's just exploring the Ruby interpreter. Just kidding. OK, my name is just Stefan Diertel. In French, Stefan, I come from Belgium, where we have some beers and the Python for them. Of course, I'm a Python lover. Since the first of the day, it's not very important. I'm not a C-Python curdeve, just that. It's just an introduction. And yes, I'm just a small contributor to C-Python and GUNICORN. If you know the project, GUNICORN. And of course, C-Python. I'm a nominated member of the PSF, Python Software Foundation. Of course, we can become a member of the PSF. And since two or three years, I'm a member of the Replython Society, the organizer of the Replython event. Welcome. So just a reminder, I'm just an introduction and I'm not a curdeve. Just a contributor. If you want to contribute, just create some patch and send them. So about the schedule. The schedule will be really simple. We have how to start with C-Python, not how can I write a print statement or just that. Just how can we read the south curve and try to understand it. We will have a small question to see how to create what's the result of Python of this expression, two more two, and a small summary. So how can we start? That's a good question, sorry. Maybe with the developer's guide. In fact, when you want to start to develop with C-Python, that was my case at Pycon in Montreal, sometimes we can find some sprints. There is a sprints on C-Python and that was my case where I came with my bag and my laptop and I just asked to some developers, hello, I would like to help you with C-Python. First thing, so can you read the developer's guide, the dev guide in short? Yeah, of course, I can. In this document, it's just a small document, sorry. Here, please. Opla. No, it's not the direct, it's just the developer's guide. If you want to start to develop to hack on C-Python, you can read this documentation. You will read how to make a clone of the repository, how to become a core dev, how to, for example, you want to add a new keyword in the syntax of Python. There is a small checklist, in fact, a checklist with 20 points to verify, okay? Just that. Yeah, how to become a, sorry. The dev guide is really interesting because we have some explanation about this, the tracker, the build-ups, the Python developer pack, the peps, and you can read everything. So that's really interesting because you have the getting started, how to compile Python. How can you help, for example, with the documentation, with the source code, or with everything? How to write a test and just how to run the test on several platforms. Okay, so come back to the doc, my presentation. So the dev guide will explain the quickster, the grammar, how to change the syntax, and just the design of C-Python compiler. Yes, we have the source code in Python. There will be the lexer, the parser, the peep-huller, and just the PyCut at the end with the virtual machine. So you can find the documentation as this location. When you start, okay, I'm sorry I have a question. How can I, not for you, but for me, when you go in a sprint, I have an issue, I have this issue, how can I fix it? I don't have time, but you can send a message to this mailing list, Python mentors. Python mentors is just a big mailing list program where you can send a request and you will get some response from Guido van Roosam, Brett Kenan, David Hermer, Victor Steiner, myself, and of course, other developers. That's really interesting because you can discuss about the solution for your issues, okay? In my case, I wanted to modify the interpreter, just the lexer, because I found an issue in error. And when I send my message, my mail, I receive a response from Guido where he told me, sorry, but in fact, in Python, there is no one parser, but two parsers for the descent tax, okay? So, of course, you want to start, where to start? You have the mailing list. With the mailing list, we have the announce, the bugs announce. In fact, when you create new bugs in the bug tracker of Python, you have a mailing list for that. You can follow it just to receive some notifications. When you want to discuss about a bug, you have one mailing list. This mailing list is just mapped with the bug tracker we've run up. If you need some help, you have the mentorship mailing list. If you want to discuss about one big point in the core of Python, you have the mailing list, the Python dev. If you want to create, if you have an awesome ID, for example, the Fat Python project, to try to improve the performance of Python, you can try to submit something on the mailing list, the Python IDs mailing list, and you will see if you have a good result, a good feedback or not. In this case, that was not. Yes, today we discuss about the performance with a sync IO, with a UV loop, and the rest. If you're interested by the speed of Python, you can discuss on this mailing list. That's very useful. It's a mailing list where we discuss about the internal parts of Python, okay? Not about how to use the best, what's the best practice for the performance. Okay. So, how to contribute? Firstly, that's really simple. You go on the bugs.python.hoc website, and you create a user account. With this user account, you have to sign a contributor agreement with the PSF, because the south code is the owner or the south code is the PSF, okay? Looking for one stuff. Yeah, sorry, excuse me. So, the step two, just how can I prove the Python? Firstly, you have the documentation. Please, we have a good documentation, we have some missing tutorials. For example, a sync IO. We have the documentation about a sync IO, but we don't have a tutorial about that. How can we start with a sync IO? How can we use it and the rest? We have a reference in the documentation. If you want to contribute, that's the right place. Yes, of course, you can create some issues, fill them, and if you find a bug, of course. If you want a feature, a new feature, I'm going to show a feature, a small feature. We need some reviewers, yeah. If you look at the south code of Python, per day, we only have 10 commits per day. It's not really big. If you want to contribute, just review the patches and we will be happy, okay? You will receive a good message, thank you, because that's really interesting and important for us. Sometimes you can create a patch, propose it, just create an issue, propose a patch, and rest. Yes, and sometimes that's really interesting because you have created your patch and you can wait for six months before a review because we have some two or three reviewers. If you want to contribute, it's a good place at a good time. Yes, of course, the process is really slow. I have some issues, open issues, and it happens in two years. Sometimes that's really difficult for me because, but why my patch is not melt in the south code? We don't have time, sorry. Yeah, the last point, just we try to migrate Python to GitHub, bye bye, make sure you have. Yes, yes, yes, you can create account, you can use your hackathon on GitHub and just create a pull request. I prefer that. Usually when you try to create a patch, firstly, you don't know the branch, you create your patch and you create a diff. This diff file, you will send it, you will upload it to the bug tracker. If there is a new version, your patch is just outdated. So, okay, and now what can we do? Just firstly, when you start, maybe we can try to find the directories of Python and try to understand them. In fact, how can we find information? Firstly, with the documentation, the doc directory, just the manual of Python, where you will find the syntax, the reference of the language, the reference of the library, the standard library. You can buy some books. David Beasley or Dugan Mann have some good books. It's a good reference. The grammar directory is just the grammar, where the grammar is defined. It's just a text file, does that. If you want to modify it, you have the grammar directory and the parser directory because if you had a new keyword, you have to lax them and just improve the parser and the ST, and the byte code, of course. You have the lib directory just for the Python library, Python models. For example, you have the telnet lib. If you want to modify it, it's just in this directory. For the models directory, there's a C part of Python. For the object, for example, you want to learn the implementation of the dictionary of Python. You can go into the object directory, okay? Hello, then. We have the programs directory. It's just the Python executable, yeah? Because Python is a small executable. And Python is a library. You can load the library if you want to embed the Python in your software. Okay, about the documentation, we have the reference for the language, the reference for the library, the reference for the C API. If you want to learn, you can read the documentation. And sincerely, we want a small tutorial. Who is an expert of Async.io? Okay, you have a new fix for you. So, just, yes? Another guy, yeah? No? Oh, shit. No, it's really boring because you have Victor Stiner and Andrew, they are discussing on the table near the lunch and they try to improve the documentation about Async.io. They want to create a tutorial. So, I have one question. Just one. Really, just one. What's the result of this expression? Okay, four. It's not very difficult. But for me, I don't want to know this value. I prefer to see the common line, the lexer, the parser, the interpreter, the compiler, everything about that. And when you start to modify Python, okay, you have the Python part, but I'm just interested by the C part. When you execute the common line, you have that. Firstly, we have the common line, of course. The common line is just executed by the python.c file. The python.c file will load the Python library. You can try on Windows, OSX, or just on Linux, you will get the same result. Okay? If you want to embed Python with your software because you have developed a software in C++, just use the Python library. Okay, so libpythons, one so labor, I don't know. When you will execute the source code, automatically, we will initialize a Cpyton and we try to load some models and read the source code, convert it to an ST and execute it. Okay? So, the lexer. The lexer is just defined, if you are interested, of course, is the topic of this talk. You have the tokenizer.c. The tokenizer will take a string, a Python string, we convert in some keyword, some expression. I know, in token. You have the parse talk and the tokenize. That's good. For example, we take x equals two plus two. We have this result. Where is my mouse? We have six token. Each token has one type and value. Okay? You can learn with that if you want to use it for disassembly, if you want to disassemble Python. Yeah. You know that with Python 3.5, we have two new keywords, a thing, a wait. In fact, it's not a real keyword in Python. It's just in function of the definition of your code, a keyword, but not. The parser is really smart about that. If you will make an example, a thing equal to, in this case, it's just a name, not a keyword. If we try, I don't have my code. No, sorry. Yes, if we check, it's not in the keyword list of Python. It's just a name. So, know about the parser. You have your tokens. You can convert them in AST. AST is just that. Okay? For this expression, x equal to more two, we have a model with a body, in the body, we have an equal, and the equal is just name with an ID, equal x, and we have the hard, we'll have two numbers. For the compiler, you have the AST. I would like to convert it to the byte code. Just execute this source code. Compile, you have your tree, the AST, and you can convert it to the byte code. With this model, we can see the byte code. If you want more information, you can read this documentation, this path. Yeah, I know. Okay, for the byte code, in the C part, we have a definition of the byte, yeah, definition. The byte code is just a compact numeric code. One byte, not a word, just one byte. The byte code is just portable, and when byte code is just followed by one parameter or by many parameters. Yes, it's just used by the virtual machine, in this case, a software interpreter. For the byte code, when we have this empty file and try to convert it, we will receive a byte code. The byte code is just nothing, load comes zero, and return the value, just an empty. When you create a new file, an empty file, the interpreter will execute it. If you try with this function and try to convert it, you will get the result of the byte code, okay? You have the byte code. After that, we try to optimize the byte code with the PIP holder. For example, we have x equal two more two. The system will convert it to four, okay? He doesn't want to try to add two more two. Example, another example. If one print LO, we have this byte code. If zero, there's nothing. We remove the dead code, okay? Via the PIP holder. So, no, we have the PIP holder, we have the byte code, how to interpret it. The interpreter is just a virtual stack machine. This virtual machine will execute the byte code. It's just a stack. We push an element, we pop it. We execute something, we pop it, okay? So, a small example where we try to create a small interpreter. Maybe there is a bug, I didn't test it. But an interpreter is just, we have a stack, a pointer on the instruction, the current instruction. And we run, we read each instruction. In this case, I just create a small byte code. Example, firstly, I try to push five, push again, three, and push them. And the rest is just add, add, and pop. When I'm going to read the source code, the byte code via the interpreter, I push five in the stack, push three, push 10. Just add, I will pop the two last elements, and I get 13. After that, I will add another value, take the second, the two value on the stack, and I get 18. Just add, I can get the pop. I will empty the stack. So, do you remember the distinction? Just add, we have the byte code, okay? And, yeah, we have the byte code, just add. And now we have the C part of the byte executed by the virtual machine when you execute the byte code. For example, we have the load fast here in the example. The load fast will execute this code. Just, okay, I'm going to push something in the stack of the memory of Python, in the stack frame, in the frame. For the load scones, I try to get the value from the constants in the global, sorry, just in the locales, and try to use them and just push in the stack, okay? When I try to use the binary add, the hopcode, the system will check if it's a string, if not a string, okay, maybe a number. If it's a string, we will create a concatenation, and if it's a number, we just add one, two, one and one. And after that, just push the result on the stack. For the store fast, we have the source code of Python, okay? So, for the rest, and just for the fun, have you read the source code of C Python? No, I think it's sleeping, yeah, I'm sleeping. In the source code of Python, we have the evaluation. That's our time, for me, it's okay. We have the dysfunction, PyHealthValue by frame X, the system will try to read the source code and evaluate the source code. The main function is just this function, PyHealthValue, Everframe, a function with 2,000 lines of code, just one function, okay? And there is a hack in the function, because sometimes, some compiler, C compiler, does not support a feature, and we create the default, well, in the default, there is another switch for the next byte code, okay? So, I have a summary, the summary is just weird to improve the documentation, review some patch, and try to improve the issues if you have any problem with Python, and just that. That's really fun. No, certainly, yeah, I like, because when you put, it's on my key, because I'm not a core developer, but I try to have, I am a contributor to C Python. Yes, good, good for you, Ged. No, a small example, I wanted to show you about an issue, not an issue, a small functionality for me. Come on, where are you? No, bye-bye, okay, come on. Adjust, modify, C Python. Just with a small patch. And sometimes, I want to learn the byte code, okay? And I would like to create a small debugger where you see on the left, the source code, the Python source code, and on the right, the byte code. Okay, I would like to create that. Here's my example, okay? It's the last version of Python, the version of today. If you print, hello, there is just hello. There's a feature in Python, and you don't know, okay? If you want to see the byte code of C Python, this feature is in the source code of Python since two or three years. It's not you, okay? If you define L-trust, you will get the byte code and the value of the argument, okay? So, what's the next point? Yeah, I know, two minutes. Where's my, sorry, my mouse? Yeah, that's all. Thank you very much, Tiffan. Can I just say it's absolutely wonderful to know that someone can go from not being a contributor to going to a conference and becoming one. So three years ago, Tiffan could not have given that talk and now he really is an actual contributor to Python. Anyone can do it. Not that I'm saying, Tiffan isn't a wonderful person. But it makes it real, you know? So is there a quick question before we move on to the next talk? Go on. One question, you can have the honor of being the person that asked that question. It will make you special. Let's do it. Yes? Is the documentation available in different languages and is help needed in those translations? I'm sorry? The documentation, is it available in different languages like in French, in Italian, Spanish, or is it only in English? No, the documentation is just in English, of course, because it deserves France. But I know that in France, there is a group, the FP, they try to translate in French. No, if you want, you can download the documentation, of course, it's just a clone of the repository, try to translate it. And in the last version of, last, since two or three years, you have a feature in things where you can translate, you can create a French or Italian part of the documentation. Okay? All right, thank you. Join me in thanking Stefan once again. Thank you very much. Thank you.