raz / commit b38de572

commit
b38de572e45ecb08239dcafa18321d2aedd0aad7
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
24062e34
Conformance tests for the rules of the report that had none; F32 constants as the compiler reads them; the atExit hang noted

patch · log

49 files changed, +467 -4

conform/err/AnonRecords.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module AnonRecords;
2+var
3+ a: record x: I64; end;
4+ b: record x: I64; end;
5+proc main*;
6+begin
7+ a := b; (* records are always types of their own *)
8+end;
9+end AnonRecords.

conform/err/ForField.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module ForField;
2+type R = record x: INT; end;
3+proc main*;
4+var r: R;
5+begin
6+ for r.x := 1 to 3 do end; (* the variable is named by its name alone *)
7+end;
8+end ForField.

conform/err/GenInstDiff.raz (history) added +14 -0

@@ -0,0 +1,14 @@
1+module GenInstDiff;
2+import Table1 := Table(I64, I64, h1, same), Table2 := Table(I64, I64, h2, same);
3+
4+proc h1(k: I64): U64; begin return U64(k); end;
5+proc h2(k: I64): U64; begin return U64(k) + 1; end;
6+proc same(a, b: I64): BOOL; begin return a = b; end;
7+
8+var a: Table1.Table; b: Table2.Table;
9+
10+proc main*;
11+begin
12+ a := b; (* the procedures differ, so the instances do *)
13+end;
14+end GenInstDiff.

conform/err/ProcOrder.raz (history) added +10 -0

