Exemple #1
0
 public static void Lock(AphidInterpreter interpreter, AphidObject obj, AphidObject body)
 {
     lock (obj)
     {
         interpreter.CallFunction((AphidFunction)body.Value);
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            var interpreter = new AphidInterpreter();

            interpreter.Interpret("var add = @(x, y) x + y;");
            var x = interpreter.CallFunction("add", 3, 7).Value;

            Console.WriteLine(x);
        }
Exemple #3
0
        private static List <AphidObject> ListOrder(
            AphidInterpreter interpreter,
            AphidObject items,
            AphidObject keySelector,
            Func <IEnumerable <AphidObject>, Func <AphidObject, object>, IOrderedEnumerable <AphidObject> > action)
        {
            var list = (List <AphidObject>)items.Value;
            var func = (AphidFunction)keySelector.Value;

            return(action(list, x => interpreter.CallFunction(func, x).Value).ToList());
        }
Exemple #4
0
        public AphidObject CallFunction01(
            [PexAssumeUnderTest] AphidInterpreter target,
            AphidFunction function,
            object[] parms
            )
        {
            AphidObject result = target.CallFunction(function, parms);

            return(result);
            // TODO: add assertions to method AphidInterpreterTest.CallFunction01(AphidInterpreter, AphidFunction, Object[])
        }
Exemple #5
0
        private static ManualResetEvent ThreadCore(AphidInterpreter interpreter, Action <Action> start, AphidFunction function, params object[] parms)
        {
            var reset = new ManualResetEvent(false);

            void call()
            {
                interpreter.CallFunction(function, parms);
                reset.Set();
            }

            start(call);

            return(reset);
        }
Exemple #6
0
        private static ManualResetEvent ThreadCore(AphidInterpreter interpreter, Action <Action> start, AphidFunction function, params object[] parms)
        {
            var reset        = new ManualResetEvent(false);
            var interpreter2 = new AphidInterpreter(interpreter.CurrentScope);

            Action call = () =>
            {
                interpreter2.CallFunction(function, parms);
                reset.Set();
            };

            start(call);

            return(reset);
        }
Exemple #7
0
        private byte[] TryInterpretHandlerUnsafe(
            AphidInterpreter handlerInterpreter,
            HttpListenerContext context,
            AphidObject session)
        {
            var scope = AphidObject.Scope();

            SetupInterpreterScope(handlerInterpreter, scope, null, context, session);

            var handler = handlerInterpreter
                          .CurrentScope["http"]["handlers"]
                          .GetList()
                          .Select(x => x.Value)
                          .Cast <dynamic>()
                          .Select(x => new
            {
                x.Callback,
                Result = ValueHelper.Unwrap(handlerInterpreter.CallFunction(x.Predicate, scope))
            })
                          .FirstOrDefault(x => x.Result is bool && (bool)x.Result);

            if (handler != null)
            {
                var callback = handler.Callback;
                //AphidFunction callback = handler.Callback.Clone();
                //callback.Body = callback.Body.ToList();

                //var include = string.Format(
                //    "#'{0}'",
                //    GetHeaderFile().FullName.Replace("\\", "\\\\"));

                //callback.Body.Insert(0, AphidParser.ParseExpression(include));

                return(RenderResponse(
                           handlerInterpreter,
                           () => handlerInterpreter.CallFunctionWithScope(
                               callback,
                               scope,
                               scope),
                           scope,
                           context));
            }

            return(null);
        }