Esempio n. 1
0
        public void Create(NameSpace name_space)
        {
            ILGen.AddLine(".class public auto ansi beforefieldinit");
            ILGen.AddLine(name_space.name + "." + name);
            ILGen.AddLine("extends [mscorlib]System.Object");
            ILGen.AddLeftBrace();

            for (int i = 0; i < fields.Count; i++)
            {
                ILGen.AddLine(".field " + (fields[i].isPublic?"public ":"private ") + (fields[i].isStatic?"static ":" ") + "literal " + fields[i].type + " " + fields[i].name);
            }

            foreach (var t in functions)
            {
                t.Create(this);
            }
            ILGen.AddLine("  .method public hidebysig specialname rtspecialname instance void");
            ILGen.AddLine("   .ctor() cil managed ");

            ILGen.AddLeftBrace();
            ILGen.ILNumber  = 0;
            ILGen.preserved = new List <int>();
            ILGen.AddLine(".maxstack 8");

            for (int i = 0; i < fields.Count; i++)
            {
                void Set()
                {
                    switch (fields[i].type)
                    {
                    case "float32":
                        ILGen.AddInstruct(Instruction.ldc_r4, fields[i].value.Replace("f", ""));
                        break;
                        //TODO
                    }
                }

                if (fields[i].isStatic)
                {
                    Set();
                    ILGen.AddInstruct(Instruction.stsfld, fields[i].type + " " + name_space.name + "." + name + "::" + fields[i].name);
                }
                else
                {
                    ILGen.AddInstruct(Instruction.ldarg_0);
                    Set();
                    ILGen.AddInstruct(Instruction.stfld,
                                      fields[i].type + " " + name_space.name + "." + name + "::" + fields[i].name);
                }
            }
            ILGen.AddInstruct(Instruction.ret);

            ILGen.AddRightBrace();
            ILGen.AddRightBrace();
        }
Esempio n. 2
0
        public void Create(Class obj)
        {
            ILGen.current_func = this;
            ILGen.AddLine(".method public hidebysig static " + returnType.ILValue);
            ILGen.AddLine(name + "(");
            for (var index = 0; index < _params.Count; index++)
            {
                var t = _params[index];
                ILGen.AddLine(t.type.ILValue + " " + t.name + (_params.Count == 1 || index == _params.Count - 1 ? "" : ","));
            }

            ILGen.AddLine(") cil managed");
            ILGen.AddLeftBrace();
            ILGen.AddLine(".maxstack 8");
            ILGen.ILNumber  = 0;
            ILGen.preserved = new List <int>();
//            ILGen.AddLine(".locals init(");
//
//            ILGen.AddLine(")");
            block.Create();
            ILGen.AddRightBrace();
        }