Beispiel #1
0
 internal BasicNode ApplyFunc(BasicEnvironment env, FunctionProperty func)
 {
     env.InstructionCount++;
     if (!env.SaveContext())
     {
         return(env.LastError);
     }
     try
     {
         // create the formal parameters with their values
         int            nArgs      = func.argumentNames.Length;
         ConstantNode[] evaledArgs = new ConstantNode[nArgs];
         for (int i = 0; i < nArgs; i++)
         {
             string    argName = func.argumentNames[i];
             BasicNode evArg   = null;
             if (i < Arguments.Length)
             {
                 evArg = Arguments[i].Eval(env);
             }
             else
             {
                 evArg = CheckStringName(argName) ? ConstantNode.EmptyString : ConstantNode.Zero;
             }
             if (evArg.IsAbort())
             {
                 return(evArg);
             }
             var econs = evArg as ConstantNode;
             if (econs == null)
             {
                 env.RuntimeError();
             }
             evaledArgs[i] = econs;
         }
         var result = func.Apply(env, evaledArgs);
         if (result == null)
         {
             result = env.RuntimeError(ERuntimeErrors.NotImplemented, Name);
         }
         return(result);
     }
     finally
     {
         env.RestoreContext();
     }
 }
Beispiel #2
0
        BasicNode Call(BasicEnvironment env, ConstantNode[] args)
        {
            if (!env.SaveContext())
            {
                return(env.LastError);
            }
            if (argCount != args.Length)
            {
                return(env.RuntimeError("Argument count mismatch"));
            }
            for (int i = 0; i < args.Length; i++)
            {
                var prop = new ConstantProperty()
                {
                    Value = args[i],
                    Name  = parNames[i],
                };
                env.SetProperty(prop);
            }
            var result = expr.Eval(env);

            env.RestoreContext();
            return(result);
        }