I've been playing Desynced, a base building video game that features programmable behaviors for units. I found that writing my code out in a python-style pseudocode first really helped me write the Desynced code. I decided to try to compile my pseudocode into something Desynced could actually execute, and here is the result.
The Online Version is here
This binder link will open a Jupyter environment with everything ready to go:
Clone this repository (or just grab PythonToDesynced.ipynb). You'll need Jupyter installed at a minimum. I also recommend ASTPretty.
The notebook is designed to build the compilation process up step by step.
Each cell depends on the ones before it, so Run ---> Run All might be a good place to start.
Each step has descriptive text, the actual compilation code for that step, and then a test cell. Edit the python code at each step to see how it flows through the logic.
If you're new to Jupyter, this tutorial might help. Otherwise, "ctrl-enter" to run a cell is all you really need to know.
All of the game's opcodes are in a file called "instructions.lua". The information from this file is what lets the compiler know what functions are available, and to match them up at compilation time.
The compiler emits a JSON string. In order to import it to the game it needs to be serialized and base62 encoded. I haven't ported this functionality yet, but it is available online from the devs here: https://stagegames.github.io/DesyncedJavaScriptUtils/