## 3 Materials and Methods
### Language Concepts and Extensions
#### 3.2.3. Bytecode Serialization  
The general structure of the serialization format identifies each value with a type identifier, specifying the data type being serialized, such as numbers, Boolean values, or objects. Following this identifier is the value content, serialized according to its type. For example, primitive types like numbers are serialized as four-byte float values, while Boolean values are serialized as single bytes. Special types like nil, empty, and undefined are represented solely by their type identifier, as no additional data are associated with them. Strings are handled with particular attention: the length of each string is recorded as a two-byte integer, followed by the character sequence of the specified length. Each string is null-terminated to ensure it can be accurately reconstructed during deserialization. The serialization of instruction sets is more complex and includes several components. Each instruction set includes a line count, serialized as a short integer, followed by the lines themselves, represented by pairs of two-byte values indicating the start and end of each in the instruction array. Additionally, the instruction set includes an instruction count, serialized as a two-byte integer, with the instructions themselves serialized as a byte array. A key part of instruction set serialization is the value set, which begins with a count of values, followed by the serialized values themselves. This structure allows the easy loading of instruction sets with the corresponding constants within the function, using matching indexes in the instructions and value set. Objects are serialized with an object type identifier indicating the type, such as functions, lists, or object instances. Each object type has its own serialization requirements. For example, function objects include additional fields such as argument count and enclosed values, serialized as bytes, with their names serialized as strings. Lists have a count of elements and serialized values, while objects contain field counts and pairs of serialized keys and values. Custom serialization methods can be defined for other objects, such as the \"Mersenne Twister\", which consists of a seed value serialized as an eight-byte integer. Error handling during deserialization is implemented to ensure robustness. If the end of the content is reached unexpectedly, an error message is displayed, followed by a reset function call to address the error. This mechanism helps maintain the integrity of the deserialization process, preventing incomplete or corrupted data from being reconstructed and loaded onto the virtual machine. Deserialization functions in the code are designed to reverse the serialization process, reading the binary content back into the program's data structures. Each data type is read according to its serialization format, with corresponding structures created and populated with deserialized values. This detailed and structured approach to serialization and deserialization ensures that programs and data can be accurately and efficiently stored and restored, preserving their state and functionality across different executions and environments. Figure 9 illustrates the serialization process of a created program, beginning from the function and sequentially passing through its components, recursively serializing all registered values. After program compilation, all data are placed within the main function, which is passed to the serialization function. The main function alone lacks metadata on argument count, enclosed values, and names, as it is implicitly created by the compiler without arguments or a name. After these four values, the process moves to the instruction set, where the line array and instruction offsets are processed first, followed by the array of instructions. To ensure safe serialization, the array length is specified first, followed by its elements, as some arrays, such as the instruction array, cannot be null-terminated due to 0 being a valid virtual machine instruction.