Specification for implementing a VM
The stack VM works with two stacks, a base stack and a return stack.
Memory layout
0x0000 - SYSTEM
00 - PC - The program counter
01 - SP - The stack pointer. The stack is used to run operators on data.
02 - RSP - The return stack pointer. The return stack is used to store memory addresses.
03 - JUMP_OFFSET
04-10 - CLI ARGS - Write arguments from the command line to these values to use them in a program
0x0010 - IO
10 - INPUT_LENGTH - This stores the length of input written in.
11 - INPUT - Memory after this holds the most recent stdin.
0c0030 - file device
0x00 - REQUEST FS
0x01 - PATH ADDR
0x02 - PATH LEN
0x03 - IN ADDR
FORMAT
file/path.ext;1024;type;created;modified
0x04 - FORMAT OPTIONS - 0b0000111100001111
1 - local path
2 - r
3 - w
4 - execute
5 - list
6 - size
7 - type
8 - creation date
9 - modified date
0x05 - IN LEN
... This memory is reserved for future functionality
0x0100 - ROM - Load the program here
0x0600 - STACK - The stack is here in memory
0x0700 - R_STACK - The return stack is here in memory
... This memory can be used to store variables and data.
0xFFFF - END OF MEMORY
OPERATORS
All operators (except LIT) use postfix notation meaning the operands must be on the
stack before the operator.
For example to add `1` and `2` the syntax is `1 2 ADD`.
The below operators are defined with
`(OPERAND1 OPERAND2 OPERAND3) OPERATOR_NAME OPERATOR_BYTECODE -> (STACK STATE AFTER OPERATOR) ->
ACTION`