本文整理汇总了C#中CodeGenContext.CreateModuleMethod方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenContext.CreateModuleMethod方法的具体用法?C# CodeGenContext.CreateModuleMethod怎么用?C# CodeGenContext.CreateModuleMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGenContext
的用法示例。
在下文中一共展示了CodeGenContext.CreateModuleMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateOptionsMethod
private static MethodDef GenerateOptionsMethod(CodeGenContext context, List<KeyValuePair<string, object>> runtime_options) {
// internal void SetOptions(string[] args) {
CodeGenContext SetOptions = context.CreateModuleMethod("SetOptions", PrimitiveType.Void, new Param(ParamAttr.Default, "args", new PERWAPI.ZeroBasedArray(PrimitiveType.String)));
SetOptions.ldarg("args");
SetOptions.call(Runtime.Options.SetArgs);
if (runtime_options != null)
foreach (KeyValuePair<string, object> option in runtime_options) {
SetOptions.ldstr(option.Key);
if (option.Value == null)
SetOptions.ldnull();
else if (option.Value is string)
SetOptions.ldstr((string)option.Value);
else if (option.Value is int) {
SetOptions.ldc_i4((int)option.Value);
SetOptions.box(PrimitiveType.Int32);
} else if (option.Value is bool) {
if ((bool)option.Value)
SetOptions.PushTrue();
else
SetOptions.PushFalse();
SetOptions.box(PrimitiveType.Boolean);
} else
throw new System.NotImplementedException("unknown option");
SetOptions.call(Runtime.Options.SetRuntimeOption);
}
SetOptions.ret();
SetOptions.Close();
return SetOptions.Method;
}
示例2: GenerateMainMethod
internal static void GenerateMainMethod(CodeGenContext context, ClassDef fileClass, MethodDef SetOptions, List<SOURCEFILE> files) {
// public static void Main(string[] args) {
CodeGenContext Main = context.CreateModuleMethod("Main", PrimitiveType.Void, new Param[] { new Param(ParamAttr.Default, "args", new PERWAPI.ZeroBasedArray(PrimitiveType.String)) });
Main.Method.DeclareEntryPoint();
PERWAPI.CILLabel endLabel = Main.NewLabel();
// try {
Main.StartBlock(Clause.Try);
if (SetOptions != null) {
// SetOptions(args);
Main.ldarg("args");
Main.call(SetOptions);
}
// register other ruby source files in assembly so that they can be loaded if requested
foreach (SOURCEFILE f in files) {
// Ruby.Runtime.Program.AddProgram(filename, fileClass);
Main.ldstr(File.stripExtension(f.location.file));
Main.ldtoken(f.fileClass);
Main.call(Runtime.SystemType.GetTypeFromHandle);
Main.call(Runtime.Program.AddProgram);
}
// Explicit load
// Load(ruby_top_self, null);
Main.ldsfld(Runtime.Object.ruby_top_self);
Main.ldnull();
Main.call(LoadMethod.Method);
Main.pop();
Main.Goto(endLabel);
// }
TryBlock block = Main.EndTryBlock();
// finally {
Main.StartBlock(Clause.Finally);
// Program.ruby_stop();
Main.call(Runtime.Program.ruby_stop);
Main.endfinally();
// }
Main.EndFinallyBlock(block);
Main.CodeLabel(endLabel);
Main.ret();
Main.Close();
// }
}