Last active
November 13, 2019 21:46
-
-
Save 166MMX/b71e179b224c5d98759122e4b22b4ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused_variables)] | |
#![allow(unused_assignments)] | |
fn main() {} | |
trait ProgramCounterOperations { | |
fn consume_instruction(&mut self, m: &VirtualMemory) -> &OpCode; | |
} | |
impl ProgramCounterOperations for u16 { | |
fn consume_instruction(&mut self, memory: &VirtualMemory) -> &OpCode { | |
unimplemented!() | |
} | |
} | |
struct VirtualMemory {} | |
enum AddressingMode {} | |
struct OpCode { | |
mode: AddressingMode, | |
byte: u8, | |
cycles: u8, | |
func: fn(&mut CentralProcessingUnit, &OpCode) -> u8, | |
} | |
struct CentralProcessingUnitRegisters { | |
a: u8, y: u8, x: u8, pc: u16, s: u8, p: u8, | |
} | |
struct CentralProcessingUnit { | |
r: CentralProcessingUnitRegisters, m: VirtualMemory, | |
} | |
impl CentralProcessingUnit { | |
pub fn run(&mut self) { | |
loop { | |
let op_code = self.r.pc.consume_instruction(&self.m); | |
let cycles = (op_code.func)(self, op_code); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error[E0499]: cannot borrow `*self` as mutable more than once at a time | |
--> src/lib.rs:1825:41 | |
| | |
1824 | let op_code = self.r.pc.consume_instruction(&self.m); | |
| --------- first mutable borrow occurs here | |
1825 | let cycles = (op_code.func)(self, op_code); | |
| ^^^^ ------- first borrow later used here | |
| | | |
| second mutable borrow occurs here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment