diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-09-02 00:40:35 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-09-02 00:40:35 -0400 |
commit | 7097749bf41739feffbb7f6da20b2b951f73aa9d (patch) | |
tree | fc967c0dc01b60e6f66b6b1bceb4e7e52f0086df | |
parent | e71901e1f0a981aff8eb37162ab053e1bb9df5aa (diff) |
re-added dots in idents
-rw-r--r-- | base_cgen.c | 2 | ||||
-rw-r--r-- | identifiers.c | 14 | ||||
-rw-r--r-- | out.c | 7 | ||||
-rw-r--r-- | out.h | 2 | ||||
-rw-r--r-- | test.toc | 9 |
5 files changed, 20 insertions, 14 deletions
diff --git a/base_cgen.c b/base_cgen.c index 64d96d0..4d4bb3a 100644 --- a/base_cgen.c +++ b/base_cgen.c @@ -99,7 +99,7 @@ static bool cgen_ident(CGenerator *g, Identifier i, Location *where) { } } cgen_indent(g); - fprint_ident_ascii(cgen_writing_to(g), i); + fprint_ident_reduced_charset(cgen_writing_to(g), i); return true; } diff --git a/identifiers.c b/identifiers.c index c71ee4b..1cb543d 100644 --- a/identifiers.c +++ b/identifiers.c @@ -41,7 +41,7 @@ static int isident(int c) { return 1; if (c >= '0' && c <= '9') return 1; - if (c == '_') return 1; + if (c == '_' || c == '.') return 1; #if CHAR_MIN < 0 if (c < 0) /* on systems where char = signed char, UTF-8 characters are probably < 0? */ return 1; @@ -121,17 +121,23 @@ static void fprint_ident(FILE *out, Identifier id) { fputc(c, out); } -static void fprint_ident_ascii(FILE *out, Identifier id) { +/* reduced charset = a-z, A-Z, 0-9, _ */ +static void fprint_ident_reduced_charset(FILE *out, Identifier id) { assert(id); if (id->parent == NULL) return; /* at root */ - fprint_ident_ascii(out, id->parent->parent); /* to go up one character, we need to go to the grandparent */ + fprint_ident_reduced_charset(out, id->parent->parent); /* to go up one character, we need to go to the grandparent */ int c_low = id->parent->index_in_parent; int c_high = id->index_in_parent; int c = c_low + (c_high << 4); if (c > 127) { fprintf(out, "x__%x",c); } else { - fputc(ident_uchar_to_char(c), out); + char chr = (char)ident_uchar_to_char(c); + if (chr == '.') { + fprintf(out, "__"); /* replace . with __ */ + } else { + fputc(chr, out); + } } } @@ -2,11 +2,12 @@ /* toc */ #include <stdio.h> -void x__c5x__b3x__c5x__84x__c4x__a8(void) { - printf("Hello, World!\n"); +void foo__bar(void) { + puts("Hello!"); +; } void main__(void) { - x__c5x__b3x__c5x__84x__c4x__a8(); + foo__bar(); } int main(void) { @@ -1,4 +1,4 @@ #include <stddef.h> #include <stdint.h> -void x__c5x__b3x__c5x__84x__c4x__a8(void); +void foo__bar(void); void main__(void); @@ -1,9 +1,8 @@ #C("#include <stdio.h>\n"); - -ųńĨ @= fn() { - #C("printf(\"Hello, World!\\n\")"); +foo.bar @= fn() { + #C("puts(\"Hello!\");\n"); }; -main @= fn() { - ųńĨ(); +main @= fn() { + foo.bar(); }; |