summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-14 14:17:40 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-14 14:17:40 -0500
commitc25fd395a256e7fd4656c767a2143a3de4b33f55 (patch)
treea2a9aaf9f60ddfd625bcf8fbcec8f297d9175d38
parentc2e28acbb73e9c9c4a720664cbeb6b8eb6d4c978 (diff)
packages finally mostly working!
-rw-r--r--identifiers.c30
-rw-r--r--types.c2
2 files changed, 14 insertions, 18 deletions
diff --git a/identifiers.c b/identifiers.c
index 07b0d74..505b565 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -33,24 +33,12 @@ static void idents_create(Identifiers *ids) {
ids->rseed = 0x27182818;
}
-#if CHAR_MIN < 0
-#define ident_char_to_uchar(c) (unsigned char)((c) < 0 ? (256 + (c)) : (c))
-#else
-#define ident_char_to_uchar(c) (unsigned char)(c)
-#endif
-
-#if CHAR_MIN < 0
-#define ident_uchar_to_char(c) (unsigned char)((c) > 127 ? ((c) - 256) : (c))
-#else
-#define ident_uchar_to_char(c) (unsigned char)(c)
-#endif
-
static U64 ident_hash(char **s) {
U32 x = 0xabcdef01;
U32 y = 0x31415926;
U64 hash = 0;
while (is_ident(**s)) {
- hash += (U64)x * ident_char_to_uchar(**s) + y;
+ hash += (U64)x * (unsigned char)(**s) + y;
x = rand_u32(x);
y = rand_u32(y);
++*s;
@@ -58,9 +46,8 @@ static U64 ident_hash(char **s) {
return hash;
}
-
-static bool ident_eq_str(Identifier i, const char *s) {
- char *t = i->text;
+/* are these strings equal, up to the first non-ident character? */
+static bool ident_str_eq_str(const char *s, const char *t) {
while (is_ident(*s) && is_ident(*t)) {
if (*s != *t) return false;
++s, ++t;
@@ -68,6 +55,10 @@ static bool ident_eq_str(Identifier i, const char *s) {
return !is_ident(*s) && !is_ident(*t);
}
+static inline bool ident_eq_str(Identifier i, const char *s) {
+ return ident_str_eq_str(i->text, s);
+}
+
static IdentSlot **ident_slots_insert(IdentSlot **slots, char *s, size_t i) {
@@ -177,7 +168,7 @@ static void fprint_ident_reduced_charset(FILE *out, Identifier id) {
return;
}
for (char *s = id->text; is_ident(*s); ++s) {
- int c = ident_char_to_uchar(*s);
+ int c = (unsigned char)(*s);
if (c > 127) {
fprintf(out, "x__%x", c);
} else {
@@ -213,6 +204,11 @@ static IdentDecl *ident_decl(Identifier i) {
return (IdentDecl *)arr_last(i->decls);
}
+/* returns true if i and j are equal, even if they're not in the same table */
+static bool ident_eq(Identifier i, Identifier j) {
+ return ident_str_eq_str(i->text, j->text);
+}
+
static void idents_free(Identifiers *ids) {
arr_foreach(ids->slots, IdentSlotPtr, slotp) {
IdentSlot *slot = *slotp;
diff --git a/types.c b/types.c
index 2d6f6d4..de78d56 100644
--- a/types.c
+++ b/types.c
@@ -1967,7 +1967,7 @@ static bool types_expr(Typer *tr, Expression *e) {
if (rhs->kind == EXPR_IDENT) {
/* maybe accessing a field? */
arr_foreach(struct_type->struc->fields, Field, f) {
- if (f->name == rhs->ident) {
+ if (ident_eq(f->name, rhs->ident)) {
is_field = true;
*t = f->type;
e->binary.dot.field = f;