Fixed bug with VM assigning wrong opcode

- Fixed a bug with VM assigning wrong opcode. After doing a little digging into the Iridium 1 source code (skipping to the next part of the tutorial), I discovered I had to have implement from() function in both directions. I.e. the Opcode outputs integer and integer outputs an Opcode. Derp moment in retrospective since I already had it done for the former but this is a learning experience.
- Moved Opcode enum to assembler module.
This commit is contained in:
Anthony Foxclaw 2020-02-08 15:14:37 -05:00
parent afb68e46b3
commit 853188b010
8 changed files with 92 additions and 66 deletions

View file

@ -21,7 +21,7 @@ impl AssemblerInstruction {
match self.opcode.to_owned() {
Token::Opcode { code } => match code {
_ => {
results.push(code as u8);
results.push(code.into());
}
},
_ => {
@ -30,6 +30,7 @@ impl AssemblerInstruction {
}
};
for operand in vec![&self.op1, &self.op2, &self.op3] {
match operand {
Some(t) => AssemblerInstruction::extract_operand(t, &mut results),
@ -81,7 +82,7 @@ named!(pub instruction_one<CompleteStr, AssemblerInstruction>,
#[cfg(test)]
mod instruction_parser_test {
use super::*;
use crate::instruction::Opcode;
use crate::assembler::Opcode;
#[test]
fn test_parse_instruction_form_one() {