Exemplo n.º 1
0
            public Continuation Perform(Continuation c)
            {
                var args = new Datum[argCount];

                for (var i = 0; i < argCount; ++i)
                {
                    args[i] = c.Result;
                    c       = c.PopResult();
                }
                return(function.Evaluate(c, DatumHelpers.compound(args)));
            }
        public override Continuation Evaluate(Continuation c, Datum args)
        {
            var argArray = args.ToArray();

            if (argArray.Length != 2)
            {
                throw DatumHelpers.error("Invalid syntax. ArgCount ({0}) != 2. Usage: (execute-with-error-handler <error-function> <fn>)", argArray.Length);
            }
            var errorHandler = makeErrorHandler(c.ErrorHandler, (StackFunction)argArray[0]);
            var fn           = (StackFunction)argArray[1];

            return(fn.Evaluate(c.NewErrorHandler(errorHandler), DatumHelpers.compound()));
        }
Exemplo n.º 3
0
        public override Continuation Evaluate(Continuation c, Datum args)
        {
            var argArray = args.ToArray();

            if (argArray.Length != 1)
            {
                throw DatumHelpers.error("call/cc: expect a single function as an argument. Got {0}", argArray.Length);
            }
            var arg      = argArray[0];
            var function = arg as StackFunction;

            if (function == null)
            {
                throw DatumHelpers.error("call/cc: {0} must be a function", arg);
            }
            return(function.Evaluate(c, DatumHelpers.compound(new ContinuationFunction(c))));
        }
 private static ErrorHandler makeErrorHandler(ErrorHandler oldErrorHandler, StackFunction f)
 {
     // Report the "message" from the exception to the Lisp
     // error handling function.
     // Ensure that the original error handler is in scope before evaluating the error function -
     // otherwise we end up in an infinite loop if there's an error in the error function itself.
     return((c, ex) => f.Evaluate(c.PopTask().SetErrorHandler(oldErrorHandler), DatumHelpers.compound(ex.Message.ToAtom(), CallCC.MakeContinuationFunction(c))));
 }