selfhost: fix pointer field access, algebraic enums, string literal escaping
- hir_lower: use per-function scope instead of global scope for params fixes p->error emission for pointer parameters - parser: assign variant4..variant7 in enum decls (was only 0..3) - c_backend: escape quotes, backslash, newline, tab, cr in string literals - runtime: bux_write_file now writes raw bytes (was un-escaping sequences) - c_backend: emit algebraic enums as tagged unions (tag enum + data union + struct) - hir_lower: add hBreak/hContinue lowering - sema: skip empty variant names when collecting enum globals
This commit is contained in:
+1
-25
@@ -507,31 +507,7 @@ int bux_write_file(const char* path, const char* content) {
|
||||
FILE* f = fopen(path, "wb");
|
||||
if (!f) return 0;
|
||||
size_t len = strlen(content);
|
||||
size_t written = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (content[i] == '\\' && i + 1 < len && content[i + 1] == 'n') {
|
||||
if (fputc('\n', f) == EOF) break;
|
||||
i++;
|
||||
} else if (content[i] == '\\' && i + 1 < len && content[i + 1] == 't') {
|
||||
if (fputc('\t', f) == EOF) break;
|
||||
i++;
|
||||
} else if (content[i] == '\\' && i + 1 < len && content[i + 1] == 'r') {
|
||||
if (fputc('\r', f) == EOF) break;
|
||||
i++;
|
||||
} else if (content[i] == '\\' && i + 1 < len && content[i + 1] == '\\') {
|
||||
if (fputc('\\', f) == EOF) break;
|
||||
i++;
|
||||
} else if (content[i] == '\\' && i + 1 < len && content[i + 1] == '"') {
|
||||
if (fputc('"', f) == EOF) break;
|
||||
i++;
|
||||
} else if (content[i] == '\\' && i + 1 < len && content[i + 1] == '\'') {
|
||||
if (fputc('\'', f) == EOF) break;
|
||||
i++;
|
||||
} else {
|
||||
if (fputc(content[i], f) == EOF) break;
|
||||
}
|
||||
written++;
|
||||
}
|
||||
size_t written = fwrite(content, 1, len, f);
|
||||
fclose(f);
|
||||
return written > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user