コード例 #1
0
        protected bool IsString(NovelVariable v)
        {
            if (v.VariableType == typeof(string))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        protected bool ValidateArithmetics(NovelVariable v1, NovelVariable v2)
        {
            if (IsNumeric(v1) && IsNumeric(v2))
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        protected bool ValidateLogical(NovelVariable v1, NovelVariable v2)
        {
            if (v1.VariableType == typeof(bool) &&
                v2.VariableType == typeof(bool))
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        protected bool IsNumeric(NovelVariable v)
        {
            if (v.VariableType == typeof(int) ||
                v.VariableType == typeof(float) ||
                v.VariableType == typeof(double))
            {
                return(true);
            }

            return(false);
        }
コード例 #5
0
 protected int GetMaxArithmeticType(NovelVariable v)
 {
     for (int i = 0; i < ArithmeticTypes.Count(); i++)
     {
         if (v.VariableType == ArithmeticTypes[i])
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #6
0
        protected Type GetReturnType(NovelVariable v1, NovelVariable v2)
        {
            var type1  = GetMaxArithmeticType(v1);
            var type2  = GetMaxArithmeticType(v2);
            var result = (type1 > type2 ? type1 : type2);

            if (result >= 0)
            {
                return(ArithmeticTypes[result]);
            }

            return(typeof(int));
        }
コード例 #7
0
        public override NovelVariable Operate(NovelVariable var1, NovelVariable var2)
        {
            if (!ValidateArithmetics(var1, var2))
            {
                throw new NovelException("Not available operation (" + GetName() + ")", "temp", 0);
            }

            var dec1   = GetDecimal(var1);
            var dec2   = GetDecimal(var2);
            var result = Convert.ChangeType(dec1 % dec2, GetReturnType(var1, var2));

            return(new NovelVariable(result));
        }
コード例 #8
0
        public override NovelVariable Operate(NovelVariable var1, NovelVariable var2)
        {
            if (!ValidateLogical(var1, var2))
            {
                throw new NovelException("Not available operation (" + GetName() + ")", "temp", 0);
            }

            var dec1 = GetBool(var1);
            var dec2 = GetBool(var2);

            var result = Convert.ChangeType(dec1 || dec2, typeof(bool));

            return(new NovelVariable(result));
        }
コード例 #9
0
        public void CallScriptFunction(string name, object [] args)
        {
            int argsCount = 0;

            if (args != null)
            {
                argsCount = args.Length;
            }

            var function = Script.FunctionList.Where(x => x.Name.Equals(name) &&
                                                     x.ParameterNameList.Count.Equals(argsCount)).FirstOrDefault();

            if (function != null)
            {
                //Save pointer states
                var lastInstructionPtr = new NovelVariable(InstructionPointer);
                var lastStackPtr       = new NovelVariable(StackPointer);

                var stackSize = Stack.GetStackSize();
                //First expand the stack
                Stack.ExpandStack(3);
                //Push the variables on stack
                Stack.SetVariableAt(stackSize, 1, lastInstructionPtr);
                Stack.SetVariableAt(stackSize, 2, lastStackPtr);
                //Set new stack poitner
                StackPointer = Stack.GetStackSize();
                //Set new instruction pointer
                InstructionPointer = function.Offset;
                //Expand by the number of arguments
                Stack.ExpandStack(function.ParameterNameList.Count);
                //Fill arguments
                for (int i = 0; i < argsCount; i++)
                {
                    Stack.SetVariableAt(StackPointer, i, new NovelVariable(args[i]));
                }
            }
            else
            {
                throw new NovelException("Could not find function " + name + " with given signature", Script.Name, 0);
            }
        }
コード例 #10
0
        public override NovelVariable Operate(NovelVariable var1, NovelVariable var2)
        {
            if (!ValidateArithmetics(var1, var2))
            {
                throw new NovelException("Not available operation (" + GetName() + ")", "temp", 0);
            }

            var dec1 = GetDecimal(var1);
            var dec2 = GetDecimal(var2);

            decimal output = dec1;

            for (int i = 0; i < dec2 - 1; i++)
            {
                output *= dec1;
            }

            var result = Convert.ChangeType(output, GetReturnType(var1, var2));

            return(new NovelVariable(result));
        }
コード例 #11
0
        public override NovelVariable Operate(NovelVariable var1, NovelVariable var2)
        {
            if (IsString(var1) || IsString(var2))
            {
                string v1, v2;
                if (IsString(var1))
                {
                    v1 = (string)var1.Value;
                }
                else
                {
                    v1 = "" + GetDecimal(var1);
                }

                if (IsString(var2))
                {
                    v2 = (string)var2.Value;
                }
                else
                {
                    v2 = "" + GetDecimal(var2);
                }

                return(new NovelVariable(v1 + v2));
            }
            else if (!ValidateArithmetics(var1, var2))
            {
                throw new NovelException("Not available operation (" + GetName() + ")", "temp", 0);
            }

            var dec1   = GetDecimal(var1);
            var dec2   = GetDecimal(var2);
            var result = Convert.ChangeType(dec1 + dec2, GetReturnType(var1, var2));

            return(new NovelVariable(result));
        }
コード例 #12
0
 public override NovelVariable Operate(NovelVariable var1, NovelVariable var2)
 {
     return(null);
 }
コード例 #13
0
 public abstract NovelVariable Operate(NovelVariable var1,
                                       NovelVariable var2);
コード例 #14
0
 protected decimal GetDecimal(NovelVariable v)
 {
     return(Convert.ToDecimal(v.Value));
 }
コード例 #15
0
 protected bool GetBool(NovelVariable v)
 {
     return(Convert.ToBoolean(v.Value));
 }