Finish up parser and assembler with more-or-less complete syntax

Major changes inlude:

* Bit the bullet and now instructions have their length hard-coded
* Move from_utf8 object parsing to be done by their objects (instead of
  a Parser god object)
* A list of AST sections are assembled into an Object using the new
  vm::obj::assemble module.
* Changed the object layout some in the spec, and adjusted code to match
  this.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-09 13:04:56 -05:00
parent 329e61e087
commit e198da5825
19 changed files with 739 additions and 311 deletions

24
vm.md
View File

@@ -436,13 +436,10 @@ the object.
The header is composed of:
* 64 bits - A magic number (0xDEAD_BEA7_BA5E_BA11).
* 16 bits - Version of the file
* 16 bits - The number of sections in the file
* 32 bits - Unused
* 32 bits - Version of the file
* 32 bits - The number of sections in the file
* section descriptions detailed below
Total length: 128 bits
## Sections
The rest of the object is a list of sections. A section's layout is a section header, followed by
@@ -454,23 +451,21 @@ the section contents.
* 0x00 - Data
* 0x10 - Code
* 0xFF - Meta
* 24 bits - Unused
* 32 bits - Checksum of the section
* 64 bits - Length of the section
Total length: 128 bits
### Data section
The data section contains static data that is initialized to some known value.
* 64 bits - load location - where in memory the contents of this section are put.
* 64 bits - section load start - where in memory the content of this section begins
* 64 bits - section load end - where in memory the content of this section ends
### Code section
The code section contains executable code.
* 64 bits - load location - where in memory the contents of this section are put.
* 64 bits - section load start - where in memory the content of this section begins
* 64 bits - section load end - where in memory the content of this section ends
The remaining length of the section is the code itself.
@@ -483,10 +478,9 @@ to other strings. All strings are UTF-8 encoded.
The remaining length of the section are the key-value pairs.
The layout for a key-value pair is the key, followed immediately by the value. The key is always a
string, and the value may be any type of data. A key starts with the length of the string, followed
by the key string itself. A value starts with the length of the data, followed by the value data
itself.
The layout for a key-value pair is the key, followed immediately by the value. The key is a string,
and the value is a 64-bit value. A key starts with the length of the string, followed by the key
string itself. A value is just the 8 bytes of the number.
The meta section should be used to place data that's readable by the VM, but is not used by the
executing program. Data in the meta section is not copied to the program memory.