commit b2b9428f8581e0221c6cd2b668a7d14d819b0d35 (tree)
parent bd709678f66635ec63f151fba23dc38c886b0deb
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Tue, 17 Feb 2026 10:56:11 +0000
use C parser in AstGen
Diffstat:
4 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/stage0/README.md b/stage0/README.md
@@ -18,18 +18,18 @@ This is written with help from LLM:
Quick test:
- zig build fmt-zig0 test-zig0
+ ./zig3 build fmt-zig0 test-zig0
Full test and static analysis with all supported compilers and valgrind (run
before commit, takes a while):
- zig build all-zig0 -Dvalgrind
+ ./zig3 build all-zig0 -Dvalgrind
# Debugging tips
Test runs infinitely? Build the test program executable:
- $ zig build test-zig0 -Dzig0-no-exec
+ $ ./zig3 build test-zig0 -Dzig0-no-exec
And then run it, capturing the stack trace:
diff --git a/stage0/astgen.c b/stage0/astgen.c
@@ -3386,8 +3386,8 @@ static bool hex_float_fits_f64(const char* buf) {
}
// 128-bit multiply: (a_hi:a_lo) * b -> (r_hi:r_lo), returns true on overflow.
-static bool mul128x64(uint64_t a_hi, uint64_t a_lo, uint64_t b,
- uint64_t* r_hi, uint64_t* r_lo) {
+static bool mul128x64(
+ uint64_t a_hi, uint64_t a_lo, uint64_t b, uint64_t* r_hi, uint64_t* r_lo) {
// Compute a_lo * b as 128-bit result using mul64.
uint64_t lo_hi, lo_lo;
mul64(a_lo, b, &lo_hi, &lo_lo);
@@ -3409,8 +3409,8 @@ static bool mul128x64(uint64_t a_hi, uint64_t a_lo, uint64_t b,
}
// 128-bit divide: (a_hi:a_lo) / b -> (q_hi:q_lo), remainder in *rem.
-static void div128x64(uint64_t a_hi, uint64_t a_lo, uint64_t b,
- uint64_t* q_hi, uint64_t* q_lo, uint64_t* rem) {
+static void div128x64(uint64_t a_hi, uint64_t a_lo, uint64_t b, uint64_t* q_hi,
+ uint64_t* q_lo, uint64_t* rem) {
// High part division.
*q_hi = a_hi / b;
uint64_t r = a_hi % b;
@@ -13336,9 +13336,9 @@ static void blockExprStmts(GenZir* gz, Scope* scope,
break;
// assign_destructure (AstGen.zig:2578).
case AST_NODE_ASSIGN_DESTRUCTURE:
- cur_scope
- = assignDestructureMaybeDecls(gz, cur_scope, inner_node,
- val_scopes, &val_idx, ptr_scopes, &ptr_idx, max_scopes);
+ cur_scope = assignDestructureMaybeDecls(gz, cur_scope,
+ inner_node, val_scopes, &val_idx, ptr_scopes, &ptr_idx,
+ max_scopes);
break;
// Shift assignment operators (AstGen.zig:2585-2586).
case AST_NODE_ASSIGN_SHL:
@@ -18057,8 +18057,7 @@ static bool rlBuiltinCall(AstGenCtx* ag, RlBlock* block, uint32_t node,
// Zig tracking issue: #16876
// @frameAddress consumes its result location
// (AstRlAnnotate.zig:887-889).
- if (name_len == 12
- && memcmp(source + name_start, "frameAddress", 12) == 0)
+ if (name_len == 12 && memcmp(source + name_start, "frameAddress", 12) == 0)
return true;
for (uint32_t i = 0; i < nargs; i++)
diff --git a/stage0/astgen_test.zig b/stage0/astgen_test.zig
@@ -1,15 +1,15 @@
const std = @import("std");
-const Ast = std.zig.Ast;
const Zir = std.zig.Zir;
const AstGen = std.zig.AstGen;
const Allocator = std.mem.Allocator;
-const c = @cImport({
- @cInclude("astgen.h");
-});
+const parser_test = @import("parser_test.zig");
+const c = parser_test.c;
fn refZir(gpa: Allocator, source: [:0]const u8) !Zir {
- var tree = try Ast.parse(gpa, source, .zig);
+ var c_ast = c.astParse(source.ptr, @intCast(source.len));
+ defer c.astDeinit(&c_ast);
+ var tree = try parser_test.zigAst(gpa, c_ast);
defer tree.deinit(gpa);
return try AstGen.generate(gpa, tree);
}
@@ -1324,14 +1324,14 @@ const corpus_files = .{
};
pub fn corpusCheck(gpa: Allocator, source: [:0]const u8) !void {
- var tree = try Ast.parse(gpa, source, .zig);
- defer tree.deinit(gpa);
+ var c_ast = c.astParse(source.ptr, @intCast(source.len));
+ defer c.astDeinit(&c_ast);
+ var tree = try parser_test.zigAst(gpa, c_ast);
+ defer tree.deinit(gpa);
var ref_zir = try AstGen.generate(gpa, tree);
defer ref_zir.deinit(gpa);
- var c_ast = c.astParse(source.ptr, @intCast(source.len));
- defer c.astDeinit(&c_ast);
var c_zir = c.astGen(&c_ast);
defer c.zirDeinit(&c_zir);
diff --git a/stage0/parser_test.zig b/stage0/parser_test.zig
@@ -6563,8 +6563,8 @@ const testing = std.testing;
const Ast = std.zig.Ast;
const Allocator = std.mem.Allocator;
-const c = @cImport({
- @cInclude("ast.h");
+pub const c = @cImport({
+ @cInclude("astgen.h");
});
const zigToken = @import("./tokenizer_test.zig").zigToken;