An error in a library from -I or RAZ_PATH says the raz its RAZ-VERSION names
| @@ -16,17 +16,17 @@ | ||
| 16 | 16 | |
| 17 | 17 | | File | Lines | Code | What | |
| 18 | 18 | |---|---|---|---| |
| 19 | -| `src/Diag.raz` | 410 | 315 | Messages: positions, source excerpts, colour, counts | | |
| 19 | +| `src/Diag.raz` | 422 | 324 | Messages: positions, source excerpts, colour, counts | | |
| 20 | 20 | | `src/Scan.raz` | 1,148 | 949 | Symbols, literals, comments, positions | |
| 21 | 21 | | `src/Sym.raz` | 715 | 573 | Types, objects, scopes, layout | |
| 22 | 22 | | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | |
| 23 | 23 | | `src/X64.raz` | 1,584 | 1,304 | The instruction encoder, jumps within a procedure, the assembler | |
| 24 | 24 | | `src/Gen.raz` | 2,592 | 1,843 | The stack machine, for x86-64: values, operations, checks, calls, frames | |
| 25 | 25 | | `src/Item.raz` | 2,223 | 1,785 | Items: types, constants, variables, operators, conversions, calls | |
| 26 | -| `src/Parse.raz` | 4,266 | 3,689 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 26 | +| `src/Parse.raz` | 4,323 | 3,735 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 27 | 27 | | `src/Link.raz` | 407 | 315 | Tree shaking, layout, patching, the places | |
| 28 | 28 | | `src/Elf.raz` | 449 | 355 | Static and dynamic ELF, symbol table, line numbers | |
| 29 | -| `src/Raz.raz` | 417 | 332 | The command line | | |
| 29 | +| `src/Raz.raz` | 418 | 333 | The command line | | |
| 30 | 30 | |
| 31 | 31 | Every file opens with a comment that says what it is, what it depends |
| 32 | 32 | on and what it leaves out. Read those first; they are the map. |
| @@ -895,7 +895,9 @@ | ||
| 895 | 895 | follows from another (see Parse.raz). The line and column are worked out |
| 896 | 896 | only when a message is printed (`locate`, `chars`), so positions cost |
| 897 | 897 | nothing while compiling. `addFile` keeps every source file the scanner |
| 898 | -opens, so a note can show a line of any of them. `finish` prints the | |
| 898 | +opens, so a note can show a line of any of them. A file may carry one | |
| 899 | +line to tell (`setOrigin`), shown once under the first message about | |
| 900 | +it: the parser gives a library's. `finish` prints the | |
| 899 | 901 | count of errors and warnings and stops if there were errors; `fatal` is |
| 900 | 902 | for errors with no place in the source. A message is made by `say` from |
| 901 | 903 | a format and its arguments, and kept for good, since a message is made |
| @@ -1537,7 +1539,11 @@ | ||
| 1537 | 1539 | |
| 1538 | 1540 | Last, modules, at the end of the file. `compileFile` reads one module. |
| 1539 | 1541 | `importModule` finds a module's file, trying the target's names first, |
| 1540 | -and compiles it if it isn't yet. `checkOneModule` first makes sure no | |
| 1542 | +and compiles it if it isn't yet. A module found in an `-I` or | |
| 1543 | +`RAZ_PATH` directory that holds a file `RAZ-VERSION` gets a line | |
| 1544 | +(`libraryNote`, `majorMinor`) saying the raz its library was written | |
| 1545 | +for and this one's, "0.21" for `0.21.0-5-g38d29a8`; the compiler only | |
| 1546 | +reads the file. `checkOneModule` first makes sure no | |
| 1541 | 1547 | later directory has the module too, unless the file is a link to one |
| 1542 | 1548 | of its files there; `checkSiblings` then reads the files for other |
| 1543 | 1549 | targets beside it, declarations only, and `compareIface` holds them |
| @@ -89,6 +89,15 @@ | ||
| 89 | 89 | .Ar dir |
| 90 | 90 | too, after the main module's own directory and before the library. |
| 91 | 91 | It may be given up to 16 times. |
| 92 | +An error in a module found in such a directory, or in one of | |
| 93 | +.Ev RAZ_PATH , | |
| 94 | +names that directory in its path; and if the directory holds a file | |
| 95 | +.Pa RAZ-VERSION , | |
| 96 | +of one line such as | |
| 97 | +.Ql 0.21 , | |
| 98 | +a second line says the raz the library was written for and this one: | |
| 99 | +.Ql (a library written for raz 0.18; this is raz 0.21) . | |
| 100 | +The compiler only reads the file; it never refuses to build for it. | |
| 92 | 101 | .It Fl Werror |
| 93 | 102 | A warning counts as an error. |
| 94 | 103 | .It Fl S |
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | path: []U8; |
| 27 | 27 | buf: ^U8; |
| 28 | 28 | len: INT; |
| 29 | + origin: []U8; (* a line told once, under the first message about the file; "" for none *) | |
| 29 | 30 | end; |
| 30 | 31 | |
| 31 | 32 | const |
| @@ -106,11 +107,18 @@ | ||
| 106 | 107 | end; |
| 107 | 108 | p, ok := Str.copy(Heap.heap, shownPath(path)); |
| 108 | 109 | if not ok then fatal("out of memory"); end; |
| 109 | - files[numFiles] := {path: p, buf: buf, len: len}; | |
| 110 | + files[numFiles] := {path: p, buf: buf, len: len, origin: ""}; | |
| 110 | 111 | INC(numFiles); |
| 111 | 112 | return numFiles - 1; |
| 112 | 113 | end; |
| 113 | 114 | |
| 115 | +(* Gives file f a line to tell once, under the first message about it: | |
| 116 | + where a library came from and the raz it was written for *) | |
| 117 | +proc setOrigin*(f: INT; text: []U8); | |
| 118 | +begin | |
| 119 | + files[f].origin := text; | |
| 120 | +end; | |
| 121 | + | |
| 114 | 122 | proc pathOf*(f: INT): []U8; |
| 115 | 123 | begin |
| 116 | 124 | return files[f].path; |
| @@ -251,6 +259,10 @@ | ||
| 251 | 259 | put(" "); |
| 252 | 260 | paint(Bold, msg); |
| 253 | 261 | putc('\n'); |
| 262 | + if LEN(f^.origin) > 0 then | |
| 263 | + put(" ("); put(f^.origin); put(")\n"); | |
| 264 | + f^.origin := ""; | |
| 265 | + end; | |
| 254 | 266 | stop := start; |
| 255 | 267 | while (stop < f^.len) and (buf[stop] # 10) do INC(stop); end; |
| 256 | 268 | lo := start; |
| @@ -76,6 +76,8 @@ | ||
| 76 | 76 | incDirs*: [16][]U8; |
| 77 | 77 | numInc*: INT; |
| 78 | 78 | userDirs: [][]U8; (* RAZ_PATH, or HOME/.raz/lib; set by the driver *) |
| 79 | + thisVersion: []U8; (* the compiler's version; set by the driver *) | |
| 80 | + originNote: []U8; (* for the module about to be opened, see libraryNote *) | |
| 79 | 81 | firstModule*, lastModule*: PModule; (* in the order they were finished *) |
| 80 | 82 | |
| 81 | 83 | checkMode: BOOL; (* reading a file only for its interface *) |
| @@ -148,6 +150,12 @@ | ||
| 148 | 150 | userDirs := dirs; |
| 149 | 151 | end; |
| 150 | 152 | |
| 153 | +(* The driver's version of the compiler, which a library's note names *) | |
| 154 | +proc setVersion*(v: []U8); | |
| 155 | +begin | |
| 156 | + thisVersion := v; | |
| 157 | +end; | |
| 158 | + | |
| 151 | 159 | proc nameOf(n: INT): []U8; |
| 152 | 160 | begin |
| 153 | 161 | return Scan.nameOf(n); |
| @@ -3861,6 +3869,8 @@ | ||
| 3861 | 3869 | Chunk.setCurFile(internName(path)); |
| 3862 | 3870 | why := Scan.open(path); |
| 3863 | 3871 | if LEN(why) # 0 then Diag.fatal(say2("can't read {}: {}", path, why)); end; |
| 3872 | + Diag.setOrigin(Scan.tokPos().f, originNote); | |
| 3873 | + originNote := ""; | |
| 3864 | 3874 | NEW(m, Heap.heap); |
| 3865 | 3875 | m^.name := n; |
| 3866 | 3876 | m^.sname := n; |
| @@ -4069,6 +4079,39 @@ | ||
| 4069 | 4079 | return nil; |
| 4070 | 4080 | end; |
| 4071 | 4081 | |
| 4082 | +(* The compiler's version as a library's RAZ-VERSION would say it: | |
| 4083 | + "0.21" for "0.21.0-5-g38d29a8"; a name with fewer dots stays whole *) | |
| 4084 | +proc majorMinor(v: []U8): []U8; | |
| 4085 | +var i, dots: INT; | |
| 4086 | +begin | |
| 4087 | + dots := 0; | |
| 4088 | + for i := 0 to LEN(v) - 1 do | |
| 4089 | + if v[i] = '.' then | |
| 4090 | + INC(dots); | |
| 4091 | + if dots = 2 then return v[0..i]; end; | |
| 4092 | + end; | |
| 4093 | + end; | |
| 4094 | + return v; | |
| 4095 | +end; | |
| 4096 | + | |
| 4097 | +(* The line told with the first error in a module found in dir, an -I or | |
| 4098 | + RAZ_PATH directory: if dir holds a file RAZ-VERSION, the raz its | |
| 4099 | + library was written for. The file is only read; a library with none, | |
| 4100 | + or a module of the program's own directory or of lib, has no line. *) | |
| 4101 | +proc libraryNote(dir: []U8): []U8; | |
| 4102 | +var fd, n, i: INT; b: [32]U8; | |
| 4103 | +begin | |
| 4104 | + if (dir = mainDir) or (dir = libDir) then return ""; end; | |
| 4105 | + fd := Sys.openRead(say1("{}/RAZ-VERSION", dir)); | |
| 4106 | + if fd < 0 then return ""; end; | |
| 4107 | + n := Sys.read(fd, b[0..32]); | |
| 4108 | + Sys.close(fd); | |
| 4109 | + i := 0; | |
| 4110 | + while (i < n) and (b[i] # 10) and (b[i] # 32) do INC(i); end; | |
| 4111 | + if i = 0 then return ""; end; | |
| 4112 | + return say2("a library written for raz {}; this is raz {}", b[0..i], majorMinor(thisVersion)); | |
| 4113 | +end; | |
| 4114 | + | |
| 4072 | 4115 | (* The directories searched for modules: main, -I, user libraries, lib *) |
| 4073 | 4116 | proc searchDir(i: INT): []U8; |
| 4074 | 4117 | begin |
| @@ -4150,6 +4193,7 @@ | ||
| 4150 | 4193 | return nil, Scan.Failed; |
| 4151 | 4194 | end; |
| 4152 | 4195 | try checkOneModule(name, dir, f, args.at); |
| 4196 | + originNote := libraryNote(dir); | |
| 4153 | 4197 | m := try compileFile(say2("{}/{}", dir, f), name, args, false); |
| 4154 | 4198 | try checkSiblings(dir, f, name, m, args); |
| 4155 | 4199 | return m, nil; |
| @@ -320,6 +320,7 @@ | ||
| 320 | 320 | if errno # 0 then dir := Files.arg(0); end; |
| 321 | 321 | i := LEN(dir); |
| 322 | 322 | while (i > 0) and (dir[i - 1] # '/') do DEC(i); end; |
| 323 | + Parse.setVersion(Version.Text); | |
| 323 | 324 | if i = 0 then Parse.setLibDir("lib"); else Parse.setLibDir(say1("{}lib", dir[0..i])); end; |
| 324 | 325 | userLibraries(); |
| 325 | 326 | if LEN(outPath) = 0 then |
| @@ -12,7 +12,8 @@ | ||
| 12 | 12 | # each address in it, 0x and hex digits, written 0x? |
| 13 | 13 | # A program without X.expect is compiled, not run. test/libc puts |
| 14 | 14 | # lib/Sys.raz, over the C library, before the system call one. |
| 15 | -# Programs in test/err must not compile, and must print X.err; there | |
| 15 | +# Programs in test/err must not compile, and must print X.err (with | |
| 16 | +# the compiler's own version in a library's note written as N); there | |
| 16 | 17 | # X.args holds the compiler's options. The examples, test/libc, the |
| 17 | 18 | # tools and the library's tests are compiled with -Werror, so warnings |
| 18 | 19 | # fail them. Then the version, tools/Doc.raz, the report's examples, |
| @@ -99,7 +100,7 @@ | ||
| 99 | 100 | if $raz $flags -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then |
| 100 | 101 | echo "FAIL $f: compiles" |
| 101 | 102 | fail=$((fail + 1)) |
| 102 | - elif ! cmp -s test/err/$name.err $out/$name.cerr; then | |
| 103 | + elif ! sed 's/ this is raz [^)]*)/ this is raz N)/' $out/$name.cerr | cmp -s test/err/$name.err -; then | |
| 103 | 104 | echo "FAIL $f: says"; diff test/err/$name.err $out/$name.cerr |
| 104 | 105 | fail=$((fail + 1)) |
| 105 | 106 | else |
| @@ -0,0 +1 @@ | ||
| 1 | +-I test/err/mods/oldlib |
| @@ -0,0 +1,5 @@ | ||
| 1 | +test/err/mods/oldlib/OldLib.raz:2:17: error: an integer constant and a string are different types | |
| 2 | + (a library written for raz 0.18; this is raz N) | |
| 3 | + 2 | const Answer* = 1 + "a"; | |
| 4 | + | ^^^^^^^ | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,3 @@ | ||
| 1 | +module Stale; | |
| 2 | +import OldLib; | |
| 3 | +end Stale. |
| @@ -0,0 +1,3 @@ | ||
| 1 | +module OldLib; | |
| 2 | +const Answer* = 1 + "a"; | |
| 3 | +end OldLib. |
| @@ -0,0 +1 @@ | ||
| 1 | +0.18 |