public MethodWriter(TypeBuilder Parent, CodeMemberMethod Member, MethodCollection Lookup, ILMirror Mirror) { Loops = new Stack <LoopMetadata>(); this.Member = Member; this.Lookup = Lookup; this.Mirror = Mirror; if (Member is CodeEntryPointMethod) { Method = Parent.DefineMethod("Main", MethodAttributes.Private | MethodAttributes.Static, typeof(void), null); IsEntryPoint = true; } else { Method = Parent.DefineMethod(Member.Name, MethodAttributes.Public | MethodAttributes.Static, typeof(object), new[] { typeof(object[]) }); } Generator = Method.GetILGenerator(); ForceString = typeof(Script).GetMethod("ForceString"); ForceDecimal = typeof(Script).GetMethod("ForceDecimal"); ForceLong = typeof(Script).GetMethod("ForceLong"); ForceInt = typeof(Script).GetMethod("ForceInt"); ForceBool = typeof(Script).GetMethod("ForceBool"); Locals = new Dictionary <string, LocalBuilder>(); Labels = new Dictionary <string, LabelMetadata>(); Type Variables = typeof(Script.Variables); if (IsEntryPoint) { GenerateEntryPointHeader(Generator); } SetVariable = typeof(Script.Variables).GetMethod("SetVariable"); GetVariable = typeof(Script.Variables).GetMethod("GetVariable"); MethodInfo GetVars = typeof(Script).GetMethod("get_Vars"); if (Mirror != null) { ForceString = Mirror.GrabMethod(ForceString); ForceDecimal = Mirror.GrabMethod(ForceDecimal); ForceLong = Mirror.GrabMethod(ForceLong); ForceInt = Mirror.GrabMethod(ForceInt); ForceBool = Mirror.GrabMethod(ForceBool); SetVariable = Mirror.GrabMethod(SetVariable); GetVariable = Mirror.GrabMethod(GetVariable); Variables = Mirror.GrabType(Variables); GetVars = Mirror.GrabMethod(GetVars); } VarsProperty = Generator.DeclareLocal(Variables); Generator.Emit(OpCodes.Call, GetVars); Generator.Emit(OpCodes.Stloc, VarsProperty); }
public MethodWriter(TypeBuilder Parent, CodeMemberMethod Member, MethodCollection Lookup, ILMirror Mirror) { Loops = new Stack<LoopMetadata>(); this.Member = Member; this.Lookup = Lookup; this.Mirror = Mirror; if(Member is CodeEntryPointMethod) { Method = Parent.DefineMethod("Main", MethodAttributes.Private | MethodAttributes.Static, typeof(void), null); IsEntryPoint = true; } else Method = Parent.DefineMethod(Member.Name, MethodAttributes.Public | MethodAttributes.Static, typeof(object), new[] { typeof(object[]) }); Generator = Method.GetILGenerator(); ForceString = typeof(Script).GetMethod("ForceString"); ForceDecimal = typeof(Script).GetMethod("ForceDecimal"); ForceLong = typeof(Script).GetMethod("ForceLong"); ForceInt = typeof(Script).GetMethod("ForceInt"); ForceBool = typeof(Script).GetMethod("ForceBool"); Locals = new Dictionary<string, LocalBuilder>(); Labels = new Dictionary<string, LabelMetadata>(); Type Variables = typeof(Script.Variables); if(IsEntryPoint) GenerateEntryPointHeader(Generator); SetVariable = typeof(Script.Variables).GetMethod("SetVariable"); GetVariable = typeof(Script.Variables).GetMethod("GetVariable"); MethodInfo GetVars = typeof(Script).GetMethod("get_Vars"); if(Mirror != null) { ForceString = Mirror.GrabMethod(ForceString); ForceDecimal = Mirror.GrabMethod(ForceDecimal); ForceLong = Mirror.GrabMethod(ForceLong); ForceInt = Mirror.GrabMethod(ForceInt); ForceBool = Mirror.GrabMethod(ForceBool); SetVariable = Mirror.GrabMethod(SetVariable); GetVariable = Mirror.GrabMethod(GetVariable); Variables = Mirror.GrabType(Variables); GetVars = Mirror.GrabMethod(GetVars); } VarsProperty = Generator.DeclareLocal(Variables); Generator.Emit(OpCodes.Call, GetVars); Generator.Emit(OpCodes.Stloc, VarsProperty); }