aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/SPEC.md39
-rw-r--r--src/compiler/builtins.zc1
-rw-r--r--src/compiler/decl.zc15
-rw-r--r--src/compiler/expr.zc21
-rw-r--r--src/runtime/rt.zc1
-rw-r--r--tests/conformance/1-source/ident_tags_global_glued_star.zc8
-rw-r--r--tests/conformance/3-expressions/closure_24_parameters.zc6
-rw-r--r--tests/conformance/3-expressions/ternary_int_float_variables.zc8
-rw-r--r--tests/conformance/5-declarations/global_float_init_f32_and_list.zc8
-rw-r--r--tests/conformance/5-declarations/global_float_int_init.zc9
-rw-r--r--tests/conformance/5-declarations/include_in_function_b9.zc2
-rw-r--r--tests/conformance/known.txt19
-rw-r--r--tests/langerrors/closure_params_25.zc3
-rw-r--r--tests/langerrors/fn_defined_twice.zc4
-rw-r--r--tests/langerrors/include_in_function.zc2
-rw-r--r--tests/langerrors/proto_after_def_mismatch.zc4
-rw-r--r--tests/programs/zc0umd.zc19
17 files changed, 121 insertions, 48 deletions
diff --git a/docs/SPEC.md b/docs/SPEC.md
index 6df55f6..f53c469 100644
--- a/docs/SPEC.md
+++ b/docs/SPEC.md
@@ -55,7 +55,7 @@ a name that looks like `x.y` where `x` is not a known module is the three tokens
| `break` `continue` `return` | S | | | 4.8 |
| `defer` | S | | | 4.14 |
| `enum` | S | T | | 5.8 |
-| `include` | S | T | | 5.12 (a statement only by accident, 5.12.7) |
+| `include` | S | T | | 5.12 (in a function body it is an error, 5.12.7) |
| `embed` | S | T | | 5.11 |
| `memdebug` | S | T | | 4.11 |
| `hints` | S | T | | 4.12 |
@@ -395,7 +395,7 @@ a = b = 7 // assigns both, value 7
3.5.4 `-x` of a float is computed as `0.0 - x`, so `-0.0` evaluates to `+0.0`. do not depend on the sign of zero.
-3.5.5 `?:` with one float branch and one integer branch is broken in the reference implementation (appendix b). write both branches as floats.
+3.5.5 `?:` with one float branch and one integer branch converts the integer branch to float: `1 ? 1 : 2.5` is 1.0, `1 ? 2.5 : 1` is 2.5.
### 3.6 evaluation order and short circuit
@@ -507,7 +507,7 @@ other operators (`/ % ^ < ?:` and so on) are not part of a constant expression:
### 3.15 closures
-3.15.1 `fn(a, b) { ... }` in an expression is a closure. parameters may be typed (`fn(int a)`) and tagged. `fn:T(a) { ... }` declares the result type `T` and coerces and checks returns against it. a closure is an owned heap object (a fresh object, 6.1): bind it to a local, pass it to a `.d` parameter or to a borrower, or return it from a `.u` function.
+3.15.1 `fn(a, b) { ... }` in an expression is a closure. parameters (up to 24) may be typed (`fn(int a)`) and tagged. `fn:T(a) { ... }` declares the result type `T` and coerces and checks returns against it. a closure is an owned heap object (a fresh object, 6.1): bind it to a local, pass it to a `.d` parameter or to a borrower, or return it from a `.u` function.
3.15.2 a closure captures the locals and parameters of the enclosing function by reference (shared cells): later changes are visible both ways, and the cells outlive the creating function.
```
@@ -624,7 +624,7 @@ o3 int sum(fixed int[?] a) { int s = 0; for (int i = 0; i < len(a); i++) s += a[
### 4.11 memdebug
-`memdebug on;` turns on heap header checks and allocation-site tracking from this point in the file (top level) or from this point in the function (statement); the runtime enables the checks before `main` for the top-level form. `memdebug scrub;` additionally fills freed payloads with 57005; `memdebug off;` stops. with checks on, a use after free prints `zy: use after free from line N`, a double free prints `zy: double free from line N` and returns, a stray address prints `zy: bad heap pointer`. `rt.memreport()` prints a line `leak: line N W words` per live recorded object and returns the count. (`memdebug scrub;` is rejected by the reference implementation, appendix b.)
+`memdebug on;` turns on heap header checks and allocation-site tracking from this point in the file (top level) or from this point in the function (statement); the runtime enables the checks before `main` for the top-level form. `memdebug scrub;` additionally fills freed payloads with 57005; `memdebug off;` stops. with checks on, a use after free prints `zy: use after free from line N`, a double free prints `zy: double free from line N` and returns, a stray address prints `zy: bad heap pointer`. `rt.memreport()` prints a line `leak: line N W words` per live recorded object and returns the count.
### 4.12 hints
@@ -695,7 +695,7 @@ a bare `name(params) { ... }` with no `fn` and no type is not a function declara
5.2.5 `main`. after the unit compiles without errors, the runtime calls `main` with no arguments (declared parameters read unspecified values; `main(a, b)` prints 0 0 in the reference implementation). its return value is ignored and is not the exit status; `main` may be declared `int`, `void` or untyped, in a run-only image as in `zy`. 8.1.
-5.2.6 a function is defined once. redefining a name that already has a body is, per the rule, error: f: is defined twice; the reference implementation does not detect an ordinary redefinition (appendix b). a prototype must agree with the definition: error: f: doesn't match its earlier declaration.
+5.2.6 a function is defined once. redefining a name that already has a body in the same module is error: f: is defined twice. a prototype may come before or after the definition and must agree with it: error: f: doesn't match its earlier declaration. a prototype after the definition keeps the definition.
5.2.7 `immediate fn` defines a parse word (7.2). `unchecked fn` and `o3 fn` are 4.9 and 4.10.
@@ -703,7 +703,7 @@ a bare `name(params) { ... }` with no `fn` and no type is not a function declara
5.3.1 `T a = e, b, c[10];`, `let g = 1, buf[10];`, `int[10] buf;`, `point origin;`. storage is emitted in place, zero initialised.
-5.3.2 an initializer is: a constant expression (3.14), a word string, a byte string, or a brace list or compound literal for an array. anything else is an error: for `int a = f();` error: expected ';', found '('. a float literal initializer is rejected (error: expected a constant) in the reference implementation (appendix b); assign floats in code. a name of another global in the initializer evaluates to its address, not its value: `int a = 5; int b = a + 1;` gives `b` the value `&a + 1`.
+5.3.2 an initializer is: a constant expression (3.14), a word string, a byte string, or a brace list or compound literal for an array. anything else is an error: for `int a = f();` error: expected ';', found '('. a `float`, `f64` or `f32` global takes a float literal initializer (`float g = 1.5;`); an integer constant initializer converts to float (`float g = 2;` stores 2.0), as it does for a local. a name of another global in the initializer evaluates to its address, not its value: `int a = 5; int b = a + 1;` gives `b` the value `&a + 1`.
5.3.3 a global cannot be tagged (error: tags go on locals and parameters, not globals), cannot be `void`, and an array global needs a length or an initializer.
@@ -782,7 +782,7 @@ rt.put_n(util.twice(1)); // error: module access requires `include util;`
5.12.6 in a namespaced file, a declaration `f` is `ns.f`. an unqualified name is looked up first in the file's namespace, then globally, and `rt` is not searched for bare names (3.11.5).
-5.12.7 `include` is parsed at the top level; written inside a function body it mis-compiles (appendix b).
+5.12.7 `include` is parsed at the top level; written inside a function body it is error: include is top level only.
5.12.8 when a library is included more than once, it is compiled once.
@@ -1086,11 +1086,11 @@ not in the zc0 subset: `struct`, methods, `enum`, `type`, generics, `do`/`while`
## appendix b: disagreements and bugs
-each item gives a minimal program, the expected behavior (per this spec) and the actual behavior of the reference implementation on `build/bin/zy` (unless it names zc0). none are fixed here.
+each item gives a minimal program, the expected behavior (per this spec) and the actual behavior of the reference implementation on `build/bin/zy` (unless it names zc0). items marked fixed are kept for their numbers; the rest are open.
### b.1 disagreements between the prose docs and the code
-1. README ("memory debug"): "`memdebug scrub;` also fills a freed payload with 57005". the compiler compares the word after `memdebug` with the interned name `rt.scrub` instead of `scrub`, so the statement is rejected: `memdebug scrub;` => `zc: line N: memdebug on, memdebug scrub or memdebug off`. (also b.2.1)
+1. fixed: README ("memory debug") says `memdebug scrub;` also fills a freed payload with 57005; the compiler used to compare the word with `rt.scrub` and reject it. it is accepted now (also b.2.1).
2. README ("zc, the language") says a cast type "has to be a simple type ... `int` or `*node`". the prefix pointer spelling `*node` is not a type (README's own "pointer types" section says so, and `(*int)y` => `int: is a type, not a value`). the postfix form `(node*)x` is the one that works.
3. README says "operators follow C precedence". this holds for expressions. constant expressions (array lengths, enum values, `const`, `case` labels) have no precedence: `+ - * | & << >>` only, left to right (3.14). `const X = 1 + 2 * 3;` is 9, and `/ % ^` are rejected (`const Z = 6 / 2;` => `expected ';', found '/'`). README does not mention either fact.
4. README lists `switch` forms `case 1, 2:` and `default:`. the catch-all `case _:` exists in the compiler and is not documented.
@@ -1104,15 +1104,15 @@ each item gives a minimal program, the expected behavior (per this spec) and the
### b.2 implementation bugs and limitations
-1. `memdebug scrub;` is rejected (b.1.1). expected: poison freed payloads with 57005.
+1. fixed: `memdebug scrub;` is accepted and poisons freed payloads with 57005 (b.1.1).
2. enum members cannot name earlier members of the same enum: `enum { HI = 16, LO = HI + 1 };` => `expected a constant` (the members are defined after the closing brace). members of an earlier enum and constants work.
-3. a function can be silently redefined. `int f() { return 1; } int g() { return f() + 10; } int f() { return 2; }`, then `g()` gives 11 and a later call of `f()` gives 2. expected: error `f: is defined twice` (the message exists in the compiler and is unreachable for an ordinary second definition).
-4. a prototype after the definition hides it. `int f() { return 1; } int f();` then `f()` => `zc: line 0: f is used but never defined`. expected: the definition stays.
-5. `?:` with one float branch and one integer branch converts wrongly. `pf(1 ? 1 : 2.5)` prints `0.000000` (the integer 1's bits read as a float); `pf(1 ? 2.5 : 1)` prints `4612811918334230528.000000` (the taken float converted again as if an integer); `pf(0 ? 2.5 : 1)` prints 1.000000 and `pf(0 ? 1 : 2.5)` 2.500000 (these two are right). expected 1.0, 2.5, 1.0, 2.5.
+3. fixed (now error: f: is defined twice): a function could be silently redefined. `int f() { return 1; } int g() { return f() + 10; } int f() { return 2; }`, then `g()` gives 11 and a later call of `f()` gives 2. expected: error `f: is defined twice` (the message exists in the compiler and is unreachable for an ordinary second definition).
+4. fixed (the definition stays): a prototype after the definition hid it. `int f() { return 1; } int f();` then `f()` => `zc: line 0: f is used but never defined`. expected: the definition stays.
+5. fixed (3.5.5): `?:` with one float branch and one integer branch converted wrongly. `pf(1 ? 1 : 2.5)` prints `0.000000` (the integer 1's bits read as a float); `pf(1 ? 2.5 : 1)` prints `4612811918334230528.000000` (the taken float converted again as if an integer); `pf(0 ? 2.5 : 1)` prints 1.000000 and `pf(0 ? 1 : 2.5)` 2.500000 (these two are right). expected 1.0, 2.5, 1.0, 2.5.
6. `bool` does not normalise: `bool b = 5; rt.put_n(b); rt.put_n(b == 1); rt.put_n(!b);` prints 5, 0, 0. expected 1, 1, 0 if `bool` is a 0/1 type; it behaves as a plain integer.
-7. a float literal as a global initializer: `float g = 1.5;` at the top level => `expected a constant`. expected: allowed (a float local initializer works).
-8. a global initializer that names another global uses the other global's address, not its value: `int a = 5; int b = a + 1;` gives `b` the value `&a + 1` (1 when `a` is at address 0). expected: the value of `a`, or an error.
-9. `include std;` written inside a function body: `zc: line N: return outside a function`. expected: an error saying include is top level only.
+7. fixed (5.3.2): a float literal as a global initializer (`float g = 1.5;`) was rejected.
+8. not a bug: a global initializer that names another global uses the other global's address (5.3.2, 3.14.2): `int a = 5; int b = a + 1;` gives `b` the value `&a + 1`.
+9. fixed (5.12.7): `include std;` inside a function body gave `return outside a function`; it is now error: include is top level only.
10. a syntax error hides errors in the statements skipped by recovery: `int a = ; int b = 3 +;` reports only the first error (8.2). by design, but easy to miss.
11. an unterminated `/* ...` comment is accepted silently (1.2.2); an unterminated string literal is only reported as a later syntax error.
12. `x as int * y` parses `int*` as the type (3.2.3).
@@ -1120,6 +1120,13 @@ each item gives a minimal program, the expected behavior (per this spec) and the
14. `len(s)` on a `char*` returns word 0 of the string when `typecheck` is off.
15. duplicate `case` labels are not diagnosed (4.7.2).
16. a local `const` cannot be used in a constant expression (b.1.7).
+17. fixed: a bad float or character literal in a function's first statement was not reported (1.4).
+18. fixed: `u*d` with a visible variable `u` (local or global) was read as a recast; it is a product (1.6.3).
+19. fixed: a cast such as `(int*)s` of a `bstr` kept the byte-string flag, so `p[0]` read a byte.
+20. fixed: functions took 23 parameters and closures 19; both take 24 (5.2.2, 3.15.1).
+21. fixed: `return e;` in a `void` function with `typecheck` off returned `e`; the value is dropped and the function yields 0 (4.8.3).
+22. fixed: `case member():` on a tagged member with fields was rejected; it matches by tag (4.7.3).
+23. fixed: `INT_MIN / -1` gave 0 and `INT_MIN % -1` gave INT_MIN in programs compiled by zc0 (software division, `rt.zdiv`); they give INT_MIN and 0 (3.4.3).
## appendix c: how this spec was checked
diff --git a/src/compiler/builtins.zc b/src/compiler/builtins.zc
index 9a89052..214d493 100644
--- a/src/compiler/builtins.zc
+++ b/src/compiler/builtins.zc
@@ -312,6 +312,7 @@ int inc_compile(char* buf, char* name, char*.d dir) {
int kw_include() {
int pp, sv; char* path; char* buf;
stmtonly();
+ if (infn) { die("include is top level only"); return 0; } // appendix b.2.9
next();
if (tk == T_ID) {
while (1) {
diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc
index 3a02b90..e9500c4 100644
--- a/src/compiler/decl.zc
+++ b/src/compiler/decl.zc
@@ -282,12 +282,17 @@ int body() {
// into stype, checked against any earlier prototype or prescan result, and
// where the o3 region for an o3 function is handed to the core)
int fndef(int chk, int rty, int ret, int n) {
- int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline;
+ int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline, redef;
o3nxt = 0;
if (rty || ntp) typed = 1;
if (!dnm) dnm = n;
s = lookup(n);
- if (s < 0 || s < ubase || skind[s] != K_FN || (sflag[s] & F_DEF)) {
+ redef = 0; // a function this module already defined: a prototype after it keeps it (b.2.4), a second body is defined twice (b.2.3)
+ if (s >= ubase && skind[s] == K_FN && (sflag[s] & F_DEF) && !(sflag[s] & F_TPL) && !ginst && !ntp) {
+ word qn = n; if (module_name) qn = module_symbol(n);
+ redef = rt.eq_w(sname[s], qn);
+ }
+ if (!redef && (s < 0 || s < ubase || skind[s] != K_FN || (sflag[s] & F_DEF))) {
s = addsym(n, K_FN, 0);
sflag[s] = 0;
}
@@ -475,8 +480,12 @@ int gdecl2(int t, int tg, int n) {
if (arraytype[0] != TY_ARR || !is_op(s_lb)) serr("a global compound literal needs an array initializer");
else { array_literal(arraytype); vv = xcval; *(a + hdelta) = vv; if (!t) stype[s] = decay(xty); }
}
+ else if (t && isfl(t) && tk == T_FLT) { // float g = 1.5; (appendix b.2.7)
+ vv = tv; next(); if (t == tf32) vv = rt.zs2f(rt.zf2s(vv)); *(a + hdelta) = vv; // an f32 scalar is a rounded double
+ }
else {
- vv = cnorm(t, cexpr()); *(a + hdelta) = vv;
+ vv = cnorm(t, cexpr()); if (t && isfl(t)) { vv = vf_i2f(vv); if (t == tf32) vv = rt.zs2f(rt.zf2s(vv)); } // float g = 2; is 2.0
+ *(a + hdelta) = vv;
if (gok) { if (!gty) gty = tint; else if (gty != tint) gok = 0; }
}
} else if (gok) gok = 0; // no initializer: nothing says what it is
diff --git a/src/compiler/expr.zc b/src/compiler/expr.zc
index 4c77ceb..230a2d3 100644
--- a/src/compiler/expr.zc
+++ b/src/compiler/expr.zc
@@ -647,7 +647,7 @@ word closure_layout(int closure_index, int count) {
// variable in. ctx_push / ctx_pop save and restore the enclosing function's
// compiler state around the body.
int closure() {
- int np = 0; char*[20] pn; word[20] pty; int hop, entry, i, t, envl, ncap, c, result, declared = 0, tags = 0, tag, lt, lfl = tline; word[20] ptags;
+ int np = 0; char*[24] pn; word[24] pty; int hop, entry, i, t, envl, ncap, c, result, declared = 0, tags = 0, tag, lt, lfl = tline; word[24] ptags;
word expected = closure_expected; closure_expected = 0;
reserve_closures(nclo + 1);
if (o3on) serr("closures can't be made inside an o3 region");
@@ -668,8 +668,8 @@ int closure() {
if (expected && expected[0] == TY_FN && !tag && (isptr(pty[np]) || pty[np][0] == TY_DYN || pty[np][0] == TY_FN)) ptags[np] = 1;
pnoffs[np] = toff; pnplaces[np] = tpack(); rs_note(RS_PARAM, toff); pn[np] = name();
np++;
- if (np >= 20) { die("too many parameters"); break; }
if (!accept(s_comma)) break;
+ if (np >= 24) { die("too many parameters"); break; } // 24, like a function
}
}
expect(s_rp);
@@ -1561,12 +1561,17 @@ int postfix_tail(int c) {
}
return c;
}
+// a global variable or array named u, m or d: then u*x is a multiplication (spec 1.6.3)
+int tag_is_global(int n) {
+ int s = lookup(n);
+ return s >= 0 && (skind[s] == K_GVAR || skind[s] == K_GARR);
+}
// prefix operators: the u*x / d*x / m*x recasts (the star has to touch the
// tag), casts like (int)x and (node*)x, dereference, address-of, prefix ++ and
// --, and any unary operator a program added (- ! ~ built in).
int unary() {
int c, un, t, place, constant, value; word storage, dependency;
- if (tk == T_ID && (tv == s_u || tv == s_m || tv == s_d) && findloc(tv) < 0) { // u*x, d*x, m*x: recast only when * is glued and the tag is not a local's name
+ if (tk == T_ID && (tv == s_u || tv == s_m || tv == s_d) && findloc(tv) < 0 && !tag_is_global(tv)) { // u*x, d*x, m*x: recast only when * is glued and the tag is not a local's name
peek();
if (pk_tk == T_OP && pk_tv == s_star && pq_gl[0]) {
t = S_M; if (tv == s_u) t = S_U; if (tv == s_d) t = S_D;
@@ -1777,7 +1782,7 @@ int storekeep(int t) {
// restored for the second side) and then joined, so a variable can't be given
// away on one side only. both sides are fresh objects, or neither is.
int ternary(int c) {
- int a, b, s0, sa, livea, live0 = live, n0 = nloc, ca, cb, ta, ba, bb; word temp_a, temp_b, mask_a, mask_b;
+ int a, b, s0, sa, livea, live0 = live, n0 = nloc, ca, cb, ta, ba, bb, conv, skip, back; word temp_a, temp_b, mask_a, mask_b;
rval(); plainuse(c);
ftest();
next();
@@ -1785,6 +1790,7 @@ int ternary(int c) {
s0 = snap_push();
ca = expr(); rval(); ta = xty; ba = xbor; temp_a = xaf; mask_a = effect_mask(ca);
if (ca != C_FRESH) plainuse(ca);
+ conv = -1; if (isnum(ta) && !isfl(ta) && ta != tword) { conv = hole(); op(O_JMP); back = here; setlit(conv, back); } // a jump to the next word, redirected below if the other side is a float (appendix b.2.5)
livea = live; sa = snap_push();
b = hole(); op(O_JMP);
expect(s_colon);
@@ -1792,11 +1798,14 @@ int ternary(int c) {
snap_restore(s0); live = live0;
cb = expr(); rval(); bb = xbor; temp_b = xaf; mask_b = effect_mask(cb);
if (cb != C_FRESH) plainuse(cb);
+ if (isfl(ta) && !isfl(xty)) { op(OP_I2F); xfloat = 1; xty = tfloat; } // on the second side's path only
join2(sa, livea, b, live, n0, "ends the two sides of ?: in different states");
snap_pop(s0);
- if (isfl(ta) && !isfl(xty)) { op(OP_I2F); xfloat = 1; xty = tfloat; }
+ if (conv >= 0 && isfl(xty)) { // the first side was an integer: convert it out of line
+ skip = hole(); op(O_JMP); setlit(conv, here); op(OP_I2F); lit(back); op(O_JMP); setlit(skip, here);
+ }
if (!compat(ta, xty) && !compat(xty, ta)) tcerr("the two sides of ?:", ta, xty);
- if (ta != tword && !isfl(ta)) xty = ta;
+ if (ta != tword && !isfl(ta) && !(conv >= 0 && isfl(xty))) xty = ta;
else if (isfl(ta) || isfl(xty)) { xty = tfloat; xfloat = 1; }
if_value = 0;
effect_value = mask_a | mask_b;
diff --git a/src/runtime/rt.zc b/src/runtime/rt.zc
index f1414e4..44f3570 100644
--- a/src/runtime/rt.zc
+++ b/src/runtime/rt.zc
@@ -377,6 +377,7 @@ int zudiv(int n, int dv) {
int zdiv(int a, int b) {
word s = 0; int q;
if (b == 0) { zrem = a; return 0; }
+ if (b == 0 - 1) { zrem = 0; return 0 - a; } // INT_MIN / -1 is INT_MIN and its remainder 0 (spec 3.4.3); zudiv can't take 2^63
if (a < 0) { a = 0 - a; s = 1; }
if (b < 0) { b = 0 - b; s = s ^ 1; }
q = zudiv(a, b);
diff --git a/tests/conformance/1-source/ident_tags_global_glued_star.zc b/tests/conformance/1-source/ident_tags_global_glued_star.zc
new file mode 100644
index 0000000..516f9a3
--- /dev/null
+++ b/tests/conformance/1-source/ident_tags_global_glued_star.zc
@@ -0,0 +1,8 @@
+// expect: 12/10/
+// spec 1.6.3: u*x and m*x are not recasts when u or m is a visible global variable
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+int u = 3;
+int m = 5;
+fn main() { int d = 4; int k = 2; pn(u*d); pn(m*k); return 0; }
+// zc0: skip
diff --git a/tests/conformance/3-expressions/closure_24_parameters.zc b/tests/conformance/3-expressions/closure_24_parameters.zc
new file mode 100644
index 0000000..e12d258
--- /dev/null
+++ b/tests/conformance/3-expressions/closure_24_parameters.zc
@@ -0,0 +1,6 @@
+// expect: 300/
+// spec 3.15.1 and 5.2.2: a closure takes up to 24 parameters, like a function
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+fn main() { let f = fn(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24) { return a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24; }; pn(f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24)); return 0; }
+// zc0: skip
diff --git a/tests/conformance/3-expressions/ternary_int_float_variables.zc b/tests/conformance/3-expressions/ternary_int_float_variables.zc
new file mode 100644
index 0000000..4bd2d57
--- /dev/null
+++ b/tests/conformance/3-expressions/ternary_int_float_variables.zc
@@ -0,0 +1,8 @@
+// expect: 3.000000/0.500000/3.000000/0.500000/
+// spec 3.5 and appendix b.2.5: ?: with an int side and a float side gives a float on both paths, also in o3
+include rt;
+fn pf(float f) { asm { f @ #1220 } rt.put_c(10); return 0; }
+float pick(int k, int i, float f) { return k ? i : f; }
+o3 float pick3(int k, int i, float f) { return k ? i : f; }
+fn main() { pf(pick(1, 3, 0.5)); pf(pick(0, 3, 0.5)); pf(pick3(1, 3, 0.5)); pf(pick3(0, 3, 0.5)); return 0; }
+// zc0: skip
diff --git a/tests/conformance/5-declarations/global_float_init_f32_and_list.zc b/tests/conformance/5-declarations/global_float_init_f32_and_list.zc
new file mode 100644
index 0000000..57df35b
--- /dev/null
+++ b/tests/conformance/5-declarations/global_float_init_f32_and_list.zc
@@ -0,0 +1,8 @@
+// expect: 1/1/
+// spec 5.3.2 and appendix b.2.7: float globals take a float literal initializer
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+float a = 0.25, b = 2.5;
+f32 c = 0.5;
+fn main() { pn(a + b == 2.75); pn(c * 4.0 == 2.0); return 0; }
+// zc0: skip
diff --git a/tests/conformance/5-declarations/global_float_int_init.zc b/tests/conformance/5-declarations/global_float_int_init.zc
new file mode 100644
index 0000000..ac0e187
--- /dev/null
+++ b/tests/conformance/5-declarations/global_float_int_init.zc
@@ -0,0 +1,9 @@
+// expect: 1/1/1/1/1/
+// spec 5.3.2: an integer constant initializing a float or f32 converts to float, for globals and locals
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+float g = 2;
+f32 h = 1 + 2;
+float n = -4;
+fn main() { float l = 2; f32 m = 3; pn(g == 2.0); pn(h == 3.0); pn(n == -4.0); pn(l == 2.0); pn(m == 3.0); return 0; }
+// zc0: skip
diff --git a/tests/conformance/5-declarations/include_in_function_b9.zc b/tests/conformance/5-declarations/include_in_function_b9.zc
index cccaea5..64f170c 100644
--- a/tests/conformance/5-declarations/include_in_function_b9.zc
+++ b/tests/conformance/5-declarations/include_in_function_b9.zc
@@ -1,4 +1,4 @@
-// expect error: include
+// expect error: include is top level only
// spec 5.12.7 and appendix b.2.9: expected an error saying include is top level only
include rt;
void pn(int x) { rt.put_n(x); rt.put_c(10); }
diff --git a/tests/conformance/known.txt b/tests/conformance/known.txt
index 9bec99b..22a1e3d 100644
--- a/tests/conformance/known.txt
+++ b/tests/conformance/known.txt
@@ -2,18 +2,13 @@
# class a: self-hosted compiler bug; b: zc0 deviation (appendix a/b); c: spec issue to settle
# appendix b.2.8 (a global named in an initializer is its address) is documented behavior per 5.3.2 and 3.14.2: no entry
4-statements/o3_outside_function_ordinary_block.zc zy c top-level o3 { } is rejected; spec 4.10.2 says it is an ordinary block
-5-declarations/enum_member_names_earlier_b2.zc zy a appendix b.2.2 confirmed: enum members can't name earlier members
-5-declarations/fn_prototype_after_definition_b4.zc zy a appendix b.2.4 confirmed: a prototype after the definition hides it
-5-declarations/fn_prototype_unnamed_params_b13.zc zy a appendix b.2.13 confirmed (message now: doesn't match its earlier declaration)
-5-declarations/fn_redefined_b3.zc zy a appendix b.2.3 confirmed: a plain redefinition silently shadows the first
-5-declarations/global_float_init_b7.zc zy a appendix b.2.7 confirmed: float global initializer rejected
-5-declarations/include_in_function_b9.zc zy a appendix b.2.9 confirmed: include in a body gives "return outside a function"
-9-appendix-b/b2_05_ternary_int_float.zc zy a appendix b.2.5 confirmed
-9-appendix-b/b2_06_bool_normalises.zc zy a appendix b.2.6 confirmed
+5-declarations/enum_member_names_earlier_b2.zc zy c appendix b.2.2 confirmed, but spec 2.8.1 documents it (members are defined at the closing brace); not fixed, like b.2.8 the spec body wins until decided
+5-declarations/fn_prototype_unnamed_params_b13.zc zy c spec 5.2.1 says prototype parameter names are required, and a type name alone is read as an untyped parameter of that name (paramstart); b.2.13 is a spec choice, not fixed
+9-appendix-b/b2_06_bool_normalises.zc zy c appendix b.2.6 confirmed, but spec 2.1 documents bool as a number that is not normalised
9-appendix-b/b2_10_recovery_hides_errors.zc zy c appendix b.2.10 confirmed; by design per 8.2
-9-appendix-b/b2_11_unterminated_comment.zc zy a appendix b.2.11 confirmed
-9-appendix-b/b2_12_as_int_star.zc zy a appendix b.2.12 confirmed
-9-appendix-b/b2_14_len_char_ptr_typecheck_off.zc zy a appendix b.2.14 confirmed
+9-appendix-b/b2_11_unterminated_comment.zc zy c appendix b.2.11 confirmed, but spec 1.2.2 says an unclosed block comment is not an error
+9-appendix-b/b2_12_as_int_star.zc zy c appendix b.2.12 confirmed, but spec 3.2.3 documents it (parenthesise)
+9-appendix-b/b2_14_len_char_ptr_typecheck_off.zc zy c appendix b.2.14 confirmed, but spec 3.13.5 leaves it unspecified
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
@@ -38,8 +33,6 @@
3-expressions/float_division_int_stored.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
3-expressions/float_int_ops_on_bits.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
3-expressions/incr_on_float_changes_bits.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
-3-expressions/int_min_div_minus1.zc zc0 b INT_MIN / -1 gives 0 and % gives INT_MIN in zc0
-3-expressions/int_min_mod_minus1.zc zc0 b INT_MIN / -1 gives 0 and % gives INT_MIN in zc0
3-expressions/prec_as_binds_tight.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
4-statements/return_value_converted_float.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
4-statements/return_value_converted_int.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
diff --git a/tests/langerrors/closure_params_25.zc b/tests/langerrors/closure_params_25.zc
new file mode 100644
index 0000000..0444007
--- /dev/null
+++ b/tests/langerrors/closure_params_25.zc
@@ -0,0 +1,3 @@
+// expect: too many parameters
+include rt;
+fn main() { let f = fn(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24, int a25) { return 0; }; return 0; }
diff --git a/tests/langerrors/fn_defined_twice.zc b/tests/langerrors/fn_defined_twice.zc
new file mode 100644
index 0000000..7af57e8
--- /dev/null
+++ b/tests/langerrors/fn_defined_twice.zc
@@ -0,0 +1,4 @@
+// expect: f: is defined twice
+int f() { return 1; }
+int f() { return 2; }
+fn main() { return f(); }
diff --git a/tests/langerrors/include_in_function.zc b/tests/langerrors/include_in_function.zc
new file mode 100644
index 0000000..06136f9
--- /dev/null
+++ b/tests/langerrors/include_in_function.zc
@@ -0,0 +1,2 @@
+// expect: include is top level only
+fn main() { include std; return 0; }
diff --git a/tests/langerrors/proto_after_def_mismatch.zc b/tests/langerrors/proto_after_def_mismatch.zc
new file mode 100644
index 0000000..94a04e6
--- /dev/null
+++ b/tests/langerrors/proto_after_def_mismatch.zc
@@ -0,0 +1,4 @@
+// expect: f: doesn't match its earlier declaration
+int f(int a) { return a; }
+int f(int a, int b);
+fn main() { return f(1); }
diff --git a/tests/programs/zc0umd.zc b/tests/programs/zc0umd.zc
index 9693111..b5a6d2a 100644
--- a/tests/programs/zc0umd.zc
+++ b/tests/programs/zc0umd.zc
@@ -2,12 +2,13 @@ namespace;
include rt;
// u, m and d are ordinary names, and a tag is written .u, .m or .d after a type.
-// u*x, m*x and d*x with no space before the star is a recast, and u * x with a
-// space is a product. the same program runs on the resident compiler and, built
+// u*x, m*x and d*x with no space before the star is a recast when no variable
+// named u, m or d is visible there (spec 1.6.3); otherwise, and with a space, it
+// is a product. the same program runs on the resident compiler and, built
// into a run-only image, on stage 0 (src/tools/zc0.c), which reads the tags and
// recasts and does nothing with them.
-int u = 2, m = 3; // globals
+int uu = 2, m = 3; // globals (no global u, so u*x recasts below; m*x with m visible is a product)
int[4] d4;
int d(int x) { return x + 1; } // a function
@@ -17,12 +18,12 @@ int tagged(int(int) f, int.m x) { return f(x); }
// owned objects through locals named for their tags
word*.u box(int v) { word* m = rt.new(2); m[0] = v; m[1] = v * 2; return u*m; }
-word*.u pair(int u, int m) {
+word*.u pair(int x, int m) {
word* d = rt.new(2);
- d[0] = u; d[1] = m;
+ d[0] = x; d[1] = m;
return u*d;
}
-.u single(int v) { let u = rt.new(1); u[0] = v; return u*u; }
+.u single(int v) { let d = rt.new(1); d[0] = v; return u*d; }
int sum(word*.m m) { return m[0] + m[1]; }
int eat(word*.d d) { return d[0] + d[1]; }
int hold(.m u, .d d) { return u[0] * 100 + d[0]; }
@@ -35,9 +36,9 @@ fn main() {
.m q = single(6);
word* r = pair(8, 9);
let c = box(10), e = pair(1, 2);
- rt.put_n(u * m); rt.put_c(32); // two globals multiplied
- rt.put_n(u*=m); rt.put_c(32); // u *= m is not a recast either
- rt.put_n(d(u) * d(m)); rt.put_c(32);
+ rt.put_n(uu * m); rt.put_c(32); // two globals multiplied
+ rt.put_n(uu*=m); rt.put_c(32); // *= is not a recast either
+ rt.put_n(d(uu) * d(m)); rt.put_c(32);
rt.put_n(mul3(2, 3, 4)); rt.put_c(32);
rt.put_n(mixed(7, 6, 5)); rt.put_c(32);
rt.put_n(tagged(d, n)); rt.put_c(10);