Split Payload and PayloadType

This commit is contained in:
Werner
2021-12-26 18:44:17 -03:00
parent 96abcde56b
commit 5b7fc61723
5 changed files with 23 additions and 15 deletions

View File

@ -1,6 +1,5 @@
use crate::Machine;
use crate::Payload::PayloadType;
use crate::Types::Byte;
use crate::{Machine, PayloadType};
pub struct Instruction {
pub code: Byte,
@ -13,7 +12,12 @@ pub type InstructionFunction = fn(machine: &mut Machine) -> bool;
impl Instruction {
#[inline]
pub fn New(code: Byte, name: &str, payload: PayloadType, function: InstructionFunction) -> Self {
pub fn New(
code: Byte,
name: &str,
payload: PayloadType,
function: InstructionFunction,
) -> Self {
Self {
code,
name: name.to_string(),

View File

@ -1,8 +1,7 @@
use crate::Instruction;
use crate::Instructions::*;
use crate::Operations::*;
use crate::Payload::PayloadType;
use crate::Types::Byte;
use crate::{Instruction, PayloadType};
use std::collections::HashMap;
pub struct InstructionTable {
@ -19,6 +18,7 @@ impl Default for InstructionTable {
impl InstructionTable {
#[inline]
#[rustfmt::skip]
pub fn New() -> Self {
let mut table = InstructionTable::default();

View File

@ -8,16 +8,6 @@ pub type TwoRegisters = (Byte, Byte);
pub type ThreeRegisters = (Byte, Byte, Byte);
pub type FourRegisters = (Byte, Byte, Byte, Byte);
pub enum PayloadType {
Nothing,
Register,
RegisterAddress,
AddressRegister,
TwoRegisters,
ThreeRegisters,
FourRegisters,
}
#[inline]
pub fn GetRegister(vm: &mut Machine) -> Register {
vm.ReadByte(None)

10
Source/PayloadType.rs Normal file
View File

@ -0,0 +1,10 @@
pub enum PayloadType {
Nothing,
Register,
RegisterAddress,
AddressRegister,
TwoRegisters,
ThreeRegisters,
FourRegisters,
}

View File

@ -23,6 +23,10 @@ pub use self::_Limits::*;
mod _Machine;
pub use self::_Machine::*;
#[path = "PayloadType.rs"]
mod _PayloadType;
pub use self::_PayloadType::*;
#[path = "Registry.rs"]
mod _Registry;
pub use self::_Registry::*;