Example #1
0
        /// <inheritdoc/>
        internal override void Run()
        {
            if (BaZicInterpreter.Verbose)
            {
                ParentInterpreter.VerboseLog(L.BaZic.Runtime.Interpreters.Statements.AssignInterpreter.FormattedAssign(Statement.LeftExpression, Statement.RightExpression));
            }

            if (!typeof(IAssignable).IsAssignableFrom(Statement.LeftExpression.GetType()))
            {
                BaZicInterpreter.ChangeState(this, new NotAssignableException(L.BaZic.Runtime.Interpreters.Statements.AssignInterpreter.NotAssignable), Statement);
                return;
            }

            var rightValue = ParentInterpreter.RunExpression(Statement.RightExpression);

            if (ParentInterpreter.IsAborted)
            {
                return;
            }

            switch (Statement.LeftExpression)
            {
            case ArrayIndexerExpression arrayIndexer:
                AssignArrayValue(arrayIndexer, rightValue);
                break;

            case PropertyReferenceExpression propertyReference:
                AssignProperty(propertyReference, rightValue);
                break;

            case VariableReferenceExpression variableReference:
                ParentInterpreter.SetVariable(variableReference, rightValue);
                break;

            default:
                throw new InternalException(L.BaZic.Runtime.Interpreters.Statements.AssignInterpreter.FormattedNoInterpreter(Statement.LeftExpression.GetType().FullName));
            }

            if (BaZicInterpreter.Verbose && !ParentInterpreter.IsAborted)
            {
                var rightValueString = rightValue == null ? L.BaZic.Runtime.Debugger.ValueInfo.Null : $"'{rightValue}'(type:{ rightValue.GetType().FullName})";
                ParentInterpreter.VerboseLog(L.BaZic.Runtime.Interpreters.Statements.AssignInterpreter.FormattedNowEqualsTo(Statement.LeftExpression, rightValueString));
            }
        }