BC0 File Parser
A bc0 file is divided into several sections:
Magic Number Starting with
C0 C0 FF EE, the magic number tells us that this file is generated by aCC0compiler. Some other "meta-data" like version number etc. are also included in this section.Integer Pool Inside the
bc0instructions, we can push small values ranging from0x00to0xFFdirectly into the operand stack usingBIPUSHinstruction. However, to use larger integer constants (literals that written in the code like0xDEADBEEF), we need to store them separately in a Int Pool.String Pool String literals are stored in a specific memory section and will be loaded when the VM initializes. During the runtime, these strings will be loaded into the operand stack according to the instructions. This specific section is called the String Pool.
Functions The name of function and the bytecode instructions.
Native Pool The native functions that will be needed in this program will be logged here.
The parser will convert the bc0 raw string into a data structure like this:
type C0ByteCode = {
version: number;
/* Int Constant Pool */
intCount: number;
intPool: Int32Array;
/* String Constant Pool */
stringCount: number;
stringPool: Uint8Array;
/* Function Pool */
functionCount: number;
functionPool: C0Function[];
/* Native Functions */
nativeCount: number;
nativePool: (C0Native|undefined)[];
};Last updated