raz / commit 22cd3a48

commit
22cd3a48802e278f7e09f1577a937c63d47cddeb
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
cb2bb189
Errors point at the offending construct

Items carry their source span; errors about an item or two operands
underline it, a missing symbol goes after the one before when the
next starts a new line, scanner errors underline the bad characters.
An import's arguments keep positions: generic errors point at the
importer, with a note at the parameter. Paths are shown from the
working directory. 40 new tests in test/err/At*.

patch · log

105 files changed, +787 -231

PLAN.md (history) modified +1 -1

@@ -220,7 +220,7 @@
220220 `X.err` becomes the whole message, without colour, and the
221221 Makefile compares all of it. *main*; regenerating and checking
222222 the 57 `.err` files, *agent*.
223-- [ ] 21. Exact positions. An item and a statement remember where
223+- [x] 21. Exact positions. An item and a statement remember where
224224 they start, so an error points at the whole offending
225225 expression, not the symbol after it; a missing `;`, `then` or
226226 `end` points just after the symbol before it. The scanner keeps

doc/compiler.md (history) modified +16 -7

@@ -8,12 +8,12 @@
88
99 | File | Lines | Code | What |
1010 |---|---|---|---|
11-| `src/diag.pas` | 227 | 162 | Messages: positions, source excerpts, colour, counts |
12-| `src/scan.pas` | 535 | 459 | Symbols, literals, comments, positions |
13-| `src/sym.pas` | 508 | 422 | Types, objects, scopes, layout |
11+| `src/diag.pas` | 243 | 174 | Messages: positions, source excerpts, colour, counts |
12+| `src/scan.pas` | 584 | 495 | Symbols, literals, comments, positions |
13+| `src/sym.pas` | 510 | 424 | Types, objects, scopes, layout |
1414 | `src/x64.pas` | 680 | 546 | Code buffer, chunks, fixups, line notes, instruction encoder |
15-| `src/gen.pas` | 1,414 | 1,240 | Items: loading, storing, copying, frames, calls |
16-| `src/parse.pas` | 1,816 | 1,685 | Declarations, statements, expressions, built-ins |
15+| `src/gen.pas` | 1,421 | 1,247 | Items: loading, storing, copying, frames, calls |
16+| `src/parse.pas` | 1,851 | 1,720 | Declarations, statements, expressions, built-ins |
1717 | `src/link.pas` | 131 | 95 | Tree shaking, layout, patching |
1818 | `src/elf.pas` | 425 | 351 | Static and dynamic ELF, symbol table, line numbers |
1919 | `src/raz.pas` | 219 | 172 | The command line, the entry points |
@@ -145,8 +145,12 @@
145145 Source is UTF-8, checked by `Utf8` wherever a byte above 127 appears:
146146 in strings, characters and comments. Anywhere else it is an error.
147147
148-`TokPos` is the position of the current symbol. Errors go through
149-`Mark`, which reports one there (`diag.Error`) and stops. There is no
148+`TokPos` is the position of the current symbol, `SpanFrom` the stretch
149+from a saved position to the end of the symbol before the current one,
150+and `MissingPos` the place to say a symbol is missing: just after the
151+symbol before, when the current one starts a new line. Errors go
152+through `Mark`, at the current symbol, or `MarkAt`, at a position; each
153+reports the error (`diag.Error`) and stops. There is no
150154 recovery: the first error ends the compilation. `SaveScan` and `RestoreScan` keep
151155 the scanner's state while an imported module is compiled.
152156
@@ -224,6 +228,11 @@
224228 (`bSlot`); plus `off`;
225229 - `mReg`: a value in `rax`; `mStack`: a value pushed on the stack;
226230 - `mProc`, `mType`, `mStr`, and a few more the parser needs.
231+
232+An item also carries `pos`, the stretch of source it came from, which
233+the parser sets as it reads an expression; an error about an item is
234+reported there (`MarkAt(x.pos, ...)`), and one about two operands
235+across both (`Join(x.pos, y.pos)`).
227236
228237 Three routines move items towards the machine. `Value` brings a value
229238 into `rax`, loading it with the one instruction its size needs.

src/diag.pas modified +17 -1

@@ -36,6 +36,7 @@
3636 function AddFile(const path: shortstring; buf: PChar; len: longint): longint;
3737 function PathOf(f: longint): shortstring;
3838 function LineOf(const p: TPos): longint;
39+function Join(const p, q: TPos): TPos;
3940 procedure Error(const p: TPos; const msg: shortstring);
4041 procedure Warning(const p: TPos; const msg: shortstring);
4142 procedure Note(const p: TPos; const msg: shortstring);
@@ -58,14 +59,22 @@
5859 files: ^TFile; { numFiles of them, in room for cap }
5960 numFiles, cap: longint;
6061 colour, colourKnown: boolean;
62+ cwd: shortstring; { the working directory and a /, or '' if unknown }
6163
64+{ Paths are shown from the working directory where they are under it,
65+ so messages read the same wherever the compiler or its library is. }
6266 function AddFile(const path: shortstring; buf: PChar; len: longint): longint;
67+var d: array[0..255] of char;
6368 begin
69+ if numFiles = 0 then
70+ if FpGetcwd(@d[0], SizeOf(d)) <> nil then cwd := StrPas(@d[0]) + '/';
6471 if numFiles = cap then begin
6572 cap := 2 * cap + 8;
6673 ReallocMem(files, cap * SizeOf(TFile));
6774 end;
68- files[numFiles].path := path;
75+ if (cwd <> '') and (copy(path, 1, length(cwd)) = cwd) then
76+ files[numFiles].path := copy(path, length(cwd) + 1, 255)
77+ else files[numFiles].path := path;
6978 files[numFiles].buf := buf;
7079 files[numFiles].len := len;
7180 AddFile := numFiles;
@@ -167,6 +176,13 @@
167176 if p.b < stop then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, stop);
168177 if n < 1 then n := 1;
169178 writeln(StdErr, Paint(kindColour, StringOfChar('^', n)));
179+end;
180+
181+{ From the start of p to the end of q }
182+function Join(const p, q: TPos): TPos;
183+begin
184+ Join := p;
185+ Join.b := q.b;
170186 end;
171187
172188 { Messages }

src/gen.pas modified +74 -67

