Skip to content

Commit

Permalink
fix: Index of static/methods were sometimes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jun 28, 2024
1 parent e4d4c85 commit 342fd36
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
```buzz
const tuple = .{ "john", "james" };
tuples.@"0" == "john";
tuple.@"0" == "john";
```
- Checked subscript access to list and strings:
```buzz
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/Codegen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_function.chunk, current_function.name.string);
disassembler.disassembleChunk(&current_function.chunk, current_function.type_def.resolved_type.?.Function.name.string);
io.print("\n\n", .{});
}

Expand Down
17 changes: 5 additions & 12 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
.{
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
7 changes: 2 additions & 5 deletions tests/058-ffi.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<int>("i32", values: [1, 2, 3]);
Expand All @@ -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::<int>("u64", values: [1]);
std.assert(false, message: "Using bad buzz type triggers error");
} catch (ffi.FFITypeMismatchError _) {
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 342fd36

Please sign in to comment.