//----------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteCaptureFieldInitialization(OperandCapture capture) { using (TypeTemplate.CreateScope <TypeTemplate.TField>(capture.OperandType)) { if (capture.SourceOperand.ShouldInitializeHoistedField) { capture.HoistedField.AsOperand <TypeTemplate.TField>(m_ClosureInstanceReference).Assign(capture.SourceOperand.CastTo <TypeTemplate.TField>()); } } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public void AddCapture(OperandCapture capture) { ValidateMutability(); if (!m_Captures.Any(c => c.SourceOperand == capture.SourceOperand)) { m_Captures.Add(capture); capture.HoistInClosure(this); } }
//------------------------------------------------------------------------------------------------------------------------------------------------- public void Merge(OperandCapture other) { if (this.HoistingClosure != null) { throw new InvalidOperationException("Cannot merge other captures because current capture was already assigned a closure."); } if (other.HoistingClosure != null) { throw new ArgumentException("Cannot merge specified capture because it was already assigned a closure."); } if (other.SourceOperand != this.SourceOperand) { throw new ArgumentException("Cannot merge specified capture because of source operands mismatch."); } m_Consumers.UnionWith(other.Consumers); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private IOperand GetRewrittenOperand(OperandCapture capture, IOperand target) { using (TypeTemplate.CreateScope <TypeTemplate.TField>(capture.OperandType)) { if (capture.HoistingClosure == this) { return(new Field <TypeTemplate.TField>(target, capture.HoistedField)); } else if (m_Parent != null) { return(m_Parent.GetRewrittenOperand(capture, m_ParentField.AsOperand <TypeTemplate.TField>(target))); } else { Debug.Fail("Captured operand is not hoisted."); throw new Exception(); } } }