Add set_catch, unset_catch instructions

This commit is contained in:
Andrew Morris
2023-03-23 09:35:33 +11:00
parent 56f6ce5922
commit 337c5c5296
11 changed files with 50 additions and 14 deletions

View File

@@ -285,6 +285,8 @@ pub enum Instruction {
Throw(Value),
Import(Value, Register),
ImportStar(Value, Register),
SetCatch(LabelRef, Register),
UnsetCatch,
}
impl std::fmt::Display for Instruction {
@@ -421,6 +423,10 @@ impl std::fmt::Display for Instruction {
Instruction::ImportStar(value, register) => {
write!(f, "import* {} {}", value, register)
}
Instruction::SetCatch(label, register) => {
write!(f, "set_catch {} {}", label, register)
}
Instruction::UnsetCatch => write!(f, "unset_catch"),
}
}
}
@@ -478,6 +484,8 @@ impl Instruction {
Throw(..) => InstructionByte::Throw,
Import(..) => InstructionByte::Import,
ImportStar(..) => InstructionByte::ImportStar,
SetCatch(..) => InstructionByte::SetCatch,
UnsetCatch => InstructionByte::UnsetCatch,
}
}
}

View File

@@ -160,7 +160,7 @@ impl Assembler {
self.output.push(instruction.byte() as u8);
match instruction {
End => {}
End | UnsetCatch => {}
OpInc(dst) | OpDec(dst) => {
self.register(dst);
}
@@ -226,6 +226,10 @@ impl Assembler {
Throw(value) => {
self.value(value);
}
SetCatch(label_ref, register) => {
self.label_ref(label_ref);
self.register(register);
}
}
}

View File

@@ -222,6 +222,8 @@ impl<'a> AssemblyParser<'a> {
("throw", InstructionByte::Throw),
("import", InstructionByte::Import),
("import*", InstructionByte::ImportStar),
("set_catch", InstructionByte::SetCatch),
("unset_catch", InstructionByte::UnsetCatch),
]);
for (word, instruction) in instruction_word_map {
@@ -665,6 +667,8 @@ impl<'a> AssemblyParser<'a> {
Throw => Instruction::Throw(self.assemble_value()),
Import => Instruction::Import(self.assemble_value(), self.assemble_register()),
ImportStar => Instruction::ImportStar(self.assemble_value(), self.assemble_register()),
SetCatch => Instruction::SetCatch(self.assemble_label_read(), self.assemble_register()),
UnsetCatch => Instruction::UnsetCatch,
}
}

View File

@@ -234,8 +234,7 @@ where
use Instruction::*;
match instruction {
End => {}
OpInc(_) | OpDec(_) => {}
End | UnsetCatch | OpInc(..) | OpDec(..) | Jmp(..) | SetCatch(..) => {}
Mov(arg, _)
| OpNot(arg, _)
| OpBitNot(arg, _)
@@ -286,7 +285,6 @@ where
self.value(Some(owner), arg2);
self.value(Some(owner), arg3);
}
Jmp(_) => {}
JmpIf(arg, _) => {
self.value(Some(owner), arg);
}