public static bool TryCompile(PFunction func, Engine targetEngine, FunctionLinking linking) { if (_checkQualification(func, targetEngine)) { var pass = new CompilerPass(func.ParentApplication, linking); var m = pass.DefineImplementationMethod(func.Id); var il = CompilerPass.GetIlGenerator(m); _compile(func, il, targetEngine, pass, linking); func.Declaration.CilImplementation = pass.GetDelegate(m); pass.LinkMetadata(func); return true; } return false; }
public static void Compile(IEnumerable<PFunction> functions, Engine targetEngine, FunctionLinking linking) { _checkQualification(functions, targetEngine); var qfuncs = new List<PFunction>(); //Get a list of qualifying functions foreach (var func in functions) if (!func.Meta.GetDefault(PFunction.VolatileKey, false)) qfuncs.Add(func); if (qfuncs.Count == 0) return; //No compilation to be done var pass = new CompilerPass(linking); //Generate method stubs foreach (var func in qfuncs) pass.DefineImplementationMethod(func.Id); //Emit IL foreach (var func in qfuncs) { _compile(func, CompilerPass.GetIlGenerator(pass.Implementations[func.Id]), targetEngine, pass, linking); } //Enable by name linking and link meta data to CIL implementations foreach (var func in qfuncs) { func.Declaration.CilImplementation = pass.GetDelegate(func.Id); pass.LinkMetadata(func); } }