Compare commits
1 commit
master
...
feature/te
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e0e5ff8ea |
12 changed files with 296 additions and 1632 deletions
|
|
@ -18,7 +18,9 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
run_cmd.addPassthruArgs();
|
if (b.args) |args| {
|
||||||
|
run_cmd.addArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
|
||||||
12
flake.lock
generated
12
flake.lock
generated
|
|
@ -5,11 +5,11 @@
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1791914995,
|
"lastModified": 1731533236,
|
||||||
"narHash": "sha256-Zf/xfQEAasnwnmEfHqW/4hjDE/s44yn2hD4RuVIZRjA=",
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "b7a79d3fea1e214f6d668d521cecec0c01e26544",
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -20,11 +20,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1793110635,
|
"lastModified": 1781577229,
|
||||||
"narHash": "sha256-dhoW6VgFWlaodSY5jrBn+CF2FLmaUvDVgM7+C7T2+NM=",
|
"narHash": "sha256-lrp67w8AulE9Ks53n27I45ADSzbOCn4H+CNW1Ck8B+8=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "31ecbaca1bdefa45dffc409f0250bd8039ea0010",
|
"rev": "567a49d1913ce81ac6e9582e3553dd90a955875f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@ pub const ClassAccessFlags = EnumFlags(enum(u16) {
|
||||||
pub const ParseError = std.Io.Reader.Error || std.mem.Allocator.Error || error {
|
pub const ParseError = std.Io.Reader.Error || std.mem.Allocator.Error || error {
|
||||||
InvalidMagicNumber,
|
InvalidMagicNumber,
|
||||||
InvalidTag,
|
InvalidTag,
|
||||||
InvalidOp,
|
|
||||||
InvalidArrayType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ResolveError = error {
|
pub const ResolveError = error {
|
||||||
|
|
@ -121,12 +119,8 @@ fn parseFields(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: st
|
||||||
const fields = try allocator.alloc(FieldInfo, fields_count);
|
const fields = try allocator.alloc(FieldInfo, fields_count);
|
||||||
errdefer allocator.free(fields);
|
errdefer allocator.free(fields);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| fields[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (0..fields_count) |i| {
|
for (0..fields_count) |i| {
|
||||||
fields[i] = try .parse(input, constant_pool, allocator);
|
fields[i] = try FieldInfo.parse(input, constant_pool, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
|
|
@ -137,12 +131,8 @@ fn parseMethods(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: s
|
||||||
const methods = try allocator.alloc(MethodInfo, methods_count);
|
const methods = try allocator.alloc(MethodInfo, methods_count);
|
||||||
errdefer allocator.free(methods);
|
errdefer allocator.free(methods);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| methods[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (0..methods_count) |i| {
|
for (0..methods_count) |i| {
|
||||||
methods[i] = try .parse(input, constant_pool, allocator);
|
methods[i] = try .parse(input, constant_pool, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return methods;
|
return methods;
|
||||||
|
|
@ -153,12 +143,8 @@ pub fn parseAttributes(input: *std.Io.Reader, constant_pool: ConstantPool, alloc
|
||||||
const attributes = try allocator.alloc(AttributeInfo, attributes_count);
|
const attributes = try allocator.alloc(AttributeInfo, attributes_count);
|
||||||
errdefer allocator.free(attributes);
|
errdefer allocator.free(attributes);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| attributes[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (0..attributes_count) |i| {
|
for (0..attributes_count) |i| {
|
||||||
attributes[i] = try .parse(input, constant_pool, allocator);
|
attributes[i] = try AttributeInfo.parse(input, constant_pool, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
|
|
@ -166,25 +152,49 @@ pub fn parseAttributes(input: *std.Io.Reader, constant_pool: ConstantPool, alloc
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
self.constant_pool.deinit(allocator);
|
self.constant_pool.deinit(allocator);
|
||||||
|
self.freeInterfaces(allocator);
|
||||||
|
self.freeFields(allocator);
|
||||||
|
self.freeMethods(allocator);
|
||||||
|
self.freeAttributes(allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn freeInterfaces(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
allocator.free(self.interfaces);
|
allocator.free(self.interfaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn freeFields(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.fields) |*field_info| {
|
for (self.fields) |*field_info| {
|
||||||
field_info.deinit(allocator);
|
field_info.deinit(allocator);
|
||||||
}
|
}
|
||||||
allocator.free(self.fields);
|
allocator.free(self.fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn freeMethods(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.methods) |*method_info| {
|
for (self.methods) |*method_info| {
|
||||||
method_info.deinit(allocator);
|
method_info.deinit(allocator);
|
||||||
}
|
}
|
||||||
allocator.free(self.methods);
|
allocator.free(self.methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn freeAttributes(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.attributes) |*attr| {
|
for (self.attributes) |*attr| {
|
||||||
attr.deinit(allocator);
|
attr.deinit(allocator);
|
||||||
}
|
}
|
||||||
allocator.free(self.attributes);
|
allocator.free(self.attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn jsonStringify(self: *const Self, jws: *std.json.Stringify) !void {
|
||||||
|
try jws.beginObject();
|
||||||
|
|
||||||
|
inline for (std.meta.fields(Self)) |field| {
|
||||||
|
if (comptime std.mem.eql(u8, field.name, "allocator")) continue;
|
||||||
|
try jws.objectField(field.name);
|
||||||
|
try jws.write(@field(self, field.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
try jws.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn format(self: *const Self, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
pub fn format(self: *const Self, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
||||||
const depth = 2;
|
const depth = 2;
|
||||||
var indent: u8 = 0;
|
var indent: u8 = 0;
|
||||||
|
|
@ -254,3 +264,4 @@ pub fn thisClass(self: *const Self) ResolveError!ConstantPool.Info {
|
||||||
pub fn superClass(self: *const Self) ResolveError!?ConstantPool.Info {
|
pub fn superClass(self: *const Self) ResolveError!?ConstantPool.Info {
|
||||||
return self.constant_pool.getTagOptional(self.super_class, .class);
|
return self.constant_pool.getTagOptional(self.super_class, .class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -319,9 +319,7 @@ pub const AttributeInfo = union(enum) {
|
||||||
defer instr_indent -= 1;
|
defer instr_indent -= 1;
|
||||||
|
|
||||||
try w.splatByteAll(' ', depth * instr_indent);
|
try w.splatByteAll(' ', depth * instr_indent);
|
||||||
try w.print("{d}:\n", .{i});
|
try w.print("{d}: 0x{x}\n", .{ i, instr });
|
||||||
|
|
||||||
try instr.indentedFormat(w, depth, instr_indent + 1, constant_pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try w.splatByteAll(' ', depth * indent);
|
try w.splatByteAll(' ', depth * indent);
|
||||||
|
|
@ -692,14 +690,12 @@ pub const ConstantValue = struct {
|
||||||
pub const Code = struct {
|
pub const Code = struct {
|
||||||
max_stack: u16,
|
max_stack: u16,
|
||||||
max_locals: u16,
|
max_locals: u16,
|
||||||
code: []Instruction,
|
code: []u8,
|
||||||
exception_table: []ExceptionHandler,
|
exception_table: []ExceptionHandler,
|
||||||
attributes: []AttributeInfo,
|
attributes: []AttributeInfo,
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
pub const Instruction = @import("Code/Instruction.zig").Instruction;
|
|
||||||
|
|
||||||
pub const ExceptionHandler = struct {
|
pub const ExceptionHandler = struct {
|
||||||
start_pc: u16,
|
start_pc: u16,
|
||||||
end_pc: u16,
|
end_pc: u16,
|
||||||
|
|
@ -740,30 +736,12 @@ pub const Code = struct {
|
||||||
const max_locals = try input.takeInt(u16, .big);
|
const max_locals = try input.takeInt(u16, .big);
|
||||||
|
|
||||||
const code_length = try input.takeInt(u32, .big);
|
const code_length = try input.takeInt(u32, .big);
|
||||||
var code_reader_buf: [1024]u8 = undefined;
|
const code = try input.readAlloc(allocator, code_length);
|
||||||
var code_reader = input.limited(.limited(code_length), &code_reader_buf);
|
errdefer allocator.free(code);
|
||||||
var code = &code_reader.interface;
|
|
||||||
var byte_index: usize = 0;
|
|
||||||
var instructions: std.ArrayList(Instruction) = .empty;
|
|
||||||
defer instructions.deinit(allocator);
|
|
||||||
|
|
||||||
var parsed_instructions: usize = 0;
|
|
||||||
errdefer for (0..parsed_instructions) |i| instructions.items[i].deinit(allocator);
|
|
||||||
|
|
||||||
loop: while (true) {
|
|
||||||
_ = code.peekByte() catch |err| switch (err) {
|
|
||||||
error.EndOfStream => break :loop,
|
|
||||||
else => return err,
|
|
||||||
};
|
|
||||||
|
|
||||||
try instructions.append(allocator, try .parse(code, allocator, &byte_index));
|
|
||||||
parsed_instructions += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const exception_table_length = try input.takeInt(u16, .big);
|
const exception_table_length = try input.takeInt(u16, .big);
|
||||||
const exception_table = try allocator.alloc(ExceptionHandler, exception_table_length);
|
const exception_table = try allocator.alloc(ExceptionHandler, exception_table_length);
|
||||||
errdefer allocator.free(exception_table);
|
errdefer allocator.free(exception_table);
|
||||||
|
|
||||||
for (exception_table) |*exception_handler| {
|
for (exception_table) |*exception_handler| {
|
||||||
exception_handler.* = .{
|
exception_handler.* = .{
|
||||||
.start_pc = try input.takeInt(u16, .big),
|
.start_pc = try input.takeInt(u16, .big),
|
||||||
|
|
@ -776,32 +754,22 @@ pub const Code = struct {
|
||||||
const attribute_count = try input.takeInt(u16, .big);
|
const attribute_count = try input.takeInt(u16, .big);
|
||||||
const attributes = try allocator.alloc(AttributeInfo, attribute_count);
|
const attributes = try allocator.alloc(AttributeInfo, attribute_count);
|
||||||
errdefer allocator.free(attributes);
|
errdefer allocator.free(attributes);
|
||||||
|
|
||||||
var parsed_attributes: usize = 0;
|
|
||||||
errdefer for (0..parsed_attributes) |i| attributes[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (attributes) |*attribute| {
|
for (attributes) |*attribute| {
|
||||||
attribute.* = try .parse(input, constant_pool, allocator);
|
attribute.* = try .parse(input, constant_pool, allocator);
|
||||||
parsed_attributes += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.max_stack = max_stack,
|
.max_stack = max_stack,
|
||||||
.max_locals = max_locals,
|
.max_locals = max_locals,
|
||||||
.code = try instructions.toOwnedSlice(allocator),
|
.code = code,
|
||||||
.exception_table = exception_table,
|
.exception_table = exception_table,
|
||||||
.attributes = attributes,
|
.attributes = attributes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.code) |*instruction| {
|
|
||||||
instruction.deinit(allocator);
|
|
||||||
}
|
|
||||||
allocator.free(self.code);
|
allocator.free(self.code);
|
||||||
|
|
||||||
allocator.free(self.exception_table);
|
allocator.free(self.exception_table);
|
||||||
|
|
||||||
for (self.attributes) |*attr| {
|
for (self.attributes) |*attr| {
|
||||||
attr.deinit(allocator);
|
attr.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
@ -877,7 +845,6 @@ pub const StackMapTable = struct {
|
||||||
const length = frame_type - 251;
|
const length = frame_type - 251;
|
||||||
const locals = try allocator.alloc(StackMapTable.VerificationTypeInfo, length);
|
const locals = try allocator.alloc(StackMapTable.VerificationTypeInfo, length);
|
||||||
errdefer allocator.free(locals);
|
errdefer allocator.free(locals);
|
||||||
|
|
||||||
for (locals) |*local| {
|
for (locals) |*local| {
|
||||||
local.* = try .parse(input);
|
local.* = try .parse(input);
|
||||||
}
|
}
|
||||||
|
|
@ -895,7 +862,6 @@ pub const StackMapTable = struct {
|
||||||
const number_of_locals = try input.takeInt(u16, .big);
|
const number_of_locals = try input.takeInt(u16, .big);
|
||||||
const locals = try allocator.alloc(StackMapTable.VerificationTypeInfo, number_of_locals);
|
const locals = try allocator.alloc(StackMapTable.VerificationTypeInfo, number_of_locals);
|
||||||
errdefer allocator.free(locals);
|
errdefer allocator.free(locals);
|
||||||
|
|
||||||
for (locals) |*local| {
|
for (locals) |*local| {
|
||||||
local.* = try .parse(input);
|
local.* = try .parse(input);
|
||||||
}
|
}
|
||||||
|
|
@ -903,7 +869,6 @@ pub const StackMapTable = struct {
|
||||||
const number_of_stack_items = try input.takeInt(u16, .big);
|
const number_of_stack_items = try input.takeInt(u16, .big);
|
||||||
const stack = try allocator.alloc(StackMapTable.VerificationTypeInfo, number_of_stack_items);
|
const stack = try allocator.alloc(StackMapTable.VerificationTypeInfo, number_of_stack_items);
|
||||||
errdefer allocator.free(stack);
|
errdefer allocator.free(stack);
|
||||||
|
|
||||||
for (stack) |*stack_item| {
|
for (stack) |*stack_item| {
|
||||||
stack_item.* = try .parse(input);
|
stack_item.* = try .parse(input);
|
||||||
}
|
}
|
||||||
|
|
@ -1119,13 +1084,8 @@ pub const StackMapTable = struct {
|
||||||
const number_of_entries = try input.takeInt(u16, .big);
|
const number_of_entries = try input.takeInt(u16, .big);
|
||||||
const entries = try allocator.alloc(StackMapTable.StackMapFrame, number_of_entries);
|
const entries = try allocator.alloc(StackMapTable.StackMapFrame, number_of_entries);
|
||||||
errdefer allocator.free(entries);
|
errdefer allocator.free(entries);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| entries[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (entries) |*entry| {
|
for (entries) |*entry| {
|
||||||
entry.* = try .parse(input, allocator);
|
entry.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1150,7 +1110,6 @@ pub const Exceptions = struct {
|
||||||
const number_of_exceptions = try input.takeInt(u16, .big);
|
const number_of_exceptions = try input.takeInt(u16, .big);
|
||||||
const exception_index_table = try allocator.alloc(u16, number_of_exceptions);
|
const exception_index_table = try allocator.alloc(u16, number_of_exceptions);
|
||||||
errdefer allocator.free(exception_index_table);
|
errdefer allocator.free(exception_index_table);
|
||||||
|
|
||||||
for (exception_index_table) |*exception_index| {
|
for (exception_index_table) |*exception_index| {
|
||||||
exception_index.* = try input.takeInt(u16, .big);
|
exception_index.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
@ -1236,7 +1195,6 @@ pub const InnerClasses = struct {
|
||||||
const number_of_classes = try input.takeInt(u16, .big);
|
const number_of_classes = try input.takeInt(u16, .big);
|
||||||
const classes = try allocator.alloc(InnerClass, number_of_classes);
|
const classes = try allocator.alloc(InnerClass, number_of_classes);
|
||||||
errdefer allocator.free(classes);
|
errdefer allocator.free(classes);
|
||||||
|
|
||||||
for (classes) |*class| {
|
for (classes) |*class| {
|
||||||
class.* = .{
|
class.* = .{
|
||||||
.inner_class_info_index = try input.takeInt(u16, .big),
|
.inner_class_info_index = try input.takeInt(u16, .big),
|
||||||
|
|
@ -1355,7 +1313,6 @@ pub const LineNumberTable = struct {
|
||||||
const line_number_table_length = try input.takeInt(u16, .big);
|
const line_number_table_length = try input.takeInt(u16, .big);
|
||||||
const line_number_table = try allocator.alloc(LineNumber, line_number_table_length);
|
const line_number_table = try allocator.alloc(LineNumber, line_number_table_length);
|
||||||
errdefer allocator.free(line_number_table);
|
errdefer allocator.free(line_number_table);
|
||||||
|
|
||||||
for (line_number_table) |*line_number| {
|
for (line_number_table) |*line_number| {
|
||||||
line_number.* = .{
|
line_number.* = .{
|
||||||
.start_pc = try input.takeInt(u16, .big),
|
.start_pc = try input.takeInt(u16, .big),
|
||||||
|
|
@ -1422,7 +1379,6 @@ pub const LocalVariableTable = struct {
|
||||||
const local_variable_table_length = try input.takeInt(u16, .big);
|
const local_variable_table_length = try input.takeInt(u16, .big);
|
||||||
const local_variable_table = try allocator.alloc(LocalVariable, local_variable_table_length);
|
const local_variable_table = try allocator.alloc(LocalVariable, local_variable_table_length);
|
||||||
errdefer allocator.free(local_variable_table);
|
errdefer allocator.free(local_variable_table);
|
||||||
|
|
||||||
for (local_variable_table) |*local_variable| {
|
for (local_variable_table) |*local_variable| {
|
||||||
local_variable.* = .{
|
local_variable.* = .{
|
||||||
.start_pc = try input.takeInt(u16, .big),
|
.start_pc = try input.takeInt(u16, .big),
|
||||||
|
|
@ -1492,7 +1448,6 @@ pub const LocalVariableTypeTable = struct {
|
||||||
const local_variable_type_table_length = try input.takeInt(u16, .big);
|
const local_variable_type_table_length = try input.takeInt(u16, .big);
|
||||||
const local_variable_type_table = try allocator.alloc(LocalVariableType, local_variable_type_table_length);
|
const local_variable_type_table = try allocator.alloc(LocalVariableType, local_variable_type_table_length);
|
||||||
errdefer allocator.free(local_variable_type_table);
|
errdefer allocator.free(local_variable_type_table);
|
||||||
|
|
||||||
for (local_variable_type_table) |*local_variable_type| {
|
for (local_variable_type_table) |*local_variable_type| {
|
||||||
local_variable_type.* = .{
|
local_variable_type.* = .{
|
||||||
.start_pc = try input.takeInt(u16, .big),
|
.start_pc = try input.takeInt(u16, .big),
|
||||||
|
|
@ -1530,7 +1485,7 @@ pub const ElementValue = union(enum) {
|
||||||
},
|
},
|
||||||
|
|
||||||
pub const ConstValue = struct {
|
pub const ConstValue = struct {
|
||||||
type: Type,
|
@"type": Type,
|
||||||
index: u16,
|
index: u16,
|
||||||
|
|
||||||
pub const Type = enum(u8) {
|
pub const Type = enum(u8) {
|
||||||
|
|
@ -1547,7 +1502,7 @@ pub const ElementValue = union(enum) {
|
||||||
|
|
||||||
pub fn value(self: *const ConstValue, constant_pool: ConstantPool) ResolveError!ConstantPool.Info {
|
pub fn value(self: *const ConstValue, constant_pool: ConstantPool) ResolveError!ConstantPool.Info {
|
||||||
const value_ = try constant_pool.get(self.index);
|
const value_ = try constant_pool.get(self.index);
|
||||||
return switch (self.type) {
|
return switch (self.@"type") {
|
||||||
.byte, .char, .int, .short, .boolean => blk: {
|
.byte, .char, .int, .short, .boolean => blk: {
|
||||||
if (!value_.is(.integer)) break :blk ResolveError.InvalidConstantType;
|
if (!value_.is(.integer)) break :blk ResolveError.InvalidConstantType;
|
||||||
break :blk value_;
|
break :blk value_;
|
||||||
|
|
@ -1598,7 +1553,7 @@ pub const ElementValue = union(enum) {
|
||||||
return switch (tag) {
|
return switch (tag) {
|
||||||
'B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z', 's' => .{
|
'B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z', 's' => .{
|
||||||
.const_value = .{
|
.const_value = .{
|
||||||
.type = @fromBackingInt(@intCast(tag)),
|
.@"type" = @enumFromInt(tag),
|
||||||
.index = try input.takeInt(u16, .big),
|
.index = try input.takeInt(u16, .big),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1621,13 +1576,8 @@ pub const ElementValue = union(enum) {
|
||||||
const num_values = try input.takeInt(u16, .big);
|
const num_values = try input.takeInt(u16, .big);
|
||||||
const values = try allocator.alloc(ElementValue, num_values);
|
const values = try allocator.alloc(ElementValue, num_values);
|
||||||
errdefer allocator.free(values);
|
errdefer allocator.free(values);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| values[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (values) |*value| {
|
for (values) |*value| {
|
||||||
value.* = try .parse(input, allocator);
|
value.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break :blk .{
|
break :blk .{
|
||||||
|
|
@ -1748,16 +1698,11 @@ pub const Annotation = struct {
|
||||||
const num_element_value_pairs = try input.takeInt(u16, .big);
|
const num_element_value_pairs = try input.takeInt(u16, .big);
|
||||||
const element_value_pairs = try allocator.alloc(ElementValuePair, num_element_value_pairs);
|
const element_value_pairs = try allocator.alloc(ElementValuePair, num_element_value_pairs);
|
||||||
errdefer allocator.free(element_value_pairs);
|
errdefer allocator.free(element_value_pairs);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| element_value_pairs[i].value.deinit(allocator);
|
|
||||||
|
|
||||||
for (element_value_pairs) |*element_value_pair| {
|
for (element_value_pairs) |*element_value_pair| {
|
||||||
element_value_pair.* = .{
|
element_value_pair.* = .{
|
||||||
.element_name_index = try input.takeInt(u16, .big),
|
.element_name_index = try input.takeInt(u16, .big),
|
||||||
.value = try .parse(input, allocator),
|
.value = try .parse(input, allocator),
|
||||||
};
|
};
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1780,7 +1725,7 @@ pub const Annotation = struct {
|
||||||
indent: u8,
|
indent: u8,
|
||||||
constant_pool: ConstantPool,
|
constant_pool: ConstantPool,
|
||||||
) std.Io.Writer.Error!void {
|
) std.Io.Writer.Error!void {
|
||||||
const type_ = self.type(constant_pool) catch return error.WriteFailed;
|
const type_ = self.@"type"(constant_pool) catch return error.WriteFailed;
|
||||||
try w.splatByteAll(' ', depth * indent);
|
try w.splatByteAll(' ', depth * indent);
|
||||||
_ = try w.write("type:\n");
|
_ = try w.write("type:\n");
|
||||||
try type_.indentedFormat(w, depth, indent + 1, constant_pool);
|
try type_.indentedFormat(w, depth, indent + 1, constant_pool);
|
||||||
|
|
@ -1812,13 +1757,8 @@ pub const RuntimeVisibleAnnotations = struct {
|
||||||
const num_annotations = try input.takeInt(u16, .big);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
const annotations = try allocator.alloc(Annotation, num_annotations);
|
const annotations = try allocator.alloc(Annotation, num_annotations);
|
||||||
errdefer allocator.free(annotations);
|
errdefer allocator.free(annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (annotations) |*annotation| {
|
for (annotations) |*annotation| {
|
||||||
annotation.* = try .parse(input, allocator);
|
annotation.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1843,13 +1783,8 @@ pub const RuntimeInvisibleAnnotations = struct {
|
||||||
const num_annotations = try input.takeInt(u16, .big);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
const annotations = try allocator.alloc(Annotation, num_annotations);
|
const annotations = try allocator.alloc(Annotation, num_annotations);
|
||||||
errdefer allocator.free(annotations);
|
errdefer allocator.free(annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (annotations) |*annotation| {
|
for (annotations) |*annotation| {
|
||||||
annotation.* = try .parse(input, allocator);
|
annotation.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1868,33 +1803,6 @@ pub const RuntimeInvisibleAnnotations = struct {
|
||||||
pub const ParameterAnnotation = struct {
|
pub const ParameterAnnotation = struct {
|
||||||
annotations: []Annotation,
|
annotations: []Annotation,
|
||||||
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
|
||||||
const num_annotations = try input.takeInt(u16, .big);
|
|
||||||
const annotations = try allocator.alloc(Annotation, num_annotations);
|
|
||||||
errdefer allocator.free(annotations);
|
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (annotations) |*annotation| {
|
|
||||||
annotation.* = try .parse(input, allocator);
|
|
||||||
parsed += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return .{
|
|
||||||
.annotations = annotations,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
|
||||||
for (self.annotations) |*annotation| {
|
|
||||||
annotation.deinit(allocator);
|
|
||||||
}
|
|
||||||
allocator.free(self.annotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn indentedFormat(
|
pub fn indentedFormat(
|
||||||
self: *const ParameterAnnotation,
|
self: *const ParameterAnnotation,
|
||||||
w: *std.Io.Writer,
|
w: *std.Io.Writer,
|
||||||
|
|
@ -1925,13 +1833,17 @@ pub const RuntimeVisibleParameterAnnotations = struct {
|
||||||
const num_parameters = try input.takeByte();
|
const num_parameters = try input.takeByte();
|
||||||
const parameter_annotations = try allocator.alloc(ParameterAnnotation, num_parameters);
|
const parameter_annotations = try allocator.alloc(ParameterAnnotation, num_parameters);
|
||||||
errdefer allocator.free(parameter_annotations);
|
errdefer allocator.free(parameter_annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| parameter_annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (parameter_annotations) |*parameter_annotation| {
|
for (parameter_annotations) |*parameter_annotation| {
|
||||||
parameter_annotation.* = try .parse(input, allocator);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
parsed += 1;
|
const annotations = try allocator.alloc(Annotation, num_annotations);
|
||||||
|
errdefer allocator.free(annotations);
|
||||||
|
for (annotations) |*annotation| {
|
||||||
|
annotation.* = try .parse(input, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_annotation.* = .{
|
||||||
|
.annotations = annotations,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1940,8 +1852,11 @@ pub const RuntimeVisibleParameterAnnotations = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.parameter_annotations) |*parameter_annotation| {
|
for (self.parameter_annotations) |parameter_annotation| {
|
||||||
parameter_annotation.deinit(allocator);
|
for (parameter_annotation.annotations) |*annotation| {
|
||||||
|
annotation.deinit(allocator);
|
||||||
|
}
|
||||||
|
allocator.free(parameter_annotation.annotations);
|
||||||
}
|
}
|
||||||
allocator.free(self.parameter_annotations);
|
allocator.free(self.parameter_annotations);
|
||||||
}
|
}
|
||||||
|
|
@ -1956,13 +1871,17 @@ pub const RuntimeInvisibleParameterAnnotations = struct {
|
||||||
const num_parameters = try input.takeByte();
|
const num_parameters = try input.takeByte();
|
||||||
const parameter_annotations = try allocator.alloc(ParameterAnnotation, num_parameters);
|
const parameter_annotations = try allocator.alloc(ParameterAnnotation, num_parameters);
|
||||||
errdefer allocator.free(parameter_annotations);
|
errdefer allocator.free(parameter_annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| parameter_annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (parameter_annotations) |*parameter_annotation| {
|
for (parameter_annotations) |*parameter_annotation| {
|
||||||
parameter_annotation.* = try .parse(input, allocator);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
parsed += 1;
|
const annotations = try allocator.alloc(Annotation, num_annotations);
|
||||||
|
errdefer allocator.free(annotations);
|
||||||
|
for (annotations) |*annotation| {
|
||||||
|
annotation.* = try .parse(input, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_annotation.* = .{
|
||||||
|
.annotations = annotations,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -1971,8 +1890,11 @@ pub const RuntimeInvisibleParameterAnnotations = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.parameter_annotations) |*parameter_annotation| {
|
for (self.parameter_annotations) |parameter_annotation| {
|
||||||
parameter_annotation.deinit(allocator);
|
for (parameter_annotation.annotations) |*annotation| {
|
||||||
|
annotation.deinit(allocator);
|
||||||
|
}
|
||||||
|
allocator.free(parameter_annotation.annotations);
|
||||||
}
|
}
|
||||||
allocator.free(self.parameter_annotations);
|
allocator.free(self.parameter_annotations);
|
||||||
}
|
}
|
||||||
|
|
@ -2202,7 +2124,6 @@ pub const TypeAnnotation = struct {
|
||||||
const length = try input.takeByte();
|
const length = try input.takeByte();
|
||||||
const paths = try allocator.alloc(Path, length);
|
const paths = try allocator.alloc(Path, length);
|
||||||
errdefer allocator.free(paths);
|
errdefer allocator.free(paths);
|
||||||
|
|
||||||
for (paths) |*path| {
|
for (paths) |*path| {
|
||||||
path.* = .{
|
path.* = .{
|
||||||
.type_path_kind = try input.takeByte(),
|
.type_path_kind = try input.takeByte(),
|
||||||
|
|
@ -2240,7 +2161,7 @@ pub const TypeAnnotation = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
||||||
const target_type: TargetType = @fromBackingInt(@intCast(try input.takeInt(u8, .big)));
|
const target_type: TargetType = @enumFromInt(try input.takeInt(u8, .big));
|
||||||
const target_info: TargetInfo = switch (target_type) {
|
const target_info: TargetInfo = switch (target_type) {
|
||||||
.type_parameter_generic_class_interface, .type_parameter_generic_method_constructor => .{
|
.type_parameter_generic_class_interface, .type_parameter_generic_method_constructor => .{
|
||||||
.type_parameter = .{
|
.type_parameter = .{
|
||||||
|
|
@ -2275,7 +2196,6 @@ pub const TypeAnnotation = struct {
|
||||||
const table_length = try input.takeInt(u16, .big);
|
const table_length = try input.takeInt(u16, .big);
|
||||||
const table = try allocator.alloc(TargetInfo.Localvar.Entry, table_length);
|
const table = try allocator.alloc(TargetInfo.Localvar.Entry, table_length);
|
||||||
errdefer allocator.free(table);
|
errdefer allocator.free(table);
|
||||||
|
|
||||||
for (table) |*entry| {
|
for (table) |*entry| {
|
||||||
entry.* = .{
|
entry.* = .{
|
||||||
.start_pc = try input.takeInt(u16, .big),
|
.start_pc = try input.takeInt(u16, .big),
|
||||||
|
|
@ -2316,16 +2236,11 @@ pub const TypeAnnotation = struct {
|
||||||
const num_element_value_pairs = try input.takeInt(u16, .big);
|
const num_element_value_pairs = try input.takeInt(u16, .big);
|
||||||
const element_value_pairs = try allocator.alloc(ElementValuePair, num_element_value_pairs);
|
const element_value_pairs = try allocator.alloc(ElementValuePair, num_element_value_pairs);
|
||||||
errdefer allocator.free(element_value_pairs);
|
errdefer allocator.free(element_value_pairs);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| element_value_pairs[i].value.deinit(allocator);
|
|
||||||
|
|
||||||
for (element_value_pairs) |*element_value_pair| {
|
for (element_value_pairs) |*element_value_pair| {
|
||||||
element_value_pair.* = .{
|
element_value_pair.* = .{
|
||||||
.element_name_index = try input.takeInt(u16, .big),
|
.element_name_index = try input.takeInt(u16, .big),
|
||||||
.value = try .parse(input, allocator),
|
.value = try .parse(input, allocator),
|
||||||
};
|
};
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -2342,7 +2257,6 @@ pub const TypeAnnotation = struct {
|
||||||
.localvar => |localvar| allocator.free(localvar.table),
|
.localvar => |localvar| allocator.free(localvar.table),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
for (self.element_value_pairs) |*element_value_pair| {
|
for (self.element_value_pairs) |*element_value_pair| {
|
||||||
element_value_pair.value.deinit(allocator);
|
element_value_pair.value.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
@ -2367,7 +2281,7 @@ pub const TypeAnnotation = struct {
|
||||||
_ = try w.write("target_path:\n");
|
_ = try w.write("target_path:\n");
|
||||||
try self.target_path.indentedFormat(w, depth + 1, indent);
|
try self.target_path.indentedFormat(w, depth + 1, indent);
|
||||||
|
|
||||||
const type_ = self.type(constant_pool) catch return error.WriteFailed;
|
const type_ = self.@"type"(constant_pool) catch return error.WriteFailed;
|
||||||
try w.splatByteAll(' ', depth * indent);
|
try w.splatByteAll(' ', depth * indent);
|
||||||
_ = try w.write("type:\n");
|
_ = try w.write("type:\n");
|
||||||
try type_.indentedFormat(w, depth, indent + 1, constant_pool);
|
try type_.indentedFormat(w, depth, indent + 1, constant_pool);
|
||||||
|
|
@ -2399,13 +2313,8 @@ pub const RuntimeVisibleTypeAnnotations = struct {
|
||||||
const num_annotations = try input.takeInt(u16, .big);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
const type_annotations = try allocator.alloc(TypeAnnotation, num_annotations);
|
const type_annotations = try allocator.alloc(TypeAnnotation, num_annotations);
|
||||||
errdefer allocator.free(type_annotations);
|
errdefer allocator.free(type_annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| type_annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (type_annotations) |*type_annotation| {
|
for (type_annotations) |*type_annotation| {
|
||||||
type_annotation.* = try .parse(input, allocator);
|
type_annotation.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -2430,13 +2339,8 @@ pub const RuntimeInvisibleTypeAnnotations = struct {
|
||||||
const num_annotations = try input.takeInt(u16, .big);
|
const num_annotations = try input.takeInt(u16, .big);
|
||||||
const type_annotations = try allocator.alloc(TypeAnnotation, num_annotations);
|
const type_annotations = try allocator.alloc(TypeAnnotation, num_annotations);
|
||||||
errdefer allocator.free(type_annotations);
|
errdefer allocator.free(type_annotations);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| type_annotations[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (type_annotations) |*type_annotation| {
|
for (type_annotations) |*type_annotation| {
|
||||||
type_annotation.* = try .parse(input, allocator);
|
type_annotation.* = try .parse(input, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -2513,17 +2417,12 @@ pub const BootstrapMethods = struct {
|
||||||
const num_bootstrap_methods = try input.takeInt(u16, .big);
|
const num_bootstrap_methods = try input.takeInt(u16, .big);
|
||||||
const bootstrap_methods = try allocator.alloc(BootstrapMethod, num_bootstrap_methods);
|
const bootstrap_methods = try allocator.alloc(BootstrapMethod, num_bootstrap_methods);
|
||||||
errdefer allocator.free(bootstrap_methods);
|
errdefer allocator.free(bootstrap_methods);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| allocator.free(bootstrap_methods[i].bootstrap_arguments);
|
|
||||||
|
|
||||||
for (bootstrap_methods) |*bootstrap_method| {
|
for (bootstrap_methods) |*bootstrap_method| {
|
||||||
const bootstrap_method_ref = try input.takeInt(u16, .big);
|
const bootstrap_method_ref = try input.takeInt(u16, .big);
|
||||||
|
|
||||||
const num_bootstrap_arguments = try input.takeInt(u16, .big);
|
const num_bootstrap_arguments = try input.takeInt(u16, .big);
|
||||||
const bootstrap_arguments = try allocator.alloc(u16, num_bootstrap_arguments);
|
const bootstrap_arguments = try allocator.alloc(u16, num_bootstrap_arguments);
|
||||||
errdefer allocator.free(bootstrap_arguments);
|
errdefer allocator.free(bootstrap_arguments);
|
||||||
|
|
||||||
for (bootstrap_arguments) |*bootstrap_argument| {
|
for (bootstrap_arguments) |*bootstrap_argument| {
|
||||||
bootstrap_argument.* = try input.takeInt(u16, .big);
|
bootstrap_argument.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
@ -2532,7 +2431,6 @@ pub const BootstrapMethods = struct {
|
||||||
.bootstrap_method_ref = bootstrap_method_ref,
|
.bootstrap_method_ref = bootstrap_method_ref,
|
||||||
.bootstrap_arguments = bootstrap_arguments,
|
.bootstrap_arguments = bootstrap_arguments,
|
||||||
};
|
};
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -2590,7 +2488,6 @@ pub const MethodParameters = struct {
|
||||||
const parameter_count = try input.takeByte();
|
const parameter_count = try input.takeByte();
|
||||||
const parameters = try allocator.alloc(Parameter, parameter_count);
|
const parameters = try allocator.alloc(Parameter, parameter_count);
|
||||||
errdefer allocator.free(parameters);
|
errdefer allocator.free(parameters);
|
||||||
|
|
||||||
for (parameters) |*parameter| {
|
for (parameters) |*parameter| {
|
||||||
parameter.* = .{
|
parameter.* = .{
|
||||||
.name_index = try input.takeInt(u16, .big),
|
.name_index = try input.takeInt(u16, .big),
|
||||||
|
|
@ -2804,71 +2701,58 @@ pub const Module = struct {
|
||||||
const requires_count = try input.takeInt(u16, .big);
|
const requires_count = try input.takeInt(u16, .big);
|
||||||
const requires = try allocator.alloc(Requires, requires_count);
|
const requires = try allocator.alloc(Requires, requires_count);
|
||||||
errdefer allocator.free(requires);
|
errdefer allocator.free(requires);
|
||||||
|
|
||||||
for (requires) |*r| {
|
for (requires) |*r| {
|
||||||
|
const requires_index = try input.takeInt(u16, .big);
|
||||||
|
const requires_flags: Requires.RequiresFlags = .from(try input.takeInt(u16, .big));
|
||||||
|
const requires_version_index = try input.takeInt(u16, .big);
|
||||||
r.* = .{
|
r.* = .{
|
||||||
.requires_index = try input.takeInt(u16, .big),
|
.requires_index = requires_index,
|
||||||
.requires_flags = .from(try input.takeInt(u16, .big)),
|
.requires_flags = requires_flags,
|
||||||
.requires_version_index = try input.takeInt(u16, .big),
|
.requires_version_index = requires_version_index,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const exports_count = try input.takeInt(u16, .big);
|
const exports_count = try input.takeInt(u16, .big);
|
||||||
const exports = try allocator.alloc(Exports, exports_count);
|
const exports = try allocator.alloc(Exports, exports_count);
|
||||||
errdefer allocator.free(exports);
|
errdefer allocator.free(exports);
|
||||||
|
|
||||||
var parsed_exports: usize = 0;
|
|
||||||
errdefer for (0..parsed_exports) |i| allocator.free(exports[i].exports_to_indeces);
|
|
||||||
|
|
||||||
for (exports) |*e| {
|
for (exports) |*e| {
|
||||||
const exports_index = try input.takeInt(u16, .big);
|
const exports_index = try input.takeInt(u16, .big);
|
||||||
const exports_flags: Exports.ExportsFlags = .from(try input.takeInt(u16, .big));
|
const exports_flags: Exports.ExportsFlags = .from(try input.takeInt(u16, .big));
|
||||||
const exports_to_count = try input.takeInt(u16, .big);
|
const exports_to_count = try input.takeInt(u16, .big);
|
||||||
const exports_to_indeces = try allocator.alloc(u16, exports_to_count);
|
const exports_to_indeces = try allocator.alloc(u16, exports_to_count);
|
||||||
errdefer allocator.free(exports_to_indeces);
|
errdefer allocator.free(exports_to_indeces);
|
||||||
|
|
||||||
for (exports_to_indeces) |*i| {
|
for (exports_to_indeces) |*i| {
|
||||||
i.* = try input.takeInt(u16, .big);
|
i.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.* = .{
|
e.* = .{
|
||||||
.exports_index = exports_index,
|
.exports_index = exports_index,
|
||||||
.exports_flags = exports_flags,
|
.exports_flags = exports_flags,
|
||||||
.exports_to_indeces = exports_to_indeces,
|
.exports_to_indeces = exports_to_indeces,
|
||||||
};
|
};
|
||||||
parsed_exports += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const opens_count = try input.takeInt(u16, .big);
|
const opens_count = try input.takeInt(u16, .big);
|
||||||
const opens = try allocator.alloc(Opens, opens_count);
|
const opens = try allocator.alloc(Opens, opens_count);
|
||||||
errdefer allocator.free(opens);
|
errdefer allocator.free(opens);
|
||||||
|
|
||||||
var parsed_opens: usize = 0;
|
|
||||||
errdefer for (0..parsed_opens) |i| allocator.free(opens[i].opens_to_indeces);
|
|
||||||
|
|
||||||
for (opens) |*o| {
|
for (opens) |*o| {
|
||||||
const opens_index = try input.takeInt(u16, .big);
|
const opens_index = try input.takeInt(u16, .big);
|
||||||
const opens_flags: Opens.OpensFlags = .from(try input.takeInt(u16, .big));
|
const opens_flags: Opens.OpensFlags = .from(try input.takeInt(u16, .big));
|
||||||
const opens_to_count = try input.takeInt(u16, .big);
|
const opens_to_count = try input.takeInt(u16, .big);
|
||||||
const opens_to_indeces = try allocator.alloc(u16, opens_to_count);
|
const opens_to_indeces = try allocator.alloc(u16, opens_to_count);
|
||||||
errdefer allocator.free(opens_to_indeces);
|
errdefer allocator.free(opens_to_indeces);
|
||||||
|
|
||||||
for (opens_to_indeces) |*i| {
|
for (opens_to_indeces) |*i| {
|
||||||
i.* = try input.takeInt(u16, .big);
|
i.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
||||||
o.* = .{
|
o.* = .{
|
||||||
.opens_index = opens_index,
|
.opens_index = opens_index,
|
||||||
.opens_flags = opens_flags,
|
.opens_flags = opens_flags,
|
||||||
.opens_to_indeces = opens_to_indeces,
|
.opens_to_indeces = opens_to_indeces,
|
||||||
};
|
};
|
||||||
parsed_opens += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uses_count = try input.takeInt(u16, .big);
|
const uses_count = try input.takeInt(u16, .big);
|
||||||
const uses_indeces = try allocator.alloc(u16, uses_count);
|
const uses_indeces = try allocator.alloc(u16, uses_count);
|
||||||
errdefer allocator.free(uses_indeces);
|
errdefer allocator.free(uses_indeces);
|
||||||
|
|
||||||
for (uses_indeces) |*i| {
|
for (uses_indeces) |*i| {
|
||||||
i.* = try input.takeInt(u16, .big);
|
i.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
@ -2876,25 +2760,18 @@ pub const Module = struct {
|
||||||
const provides_count = try input.takeInt(u16, .big);
|
const provides_count = try input.takeInt(u16, .big);
|
||||||
const provides = try allocator.alloc(Provides, provides_count);
|
const provides = try allocator.alloc(Provides, provides_count);
|
||||||
errdefer allocator.free(provides);
|
errdefer allocator.free(provides);
|
||||||
|
|
||||||
var parsed_provides: usize = 0;
|
|
||||||
errdefer for (0..parsed_provides) |i| allocator.free(provides[i].provides_with_indeces);
|
|
||||||
|
|
||||||
for (provides) |*p| {
|
for (provides) |*p| {
|
||||||
const provides_index = try input.takeInt(u16, .big);
|
const provides_index = try input.takeInt(u16, .big);
|
||||||
const provides_with_count = try input.takeInt(u16, .big);
|
const provides_with_count = try input.takeInt(u16, .big);
|
||||||
const provides_with_indeces = try allocator.alloc(u16, provides_with_count);
|
const provides_with_indeces = try allocator.alloc(u16, provides_with_count);
|
||||||
errdefer allocator.free(provides_with_indeces);
|
errdefer allocator.free(provides_with_indeces);
|
||||||
|
|
||||||
for (provides_with_indeces) |*i| {
|
for (provides_with_indeces) |*i| {
|
||||||
i.* = try input.takeInt(u16, .big);
|
i.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.* = .{
|
p.* = .{
|
||||||
.provides_index = provides_index,
|
.provides_index = provides_index,
|
||||||
.provides_with_indeces = provides_with_indeces,
|
.provides_with_indeces = provides_with_indeces,
|
||||||
};
|
};
|
||||||
parsed_provides += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -2911,19 +2788,15 @@ pub const Module = struct {
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
allocator.free(self.requires);
|
allocator.free(self.requires);
|
||||||
|
|
||||||
for (self.exports) |*e| {
|
for (self.exports) |*e| {
|
||||||
allocator.free(e.exports_to_indeces);
|
allocator.free(e.exports_to_indeces);
|
||||||
}
|
}
|
||||||
allocator.free(self.exports);
|
allocator.free(self.exports);
|
||||||
|
|
||||||
for (self.opens) |*o| {
|
for (self.opens) |*o| {
|
||||||
allocator.free(o.opens_to_indeces);
|
allocator.free(o.opens_to_indeces);
|
||||||
}
|
}
|
||||||
allocator.free(self.opens);
|
allocator.free(self.opens);
|
||||||
|
|
||||||
allocator.free(self.uses_indeces);
|
allocator.free(self.uses_indeces);
|
||||||
|
|
||||||
for (self.provides) |*p| {
|
for (self.provides) |*p| {
|
||||||
allocator.free(p.provides_with_indeces);
|
allocator.free(p.provides_with_indeces);
|
||||||
}
|
}
|
||||||
|
|
@ -3033,7 +2906,6 @@ pub const ModulePackages = struct {
|
||||||
const package_count = try input.takeInt(u16, .big);
|
const package_count = try input.takeInt(u16, .big);
|
||||||
const package_indeces = try allocator.alloc(u16, package_count);
|
const package_indeces = try allocator.alloc(u16, package_count);
|
||||||
errdefer allocator.free(package_indeces);
|
errdefer allocator.free(package_indeces);
|
||||||
|
|
||||||
for (package_indeces) |*package_index| {
|
for (package_indeces) |*package_index| {
|
||||||
package_index.* = try input.takeInt(u16, .big);
|
package_index.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
@ -3088,7 +2960,6 @@ pub const NestMembers = struct {
|
||||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
||||||
const number_of_classes = try input.takeInt(u16, .big);
|
const number_of_classes = try input.takeInt(u16, .big);
|
||||||
const classes = try allocator.alloc(u16, number_of_classes);
|
const classes = try allocator.alloc(u16, number_of_classes);
|
||||||
|
|
||||||
for (classes) |*class| {
|
for (classes) |*class| {
|
||||||
class.* = try input.takeInt(u16, .big);
|
class.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
@ -3120,13 +2991,8 @@ pub const Record = struct {
|
||||||
const attribute_count = try input.takeInt(u16, .big);
|
const attribute_count = try input.takeInt(u16, .big);
|
||||||
const attributes = try allocator.alloc(AttributeInfo, attribute_count);
|
const attributes = try allocator.alloc(AttributeInfo, attribute_count);
|
||||||
errdefer allocator.free(attributes);
|
errdefer allocator.free(attributes);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| attributes[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (attributes) |*attribute| {
|
for (attributes) |*attribute| {
|
||||||
attribute.* = try .parse(input, constant_pool, allocator);
|
attribute.* = try .parse(input, constant_pool, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -3185,13 +3051,8 @@ pub const Record = struct {
|
||||||
pub fn parse(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: std.mem.Allocator) (ParseError || ResolveError)!Self {
|
pub fn parse(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: std.mem.Allocator) (ParseError || ResolveError)!Self {
|
||||||
const components_count = try input.takeInt(u16, .big);
|
const components_count = try input.takeInt(u16, .big);
|
||||||
const components = try allocator.alloc(RecordComponentInfo, components_count);
|
const components = try allocator.alloc(RecordComponentInfo, components_count);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer for (0..parsed) |i| components[i].deinit(allocator);
|
|
||||||
|
|
||||||
for (components) |*component| {
|
for (components) |*component| {
|
||||||
component.* = try .parse(input, constant_pool, allocator);
|
component.* = try .parse(input, constant_pool, allocator);
|
||||||
parsed += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -3215,7 +3076,6 @@ pub const PermittedSubclasses = struct {
|
||||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
||||||
const number_of_classes = try input.takeInt(u16, .big);
|
const number_of_classes = try input.takeInt(u16, .big);
|
||||||
const classes = try allocator.alloc(u16, number_of_classes);
|
const classes = try allocator.alloc(u16, number_of_classes);
|
||||||
|
|
||||||
for (classes) |*class| {
|
for (classes) |*class| {
|
||||||
class.* = try input.takeInt(u16, .big);
|
class.* = try input.takeInt(u16, .big);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -466,18 +466,8 @@ pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Sel
|
||||||
const constant_pool = try allocator.alloc(?Info, constant_pool_size - 1);
|
const constant_pool = try allocator.alloc(?Info, constant_pool_size - 1);
|
||||||
errdefer allocator.free(constant_pool);
|
errdefer allocator.free(constant_pool);
|
||||||
|
|
||||||
var parsed: usize = 0;
|
|
||||||
errdefer {
|
|
||||||
for (0..parsed) |i| {
|
|
||||||
if (constant_pool[i]) |*info| {
|
|
||||||
info.deinit(allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < constant_pool_size - 1) {
|
while (i < constant_pool_size - 1) {
|
||||||
defer parsed = i;
|
|
||||||
defer i += 1;
|
defer i += 1;
|
||||||
|
|
||||||
const info: Info = try .parse(input, allocator);
|
const info: Info = try .parse(input, allocator);
|
||||||
|
|
|
||||||
|
|
@ -87,3 +87,4 @@ pub fn name(self: *const Self, constant_pool: ConstantPool) ResolveError!Constan
|
||||||
pub fn descriptor(self: *const Self, constant_pool: ConstantPool) ResolveError!ConstantPool.Info {
|
pub fn descriptor(self: *const Self, constant_pool: ConstantPool) ResolveError!ConstantPool.Info {
|
||||||
return constant_pool.getTag(self.descriptor_index, .utf8);
|
return constant_pool.getTag(self.descriptor_index, .utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,13 @@ pub fn EnumFlags(comptime E: type) type {
|
||||||
|
|
||||||
mask: BackingInt,
|
mask: BackingInt,
|
||||||
|
|
||||||
pub const empty: Self = .{ .data = 0 };
|
pub const empty: Self = .{ .mask = 0 };
|
||||||
|
|
||||||
|
test empty {
|
||||||
|
const flags: EnumFlags(Enum) = .empty;
|
||||||
|
|
||||||
|
try std.testing.expectEqual(0b0000_0000, flags.mask);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from(mask: BackingInt) Self {
|
pub fn from(mask: BackingInt) Self {
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -16,34 +22,102 @@ pub fn EnumFlags(comptime E: type) type {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test from {
|
||||||
|
const flags: EnumFlags(Enum) = .from(0b0000_0001);
|
||||||
|
|
||||||
|
try std.testing.expectEqual(0b0000_0001, flags.mask);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn contains(self: Self, flag: E) bool {
|
pub fn contains(self: Self, flag: E) bool {
|
||||||
return (self.mask & @backingInt(flag)) != 0;
|
return (self.mask & @intFromEnum(flag)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(self: *Self, flag: E) void {
|
pub fn insert(self: *Self, flag: E) void {
|
||||||
self.mask |= @backingInt(flag);
|
self.mask |= @intFromEnum(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(self: *Self, flag: E) void {
|
pub fn remove(self: *Self, flag: E) void {
|
||||||
self.mask &= ~@backingInt(flag);
|
self.mask &= ~@intFromEnum(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle(self: *Self, flag: E) void {
|
pub fn toggle(self: *Self, flag: E) void {
|
||||||
self.mask ^= @backingInt(flag);
|
self.mask ^= @intFromEnum(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(self: *const Self, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
pub fn format(self: *const Self, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
||||||
var index: usize = 0;
|
var index: usize = 0;
|
||||||
inline for (@typeInfo(E).@"enum".field_names) |field| {
|
inline for (std.meta.fields(E)) |field| {
|
||||||
const key = @field(E, field);
|
const key = @field(E, field.name);
|
||||||
if (self.contains(key)) {
|
if (self.contains(key)) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
_ = try w.write(" | ");
|
_ = try w.write(" | ");
|
||||||
}
|
}
|
||||||
try w.print("{s}", .{field});
|
try w.print("{s}", .{ field.name });
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Enum = enum(u8) {
|
||||||
|
a = 0b0000_0001,
|
||||||
|
b = 0b0000_0010,
|
||||||
|
c = 0b0000_0100,
|
||||||
|
};
|
||||||
|
|
||||||
|
test {
|
||||||
|
|
||||||
|
std.testing.refAllDecls(EnumFlags(Enum));
|
||||||
|
}
|
||||||
|
|
||||||
|
test "EnumFlags operations" {
|
||||||
|
var flags: EnumFlags(Enum) = .from(0b0000_0001);
|
||||||
|
|
||||||
|
try std.testing.expect(flags.contains(Enum.a));
|
||||||
|
|
||||||
|
flags.remove(Enum.a);
|
||||||
|
try std.testing.expect(!flags.contains(Enum.a));
|
||||||
|
|
||||||
|
flags.remove(Enum.a); // Removing twice should not enable the flag
|
||||||
|
try std.testing.expect(!flags.contains(Enum.a));
|
||||||
|
|
||||||
|
flags.insert(Enum.b);
|
||||||
|
try std.testing.expectEqual(0b0000_0010, flags.mask);
|
||||||
|
try std.testing.expect(flags.contains(Enum.b));
|
||||||
|
try std.testing.expect(!flags.contains(Enum.a));
|
||||||
|
|
||||||
|
flags.toggle(Enum.a);
|
||||||
|
try std.testing.expectEqual(0b0000_0011, flags.mask);
|
||||||
|
try std.testing.expect(flags.contains(Enum.a));
|
||||||
|
try std.testing.expect(flags.contains(Enum.b));
|
||||||
|
try std.testing.expect(!flags.contains(Enum.c));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn testFormat(expected: []const u8, flags: EnumFlags(Enum)) !void {
|
||||||
|
var out_buf: [1024]u8 = undefined;
|
||||||
|
var out: std.Io.Writer = .fixed(&out_buf);
|
||||||
|
|
||||||
|
try flags.format(&out);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings(expected, out.buffered());
|
||||||
|
}
|
||||||
|
|
||||||
|
test "EnumFlags format" {
|
||||||
|
var flags: EnumFlags(Enum) = .empty;
|
||||||
|
|
||||||
|
flags.toggle(Enum.a);
|
||||||
|
flags.toggle(Enum.b);
|
||||||
|
flags.toggle(Enum.c);
|
||||||
|
try testFormat("a | b | c", flags);
|
||||||
|
|
||||||
|
flags.toggle(Enum.b);
|
||||||
|
try testFormat("a | c", flags);
|
||||||
|
|
||||||
|
flags.remove(Enum.c);
|
||||||
|
try testFormat("a", flags);
|
||||||
|
|
||||||
|
flags.insert(Enum.b);
|
||||||
|
try testFormat("a | b", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
src/main.zig
10
src/main.zig
|
|
@ -19,17 +19,17 @@ pub fn main(init: std.process.Init) !void {
|
||||||
std.debug.assert(args.skip());
|
std.debug.assert(args.skip());
|
||||||
const file_path = if (args.next()) |fp| fp else {
|
const file_path = if (args.next()) |fp| fp else {
|
||||||
try stderr.writeAll("No file argument provided.\n");
|
try stderr.writeAll("No file argument provided.\n");
|
||||||
std.process.exit(1);
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const file = std.Io.Dir.cwd().openFile(io, file_path, .{}) catch |err| switch (err) {
|
const file = std.Io.Dir.cwd().openFile(io, file_path, .{}) catch |err| switch (err) {
|
||||||
error.FileNotFound => {
|
error.FileNotFound => {
|
||||||
try stderr.writeAll("File not found.\n");
|
try stderr.writeAll("File not found.\n");
|
||||||
std.process.exit(1);
|
return;
|
||||||
},
|
},
|
||||||
error.IsDir => {
|
error.IsDir => {
|
||||||
try stderr.writeAll("Path is a directory.\n");
|
try stderr.writeAll("Path is a directory.\n");
|
||||||
std.process.exit(1);
|
return;
|
||||||
},
|
},
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
|
@ -42,11 +42,11 @@ pub fn main(init: std.process.Init) !void {
|
||||||
var class = Class.parse(reader, allocator) catch |err| switch (err) {
|
var class = Class.parse(reader, allocator) catch |err| switch (err) {
|
||||||
error.InvalidMagicNumber => {
|
error.InvalidMagicNumber => {
|
||||||
try stderr.writeAll("Invalid magic number.\n");
|
try stderr.writeAll("Invalid magic number.\n");
|
||||||
std.process.exit(1);
|
return;
|
||||||
},
|
},
|
||||||
error.InvalidTag => {
|
error.InvalidTag => {
|
||||||
try stderr.writeAll("Unrecognized tag type.\n");
|
try stderr.writeAll("Unrecognized tag type.\n");
|
||||||
std.process.exit(1);
|
return;
|
||||||
},
|
},
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,52 +17,6 @@ public class Main implements Runnable, Supplier<Integer>, Interface {
|
||||||
} finally {
|
} finally {
|
||||||
System.err.println("Finally block");
|
System.err.println("Finally block");
|
||||||
}
|
}
|
||||||
|
|
||||||
var a = 8;
|
|
||||||
a <<= 3;
|
|
||||||
final var b = a >> 1;
|
|
||||||
switch (b) {
|
|
||||||
case 1:
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
System.out.println("Good");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("Number " + a);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
final var o = getObject();
|
|
||||||
switch (o) {
|
|
||||||
case Integer i:
|
|
||||||
switch (i) {
|
|
||||||
case 1:
|
|
||||||
System.out.println("One");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
System.out.println("Two");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
System.out.println("Three");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("Something else");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
inc(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object getObject() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void inc(int i) {
|
|
||||||
i += 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
BIN
testsuite/classes/java/Object.class
Normal file
BIN
testsuite/classes/java/Object.class
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue