示例#1
0
        /// <summary>
        /// Update the full or partial value of a symbol (if allowed) depending on the given value access
        /// </summary>
        /// <param name="valueAccess"></param>
        /// <param name="value"></param>
        protected virtual void UpdateSymbolValue(LanguageValueAccess valueAccess, ILanguageValue value)
        {
            var symbol = valueAccess.RootSymbol;

            if (AllowUpdateSymbolValue(symbol) == false)
            {
                throw new InvalidOperationException("Invalid symbol type");
            }

            if (valueAccess.IsFullAccess)
            {
                SetSymbolData((SymbolDataStore)symbol, value);

                return;
            }

            var sourceValue = ReadSymbolFullValue(symbol);

            ValueAccessProcessor.WritePartialValue(sourceValue, valueAccess, value);
        }
示例#2
0
        /// <summary>
        /// Evaluate a structure construction operation
        /// </summary>
        /// <param name="structureCons"></param>
        /// <param name="operands"></param>
        /// <returns></returns>
        private ValueStructureSparse EvaluateBasicPolyadicStructureConstructor(GMacStructureConstructor structureCons, OperandsByValueAccess operands)
        {
            ValueStructureSparse value;

            if (structureCons.HasDefaultValueSource)
            {
                value =
                    (ValueStructureSparse)structureCons
                    .DefaultValueSource
                    .AcceptVisitor(this)
                    .DuplicateValue(true);
            }

            else
            {
                value =
                    (ValueStructureSparse)GMacRootAst
                    .CreateDefaultValue(structureCons.Structure);
            }

            foreach (var command in operands.AssignmentsList)
            {
                var rhsValue = command.RhsExpression.AcceptVisitor(this);

                if (command.LhsValueAccess.IsFullAccess)
                {
                    value[command.LhsValueAccess.RootSymbol.ObjectName] = rhsValue.DuplicateValue(true);
                }

                else
                {
                    var sourceValue = value[command.LhsValueAccess.RootSymbol.ObjectName];

                    ValueAccessProcessor.WritePartialValue(sourceValue, command.LhsValueAccess, rhsValue.DuplicateValue(true));
                }
            }

            return(value);
        }