@@ -44,6 +44,7 @@
4444 vol: boolean; { mVar: reached through ^VOLATILE }
4545 isVar: boolean; { mVar: a variable of the program, not a temporary }
4646 obj: PObj; { mProc, mBuiltin, mCase }
47+ pos: TPos; { where it is in the source, for messages }
4748 end;
4849
4950 TCall = record
@@ -147,8 +148,11 @@
147148 { Items }
148149
149150 procedure MakeConst(var x: TItem; t: PType; v: int64);
151+var p: TPos;
150152 begin
153+ p := x.pos;
151154 FillChar(x, SizeOf(x), 0);
155+ x.pos := p;
152156 x.mode := mConst;
153157 x.typ := t;
154158 x.val := v;
@@ -306,7 +310,7 @@
306310 case x.mode of
307311 mConst: ConstTo(RAX, x);
308312 mVar: begin
309- if not IsScalar(x.typ) then Mark('not a single value');
313+ if not IsScalar(x.typ) then MarkAt(x.pos, 'not a single value');
310314 m := MemOf(x, RAX);
311315 Load(RAX, m, ScalarSize(x.typ), (x.typ^.form = fInt) and x.typ^.signed);
312316 end;
@@ -314,11 +318,11 @@
314318 mStack: PopR(RAX);
315319 mProc: begin
316320 if x.obj^.isCode and (x.obj^.typ^.base <> nil) and x.obj^.typ^.base^.tuple then
317- Mark('a code procedure with two results can only be called');
321+ MarkAt(x.pos, 'a code procedure with two results can only be called');
318322 if x.obj^.ext then Load(RAX, MemRip(x.obj^.chunk, 0), 8, false)
319323 else Lea(RAX, MemRip(x.obj^.chunk, 0));
320324 end;
321- else Mark('not a value');
325+ else MarkAt(x.pos, 'not a value');
322326 end;
323327 x.mode := mReg;
324328 end;
@@ -331,7 +335,7 @@
331335 m := MemOf(x, r);
332336 if (x.base <> bReg) or (x.reg <> r) or (x.off <> 0) then Lea(r, m);
333337 x.base := bReg; x.reg := r; x.off := 0;
334- end else Mark('not a variable');
338+ end else MarkAt(x.pos, 'not a variable');
335339 end;
336340
337341 procedure Save(var x: TItem);
@@ -380,8 +384,11 @@
380384 end;
381385
382386 procedure TempItem(var x: TItem; t: PType; off: int64);
387+var p: TPos;
383388 begin
389+ p := x.pos;
384390 FillChar(x, SizeOf(x), 0);
391+ x.pos := p;
385392 x.mode := mVar; x.typ := t; x.base := bFrame; x.off := off;
386393 end;
387394
@@ -405,7 +412,7 @@
405412 procedure CopyToTemp(var x: TItem);
406413 var t: int64;
407414 begin
408- if x.vol then Mark('can''t copy through a volatile pointer');
415+ if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer');
409416 t := AllocTemp(x.typ^.size, x.typ^.align);
410417 Address(x, RSI);
411418 Lea(RDI, Mem(RBP, t));
@@ -442,14 +449,14 @@
442449 MovRI(RAX, 0);
443450 RepStosb;
444451 TempItem(x, t, tmp);
445- end else Mark('can''t use a string as ' + TypeName(t));
452+ end else MarkAt(x.pos, 'can''t use a string as ' + TypeName(t));
446453 exit;
447454 end;
448- if x.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value');
455+ if x.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(x.pos, 'not a value');
449456 if Same(s, t) then exit;
450457 if (s = tRConst) and (t^.form = fReal) then RealTo(x, t)
451458 else if (s^.form = fConst) and (t^.form = fInt) then begin
452- if (x.mode = mConst) and not Fits(x.val, t) then Mark('constant doesn''t fit ' + TypeName(t));
459+ if (x.mode = mConst) and not Fits(x.val, t) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(t));
453460 x.typ := t;
454461 end else if (s^.form = fNil) and (t^.form in [fPtr, fProc, fError]) then
455462 x.typ := t
@@ -457,11 +464,11 @@
457464 and Same(s^.base, t^.base) then
458465 x.typ := t
459466 else if (s^.form = fArray) and (t^.form = fSlice) and Same(s^.base, t^.base) then begin
460- if x.vol then Mark('can''t make a slice through a volatile pointer');
467+ if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer');
461468 Address(x, RAX);
462469 SliceOf(x, t, s^.len);
463470 end else
464- Mark('can''t use ' + TypeName(s) + ' as ' + TypeName(t));
471+ MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t));
465472 end;
466473
467474 procedure Assign(var dst, src: TItem);
@@ -473,7 +480,7 @@
473480 m := MemOf(dst, RCX);
474481 Store(m, RAX, ScalarSize(dst.typ));
475482 end else begin
476- if dst.vol or src.vol then Mark('can''t copy through a volatile pointer');
483+ if dst.vol or src.vol then MarkAt(src.pos, 'can''t copy through a volatile pointer');
477484 Address(src, RSI);
478485 Address(dst, RDI);
479486 Copy(dst.typ^.size);
@@ -508,8 +515,8 @@
508515 var t: PType;
509516 begin
510517 t := x.typ;
511- if t^.form <> fPtr then Mark('not a pointer');
512- if t^.base = nil then Mark('pointer to an undeclared type');
518+ if t^.form <> fPtr then MarkAt(x.pos, 'not a pointer');
519+ if t^.base = nil then MarkAt(x.pos, 'pointer to an undeclared type');
513520 Value(x);
514521 x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0;
515522 x.typ := t^.base; x.vol := t^.vol; x.isVar := true;
@@ -525,12 +532,12 @@
525532 begin
526533 if x.mode = mStr then Coerce(x, tBytes);
527534 if (x.typ^.form = fPtr) and (x.typ^.base^.form = fArray) then
528- Mark('a pointer to an array is indexed as p^[i]');
535+ MarkAt(x.pos, 'a pointer to an array is indexed as p^[i]');
529536 if x.typ^.form = fPtr then begin
530537 Value(x); PushRax; x.mode := mStack
531538 end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then
532539 Save(x)
533- else Mark('not an array, slice or pointer');
540+ else MarkAt(x.pos, 'not an array, slice or pointer');
534541 end;
535542
536543 procedure Index(var x, y: TItem);
@@ -538,7 +545,7 @@
538545 begin
539546 t := x.typ;
540547 s := t^.base^.size;
541- if not IsInt(y.typ) then Mark('an index is an integer');
548+ if not IsInt(y.typ) then MarkAt(y.pos, 'an index is an integer');
542549 if t^.form = fPtr then begin
543550 Value(y);
544551 if s <> 1 then ImulI(RAX, s);
@@ -547,7 +554,7 @@
547554 x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0;
548555 x.vol := t^.vol; x.isVar := true;
549556 end else if (t^.form = fArray) and (y.mode = mConst) then begin
550- if (y.val < 0) or (y.val >= t^.len) then Mark('index out of range');
557+ if (y.val < 0) or (y.val >= t^.len) then MarkAt(y.pos, 'index out of range');
551558 x.off := x.off + y.val * s;
552559 if x.base = bStack then begin
553560 PopR(RAX); x.base := bReg; x.reg := RAX
@@ -576,7 +583,7 @@
576583
577584 procedure SliceLo(var lo: TItem);
578585 begin
579- if not IsInt(lo.typ) then Mark('an index is an integer');
586+ if not IsInt(lo.typ) then MarkAt(lo.pos, 'an index is an integer');
580587 Value(lo);
581588 PushRax;
582589 end;
@@ -586,8 +593,8 @@
586593 begin
587594 t := x.typ;
588595 s := t^.base^.size;
589- if not IsInt(hi.typ) then Mark('an index is an integer');
590- if x.vol then Mark('can''t make a slice through a volatile pointer');
596+ if not IsInt(hi.typ) then MarkAt(hi.pos, 'an index is an integer');
597+ if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer');
591598 Value(hi);
592599 MovRR(RDX, RAX);
593600 PopR(RCX);
@@ -630,7 +637,7 @@
630637 end else if IsInt(x.typ) then begin
631638 if x.mode = mConst then x.val := Cut(-x.val, x.typ)
632639 else begin Value(x); Unary(3, RAX); Norm(x.typ) end;
633- end else Mark('can''t negate ' + TypeName(x.typ));
640+ end else MarkAt(x.pos, 'can''t negate ' + TypeName(x.typ));
634641 end;
635642
636643 procedure NotOp(var x: TItem);
@@ -641,7 +648,7 @@
641648 end else if IsInt(x.typ) then begin
642649 if x.mode = mConst then x.val := Cut(not x.val, x.typ)
643650 else begin Value(x); Unary(2, RAX); Norm(x.typ) end;
644- end else Mark('not needs BOOL or an integer');
651+ end else MarkAt(x.pos, 'not needs BOOL or an integer');
645652 end;
646653
647654 function IsStrLike(t: PType): boolean;
@@ -660,7 +667,7 @@
660667 end else begin
661668 if x.mode = mStr then begin Address(x, RAX); SliceOf(x, t, x.val) end
662669 else begin
663- if x.vol then Mark('can''t compare through a volatile pointer');
670+ if x.vol then MarkAt(x.pos, 'can''t compare through a volatile pointer');
664671 Address(x, RAX); SliceOf(x, t, x.typ^.len)
665672 end;
666673 end;
@@ -679,7 +686,7 @@
679686 end else if (op in [sEql, sNeq]) and IsStrLike(x.typ) then
680687 StrSlice(x)
681688 else if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then
682- Mark('not a value')
689+ MarkAt(x.pos, 'not a value')
683690 else if x.mode <> mConst then begin
684691 Value(x); PushRax; x.mode := mStack
685692 end;
@@ -694,7 +701,7 @@
694701 Log2 := n;
695702 end;
696703
697-function FoldInt(op: TSym; a, b: int64; t: PType): int64;
704+function FoldInt(op: TSym; a, b: int64; t: PType; const p: TPos): int64;
698705 var u: boolean;
699706 begin
700707 u := (t^.form = fInt) and not t^.signed;
@@ -703,11 +710,11 @@
703710 sMinus: FoldInt := a - b;
704711 sTimes: FoldInt := a * b;
705712 sDiv, sMod: begin
706- if b = 0 then Mark('division by zero');
713+ if b = 0 then MarkAt(p, 'division by zero');
707714 if u then begin
708715 if op = sDiv then FoldInt := int64(qword(a) div qword(b))
709716 else FoldInt := int64(qword(a) mod qword(b));
710- end else if (b = -1) and (a = low(int64)) then Mark('division overflows')
717+ end else if (b = -1) and (a = low(int64)) then MarkAt(p, 'division overflows')
711718 else if op = sDiv then FoldInt := a div b
712719 else FoldInt := a mod b;
713720 end;
@@ -723,7 +730,7 @@
723730 sLeq: if u then FoldInt := ord(qword(a) <= qword(b)) else FoldInt := ord(a <= b);
724731 sGtr: if u then FoldInt := ord(qword(a) > qword(b)) else FoldInt := ord(a > b);
725732 sGeq: if u then FoldInt := ord(qword(a) >= qword(b)) else FoldInt := ord(a >= b);
726- else Mark('bad operator'); FoldInt := 0;
733+ else MarkAt(p, 'bad operator'); FoldInt := 0;
727734 end;
728735 end;
729736
@@ -759,10 +766,10 @@
759766 xt, yt, t: PType; r: TItem; scale, sh: longint; isPtr, unsign, f: boolean; a, b: int64;
760767 begin
761768 xt := x.typ; yt := y.typ;
762- if y.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value');
769+ if y.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(y.pos, 'not a value');
763770
764771 if (op in [sAnd, sOr]) and (xt^.form = fBool) then begin
765- if yt^.form <> fBool then Mark('and, or need two BOOLs');
772+ if yt^.form <> fBool then MarkAt(y.pos, 'and, or need two BOOLs');
766773 if (x.mode = mConst) and (y.mode = mConst) then begin
767774 FixLink(L);
768775 if op = sAnd then x.val := x.val and y.val else x.val := x.val or y.val;
@@ -775,7 +782,7 @@
775782 end;
776783
777784 if (op in [sEql, sNeq]) and IsStrLike(xt) then begin
778- if not IsStrLike(yt) then Mark('can''t compare a string with ' + TypeName(yt));
785+ if not IsStrLike(yt) then MarkAt(y.pos, 'can''t compare a string with ' + TypeName(yt));
779786 StrSlice(y);
780787 Address(y, RSI);
781788 Address(x, RDI);
@@ -792,58 +799,58 @@
792799 { the type of the result, and the checks }
793800 t := nil; scale := 1; isPtr := false;
794801 if IsInt(xt) and IsInt(yt) then begin
795- if op = sSlash then Mark('/ is for reals; integers use div');
802+ if op = sSlash then MarkAt(Join(x.pos, y.pos), '/ is for reals; integers use div');
796803 if op in [sShl, sShr] then begin
797804 if xt^.form = fConst then t := tConst else t := xt
798805 end else if (xt^.form = fConst) and (yt^.form = fConst) then t := tConst
799806 else if xt^.form = fConst then begin
800- if (x.mode = mConst) and not Fits(x.val, yt) then Mark('constant doesn''t fit ' + TypeName(yt));
807+ if (x.mode = mConst) and not Fits(x.val, yt) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(yt));
801808 t := yt
802809 end else if yt^.form = fConst then begin
803- if (y.mode = mConst) and not Fits(y.val, xt) then Mark('constant doesn''t fit ' + TypeName(xt));
810+ if (y.mode = mConst) and not Fits(y.val, xt) then MarkAt(y.pos, 'constant doesn''t fit ' + TypeName(xt));
804811 t := xt
805812 end else if Same(xt, yt) then t := xt
806- else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt));
813+ else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt));
807814 end else if (xt^.form = fReal) and (yt^.form = fReal) then begin
808- if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then Mark('not a real operator');
815+ if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then MarkAt(Join(x.pos, y.pos), 'not a real operator');
809816 if xt = tRConst then t := yt
810817 else if (yt = tRConst) or Same(xt, yt) then t := xt
811- else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt));
818+ else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt));
812819 if (x.mode = mConst) and (x.typ <> t) then RealTo(x, t);
813820 if (y.mode = mConst) and (y.typ <> t) then RealTo(y, t);
814821 end else if (xt^.form = fBool) and (yt^.form = fBool) then begin
815- if not (op in [sXor, sEql, sNeq]) then Mark('not a BOOL operator');
822+ if not (op in [sXor, sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'not a BOOL operator');
816823 t := tBool;
817824 end else if (xt^.form = fPtr) and IsInt(yt) and (op in [sPlus, sMinus]) then begin
818825 t := xt; scale := xt^.base^.size; isPtr := true;
819826 if y.mode = mConst then y.typ := tI64;
820827 end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin
821- if not Same(xt, yt) then Mark('different pointer types');
828+ if not Same(xt, yt) then MarkAt(Join(x.pos, y.pos), 'different pointer types');
822829 t := tI64; scale := xt^.base^.size; isPtr := true;
823830 end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin
824- if not (op in Rel) then Mark('not a pointer operator');
831+ if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'not a pointer operator');
825832 if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then
826- if not (op in [sEql, sNeq]) then Mark('procedures and errors compare only with = and #');
833+ if not (op in [sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'procedures and errors compare only with = and #');
827834 if (xt^.form <> fNil) and (yt^.form <> fNil) and not Same(xt, yt) then
828835 if not ((xt^.form = fPtr) and (yt^.form = fPtr) and Same(xt^.base, yt^.base)) then
829- Mark('different pointer types');
836+ MarkAt(Join(x.pos, y.pos), 'different pointer types');
830837 t := tU64;
831838 end else if (xt^.form = fEnum) and Same(xt, yt) then begin
832- if not (op in Rel) then Mark('enumerations only compare');
839+ if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'enumerations only compare');
833840 t := xt;
834841 end else if (xt^.form = fSet) and Same(xt, yt) then begin
835- if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then Mark('not a set operator');
842+ if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then MarkAt(Join(x.pos, y.pos), 'not a set operator');
836843 t := xt;
837844 end else if (op = sIn) and (yt^.form = fSet) and Same(xt, yt^.base) then
838845 t := yt
839846 else
840- Mark('can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt));
847+ MarkAt(Join(x.pos, y.pos), 'can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt));
841848 unsign := (t^.form = fInt) and not t^.signed;
842849
843850 { constants }
844851 if (x.mode = mConst) and (y.mode = mConst) and not isPtr then begin
845852 if t^.form = fReal then begin
846- if not FoldReal(op, x, y, t, r) then Mark('not a real operator');
853+ if not FoldReal(op, x, y, t, r) then MarkAt(Join(x.pos, y.pos), 'not a real operator');
847854 x := r;
848855 end else if t^.form = fSet then begin
849856 a := x.val; b := y.val;
@@ -857,9 +864,9 @@
857864 else MakeConst(x, tBool, ord((a = b) = (op = sEql)));
858865 end;
859866 end else if op in Rel then
860- MakeConst(x, tBool, FoldInt(op, x.val, y.val, t))
867+ MakeConst(x, tBool, FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos)))
861868 else
862- MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t), t));
869+ MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos)), t));
863870 exit;
864871 end;
865872
@@ -935,7 +942,7 @@
935942 sXor: Alu(aluXor, RAX, RCX);
936943 sShl: Shift(shShl, RAX);
937944 sShr: if unsign then Shift(shShr, RAX) else Shift(shSar, RAX);
938- else Mark('not an operator for ' + TypeName(t));
945+ else MarkAt(Join(x.pos, y.pos), 'not an operator for ' + TypeName(t));
939946 end;
940947 Norm(t);
941948 end;
@@ -947,14 +954,14 @@
947954 var s: PType; r: double; L1, L2: longint; f: boolean;
948955 begin
949956 s := x.typ;
950- if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then Mark('can''t convert this');
957+ if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then MarkAt(x.pos, 'can''t convert this');
951958 if Same(s, t) then exit;
952959 if (IsInt(s) or (s^.form in [fEnum, fSet])) and (t^.form = fInt) then begin
953960 if x.mode = mConst then x.val := Cut(x.val, t)
954961 else begin Value(x); Norm(t) end;
955962 end else if IsInt(s) and (t^.form = fEnum) then begin
956963 if x.mode = mConst then begin
957- if (x.val < 0) or (x.val >= t^.len) then Mark('not a position of ' + TypeName(t))
964+ if (x.val < 0) or (x.val >= t^.len) then MarkAt(x.pos, 'not a position of ' + TypeName(t))
958965 end else begin Value(x); CmpI(RAX, t^.len); Check(ccB) end;
959966 end else if IsInt(s) and (t^.form = fSet) then begin
960967 if x.mode = mConst then begin
@@ -1009,7 +1016,7 @@
10091016 end else if (s^.form in [fPtr, fProc]) and (t^.form = fInt) then begin
10101017 Value(x); Norm(t)
10111018 end else
1012- Mark('can''t convert ' + TypeName(s) + ' to ' + TypeName(t));
1019+ MarkAt(x.pos, 'can''t convert ' + TypeName(s) + ' to ' + TypeName(t));
10131020 x.typ := t;
10141021 end;
10151022
@@ -1022,7 +1029,7 @@
10221029 c.code := x.obj^.isCode; c.ext := x.obj^.ext;
10231030 end else begin
10241031 c.code := false; c.ext := false;
1025- if x.typ^.form <> fProc then Mark('not a procedure');
1032+ if x.typ^.form <> fProc then MarkAt(x.pos, 'not a procedure');
10261033 c.sig := x.typ; c.chunk := -1;
10271034 c.target := ToSlot(x);
10281035 end;
@@ -1034,17 +1041,17 @@
10341041 var p: PObj; s: int64;
10351042 begin
10361043 p := c.param;
1037- if c.n > High(c.slots) then Mark('too many arguments');
1044+ if c.n > High(c.slots) then MarkAt(a.pos, 'too many arguments');
10381045 if p = nil then begin
10391046 { past the parameters of a C procedure that ends in ...: a string
10401047 goes as a C string, an integer constant as an I64, a real
10411048 constant as an F64; C takes no F32 there }
1042- if not c.sig^.variadic then Mark('too many arguments');
1049+ if not c.sig^.variadic then MarkAt(a.pos, 'too many arguments');
10431050 if a.mode = mStr then Coerce(a, tPtrU8)
10441051 else if a.typ^.form = fConst then Coerce(a, tI64)
10451052 else if a.typ = tRConst then Coerce(a, tReal)
1046- else if IsF32(a.typ) then Mark('an F32 goes to ... as F64(x)')
1047- else if not IsScalar(a.typ) then Mark('only a single value goes to ...');
1053+ else if IsF32(a.typ) then MarkAt(a.pos, 'an F32 goes to ... as F64(x)')
1054+ else if not IsScalar(a.typ) then MarkAt(a.pos, 'only a single value goes to ...');
10481055 c.isF[c.n] := a.typ^.form = fReal;
10491056 c.slots[c.n] := ToSlot(a);
10501057 inc(c.n);
@@ -1052,9 +1059,9 @@
10521059 end;
10531060 c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar;
10541061 if p^.isVar then begin
1055- if (a.mode <> mVar) or not a.isVar then Mark('a var parameter needs a variable');
1056- if not Same(a.typ, p^.typ) then Mark('a var parameter needs exactly ' + TypeName(p^.typ));
1057- if a.vol then Mark('can''t pass through a volatile pointer to a var parameter');
1062+ if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable');
1063+ if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ));
1064+ if a.vol then MarkAt(a.pos, 'can''t pass through a volatile pointer to a var parameter');
10581065 Address(a, RAX);
10591066 s := AllocTemp(8, 8);
10601067 Store(Mem(RBP, s), RAX, 8);
@@ -1161,7 +1168,7 @@
11611168 Value(a);
11621169 Store(Mem(RBP, x.off + f^.val), RAX, ScalarSize(f^.typ));
11631170 end else begin
1164- if a.vol then Mark('can''t copy through a volatile pointer');
1171+ if a.vol then MarkAt(a.pos, 'can''t copy through a volatile pointer');
11651172 Address(a, RSI);
11661173 Lea(RDI, Mem(RBP, x.off + f^.val));
11671174 Copy(f^.typ^.size);
@@ -1173,7 +1180,7 @@
11731180 var p: int64;
11741181 begin
11751182 if x.typ^.form = fEnum then exit(ToSlot(x));
1176- if (x.mode <> mVar) or (x.typ^.form <> fVariant) then Mark('match needs a variant or an enumeration');
1183+ if (x.mode <> mVar) or (x.typ^.form <> fVariant) then MarkAt(x.pos, 'match needs a variant or an enumeration');
11771184 Address(x, RAX);
11781185 p := AllocTemp(8, 8);
11791186 Store(Mem(RBP, p), RAX, 8);
@@ -1218,7 +1225,7 @@
12181225
12191226 procedure CondJump(var x: TItem; var L: longint);
12201227 begin
1221- if x.typ^.form <> fBool then Mark('a condition is a BOOL');
1228+ if x.typ^.form <> fBool then MarkAt(x.pos, 'a condition is a BOOL');
12221229 Value(x);
12231230 TestRR(RAX, RAX);
12241231 Jcc(ccE, L);
@@ -1283,10 +1290,10 @@
12831290
12841291 procedure ReturnValue(var x: TItem);
12851292 begin
1286- if result = nil then Mark('this procedure returns nothing');
1293+ if result = nil then MarkAt(x.pos, 'this procedure returns nothing');
12871294 Coerce(x, result);
12881295 if IsAggregate(result) then begin
1289- if x.vol then Mark('can''t copy through a volatile pointer');
1296+ if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer');
12901297 Address(x, RSI);
12911298 Load(RDI, Mem(RBP, retSlot), 8, false);
12921299 Copy(result^.size);
@@ -1303,7 +1310,7 @@
13031310 Load(RCX, Mem(RBP, retSlot), 8, false);
13041311 Store(Mem(RCX, f^.val), RAX, ScalarSize(f^.typ));
13051312 end else begin
1306- if x.vol then Mark('can''t copy through a volatile pointer');
1313+ if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer');
13071314 Address(x, RSI);
13081315 Load(RDI, Mem(RBP, retSlot), 8, false);
13091316 Lea(RDI, Mem(RDI, f^.val));
@@ -1350,7 +1357,7 @@
13501357 function ErrorChunk(var x: TItem; module, name: longint): longint;
13511358 var c: longint; p: PBytes;
13521359 begin
1353- if x.mode <> mStr then Mark('an error is made from a string');
1360+ if x.mode <> mStr then MarkAt(x.pos, 'an error is made from a string');
13541361 p := GetMem(x.val + 8);
13551362 PInt64(p)^ := x.val;
13561363 Move(rodata^[chunks^[x.chunk].start], p^[8], x.val);

