Exemple #1
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            FlowState state;

            bool continuing = true;

            while (continuing && continueExpression.GetAs <bool>(context))
            {
                bodyContext = new ScopeRuntimeContext(context);

                state = loopBody.Execute(bodyContext);

                switch (state)
                {
                case FlowState.Nominal:
                case FlowState.LoopContinue:
                    //Do nothing
                    break;

                case FlowState.LoopBreak:
                    continuing = false;
                    break;

                case FlowState.Return:
                    return(state);

                default:
                    throw new Exception($"Unexpected FlowState: {state}");
                }
            }

            return(FlowState.Nominal);
        }
        public override FlowState Execute(ScopeRuntimeContext parentContext)
        {
            ScopeRuntimeContext context = new ScopeRuntimeContext(parentContext);

            foreach (IExecutable statement in statements)
            {
                FlowState state = statement.Execute(context);

                switch (state)
                {
                case FlowState.Nominal:
                    //Continue
                    break;

                case FlowState.LoopContinue:
                case FlowState.LoopBreak:
                case FlowState.Return:
                    return(state);

                default:
                    throw new Exception($"Unexpected FlowState: {state}");
                }
            }

            return(FlowState.Nominal);
        }
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            switch (operatorType)
            {
            case Operator.AndEquals:
                if (!assignee.GetAs <bool>(context))
                {
                    //Short Circuiting
                    //No need to set anything
                    break;
                }
                assignee.SetAs(context, value.GetAs <bool>(context));
                break;

            case Operator.OrEquals:
                if (assignee.GetAs <bool>(context))
                {
                    //Short Circuiting
                    //No need to set anything
                    break;
                }
                assignee.SetAs(context, value.GetAs <bool>(context));
                break;

            default:
                throw new ArgumentException($"Unexpected Operator: {operatorType}");
            }

            return(FlowState.Nominal);
        }
Exemple #4
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (valueType == typeof(string))
            {
                PlayerData.SetString(keyArg.GetAs <string>(context), valueArg.GetAs <string>(context));
            }
            else if (valueType == typeof(bool))
            {
                PlayerData.SetBool(keyArg.GetAs <string>(context), valueArg.GetAs <bool>(context));
            }
            else if (valueType == typeof(double))
            {
                PlayerData.SetDouble(keyArg.GetAs <string>(context), valueArg.GetAs <double>(context));
            }
            else if (valueType == typeof(int))
            {
                PlayerData.SetInt(keyArg.GetAs <string>(context), valueArg.GetAs <int>(context));
            }
            else if (valueType == typeof(IList))
            {
                PlayerData.SetJsonValue(
                    key: keyArg.GetAs <string>(context),
                    value: GetUserListFunction.SerializeList(valueArg.GetAs <IList>(context)));
            }
            else
            {
                throw new Exception($"Unexpected ValueType for SetValue: {valueType.Name}");
            }

            return(FlowState.Nominal);
        }
 public override FlowState Execute(ScopeRuntimeContext context)
 {
     if (condition.GetAs <bool>(context))
     {
         return(trueBlock?.Execute(new ScopeRuntimeContext(context)) ?? FlowState.Nominal);
     }
     else
     {
         return(falseBlock?.Execute(new ScopeRuntimeContext(context)) ?? FlowState.Nominal);
     }
 }
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            switch (keyword)
            {
            case Keyword.Continue: return(FlowState.LoopContinue);

            case Keyword.Break: return(FlowState.LoopBreak);

            default: throw new ArgumentException($"Unexpected Keyword: {keyword}");
            }
        }
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            loopContext = new ScopeRuntimeContext(context);
            FlowState state = declarationStatement?.Execute(loopContext) ?? FlowState.Nominal;

            switch (state)
            {
            case FlowState.Nominal:
                //Continue
                break;

            case FlowState.LoopContinue:
            case FlowState.LoopBreak:
            case FlowState.Return:
            default:
                throw new Exception($"Unexpected FlowState: {state}");
            }

            bool continuing = true;

            foreach (object item in containerExpression.GetAs <IEnumerable>(loopContext))
            {
                loopVariable.Set(loopContext, item);
                bodyContext = new ScopeRuntimeContext(loopContext);

                state = loopBody.Execute(bodyContext);

                switch (state)
                {
                case FlowState.Nominal:
                case FlowState.LoopContinue:
                    //Do Nothing
                    break;

                case FlowState.LoopBreak:
                    continuing = false;
                    break;

                case FlowState.Return:
                    return(state);

                default:
                    throw new Exception($"Unexpected FlowState: {state}");
                }

                if (!continuing)
                {
                    break;
                }
            }

            return(FlowState.Nominal);
        }
Exemple #8
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (context.VariableExists(identifier))
            {
                //You cannot declare a local variable to shadow an existing global
                throw new ScriptRuntimeException($"Variable already declared in this context: {identifier}");
            }

            object defaultValue = initializer.GetAs <object>(context);

            context.DeclareVariable(identifier, valueType, defaultValue);

            return(FlowState.Nominal);
        }
Exemple #9
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            FlowState state;

            foreach (IExecutable statement in statements)
            {
                state = statement.Execute(context);

                if (state != FlowState.Nominal)
                {
                    return(state);
                }
            }

            return(FlowState.Nominal);
        }
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (assigneeType == valueType)
            {
                assignee.Set(context, value.GetAs <object>(context));
            }
            else if (assigneeType.AssignableFromType(valueType))
            {
                assignee.Set(context, Convert.ChangeType(value.GetAs <object>(context), assigneeType));
            }
            else
            {
                throw new ScriptRuntimeException(
                          $"Unable to assign {assignee} of type {assigneeType.Name} the value {value} of type {value.GetValueType().Name}");
            }

            return(FlowState.Nominal);
        }
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (returnType == typeof(void))
            {
                context.PushReturnValue(null);
            }
            else
            {
                if (returnType == returnValue.GetValueType())
                {
                    context.PushReturnValue(returnValue.GetAs <object>(context));
                }
                else
                {
                    context.PushReturnValue(
                        Convert.ChangeType(returnValue.GetAs <object>(context), returnType));
                }
            }

            return(FlowState.Return);
        }
