How does a virtual machine execute bytecode?(Python Virtual Machine 3)
Learn how virtual machines execute bytecode, covering serialization, VM implementation, and the difference between interpretation and JIT compilation.
"Top Python Libraries" publication New Year 20% discount link.
Welcome to the "Python Virtual Machine" Series
In the previous lesson, we introduced how the compiler translates source code into bytecode. In this lesson, we will continue with the example from the previous lesson to implement a simple virtual machine that will run the generated bytecode.
Let's first take a look at the bytecode defined in the previous lesson.
#define BINARY_MUL 20
#define BINARY_DIV 21
#define BINARY_ADD 23
#define BINARY_SUB 24
#define LOAD_CONST 100
At the end of the last lesson, the generated bytecode was [100, 00, 12, 100, 00, 48, 20, 100, 00, 59, 23]. Let's decode this bytecode.
LOAD_CONST 12
LOAD_CONST 48
BINARY_MUL
LOAD_CONST 59
BINARY_ADD