コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public void Compile(ByteCodeGenerator generator)
        {
            var variable = generator.DefineVariable(node.Name, node.Type);

            if (node.Initialiser != null)
            {
                new AssignmentCompiler(
                    new AssignmentNode.NormalAssignNode
                    {
                        Left = new PrimaryNode.TermIdentifierExpression { Identifier = node.Name },
                        Right = new TranslateNode { Child = node.Initialiser }
                    }).Compile(generator);

                new LocalItem(generator, variable).Store();
            }
        }
コード例 #3
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);
        }