Exemple #12
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (assigneeType == typeof(int))
            {
                assignee.SetAs(context, assignee.GetAs <int>(context) + value.GetAs <int>(context));
            }
            else if (assigneeType == typeof(double))
            {
                assignee.SetAs(context, assignee.GetAs <double>(context) + value.GetAs <double>(context));
            }
            else if (assigneeType == typeof(string))
            {
                assignee.SetAs(context, assignee.GetAs <string>(context) + GetStringValue(value, context));
            }
            else
            {
                throw new ScriptRuntimeException(
                          $"Incompatible types for operator {Operator.PlusEquals}: {assignee} of type {assigneeType.Name} and {value} of type {value.GetValueType().Name}");
            }

            return(FlowState.Nominal);
        }
 public abstract FlowState Execute(ScopeRuntimeContext context);
Exemple #14
0
 public FlowState Execute(ScopeRuntimeContext context)
 {
     operation(value.GetAs <TInput>(context), context);
     return(FlowState.Nominal);
 }
Exemple #15
0
 FlowState IExecutable.Execute(ScopeRuntimeContext context)
 {
     operation.Invoke(value.GetAs <TInput>(context));
     return(FlowState.Nominal);
 }
        public FlowState Execute(ScopeRuntimeContext context)
        {
            operation(context);

            return(FlowState.Nominal);
        }
        public FlowState Execute(ScopeRuntimeContext context)
        {
            Modify(context);

            return(FlowState.Nominal);
        }
Exemple #18
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (assigneeType == typeof(int))
            {
                switch (operatorType)
                {
                case Operator.PlusEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) + value.GetAs <int>(context));
                    break;

                case Operator.MinusEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) - value.GetAs <int>(context));
                    break;

                case Operator.TimesEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) * value.GetAs <int>(context));
                    break;

                case Operator.DivideEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) / value.GetAs <int>(context));
                    break;

                case Operator.PowerEquals:
                    assignee.SetAs(context, (int)Math.Pow(assignee.GetAs <int>(context), value.GetAs <int>(context)));
                    break;

                case Operator.ModuloEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) % value.GetAs <int>(context));
                    break;

                default: throw new ArgumentException($"Unexpected Operator: {operatorType}");
                }
            }
            else if (assigneeType == typeof(double))
            {
                switch (operatorType)
                {
                case Operator.PlusEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) + value.GetAs <double>(context));
                    break;

                case Operator.MinusEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) - value.GetAs <double>(context));
                    break;

                case Operator.TimesEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) * value.GetAs <double>(context));
                    break;

                case Operator.DivideEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) / value.GetAs <double>(context));
                    break;

                case Operator.PowerEquals:
                    assignee.SetAs(context, Math.Pow(assignee.GetAs <double>(context), value.GetAs <double>(context)));
                    break;

                case Operator.ModuloEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) % value.GetAs <double>(context));
                    break;

                default: throw new ArgumentException($"Unexpected Operator: {operatorType}");
                }
            }
            else
            {
                throw new ScriptRuntimeException(
                          $"Incompatible types for operator {operatorType}: {assignee} of type {assigneeType.Name} and {value} of type {value.GetValueType().Name}");
            }

            return(FlowState.Nominal);
        }
Exemple #19
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            context.AddToReport(headerArg.GetAs <string>(context), valueArg.GetAs <string>(context));

            return(FlowState.Nominal);
        }
 public override FlowState Execute(ScopeRuntimeContext context)
 {
     PlayerData.RemoveKey(keyArg.GetAs <string>(context));
     return(FlowState.Nominal);
 }
Exemple #21
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            loopContext = new ScopeRuntimeContext(context);
            FlowState state = initializationStatement?.Execute(loopContext) ?? FlowState.Nominal;

            switch (state)
            {
            case FlowState.Nominal:
                //Continue
                break;

            case FlowState.LoopContinue:
            case FlowState.LoopBreak:
            case FlowState.Return:
            default:
                throw new Exception($"Unexpected FlowState: {state}");
            }

            bool continuing = true;

            while (continuing && continueExpression.GetAs <bool>(loopContext))
            {
                bodyContext = new ScopeRuntimeContext(loopContext);

                state = loopBody.Execute(bodyContext);

                switch (state)
                {
                case FlowState.Nominal:
                case FlowState.LoopContinue:
                    //Do Nothing
                    break;

                case FlowState.LoopBreak:
                    continuing = false;
                    break;

                case FlowState.Return:
                    return(state);

                default:
                    throw new Exception($"Unexpected FlowState: {state}");
                }

                //Don't run incrementStatement if we are breaking out
                if (continuing)
                {
                    state = incrementStatement?.Execute(loopContext) ?? FlowState.Nominal;

                    switch (state)
                    {
                    case FlowState.Nominal:
                        //Do Nothing
                        break;

                    case FlowState.Return:
                    case FlowState.LoopContinue:
                    case FlowState.LoopBreak:
                    default:
                        throw new Exception($"Unexpected FlowState: {state}");
                    }
                }
            }

            return(FlowState.Nominal);
        }
Exemple #22
0
 FlowState IExecutable.Execute(ScopeRuntimeContext context)
 {
     operation.Invoke(context);
     return(FlowState.Nominal);
 }