src/parse.pas modified +134 -99

@@ -74,7 +74,7 @@
7474
7575 procedure Expect(s: TSym; const what: shortstring);
7676 begin
77- if tok <> s then Mark(what + ' expected');
77+ if tok <> s then MarkAt(MissingPos, what + ' expected');
7878 Next;
7979 end;
8080
@@ -85,7 +85,7 @@
8585
8686 procedure IdentDef(var n: longint; var exp: boolean);
8787 begin
88- if tok <> sIdent then Mark('name expected');
88+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
8989 n := id;
9090 Next;
9191 exp := false;
@@ -109,7 +109,7 @@
109109
110110 function ConstValue(var x: TItem): int64;
111111 begin
112- if x.mode <> mConst then Mark('constant expected');
112+ if x.mode <> mConst then MarkAt(x.pos, 'constant expected');
113113 ConstValue := x.val;
114114 end;
115115
@@ -117,20 +117,20 @@
117117 var x: TItem;
118118 begin
119119 Expression(x, nil);
120- if not IsInt(x.typ) then Mark('integer constant expected');
120+ if not IsInt(x.typ) then MarkAt(x.pos, 'integer constant expected');
121121 ConstExpr := ConstValue(x);
122122 end;
123123
124124 function QualIdent: PObj;
125125 var o: PObj;
126126 begin
127- if tok <> sIdent then Mark('name expected');
127+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
128128 o := Lookup(id);
129129 if o = nil then Mark(NameOf(id) + ' isn''t declared');
130130 Next;
131131 if o^.cls = oModule then begin
132132 Expect(sPeriod, '.');
133- if tok <> sIdent then Mark('name expected');
133+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
134134 o := Find(o^.module^.scope, id);
135135 if (o = nil) or not o^.exported then Mark(NameOf(id) + ' isn''t exported');
136136 Next;
@@ -211,7 +211,7 @@
211211 repeat
212212 n := 0;
213213 repeat
214- if tok <> sIdent then Mark('name expected');
214+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
215215 f := NewObj(oField, id, nil);
216216 f^.exported := true;
217217 if lastF = nil then c^.fields := f else lastF^.next := f;
@@ -293,7 +293,7 @@
293293 if isVar then Next;
294294 first := nil;
295295 repeat
296- if tok <> sIdent then Mark('name expected');
296+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
297297 p := NewObj(oVar, id, nil);
298298 p^.isVar := isVar;
299299 p^.lev := 1;
@@ -322,13 +322,14 @@
322322 end;
323323
324324 function EnumType: PType;
325-var t: PType; o, last: PObj;
325+var t: PType; o, last: PObj; start: TPos;
326326 begin
327+ start := TokPos;
327328 t := NewType(fEnum, 1, 1);
328329 last := nil;
329330 repeat
330331 Next;
331- if tok <> sIdent then Mark('name expected');
332+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
332333 o := NewObj(oConst, id, t);
333334 o^.val := t^.len;
334335 o^.exported := declExported;
@@ -339,14 +340,14 @@
339340 Next;
340341 until tok <> sComma;
341342 Expect(sRparen, ')');
342- if t^.len > 256 then Mark('more than 256 names');
343+ if t^.len > 256 then MarkAt(SpanFrom(start), 'more than 256 names');
343344 EnumType := t;
344345 end;
345346
346-function SetOf(e: PType): PType;
347+function SetOf(e: PType; const at: TPos): PType;
347348 var t: PType;
348349 begin
349- if (e^.form <> fEnum) or (e^.len > 64) then Mark('a set is of an enumeration of at most 64 names');
350+ if (e^.form <> fEnum) or (e^.len > 64) then MarkAt(at, 'a set is of an enumeration of at most 64 names');
350351 t := NewType(fSet, 8, 8);
351352 if e^.len <= 8 then t^.size := 1
352353 else if e^.len <= 16 then t^.size := 2
@@ -358,12 +359,13 @@
358359 end;
359360
360361 function ParseType: PType;
361-var t: PType; o: PObj; n: int64; vol: boolean;
362+var t: PType; o: PObj; n: int64; vol: boolean; start: TPos;
362363 begin
364+ start := TokPos;
363365 case tok of
364366 sIdent: begin
365367 o := QualIdent;
366- if o^.cls <> oType then Mark('type expected');
368+ if o^.cls <> oType then MarkAt(SpanFrom(start), 'type expected');
367369 t := o^.typ;
368370 end;
369371 sLbrak: begin
@@ -373,8 +375,9 @@
373375 t := NewType(fSlice, 16, 8);
374376 t^.base := ParseType();
375377 end else begin
378+ start := TokPos;
376379 n := ConstExpr;
377- if (n <= 0) or (n > (int64(1) shl 40)) then Mark('bad array length');
380+ if (n <= 0) or (n > (int64(1) shl 40)) then MarkAt(SpanFrom(start), 'bad array length');
378381 Expect(sRbrak, ']');
379382 t := NewType(fArray, 0, 1);
380383 t^.len := n;
@@ -405,9 +408,10 @@
405408 sSet: begin
406409 Next;
407410 Expect(sOf, 'of');
408- t := SetOf(ParseType());
411+ start := TokPos;
412+ t := SetOf(ParseType(), start);
409413 end;
410- else Mark('type expected');
414+ else MarkAt(MissingPos, 'type expected');
411415 end;
412416 ParseType := t;
413417 end;
@@ -437,7 +441,7 @@
437441 for i := 0 to n - 1 do begin
438442 if i > 0 then Expect(sComma, ',');
439443 Expression(a, nil);
440- if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then Mark('integer or pointer expected');
444+ if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then MarkAt(a.pos, 'integer or pointer expected');
441445 if a.typ^.form = fConst then Coerce(a, tI64);
442446 slots[i] := ToSlot(a);
443447 end;
@@ -447,10 +451,10 @@
447451 var p, a: TItem; t: PType; s: array[0..2] of int64; i, n: longint;
448452 begin
449453 Expression(p, nil);
450- if p.typ^.form <> fPtr then Mark('a pointer expected');
454+ if p.typ^.form <> fPtr then MarkAt(p.pos, 'a pointer expected');
451455 t := p.typ^.base;
452456 if not (((t^.form = fInt) or ((t^.form = fPtr) and (which <> bXadd))) and (t^.size = 8)) then
453- Mark('an 8-byte integer or pointer expected');
457+ MarkAt(p.pos, 'an 8-byte integer or pointer expected');
454458 s[0] := ToSlot(p);
455459 if which = bCas then n := 2 else n := 1;
456460 for i := 1 to n do begin
@@ -481,14 +485,14 @@
481485 var y, z: TItem; t: PType; f: PObj; s: int64; c: TCall; L: longint;
482486 begin
483487 Expression(x, nil);
484- if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then Mark('NEW needs a pointer variable');
488+ if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then MarkAt(x.pos, 'NEW needs a pointer variable');
485489 t := x.typ^.base;
486490 Save(x);
487491 Expect(sComma, ',');
488492 Expression(y, nil);
489493 if (y.typ^.form <> fPtr) or (y.typ^.base^.obj = nil) or (y.typ^.base^.obj^.module = nil)
490494 or (NameOf(y.typ^.base^.obj^.name) <> 'Allocator')
491- or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then Mark('NEW needs a ^Mem.Allocator');
495+ or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then MarkAt(y.pos, 'NEW needs a ^Mem.Allocator');
492496 f := Find(y.typ^.base^.scope, Name('alloc'));
493497 s := ToSlot(y);
494498 Load(RAX, Mem(RBP, s), 8, false);
@@ -543,7 +547,7 @@
543547 end;
544548 bAdr: begin
545549 Expression(y, nil);
546- if (y.mode <> mVar) or not y.isVar then Mark('ADR needs a variable');
550+ if (y.mode <> mVar) or not y.isVar then MarkAt(y.pos, 'ADR needs a variable');
547551 t := NewPtr(y.typ, y.vol);
548552 Address(y, RAX);
549553 MakeConst(x, t, 0);
@@ -558,7 +562,7 @@
558562 Load(RAX, Mem(RAX, 8), 8, false);
559563 MakeConst(x, tI64, 0);
560564 x.mode := mReg;
561- end else Mark('LEN needs an array or slice');
565+ end else MarkAt(y.pos, 'LEN needs an array or slice');
562566 end;
563567 bSyscall: begin
564568 n := 1;
@@ -566,7 +570,7 @@
566570 while (tok = sComma) and (n < 7) do begin
567571 Next;
568572 Expression(y, nil);
569- if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then Mark('integer or pointer expected');
573+ if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then MarkAt(y.pos, 'integer or pointer expected');
570574 if y.typ^.form = fConst then Coerce(y, tI64);
571575 slots[n] := ToSlot(y);
572576 inc(n);
@@ -581,7 +585,7 @@
581585 bInc, bDec: begin
582586 Expression(x, nil);
583587 if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then
584- Mark('INC and DEC need an integer variable');
588+ MarkAt(x.pos, 'INC and DEC need an integer variable');
585589 Save(x);
586590 if tok = sComma then begin
587591 Next;
@@ -596,7 +600,7 @@
596600 Expect(sRparen, ')');
597601 end;
598602
599-procedure ConstructCase(var x: TItem; c: PObj);
603+procedure ConstructCase(var x: TItem; c: PObj; const at: TPos);
600604 var f: PObj; a: TItem;
601605 begin
602606 Construct(x, c);
@@ -610,30 +614,32 @@
610614 if f <> nil then Expect(sComma, ',');
611615 end;
612616 Expect(sRparen, ')');
613- end else if f <> nil then Mark(NameOf(c^.name) + ' needs its fields');
617+ end else if f <> nil then MarkAt(at, NameOf(c^.name) + ' needs its fields');
614618 end;
615619
616620 { A designator, with any selectors and calls after it. called tells
617621 whether the last thing done was a call. }
618622 procedure Designator(var x: TItem; var called: boolean);
619-var o, f: PObj; y, z: TItem; t: PType;
623+var o, f: PObj; y, z: TItem; t: PType; start: TPos;
620624 begin
625+ start := TokPos;
621626 o := QualIdent;
622627 called := false;
623- if o^.cls = oModule then Mark('a module is not a value');
628+ if o^.cls = oModule then MarkAt(SpanFrom(start), 'a module is not a value');
624629 MakeItem(x, o);
625630 if x.mode = mBuiltin then begin
626631 Builtin(x);
627632 called := true;
628633 end else if x.mode = mCase then begin
629- ConstructCase(x, o);
634+ ConstructCase(x, o, SpanFrom(start));
630635 end;
631636 repeat
637+ x.pos := SpanFrom(start);
632638 case tok of
633639 sPeriod: begin
634640 Next;
635- if (x.mode <> mVar) or (x.typ^.form <> fRecord) then Mark('not a record');
636- if tok <> sIdent then Mark('field expected');
641+ if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'not a record');
642+ if tok <> sIdent then MarkAt(MissingPos, 'field expected');
637643 f := Find(x.typ^.scope, id);
638644 if f = nil then Mark('no field ' + NameOf(id));
639645 if not f^.exported and (x.typ^.module <> curModule) then
@@ -671,13 +677,15 @@
671677 else break;
672678 end;
673679 until false;
680+ x.pos := SpanFrom(start);
674681 end;
675682
676683 procedure ArrayLiteral(var x: TItem; want: PType);
677684 var
678685 et, at: PType; e: TItem; slots: array[0..1023] of int64; n, i: longint;
679- off, es: int64;
686+ off, es: int64; start: TPos;
680687 begin
688+ start := TokPos;
681689 if (want = nil) or not (want^.form in [fArray, fSlice]) then
682690 Mark('an array literal needs a known array or slice type');
683691 et := want^.base;
@@ -699,7 +707,7 @@
699707 Next;
700708 until false;
701709 Expect(sRbrak, ']');
702- if (want^.form = fArray) and (n <> want^.len) then Mark('wrong number of elements');
710+ if (want^.form = fArray) and (n <> want^.len) then MarkAt(SpanFrom(start), 'wrong number of elements');
703711 if n = 0 then begin
704712 MovRI(RAX, 0);
705713 SliceOf(x, want, 0);
@@ -737,7 +745,7 @@
737745 n := 0;
738746 if tok <> sRbrace then
739747 repeat
740- if tok <> sIdent then Mark('field expected');
748+ if tok <> sIdent then MarkAt(MissingPos, 'field expected');
741749 f := Find(t^.scope, id);
742750 if f = nil then Mark('no field ' + NameOf(id));
743751 if not f^.exported and (t^.module <> curModule) then Mark('field ' + NameOf(id) + ' isn''t exported');
@@ -756,20 +764,21 @@
756764 { A set literal: the bits of the constant names, or'd at run time with
757765 those of the others. }
758766 procedure SetLiteral(var x: TItem; t: PType);
759-var e: TItem; bits, slot: int64;
767+var e: TItem; bits, slot: int64; start: TPos;
760768 begin
769+ start := TokPos;
761770 Next;
762- if (t <> nil) and (t^.form <> fSet) then Mark('a set literal needs a set type');
771+ if (t <> nil) and (t^.form <> fSet) then MarkAt(SpanFrom(start), 'a set literal needs a set type');
763772 bits := 0;
764773 slot := 0;
765774 if tok <> sRbrace then
766775 repeat
767776 if t = nil then Expression(e, nil) else Expression(e, t^.base);
768777 if t = nil then begin
769- if e.typ^.form <> fEnum then Mark('a set holds names of an enumeration');
770- t := SetOf(e.typ);
778+ if e.typ^.form <> fEnum then MarkAt(e.pos, 'a set holds names of an enumeration');
779+ t := SetOf(e.typ, e.pos);
771780 end;
772- if not Same(e.typ, t^.base) then Mark('not a name of ' + TypeName(t^.base));
781+ if not Same(e.typ, t^.base) then MarkAt(e.pos, 'not a name of ' + TypeName(t^.base));
773782 if e.mode = mConst then bits := bits or (int64(1) shl e.val)
774783 else begin
775784 if slot = 0 then begin
@@ -788,7 +797,7 @@
788797 Next;
789798 until false;
790799 Expect(sRbrace, '}');
791- if t = nil then Mark('{} needs a known set type');
800+ if t = nil then MarkAt(SpanFrom(start), '{} needs a known set type');
792801 MakeConst(x, t, bits);
793802 if slot <> 0 then begin
794803 Load(RAX, Mem(RBP, slot), 8, false);
@@ -799,8 +808,9 @@
799808 end;
800809
801810 procedure Factor(var x: TItem; want: PType);
802-var called, vol: boolean; t: PType;
811+var called, vol: boolean; t: PType; start: TPos;
803812 begin
813+ start := TokPos;
804814 case tok of
805815 sInt, sChar: begin
806816 { only a hex number can be above high(I64), and it is a U64 }
@@ -811,8 +821,8 @@
811821 sString: begin MakeStr(x); Next end;
812822 sIdent: begin
813823 Designator(x, called);
814- if x.mode = mNone then Mark('this procedure returns nothing');
815- if x.typ^.tuple then Mark('several results go only to a, b := ...');
824+ if x.mode = mNone then MarkAt(x.pos, 'this procedure returns nothing');
825+ if x.typ^.tuple then MarkAt(x.pos, 'several results go only to a, b := ...');
816826 end;
817827 sLparen: begin Next; Expression(x, want); Expect(sRparen, ')') end;
818828 sNot: begin Next; Factor(x, nil); NotOp(x) end;
@@ -829,13 +839,15 @@
829839 Expect(sRparen, ')');
830840 Convert(x, t);
831841 end;
832- else Mark('expression expected');
842+ else MarkAt(MissingPos, 'expression expected');
833843 end;
844+ x.pos := SpanFrom(start);
834845 end;
835846
836847 procedure Term(var x: TItem; want: PType);
837-var op: TSym; y: TItem; L: longint;
848+var op: TSym; y: TItem; L: longint; start: TPos;
838849 begin
850+ start := TokPos;
839851 Factor(x, want);
840852 while tok in [sTimes, sSlash, sDiv, sMod, sAnd, sShl, sShr] do begin
841853 op := tok;
@@ -843,15 +855,18 @@
843855 Op1(op, x, L);
844856 Factor(y, nil);
845857 Op2(op, x, y, L);
858+ x.pos := SpanFrom(start);
846859 end;
847860 end;
848861
849862 procedure SimpleExpr(var x: TItem; want: PType);
850-var op: TSym; y: TItem; L: longint;
863+var op: TSym; y: TItem; L: longint; start: TPos;
851864 begin
865+ start := TokPos;
852866 if tok = sMinus then begin
853867 Next;
854868 Term(x, nil);
869+ x.pos := SpanFrom(start);
855870 Neg(x);
856871 end else Term(x, want);
857872 while tok in [sPlus, sMinus, sOr, sXor] do begin
@@ -860,6 +875,7 @@
860875 Op1(op, x, L);
861876 Term(y, nil);
862877 Op2(op, x, y, L);
878+ x.pos := SpanFrom(start);
863879 end;
864880 end;
865881
@@ -873,6 +889,7 @@
873889 Op1(op, x, L);
874890 if op = sIn then SimpleExpr(y, nil) else SimpleExpr(y, x.typ);
875891 Op2(op, x, y, L);
892+ x.pos := Join(x.pos, y.pos);
876893 end;
877894 end;
878895
@@ -963,7 +980,7 @@
963980 lp: TLoop; old: PLoop;
964981 begin
965982 Next;
966- if tok <> sIdent then Mark('name expected');
983+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
967984 o := Lookup(id);
968985 if (o = nil) or (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then
969986 Mark('a for loop needs an integer or enumeration variable');
@@ -982,7 +999,7 @@
982999 Next;
9831000 Expression(s, nil);
9841001 step := ConstValue(s);
985- if step = 0 then Mark('the step can''t be zero');
1002+ if step = 0 then MarkAt(s.pos, 'the step can''t be zero');
9861003 end;
9871004 Expect(sDo, 'do');
9881005 exitL := NoLabel;
@@ -1008,7 +1025,7 @@
10081025 procedure MatchStatement;
10091026 var
10101027 x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n: longint;
1011- seen: array[0..255] of boolean; hasElse: boolean;
1028+ seen: array[0..255] of boolean; hasElse: boolean; endAt: TPos;
10121029 begin
10131030 Next;
10141031 Expression(x, nil);
@@ -1027,7 +1044,7 @@
10271044 Statements;
10281045 hasElse := true;
10291046 end else begin
1030- if tok <> sIdent then Mark('case expected');
1047+ if tok <> sIdent then MarkAt(MissingPos, 'case expected');
10311048 c := t^.fields;
10321049 while (c <> nil) and (c^.name <> id) do c := c^.next;
10331050 if c = nil then Mark(NameOf(id) + ' isn''t a case of ' + TypeName(t));
@@ -1042,7 +1059,7 @@
10421059 f := c^.fields;
10431060 n := 0;
10441061 repeat
1045- if tok <> sIdent then Mark('name expected');
1062+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
10461063 if f = nil then Mark('too many fields');
10471064 o := NewObj(oVar, id, f^.typ);
10481065 o^.lev := 1; o^.ind := true; o^.isVar := true;
@@ -1064,11 +1081,12 @@
10641081 FixLink(L);
10651082 end;
10661083 end;
1084+ endAt := TokPos;
10671085 Expect(sEnd, 'end');
10681086 if not hasElse then begin
10691087 c := t^.fields;
10701088 while c <> nil do begin
1071- if (c^.val > High(seen)) or not seen[c^.val] then Mark('no arm for ' + NameOf(c^.name));
1089+ if (c^.val > High(seen)) or not seen[c^.val] then MarkAt(endAt, 'no arm for ' + NameOf(c^.name));
10721090 c := c^.next;
10731091 end;
10741092 end;
@@ -1083,7 +1101,7 @@
10831101 n := 0;
10841102 d[0] := x;
10851103 repeat
1086- if (d[n].mode <> mVar) or not d[n].isVar then Mark('can''t assign to this');
1104+ if (d[n].mode <> mVar) or not d[n].isVar then MarkAt(d[n].pos, 'can''t assign to this');
10871105 Pin(d[n]);
10881106 inc(n);
10891107 if tok <> sComma then break;
@@ -1094,7 +1112,7 @@
10941112 Expect(sBecomes, ':=');
10951113 Designator(y, called);
10961114 if not called or not y.typ^.tuple or (y.typ^.len <> n) then
1097- Mark('needs a call with as many results as variables');
1115+ MarkAt(y.pos, 'needs a call with as many results as variables');
10981116 f := y.typ^.fields;
10991117 for i := 0 to n - 1 do begin
11001118 z := y;
@@ -1119,11 +1137,12 @@
11191137 { defer s: s is compiled where it stands, as a little subroutine of the
11201138 procedure, jumped over; each way out of the statement list calls it. }
11211139 procedure Defer;
1122-var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean;
1140+var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean; start: TPos;
11231141 begin
1142+ start := TokPos;
11241143 Next;
1125- if directDefer then Mark('defer can''t be deferred');
1126- if numDefers > High(defers) then Mark('too many deferred statements');
1144+ if directDefer then MarkAt(SpanFrom(start), 'defer can''t be deferred');
1145+ if numDefers > High(defers) then MarkAt(SpanFrom(start), 'too many deferred statements');
11271146 L := NoLabel;
11281147 Jmp(L);
11291148 pos := pc;
@@ -1143,15 +1162,16 @@
11431162 end;
11441163
11451164 procedure Statement;
1146-var x, y: TItem; called: boolean; m: int64; c: TCall;
1165+var x, y: TItem; called: boolean; m: int64; c: TCall; start: TPos;
11471166 begin
1167+ start := TokPos;
11481168 NoteLine(CurLine);
11491169 m := TempMark;
11501170 case tok of
11511171 sIdent: begin
11521172 Designator(x, called);
11531173 if tok = sBecomes then begin
1154- if (x.mode <> mVar) or not x.isVar then Mark('can''t assign to this');
1174+ if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to this');
11551175 Save(x);
11561176 Next;
11571177 Expression(y, x.typ);
@@ -1162,7 +1182,7 @@
11621182 if (x.mode = mProc) or ((x.mode in [mVar, mReg]) and (x.typ^.form = fProc)) then begin
11631183 BeginCall(c, x);
11641184 EndCall(c, x);
1165- end else Mark('not a statement');
1185+ end else MarkAt(x.pos, 'not a statement');
11661186 end;
11671187 end;
11681188 sIf: IfStatement;
@@ -1172,7 +1192,7 @@
11721192 sMatch: MatchStatement;
11731193 sReturn: begin
11741194 Next;
1175- if deferring then Mark('return can''t leave a deferred statement');
1195+ if deferring then MarkAt(SpanFrom(start), 'return can''t leave a deferred statement');
11761196 if tok = sSemicolon then begin
11771197 RunDefers(0);
11781198 ReturnNone;
@@ -1193,12 +1213,12 @@
11931213 end;
11941214 sBreak: begin
11951215 Next;
1196- if curLoop = nil then Mark('break outside a loop');
1216+ if curLoop = nil then MarkAt(SpanFrom(start), 'break outside a loop');
11971217 RunDefers(curLoop^.base);
11981218 Jmp(curLoop^.brk);
11991219 end;
12001220 sDefer: Defer;
1201- else Mark('statement expected');
1221+ else MarkAt(MissingPos, 'statement expected');
12021222 end;
12031223 ReleaseTemps(m);
12041224 end;
@@ -1278,30 +1298,31 @@
12781298 CloseScope;
12791299 end;
12801300
1281-procedure CodeBody(p: PObj; sig: PType);
1282-var q: PObj; ni, nf: longint; v: int64;
1301+procedure CodeBody(p: PObj; sig: PType; const at: TPos);
1302+var q: PObj; ni, nf: longint; v: int64; start: TPos;
12831303 begin
12841304 ni := 0; nf := 0;
12851305 q := sig^.fields;
12861306 while q <> nil do begin
12871307 if not q^.isVar and not IsScalar(q^.typ) then
1288- Mark('a code procedure takes integers, BOOL, reals, pointers and procedures');
1308+ MarkAt(at, 'a code procedure takes integers, BOOL, reals, pointers and procedures');
12891309 if (q^.typ^.form = fReal) and not q^.isVar then inc(nf) else inc(ni);
12901310 q := q^.next;
12911311 end;
1292- if (ni > 6) or (nf > 8) or sig^.variadic then Mark('too many parameters for a code procedure');
1312+ if (ni > 6) or (nf > 8) or sig^.variadic then MarkAt(at, 'too many parameters for a code procedure');
12931313 if sig^.base <> nil then
12941314 if sig^.base^.tuple then begin
12951315 q := sig^.base^.fields;
12961316 if (sig^.base^.len <> 2) or (q^.typ^.size <> 8) or (q^.next^.typ^.size <> 8)
12971317 or not IsScalar(q^.typ) or not IsScalar(q^.next^.typ)
12981318 or (q^.typ^.form = fReal) or (q^.next^.typ^.form = fReal) then
1299- Mark('a code procedure returns two results only in rax and rdx');
1300- end else if not IsScalar(sig^.base) then Mark('a code procedure returns a single value');
1319+ MarkAt(at, 'a code procedure returns two results only in rax and rdx');
1320+ end else if not IsScalar(sig^.base) then MarkAt(at, 'a code procedure returns a single value');
13011321 BeginChunk(p^.chunk);
13021322 repeat
1323+ start := TokPos;
13031324 v := ConstExpr;
1304- if (v < 0) or (v > 255) then Mark('a byte expected');
1325+ if (v < 0) or (v > 255) then MarkAt(SpanFrom(start), 'a byte expected');
13051326 Put1(v);
13061327 if tok <> sComma then break;
13071328 Next;
@@ -1310,16 +1331,18 @@
13101331 end;
13111332
13121333 procedure ProcDecl;
1313-var n, line: longint; exp: boolean; sig: PType; p: PObj;
1334+var n, line: longint; exp: boolean; sig: PType; p: PObj; at: TPos;
13141335 begin
13151336 line := CurLine;
13161337 Next;
1338+ at := TokPos;
13171339 IdentDef(n, exp);
1340+ at := SpanFrom(at);
13181341 sig := Signature;
13191342 Expect(sSemicolon, ';');
13201343 p := Find(TopScope, n);
13211344 if (p <> nil) and (p^.cls = oProc) and p^.fwd then begin
1322- if not Same(p^.typ, sig) then Mark('not the signature it was declared with');
1345+ if not Same(p^.typ, sig) then MarkAt(at, 'not the signature it was declared with');
13231346 if tok = sForward then Mark('declared forward twice');
13241347 p^.exported := p^.exported or exp;
13251348 end else begin
@@ -1339,7 +1362,7 @@
13391362 if tok = sCode then begin
13401363 Next;
13411364 p^.isCode := true;
1342- CodeBody(p, sig);
1365+ CodeBody(p, sig, at);
13431366 exit;
13441367 end;
13451368 if checkMode then SkipBody else Body(p, sig, line);
@@ -1352,26 +1375,28 @@
13521375 { An extern procedure or variable: C's, reached through the quadword
13531376 that holds its address. }
13541377 procedure ExternDecl;
1355-var n: longint; exp: boolean; o, q: PObj; t: PType;
1378+var n: longint; exp: boolean; o, q: PObj; t: PType; at: TPos;
13561379 begin
13571380 Next;
13581381 curModule^.usesC := true;
13591382 if tok = sProc then begin
13601383 Next;
1384+ at := TokPos;
13611385 IdentDef(n, exp);
1386+ at := SpanFrom(at);
13621387 inExtern := true;
13631388 t := Signature;
13641389 inExtern := false;
13651390 q := t^.fields;
13661391 while q <> nil do begin
13671392 if q^.isVar or not IsScalar(q^.typ) then
1368- Mark('C takes integers, BOOL, reals, pointers and procedures');
1393+ MarkAt(at, 'C takes integers, BOOL, reals, pointers and procedures');
13691394 q := q^.next;
13701395 end;
1371- if (t^.base <> nil) and not IsScalar(t^.base) then Mark('C returns a single value');
1396+ if (t^.base <> nil) and not IsScalar(t^.base) then MarkAt(at, 'C returns a single value');
13721397 o := NewObj(oProc, n, t);
13731398 end else begin
1374- if tok <> sVar then Mark('proc or var expected');
1399+ if tok <> sVar then MarkAt(MissingPos, 'proc or var expected');
13751400 Next;
13761401 IdentDef(n, exp);
13771402 Expect(sColon, ':');
@@ -1389,7 +1414,7 @@
13891414 procedure Declarations(top: boolean);
13901415 var
13911416 n, i, k: longint; exp: boolean; x: TItem; o: PObj; t: PType;
1392- names: array[0..63] of longint; exps: array[0..63] of boolean;
1417+ names: array[0..63] of longint; exps: array[0..63] of boolean; start: TPos;
13931418 begin
13941419 repeat
13951420 case tok of
@@ -1400,8 +1425,9 @@
14001425 t := nil;
14011426 if tok = sColon then begin
14021427 Next;
1428+ start := TokPos;
14031429 t := ParseType;
1404- if t <> tError then Mark('only an ERROR constant has a type');
1430+ if t <> tError then MarkAt(SpanFrom(start), 'only an ERROR constant has a type');
14051431 end;
14061432 Expect(sEql, '=');
14071433 Expression(x, nil);
@@ -1510,18 +1536,20 @@
15101536
15111537 { The arguments of an instance: types, or procedures named. }
15121538 procedure ParseArgs(var args: TArgs);
1513-var o: PObj;
1539+var o: PObj; start: TPos;
15141540 begin
15151541 Next;
15161542 repeat
15171543 if args.n > High(args.t) then Mark('too many arguments');
15181544 args.o[args.n] := nil;
1545+ start := TokPos;
15191546 if tok = sIdent then begin
15201547 o := QualIdent;
15211548 if o^.cls = oProc then args.o[args.n] := o
1522- else if o^.cls <> oType then Mark('a type or a procedure expected');
1549+ else if o^.cls <> oType then MarkAt(SpanFrom(start), 'a type or a procedure expected');
15231550 args.t[args.n] := o^.typ;
15241551 end else args.t[args.n] := ParseType;
1552+ args.pos[args.n] := SpanFrom(start);
15251553 inc(args.n);
15261554 if tok <> sComma then break;
15271555 Next;
@@ -1532,14 +1560,14 @@
15321560 { A generic module's parameters, bound to the instance's arguments: a
15331561 type parameter names its type, a procedure parameter its procedure. }
15341562 procedure Params(m: PModule);
1535-var i: longint; o, a: PObj; sig: PType; s: shortstring;
1563+var i: longint; o, a: PObj; sig: PType; s: shortstring; at: TPos;
15361564 begin
15371565 i := 0;
15381566 s := NameOf(m^.name) + '(';
15391567 Next;
15401568 repeat
1541- if (tok <> sIdent) or (i >= m^.args.n) or (m^.args.o[i] <> nil) then
1542- Mark('needs a type for each type parameter');
1569+ if (tok <> sIdent) or (i >= m^.args.n) then MarkAt(m^.args.at, 'needs a type for each type parameter');
1570+ if m^.args.o[i] <> nil then MarkAt(m^.args.pos[i], 'needs a type for each type parameter');
15431571 Declare(NewObj(oType, id, m^.args.t[i]));
15441572 s := s + TypeName(m^.args.t[i]) + ',';
15451573 inc(i);
@@ -1549,23 +1577,27 @@
15491577 until false;
15501578 while tok = sSemicolon do begin
15511579 Next;
1552- if tok <> sIdent then Mark('name expected');
1580+ if tok <> sIdent then MarkAt(MissingPos, 'name expected');
1581+ at := TokPos;
15531582 o := NewObj(oProc, id, nil);
15541583 Next;
15551584 Expect(sColon, ':');
15561585 Expect(sProc, 'proc');
15571586 sig := Signature;
1558- if i >= m^.args.n then Mark('needs a procedure for ' + NameOf(o^.name));
1587+ if i >= m^.args.n then MarkAt(m^.args.at, 'needs a procedure for ' + NameOf(o^.name));
15591588 a := m^.args.o[i];
1560- if (a = nil) or not Same(a^.typ, sig) then
1561- Mark('needs a procedure with the signature of ' + NameOf(o^.name));
1589+ if (a = nil) or not Same(a^.typ, sig) then begin
1590+ Error(m^.args.pos[i], 'needs a procedure with the signature of ' + NameOf(o^.name));
1591+ Note(at, NameOf(o^.name) + ' is declared here');
1592+ Finish;
1593+ end;
15621594 o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext;
15631595 Declare(o);
15641596 s := s + NameOf(a^.module^.name) + '.' + NameOf(a^.name) + ',';
15651597 inc(i);
15661598 end;
15671599 Expect(sRparen, ')');
1568- if i <> m^.args.n then Mark('too many arguments');
1600+ if i <> m^.args.n then MarkAt(m^.args.at, 'too many arguments');
15691601 s[length(s)] := ')';
15701602 m^.sname := Name(s);
15711603 end;
@@ -1586,7 +1618,7 @@
15861618 var
15871619 st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint;
15881620 oldMod: PModule; oldFile: longint; oldCheck: boolean; m, im: PModule;
1589- imp: PImport; lib: PLib; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs;
1621+ imp: PImport; lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs;
15901622 begin
15911623 SaveScan(st);
15921624 SaveScopes(d, saved);
@@ -1616,23 +1648,25 @@
16161648 if (tok <> sIdent) or (id <> n) then Mark('this file must hold module ' + NameOf(n));
16171649 Next;
16181650 if tok = sLparen then Params(m)
1619- else if args.n > 0 then Mark(NameOf(n) + ' isn''t generic');
1651+ else if args.n > 0 then MarkAt(args.at, NameOf(n) + ' isn''t generic');
16201652 Expect(sSemicolon, ';');
16211653 while tok = sImport do begin
16221654 Next;
16231655 repeat
1624- if tok <> sIdent then Mark('module name expected');
1656+ if tok <> sIdent then MarkAt(MissingPos, 'module name expected');
1657+ start := TokPos;
16251658 alias := id;
16261659 mname := id;
16271660 iargs.n := 0;
16281661 Next;
16291662 if tok = sBecomes then begin
16301663 Next;
1631- if tok <> sIdent then Mark('module name expected');
1664+ if tok <> sIdent then MarkAt(MissingPos, 'module name expected');
16321665 mname := id;
16331666 Next;
16341667 if tok = sLparen then ParseArgs(iargs);
16351668 end;
1669+ iargs.at := SpanFrom(start);
16361670 im := ImportModule(mname, iargs);
16371671 o := NewObj(oModule, alias, nil);
16381672 o^.module := im;
@@ -1679,7 +1713,7 @@
16791713 end else Expect(sEnd, 'end');
16801714 if (tok <> sIdent) or (id <> n) then Mark('end ' + NameOf(n) + ' expected');
16811715 Next;
1682- if tok <> sPeriod then Mark('. expected');
1716+ if tok <> sPeriod then MarkAt(MissingPos, '. expected');
16831717 o := m^.first;
16841718 while o <> nil do begin
16851719 if (o^.cls = oProc) and o^.fwd then Mark(NameOf(o^.name) + ' is declared forward but never defined');
@@ -1759,7 +1793,7 @@
17591793 m := FindModule(name, args);
17601794 if m <> nil then exit(m);
17611795 for i := 0 to numPending - 1 do
1762- if IsModule(pending[i], name, args) then Mark(NameOf(name) + ' imports itself');
1796+ if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself');
17631797 for i := -1 to numInc do begin
17641798 if i = -1 then dir := mainDir
17651799 else if i = numInc then dir := libDir
@@ -1773,7 +1807,7 @@
17731807 end;
17741808 end;
17751809 end;
1776- Mark('can''t find module ' + NameOf(name));
1810+ MarkAt(args.at, 'can''t find module ' + NameOf(name));
17771811 ImportModule := nil;
17781812 end;
17791813
@@ -1789,6 +1823,7 @@
17891823 if i > 0 then base := copy(base, 1, i - 1);
17901824 if base = '' then Fatal('no module in ' + path);
17911825 n := Name(base);
1826+ none.at := TokPos;
17921827 if n <> nameRt then ImportModule(nameRt, none);
17931828 if FindModule(n, none) <> nil then CompileMain := FindModule(n, none)
17941829 else CompileMain := CompileFile(path, n, none, false);

src/scan.pas modified +62 -13

@@ -41,6 +41,7 @@
4141 buf: PChar;
4242 len, pos, line, lineStart: longint;
4343 tokPos, tokLine, tokLineStart: longint;
44+ prevEnd: longint; { where the symbol before this one ends }
4445 tok: TSym;
4546 ival: int64;
4647 rval: double;
@@ -66,9 +67,13 @@
6667 function Open(const path: shortstring): boolean;
6768 procedure Next;
6869 procedure Mark(const msg: shortstring);
70+procedure MarkAt(const p: TPos; const msg: shortstring);
6971 procedure SaveScan(var st: TScanState);
7072 procedure RestoreScan(const st: TScanState);
7173 function TokPos: TPos;
74+function AfterPrev: TPos;
75+function MissingPos: TPos;
76+function SpanFrom(const p: TPos): TPos;
7277 function CurPath: shortstring;
7378 function CurLine: longint;
7479
@@ -171,6 +176,34 @@
171176 TokPos.b := cur.pos;
172177 end;
173178
179+{ The place just after the symbol before the current one, where a
180+ missing symbol belongs }
181+function AfterPrev: TPos;
182+begin
183+ AfterPrev.f := cur.f;
184+ AfterPrev.a := cur.prevEnd;
185+ AfterPrev.b := cur.prevEnd;
186+end;
187+
188+{ Where to say a symbol is missing: at the current symbol, unless it
189+ starts a later line than the symbol before it, which is more likely
190+ where the missing one belongs }
191+function MissingPos: TPos;
192+var i: longint;
193+begin
194+ MissingPos := TokPos;
195+ for i := cur.prevEnd to cur.tokPos - 1 do
196+ if cur.buf[i] = #10 then MissingPos := AfterPrev;
197+end;
198+
199+{ From the start of p to the end of the symbol before the current one:
200+ the whole of a construct that has just been read }
201+function SpanFrom(const p: TPos): TPos;
202+begin
203+ SpanFrom := p;
204+ SpanFrom.b := cur.prevEnd;
205+end;
206+
174207 function CurPath: shortstring;
175208 begin
176209 CurPath := cur.path;
@@ -183,7 +216,20 @@
183216
184217 procedure Mark(const msg: shortstring);
185218 begin
186- Error(TokPos, msg);
219+ MarkAt(TokPos, msg);
220+end;
221+
222+{ Report at the bytes a to b of the file being read }
223+procedure MarkBytes(a, b: longint; const msg: shortstring);
224+var p: TPos;
225+begin
226+ p.f := cur.f; p.a := a; p.b := b;
227+ MarkAt(p, msg);
228+end;
229+
230+procedure MarkAt(const p: TPos; const msg: shortstring);
231+begin
232+ Error(p, msg);
187233 Finish;
188234 end;
189235
@@ -298,9 +344,10 @@
298344 { One character of a character or string literal, at buf[pos]: its code
299345 point, or for \xHH, minus one minus the byte. }
300346 function LitChar(inString: boolean): longint;
301-var c: char; v, d, n: longint;
347+var c: char; v, d, n, esc: longint;
302348 begin
303349 c := cur.buf[cur.pos];
350+ esc := cur.pos;
304351 if c = '\' then begin
305352 inc(cur.pos);
306353 c := cur.buf[cur.pos];
@@ -312,28 +359,28 @@
312359 '0': v := 0;
313360 '\', '''', '"': v := ord(c);
314361 'x': begin
315- if not inString then Mark('\x only in strings');
362+ if not inString then MarkBytes(esc, cur.pos, '\x only in strings');
316363 d := HexVal(cur.buf[cur.pos]);
317364 n := HexVal(cur.buf[cur.pos + 1]);
318- if (d < 0) or (n < 0) then Mark('\x needs two hex digits');
365+ if (d < 0) or (n < 0) then MarkBytes(esc, cur.pos + 2, '\x needs two hex digits');
319366 inc(cur.pos, 2);
320367 v := -1 - (d * 16 + n);
321368 end;
322369 'u': begin
323- if cur.buf[cur.pos] <> '{' then Mark('\u needs {');
370+ if cur.buf[cur.pos] <> '{' then MarkBytes(esc, cur.pos, '\u needs {');
324371 inc(cur.pos);
325372 v := 0; n := 0;
326373 while HexVal(cur.buf[cur.pos]) >= 0 do begin
327374 v := v * 16 + HexVal(cur.buf[cur.pos]);
328375 inc(n); inc(cur.pos);
329- if n > 6 then Mark('code point too big');
376+ if n > 6 then MarkBytes(esc, cur.pos, 'code point too big');
330377 end;
331- if (n = 0) or (cur.buf[cur.pos] <> '}') then Mark('bad \u{...}');
378+ if (n = 0) or (cur.buf[cur.pos] <> '}') then MarkBytes(esc, cur.pos, 'bad \u{...}');
332379 inc(cur.pos);
333380 if (v > $10FFFF) or ((v >= $D800) and (v <= $DFFF)) then
334- Mark('not a code point');
381+ MarkBytes(esc, cur.pos, 'not a code point');
335382 end;
336- else Mark('unknown escape');
383+ else MarkBytes(esc, cur.pos, 'unknown escape');
337384 end;
338385 end else if byte(c) >= $80 then
339386 v := Utf8(cur.pos)
@@ -349,14 +396,15 @@
349396 { Symbols }
350397
351398 procedure Comment;
352-var depth: longint; c: char;
399+var depth, open: longint; c: char;
353400 begin
354401 depth := 1;
402+ open := cur.pos;
355403 inc(cur.pos, 2);
356404 repeat
357405 c := cur.buf[cur.pos];
358406 if c = #0 then begin
359- if cur.pos >= cur.len then Mark('comment not closed');
407+ if cur.pos >= cur.len then MarkBytes(open, open + 2, 'comment not closed');
360408 inc(cur.pos);
361409 end else if (c = '(') and (cur.buf[cur.pos + 1] = '*') then begin
362410 inc(depth); inc(cur.pos, 2)
@@ -422,6 +470,7 @@
422470 procedure Next;
423471 var c: char; start, h, v: longint;
424472 begin
473+ cur.prevEnd := cur.pos;
425474 repeat
426475 c := cur.buf[cur.pos];
427476 while c in [' ', #9, #13, #10] do begin
@@ -509,13 +558,13 @@
509558 '^': begin inc(cur.pos); tok := sArrow end;
510559 '|': begin inc(cur.pos); tok := sBar end;
511560 #0: begin
512- if cur.pos < cur.len then Mark('NUL character');
561+ if cur.pos < cur.len then MarkBytes(cur.pos, cur.pos + 1, 'NUL character');
513562 tok := sEof;
514563 end;
515564 else
516565 if byte(c) >= $80 then
517566 Mark('text outside strings, characters and comments must be ASCII');
518- Mark('unexpected character');
567+ MarkBytes(cur.pos, cur.pos + 1, 'unexpected character');
519568 end;
520569 end;
521570

src/sym.pas modified +3 -1

@@ -17,7 +17,7 @@
1717
1818 interface
1919
20-uses scan;
20+uses scan, diag;
2121
2222 type
2323 TForm = (fNone, fBool, fInt, fReal, fConst, fNil, fStr, fPtr, fArray,
@@ -80,6 +80,8 @@
8080 n: longint;
8181 t: array[0..7] of PType;
8282 o: array[0..7] of PObj;
83+ pos: array[0..7] of TPos; { where each argument is, for messages }
84+ at: TPos; { where the import is }
8385 end;
8486
8587 TImport = record

test/err/Assign.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Assign.raz:5:11: error: can't use I32 as I64
1+test/err/Assign.raz:5:10: error: can't use I32 as I64
22 5 | a := b;
3- | ^
3+ | ^
44 raz: 1 error

test/err/AtAnd.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtAnd.raz:5:16: error: and, or need two BOOLs
2+ 5 | b := b and (x + 1);
3+ | ^^^^^^^
4+raz: 1 error

test/err/AtAnd.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtAnd;
2+proc main*;
3+var b: BOOL; x: I64;
4+begin
5+ b := b and (x + 1);
6+end;
7+end AtAnd.

test/err/AtArgType.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtArgType.raz:7:8: error: can't use BOOL as I64
2+ 7 | Id(b);
3+ | ^
4+raz: 1 error

test/err/AtArgType.raz added +9 -0

@@ -0,0 +1,9 @@
1+module AtArgType;
2+proc Id(a: I64): I64;
3+begin return a; end;
4+proc main*;
5+var b: BOOL;
6+begin
7+ Id(b);
8+end;
9+end AtArgType.

test/err/AtBinary.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtBinary.raz:5:10: error: can't combine I64 and BOOL
2+ 5 | x := (x + 2) * b;
3+ | ^^^^^^^^^^^
4+raz: 1 error

test/err/AtBinary.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtBinary;
2+proc main*;
3+var x: I64; b: BOOL;
4+begin
5+ x := (x + 2) * b;
6+end;
7+end AtBinary.

test/err/AtCall.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtCall.raz:5:10: error: not a procedure
2+ 5 | x := x(1);
3+ | ^
4+raz: 1 error

test/err/AtCall.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtCall;
2+proc main*;
3+var x: I64;
4+begin
5+ x := x(1);
6+end;
7+end AtCall.

test/err/AtCondition.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtCondition.raz:5:8: error: a condition is a BOOL
2+ 5 | if x + 1 then end;
3+ | ^^^^^
4+raz: 1 error

test/err/AtCondition.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtCondition;
2+proc main*;
3+var x: I64;
4+begin
5+ if x + 1 then end;
6+end;
7+end AtCondition.

test/err/AtConstFit.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtConstFit.raz:5:10: error: constant doesn't fit I32
2+ 5 | x := 5 + 3000000000;
3+ | ^^^^^^^^^^^^^^
4+raz: 1 error

test/err/AtConstFit.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtConstFit;
2+proc main*;
3+var x: I32;
4+begin
5+ x := 5 + 3000000000;
6+end;
7+end AtConstFit.

test/err/AtConvert.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtConvert.raz:5:14: error: can't convert BOOL to I64
2+ 5 | x := I64(b);
3+ | ^
4+raz: 1 error

test/err/AtConvert.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtConvert;
2+proc main*;
3+var b: BOOL; x: I64;
4+begin
5+ x := I64(b);
6+end;
7+end AtConvert.

test/err/AtDeref.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtDeref.raz:5:10: error: not a pointer
2+ 5 | y := x^;
3+ | ^
4+raz: 1 error

test/err/AtDeref.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtDeref;
2+proc main*;
3+var x, y: I64;
4+begin
5+ y := x^;
6+end;
7+end AtDeref.

test/err/AtDivZero.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtDivZero.raz:5:10: error: division by zero
2+ 5 | x := 7 div (3 - 3);
3+ | ^^^^^^^^^^^^^
4+raz: 1 error

test/err/AtDivZero.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtDivZero;
2+proc main*;
3+var x: I64;
4+begin
5+ x := 7 div (3 - 3);
6+end;
7+end AtDivZero.

test/err/AtIndex.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtIndex.raz:5:12: error: an index is an integer
2+ 5 | x := a[b];
3+ | ^
4+raz: 1 error

test/err/AtIndex.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtIndex;
2+proc main*;
3+var a: [4]I64; b: BOOL; x: I64;
4+begin
5+ x := a[b];
6+end;
7+end AtIndex.

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

@@ -0,0 +1,4 @@
1+test/err/AtIndexConst.raz:5:12: error: index out of range
2+ 5 | x := a[2 + 3];
3+ | ^^^^^
4+raz: 1 error

test/err/AtIndexConst.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module AtIndexConst;
2+proc main*;
3+var a: [4]I64; x: I64;
4+begin
5+ x := a[2 + 3];
6+end;
7+end AtIndexConst.

test/err/AtMany.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtMany.raz:7:16: error: too many arguments
2+ 7 | x := Id(1, 2 * 3);
3+ | ^^^^^
4+raz: 1 error

test/err/AtMany.raz added +9 -0

@@ -0,0 +1,9 @@
1+module AtMany;
2+proc Id(a: I64): I64;
3+begin return a; end;
4+proc main*;
5+var x: I64;
6+begin
7+ x := Id(1, 2 * 3);
8+end;
9+end AtMany.

test/err/AtMatch.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtMatch.raz:5:11: error: match needs a variant or an enumeration
2+ 5 | match x + 1 do end;
3+ | ^^^^^
4+raz: 1 error

test/err/AtMatch.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtMatch;
2+proc main*;
3+var x: I64;
4+begin
5+ match x + 1 do end;
6+end;
7+end AtMatch.

test/err/AtNegate.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtNegate.raz:5:10: error: can't negate BOOL
2+ 5 | x := -b;
3+ | ^^
4+raz: 1 error

test/err/AtNegate.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtNegate;
2+proc main*;
3+var b: BOOL; x: I64;
4+begin
5+ x := -b;
6+end;
7+end AtNegate.

test/err/AtNot.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtNot.raz:5:14: error: not needs BOOL or an integer
2+ 5 | b := not s;
3+ | ^
4+raz: 1 error

test/err/AtNot.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtNot;
2+proc main*;
3+var s: []U8; b: BOOL;
4+begin
5+ b := not s;
6+end;
7+end AtNot.

test/err/AtNotValue.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtNotValue.raz:5:10: error: not a value
2+ 5 | x := I64 + 1;
3+ | ^^^
4+raz: 1 error

test/err/AtNotValue.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtNotValue;
2+proc main*;
3+var x: I64;
4+begin
5+ x := I64 + 1;
6+end;
7+end AtNotValue.

test/err/AtPAdr.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPAdr.raz:5:14: error: ADR needs a variable
2+ 5 | p := ADR(1);
3+ | ^
4+raz: 1 error

test/err/AtPAdr.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPAdr;
2+proc main*;
3+var p: ^I64;
4+begin
5+ p := ADR(1);
6+end;
7+end AtPAdr.

test/err/AtPArrayLen.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPArrayLen.raz:2:9: error: bad array length
2+ 2 | var a: [0]I64;
3+ | ^
4+raz: 1 error

test/err/AtPArrayLen.raz added +6 -0

@@ -0,0 +1,6 @@
1+module AtPArrayLen;
2+var a: [0]I64;
3+proc main*;
4+begin
5+end;
6+end AtPArrayLen.

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

@@ -0,0 +1,4 @@
1+test/err/AtPByte.raz:3:6: error: a byte expected
2+ 3 | code 300;
3+ | ^^^
4+raz: 1 error

test/err/AtPByte.raz (history) added +4 -0

@@ -0,0 +1,4 @@
1+module AtPByte;
2+proc f(a: I64);
3+code 300;
4+end AtPByte.

test/err/AtPCantAssign.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPCantAssign.raz:7:8: error: can't assign to this
2+ 7 | a, k := two();
3+ | ^
4+raz: 1 error

test/err/AtPCantAssign.raz added +9 -0

@@ -0,0 +1,9 @@
1+module AtPCantAssign;
2+const k = 1;
3+proc two: (I64, I64); begin return 1, 2; end;
4+proc main*;
5+var a: I64;
6+begin
7+ a, k := two();
8+end;
9+end AtPCantAssign.

test/err/AtPChar.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPChar.raz:5:12: error: unexpected character
2+ 5 | a := 1 ? 2;
3+ | ^
4+raz: 1 error

test/err/AtPChar.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPChar;
2+proc main*;
3+var a: I64;
4+begin
5+ a := 1 ? 2;
6+end;
7+end AtPChar.

test/err/AtPComment.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPComment.raz:5:1: error: comment not closed
2+ 5 | (* never closed
3+ | ^^
4+raz: 1 error

test/err/AtPComment.raz added +6 -0

@@ -0,0 +1,6 @@
1+module AtPComment;
2+proc main*;
3+begin
4+end;
5+(* never closed
6+end AtPComment.

test/err/AtPConstExpr.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPConstExpr.raz:4:9: error: constant expected
2+ 4 | var a: [n]I64;
3+ | ^
4+raz: 1 error

test/err/AtPConstExpr.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPConstExpr;
2+proc main*;
3+var n: I64;
4+var a: [n]I64;
5+begin
6+end;
7+end AtPConstExpr.

test/err/AtPElems.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPElems.raz:5:10: error: wrong number of elements
2+ 5 | a := [1, 2];
3+ | ^^^^^^
4+raz: 1 error

test/err/AtPElems.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPElems;
2+proc main*;
3+var a: [3]I64;
4+begin
5+ a := [1, 2];
6+end;
7+end AtPElems.

test/err/AtPEscape.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPEscape.raz:5:12: error: unknown escape
2+ 5 | s := "a\q";
3+ | ^^
4+raz: 1 error

test/err/AtPEscape.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPEscape;
2+proc main*;
3+var s: [8]U8;
4+begin
5+ s := "a\q";
6+end;
7+end AtPEscape.

test/err/AtPInc.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPInc.raz:5:9: error: INC and DEC need an integer variable
2+ 5 | INC(a);
3+ | ^
4+raz: 1 error

test/err/AtPInc.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPInc;
2+proc main*;
3+var a: BOOL;
4+begin
5+ INC(a);
6+end;
7+end AtPInc.

test/err/AtPLen.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPLen.raz:5:14: error: LEN needs an array or slice
2+ 5 | a := LEN(a);
3+ | ^
4+raz: 1 error

test/err/AtPLen.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPLen;
2+proc main*;
3+var a: I64;
4+begin
5+ a := LEN(a);
6+end;
7+end AtPLen.

test/err/AtPNewVar.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPNewVar.raz:5:9: error: NEW needs a pointer variable
2+ 5 | NEW(a, a);
3+ | ^
4+raz: 1 error

test/err/AtPNewVar.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPNewVar;
2+proc main*;
3+var a: I64;
4+begin
5+ NEW(a, a);
6+end;
7+end AtPNewVar.

test/err/AtPNoResult.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPNoResult.raz:8:10: error: this procedure returns nothing
2+ 8 | a := p() + 1;
3+ | ^^^
4+raz: 1 error

test/err/AtPNoResult.raz added +10 -0

@@ -0,0 +1,10 @@
1+module AtPNoResult;
2+proc p;
3+begin
4+end;
5+proc main*;
6+var a: I64;
7+begin
8+ a := p() + 1;
9+end;
10+end AtPNoResult.

test/err/AtPNotRecord.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPNotRecord.raz:5:10: error: not a record
2+ 5 | a := a.f;
3+ | ^
4+raz: 1 error

test/err/AtPNotRecord.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPNotRecord;
2+proc main*;
3+var a: I64;
4+begin
5+ a := a.f;
6+end;
7+end AtPNotRecord.

test/err/AtPNotStmt.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPNotStmt.raz:5:5: error: not a statement
2+ 5 | a;
3+ | ^
4+raz: 1 error

test/err/AtPNotStmt.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPNotStmt;
2+proc main*;
3+var a: I64;
4+begin
5+ a;
6+end;
7+end AtPNotStmt.

test/err/AtPSetLit.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPSetLit.raz:6:14: error: not a name of C
2+ 6 | s := {r, 1};
3+ | ^
4+raz: 1 error

test/err/AtPSetLit.raz added +8 -0

@@ -0,0 +1,8 @@
1+module AtPSetLit;
2+type C = (r, g, b);
3+proc main*;
4+var s: set of C;
5+begin
6+ s := {r, 1};
7+end;
8+end AtPSetLit.

test/err/AtPStep.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPStep.raz:5:24: error: the step can't be zero
2+ 5 | for i := 1 to 5 by 1 - 1 do end;
3+ | ^^^^^
4+raz: 1 error

test/err/AtPStep.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPStep;
2+proc main*;
3+var i: I64;
4+begin
5+ for i := 1 to 5 by 1 - 1 do end;
6+end;
7+end AtPStep.

test/err/AtPtrMinus.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtPtrMinus.raz:5:10: error: different pointer types
2+ 5 | x := p - q;
3+ | ^^^^^
4+raz: 1 error

test/err/AtPtrMinus.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtPtrMinus;
2+proc main*;
3+var p: ^I64; q: ^I32; x: I64;
4+begin
5+ x := p - q;
6+end;
7+end AtPtrMinus.

test/err/AtReturn.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtReturn.raz:4:12: error: this procedure returns nothing
2+ 4 | return 1 + 2;
3+ | ^^^^^
4+raz: 1 error

test/err/AtReturn.raz added +6 -0

@@ -0,0 +1,6 @@
1+module AtReturn;
2+proc main*;
3+begin
4+ return 1 + 2;
5+end;
6+end AtReturn.

test/err/AtSliceHi.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtSliceHi.raz:5:15: error: an index is an integer
2+ 5 | s := a[0..b];
3+ | ^
4+raz: 1 error

test/err/AtSliceHi.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtSliceHi;
2+proc main*;
3+var a: [4]I64; b: BOOL; s: []I64;
4+begin
5+ s := a[0..b];
6+end;
7+end AtSliceHi.

test/err/AtSliceLo.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtSliceLo.raz:5:12: error: an index is an integer
2+ 5 | s := a[b..2];
3+ | ^
4+raz: 1 error

test/err/AtSliceLo.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtSliceLo;
2+proc main*;
3+var a: [4]I64; b: BOOL; s: []I64;
4+begin
5+ s := a[b..2];
6+end;
7+end AtSliceLo.

test/err/AtStrCmp.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtStrCmp.raz:5:12: error: can't compare a string with I64
2+ 5 | if s = x + 1 then end;
3+ | ^^^^^
4+raz: 1 error

test/err/AtStrCmp.raz added +7 -0

@@ -0,0 +1,7 @@
1+module AtStrCmp;
2+proc main*;
3+var s: []U8; x: I64;
4+begin
5+ if s = x + 1 then end;
6+end;
7+end AtStrCmp.

test/err/AtVarArg.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AtVarArg.raz:7:9: error: a var parameter needs a variable
2+ 7 | Inc(1 + 2);
3+ | ^^^^^
4+raz: 1 error

test/err/AtVarArg.raz added +9 -0

@@ -0,0 +1,9 @@
1+module AtVarArg;
2+proc Inc(var a: I64);
3+begin a := a + 1; end;
4+proc main*;
5+var x: I64;
6+begin
7+ Inc(1 + 2);
8+end;
9+end AtVarArg.

test/err/BadProc.err modified +5 -2

@@ -1,4 +1,7 @@
1-/home/luis/raz/lib/Map.raz:4:39: error: needs a procedure with the signature of hash
1+test/err/BadProc.raz:2:33: error: needs a procedure with the signature of hash
2+ 2 | import Str, M := Map([]U8, I64, Str.cmp, Str.eq);
3+ | ^^^^^^^
4+lib/Map.raz:4:18: note: hash is declared here
25 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
3- | ^
6+ | ^^^^
47 raz: 1 error

test/err/BigI64.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/BigI64.raz:5:28: error: can't use U64 as I64
1+test/err/BigI64.raz:5:10: error: can't use U64 as I64
22 5 | i := 0FFFFFFFFFFFFFFFFH;
3- | ^
3+ | ^^^^^^^^^^^^^^^^^^
44 raz: 1 error

test/err/Break.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Break.raz:4:10: error: break outside a loop
1+test/err/Break.raz:4:5: error: break outside a loop
22 4 | break;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/Cycle.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/mods/CycleB.raz:2:13: error: Cycle imports itself
1+test/err/mods/CycleB.raz:2:8: error: Cycle imports itself
22 2 | import Cycle;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/DeferBreak.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/DeferBreak.raz:5:20: error: break outside a loop
1+test/err/DeferBreak.raz:5:15: error: break outside a loop
22 5 | defer break;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/DeferDefer.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/DeferDefer.raz:4:17: error: defer can't be deferred
1+test/err/DeferDefer.raz:4:11: error: defer can't be deferred
22 4 | defer defer f;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/DeferReturn.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/DeferReturn.raz:4:18: error: return can't leave a deferred statement
1+test/err/DeferReturn.raz:4:11: error: return can't leave a deferred statement
22 4 | defer return 1;
3- | ^
3+ | ^^^^^^
44 raz: 1 error

test/err/ErrOrder.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/ErrOrder.raz:5:14: error: procedures and errors compare only with = and #
1+test/err/ErrOrder.raz:5:8: error: procedures and errors compare only with = and #
22 5 | if A < B then end;
3- | ^^^^
3+ | ^^^^^
44 raz: 1 error

test/err/ExternRec.err (history) modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/ExternRec.raz:5:20: error: C takes integers, BOOL, reals, pointers and procedures
1+test/err/ExternRec.raz:5:13: error: C takes integers, BOOL, reals, pointers and procedures
22 5 | extern proc f(r: R);
3- | ^
3+ | ^
44 raz: 1 error

test/err/F32Dots.err (history) modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/F32Dots.raz:8:23: error: an F32 goes to ... as F64(x)
1+test/err/F32Dots.raz:8:22: error: an F32 goes to ... as F64(x)
22 8 | C.printf("%f\n", x);
3- | ^
3+ | ^
44 raz: 1 error

test/err/Match.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Match.raz:9:8: error: no arm for c
1+test/err/Match.raz:9:5: error: no arm for c
22 9 | end;
3- | ^
3+ | ^^^
44 raz: 1 error

test/err/Mixed.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Mixed.raz:6:15: error: different types: F32 and F64
1+test/err/Mixed.raz:6:10: error: different types: F32 and F64
22 6 | y := x + y;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/NegU64.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/NegU64.raz:5:12: error: constant doesn't fit U64
1+test/err/NegU64.raz:5:10: error: constant doesn't fit U64
22 5 | u := -1;
3- | ^
3+ | ^^
44 raz: 1 error

test/err/NoArgs.err modified +3 -3

@@ -1,4 +1,4 @@
1-/home/luis/raz/lib/List.raz:2:13: error: needs a type for each type parameter
2- 2 | module List(T);
3- | ^
1+test/err/NoArgs.raz:2:8: error: needs a type for each type parameter
2+ 2 | import List;
3+ | ^^^^
44 raz: 1 error

test/err/NotGeneric.err modified +3 -3

@@ -1,4 +1,4 @@
1-/home/luis/raz/lib/Str.raz:3:11: error: Str isn't generic
2- 3 | module Str;
3- | ^
1+test/err/NotGeneric.raz:2:8: error: Str isn't generic
2+ 2 | import S := Str(I64);
3+ | ^^^^^^^^^^^^^
44 raz: 1 error

test/err/PtrArray.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/PtrArray.raz:6:7: error: a pointer to an array is indexed as p^[i]
1+test/err/PtrArray.raz:6:5: error: a pointer to an array is indexed as p^[i]
22 6 | p[1] := 0;
3- | ^
3+ | ^
44 raz: 1 error

test/err/Tuple.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Tuple.raz:6:16: error: several results go only to a, b := ...
1+test/err/Tuple.raz:6:10: error: several results go only to a, b := ...
22 6 | a := two() + 1;
3- | ^
3+ | ^^^^^
44 raz: 1 error

test/err/TwoTypes.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/TwoTypes.raz:6:11: error: can't use List(I32).List as List(I64).List
1+test/err/TwoTypes.raz:6:10: error: can't use List(I32).List as List(I64).List
22 6 | a := b;
3- | ^
3+ | ^
44 raz: 1 error

test/err/Volatile.err modified +2 -2

@@ -1,4 +1,4 @@
1-test/err/Volatile.raz:6:11: error: can't use ^VOLATILE I64 as ^I64
1+test/err/Volatile.raz:6:10: error: can't use ^VOLATILE I64 as ^I64
22 6 | q := p;
3- | ^
3+ | ^
44 raz: 1 error