protected override void RunInstruction(ComputerInstruction instruction, ArgumentInfo arg0, ArgumentInfo arg1, ref int instructionOffset) { switch (instruction.Operator) { case ComputerOperator.Send: long message = arg0.Value; LinkedProgram.messageQueue.Enqueue(message); HaltRequested = ValueSent?.Invoke(message) ?? false; break; case ComputerOperator.Receive: bool received = messageQueue.TryDequeue(out long value); if (!received) { // Reattempt receiving the value when continuing execution, halt until rerun instructionOffset = 0; HaltRequested = true; break; } Registers[arg0.RegisterName] = value; break; default: base.RunInstruction(instruction, arg0, arg1, ref instructionOffset); return; } }
private void Send(string registerOrValue) { Debug.WriteLine($"program {_programId} sending... {SentCount}"); long value = GetValue(registerOrValue); SendQueue.Add(value); SentCount++; ValueSent?.Invoke(this, null); }