From 342fd361e773e632a7880025786e9ea62dc9823f Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 28 Jun 2024 11:28:55 +0200 Subject: [PATCH] fix: Index of static/methods were sometimes wrong --- CHANGELOG.md | 4 ++-- src/Codegen.zig | 2 +- src/Parser.zig | 17 +++++------------ src/vm.zig | 2 +- tests/058-ffi.buzz | 7 ++----- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a7b661..3605418b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ```buzz const tuple = .{ "john", "james" }; -tuples.@"0" == "john"; +tuple.@"0" == "john"; ``` - Checked subscript access to list and strings: ```buzz @@ -28,7 +28,7 @@ list[?10] == null; - Http client could not be collected because it kept connection opened to previous requests' domains ## Internal -- Properties are now retrieve with an index rather than by a hashmap lookup (https://github.com/buzz-language/buzz/issues/90) which gives a nice performance boost of about 40% on some benches +- Properties are now retrieved with an index rather than a hashmap lookup (https://github.com/buzz-language/buzz/issues/90) which gives a nice performance boost of about 40% on some benches # 0.4.0 (05-16-2024) diff --git a/src/Codegen.zig b/src/Codegen.zig index 1f1ad611..8b34843d 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -2382,7 +2382,7 @@ fn generateFunction(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!? current_function.upvalue_count = @intCast(components.upvalue_binding.count()); if (BuildOptions.debug) { - disassembler.disassembleChunk(¤t_function.chunk, current_function.name.string); + disassembler.disassembleChunk(¤t_function.chunk, current_function.type_def.resolved_type.?.Function.name.string); io.print("\n\n", .{}); } diff --git a/src/Parser.zig b/src/Parser.zig index b8a9b68e..9ff414c2 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -6360,7 +6360,7 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { // Docblocks var property_idx: usize = 0; - var static_property_idx: usize = 0; + var static_or_method_property_idx: usize = 0; while (!self.check(.RightBrace) and !self.check(.Eof)) { const docblock = if (try self.match(.Docblock)) self.current_token.? - 1 @@ -6429,18 +6429,11 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { .location = self.ast.tokens.get(method_token), .method = true, .has_default = false, - .index = if (static) - static_property_idx - else - property_idx, + .index = static_or_method_property_idx, }, ); - if (static) { - static_property_idx += 1; - } else { - property_idx += 1; - } + static_or_method_property_idx += 1; try members.append( .{ @@ -6544,14 +6537,14 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { .method = false, .has_default = default != null, .index = if (static) - static_property_idx + static_or_method_property_idx else property_idx, }, ); if (static) { - static_property_idx += 1; + static_or_method_property_idx += 1; } else { property_idx += 1; } diff --git a/src/vm.zig b/src/vm.zig index 6183c5a9..51558daf 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -5210,7 +5210,7 @@ pub const VM = struct { self.currentFrame().?.ip = hotspot_call_start; if (BuildOptions.debug) { - disassembler.disassembleChunk(chunk, self.currentFrame().?.closure.function.name.string); + disassembler.disassembleChunk(chunk, self.currentFrame().?.closure.function.type_def.resolved_type.?.Function.name.string); } } }; diff --git a/tests/058-ffi.buzz b/tests/058-ffi.buzz index 32d388d3..3787f2fe 100644 --- a/tests/058-ffi.buzz +++ b/tests/058-ffi.buzz @@ -2,8 +2,6 @@ import "std"; import "buffer" as _; import "ffi"; -| TODO: one zdef for one lib and multiple declarations -| TODO: Allow multiple declarations in one string zdef("tests/utils/libforeign", ` fn acos(value: f64) f64; fn fprint(msg: [*:0]const u8) void; @@ -19,7 +17,6 @@ test "cstring" { } test "pointer with Buffer" { - | TODO: would be better with object destructor so the buffer can be collected var buffer = Buffer.init(); buffer.writeZ::("i32", values: [1, 2, 3]); @@ -28,7 +25,7 @@ test "pointer with Buffer" { try { | Arguably, the zig type parameter could a constant and be built at compile time | But: that would require a new type - | Since we cache the result of the type parsing this roughly equivalent + | Since we cache the result of the type parsing this is roughly equivalent buffer.writeZ::("u64", values: [1]); std.assert(false, message: "Using bad buzz type triggers error"); } catch (ffi.FFITypeMismatchError _) { @@ -150,4 +147,4 @@ test "union" { std.assert(misc.id == 321, message: "Got expected memory layout of a C union"); std.assert(misc.data.id == 321, message: "Got expected memory layout of a C union"); std.assert(misc.flag.id == 321, message: "Got expected memory layout of a C union"); -} \ No newline at end of file +}