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

View File

@@ -2,13 +2,14 @@ macro_rules! instructions {
{
$($variant:ident = $value:expr),* $(,)?
} => {
pub type InstOp = u16;
$(
pub const $variant: InstOp = $value;
)*
};
}
pub type InstOp = u16;
instructions! {
ADD = 0x0000,
@@ -37,3 +38,37 @@ instructions! {
HALT = 0xF000,
NOP = 0xF001,
}
pub fn inst_len(op: InstOp) -> usize {
match op {
// 2 bytes
INEG
| INV
| NOT
| HALT
| NOP => 2,
// 4 bytes
ADD
| MUL
| DIV
| MOD
| AND
| OR
| XOR
| SHL
| SHR
| CMPEQ
| CMPLT
| JMP
| JZ
| JNZ
| LOAD
| REGCOPY
| MEMCOPY
| STORE => 4,
// Immediates - 4+ bytes
STOREIMM64 => 16,
STOREIMM32 => 8,
_ => panic!("unknown instruction op 0x{:04x}", op),
}
}