Skip to content

Commit

Permalink
Fix symbols with characters not allowed in C names
Browse files Browse the repository at this point in the history
  • Loading branch information
StavromulaBeta committed Sep 15, 2024
1 parent 026c987 commit d3113b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cognac.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ bool debug = false;
bool gc_test = false;
bool noinline = false;

char* sanitize(char*);

static bool is_prelude(module_t* mod)
{
return mod == &prelude1 || mod == &prelude2;
Expand Down Expand Up @@ -724,7 +726,7 @@ const char* c_literal(lit_t* literal)
char s[strlen(literal->string) + strlen(prefix) + 1];
s[0] = '\0';
strcat(s, prefix);
strcat(s, literal->string);
strcat(s, sanitize((char*)literal->string));
return strdup(s);
}
return literal->string; // TODO
Expand Down Expand Up @@ -899,7 +901,7 @@ void to_c(module_t* mod)
{
for (int i = 0 ; i < sizeof(builtin_symbols) / sizeof(builtin_symbols[0]) ; ++i)
if (!strcmp(builtin_symbols[i], syms->text)) goto next;
fprintf(c_source, "const SYMBOL SYM%s = \"%s\";\n", syms->text, syms->text);
fprintf(c_source, "const SYMBOL SYM%s = \"%s\";\n", sanitize(syms->text), syms->text);
next:;
}
if (mod->symbols) fputc('\n', c_source);
Expand Down

0 comments on commit d3113b4

Please sign in to comment.