-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax error in generated code inside zig-cache (translate-c?) #2043
Comments
Oh wow, I didn't know that Zig was successfully translating That's probably a good candidate to become a regression test of translate-c. I'm pretty sure this was broken by the C pointers change - which although it caused this regression, it actually is going to result in much cleaner translate-c output, and make a lot of translate-c code easier to implement. I think this regression can definitely get fixed before 0.4.0 comes out. |
That switch translation also looks very incorrect, but I don't think: case 0: do { *_p++ = _val; /* fallthrough */
case 3: *_p++ = _val; /* fallthrough */
case 2: *_p++ = _val; /* fallthrough */
case 1: *_p++ = _val; /* fallthrough */
} while ( --_n ); can be easily be translated to Zig |
Yeah it definitely looks wrong. I think it can work in theory though. |
Actually, this broke with the grammar changes in #1685. Basically, we have this rule at stmt level:
The parser parses the grammar correctly, but the new grammar just does not allow this syntax. I can't come up with a solution on top of my head right now. Edit: Well, a solution would be to make translate-c conform to this new grammar. Idk if we want to put in the work to make |
This now works in master. const SDL = @cImport({
@cInclude("/usr/include/SDL2/SDL_stdinc.h");
});
export fn foo(dst: [*]u32, val: u32, n: usize) void {
SDL.SDL_memset4(dst, val, n);
} It was translated to: pub fn SDL_memset4(arg_dst: ?*c_void, arg_val: Uint32, arg_dwords: usize) void {
var dst = arg_dst;
var val = arg_val;
var dwords = arg_dwords;
var _n: usize = ((dwords +% @bitCast(c_ulong, @as(c_long, @as(c_int, 3)))) / @bitCast(c_ulong, @as(c_long, @as(c_int, 4))));
var _p: [*c]Uint32 = (@ptrCast([*c]Uint32, @alignCast(@alignOf(Uint32), (dst))));
var _val: Uint32 = (val);
if (dwords == @bitCast(c_ulong, @as(c_long, @as(c_int, 0)))) return;
__switch: {
__case_3: {
__case_2: {
__case_1: {
__case_0: {
switch ((dwords % @bitCast(c_ulong, @as(c_long, @as(c_int, 4))))) {
@bitCast(c_ulong, @as(c_long, 0)) => break :__case_0,
@bitCast(c_ulong, @as(c_long, 3)) => break :__case_1,
@bitCast(c_ulong, @as(c_long, 2)) => break :__case_2,
@bitCast(c_ulong, @as(c_long, 1)) => break :__case_3,
else => break :__switch,
}
}
(blk: {
const ref = &_p;
const tmp = ref.*;
ref.* += 1;
break :blk tmp;
}).?.* = _val;
}
(blk: {
const ref = &_p;
const tmp = ref.*;
ref.* += 1;
break :blk tmp;
}).?.* = _val;
}
(blk: {
const ref = &_p;
const tmp = ref.*;
ref.* += 1;
break :blk tmp;
}).?.* = _val;
}
while (true) {
(blk: {
const ref = &_p;
const tmp = ref.*;
ref.* += 1;
break :blk tmp;
}).?.* = _val;
if (!((blk: {
const ref = &_n;
ref.* -%= 1;
break :blk ref.*;
}) != 0)) break;
}
}
} |
I'm trying to get my project working with the zig changes from the last day or two and ran into an error. Here is a branch where this error is happening: https://github.com/dbandstra/oxid/commits/not-working
I'm on Ubuntu right now.
Here's a paste of the relevant part of that file. I marked the bad line with a comment.
P.S. Zig syntax highlighting in github! Nice!
edit: here's the c code from SDL_stdinc.h:
The text was updated successfully, but these errors were encountered: