Beispiel #1
0
        public void TestIL()
        {
            var module = new VeinModuleBuilder("xuy");
            var clazz  = module.DefineClass("global::vein/lang/svack_pidars");

            clazz.Flags = ClassFlags.Public | ClassFlags.Static;
            var method = clazz.DefineMethod("insert_dick_into_svack", MethodFlags.Public, VeinTypeCode.TYPE_VOID.AsClass(), ("x", VeinTypeCode.TYPE_STRING));

            method.Flags = MethodFlags.Public | MethodFlags.Static;
            var body = method.GetGenerator();

            body.Emit(OpCodes.LDC_I4_S, 1448);
            body.Emit(OpCodes.LDC_I4_S, 228);
            body.Emit(OpCodes.ADD);
            body.Emit(OpCodes.LDC_I4_S, 2);
            body.Emit(OpCodes.XOR);
            body.Emit(OpCodes.RESERVED_0);
            body.Emit(OpCodes.LDF, "x");
            body.Emit(OpCodes.RET);


            var body_module = module.BakeByteArray();


            var asm = new IshtarAssembly();

            asm.AddSegment((".code", body_module));

            //IshtarAssembly.WriteTo(asm, new DirectoryInfo(@"C:\Users\ls-mi\Desktop\"));
        }
Beispiel #2
0
        public void ManualGenCallExternFunction()
        {
            var module = new VeinModuleBuilder("hello_world");
            var clazz  = module.DefineClass("hello_world%global::wave/lang/program");

            clazz.Flags = ClassFlags.Public | ClassFlags.Static;


            var method = clazz.DefineMethod("master", MethodFlags.Public | MethodFlags.Static,
                                            VeinTypeCode.TYPE_VOID.AsClass());
            var body = method.GetGenerator();

            var @while = body.DefineLabel();

            body.UseLabel(@while);
            body.Emit(OpCodes.NOP);
            body.Emit(OpCodes.NEWOBJ, VeinCore.StringClass);
            body.Emit(OpCodes.RESERVED_2);
            body.Emit(OpCodes.JMP, @while);
            body.Emit(OpCodes.RET);


            var body_module = module.BakeByteArray();


            var asm = new IshtarAssembly {
                Name = module.Name
            };

            asm.AddSegment((".code", body_module));

            IshtarAssembly.WriteTo(asm, new DirectoryInfo(@"C:\Users\ls-mi\Desktop\"));
            File.WriteAllText($@"C:\Users\ls-mi\Desktop\{module.Name}.wvil", module.BakeDebugString());
        }
Beispiel #3
0
        public void WriteTest()
        {
            var verSR    = new Version(2, 2, 2, 2);
            var moduleSR = new VeinModuleBuilder("set1", verSR);
            {
                moduleSR.Deps.AddRange(GetDeps());


                var @class = moduleSR.DefineClass("set1%global::wave/lang/SR");


                @class.Flags = ClassFlags.Public | ClassFlags.Static;
                var method = @class.DefineMethod("blank", MethodFlags.Public | MethodFlags.Static,
                                                 VeinTypeCode.TYPE_VOID.AsClass());

                var gen = method.GetGenerator();

                gen.Emit(OpCodes.NOP);

                moduleSR.BakeByteArray();
                moduleSR.BakeDebugString();

                var blank = new IshtarAssembly(moduleSR)
                {
                    Name = "set1", Version = verSR
                };


                IshtarAssembly.WriteTo(blank, new DirectoryInfo("C:/wavelib"));
            }


            {
                var ver    = new Version(2, 2, 2, 2);
                var module = new VeinModuleBuilder("set2", ver);
                module.Deps.AddRange(GetDeps());


                var @class = module.DefineClass("set2%global::wave/lang/DR");


                @class.Flags = ClassFlags.Public | ClassFlags.Static;
                var method = @class.DefineMethod("blank", MethodFlags.Public | MethodFlags.Static,
                                                 VeinTypeCode.TYPE_VOID.AsClass());

                var gen = method.GetGenerator();

                gen.Emit(OpCodes.NOP);

                module.BakeByteArray();
                module.BakeDebugString();

                module.Deps.Add(moduleSR);

                var blank = new IshtarAssembly(module)
                {
                    Name = "set2", Version = ver
                };


                IshtarAssembly.WriteTo(blank, new DirectoryInfo("C:/wavelib"));
            }
        }
Beispiel #4
0
        public void ManualGen()
        {
            var module = new VeinModuleBuilder("satl");
            var clazz  = module.DefineClass("satl%global::wave/lang/program");

            clazz.Flags = ClassFlags.Public | ClassFlags.Static;


            var fib = clazz.DefineMethod("fib",
                                         MethodFlags.Public | MethodFlags.Static,
                                         VeinTypeCode.TYPE_I8.AsClass(), ("x", VeinTypeCode.TYPE_I8));

            var fibGen = fib.GetGenerator();

            //fibGen.Emit(OpCodes.LDC_I8_1);
            //fibGen.Emit(OpCodes.LDC_I8_1);
            //fibGen.Emit(OpCodes.EQL);
            //fibGen.Emit(OpCodes.RET);

            var label_if_1 = fibGen.DefineLabel();
            var label_if_2 = fibGen.DefineLabel();
            var for_1      = fibGen.DefineLabel();
            var for_body   = fibGen.DefineLabel();

            // if (x == 0) return 0;
            fibGen.Emit(OpCodes.LDARG_1);
            fibGen.Emit(OpCodes.JMP_T, label_if_1);
            fibGen.Emit(OpCodes.LDC_I4_0);
            fibGen.Emit(OpCodes.RET);
            fibGen.UseLabel(label_if_1);
            // if (x == 1) return 1;
            fibGen.Emit(OpCodes.LDARG_1);
            fibGen.Emit(OpCodes.LDC_I4_1);
            fibGen.Emit(OpCodes.JMP_NN, label_if_2);
            fibGen.Emit(OpCodes.LDC_I4_1);
            fibGen.Emit(OpCodes.RET);
            fibGen.UseLabel(label_if_2);
            // var first, second, nth, i = 0;
            fibGen.EnsureLocal("first", VeinTypeCode.TYPE_I4.AsClass());
            fibGen.EnsureLocal("second", VeinTypeCode.TYPE_I4.AsClass());
            fibGen.EnsureLocal("nth", VeinTypeCode.TYPE_I4.AsClass());
            fibGen.EnsureLocal("i", VeinTypeCode.TYPE_I4.AsClass());
            // second, nth = 1; i = 2;
            fibGen.Emit(OpCodes.LDC_I4_1); fibGen.Emit(OpCodes.STLOC_1);
            fibGen.Emit(OpCodes.LDC_I4_1); fibGen.Emit(OpCodes.STLOC_2);
            fibGen.Emit(OpCodes.LDC_I4_2); fibGen.Emit(OpCodes.STLOC_3);

            // for
            //
            fibGen.Emit(OpCodes.JMP, for_1);
            fibGen.UseLabel(for_body);
            fibGen.Emit(OpCodes.LDLOC_0);
            fibGen.Emit(OpCodes.LDLOC_1);
            fibGen.Emit(OpCodes.ADD);
            fibGen.Emit(OpCodes.STLOC_2);

            fibGen.Emit(OpCodes.LDLOC_1);
            fibGen.Emit(OpCodes.STLOC_0);

            fibGen.Emit(OpCodes.LDLOC_2);
            fibGen.Emit(OpCodes.STLOC_1);

            // i++
            fibGen.Emit(OpCodes.LDLOC_3);
            fibGen.Emit(OpCodes.LDC_I4_1);
            fibGen.Emit(OpCodes.ADD);
            fibGen.Emit(OpCodes.STLOC_3);

            // var exceptionType =
            //    module.FindType(new QualityTypeName("std%global::wave/lang/Exception")).AsClass();

            //fibGen.Emit(OpCodes.NEWOBJ, exceptionType.FullName);
            //fibGen.Emit(OpCodes.CALL, exceptionType.FindMethod("ctor()"));
            //fibGen.Emit(OpCodes.THROW);


            // i <= n
            fibGen.UseLabel(for_1);
            fibGen.Emit(OpCodes.NOP);
            fibGen.Emit(OpCodes.LDARG_1);
            fibGen.Emit(OpCodes.LDLOC_3);
            fibGen.Emit(OpCodes.JMP_LQ, for_body);
            // return nth;
            fibGen.Emit(OpCodes.LDLOC_2);
            fibGen.Emit(OpCodes.RET);

            var method = clazz.DefineMethod("master", MethodFlags.Public | MethodFlags.Static,
                                            VeinTypeCode.TYPE_VOID.AsClass());
            var body = method.GetGenerator();



            body.Emit(OpCodes.LDC_I4_S, 120 /**/);
            body.Emit(OpCodes.CALL, fib);
            body.Emit(OpCodes.RESERVED_0);
            body.Emit(OpCodes.RESERVED_1);
            body.Emit(OpCodes.RET);
            //body.Emit(OpCodes.CALL);


            var body_module = module.BakeByteArray();


            var asm = new IshtarAssembly {
                Name = module.Name
            };

            asm.AddSegment((".code", body_module));

            IshtarAssembly.WriteTo(asm, new DirectoryInfo(@"C:\Users\ls-mi\Desktop\"));
            File.WriteAllText($@"C:\Users\ls-mi\Desktop\{module.Name}.wvil", module.BakeDebugString());
        }