GitXplorerGitXplorer
d

coconut

public
29 stars
3 forks
1 issues

Commits

List of commits on branch master.
Unverified
ab3dc8d9d6b9767683d2f1071dad547df82c3f9f

Specify version of CPython for cpython.patch

ddavidmalcolm committed 9 years ago
Unverified
6913271e7a50a71859a6db0b1b2d34ceb63f28ce

Update the README.rst

ddavidmalcolm committed 10 years ago
Unverified
0b7b0c326703104cfeb39209005dd494adb256b2

Fix STORE_ATTR

ddavidmalcolm committed 11 years ago
Unverified
b60dde6036e70935365fd5bbe18be9f56760ddb8

Add a testcase for BUILD_LIST

ddavidmalcolm committed 11 years ago
Unverified
292883c9bf53b237eb0ffbaf463fd4530959cc5d

test_BUILD_SLICE now works

ddavidmalcolm committed 11 years ago
Unverified
c5ef5ae12ac58c53408eefc3e531a540c68a5649

Add PyListObject and PyList_SET_ITEM

ddavidmalcolm committed 11 years ago

README

The README file for this repository.

Experiments towards a method JIT for CPython 3.*

To run, with a suitably patched python3:

PYTHONPATH=. python3 setup.py test

CPython bytecode for a function is parsed and converted to a coconut.bytecode.BytecodeCFG, where the blocks consist of those seen e.g. within Python's peephole.c and the ops are bytecodes. These ops "know" what their stack depths are.

This is then compiled (by coconut.compiler) into a lower-level representation, coconut.ir.IrCFG. The higher-level ops are exploded into one or more blocks per bytecode op, along with various other blocks for e.g. exception handling: even a simple BytecodeCFG typically becomes a fairly complicate IrCFG.

It may be possible to optimize the IrCFG (e.g. type inference, specialization, etc).

This low-level representation can then be sent via pygccjit into libgccjit, converting it to a machine code specialization of that function.

Caveats:

  • under development: lots of FIXMEs in the code
  • generators aren't yet supported

Actually running the built code is a work-in-progress. The approach I'm currently following involves a small patch to CPython, see cpython.patch within the coconut source tree (this was built against CPython 3.3). Approaches that don't require patching CPython are probably preferable.

It's currently a toy: it only implements a subset of the bytecodes, and there are plenty of optimizations it doesn't do e.g. type inference, specialization for given types etc), so the performance isn't an improvement (AIUI we gain a little from eliminating the stack push/pop activity in favor of direct access to specific memory regions, but we lose a little since we're thrashing the instruction cache with new code, vs a single bytecode dispatch loop plus the relatively compact bytecode format).

That said, it's already been useful for finding bugs and design issues with libgccjit (and the Python bindings).

The implementation current attempts to faithfully respect the full dynamic behaviors of the Python interpreter (even the somewhat pathological ones e.g. where something you call can manipulate your stack frame and change the types of variables from under you, or a tp_dealloc hook could toggle whether of not profiling is enabled from within a Py_DECREF). Potentially we could relax that to get speed wins.