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;
        }
        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();
            // }
        }