Exemple #1
0
        public MethodCall(ASTNode?node, IMnemonicsCompiler runtime) : base(node)
        {
            var namespaceName = node.GetChildAndAddError(0, "namespace", runtime)
                                .GetChildAndAddError(0, "LITERAL", runtime, false);

            var methodName = node.GetChildAndAddError(2, "method_name", runtime)
                             .GetChildAndAddError(0, "LITERAL", runtime, false);
            var methodArguments = node.GetChildAndAddError(4, "method_arguments", runtime, true);

            if (namespaceName.HasValue && methodName.HasValue)
            {
                Pointer = new MethodPointer
                {
                    NameSpace = namespaceName.Value.Value,
                    Name      = methodName.Value.Value
                };

                Arguments = new Arguments();

                if (methodArguments.HasValue)
                {
                    for (var k = 0; k < methodArguments.Value.Children.Count; k += 2)
                    {
                        var element = methodArguments.Value.Children.ElementAt(k);
                        var value   = runtime.Get(element);
                        Arguments.Args.Add(value);
                    }
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            MethodPointer methodPointer = AddInt;

            Console.WriteLine(methodPointer(2, 3));
            Console.WriteLine(CompareValue(2, 3, CompareAsc));
            //Anonymous Method
            MethodPointer Point = delegate(int a, int b)
            {
                return(a + b);
            };

            Console.WriteLine(CompareValue(2, 3, delegate(int a, int b) { return(a > b); }));

            //Lambda Expression
            MathZarb2 zarb2   = (a) => { return(a * 2); };
            MathZarb2 zarb2_2 = a => a * 2;

            Console.WriteLine("Lambda Expression: " + zarb2_2(2));
            //Generic
            MathString <string, int, int> mathString = (p1, p2) =>
            {
                return((p1 * p2).ToString());
            };
            MathString <string, int, int> mathString_2 = delegate(int p1, int p2)
            {
                return((p1 * p2).ToString());
            };

            Console.WriteLine("Generic: " + mathString_2(2, 3));
        }
Exemple #3
0
        public MethodDeclaration(ASTNode?node, IMnemonicsCompiler compiler) : base(node)
        {
            var nameSpace = node.GetChildAndAddError(0, "namespace", compiler)
                            .GetChildAndAddError(0, "LITERAL", compiler)?.Value;
            var method_name = node.GetChildAndAddError(2, "method_name", compiler)
                              .GetChildAndAddError(0, "LITERAL", compiler)?.Value;
            var body = node.GetChildAndAddError(node.Value.Children.Count - 1, "block_of_lopla", compiler);
            var code = compiler.Get(body);

            var method_parameters = node.GetChildAndAddError(4, "method_parameters", compiler, true);

            var methodArguments = new List <string>();

            if (method_parameters != null && method_parameters.Value.Children.Any())
            {
                foreach (var valueChild in method_parameters.Value.Children)
                {
                    var name = valueChild.GetChildAndAddError(0, "LITERAL", compiler).Value.Value;
                    methodArguments.Add(name);
                }
            }

            Pointer = new MethodPointer {
                Name = method_name, NameSpace = nameSpace
            };
            Code = new Method
            {
                ArgumentList = methodArguments,
                Code         = new List <Mnemonic>
                {
                    code
                }
            };
        }
Exemple #4
0
        public Dictionary <string, Result> GetArguments(MethodPointer p, List <Result> functionParamters, IRuntime runtime)
        {
            var mName = p.NameSpace + "." + p.Name;

            if (_procedures.ContainsKey(mName))
            {
                var functionRefernece = _procedures[mName];

                //// just check if user providede all paramters
                if (functionRefernece.ArgumentList?.Count != functionParamters?.Count)
                {
                    runtime.AddError(new RuntimeError(
                                         $"Invalid number of paramters passed to function {p.NameSpace}.{p.Name}. Expected {functionRefernece.ArgumentList?.Count} provided {functionParamters?.Count}"));
                }
                else
                {
                    var args = ExtractArguments(functionParamters, functionRefernece);
                    return(args);
                }
            }
            else
            {
                runtime.AddError(new RuntimeError($"Method not found {p.NameSpace}.{p.Name}"));
            }

            return(null);
        }
 public void OnPostRootDeserialize()
 {
     if (_iconList != null)
     {
         foreach (ComponentIcon ci in _iconList)
         {
             ComponentIconActionBranchParameter ciap = ci as ComponentIconActionBranchParameter;
             if (ciap != null)
             {
                 ParameterClassCollectionItem pcci = ciap.ClassPointer as ParameterClassCollectionItem;
                 if (pcci != null && pcci.BaseClassType != null)
                 {
                     if (pcci.BaseClassType.IsGenericParameter)
                     {
                         if (pcci.ConcreteType == null)
                         {
                             if (ActionData != null)
                             {
                                 MethodPointer mp = this.ActionData.ActionMethod as MethodPointer;
                                 if (mp != null)
                                 {
                                     DataTypePointer dp = mp.GetConcreteType(pcci.BaseClassType);
                                     if (dp != null)
                                     {
                                         pcci.SetConcreteType(dp);
                                     }
                                 }
                             }
                         }
                     }
                     else if (pcci.BaseClassType.IsGenericType && pcci.BaseClassType.ContainsGenericParameters)
                     {
                         if (pcci.TypeParameters == null)
                         {
                             if (ActionData != null)
                             {
                                 MethodPointer mp = this.ActionData.ActionMethod as MethodPointer;
                                 if (mp != null)
                                 {
                                     DataTypePointer dp = mp.GetConcreteType(pcci.BaseClassType);
                                     if (dp != null)
                                     {
                                         pcci.TypeParameters = dp.TypeParameters;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #6
0
        public List <Mnemonic> GetCode(MethodPointer p, IRuntime runtime)
        {
            var mName = p.NameSpace + "." + p.Name;

            if (_procedures.ContainsKey(mName))
            {
                return(_procedures[mName].Code);
            }
            runtime.AddError(new RuntimeError($"Method not found {p.NameSpace}.{p.Name}"));

            return(null);
        }
Exemple #7
0
        public GlobalScope GetScope(MethodPointer p, IRuntime runtime)
        {
            var mName = p.NameSpace + "." + p.Name;

            if (_procedures.ContainsKey(mName))
            {
                return(_procedures[mName].RootScope);
            }

            runtime.AddError(new RuntimeError($"Method not found {p.NameSpace}.{p.Name}"));

            return(null);
        }
Exemple #8
0
        public void AddMethod(int inlet, Symbol sel, MethodPointer d)
        {
            DynamicMethodPointer dyn = DynamicMethods.Create(d);

            if (inlet == 0 && sel == _pointer)
            {
                m_pointer    = dyn;
                methodflags |= MethodFlags.f_pointer;
            }
            else
            {
                AddMethodIntern(inlet, sel, Kind.k_pointer, dyn);
            }
        }
Exemple #9
0
        public void Register(MethodPointer name, Method method, IRuntime runtime, string processingStackName, GlobalScope scope)
        {
            var methodName = $"{name.NameSpace}.{name.Name}";

            if (!_procedures.ContainsKey(methodName))
            {
                method.GlobalScopeName = processingStackName;
                method.RootScope       = scope;
                _procedures.Add(methodName, method);
            }
            else
            {
                runtime.AddError(new LinkingError($"Failed to reregister method {methodName} (already declared)"));
            }
        }
Exemple #10
0
        public Result EvaluateMethodCall(MethodPointer pointer, List <Result> methodParameters)
        {
            var args  = _declarations.GetArguments(pointer, methodParameters, this);
            var stack = _declarations.GetScope(pointer, this);

            var derivedScope = _scopes.CreateFunctionScope(stack);

            var code = _declarations.GetCode(pointer, this);

            _processors.Begin(derivedScope);
            var result = _processors.Get().EvaluateFunctionInScope(code, args, pointer, this);

            _processors.End();

            return(result);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            int[] a = { 4, 5, 1, 2 };
            int[] c = { 4, 5, 1, 2 };



            MethodPointer obj1 = new MethodPointer(Print);

            obj1(a);


            MethodPointer obj2 = new MethodPointer(Sort);

            obj2(a);


            MethodPointer obj3 = new MethodPointer(Reverse);

            obj3(c);
        }
 private string getHandlerTypeDisplay()
 {
     if (_handlerType == null)
     {
         return("(?)");
     }
     if (_handlerType.IsLibType)
     {
         MethodInfo mif = _handlerType.LibTypePointer.ClassType.GetMethod("Invoke");
         return(MethodPointer.GetMethodSignature(mif, false));
     }
     else
     {
         CustomEventHandlerType ceht = _handlerType.ClassTypePointer as CustomEventHandlerType;
         if (_handlerType.ClassTypePointer == null)
         {
             return("(?)");
         }
         if (ceht == null)
         {
             throw new DesignerException("Invalid custom event handler type:{0}", _handlerType.ClassTypePointer.GetType().Name);
         }
         StringBuilder sb = new StringBuilder("(");
         if (ceht.ParameterCount > 0)
         {
             for (int i = 0; i < ceht.ParameterCount; i++)
             {
                 if (i > 0)
                 {
                     sb.Append(", ");
                 }
                 sb.Append(ceht.Parameters[i].DataTypeName);
                 sb.Append(" ");
                 sb.Append(ceht.Parameters[i].Name);
             }
         }
         sb.Append(")");
         return(sb.ToString());
     }
 }
Exemple #13
0
        public Result EvaluateFunctionInScope(List <Mnemonic> mCode,
                                              Dictionary <string, Result> args,
                                              MethodPointer pointer, Runtime runtime)
        {
            if (_requestForStop)
            {
                return(new Result());
            }

            //// local function context
            //// prevents leak of variables in global scope
            _stack.StartScope($"{pointer.NameSpace}.{pointer.Name}.{Guid.NewGuid()}");

            foreach (var result in args)
            {
                _runtime.SetVariable(result.Key,
                                     result.Value.Get(runtime), true);
            }

            var r = Evaluate(mCode);

            _stack.EndScope();
            return(r);
        }
Exemple #14
0
 protected static void AddMethod(int inlet, MethodPointer m) { AddMethod(inlet, _pointer, m); }
 public bool IsValid()
 {
     return(MethodPointer.FindDeclaredElement() != null &&
            ParameterPointer.FindDeclaredElement() != null);
 }
Exemple #16
0
 protected static void AddMethod(MethodPointer m) { AddMethod(0, m); }
Exemple #17
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            //var car = new Car();

            ////car.Name = "Tets";
            //INamed carName = car;
            //carName.PrintName();
            //ISMSNotify smsNotify = car;
            //smsNotify.Notify();
            //IEmailNotify emailNotify = car;
            //emailNotify.Notify();
            //Console.ReadKey();

            using (var cnn = new SqlConnection("data source=.; initial catalog=SampleForBulkInsert; user id=sa; password=1"))
            {
                cnn.Open();
                for (int i = 0; i < 100000; i++)
                {
                    var command = cnn.CreateCommand();
                    command.CommandText = "insert into SampleTable values ('Hossein Ahmadi','Mohammad Nasiri',@date,10000);";
                    command.Parameters.Add(new SqlParameter("date", DateTime.UtcNow));
                    command.ExecuteNonQuery();
                }
            }
            sw.Stop();


            Regex regex = new Regex("^[a-zA-Z]+$");

            if (!regex.IsMatch("sdfsg2323"))
            {
            }

            Dictionary <string, Student> students = new Dictionary <string, Student>();

            students.Add("10001", new Student("10001", "Hossein", "Ahmadi", 30));
            students.Add("10002", new Student("10002", "Mohammad", "Nasiri", 30));

            string[] fruits = { "apple",  "passionfruit", "banana", "mango",
                                "orange", "blueberry",    "grape",  "strawberry" };

            IEnumerable <string> query =
                fruits.TakeWhile((fruit, index) => fruit.Length >= index);

            foreach (string fruit in query)
            {
                Console.WriteLine(fruit + " " + fruit.Length);
            }
            Console.WriteLine();
            foreach (string fruit in fruits)
            {
                Console.WriteLine(fruit + " " + fruit.Length + " " + fruits.Select((Value, Index) => new { Value, Index }).Single(p => p.Value == fruit).Index);
            }


            Func <(int, int, int), (int, int, int)> doubleThem = ns => (2 * ns.Item1, 2 * ns.Item2, 2 * ns.Item3);
            var numbers        = (2, 3, 4);
            var doubledNumbers = doubleThem(numbers);

            Console.WriteLine($"The set {numbers} doubled: {doubledNumbers}");

            Action <int> printActionDel = delegate(int i)
            {
                Console.WriteLine(i);
            };

            printActionDel(10);

            Func <int, int, int> printActionDel1 = (i, j) => i * j;

            var mint = printActionDel1(10, 20);

            Console.WriteLine(Factorial(5));


            int[] numbers1          = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            var   firstSmallNumbers = numbers1.TakeWhile((n, index) => n >= index);

            Console.WriteLine(string.Join(" ", firstSmallNumbers));


            new Schedule().Exceute(() => Console.WriteLine("Just Run!"));

            Action <int> example1 = x => Console.WriteLine("Write {0}", x);

            example1(5);

            Func <int, string> example2 = x => string.Format("{0:n0}", x);

            Console.WriteLine(example2(5000));


            DisplayResult(2, 6, delegate(int n1, int n2) { return(n1 + n2); });
            DisplayResult(2, 6, delegate(int n1, int n2) { return(n1 * n2); });

            List <int> intList1 = new List <int>()
            {
                10, 20, 30, 40
            };

            bool res = intList1.TrueForAll(el => isPositiveInt(el));

            List <int> intList = new List <int>()
            {
                10, 20, 30
            };

            intList.ForEach(el => Console.WriteLine(el));

            MyGenericClass <int> intGenericClass = new MyGenericClass <int>(10);

            int val = intGenericClass.genericMethod(200);


            MethodPointer pointer = Sum;

            pointer += Substract;

            string str = "dgkl;ejgklsdgkl;\n";

            str += "erfggwewe";


            pointer(8, 3);

            string dummyLines = "This is first line." + Environment.NewLine +
                                "This is second line." + Environment.NewLine +
                                "This is third line.";

            //Opens DummyFile.txt and append lines. If file is not exists then create and open.
            File.AppendAllLines(@"C:\DummyFile.txt", dummyLines.Split(Environment.NewLine.ToCharArray()).ToList <string>());


            var members = new Members(new EmailManager());

            members.Register("Hossein", "Ahmadi");

            var members1 = new Members(new SmsManager());

            members1.Register("Hossein", "Ahmadi");

            var h  = new ValueHolder(12);
            var h2 = new ValueHolder(10);
            int m  = 17;

            for (double d = 1.01; d < 1.10; d += 0.01)
            {
                Console.WriteLine("Value of i: {0} {1}", d, 5);
            }

            Dictionary <int, string> dict = new Dictionary <int, string>();

            dict.Add(1, "one");
            dict.Add(2, "two");
            dict.Add(3, "three");

            Discounts saleDiscounts = new Discounts();

            saleDiscounts.Cloths    = 10;
            saleDiscounts.HomeDecor = 5;
            saleDiscounts.Grocery   = 2;

            WeekDays wd;

            int[][,,] intJaggedArray = new int[3][, , ];
            intJaggedArray[0]        = new int[3, 3, 3] {
                { { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } },
                { { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } },
                { { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } }
            };


            ArrayList myArryList = new ArrayList();

            myArryList.Add(1);
            myArryList.Add("Two");
            myArryList.Add(3);
            myArryList.Add(4.5f);

            //int[][,] intJaggedArray = new int[3][,];

            //intJaggedArray[0] = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
            //intJaggedArray[1] = new int[2, 2] { { 3, 4 }, { 5, 6 } };
            //intJaggedArray[2] = new int[2, 2];

            #region File

            //Create object of FileInfo for specified path
            FileInfo fi = new FileInfo(@"C:\DummyFile.txt");

            //Open file for Read\Write
            FileStream fs = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            //create byte array of same size as FileStream length
            byte[] fileBytes = new byte[fs.Length];

            //define counter to check how much bytes to read. Decrease the counter as you read each byte
            int numBytesToRead = (int)fileBytes.Length;

            //Counter to indicate number of bytes already read
            int numBytesRead = 0;

            //iterate till all the bytes read from FileStream
            while (numBytesToRead > 0)
            {
                int n = fs.Read(fileBytes, numBytesRead, numBytesToRead);

                if (n == 0)
                {
                    break;
                }

                numBytesRead   += n;
                numBytesToRead -= n;
            }

            //Once you read all the bytes from FileStream, you can convert it into string using UTF8 encoding
            string filestring = Encoding.UTF8.GetString(fileBytes);
            #endregion

            //throw new NotImplementedException();

            Console.WriteLine((h + h2).Value);
            Console.WriteLine((h - h2).Value);
            Console.WriteLine((h * h2).Value);
            Console.WriteLine((h / h2).Value);
            Console.WriteLine(h < h2);
            Console.WriteLine(h > h2);
            Console.WriteLine((h++).Value);
            Console.WriteLine((h--).Value);
            Console.WriteLine((int)h);
            Console.WriteLine(((ValueHolder)m).Value);

            ValueHolderType <string> v = new ValueHolderType <string>();

            MultipleGeneric <int, string, string> mm = new MultipleGeneric <int, string, string>();

            mm.Value1 = 55;
            mm.Value2 = "ds";
            mm.Value3 = "2342";

            string result = mm.DoSomething <string, int, int>(12, 20);


            Console.ReadKey();
        }
Exemple #18
0
 protected static void AddMethod(int inlet, MethodPointer m)
 {
     AddMethod(inlet, _pointer, m);
 }
Exemple #19
0
 protected static void AddMethod(int inlet, string sel, MethodPointer m) { AddMethod(inlet, new Symbol(sel), m); }
Exemple #20
0
 protected static void AddMethod(int inlet, Symbol sel, MethodPointer m)
 {
     ((External)m.Target).klass.AddMethod(inlet, sel, m);
 }
Exemple #21
0
 protected static void AddMethod(MethodPointer m)
 {
     AddMethod(0, m);
 }
Exemple #22
0
 protected static void AddMethod(int inlet, Symbol sel, MethodPointer m) { ((External)m.Target).klass.AddMethod(inlet, sel, m); }
Exemple #23
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IMethod m = value as IMethod;
             IActionMethodPointer im     = null;
             MethodPointer        method = value as MethodPointer;
             if (m == null)
             {
                 IMethodPointerHolder mh = context.Instance as IMethodPointerHolder;
                 if (mh != null)
                 {
                     im = mh.GetMethodPointer();
                     if (im != null)
                     {
                         m = im.MethodPointed;
                     }
                 }
             }
             MethodClass  scopeMethod = null;
             Type         t           = edSvc.GetType();
             PropertyInfo pif0        = t.GetProperty("OwnerGrid");
             if (pif0 != null)
             {
                 object           g  = pif0.GetValue(edSvc, null);
                 MathPropertyGrid pg = g as MathPropertyGrid;
                 if (pg != null)
                 {
                     scopeMethod = pg.ScopeMethod as MethodClass;
                 }
             }
             if (scopeMethod == null)
             {
                 IAction ia = context.Instance as IAction;
                 if (ia != null)
                 {
                     scopeMethod = ia.ScopeMethod as MethodClass;
                 }
             }
             FrmObjectExplorer dlg = DesignUtil.CreateSelectMethodDialog(scopeMethod, m);
             if (edSvc.ShowDialog(dlg) == DialogResult.OK)
             {
                 IAction act = null;
                 if (method != null)
                 {
                     act = method.Action;
                 }
                 if (act == null)
                 {
                     if (im != null)
                     {
                         act = im.Action;
                     }
                 }
                 IPropertyEx p = dlg.SelectedObject as IPropertyEx;
                 if (p != null)
                 {
                     value = p.CreateSetterMethodPointer(act);
                 }
                 else
                 {
                     MethodPointer mp = dlg.SelectedObject as MethodPointer;
                     if (mp != null)
                     {
                         mp.Action = act;
                         value     = mp;
                     }
                     else
                     {
                         CustomMethodPointer cmp = dlg.SelectedObject as CustomMethodPointer;
                         if (cmp != null)
                         {
                             cmp.Action = act;
                             value      = cmp;
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
Exemple #24
0
 protected static void AddMethod(int inlet, string sel, MethodPointer m)
 {
     AddMethod(inlet, new Symbol(sel), m);
 }
Exemple #25
0
        public void Register(MethodPointer methodName, Method body)
        {
            var stack = _processors.Get().RootStack();

            _declarations.Register(methodName, body, this, Guid.NewGuid().ToString(), stack);
        }
Exemple #26
0
 public MethodCall(MethodPointer pointer, params IArgument[] args) : base(null)
 {
     Pointer   = pointer;
     Arguments = new Arguments(args);
 }
Exemple #27
0
        public void Execute(List <ParameterClass> eventParameters)
        {
            MethodPointer mp  = (MethodPointer)ActionMethod;
            MethodBase    mif = mp.MethodDef;

            ParameterInfo[] pifs = mp.Info;
            object[]        vs   = new object[mp.ParameterCount];
            if (_parameterValues == null)
            {
                _parameterValues = new ParameterValueCollection();
            }
            mp.ValidateParameterValues(_parameterValues);
            for (int k = 0; k < mp.ParameterCount; k++)
            {
                vs[k] = null;
                IEventParameter iep = _parameterValues[k].AsEventParameter();
                if (iep != null)
                {
                    if (eventParameters != null)
                    {
                        foreach (ParameterClass p in eventParameters)
                        {
                            if (iep.IsSameParameter(p))
                            {
                                vs[k] = p.ObjectInstance;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    vs[k] = _parameterValues[k].ObjectInstance;
                }
                if (vs[k] != null)
                {
                    if (!pifs[k].ParameterType.Equals(vs[k].GetType()))
                    {
                        vs[k] = ValueTypeUtil.ConvertValueByType(pifs[k].ParameterType, vs[k]);
                    }
                }
            }
            object ret;

            if (mif.IsStatic)
            {
                ret = mif.Invoke(null, vs);
            }
            else
            {
                ret = mif.Invoke(mp.ObjectInstance, vs);
            }
            MethodInfo minfo = mif as MethodInfo;

            if (minfo != null)
            {
                if (!typeof(void).Equals(minfo.ReturnType))
                {
                    ReturnValue = ret;
                }
            }
        }
Exemple #28
0
 public void AddMethod(int inlet, Symbol sel, MethodPointer d)
 {
     DynamicMethodPointer dyn = DynamicMethods.Create(d);
     if (inlet == 0 && sel == _pointer)
     {
         m_pointer = dyn;
         methodflags |= MethodFlags.f_pointer;
     }
     else
         AddMethodIntern(inlet, sel, Kind.k_pointer, dyn);
 }