4 ms·
Python Meta Circular Interpreter (2019)
- gerardferrer 2y ago[dead]
- albertzeyer 2y agoIn Python, some of the stated use cases, like extracting coverage, extracting the call graph, etc, you can get via tracing already (sys.settrace, https://docs.python.org/3/library/sys.html#sys.settrace https://docs.python.org/3/library/sys.html#sys.settrace). And I would argue, the other stated use cases are maybe interesting to play around with, but nothing you really would want in production (I suppose). Some of the other use cases, you can also achieve by module import hooks and rewriting the AST. (E.g. see how PyTest rewrites the assertion AST to produce nice error messages: https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py https://github.com/pytest-dev/pytest/blob/main/src/_pytest/a...)
- stabbles 2y agothe pytest example screams for @assert as a macro, if only the language supported it
- zem 2y agopytype (https://github.com/google/pytype https://github.com/google/pytype) is based on symbolic interpretation of python bytecode, but with the data stack storing types rather than values. it works very well and has been running in production within google forever. the nice thing about writing a bytecode rather than an AST interpreter is that you can leverage a lot of the work the python compiler does, and work with the resulting simplified code.
- upghost 2y agoEr, to be clear, this just seems to be an interpreter -- not a meta circular interpreter. I don't see any evidence that it is able to evaluate its own definitions or its own API. It doesn't have any tools to handle class definitions, object instantiation, or method invocation, so I'm not sure by what definition of "meta circular" this interpreter fits. Not trying to knock the project. Very cool code! Just don't understand how it qualifies as a "meta circular".
- lihaoyi 2y agoIn contrast, my Metascala JVM (https://github.com/lihaoyi/Metascala https://github.com/lihaoyi/Metascala) is indeed metacircular, and can interpret itself 1 and 2 layers deep (each layer 100x slower than the layer before!)
- Zambyte 2y agoThis is so cool :D thanks for sharing! This sent me back down a small Scala rabbit hole haha
- 082349872349872 2y agoCf https://codewords.recurse.com/issues/seven/dragon-taming-with-tailbiter-a-bytecode-compiler https://codewords.recurse.com/issues/seven/dragon-taming-wit... , a python->bytecode compiler that can compile itself.
- ntrabg 2y ago[flagged]
- albertzeyer 2y agoSomewhat similar: My PyCPython project (https://github.com/albertz/PyCPython https://github.com/albertz/PyCPython), where I wrote a C interpreter in Python, and then tried to interpret CPython. I never really completed this project though.