<!--
.. title: A JIT for Deterministic Automata using PeachPy
.. slug: a-jit-for-deterministic-automata-using-peachpy
.. date: 2023-07-06 16:38:08 UTC+02:00
.. tags: python, jit, automata
.. category: 
.. link: 
.. description: 
.. type: text
-->

For a lesson about JITs in a colleague's compiler course I wrote a small
just-in-time compiler for deterministic finite automata in Python, using
PeachPy. I planned to write a complete blog post about them, but it doesn't
seem to quite be happening, so below is the code. It has a few comments at
least.

The idea is to show a few of the typical things a JIT can do that a static
compiler can't:
- switching between interpreter and compiled code
- profiling to find out which part of the program are executed most commonly
- deoptimization back to the interpreter
- patching of existing code if new code is added

Here's the [code](https://gist.github.com/cfbolz/b8ca9e37b3fcc4ba653b0d7f8be63f11):

<script src="https://gist.github.com/cfbolz/b8ca9e37b3fcc4ba653b0d7f8be63f11.js"></script>

