|
The program entry, main() routine, is in "main.c" module. Most of the preparation are done in "startup.c" under caml_main() routine that includes check the validity of bytecode, initialize minor and major heaps, extract the code segment and construct global data. The information about sizes and starting addresses of each section are kept at the end of bytecode called trail section. It contains the magic number for verifying that it is a OCaml bytecode. The other information in the trial section is extracted by read_trailer() routine. The code is kept in global start_code variable for later interpreter.
Other preparation such as the heap for memory allocation and garbage collector is initialized through init_gc() routine in "minor.c". The automatic memory management is implemented in "gc_ctrl.c", "minor_gc.c", "major_gc.c" and "freelist.c".
Once all preparation is done, code segment will
be interpreted in "interp.c" through interprete() routine.
The available instructions are listed in "instruction.h"
Finally, before exiting, the memory gets clean up in the clean_up()
routine inside "startup.c" .
The original interpreter was designed to execute
one bytecode at a time. Although new session can be started, they
are treated as two separate processes with separate address space.
One goal of this project is to make the interpreter multithreaded which
allows more than one bytecode to be executed in the same address space
simultaneously.