Exemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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>());
                }
            }
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void AddCapture(OperandCapture capture)
        {
            ValidateMutability();

            if (!m_Captures.Any(c => c.SourceOperand == capture.SourceOperand))
            {
                m_Captures.Add(capture);
                capture.HoistInClosure(this);
            }
        }
Exemplo n.º 3
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        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);
        }
Exemplo n.º 4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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();
                }
            }
        }