raz -q def: a module is its name in its module line, and an import's name answers too So that hover on a module shows its "module X;" line and the comment above it, its opening comment, and go to definition lands there. Sym.Module.at holds the place; compileFile answers at an import.
| @@ -18,12 +18,12 @@ | ||
| 18 | 18 | |---|---|---|---| |
| 19 | 19 | | `src/Diag.raz` | 479 | 363 | Messages: positions, source excerpts, colour, counts | |
| 20 | 20 | | `src/Scan.raz` | 1,267 | 1,040 | Symbols, literals, comments, positions | |
| 21 | -| `src/Sym.raz` | 865 | 688 | Types, objects, scopes, layout | | |
| 21 | +| `src/Sym.raz` | 866 | 689 | Types, objects, scopes, layout | | |
| 22 | 22 | | `src/Chunk.raz` | 364 | 280 | The compiled program: chunks, fixups, line notes | |
| 23 | 23 | | `src/X64.raz` | 1,777 | 1,450 | The instruction encoder, jumps within a procedure, the assembler | |
| 24 | 24 | | `src/Gen.raz` | 2,846 | 1,989 | The stack machine, for x86-64: values, operations, checks, calls, frames | |
| 25 | 25 | | `src/Item.raz` | 2,553 | 2,051 | Items: types, constants, variables, operators, conversions, calls | |
| 26 | -| `src/Parse.raz` | 4,918 | 4,175 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 26 | +| `src/Parse.raz` | 4,922 | 4,179 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 27 | 27 | | `src/Link.raz` | 411 | 317 | Tree shaking, layout, patching, the places | |
| 28 | 28 | | `src/Elf.raz` | 450 | 356 | Static and dynamic ELF, symbol table, line numbers | |
| 29 | 29 | | `src/Host.raz` | 103 | 52 | The system running the compiler | |
| @@ -2374,7 +2374,9 @@ | ||
| 2374 | 2374 | `Scan.word` up there and writes its declaration's place |
| 2375 | 2375 | (`Diag.writePlace`, which `-q check`'s rows use too) and what it is |
| 2376 | 2376 | (`Sym.describe`, which `offer`'s rows use): a module's place is its |
| 2377 | - file, and a name of the universe or a built-in has none. A cursor inside a comment or a string | |
| 2377 | + name in its `module` line (`Module.at`), and an import's name, read | |
| 2378 | + in `compileFile`, answers so too; a name of the universe or a | |
| 2379 | + built-in has none. A cursor inside a comment or a string | |
| 2378 | 2380 | is dropped, so that it gives no names. Since `cursor` is part of the |
| 2379 | 2381 | scanner's state, a recovery or a read ahead that puts the state back |
| 2380 | 2382 | puts the cursor back too, and it is met again. |
| @@ -335,8 +335,9 @@ | ||
| 335 | 335 | are as |
| 336 | 336 | .Cm words |
| 337 | 337 | gives them. |
| 338 | -A module's place is the start of its file; a name of the language's | |
| 339 | -own, as | |
| 338 | +A module's place is its name in its own | |
| 339 | +.Li module | |
| 340 | +line, on an import's name too; a name of the language's own, as | |
| 340 | 341 | .Cm INT |
| 341 | 342 | or |
| 342 | 343 | .Cm LEN , |
| @@ -569,8 +569,8 @@ | ||
| 569 | 569 | of scope s is written, or of any scope open if s < 0. words writes |
| 570 | 570 | the names that start with what is typed there; def where the name |
| 571 | 571 | written there is declared, its place and what it is: a module's |
| 572 | - place is its file, and the language's own names have none. Then the | |
| 573 | - compile ends. *) | |
| 572 | + place is its name in its own file, and the language's own names | |
| 573 | + have none. Then the compile ends. *) | |
| 574 | 574 | proc answer(s: INT); |
| 575 | 575 | var b: Buf.Buf; o: PObj; |
| 576 | 576 | begin |
| @@ -581,7 +581,7 @@ | ||
| 581 | 581 | if s < 0 then o := Sym.lookup(internName(Scan.word)); else o := Sym.find(s, internName(Scan.word)); end; |
| 582 | 582 | if (o # nil) and (o^.typ # Sym.tPoison) then |
| 583 | 583 | if (o^.cls = Sym.oModule) and (o^.home # nil) and (o^.home^.path # "") then |
| 584 | - Fmt.write(b, "{}\t1\t1\t1\t1", [Fmt.str(Diag.shownPath(o^.home^.path))]); | |
| 584 | + Diag.writePlace(b, o^.home^.at); | |
| 585 | 585 | elsif (o^.scope = 0) or (o^.cls = Sym.oBuiltin) then |
| 586 | 586 | Diag.writePlace(b, {f: MAX(INT), a: 0, b: 0}); |
| 587 | 587 | else |
| @@ -4428,7 +4428,7 @@ | ||
| 4428 | 4428 | st: Scan.State; saved: [Sym.MaxDepth]INT; d: INT; |
| 4429 | 4429 | oldMod: PModule; oldCheck, oldChecks: BOOL; m: PModule; |
| 4430 | 4430 | lib: ^Sym.Lib; start: Diag.Pos; alias, mname, line, oldPath: INT; o: PObj; bodyChunk: INT; iargs: Sym.Args; |
| 4431 | - generic: BOOL; argsAt: Scan.State; why: []const U8; firstDoubt: INT; | |
| 4431 | + generic, atName: BOOL; argsAt: Scan.State; why: []const U8; firstDoubt: INT; | |
| 4432 | 4432 | begin |
| 4433 | 4433 | firstDoubt := numDoubts; |
| 4434 | 4434 | Scan.saveScan(st); |
| @@ -4463,6 +4463,7 @@ | ||
| 4463 | 4463 | if (Scan.tok # Scan.sIdent) or (Scan.id # n) then |
| 4464 | 4464 | return nil, Scan.mark(say2("expected module {}, found {}", nameOf(n), Scan.found())); |
| 4465 | 4465 | end; |
| 4466 | + m^.at := Scan.tokPos(); | |
| 4466 | 4467 | Scan.next; |
| 4467 | 4468 | (* the module first pending is the one named on the command line, |
| 4468 | 4469 | which nothing imports, so no arguments come with it *) |
| @@ -4480,7 +4481,9 @@ | ||
| 4480 | 4481 | if Scan.tok # Scan.sIdent then return nil, expected("a module name"); end; |
| 4481 | 4482 | start := Scan.tokPos(); |
| 4482 | 4483 | alias := Scan.id; |
| 4483 | - mname := Scan.id; | |
| 4484 | + atName := define and (alias = Scan.atCursor); (* raz -q def on a module's name here *) | |
| 4485 | + if atName then alias := internName(Scan.word); end; | |
| 4486 | + mname := alias; | |
| 4484 | 4487 | iargs.n := 0; |
| 4485 | 4488 | generic := false; |
| 4486 | 4489 | Scan.next; |
| @@ -4511,6 +4514,7 @@ | ||
| 4511 | 4514 | elsif not generic then |
| 4512 | 4515 | o^.home := try importModule(mname, iargs); |
| 4513 | 4516 | addImport(m, o^.home); |
| 4517 | + if atName then answer(m^.scope); end; | |
| 4514 | 4518 | else |
| 4515 | 4519 | o^.home := nil; (* until the instance is made, at its first use *) |
| 4516 | 4520 | if numDeferred >= MaxDeferred then |
| @@ -128,6 +128,7 @@ | ||
| 128 | 128 | args*: Args; |
| 129 | 129 | scope*: INT; |
| 130 | 130 | path*: []const U8; |
| 131 | + at*: Diag.Pos; (* its name in its "module" line, for raz -q def *) | |
| 131 | 132 | first*, last*: ^Obj; (* its top-level declarations, in order *) |
| 132 | 133 | locals*, lastLocal*: ^Obj; (* its procedures' declarations, in order *) |
| 133 | 134 | imports*: ^Import; |
| @@ -171,12 +171,13 @@ | ||
| 171 | 171 | # raz -q, for an editor: check's rows; the names words offers at a |
| 172 | 172 | # cursor after a part of a name, after a module's dot, and none in a |
| 173 | 173 | # comment or a string; and where def finds a local, another module's |
| 174 | -# name, a module and a built-in, which has no place. The text is | |
| 175 | -# standard input: checking an empty one shows that the file on disk | |
| 176 | -# isn't read. | |
| 174 | +# name, a module, used and imported, and a built-in, which has no | |
| 175 | +# place. The text is standard input: checking an empty one shows | |
| 176 | +# that the file on disk isn't read. | |
| 177 | 177 | for t in "check Check.raz check" "words Words.raz:9:16 prefix" "words Words.raz:10:11 export" \ |
| 178 | 178 | "words Words.raz:11:10 none" "words Words.raz:12:15 none" "def Def.raz:10:15 def-local" \ |
| 179 | - "def Def.raz:11:9 def-export" "def Def.raz:11:6 def-module" "def Def.raz:10:24 def-builtin"; do | |
| 179 | + "def Def.raz:11:9 def-export" "def Def.raz:11:6 def-module" "def Def.raz:2:9 def-module" \ | |
| 180 | + "def Def.raz:10:24 def-builtin"; do | |
| 180 | 181 | set -- $t |
| 181 | 182 | f=test/query/${2%%:*} |
| 182 | 183 | $raz -q $1 test/query/$2 < $f > $out/query.out |
| @@ -1 +1 @@ | ||
| 1 | -lib/Out.raz 1 1 1 1 module Out | |
| 1 | +lib/Out.raz 9 8 9 11 module Out |