3 ms·
Why does RPython exist? It seems to be a subset of Python that can be optimized. Why not use a faster language to write the interpreter, like C? This is not m
by marmada 7y ago
Why does RPython exist? It seems to be a subset of Python that can be optimized.
Why not use a faster language to write the interpreter, like C?
This is not meant to be a hostile question, I am just confused as to why PyPy exists
- tynorf 7y agoThe PyPy interpreter is written in RPython, but is a full Python interpreter with a JIT. When you compile PyPy, it generates C files from RPython sources, which are then compiled with a normal C compiler into a standalone binary. RPython is both a language (a very ill-defined subset of Python... pretty much defined as "the subset of Python accepted by the RPython compiler"), and a tool chain for building interpreters. One benefit of writing an interpreter in RPython is that, with a few hints about the interpreter loop, it can automatically generate a JIT.
- chubot 7y agoBasically because it can be "meta-traced", and C can't (at least not easily). The whole point of the PyPy project is to write a more "abstract" Python interpreter in Python. VMs written in C force you to commit to a lot of implementation details, while PyPy is more abstract and flexible. There's another layer of indirection between the interpreter source and the actual interpreter/JIT compiler you run. See PyPy's approach to virtual machine construction https://scholar.google.com/scholar?cluster=3645326801598147265&hl=en&as_sdt=0,5&sciodt=0,5 https://scholar.google.com/scholar?cluster=36453268015981472... This sentence explains it best: Building implementations of general programming languages, in particular highly dynamic ones, using a classic direct coding approach, is typically a long-winded effort and produces a result that is tailored to a specific platform and where architectural decisions (e.g. about GC) are spread across the code in a pervasive and invasive way. Normal Python and PyPy users should probably pretend that RPython doesn't exist. It's an implementation detail of PyPy. (It has been used by other experimental VMs, but it's not super popular.)