public void Compile(MathFuncAssemblyCecil mathFuncAssembly, string funcName)
        {
            MathFuncAssembly = mathFuncAssembly;

            var globalBody = new MethodDefinition(funcName,
                                                  MethodAttributes.Public | MethodAttributes.HideBySig | (Static ? MethodAttributes.Static : 0), mathFuncAssembly.DoubleType);

            var globalIlProcessor = globalBody.Body.GetILProcessor();

            AddFuncArgs(mathFuncAssembly.Assembly, globalIlProcessor);

            DefineLocals();
            IlInstructions = new List <OpCodeArg>();
            EmitNode(Root);
            IlInstructions.Add(new OpCodeArg(OpCodes.Ret));
            OptimizeInstructions();
            OptimizeLocalVariables(ref LocalVarNumber);

            for (int i = 0; i < LocalVarNumber; i++)
            {
                globalBody.Body.Variables.Add(new VariableDefinition(mathFuncAssembly.DoubleType));
            }

            foreach (var instr in IlInstructions)
            {
                EmitInstruction(globalIlProcessor, instr, Static);
            }

            Instructions = globalBody.Body.Instructions;

            mathFuncAssembly.Class.Methods.Add(globalBody);
        }
		public void Compile(MathFuncAssemblyCecil mathFuncAssembly, string funcName)
		{
			MathFuncAssembly = mathFuncAssembly;

			var globalBody = new MethodDefinition(funcName,
				MethodAttributes.Public | MethodAttributes.HideBySig | (Static ? MethodAttributes.Static : 0), mathFuncAssembly.DoubleType);
			
			var globalIlProcessor = globalBody.Body.GetILProcessor();

			AddFuncArgs(mathFuncAssembly.Assembly, globalIlProcessor);

			DefineLocals();
			IlInstructions = new List<OpCodeArg>();
			EmitNode(Root);
			IlInstructions.Add(new OpCodeArg(OpCodes.Ret));
			OptimizeInstructions();
			OptimizeLocalVariables(ref LocalVarNumber);

			for (int i = 0; i < LocalVarNumber; i++)
				globalBody.Body.Variables.Add(new VariableDefinition(mathFuncAssembly.DoubleType));

			foreach (var instr in IlInstructions)
				EmitInstruction(globalIlProcessor, instr, Static);

			Instructions = globalBody.Body.Instructions;

			mathFuncAssembly.Class.Methods.Add(globalBody);
		}
		public MathAssembly(string expression, string variable)
		{
			var mathAssembly = new MathFuncAssemblyCecil();
			_fileName = "MathFuncLib" + "_" + GenerateRandomString(6) + ".dll";
			mathAssembly.CompileFuncAndDerivative(expression, variable, "", _fileName);
			_domain = AppDomain.CreateDomain("MathFuncDomain");
			_mathFuncObj = _domain.CreateInstanceFromAndUnwrap(_fileName, mathAssembly.NamespaceName + "." + mathAssembly.ClassName);
			var mathFuncObjType = _mathFuncObj.GetType();
			FuncMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncName);
			FuncDerivativeMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncDerivativeName);
		}
        public MathAssembly(string expression, string variable)
        {
            var mathAssembly  = new MathFuncAssemblyCecil();
            var fileName      = $"MathFuncLib_{Guid.NewGuid()}.dll";
            var assemblyBytes = mathAssembly.CompileFuncAndDerivativeInMemory(expression, variable, fileName);
            var assembly      = Assembly.Load(assemblyBytes);

            _mathFuncObj = assembly.CreateInstance(mathAssembly.NamespaceName + "." + mathAssembly.ClassName);
            var mathFuncObjType = _mathFuncObj.GetType();

            FuncMethodInfo           = mathFuncObjType.GetMethod(mathAssembly.FuncName);
            FuncDerivativeMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncDerivativeName);
        }