diff options
| author | 2026-04-13 19:25:11 +0200 | |
|---|---|---|
| committer | 2026-04-13 19:30:01 +0200 | |
| commit | ddbd42e66cc71b470730037d76f4f267e98d8d40 (patch) | |
| tree | aae9ff541b3e0690e23e391bb2e5e8927d34bf38 /src/c_lex.c | |
| parent | 36143af2748b6fcae02ca320baaac417d77ebe58 (diff) | |
C99 complex types MVP
Missing: static eval of complex values,
Silly inefficient implementation of equality comparisons between them
The whole thing is pretty inefficient without proper aggregate mem2reg
anyway
Diffstat (limited to 'src/c_lex.c')
| -rw-r--r-- | src/c_lex.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/c_lex.c b/src/c_lex.c index fe8edb5..c5e16aa 100644 --- a/src/c_lex.c +++ b/src/c_lex.c @@ -138,24 +138,26 @@ parsenumlit(u64int *outi, double *outf, const Token *tk, bool ispp) } else if (memchr(tk->s, '.', tk->len)) { extern double strtod(const char *, char **); double f; - char buf[80], *suffix; + char buf[80], *s; Float: /* float literal */ assert(tk->len < sizeof buf - 1 && "numlit too big"); memcpy(buf, tk->s, tk->len); buf[tk->len] = 0; - f = strtod(buf, &suffix); - if (suffix == buf) + f = strtod(buf, &s); + if (s == buf) return 0; - if (!*suffix) { - if (outf) *outf = f; - return TYDOUBLE; - } else if ((suffix[0]|0x20) == 'f' && !suffix[1]) { - if (outf) *outf = f; - return TYFLOAT; - } else if ((suffix[0]|0x20) == 'l' && !suffix[1]) { - if (outf) *outf = f; - return TYLDOUBLE; + if (outf) *outf = f; + if (!*s) return TYDOUBLE; + for (char *p = s; *p; ++p) { + if ((*p |= 0x20) == 'j') *p = 'i'; } + if (s[0] == 'f' && !s[1]) return TYFLOAT; + else if (s[0] == 'l' && !s[1]) return TYLDOUBLE; + else if (s[0] == 'i' && !s[1]) return TYCOMPLEX; + else if (s[0] == 'i' && s[1] == 'f' && !s[2]) return TYCOMPLEXF; + else if (s[0] == 'f' && s[1] == 'i' && !s[2]) return TYCOMPLEXF; + else if (s[0] == 'i' && s[1] == 'l' && !s[2]) return TYCOMPLEXL; + else if (s[0] == 'l' && s[1] == 'i' && !s[2]) return TYCOMPLEXL; return 0; } else { /* int literal */ static u64int max4typ[TYUVLONG-TYINT+1]; @@ -2432,7 +2434,7 @@ addpredefmacros(Arena **tmparena) }; static const char cpredefs[] = - "__antcc__\0__STDC__\0__STDC_NO_ATOMICS__\0__STDC_NO_COMPLEX__\0__STDC_NO_THREADS__\0__STDC_NO_VLA__\0", + "__antcc__\0__STDC__\0__STDC_NO_ATOMICS__\0__STDC_NO_THREADS__\0__STDC_NO_VLA__\0", cstdver[][8] = { [STDC89] = "199409L", [STDC99] = "199901L", |