## 2 State of the Art
### Zerynth Virtual Machine  
The Zerynth Virtual Machine [15] is a powerful platform designed to execute Python 3.4 scripts on embedded systems, offering a high level of code reusability across different boards. It supports various high-level Python features, including modules, classes, multi-tasking, callbacks, timers, and exceptions, as well as hardware-related functions such as interrupts, PWM, and digital I/O. The VM is built on top of real-time operating systems (RTOS), such as CHIBIOS or FreeRTOS, utilizing an abstraction layer called VOSAL (Virtual Machine Operating System Abstraction Layer). This architecture allows for easy porting to different RTOS platforms and comprises several key components [15].  
The core functionality of this platform, as presented in Figure 1, is provided by its bytecode interpreter, which executes Python bytecode that the Zerynth compiler generates from Python scripts [16]. These bytecode objects include instructions and metadata necessary for managing memory and handling errors, with each opcode represented by one byte and optional arguments of up to four bytes. The interpreter processes these instructions sequentially within the active thread until a stop instruction is encountered, offering a design that closely resembles Python but with opcodes tailored for embedded systems. To ensure thread safety during opcode execution, the Global Interpreter Lock (GIL) allows only one Python thread to execute bytecode at any moment, releasing control to other threads when a thread either sleeps or its quantum time expires, thus preventing race conditions.  
Memory management within the VM is handled by the garbage collector (GC), which periodically scans for unused objects and removes them through a mark-and-sweep algorithm, thereby optimizing memory usage and simplifying lifecycle management. The interrupt thread within Zerynth is a high-priority thread that executes bytecode triggered by hardware interrupts, allowing for typical memory allocation but requiring minimal  
Figure 1: Zerynth virtual machine architecture block diagram (adapted from [15]).  
processing time to prevent delays in handling other interrupts. The Virtual Machine Operating System Abstraction Layer (VOSAL) provides essential abstraction for interfacing with the RTOS, including functions for multitasking structures like threads and semaphores, supporting the hybrid execution of C and Python code and enhancing portability across RTOS platforms. Additionally, the Virtual Machine Hardware Abstraction Layer (VHAL) acts as an interface for controlling microcontroller peripherals, such as serial ports, SPI, I2C, ADC, and PWM, with specific implementations for each microcontroller family, ensuring a consistent hardware API regardless of the underlying hardware [15].  
To optimize the virtual machine for embedded systems, certain Python features have been modified or removed. For instance, integer values are implemented as 32-bit signed numbers, object sizes are reduced, and lists and dictionaries are limited to 65,536 elements. Compilation is moved out of the language, and features like closures, generators, and decorators are either removed or added modularly. True multithreading with priorities has been introduced, with each Zerynth thread functioning as a native thread of the real-time operating system [15].