From 31e81b5a22becfdc7c5688171643c473372024b1 Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 16:36:49 +0330 Subject: zc0: u*x, m*x, d*x are products when u, m or d is a visible local or global (spec 1.6.3); redone from zc-spec's 2f2597b --- src/tools/zc0.c | 13 ++++++++----- tests/conformance/known.txt | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tools/zc0.c b/src/tools/zc0.c index 664ea79..a3c3f4a 100644 --- a/src/tools/zc0.c +++ b/src/tools/zc0.c @@ -257,12 +257,8 @@ static int accept(const char *s) { if (is(s)) { next(); return 1; } return 0; } static void expect(const char *s) { if (!accept(s)) { char b[64]; sprintf(b, "expected '%s'", s); die(b); } } static char *ident(void) { static char b[8][256]; static int k; char *r = b[k++ & 7]; if (tk != T_ID) die("expected a name"); strcpy(r, ts); next(); return r; } /* u, m and d are ordinary names. u*x, m*x and d*x are recasts when the star touches - the letter, which the raw character after the name tells: u * x is a product, and + the letter and no variable of that name is visible, which the raw character after the name tells: u * x is a product, and so is u*=x. the current token is the name, so pos is just past it. */ -static int isrecast(void) -{ - return tk == T_ID && ts[1] == 0 && (ts[0] == 'u' || ts[0] == 'm' || ts[0] == 'd') && src[pos] == '*' && src[pos + 1] != '='; -} /* ---- symbols ---- */ typedef struct { char name[64]; int kind, sig, defd, str; int64_t val; } Sym; /* str: a global holding a byte string, or a function returning one */ @@ -303,6 +299,13 @@ static void fnref(const char *n) /* push a function address, fixing it up later typedef struct { char name[64]; int slot, arr, flt, str, dstr; } Loc; /* dstr: declared bstr, so always a byte string */ static Loc lo[1024]; static int nlo, nslot, infn; static Loc *findl(const char *n) { int i; for (i = nlo; i--;) if (!strcmp(lo[i].name, n)) return &lo[i]; return 0; } +static int isrecast(void) +{ + Sym *g; + if (!(tk == T_ID && ts[1] == 0 && (ts[0] == 'u' || ts[0] == 'm' || ts[0] == 'd') && src[pos] == '*' && src[pos + 1] != '=')) return 0; + if (findl(ts)) return 0; /* a visible variable named u, m or d: a product (spec 1.6.3) */ + g = find(ts); return !(g && (g->kind == K_GVAR || g->kind == K_GARR)); +} static void laddr(int k) { lit(ZFP); op(O_LD); if (k) { lit(k); op(O_ADD); } } /* ---- operator tables ---- */ diff --git a/tests/conformance/known.txt b/tests/conformance/known.txt index 9bec99b..54e7141 100644 --- a/tests/conformance/known.txt +++ b/tests/conformance/known.txt @@ -16,7 +16,6 @@ 9-appendix-b/b2_14_len_char_ptr_typecheck_off.zc zy a appendix b.2.14 confirmed 9-appendix-b/b2_15_duplicate_case.zc zy c appendix b.2.15 confirmed; 4.7.2 says duplicates are allowed 9-appendix-b/b2_16_local_const_in_const_expr.zc zy c appendix b.2.16 confirmed; 3.14.2 documents it -1-source/ident_tags_as_variables_glued_star.zc zc0 b u*d with visible u and d is read as a recast (no code); zy follows 1.6.3 2-types/conv_argument_and_return.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a) 2-types/conv_assignment_to_float.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a) 2-types/conv_f32_rounds.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a) -- cgit v1.2.3