mirror of
https://github.com/guilhermewerner/machine
synced 2025-06-16 21:24:18 +00:00
Split Payload and PayloadType
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
use crate::Machine;
|
|
||||||
use crate::Payload::PayloadType;
|
|
||||||
use crate::Types::Byte;
|
use crate::Types::Byte;
|
||||||
|
use crate::{Machine, PayloadType};
|
||||||
|
|
||||||
pub struct Instruction {
|
pub struct Instruction {
|
||||||
pub code: Byte,
|
pub code: Byte,
|
||||||
@ -13,7 +12,12 @@ pub type InstructionFunction = fn(machine: &mut Machine) -> bool;
|
|||||||
|
|
||||||
impl Instruction {
|
impl Instruction {
|
||||||
#[inline]
|
#[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 {
|
Self {
|
||||||
code,
|
code,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use crate::Instruction;
|
|
||||||
use crate::Instructions::*;
|
use crate::Instructions::*;
|
||||||
use crate::Operations::*;
|
use crate::Operations::*;
|
||||||
use crate::Payload::PayloadType;
|
|
||||||
use crate::Types::Byte;
|
use crate::Types::Byte;
|
||||||
|
use crate::{Instruction, PayloadType};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct InstructionTable {
|
pub struct InstructionTable {
|
||||||
@ -19,6 +18,7 @@ impl Default for InstructionTable {
|
|||||||
|
|
||||||
impl InstructionTable {
|
impl InstructionTable {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[rustfmt::skip]
|
||||||
pub fn New() -> Self {
|
pub fn New() -> Self {
|
||||||
let mut table = InstructionTable::default();
|
let mut table = InstructionTable::default();
|
||||||
|
|
||||||
|
@ -8,16 +8,6 @@ pub type TwoRegisters = (Byte, Byte);
|
|||||||
pub type ThreeRegisters = (Byte, Byte, Byte);
|
pub type ThreeRegisters = (Byte, Byte, Byte);
|
||||||
pub type FourRegisters = (Byte, Byte, Byte, Byte);
|
pub type FourRegisters = (Byte, Byte, Byte, Byte);
|
||||||
|
|
||||||
pub enum PayloadType {
|
|
||||||
Nothing,
|
|
||||||
Register,
|
|
||||||
RegisterAddress,
|
|
||||||
AddressRegister,
|
|
||||||
TwoRegisters,
|
|
||||||
ThreeRegisters,
|
|
||||||
FourRegisters,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn GetRegister(vm: &mut Machine) -> Register {
|
pub fn GetRegister(vm: &mut Machine) -> Register {
|
||||||
vm.ReadByte(None)
|
vm.ReadByte(None)
|
||||||
|
10
Source/PayloadType.rs
Normal file
10
Source/PayloadType.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
pub enum PayloadType {
|
||||||
|
Nothing,
|
||||||
|
Register,
|
||||||
|
RegisterAddress,
|
||||||
|
AddressRegister,
|
||||||
|
TwoRegisters,
|
||||||
|
ThreeRegisters,
|
||||||
|
FourRegisters,
|
||||||
|
}
|
@ -23,6 +23,10 @@ pub use self::_Limits::*;
|
|||||||
mod _Machine;
|
mod _Machine;
|
||||||
pub use self::_Machine::*;
|
pub use self::_Machine::*;
|
||||||
|
|
||||||
|
#[path = "PayloadType.rs"]
|
||||||
|
mod _PayloadType;
|
||||||
|
pub use self::_PayloadType::*;
|
||||||
|
|
||||||
#[path = "Registry.rs"]
|
#[path = "Registry.rs"]
|
||||||
mod _Registry;
|
mod _Registry;
|
||||||
pub use self::_Registry::*;
|
pub use self::_Registry::*;
|
||||||
|
Reference in New Issue
Block a user