From 9ae740fb49a0c0debfa0c2e42d2ced525a185dd1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 15 Jan 2025 01:01:34 -0800 Subject: [PATCH] InstructionCache --- lib/common/src/instruction.rs | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/common/src/instruction.rs b/lib/common/src/instruction.rs index d1d6e36..8643033 100644 --- a/lib/common/src/instruction.rs +++ b/lib/common/src/instruction.rs @@ -33,6 +33,42 @@ impl InstructionFeedback for X X:InstructionEmitter+InstructionConsumer, {} +pub struct InstructionCache{ + instruction_machine:S, + cached_instruction:Option>, + time_limit:Time, +} +impl InstructionCache + where + Time:Copy+Ord, + Option>:Clone, + S:InstructionEmitter+InstructionConsumer +{ + pub fn new( + instruction_machine:S, + )->Self{ + Self{ + instruction_machine, + cached_instruction:None, + time_limit:Time::MIN, + } + } + pub fn next_instruction_cached(&mut self,time_limit:Time)->Option>{ + if time_limit){ + // invalidate cache + self.time_limit=Time::MIN; + self.instruction_machine.process_instruction(instruction); + } +} + //PROPER PRIVATE FIELDS!!! pub struct InstructionCollector{ time:Time,