private void CompileBody(CompileManager manager)
        {
            attributes = new List<CompileAttribute>();
            generator = new ByteCodeGenerator(manager, (Method)constructor);

            foreach (Method.Parameter parameter in constructor.Parameters)
            {
                generator.DefineVariable(parameter.Name, parameter.Type);
            }

            new ConstructorBlockCompiler(constructor.Body).Compile(generator);

            attributes.Add(new CompileAttributeCode
            {
                NameIndex = manager.AddConstantUtf8(new CompileAttributeCode().Name),
                Code = generator.GetBytes(),
                Attributes = new List<CompileAttribute>(),
                ExceptionTable = new List<CompileAttributeCode.ExceptionTableEntry>(),
                MaxLocals = generator.MaxVariables,
                MaxStack = generator.MaxStack
            });

            var stackMapTable = generator.StackMapTable;
            if (stackMapTable != null)
            {
                stackMapTable.NameIndex = manager.AddConstantUtf8(stackMapTable.Name);

                attributes.Add(stackMapTable);
            }
        }
Ejemplo n.º 2
0
        private void CompileBody(CompileManager manager)
        {
            attributes = new List<CompileAttribute>();
            generator = new ByteCodeGenerator(manager, method);

            foreach (Method.Parameter parameter in method.Parameters)
            {
                generator.DefineVariable(parameter.Name, parameter.Type);
            }

            new BlockCompiler(method.Body).Compile(generator);

            if (method.ReturnType.Name == "void")
            {
                generator.Emit(OpCodeValue.@return);
            }

            var code = new CompileAttributeCode
            {
                NameIndex = manager.AddConstantUtf8(new CompileAttributeCode().Name),
                Code = generator.GetBytes(),
                Attributes = new List<CompileAttribute>(),
                ExceptionTable = new List<CompileAttributeCode.ExceptionTableEntry>(),
                MaxLocals = generator.MaxVariables,
                MaxStack = generator.MaxStack
            };

            var stackMapTable = generator.StackMapTable;
            if (stackMapTable != null)
            {
                stackMapTable.NameIndex = manager.AddConstantUtf8(stackMapTable.Name);

                code.Attributes.Add(stackMapTable);
            }

            attributes.Add(code);
        }