void Setup(CompilerParameters Options, bool ContainsLocalFunctions) { if (string.IsNullOrEmpty(Options.OutputAssembly)) { if (Options.GenerateInMemory) Options.OutputAssembly = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".exe"); else throw new ArgumentNullException(); } string name = Path.GetFileName(Options.OutputAssembly); string dir = Path.GetDirectoryName(Path.GetFullPath(Options.OutputAssembly)); AName = new AssemblyName(name); ABuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AName, AssemblyBuilderAccess.RunAndSave, dir); var Parameters = Options as IACompilerParameters; if(Parameters.Merge && (!Parameters.MergeFallbackToLink || !ContainsLocalFunctions)) { Mirror = new ILMirror(); Mirror.Sources.Add(typeof(Rusty.Core).Module); Mirror.Sources.Add(typeof(Script).Module); } foreach (var type in new[] { typeof(Core), typeof(Script) }) MineMethods(type); foreach (var assembly in Options.ReferencedAssemblies) LinkTo(assembly); }
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); }
void Setup(CompilerParameters Options, bool ContainsLocalFunctions) { if (string.IsNullOrEmpty(Options.OutputAssembly)) { if (Options.GenerateInMemory) { Options.OutputAssembly = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".exe"); } else { throw new ArgumentNullException(); } } string name = Path.GetFileName(Options.OutputAssembly); string dir = Path.GetDirectoryName(Path.GetFullPath(Options.OutputAssembly)); AName = new AssemblyName(name); ABuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AName, AssemblyBuilderAccess.RunAndSave, dir); var Parameters = Options as IACompilerParameters; if (Parameters.Merge && (!Parameters.MergeFallbackToLink || !ContainsLocalFunctions)) { Mirror = new ILMirror(); Mirror.Sources.Add(typeof(Rusty.Core).Module); Mirror.Sources.Add(typeof(Script).Module); } foreach (var type in new[] { typeof(Core), typeof(Script) }) { MineMethods(type); } foreach (var assembly in Options.ReferencedAssemblies) { LinkTo(assembly); } }
public MethodCollection() { Mirror = new ILMirror(); }