Example #1
0
        public object Eval(Object[] args)
        {
            // Debug.WriteLine("Closure.Eval: ids:" + ids + " args: " + args);
            Env eval_Env;

            if (ids != null)
            {
                if (all_in_one)                 // this might bear optimization at some point (esp since +,-,*, etc. use this)
                {
                    Pair     pairargs = Pair.FromArrayAt(args, 0);
                    Object[] newargs  = new Object[1];
                    newargs[0] = pairargs;
                    eval_Env   = env.Extend(ids, newargs);
                }
                else
                {
                    eval_Env = env.Extend(ids, args);                     //tailcall
                }
            }
            else
            {
                eval_Env = env;                 // tailcall
            }
//          DebugInfo.SetEnvironment(eval_Env);
            return(body.Eval(eval_Env));
        }
Example #2
0
        public override object Eval(Env env)
        {
            // Debug.WriteLine("Eval->Assign: " + id);
            object valEval = val.Eval(env);

//          DebugInfo.EvalExpression(this);
            return(env.Bind(id, valEval));
        }
Example #3
0
        public override object Eval(Env env)
        {
            object testVal = test_exp.Eval(env);

            // Debug.WriteLine("Eval->If: " + testVal);
            if (!(testVal is bool))
            {
                throw new Exception("invalid test expression type in if " + testVal.ToString());
            }

            if ((testVal is bool) && (((bool)testVal) == false))              // return false only if a bool false
            {
                return(false_exp.Eval(env));
            }
            else
            {
                return(true_exp.Eval(env));
            }
        }
Example #4
0
        public override object Eval(Env env)
        {
            Object proc = rator.Eval(env);

            Object[] args = Eval_Rands(rands, env);
//          DebugInfo.EvalExpression(this);
            // Debug.WriteLine("Eval->App: " + proc + " " + args);
            if (proc is Closure)
            {
//              DebugInfo.Push(proc as Closure, rator, args, marker);

                object result = (proc as Closure).Eval(args);

//              DebugInfo.Pop(marker);

                return(result);
            }
            else
            {
                throw new Exception("invalid operator" + proc.ToString());
            }
        }
Example #5
0
 public override object Eval(Expression exp)
 {
     return exp.Eval(initEnv);
 }
Example #6
0
 public override object Eval(Expression exp)
 {
     return(exp.Eval(initEnv));
 }