A.Virtual Execution Environment VMcontext
B.Critical Data VMdata & VMarray
The Dispatcher serves as the scheduling nucleus of the virtual interpreter, with its pivotal role illustrated in the diagram above. Initially, it reads and decodes bytecode from VMdata, with the sequencing of bytecode retrieval primarily governed by a variable known as the VPC (Program Counter). Subsequently, it decodes and schedules the appropriate interpretation Handler programs based on indices for execution. Upon completion, control returns to the Dispatcher, and the aforementioned process continues until the decoding of all bytecode is finalized, thereby concluding the loop. Its primary execution logic relies on VMdata to guide the scheduling of the relevant Handlers to restore the original program's functionality. Tailored to the functional requirements, the design utilizes loops in conjunction with selection structures to implement this scheduling process, as exemplified in the code snippet shown below.
D.Interpret assembly Handlers
The Interpreter Assembly is a crucial component for restoring bytecode semantics, as illustrated in the first figure. Once the Dispatcher decodes the bytecode, it invokes the relevant interpretation Handlers to execute computational operations. Virtual instructions can be categorized into parameterized and non-parameterized types. For instructions with parameters, the corresponding interpretation Handlers retrieve values from VMcontext based on the parameters read from VMdata. For instructions without parameters, values are directly retrieved from the top of the stack to perform the relevant operations. The results of these operations encompass the restoration and manifestation of code functionality, thereby affecting the values stored in VMcontext. Consequently, there exists an interactive relationship between the interpretation Handlers and the virtual execution environment.
Within the '.wasm' file, there may be additional environmental variables introduced. During instantiation, memory space and variable mapping tables need initialization. Moreover, when loading the WebAssembly module, variable parameters can also be passed to it. All these operations are handled through the glue code.