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); } }
private void CompileFields(CompileManager manager) { foreach (Field field in @class.Fields) { var fieldInfo = new CompileFieldInfo(); short nameIndex = manager.AddConstantUtf8(field.Name); short descriptorIndex = manager.AddConstantUtf8(field.ReturnType.GetDescriptor()); fieldInfo.Modifiers = field.Modifiers; fieldInfo.Name = nameIndex; fieldInfo.Descriptor = descriptorIndex; fieldInfo.Attributes = new List<CompileAttribute>(); //TODO: ConstantValue, Synthetic, Deprecated manager.AddField(fieldInfo); } }
public CompileMethodInfo Compile(CompileManager manager) { method.Resolve(manager.Imports); var methodInfo = new CompileMethodInfo(); short nameIndex = manager.AddConstantUtf8(method.Name); short descriptorIndex = manager.AddConstantUtf8(method.GetDescriptor()); CompileBody(manager); methodInfo.Modifiers = method.Modifiers; methodInfo.Name = nameIndex; methodInfo.Descriptor = descriptorIndex; methodInfo.Attributes = attributes; //TODO: Code, Exceptions, Synthetic, Deprecated return methodInfo; }
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); }