Commit e4f29309
e4f29309c880Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · ~4 modified
Description
Add M6: symbols, and emit else on its own line
Symbols:
- compiler: a program-wide symbol intern table (name -> sp_sym id).
- analyze: intern every SymbolNode literal up front.
- codegen: emit the sp_sym_names[] table + a real sp_sym_to_s when any symbol is used (else the empty stub); SymbolNode -> ((sp_sym)id); sp_sym locals; symbol ==/!=, to_s/id2name/to_sym; puts (name), p (":"+name), and interpolation of symbols.
Style:
- emit generated
elseon its own line (}then newline thenelse {), not} else {, per project C style.
make test: 7 pass.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- e4f29309c880
- Parent
- 910ff23faf75
src/analyze.cmodifiedView file
@@ -397,6 +397,15 @@
397397
walk_scope(c, c->nt->root_id, 0);398398
register_locals(c);399399
400+
/* intern every symbol literal so codegen can emit the id table */401+
for (int id = 0; id < c->nt->count; id++) {402+
const char *ty = nt_type(c->nt, id);403+
if (ty && !strcmp(ty, "SymbolNode")) {404+
const char *v = nt_str(c->nt, id, "value");405+
if (v) comp_sym_intern(c, v);406+
}407+
}408+
400409
for (int iter = 0; iter < 128; iter++) {401410
int ch = 0;402411
ch |= infer_write_types(c);src/codegen.cmodifiedView file
Loading diff…
src/compiler.cmodifiedView file
Loading diff…
src/compiler.hmodifiedView file
Loading diff…