aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:36:49 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:36:49 +0330
commit31e81b5a22becfdc7c5688171643c473372024b1 (patch)
tree42ca55570ef04ed1087f5b209f94adfccce047e4
parenttodo: zc0 gaps done (diff)
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
-rw-r--r--src/tools/zc0.c13
-rw-r--r--tests/conformance/known.txt1
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)