A simple forth dialect prototype with its VM, just for experimental purpose.
* You can continue to extend the function of this VM if you will.
Can only be used under Linux X86-64.
make # the binary will be compiled into the "build" folder.
- REPL:
➜ Forthress git:(master) ✗ ./build/vm
> 1
> 2
> +
> .S
3
> exit
- Interpreter:
➜ Forthress git:(master) ✗ ./build/vm forth_discr.fth
-8
- Native Word:
Word provided by the VM.
- Colon Word:
Word constituted by a series of Native Words (need docol to control the flow).
Format: prologue: xt_docol
, epilogue: xt_ret
;
- Control Flow:
Execution Sequences (Native Words):
+------+ +------+ | word | -> | word | ... +------+ +------+ ^ ^ w pc
Execution Sequences (Colon Words):
+------+ +------+ | word | -> | word | ... +------+ +------+ | ^ |pc (saved in rstack)+------+ +------+ | | word | -> | word | ... | +------+ +------+ | ^ ^ | w pc (new position)
- Word:
|----------------------> header (exclude private word) <---------------------| +---------------------+----------------+-----------------+---------------------+ | next word addr (dq) | label (string) | (reserved byte) | implementation addr | +---------------------+----------------+-----------------+---------------------+
- Dictionary:
(head) (tail) (.bss) +------+ +------+ +------+ +------+ +--------------------+ | word | -> | word | ... | word | -> | word | -> | dynamic_colon_stub | -> (dynamic words) +------+ +------+ +------+ +------+ +--------------------+ +--------------------+ +-------------------------------------+ ... | dynamic_colon_stub | ... => | next effective address (dq) | words | ... +--------------------+ +-------------------------------------+ |--------------|--------^
- Opcode (For inner interpreter, saving the operation and immediates of each dynamic colon word):
+----------------+-------------------+ | opcode (qword) | immediate (qword) | +----------------+-------------------+