예제 #1
0
파일: Max.cs 프로젝트: Hengle/IceKori-1
        public override BaseExpression Reduce(Enviroment env)
        {
            if (A.Reducible)
            {
                return(new Pow(A.Reduce(env), B));
            }
            if (A.ID == BaseError.Error)
            {
                return(A);
            }
            if (B.Reducible)
            {
                return(new Pow(A, B.Reduce(env)));
            }
            if (B.ID == BaseError.Error)
            {
                return(B);
            }
            if (A.ID != IceKoriBaseType.Float && A.ID != IceKoriBaseType.Int)
            {
                return(new TypeError($"Argument of type '{A}' is not assignable to parameter of type 'IceKoriFloat || IceKoriInt'."));
            }
            if (B.ID != IceKoriBaseType.Float && B.ID != IceKoriBaseType.Int)
            {
                return(new TypeError($"Argument of type '{B}' is not assignable to parameter of type 'IceKoriFloat || IceKoriInt'."));
            }

            if (A.ID == IceKoriBaseType.Float)
            {
                return(new IceKoriFloat(Mathf.Max(((IceKoriFloat)A).Value, ((IceKoriInt)B).Value)));
            }
            if (B.ID == IceKoriBaseType.Float)
            {
                return(new IceKoriFloat(Mathf.Max(((IceKoriFloat)A).Value, ((IceKoriInt)B).Value)));
            }
            return(new IceKoriFloat(Mathf.Max(((IceKoriInt)A).Value, ((IceKoriInt)B).Value)));
        }
예제 #2
0
 public override BaseExpression Reduce(Enviroment env)
 {
     if (Array.Reducible)
     {
         return(new Include(Array.Reduce(env), Value));
     }
     if (Array.ID == BaseError.Error)
     {
         return(Array);
     }
     if (Value.Reducible)
     {
         return(new Include(Array, Value.Reduce(env)));
     }
     if (Value.ID == BaseError.Error)
     {
         return(Value);
     }
     if (Array.ID == IceKoriBaseType.Array)
     {
         return(new IceKoriBool(((IceKoriArray)Array).Value.Contains((IceKoriBaseType)Value)));
     }
     return(new TypeError($"Argument of type '{Array}' is not assignable to parameter of type 'IceKoriString'."));
 }
예제 #3
0
 private void _VariableReduce(Dictionary <string, BaseExpression> variables)
 {
     foreach (var keyValuePair in variables)
     {
         BaseExpression value = keyValuePair.Value;
         while (true)
         {
             if (value.Reducible)
             {
                 value = value.Reduce(this);
                 if (value.GetType().IsSubclassOf(typeof(BaseError)))
                 {
                     Interpreter.ErrorHandling.ThrowError((BaseError)value, this);
                     return;
                 }
             }
             else
             {
                 Variables[keyValuePair.Key] = (IceKoriBaseType)value;
                 break;
             }
         }
     }
 }
예제 #4
0
        public override object[] Reduce(Enviroment env, ErrorHandling errorHandling)
        {
            var statement = _Pretreatment(Value, () => new GlobalVariableUpdate(Name, Value.Reduce(env)), () =>
            {
                if (!env.GlobalVariables.ContainsKey(Name))
                {
                    return(new Throw(new TypeError($"Global identifier \"{Name}\" does not defined")));
                }
                env.GlobalVariables[Name] = (IceKoriBaseType)Value;
                return(DoNothing.GetValue);
            });

            return(new object[] { statement, env, errorHandling });
        }