From 66ffc2ae07941e00406493020579a0b695b535ee Mon Sep 17 00:00:00 2001 From: lemon Date: Wed, 15 Oct 2025 10:44:06 +0200 Subject: implement long double (as double synonym). wchar_t placeholder --- c.c | 6 ++---- embedfilesdir.c | 1 + ir.c | 1 + lex.c | 3 +++ targ.c | 11 +++++++---- type.c | 1 - 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/c.c b/c.c index 6b29021..42e2c35 100644 --- a/c.c +++ b/c.c @@ -2047,9 +2047,7 @@ End: else if (arith == KDOUBLE) t = TYDOUBLE; else if (arith == (KLONG | KDOUBLE)) { - /* t = TYLDOUBLE; */ - warn(&span, "`long double' is unsupported"); - t = TYDOUBLE; + t = TYLDOUBLE; } else if (arith == KBOOL) t = TYBOOL; else if (arith == KCHAR) @@ -2697,7 +2695,7 @@ narrow(struct function *fn, enum irclass to, enum typetag tt, union ref ref, uin if (targ_primsizes[tt] < cls2siz[to]) { ins.cls = to; if (isfltt(tt)) { - assert(to == KF4 && tt == TYDOUBLE); + assert(to == KF4 && tt >= TYDOUBLE); ins.op = Ocvtf8f4; } else { static const enum op ext[5][2] = { diff --git a/embedfilesdir.c b/embedfilesdir.c index e2f223b..434e2e8 100644 --- a/embedfilesdir.c +++ b/embedfilesdir.c @@ -13,6 +13,7 @@ struct embedfile embedfilesdir[] = { typedef __typeof__((char*)0 - (char*)0) ptrdiff_t;\n\ typedef __typeof__(sizeof 0) size_t;\n\ /*typedef __typeof__(L'a') wchar_t;*/\n\ +typedef int wchar_t;\n\ #define NULL ((void *)0)\n\ #define offsetof(_Type, _Memb) ((size_t)(&((_Type *)0)->_Memb - (_Type *)0))\n\ ")}, diff --git a/ir.c b/ir.c index e0d219f..6c28977 100644 --- a/ir.c +++ b/ir.c @@ -58,6 +58,7 @@ irinit(struct function *fn) } type2cls[TYFLOAT] = KF4; type2cls[TYDOUBLE] = KF8; + type2cls[TYLDOUBLE] = KF8; type2cls[TYPTR] = KPTR; type2cls[TYARRAY] = KPTR; cls2siz[KI4] = cls2siz[KF4] = 4; diff --git a/lex.c b/lex.c index f99b8d3..2daa0bc 100644 --- a/lex.c +++ b/lex.c @@ -178,6 +178,9 @@ parsenumlit(uvlong *outi, double *outf, const struct token *tk, bool ispp) } 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; } return 0; } else { /* int literal */ diff --git a/targ.c b/targ.c index 7772537..306fcd8 100644 --- a/targ.c +++ b/targ.c @@ -6,16 +6,16 @@ static const struct targ { struct { uchar longsize, vlongsize, ptrsize, valistsize; }; struct { uchar longalign, vlongalign, doublealign, ptralign; }; bool charsigned; - uchar sizetype, ptrdifftype; + uchar sizetype, ptrdifftype, wchartype; const struct mctarg *mctarg; } targs[] = { - { "amd64-sysv", {8, 8, 8, 24}, {8, 8, 8, 8}, 1, TYULONG, TYLONG, &t_amd64_sysv }, - { "i686-sysv", {4, 8, 4, 8}, {4, 4, 4, 4}, 1, TYUINT, TYINT } + { "amd64-sysv", {8, 8, 8, 24}, {8, 8, 8, 8}, 1, TYULONG, TYLONG, TYUINT, &t_amd64_sysv }, + { "i686-sysv", {4, 8, 4, 8}, {4, 4, 4, 4}, 1, TYUINT, TYINT, TYUINT } }; uchar targ_primsizes[TYPTR+1]; uchar targ_primalign[TYPTR+1]; -enum typetag targ_sizetype, targ_ptrdifftype; +enum typetag targ_sizetype, targ_ptrdifftype, targ_wchartype; bool targ_charsigned, targ_bigendian, targ_64bit; const struct mctarg *mctarg; @@ -30,6 +30,7 @@ targ_init(const char *starg) sizes[TYUINT] = sizes[TYINT] = 4; sizes[TYFLOAT] = 4; sizes[TYDOUBLE] = 8; + sizes[TYLDOUBLE] = 8; memcpy(align, sizes, sizeof targ_primalign); sizes[TYULONG] = sizes[TYLONG] = t->longsize; sizes[TYUVLONG] = sizes[TYVLONG] = t->vlongsize; @@ -38,9 +39,11 @@ targ_init(const char *starg) align[TYULONG] = align[TYLONG] = t->longalign; align[TYUVLONG] = align[TYVLONG] = t->vlongalign; align[TYDOUBLE] = t->doublealign; + align[TYLDOUBLE] = t->doublealign; align[TYVALIST] = align[TYPTR] = t->ptralign; targ_sizetype = t->sizetype; targ_ptrdifftype = t->ptrdifftype; + targ_wchartype = t->wchartype; targ_charsigned = t->charsigned; targ_bigendian = 0; targ_64bit = t->ptrsize == 8; diff --git a/type.c b/type.c index 724c337..b93a654 100644 --- a/type.c +++ b/type.c @@ -1,5 +1,4 @@ #include "common.h" -#include struct typedata typedata[1<<13]; const char *ttypenames[1<<10]; -- cgit v1.2.3