astgen: implement ZIR generation for basic expressions and declarations

Mechanical translation of AstGen.zig into C. Implements:
- Container members: comptime, simple_var_decl, test_decl, fn_decl
- Expressions: number_literal, string_literal, identifier (with
  primitive types, integer types, and decl_val/decl_ref resolution),
  field_access (field_val/field_ptr), address_of, builtin_call
  (@import), array_type, array_init (with inferred [_] length),
  array_cat (++), ptr_type
- Statement types: assign with _ = expr discard pattern
- Test infrastructure: testDecl, addFunc, fullBodyExpr,
  blockExprStmts, emitDbgNode/emitDbgStmt, rvalueDiscard
- Support: GenZir sub-block instruction tracking, result location
  propagation (RL_NONE/RL_REF/RL_DISCARD), string dedup, import
  tracking, namespace decl table, lastToken, firstToken

1/5 corpus files pass (test_all.zig). Remaining 4 skip gracefully
via has_compile_errors when encountering unimplemented features.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-11 21:32:37 +00:00
parent 280997f658
commit 202733edbc
5 changed files with 2574 additions and 64 deletions

View File

@@ -6445,7 +6445,7 @@ const c = @cImport({
const zigToken = @import("./tokenizer_test.zig").zigToken;
fn zigNode(token: c_uint) Ast.Node.Tag {
pub fn zigNode(token: c_uint) Ast.Node.Tag {
return switch (token) {
c.AST_NODE_ROOT => .root,
c.AST_NODE_TEST_DECL => .test_decl,
@@ -6870,7 +6870,7 @@ fn zigData(tag: Ast.Node.Tag, lhs: u32, rhs: u32) Ast.Node.Data {
}
// zigAst converts a c.Ast to std.Zig.Ast. The resulting Ast should be freed with deinit().
fn zigAst(gpa: Allocator, c_ast: c.Ast) !Ast {
pub fn zigAst(gpa: Allocator, c_ast: c.Ast) !Ast {
var tokens = Ast.TokenList{};
try tokens.resize(gpa, c_ast.tokens.len);
errdefer tokens.deinit(gpa);