A story about modifying Python and adding functions

There is "Exploring large-scale software" as an experiment that can be selected by the Department of Electronic and Information Engineering / Department of Electrical and Electronic Engineering (eeic), Faculty of Engineering, University of Tokyo. This is an improvement / extension of a large-scale program published as OSS (open source software), and it is difficult to grasp the whole picture, which cannot be touched by a small-scale program that is usually handled in class. It's about learning how to handle programs. We decided to explore Python, which we are familiar with in class.

Link

-** Overview (a story of modifying Python and adding functions) ** ← Imma here -Add C-like grammar to Python
・ As a logical operator&&Or||Or!To add
-Make logical values True and False correspond to true and false
・ Support not only else if but also else if -Add auto-indent function to Python -(Bonus) Add unless statement to Python

environment

Preparation

First, create a working directory (here ~ / cpython). Duplicate the repository from Python3.10 (cpython) on Github using git clone.

terminal


$ mkdir cpython
$ cd cpython
$ git clone https://github.com/python/cpython

Build

Create a Makefile with configure. At this time, use the --prefix option to finally decide where to place the program (here ~ / python-install). You can also add -O0 to the environment variable CFLAGS to lower the optimization level, and add -g to include the" debug symbol "in the executable file. This allows you to use gdb to follow the behavior of your program line by line.

Once you have created a Makefile with configure, compile and install it with make and make install.

terminal


$ CFLAGS="-g -O0" ./configure --prefix=/home/[username]/python-install/
$ make 
$ make install

This completes the build, and you can start python by running ~ / python-install / bin / python3. If you change the code, you need to do make clean and then make.

Track with debugger

Start Emacs and go to ~ / python-install / bin / with the M-x shell command. Once I was able to move it, I hit M-x gud-gdb and gdb --fullname python3 to start gdb and used it to track the program.

Reference material

** Exploring large-scale software **

--This is the homepage of the experiment.

** Official CPython documentation (Changing CPython ’s Grammar) ** ** Official CPython documentation (Design of CPython ’s Compiler) **

--It describes which files should be changed when adding the syntax to python.

** GNU readline official documentation **

--This is the document referred to in Adding auto-indent function to Python.

** Introduction to modifying Python **

-This is an article by an EEIC senior who added an unless statement to Python. When modifying Python, I referred to what to start with.

Recommended Posts

A story about modifying Python and adding functions
A story about Python pop and append
About python dict and sorted functions
A story about adding a REST API to a daemon made with Python
A Java programmer studied Python. (About functions (methods))
[Python] Memo about functions
A story about Go's global variables and scope
A story about running Python on PHP on Heroku
A story about making 3D space recognition with Python
A story about making Hanon-like sheet music with Python
A story about trying a (Golang +) Python monorepo with Bazel
A story about kindergartens, nursery schools, and children's gardens
About creating and modifying custom themes for Python IDLE
About python objects and classes
About Python variables and objects
About Python, len () and randint ()
About Python datetime and timezone
A memorandum about correlation [Python]
A memorandum about Python mock
About Python and regular expressions
Python 3 sorted and comparison functions
About Python and os operations
Python higher-order functions and comprehensions
Python # About reference and copy
About Python sort () and reverse ()
A note about [python] __debug__
A story about how to specify a relative path in python.
A story about an amateur making a breakout with python (kivy) ②
A story about an amateur making a breakout with python (kivy) ①
A story about trying to implement a private variable in Python.
A story about a python beginner stuck with No module named'http.server'
Python a + = b and a = a + b are different
The story of Python and the story of NaN
About installing Pwntools and Python2 series
[python] Manage functions in a list
A refreshing story about Python's Slice
Python: A Note About Classes 1 "Abstract"
A sloppy story about Python's Slice
About dtypes in Python and Cython
About Python pickle (cPickle) and marshal
[Python] About Executor and Future classes
About Python, from and import, as
A story about using Python's reduce
Strange and horrifying Python error story
A note about mock (Python mock library)
[Python3] I made a decorator that declares undefined functions and methods.
A little more about references ~ Using Python and Java as examples ~
A story about developing a soft type with Firestore + Python + OpenAPI + Typescript
A story about everything from data collection to AI development and Web application release in Python (3. AI development)
A story about trying to run JavaScripthon on Windows and giving up.
A story about remodeling Lubuntu into a Chromebook
A story about a beginner making a VTuber notification bot from scratch in Python
A story connecting Slack and google spreadsheets
A story about automating online mahjong (Mahjong Soul) with OpenCV and machine learning
A story about my new study of Python after 3 years of MATLAB experience
A Java programmer studied Python. (About type)
A story about machine learning with Kyasuket
A memo with Python2.7 and Python3 on CentOS
Connect a lot of Python or and and
Python functions
A story about trying to connect to MySQL using Heroku and giving up