@@ -0,0 +1,10 @@
1+module ProcOrder;
2+proc f; begin end;
3+proc g; begin end;
4+proc main*;
5+var a, b: proc;
6+begin
7+ a := f; b := g;
8+ if a < b then end; (* procedures compare with = and # only *)
9+end;
10+end ProcOrder.

conform/err/SamenessTwo.raz (history) added +11 -0

@@ -0,0 +1,11 @@
1+module SamenessTwo;
2+type
3+ Node = record v: I64; end;
4+ P1 = ^Node;
5+ P2 = ^Node;
6+var a: P1; b: P2;
7+proc main*;
8+begin
9+ a := b; (* each is the same as ^Node, but they are two declarations *)
10+end;
11+end SamenessTwo.

conform/run/BodyOnly.expect (history) added +1 -0

@@ -0,0 +1 @@
1+body only

conform/run/BodyOnly.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+(* A program need not have a main: its module bodies run. *)
2+module BodyOnly;
3+import Out;
4+
5+begin
6+ Out.str("body only\n");
7+end BodyOnly.

conform/run/ConstWrap.expect (history) added +4 -0

@@ -0,0 +1,4 @@
1+4
2+1099511627776
3+-4
4+128

conform/run/ConstWrap.raz (history) added +19 -0

@@ -0,0 +1,19 @@
1+(* Constants of an integer type wrap as the program would; untyped
2+ ones don't; a shift of an untyped constant is untyped. *)
3+module ConstWrap;
4+import Out;
5+
6+proc main*;
7+var a, c: U8; b: I64; d: INT;
8+begin
9+ a := U8(250) + 10;
10+ b := 1 shl 40;
11+ d := -16 shr 2;
12+ c := U8(0C0H) shl 1;
13+ Out.int(I64(a)); Out.ln;
14+ Out.int(b); Out.ln;
15+ Out.int(d); Out.ln;
16+ Out.int(I64(c)); Out.ln;
17+end;
18+
19+end ConstWrap.

conform/run/DeferExit.expect (history) added +1 -0

@@ -0,0 +1 @@
1+before

conform/run/DeferExit.raz (history) added +13 -0

@@ -0,0 +1,13 @@
1+(* Rt.exit ends the program without running the deferred statements
2+ still pending. *)
3+module DeferExit;
4+import Out, Rt;
5+
6+proc main*;
7+begin
8+ defer Out.str("deferred\n");
9+ Out.str("before\n");
10+ Rt.exit(3);
11+end;
12+
13+end DeferExit.

conform/run/DeferExit.status (history) added +1 -0

@@ -0,0 +1 @@
1+3

conform/run/ErrorValues.expect (history) added +6 -0

@@ -0,0 +1,6 @@
1+One = Two false
2+One = One true
3+One # nil true
4+same same[]
5+same instance true
6+other instance false

conform/run/ErrorValues.raz (history) added +29 -0

@@ -0,0 +1,29 @@
1+(* Each declaration of an error makes one different from every other,
2+ whatever its message; a generic module makes its errors once for
3+ each instance. *)
4+module ErrorValues;
5+import Out, A := Fail(I64), B := Fail(I64), C := Fail(U8);
6+
7+const
8+ One: ERROR = "same";
9+ Two: ERROR = "same";
10+
11+proc yes(name: []U8; b: BOOL);
12+begin
13+ Out.str(name);
14+ if b then Out.str(" true"); else Out.str(" false"); end;
15+ Out.ln;
16+end;
17+
18+proc main*;
19+begin
20+ yes("One = Two", One = Two);
21+ yes("One = One", One = One);
22+ yes("One # nil", One # nil);
23+ Out.str(MSG(One)); Out.char(' '); Out.str(MSG(Two)); Out.char('[');
24+ Out.str(MSG(nil)); Out.str("]\n");
25+ yes("same instance", A.Oops = B.Oops);
26+ yes("other instance", A.Oops = C.Oops);
27+end;
28+
29+end ErrorValues.

conform/run/Escapes.expect (history) added +1 -0

@@ -0,0 +1 @@
1+175 175 240 159 152 128 240 159 152 128 65 195 169

conform/run/Escapes.raz (history) added +16 -0

@@ -0,0 +1,16 @@
1+(* The escapes of a string, in capitals or not. *)
2+module Escapes;
3+import Out;
4+
5+proc main*;
6+var s: []U8; i: INT;
7+begin
8+ s := "\xaF\xAF\u{1f600}\u{1F600}\x41\u{e9}";
9+ for i := 0 to LEN(s) - 1 do
10+ if i > 0 then Out.char(' '); end;
11+ Out.int(I64(s[i]));
12+ end;
13+ Out.ln;
14+end;
15+
16+end Escapes.

conform/run/ExitSkips.expect (history) added +1 -0

@@ -0,0 +1 @@
1+before

conform/run/ExitSkips.raz (history) added +17 -0

@@ -0,0 +1,17 @@
1+(* Sys.exit ends the program at once: the atExit procedures don't run. *)
2+module ExitSkips;
3+import Sys, Rt;
4+
5+proc bye;
6+begin
7+ _ := Sys.write(Sys.stdout, "bye\n");
8+end;
9+
10+proc main*;
11+begin
12+ _ := Rt.atExit(bye);
13+ _ := Sys.write(Sys.stdout, "before\n");
14+ Sys.exit(3);
15+end;
16+
17+end ExitSkips.

conform/run/ExitSkips.status (history) added +1 -0

@@ -0,0 +1 @@
1+3

conform/run/ExportedMatch.expect (history) added +2 -0

@@ -0,0 +1,2 @@
1+6
2+6

conform/run/ExportedMatch.raz (history) added +21 -0

@@ -0,0 +1,21 @@
1+(* match on an exported variable: its names stand for the fields of a
2+ copy, which the arm may change without changing the variable. *)
3+module ExportedMatch;
4+import Out, Shared;
5+
6+proc show;
7+begin
8+ match Shared.shape of
9+ | dot: Out.str("dot");
10+ | circle(r): r := r + 1; Out.int(r);
11+ end;
12+ Out.ln;
13+end;
14+
15+proc main*;
16+begin
17+ show;
18+ show;
19+end;
20+
21+end ExportedMatch.

conform/run/IncDec.expect (history) added +2 -0

@@ -0,0 +1,2 @@
1+3 1 3 255
2+0

conform/run/IncDec.raz (history) added +26 -0

@@ -0,0 +1,26 @@
1+(* INC and DEC evaluate the variable once, and wrap. *)
2+module IncDec;
3+import Out;
4+
5+var n: INT; a: [3]U8;
6+
7+proc next(): INT;
8+begin
9+ INC(n);
10+ return n - 1;
11+end;
12+
13+proc main*;
14+var i: INT;
15+begin
16+ INC(a[next()]);
17+ INC(a[next()], 3);
18+ DEC(a[next()]);
19+ Out.int(n);
20+ for i := 0 to 2 do Out.char(' '); Out.int(I64(a[i])); end;
21+ Out.ln;
22+ INC(a[2]);
23+ Out.int(I64(a[2])); Out.ln;
24+end;
25+
26+end IncDec.

conform/run/IndexBig.expect (history) added +1 -0

@@ -0,0 +1 @@
1+before

conform/run/IndexBig.raz (history) added +15 -0

@@ -0,0 +1,15 @@
1+(* An index is checked by its value: 4294967297 in a U64 is past the
2+ length, not 1. *)
3+module IndexBig;
4+import Out;
5+
6+proc main*;
7+var a: [3]I64; u: U64;
8+begin
9+ Out.str("before\n");
10+ u := 4294967297;
11+ Out.int(a[u]);
12+ Out.str("after\n");
13+end;
14+
15+end IndexBig.

conform/run/IndexBig.status (history) added +1 -0

@@ -0,0 +1 @@
1+2

conform/run/IndexSmall.expect (history) added +1 -0

@@ -0,0 +1 @@
1+before

conform/run/IndexSmall.raz (history) added +15 -0

@@ -0,0 +1,15 @@
1+(* An index is checked by its value, whatever its type: -128 in an I8
2+ is not 128. *)
3+module IndexSmall;
4+import Out;
5+
6+proc main*;
7+var a: [200]I64; i: I8;
8+begin
9+ Out.str("before\n");
10+ i := -128;
11+ Out.int(a[i]);
12+ Out.str("after\n");
13+end;
14+
15+end IndexSmall.

conform/run/IndexSmall.status (history) added +1 -0

@@ -0,0 +1 @@
1+2

conform/run/Names.expect (history) added +2 -0

@@ -0,0 +1,2 @@
1+15
2+300 8

conform/run/Names.raz (history) added +20 -0

@@ -0,0 +1,20 @@
1+(* Words that aren't reserved are names, and a predeclared name may be
2+ declared again, which hides it in its scope. *)
3+module Names;
4+import Out;
5+
6+type U8 = I64;
7+
8+var static, check, off, volatile: INT;
9+ big: U8;
10+
11+proc main*;
12+var true: INT;
13+begin
14+ static := 1; check := 2; off := 3; volatile := 4; true := 5;
15+ big := 300;
16+ Out.int(static + check + off + volatile + true); Out.ln;
17+ Out.int(big); Out.char(' '); Out.int(SIZE(U8)); Out.ln;
18+end;
19+
20+end Names.

conform/run/ProcValue.expect (history) added +4 -0

@@ -0,0 +1,4 @@
1+hello
2+hello
3+5
4+same

conform/run/ProcValue.raz (history) added +27 -0

@@ -0,0 +1,27 @@
1+(* Used without parentheses in an expression, a procedure is a value;
2+ on its own it is a call. *)
3+module ProcValue;
4+import Out;
5+
6+proc hello;
7+begin
8+ Out.str("hello\n");
9+end;
10+
11+proc five(): I64;
12+begin
13+ return 5;
14+end;
15+
16+proc main*;
17+var f: proc; g: proc(): I64;
18+begin
19+ f := hello;
20+ f();
21+ hello;
22+ g := five;
23+ Out.int(g()); Out.ln;
24+ if g = five then Out.str("same\n"); end;
25+end;
26+
27+end ProcValue.

conform/run/PtrOrder.expect (history) added +1 -0

@@ -0,0 +1 @@
1+true true false false false true true true false

conform/run/PtrOrder.raz (history) added +21 -0

@@ -0,0 +1,21 @@
1+(* Pointers compare with = # < <= > >=, as unsigned addresses. *)
2+module PtrOrder;
3+import Out;
4+
5+proc yes(b: BOOL);
6+begin
7+ if b then Out.str("true "); else Out.str("false "); end;
8+end;
9+
10+proc main*;
11+var a: [3]I64; p, q: ^I64;
12+begin
13+ p := ADR(a[0]);
14+ q := ADR(a[2]);
15+ yes(p < q); yes(p <= q); yes(p > q); yes(p >= q); yes(p = q); yes(p # q);
16+ q := ADR(a[0]);
17+ yes(p <= q); yes(p >= q); yes(p < q);
18+ Out.ln;
19+end;
20+
21+end PtrOrder.

conform/run/Sameness.expect (history) added +1 -0

@@ -0,0 +1 @@
1+14

conform/run/Sameness.raz (history) added +25 -0

@@ -0,0 +1,25 @@
1+(* A named type and an anonymous one built alike are the same; of two
2+ named types built alike on the right, each is the same as the
3+ anonymous one. *)
4+module Sameness;
5+import Out;
6+
7+type
8+ Node = record v: I64; end;
9+ P1 = ^Node;
10+ P2 = ^Node;
11+ NodePtr = ^Node;
12+
13+proc main*;
14+var r: Node; p1: P1; p2: P2; n: ^Node; q: NodePtr;
15+begin
16+ r.v := 7;
17+ n := ADR(r);
18+ p1 := n;
19+ n := p1;
20+ p2 := n;
21+ q := ADR(r);
22+ Out.int(p2^.v + q^.v); Out.ln;
23+end;
24+
25+end Sameness.

conform/run/Sizes.expect (history) added +7 -0

@@ -0,0 +1,7 @@
1+1 2 4 8 1 1
2+INT is an address yes
3+UINT is an address yes
4+procedure is an address yes
5+ERROR is an address yes
6+slice is two yes
7+empty record yes

conform/run/Sizes.raz (history) added +28 -0

@@ -0,0 +1,28 @@
1+(* Sizes the report fixes on every target, and those it ties to the
2+ size of an address. *)
3+module Sizes;
4+import Out;
5+
6+type Empty = record end;
7+
8+proc line(name: []U8; b: BOOL);
9+begin
10+ Out.str(name);
11+ if b then Out.str(" yes"); else Out.str(" NO"); end;
12+ Out.ln;
13+end;
14+
15+proc main*;
16+begin
17+ Out.int(SIZE(I8)); Out.char(' '); Out.int(SIZE(I16)); Out.char(' ');
18+ Out.int(SIZE(I32)); Out.char(' '); Out.int(SIZE(I64)); Out.char(' ');
19+ Out.int(SIZE(U8)); Out.char(' '); Out.int(SIZE(BOOL)); Out.ln;
20+ line("INT is an address", SIZE(INT) = SIZE(^U8));
21+ line("UINT is an address", SIZE(UINT) = SIZE(^U8));
22+ line("procedure is an address", SIZE(proc) = SIZE(^U8));
23+ line("ERROR is an address", SIZE(ERROR) = SIZE(^U8));
24+ line("slice is two", SIZE([]U8) = 2 * SIZE(^U8));
25+ line("empty record", SIZE(Empty) = 0);
26+end;
27+
28+end Sizes.

conform/run/TryOrder.expect (history) added +2 -0

@@ -0,0 +1,2 @@
1+ig 9
2+ib 0 oops

conform/run/TryOrder.raz (history) added +44 -0

@@ -0,0 +1,44 @@
1+(* In t[i()] := try f(), i is called before f, and if f fails nothing
2+ is assigned. *)
3+module TryOrder;
4+import Out;
5+
6+const Oops: ERROR = "oops";
7+
8+var t: [3]I64;
9+
10+proc idx(): INT;
11+begin
12+ Out.char('i');
13+ return 1;
14+end;
15+
16+proc good(): (I64, ERROR);
17+begin
18+ Out.char('g');
19+ return 9, nil;
20+end;
21+
22+proc bad(): (I64, ERROR);
23+begin
24+ Out.char('b');
25+ return 9, Oops;
26+end;
27+
28+proc run(f: proc(): (I64, ERROR)): ERROR;
29+begin
30+ t[idx()] := try f();
31+ return nil;
32+end;
33+
34+proc main*;
35+var e: ERROR;
36+begin
37+ e := run(good);
38+ Out.char(' '); Out.int(t[1]); Out.char(' '); Out.str(MSG(e)); Out.ln;
39+ t[1] := 0;
40+ e := run(bad);
41+ Out.char(' '); Out.int(t[1]); Out.char(' '); Out.str(MSG(e)); Out.ln;
42+end;
43+
44+end TryOrder.

conform/run/mods/Fail.raz (history) added +6 -0

@@ -0,0 +1,6 @@
1+(* A generic module with an error: made once for each instance *)
2+module Fail(T);
3+
4+const Oops*: ERROR = "oops";
5+
6+end Fail.

doc/compiler.md (history) modified +1 -1

@@ -1485,7 +1485,7 @@
14851485 is told at the place of the statement it stopped in, or of the
14861486 procedure for a stack overflow in its prologue, and then `Rt.exit`
14871487 ends the program with status 2, after the procedures registered with
1488- `Rt.atExit`, as for a failed check. The handlers run on a stack
1488+ `Rt.atExit`, as for a failed check. A fault inside a section that holds the lock of `Out` or `Heap` (a stack overflow in `Out`, say) would leave `atExit`'s flush waiting for it: the program hangs instead of ending. This is rare, and a failed check has the same exposure. The handlers run on a stack
14891489 of their own: `Rt`'s for the main thread, one in each `Thread`
14901490 thread's mapping. C's threads have none, so a stack overflow in one
14911491 ends the program by the signal with no message.

doc/raz.md (history) modified +4 -3

@@ -91,9 +91,10 @@
9191 untyped constants doesn't wrap: a result beyond the `I64`s, such as
9292 `9223372036854775807 + 1`, is an error.
9393
94-A real is an untyped constant too, which takes `F32` or `F64`,
95-whichever it is used as, rounded to the nearest value of that type;
96-where nothing says which, it is an `F64`. A real never becomes an
94+A real is an untyped constant too. It is read as the nearest `F64`
95+(a tie goes to the even one), and takes `F32` or `F64`, whichever it is
96+used as: an `F32` is the nearest to that `F64`. Where nothing says
97+which, it is an `F64`. A real never becomes an
9798 integer, nor an integer a real, without a conversion: `x := 1;` is an
9899 error for `x: F64`, and `x := 1.0;` is right.
99100

test/msg/AnonRecords.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/AnonRecords.raz:7:10: error: can't use record as record
2+ 7 | a := b; (* records are always types of their own *)
3+ | ^
4+raz: 1 error

test/msg/ForField.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/ForField.raz:6:9: error: a for loop needs an integer or enumeration variable, found R
2+ 6 | for r.x := 1 to 3 do end; (* the variable is named by its name alone *)
3+ | ^
4+raz: 1 error

test/msg/GenInstDiff.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/GenInstDiff.raz:12:10: error: can't use Table(I64,I64,GenInstDiff.h2,GenInstDiff.same).Table as Table(I64,I64,GenInstDiff.h1,GenInstDiff.same).Table
2+ 12 | a := b; (* the procedures differ, so the instances do *)
3+ | ^
4+raz: 1 error

test/msg/ProcOrder.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/ProcOrder.raz:8:8: error: "<" doesn't apply to proc()
2+ 8 | if a < b then end; (* procedures compare with = and # only *)
3+ | ^^^^^
4+raz: 1 error

test/msg/SamenessTwo.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/SamenessTwo.raz:9:10: error: can't use P2 as P1
2+ 9 | a := b; (* each is the same as ^Node, but they are two declarations *)
3+ | ^
4+raz: 1 error