From b38de572e45ecb08239dcafa18321d2aedd0aad7 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:06:55 +0100 Subject: [PATCH] Conformance tests for the rules of the report that had none; F32 constants as the compiler reads them; the atExit hang noted --- diff --git a/conform/err/AnonRecords.raz b/conform/err/AnonRecords.raz new file mode 100644 index 0000000..8789ba5 --- /dev/null +++ b/conform/err/AnonRecords.raz @@ -0,0 +1,9 @@ +module AnonRecords; +var + a: record x: I64; end; + b: record x: I64; end; +proc main*; +begin + a := b; (* records are always types of their own *) +end; +end AnonRecords. diff --git a/conform/err/ForField.raz b/conform/err/ForField.raz new file mode 100644 index 0000000..8149d33 --- /dev/null +++ b/conform/err/ForField.raz @@ -0,0 +1,8 @@ +module ForField; +type R = record x: INT; end; +proc main*; +var r: R; +begin + for r.x := 1 to 3 do end; (* the variable is named by its name alone *) +end; +end ForField. diff --git a/conform/err/GenInstDiff.raz b/conform/err/GenInstDiff.raz new file mode 100644 index 0000000..fcfa140 --- /dev/null +++ b/conform/err/GenInstDiff.raz @@ -0,0 +1,14 @@ +module GenInstDiff; +import Table1 := Table(I64, I64, h1, same), Table2 := Table(I64, I64, h2, same); + +proc h1(k: I64): U64; begin return U64(k); end; +proc h2(k: I64): U64; begin return U64(k) + 1; end; +proc same(a, b: I64): BOOL; begin return a = b; end; + +var a: Table1.Table; b: Table2.Table; + +proc main*; +begin + a := b; (* the procedures differ, so the instances do *) +end; +end GenInstDiff. diff --git a/conform/err/ProcOrder.raz b/conform/err/ProcOrder.raz new file mode 100644 index 0000000..0c3223b --- /dev/null +++ b/conform/err/ProcOrder.raz @@ -0,0 +1,10 @@ +module ProcOrder; +proc f; begin end; +proc g; begin end; +proc main*; +var a, b: proc; +begin + a := f; b := g; + if a < b then end; (* procedures compare with = and # only *) +end; +end ProcOrder. diff --git a/conform/err/SamenessTwo.raz b/conform/err/SamenessTwo.raz new file mode 100644 index 0000000..7950753 --- /dev/null +++ b/conform/err/SamenessTwo.raz @@ -0,0 +1,11 @@ +module SamenessTwo; +type + Node = record v: I64; end; + P1 = ^Node; + P2 = ^Node; +var a: P1; b: P2; +proc main*; +begin + a := b; (* each is the same as ^Node, but they are two declarations *) +end; +end SamenessTwo. diff --git a/conform/run/BodyOnly.expect b/conform/run/BodyOnly.expect new file mode 100644 index 0000000..7483374 --- /dev/null +++ b/conform/run/BodyOnly.expect @@ -0,0 +1 @@ +body only diff --git a/conform/run/BodyOnly.raz b/conform/run/BodyOnly.raz new file mode 100644 index 0000000..9f306e5 --- /dev/null +++ b/conform/run/BodyOnly.raz @@ -0,0 +1,7 @@ +(* A program need not have a main: its module bodies run. *) +module BodyOnly; +import Out; + +begin + Out.str("body only\n"); +end BodyOnly. diff --git a/conform/run/ConstWrap.expect b/conform/run/ConstWrap.expect new file mode 100644 index 0000000..1d8c3cb --- /dev/null +++ b/conform/run/ConstWrap.expect @@ -0,0 +1,4 @@ +4 +1099511627776 +-4 +128 diff --git a/conform/run/ConstWrap.raz b/conform/run/ConstWrap.raz new file mode 100644 index 0000000..aa90c2d --- /dev/null +++ b/conform/run/ConstWrap.raz @@ -0,0 +1,19 @@ +(* Constants of an integer type wrap as the program would; untyped + ones don't; a shift of an untyped constant is untyped. *) +module ConstWrap; +import Out; + +proc main*; +var a, c: U8; b: I64; d: INT; +begin + a := U8(250) + 10; + b := 1 shl 40; + d := -16 shr 2; + c := U8(0C0H) shl 1; + Out.int(I64(a)); Out.ln; + Out.int(b); Out.ln; + Out.int(d); Out.ln; + Out.int(I64(c)); Out.ln; +end; + +end ConstWrap. diff --git a/conform/run/DeferExit.expect b/conform/run/DeferExit.expect new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/conform/run/DeferExit.expect @@ -0,0 +1 @@ +before diff --git a/conform/run/DeferExit.raz b/conform/run/DeferExit.raz new file mode 100644 index 0000000..3f7b5ae --- /dev/null +++ b/conform/run/DeferExit.raz @@ -0,0 +1,13 @@ +(* Rt.exit ends the program without running the deferred statements + still pending. *) +module DeferExit; +import Out, Rt; + +proc main*; +begin + defer Out.str("deferred\n"); + Out.str("before\n"); + Rt.exit(3); +end; + +end DeferExit. diff --git a/conform/run/DeferExit.status b/conform/run/DeferExit.status new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/conform/run/DeferExit.status @@ -0,0 +1 @@ +3 diff --git a/conform/run/ErrorValues.expect b/conform/run/ErrorValues.expect new file mode 100644 index 0000000..1af2574 --- /dev/null +++ b/conform/run/ErrorValues.expect @@ -0,0 +1,6 @@ +One = Two false +One = One true +One # nil true +same same[] +same instance true +other instance false diff --git a/conform/run/ErrorValues.raz b/conform/run/ErrorValues.raz new file mode 100644 index 0000000..7f0fdfd --- /dev/null +++ b/conform/run/ErrorValues.raz @@ -0,0 +1,29 @@ +(* Each declaration of an error makes one different from every other, + whatever its message; a generic module makes its errors once for + each instance. *) +module ErrorValues; +import Out, A := Fail(I64), B := Fail(I64), C := Fail(U8); + +const + One: ERROR = "same"; + Two: ERROR = "same"; + +proc yes(name: []U8; b: BOOL); +begin + Out.str(name); + if b then Out.str(" true"); else Out.str(" false"); end; + Out.ln; +end; + +proc main*; +begin + yes("One = Two", One = Two); + yes("One = One", One = One); + yes("One # nil", One # nil); + Out.str(MSG(One)); Out.char(' '); Out.str(MSG(Two)); Out.char('['); + Out.str(MSG(nil)); Out.str("]\n"); + yes("same instance", A.Oops = B.Oops); + yes("other instance", A.Oops = C.Oops); +end; + +end ErrorValues. diff --git a/conform/run/Escapes.expect b/conform/run/Escapes.expect new file mode 100644 index 0000000..73c0804 --- /dev/null +++ b/conform/run/Escapes.expect @@ -0,0 +1 @@ +175 175 240 159 152 128 240 159 152 128 65 195 169 diff --git a/conform/run/Escapes.raz b/conform/run/Escapes.raz new file mode 100644 index 0000000..b26a910 --- /dev/null +++ b/conform/run/Escapes.raz @@ -0,0 +1,16 @@ +(* The escapes of a string, in capitals or not. *) +module Escapes; +import Out; + +proc main*; +var s: []U8; i: INT; +begin + s := "\xaF\xAF\u{1f600}\u{1F600}\x41\u{e9}"; + for i := 0 to LEN(s) - 1 do + if i > 0 then Out.char(' '); end; + Out.int(I64(s[i])); + end; + Out.ln; +end; + +end Escapes. diff --git a/conform/run/ExitSkips.expect b/conform/run/ExitSkips.expect new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/conform/run/ExitSkips.expect @@ -0,0 +1 @@ +before diff --git a/conform/run/ExitSkips.raz b/conform/run/ExitSkips.raz new file mode 100644 index 0000000..2742458 --- /dev/null +++ b/conform/run/ExitSkips.raz @@ -0,0 +1,17 @@ +(* Sys.exit ends the program at once: the atExit procedures don't run. *) +module ExitSkips; +import Sys, Rt; + +proc bye; +begin + _ := Sys.write(Sys.stdout, "bye\n"); +end; + +proc main*; +begin + _ := Rt.atExit(bye); + _ := Sys.write(Sys.stdout, "before\n"); + Sys.exit(3); +end; + +end ExitSkips. diff --git a/conform/run/ExitSkips.status b/conform/run/ExitSkips.status new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/conform/run/ExitSkips.status @@ -0,0 +1 @@ +3 diff --git a/conform/run/ExportedMatch.expect b/conform/run/ExportedMatch.expect new file mode 100644 index 0000000..91dea2c --- /dev/null +++ b/conform/run/ExportedMatch.expect @@ -0,0 +1,2 @@ +6 +6 diff --git a/conform/run/ExportedMatch.raz b/conform/run/ExportedMatch.raz new file mode 100644 index 0000000..abdbf4f --- /dev/null +++ b/conform/run/ExportedMatch.raz @@ -0,0 +1,21 @@ +(* match on an exported variable: its names stand for the fields of a + copy, which the arm may change without changing the variable. *) +module ExportedMatch; +import Out, Shared; + +proc show; +begin + match Shared.shape of + | dot: Out.str("dot"); + | circle(r): r := r + 1; Out.int(r); + end; + Out.ln; +end; + +proc main*; +begin + show; + show; +end; + +end ExportedMatch. diff --git a/conform/run/IncDec.expect b/conform/run/IncDec.expect new file mode 100644 index 0000000..61e3d60 --- /dev/null +++ b/conform/run/IncDec.expect @@ -0,0 +1,2 @@ +3 1 3 255 +0 diff --git a/conform/run/IncDec.raz b/conform/run/IncDec.raz new file mode 100644 index 0000000..40123d0 --- /dev/null +++ b/conform/run/IncDec.raz @@ -0,0 +1,26 @@ +(* INC and DEC evaluate the variable once, and wrap. *) +module IncDec; +import Out; + +var n: INT; a: [3]U8; + +proc next(): INT; +begin + INC(n); + return n - 1; +end; + +proc main*; +var i: INT; +begin + INC(a[next()]); + INC(a[next()], 3); + DEC(a[next()]); + Out.int(n); + for i := 0 to 2 do Out.char(' '); Out.int(I64(a[i])); end; + Out.ln; + INC(a[2]); + Out.int(I64(a[2])); Out.ln; +end; + +end IncDec. diff --git a/conform/run/IndexBig.expect b/conform/run/IndexBig.expect new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/conform/run/IndexBig.expect @@ -0,0 +1 @@ +before diff --git a/conform/run/IndexBig.raz b/conform/run/IndexBig.raz new file mode 100644 index 0000000..6ff14df --- /dev/null +++ b/conform/run/IndexBig.raz @@ -0,0 +1,15 @@ +(* An index is checked by its value: 4294967297 in a U64 is past the + length, not 1. *) +module IndexBig; +import Out; + +proc main*; +var a: [3]I64; u: U64; +begin + Out.str("before\n"); + u := 4294967297; + Out.int(a[u]); + Out.str("after\n"); +end; + +end IndexBig. diff --git a/conform/run/IndexBig.status b/conform/run/IndexBig.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conform/run/IndexBig.status @@ -0,0 +1 @@ +2 diff --git a/conform/run/IndexSmall.expect b/conform/run/IndexSmall.expect new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/conform/run/IndexSmall.expect @@ -0,0 +1 @@ +before diff --git a/conform/run/IndexSmall.raz b/conform/run/IndexSmall.raz new file mode 100644 index 0000000..84e0810 --- /dev/null +++ b/conform/run/IndexSmall.raz @@ -0,0 +1,15 @@ +(* An index is checked by its value, whatever its type: -128 in an I8 + is not 128. *) +module IndexSmall; +import Out; + +proc main*; +var a: [200]I64; i: I8; +begin + Out.str("before\n"); + i := -128; + Out.int(a[i]); + Out.str("after\n"); +end; + +end IndexSmall. diff --git a/conform/run/IndexSmall.status b/conform/run/IndexSmall.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conform/run/IndexSmall.status @@ -0,0 +1 @@ +2 diff --git a/conform/run/Names.expect b/conform/run/Names.expect new file mode 100644 index 0000000..5bb611f --- /dev/null +++ b/conform/run/Names.expect @@ -0,0 +1,2 @@ +15 +300 8 diff --git a/conform/run/Names.raz b/conform/run/Names.raz new file mode 100644 index 0000000..baab72c --- /dev/null +++ b/conform/run/Names.raz @@ -0,0 +1,20 @@ +(* Words that aren't reserved are names, and a predeclared name may be + declared again, which hides it in its scope. *) +module Names; +import Out; + +type U8 = I64; + +var static, check, off, volatile: INT; + big: U8; + +proc main*; +var true: INT; +begin + static := 1; check := 2; off := 3; volatile := 4; true := 5; + big := 300; + Out.int(static + check + off + volatile + true); Out.ln; + Out.int(big); Out.char(' '); Out.int(SIZE(U8)); Out.ln; +end; + +end Names. diff --git a/conform/run/ProcValue.expect b/conform/run/ProcValue.expect new file mode 100644 index 0000000..8123092 --- /dev/null +++ b/conform/run/ProcValue.expect @@ -0,0 +1,4 @@ +hello +hello +5 +same diff --git a/conform/run/ProcValue.raz b/conform/run/ProcValue.raz new file mode 100644 index 0000000..e24481a --- /dev/null +++ b/conform/run/ProcValue.raz @@ -0,0 +1,27 @@ +(* Used without parentheses in an expression, a procedure is a value; + on its own it is a call. *) +module ProcValue; +import Out; + +proc hello; +begin + Out.str("hello\n"); +end; + +proc five(): I64; +begin + return 5; +end; + +proc main*; +var f: proc; g: proc(): I64; +begin + f := hello; + f(); + hello; + g := five; + Out.int(g()); Out.ln; + if g = five then Out.str("same\n"); end; +end; + +end ProcValue. diff --git a/conform/run/PtrOrder.expect b/conform/run/PtrOrder.expect new file mode 100644 index 0000000..f1b8284 --- /dev/null +++ b/conform/run/PtrOrder.expect @@ -0,0 +1 @@ +true true false false false true true true false diff --git a/conform/run/PtrOrder.raz b/conform/run/PtrOrder.raz new file mode 100644 index 0000000..9e93eb3 --- /dev/null +++ b/conform/run/PtrOrder.raz @@ -0,0 +1,21 @@ +(* Pointers compare with = # < <= > >=, as unsigned addresses. *) +module PtrOrder; +import Out; + +proc yes(b: BOOL); +begin + if b then Out.str("true "); else Out.str("false "); end; +end; + +proc main*; +var a: [3]I64; p, q: ^I64; +begin + p := ADR(a[0]); + q := ADR(a[2]); + yes(p < q); yes(p <= q); yes(p > q); yes(p >= q); yes(p = q); yes(p # q); + q := ADR(a[0]); + yes(p <= q); yes(p >= q); yes(p < q); + Out.ln; +end; + +end PtrOrder. diff --git a/conform/run/Sameness.expect b/conform/run/Sameness.expect new file mode 100644 index 0000000..8351c19 --- /dev/null +++ b/conform/run/Sameness.expect @@ -0,0 +1 @@ +14 diff --git a/conform/run/Sameness.raz b/conform/run/Sameness.raz new file mode 100644 index 0000000..bb683fb --- /dev/null +++ b/conform/run/Sameness.raz @@ -0,0 +1,25 @@ +(* A named type and an anonymous one built alike are the same; of two + named types built alike on the right, each is the same as the + anonymous one. *) +module Sameness; +import Out; + +type + Node = record v: I64; end; + P1 = ^Node; + P2 = ^Node; + NodePtr = ^Node; + +proc main*; +var r: Node; p1: P1; p2: P2; n: ^Node; q: NodePtr; +begin + r.v := 7; + n := ADR(r); + p1 := n; + n := p1; + p2 := n; + q := ADR(r); + Out.int(p2^.v + q^.v); Out.ln; +end; + +end Sameness. diff --git a/conform/run/Sizes.expect b/conform/run/Sizes.expect new file mode 100644 index 0000000..9fd102d --- /dev/null +++ b/conform/run/Sizes.expect @@ -0,0 +1,7 @@ +1 2 4 8 1 1 +INT is an address yes +UINT is an address yes +procedure is an address yes +ERROR is an address yes +slice is two yes +empty record yes diff --git a/conform/run/Sizes.raz b/conform/run/Sizes.raz new file mode 100644 index 0000000..8c18067 --- /dev/null +++ b/conform/run/Sizes.raz @@ -0,0 +1,28 @@ +(* Sizes the report fixes on every target, and those it ties to the + size of an address. *) +module Sizes; +import Out; + +type Empty = record end; + +proc line(name: []U8; b: BOOL); +begin + Out.str(name); + if b then Out.str(" yes"); else Out.str(" NO"); end; + Out.ln; +end; + +proc main*; +begin + Out.int(SIZE(I8)); Out.char(' '); Out.int(SIZE(I16)); Out.char(' '); + Out.int(SIZE(I32)); Out.char(' '); Out.int(SIZE(I64)); Out.char(' '); + Out.int(SIZE(U8)); Out.char(' '); Out.int(SIZE(BOOL)); Out.ln; + line("INT is an address", SIZE(INT) = SIZE(^U8)); + line("UINT is an address", SIZE(UINT) = SIZE(^U8)); + line("procedure is an address", SIZE(proc) = SIZE(^U8)); + line("ERROR is an address", SIZE(ERROR) = SIZE(^U8)); + line("slice is two", SIZE([]U8) = 2 * SIZE(^U8)); + line("empty record", SIZE(Empty) = 0); +end; + +end Sizes. diff --git a/conform/run/TryOrder.expect b/conform/run/TryOrder.expect new file mode 100644 index 0000000..7be1b3a --- /dev/null +++ b/conform/run/TryOrder.expect @@ -0,0 +1,2 @@ +ig 9 +ib 0 oops diff --git a/conform/run/TryOrder.raz b/conform/run/TryOrder.raz new file mode 100644 index 0000000..7e145c9 --- /dev/null +++ b/conform/run/TryOrder.raz @@ -0,0 +1,44 @@ +(* In t[i()] := try f(), i is called before f, and if f fails nothing + is assigned. *) +module TryOrder; +import Out; + +const Oops: ERROR = "oops"; + +var t: [3]I64; + +proc idx(): INT; +begin + Out.char('i'); + return 1; +end; + +proc good(): (I64, ERROR); +begin + Out.char('g'); + return 9, nil; +end; + +proc bad(): (I64, ERROR); +begin + Out.char('b'); + return 9, Oops; +end; + +proc run(f: proc(): (I64, ERROR)): ERROR; +begin + t[idx()] := try f(); + return nil; +end; + +proc main*; +var e: ERROR; +begin + e := run(good); + Out.char(' '); Out.int(t[1]); Out.char(' '); Out.str(MSG(e)); Out.ln; + t[1] := 0; + e := run(bad); + Out.char(' '); Out.int(t[1]); Out.char(' '); Out.str(MSG(e)); Out.ln; +end; + +end TryOrder. diff --git a/conform/run/mods/Fail.raz b/conform/run/mods/Fail.raz new file mode 100644 index 0000000..d6fd352 --- /dev/null +++ b/conform/run/mods/Fail.raz @@ -0,0 +1,6 @@ +(* A generic module with an error: made once for each instance *) +module Fail(T); + +const Oops*: ERROR = "oops"; + +end Fail. diff --git a/doc/compiler.md b/doc/compiler.md index 73402ac..d0b4662 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1485,7 +1485,7 @@ is told at the place of the statement it stopped in, or of the procedure for a stack overflow in its prologue, and then `Rt.exit` ends the program with status 2, after the procedures registered with - `Rt.atExit`, as for a failed check. The handlers run on a stack + `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 of their own: `Rt`'s for the main thread, one in each `Thread` thread's mapping. C's threads have none, so a stack overflow in one ends the program by the signal with no message. diff --git a/doc/raz.md b/doc/raz.md index cecc89b..94fa94d 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -91,9 +91,10 @@ untyped constants doesn't wrap: a result beyond the `I64`s, such as `9223372036854775807 + 1`, is an error. -A real is an untyped constant too, which takes `F32` or `F64`, -whichever it is used as, rounded to the nearest value of that type; -where nothing says which, it is an `F64`. A real never becomes an +A real is an untyped constant too. It is read as the nearest `F64` +(a tie goes to the even one), and takes `F32` or `F64`, whichever it is +used as: an `F32` is the nearest to that `F64`. Where nothing says +which, it is an `F64`. A real never becomes an integer, nor an integer a real, without a conversion: `x := 1;` is an error for `x: F64`, and `x := 1.0;` is right. diff --git a/test/msg/AnonRecords.err b/test/msg/AnonRecords.err new file mode 100644 index 0000000..3bff82a --- /dev/null +++ b/test/msg/AnonRecords.err @@ -0,0 +1,4 @@ +conform/err/AnonRecords.raz:7:10: error: can't use record as record + 7 | a := b; (* records are always types of their own *) + | ^ +raz: 1 error diff --git a/test/msg/ForField.err b/test/msg/ForField.err new file mode 100644 index 0000000..81f68c7 --- /dev/null +++ b/test/msg/ForField.err @@ -0,0 +1,4 @@ +conform/err/ForField.raz:6:9: error: a for loop needs an integer or enumeration variable, found R + 6 | for r.x := 1 to 3 do end; (* the variable is named by its name alone *) + | ^ +raz: 1 error diff --git a/test/msg/GenInstDiff.err b/test/msg/GenInstDiff.err new file mode 100644 index 0000000..1a2a911 --- /dev/null +++ b/test/msg/GenInstDiff.err @@ -0,0 +1,4 @@ +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 + 12 | a := b; (* the procedures differ, so the instances do *) + | ^ +raz: 1 error diff --git a/test/msg/ProcOrder.err b/test/msg/ProcOrder.err new file mode 100644 index 0000000..3ff1066 --- /dev/null +++ b/test/msg/ProcOrder.err @@ -0,0 +1,4 @@ +conform/err/ProcOrder.raz:8:8: error: "<" doesn't apply to proc() + 8 | if a < b then end; (* procedures compare with = and # only *) + | ^^^^^ +raz: 1 error diff --git a/test/msg/SamenessTwo.err b/test/msg/SamenessTwo.err new file mode 100644 index 0000000..668ab06 --- /dev/null +++ b/test/msg/SamenessTwo.err @@ -0,0 +1,4 @@ +conform/err/SamenessTwo.raz:9:10: error: can't use P2 as P1 + 9 | a := b; (* each is the same as ^Node, but they are two declarations *) + | ^ +raz: 1 error