aboutsummaryrefslogtreecommitdiff
path: root/src/compiler/decl.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 19:46:41 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 19:56:53 +0330
commit41fe629f77a584ff86bba8e0a2b9c0ed895e421f (patch)
treeecfbcbf19e3d2eb694aa0a6ac4920f017f783b4d /src/compiler/decl.zc
parenttodo: run.py's sieve checksum fails on main (diff)
fndef: b.2.13 unnamed prototype parameters in fewer ops (402197 -> 402112 words, same behaviour)work/b213
Diffstat (limited to 'src/compiler/decl.zc')
-rw-r--r--src/compiler/decl.zc17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc
index 87281ad..2151bb2 100644
--- a/src/compiler/decl.zc
+++ b/src/compiler/decl.zc
@@ -328,8 +328,8 @@ int fndef(int chk, int rty, int ret, int n) {
next();
}
pnoffs[np] = toff; pnplaces[np] = tpack(); rs_note(RS_PARAM, toff);
- if (!pk && !t && tk == T_ID && istypename(tv)) amb = amb | (1 << np); // int f(int): a name, or a type if this is a prototype
- if (pk && tk == T_OP && (tv == s_comma || tv == s_rp)) { pn[np] = 0; nonm = 1; } else pn[np] = name(); // int f(int*, int): a prototype's parameters may be unnamed
+ if (pk && (is_op(s_comma) || is_op(s_rp))) { pn[np] = 0; nonm = 1; } // int f(int*, int): a prototype's parameters may be unnamed
+ else { if (!pk && !t && istypename(tv)) amb = amb | (1 << np); pn[np] = name(); } // int f(int): a name, or a type if this is a prototype
if (o3f && pty[np] == tword) serr("o3 parameters need a type");
if (np >= 12 && t) die("only the first 12 parameters can be tagged");
pt[np] = t;
@@ -340,13 +340,12 @@ int fndef(int chk, int rty, int ret, int n) {
}
}
expect(s_rp);
- if (is_op(s_semi)) { // a prototype: a lone type name is an unnamed parameter of that type (b.2.13)
- i = 0;
- while (i < np) {
- if (((amb >> i) & 1) && pn[i]) { t = lookup(pn[i]); if (t >= 0 && skind[t] == K_TYPE) { pty[i] = sval[t]; typed = 1; } }
- i++;
- }
- } else if (nonm) serr("a parameter needs a name");
+ if (!is_op(s_semi)) { if (nonm) serr("a parameter needs a name"); amb = 0; }
+ i = 0;
+ while (amb) { // a prototype: a lone type name is an unnamed parameter of that type (b.2.13)
+ if (amb & 1) { t = lookup(pn[i]); if (t >= 0 && skind[t] == K_TYPE) { pty[i] = sval[t]; typed = 1; } }
+ amb = amb >> 1; i++;
+ }
sig = ret + np + np + tags * 64;
if ((sflag[s] & F_SIG) && !(sflag[s] & F_PRE)) {
if (ssig[s] != sig) serrn(n, "doesn't match its earlier declaration");