private static void fnSwap(IVIMStack stack)
 {
     var expr0 = stack.Pop();
     var expr1 = stack.Pop();
     stack.Push(expr0);
     stack.Push(expr1);
 }
        private static void fnGraph(IVIMStack stack)
        {
            var sysExpr = (ISystemExpression)stack.Pop();
            if (sysExpr is ArrayExpression)
            {
                var arr = (ArrayExpression) sysExpr;
                var dItems = arr.Items
                    .OfType<DoubleExpression>()
                    .Select(de => de.dVal);

                var list = new GraphableList(dItems);
                VIMMessageService.SendMessage((Action<IVIMGraphPanel>)(a => a.Graph(list)));
                return;
            }

            var fn = sysExpr.GetDelegate();
            VIMMessageService.SendMessage((Action<IVIMGraphPanel>)(a => a.Graph(fn)));
        }
 private static void fnRegParser(IVIMStack stack)
 {
     var parserName = stack.Pop().ToString();
     var parserText = stack.Pop().ToString();
     var dict = new Dictionary<string, string> {{parserName, parserText}};
     var guid = new Guid("{9AAC2521-41C8-4a26-8A74-DFBB7FA85ADE}");
     dict.Persist(guid);
 }
        private static void fnFn(IVIMStack stack)
        {
            var numExpr = (DoubleExpression) stack.Pop();
            var numArgs = (int) numExpr.dVal;

            var exprs = Enumerable.Range(0, numArgs)
                .Select(i => stack.Pop())
                .Cast<StringExpression>()
                .Reverse()
                .ToList();

            stack.Push(new FunctionExpression(exprs, (ISystemExpression)stack.Pop()));
        }
 private static void fnEval(IVIMStack stack)
 {
     var sysExpr = (ISystemExpression)stack.Pop();
     var fn = sysExpr.GetDelegate();
     var parameters = Enumerable.Range(0, fn.Method.GetParameters().Count())
         .Select(i => stack.Pop())
         .Select(expression => ((DoubleExpression)expression).dVal)
         .Cast<object>()
         .ToArray();
     stack.Push(new DoubleExpression((double)fn.DynamicInvoke(parameters)));
 }
 private static void fnEdit(IVIMStack stack)
 {
     var text = String.Empty;
     if (stack.Count > 0) text = stack.Pop().ToString();
     VIMMessageService.SendMessage((Action<ITextInputProvider>)(a => a.Text = text));
 }
 private static void fnDelete(IVIMStack stack)
 {
     stack.Pop();
 }
 private static void fnArray(IVIMStack stack)
 {
     var numExpr = (DoubleExpression)stack.Pop();
     var arrayVals = Enumerable.Range(0, (int) numExpr.dVal)
         .Select(i => stack.Pop());
     stack.Push(new ArrayExpression(arrayVals));
 }