raz / commit dafe42af

commit
dafe42af25856ce48e771937a8cce8d35b807a07
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
0470e7b4
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.

patch · log

6 files changed, +24 -15

doc/compiler.md (history) modified +5 -3

@@ -18,12 +18,12 @@
1818 |---|---|---|---|
1919 | `src/Diag.raz` | 479 | 363 | Messages: positions, source excerpts, colour, counts |
2020 | `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 |
2222 | `src/Chunk.raz` | 364 | 280 | The compiled program: chunks, fixups, line notes |
2323 | `src/X64.raz` | 1,777 | 1,450 | The instruction encoder, jumps within a procedure, the assembler |
2424 | `src/Gen.raz` | 2,846 | 1,989 | The stack machine, for x86-64: values, operations, checks, calls, frames |
2525 | `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 |
2727 | `src/Link.raz` | 411 | 317 | Tree shaking, layout, patching, the places |
2828 | `src/Elf.raz` | 450 | 356 | Static and dynamic ELF, symbol table, line numbers |
2929 | `src/Host.raz` | 103 | 52 | The system running the compiler |
@@ -2374,7 +2374,9 @@
23742374 `Scan.word` up there and writes its declaration's place
23752375 (`Diag.writePlace`, which `-q check`'s rows use too) and what it is
23762376 (`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
23782380 is dropped, so that it gives no names. Since `cursor` is part of the
23792381 scanner's state, a recovery or a read ahead that puts the state back
23802382 puts the cursor back too, and it is met again.

doc/raz.1 (history) modified +3 -2

@@ -335,8 +335,9 @@
335335 are as
336336 .Cm words
337337 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
340341 .Cm INT
341342 or
342343 .Cm LEN ,

src/Parse.raz (history) modified +9 -5

@@ -569,8 +569,8 @@
569569 of scope s is written, or of any scope open if s < 0. words writes
570570 the names that start with what is typed there; def where the name
571571 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. *)
574574 proc answer(s: INT);
575575 var b: Buf.Buf; o: PObj;
576576 begin
@@ -581,7 +581,7 @@
581581 if s < 0 then o := Sym.lookup(internName(Scan.word)); else o := Sym.find(s, internName(Scan.word)); end;
582582 if (o # nil) and (o^.typ # Sym.tPoison) then
583583 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);
585585 elsif (o^.scope = 0) or (o^.cls = Sym.oBuiltin) then
586586 Diag.writePlace(b, {f: MAX(INT), a: 0, b: 0});
587587 else
@@ -4428,7 +4428,7 @@
44284428 st: Scan.State; saved: [Sym.MaxDepth]INT; d: INT;
44294429 oldMod: PModule; oldCheck, oldChecks: BOOL; m: PModule;
44304430 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;
44324432 begin
44334433 firstDoubt := numDoubts;
44344434 Scan.saveScan(st);
@@ -4463,6 +4463,7 @@
44634463 if (Scan.tok # Scan.sIdent) or (Scan.id # n) then
44644464 return nil, Scan.mark(say2("expected module {}, found {}", nameOf(n), Scan.found()));
44654465 end;
4466+ m^.at := Scan.tokPos();
44664467 Scan.next;
44674468 (* the module first pending is the one named on the command line,
44684469 which nothing imports, so no arguments come with it *)
@@ -4480,7 +4481,9 @@
44804481 if Scan.tok # Scan.sIdent then return nil, expected("a module name"); end;
44814482 start := Scan.tokPos();
44824483 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;
44844487 iargs.n := 0;
44854488 generic := false;
44864489 Scan.next;
@@ -4511,6 +4514,7 @@
45114514 elsif not generic then
45124515 o^.home := try importModule(mname, iargs);
45134516 addImport(m, o^.home);
4517+ if atName then answer(m^.scope); end;
45144518 else
45154519 o^.home := nil; (* until the instance is made, at its first use *)
45164520 if numDeferred >= MaxDeferred then

src/Sym.raz (history) modified +1 -0

@@ -128,6 +128,7 @@
128128 args*: Args;
129129 scope*: INT;
130130 path*: []const U8;
131+ at*: Diag.Pos; (* its name in its "module" line, for raz -q def *)
131132 first*, last*: ^Obj; (* its top-level declarations, in order *)
132133 locals*, lastLocal*: ^Obj; (* its procedures' declarations, in order *)
133134 imports*: ^Import;

test/check.sh (history) modified +5 -4

@@ -171,12 +171,13 @@
171171 # raz -q, for an editor: check's rows; the names words offers at a
172172 # cursor after a part of a name, after a module's dot, and none in a
173173 # 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.
177177 for t in "check Check.raz check" "words Words.raz:9:16 prefix" "words Words.raz:10:11 export" \
178178 "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
180181 set -- $t
181182 f=test/query/${2%%:*}
182183 $raz -q $1 test/query/$2 < $f > $out/query.out

test/query/def-module.expect (history) modified +1 -1

@@ -1 +1 @@
1-lib/Out.raz 1 1 1 1 module Out
1+lib/Out.raz 9 8 9 11 module Out