summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-09-02 00:40:35 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-09-02 00:40:35 -0400
commit7097749bf41739feffbb7f6da20b2b951f73aa9d (patch)
treefc967c0dc01b60e6f66b6b1bceb4e7e52f0086df
parente71901e1f0a981aff8eb37162ab053e1bb9df5aa (diff)
re-added dots in idents
-rw-r--r--base_cgen.c2
-rw-r--r--identifiers.c14
-rw-r--r--out.c7
-rw-r--r--out.h2
-rw-r--r--test.toc9
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);
+ }
}
}
diff --git a/out.c b/out.c
index 22c285e..dca1ae7 100644
--- a/out.c
+++ b/out.c
@@ -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) {
diff --git a/out.h b/out.h
index 57b86cd..d053b7d 100644
--- a/out.h
+++ b/out.h
@@ -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);
diff --git a/test.toc b/test.toc
index 86d8961..b12e461 100644
--- a/test.toc
+++ b/test.toc
@@ -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();
};