Пример #1
0
 public override Type Check(TypeCheckingEnvironment typeCheckingEnvironment, FunctionEnvironment functionEnvironment)
 {
     var argumentType = _arg.Check(typeCheckingEnvironment, functionEnvironment);
     var function = functionEnvironment.GetFunction(_name);
     if (function.CheckArgType(argumentType))
     {
         return function.ReturnType;
     }
     throw new InvalidOperationException(string.Format("Type error in call of function {0}", _name));
 }
Пример #2
0
        public override int Eval(RuntimeEnvironment env, FunctionEnvironment fenv)
        {
            int[] values;
            if (_args.Count > 0)
            {
                values = new int[_args.Count];
                int index = 0;
                foreach (Expression e in _args)
                {
                    values[index++] = e.Eval(env, fenv);
                }
            }
            else
            {
                values = new int[0];
            }
            FunctionDefinition fDef = fenv.GetFunction(fName);
            int result = fDef.Eval(env, fenv, values);

            return(result);
        }
Пример #3
0
        public override Type Check(TypeCheckingEnvironment env, FunctionEnvironment fenv)
        {
            Type[] parameterTypes = new Type[_args.Count];
            int    index          = 0;

            FunctionDefinition fDef = fenv.GetFunction(fName);

            foreach (Expression expression in _args)
            {
                parameterTypes[index++] = expression.Check(env, fenv);
            }

            if (fDef.CheckArgType(parameterTypes))
            {
                return(fDef.returnType);
            }
            else
            {
                throw new InvalidOperationException("Type error in call of function " + fName);
            }
        }
Пример #4
0
 public override int Eval(RuntimeEnvironment runtimeEnvironment, FunctionEnvironment functionEnvironment)
 {
     var argumentValue = _arg.Eval(runtimeEnvironment, functionEnvironment);
     var function = functionEnvironment.GetFunction(_name);
     return function.Eval(runtimeEnvironment, functionEnvironment, argumentValue);
 }