objvm - Bytecode file format

The header

The header is a 16 byte segment containing the following fields:

The only file subtype is raw, which signifies a raw code+data segment

Raw File Format

The raw file format contains one segment, the code segment. It starts at byte 16 and follows through to the end of the file. In memory, the code sits at the beginning of a buffer where the size of the buffer is specified by header field 3 (Code Size).

The code specifies both “code” and “data” and it is the responsibility of the code to know which is which.

You can optional segment data and code with a JMP header:

; position of the code we want to jump
; to is the size of our data region plus
; the size of this header, which is 0x0a
PUSH CONSTANT size-of-data ; size=3 cp=0
PUSH CONSTANT 0x0a         ; size=3 cp=3
ADD                        ; size=1 cp=6
JMP SPECIAL STACK          ; size=3 cp=7
; cp=10

; data region
0xaa 0xaf 0xcc ...

; code region
POP ; start of code, empty the stack , cp=0x0a+size-of-data
...