7

I'm working on a documentation API for Python I'm calling Python Docs, and I've noticed that almost all built-ins can't be accessed by my static analysis suite, because they are almost exclusively C modules. As far as I can remember, I can't think of any exceptions to this rule.

The first part of my question is simply, does being a built-in module presuppose being a C-extension in CPython?

Assuming that this might be the case, I compiled a fresh pypy runtime and tried using my project against with the built-ins from pypy. I was surprised to find that this didn't work either.

Why aren't PyPy modules available AST objects if they're pure Python? Is this a side-effect of PyPy being hosted on a JIT?

mvanveen
  • 9,754
  • 8
  • 33
  • 42
  • As a general rule, primitive operations and types in a high level language have to be "baked in" to the language implementation, because if they weren't magically provided somehow there would be no way to implement them within the high level language. e.g. Try implementing `int` in Python without using the built-in support. – Ben Apr 03 '12 at 07:15

1 Answers1

4

PyPy is two parts -- the Python interpreter and the translation toolchain.

The translation toolchain translates / "compiles" the interpreter from RPython into machine code.

So although PyPy is written in a language that is a subset of Python, it's not Python when you use it.

You should read the compiler section of the PyPy Parser docs and this blog post that describes that the AST features in PyPy mirror those in CPython.

agf
  • 171,228
  • 44
  • 289
  • 238
  • 2
    @mvanveen What is your first question exactly -- are all CPython built-in functions and types implemented in C (yes), or are all standard library modules included with CPython implemented in C (no, many are implemented in Python)? Because I'm not sure what you mean by "built-in module". – agf Mar 30 '12 at 06:50
  • The former. Thanks for the answer! – mvanveen Mar 30 '12 at 07:56