4fc156d63710541410782f14a742d6af3d36f7a7
Port several AstGen.zig patterns to C: - Thread ResultLoc through fullBodyExpr, ifExpr, switchExpr, callExpr, calleeExpr (for proper type coercion and decl_literal handling) - Add rlBr() and breakResultInfo() helpers mirroring upstream ri.br() and setBreakResultInfo - Implement labeled blocks with label on GenZir (matching upstream), restoreErrRetIndex before break, and break_result_info - Fix breakExpr to emit restoreErrRetIndex and use break_result_info for value/void breaks (AstGen.zig:2150-2237) - Add setBlockComptimeBody with comptime_reason field (was using setBlockBody which omitted the reason, causing wrong extra layout) - Add comptime_reason parameter to comptimeExpr with correct reasons for type/array_sentinel/switch_item/comptime_keyword contexts - Handle enum_literal in calleeExpr (decl_literal_no_coerce) - Fix decl_literal rvalue wrapping for ty/coerced_ty result locs All 5 corpus files now pass byte-by-byte ZIR comparison. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
About
zig0 aspires to be an interpreter of zig 0.15.1 written in C.
This is written with help from LLM:
- Lexer:
- Datastructures 100% human.
- Helper functions 100% human.
- Lexing functions 50/50 human/bot.
- Parser:
- Datastructures 100% human.
- Helper functions 50/50.
- Parser functions 5/95 human/bot.
- AstGen: TBD.
Testing
Quick test:
zig build fmt test
Full test and static analysis with all supported compilers and valgrind (run before commit, takes a while):
zig build -Dvalgrind
Debugging tips
Test runs infinitely? Build the test program executable:
$ zig build test -Dno-exec
And then run it, capturing the stack trace:
gdb -batch \
-ex "python import threading; threading.Timer(1.0, lambda: gdb.post_event(lambda: gdb.execute('interrupt'))).start()" \
-ex run \
-ex "bt full" \
-ex quit \
zig-out/bin/test
You are welcome to replace -ex "bt full" with anything other of interest.
Languages
Zig
96.3%
C
2.7%
C++
0.6%
Python
0.1%