Exemple #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();
        }
Exemple #2
0
 public override void Create()
 {
     if (Op == Word.Minus)
     {
         Expr.Create();
         ILGen.AddInstruct(Instruction.neg);
     }
     else if (Op == Word.Not)
     {
         //TODO
     }
 }
Exemple #3
0
        public override void Create()
        {
            var index = -1;
            var type  = "";

            for (var i = 0; i < ILGen.current_func._params.Count; i++)
            {
                if (ILGen.current_func._params[i].name == Name.ILValue)
                {
                    type  = ILGen.current_func._params[i].type.ILValue;
                    index = i;
                }
            }

            Instruction instruction;

//            switch (type)
//            {
//                case "float32": instruction = Instruction.ldc_r4;break;
//                //TODO
//            }

            ILGen.AddInstruct("ldarg." + (index));
        }
Exemple #4
0
 public override void Create()
 {
     //ILGen.AddInstruct(Instruction.ldarg_0);
     value.Create();
     ILGen.AddInstruct(Instruction.ret);
 }
Exemple #5
0
        public override void Create()
        {
            //foreach (var v in value)v.Create();

            if (funcName.ILValue == "CAST")
            {
                foreach (var v in value)
                {
                    v.Create();
                }
                switch (returnType.ILValue)
                {
                case "float32": ILGen.AddInstruct(Instruction.conv_r4); return;

                case "float64": ILGen.AddInstruct(Instruction.conv_r8); return;
                }
            }

            else if (funcName.ILValue == "COND")
            {
                var b = value[0] as BoolTree;


                b.left.Create();

                b.right.Create();
                var c1 = ILGen.ILNumber + 1;
                var c2 = ILGen.ILNumber + 2;
                ILGen.AddPreserved(c1);
                ILGen.AddPreserved(c2);


                switch (b.Op.ToString())
                {
                case ">":
                    ILGen.AddInstruct(Instruction.bgt_s, ILGen.GetILNumber(c1)); break;

                case "<":
                    ILGen.AddInstruct(Instruction.blt_s, ILGen.GetILNumber(c1)); break;

                case "<=":
                    ILGen.AddInstruct(Instruction.ble_s, ILGen.GetILNumber(c1));
                    break;

                case ">=":
                    ILGen.AddInstruct(Instruction.bge_s, ILGen.GetILNumber(c1));
                    break;

                case "==":
                    ILGen.AddInstruct(Instruction.beq_s, ILGen.GetILNumber(c1));
                    break;

                case "!=":
                    ILGen.AddInstruct(Instruction.bne_s, ILGen.GetILNumber(c1));
                    break;
                }

                value[2].Create();
                ILGen.AddInstruct(Instruction.br_s, ILGen.GetILNumber(c2));
                ILGen.UsePreserverd(c1);
                value[1].Create();
                ILGen.UsePreserverd(c2);
                ILGen.AddInstruct(Instruction.nop);
            }
            else
            {
                foreach (var v in value)
                {
                    v.Create();
                }
                var paramtypes = "";
                foreach (var a in arguments)
                {
                    paramtypes += a.ILValue + ",";
                }
                paramtypes = paramtypes.Remove(paramtypes.LastIndexOf(",", StringComparison.Ordinal), 1);
                ILGen.AddInstruct(Instruction.call,
                                  returnType.ILValue + " " + (isSystemFunction ? "[mscorlib]" : "") + funcName.ILValue + "(" +
                                  paramtypes + ")");
            }
        }