.
This commit is contained in:
49
doc/BYTECODE
49
doc/BYTECODE
@@ -3,33 +3,34 @@ Bytecode format
|
||||
|
||||
The bytecode file is composed of the following sections:
|
||||
|
||||
* HEADER: 16-byte header
|
||||
[0:3]: Magic
|
||||
[4]: VM format
|
||||
[rest]: Reserved for future use
|
||||
* TABLE_OF_CONTENTS: list of 8 records pointing to each one of the sections
|
||||
Each record (6 bytes):
|
||||
- Pointer to section: 4 bytes
|
||||
- Number of records in section: 2 bytes
|
||||
* [0x0] Constants indexes: pointers to each of the constant locations
|
||||
* Table of 4-byte constant indexes with pointer to constant
|
||||
(counter start at beginning of raw constants)
|
||||
* [0x1] Functions indexes: Pointer to functions within the code
|
||||
[0:3]: function pointer (counter start at the beginning of executable code)
|
||||
[4:5]: number of parameters
|
||||
[6:7]: number of local variables
|
||||
[8:b]: function size
|
||||
* [0x2] Constants raw data
|
||||
* [0x3] Code: executable code
|
||||
* [0x4] Debugging info
|
||||
???
|
||||
* HEADER: 8-byte header
|
||||
[0:3]: Magic
|
||||
[4:5]: Bytecode version
|
||||
[6:7]: Reserved for future use
|
||||
|
||||
* CONSTANTS
|
||||
[0:3]: Code start address
|
||||
[4:7]: Number of constants
|
||||
[...]: Constant index
|
||||
Each constant:
|
||||
[0]: Type (0 = string, 1 = real)
|
||||
if string:
|
||||
[1..4]: string size
|
||||
[...]: string
|
||||
if real
|
||||
[1..4]: real
|
||||
|
||||
* CODE
|
||||
Each function:
|
||||
[0:3] Address of next function
|
||||
[4:5] Number of parameters
|
||||
[6:7] Number of variables
|
||||
[...] Code
|
||||
[0] : Opcode
|
||||
[between 1 and 4] : Operand
|
||||
|
||||
The max file size is 2 Gb.
|
||||
|
||||
## Values can be encoded in the following ways:
|
||||
* The type is defined by the operator.
|
||||
* Encoding varies according to the type:
|
||||
int: use protobuf format
|
||||
float: 4-bit floating point
|
||||
string: int-defined length, followed by the string proper - no null terminator
|
||||
* Constant indexes and function ids are encoded as ints
|
||||
|
||||
Reference in New Issue
Block a user