raz / commit ce8052e0

commit
ce8052e05453737a530fa1238b5b00a4c676d660
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
701be1bc
Diagnostics: say more of what went wrong

A missing end: an end left of its statement's line is noted, and a
procedure closed by the module's end says so; "else if" gets help
toward elsif. A type mismatch in an argument notes the parameter it
goes to. Procedure types print their signature; a procedure used as a
value says it returns nothing, or how to call it. + on strings, p.x
through a pointer, s.len, assigning a constant, 'ab' and Begin in the
wrong case each say what to write. can't read says why; can't find
module says where it looked. Long source lines are cut around the
place. Rt's trap report folds a recursion's repeated calls into one
line with a count.

patch · log

31 files changed, +347 -101

lib/Rt.raz (history) modified +47 -20

@@ -273,37 +273,64 @@
273273 end;
274274 end;
275275
276+(* Says that n more calls are as the one before, if there are any;
277+ the lines it takes *)
278+proc more(n: INT): INT;
279+begin
280+ if n = 0 then return 0; end;
281+ put(" and ");
282+ putInt(n);
283+ put(" more the same");
284+ say;
285+ return 1;
286+end;
287+
276288 (* Says the calls under way, a line each, from the one at address ip
277289 whose frame is at bp: where each is, and its variables, unless vars
278- is false for the first. At most 20; a frame that isn't the
279- program's ends them. *)
290+ is false for the first. At most 20 lines; a frame that isn't the
291+ program's ends them. Calls of one procedure from one place, as in a
292+ recursion that overflowed the stack, are told once, and counted. *)
280293 proc calls(ip, bp: UINT; vars: BOOL);
281-var p: ^Proc; l: ^Local; i, n: INT; q: ^UINT;
294+var p, last: ^Proc; l: ^Local; i, n, same: INT; q: ^UINT; lastIp: UINT;
282295 begin
283- for n := 1 to 20 do
296+ n := 0;
297+ same := 0;
298+ last := nil;
299+ lastIp := 0;
300+ while n < 20 do
284301 p := procAt(ip);
285- if p = nil then return; end;
286- put(" in ");
287- putStr(names() + INT(p^.name));
288- put(" at ");
289- where(ip);
290- l := ^Local(^U8(places + 5) + 16 * places[0] + 20 * places[3]) + INT(p^.first);
291- if not vars or (p^.count = 0) then DEC(lineLen, 2); end; (* where's ": " *)
292- for i := 0 to INT(p^.count) - 1 do
293- if vars then
294- if i > 0 then put(", "); end;
295- putStr(names() + INT(l[i].name));
296- put(" = ");
297- putValue(bp, l + i);
302+ if p = nil then break; end;
303+ if (p = last) and (ip = lastIp) then
304+ INC(same);
305+ else
306+ n := n + more(same);
307+ same := 0;
308+ last := p;
309+ lastIp := ip;
310+ put(" in ");
311+ putStr(names() + INT(p^.name));
312+ put(" at ");
313+ where(ip);
314+ l := ^Local(^U8(places + 5) + 16 * places[0] + 20 * places[3]) + INT(p^.first);
315+ if not vars or (p^.count = 0) then DEC(lineLen, 2); end; (* where's ": " *)
316+ for i := 0 to INT(p^.count) - 1 do
317+ if vars then
318+ if i > 0 then put(", "); end;
319+ putStr(names() + INT(l[i].name));
320+ put(" = ");
321+ putValue(bp, l + i);
322+ end;
298323 end;
324+ say;
325+ INC(n);
326+ vars := true;
299327 end;
300- say;
301- vars := true;
302328 q := ^UINT(bp);
303- if (bp & 7 # 0) or (q[0] <= bp) then return; end;
329+ if (bp & 7 # 0) or (q[0] <= bp) then break; end;
304330 ip := q[1] - 1; (* the call, by its return address *)
305331 bp := q[0];
306332 end;
333+ more(same);
307334 end;
308335
309336 (* Says on standard error the calls under way, from the one that calls

src/diag.pas modified +18 -4

@@ -168,8 +168,12 @@
168168 { "file:line:col: kind: msg", then the line with p underlined. A tab
169169 before p is copied into the underline, so that the two line up
170170 whatever the terminal makes of tabs. }
171+{ A long line is shown cut to this many bytes around the place, its
172+ cut ends marked ... }
173+const ShownBytes = 100;
174+
171175 procedure Show(const p: TPos; const kind, kindColour, msg: shortstring);
172-var line, start, stop, i, n: longint; buf: PChar; num, gutter: shortstring;
176+var line, start, stop, lo, hi, i, n: longint; buf: PChar; num, gutter: shortstring;
173177 begin
174178 Locate(p, line, start);
175179 buf := files[p.f].buf;
@@ -181,14 +185,24 @@
181185 num := IntStr(line);
182186 while length(num) < 5 do num := ' ' + num;
183187 gutter := Paint(Blue, num + ' |');
188+ lo := start; hi := stop;
189+ if hi - lo > ShownBytes then begin
190+ if p.a - lo > ShownBytes div 2 then lo := p.a - ShownBytes div 2;
191+ while (byte(buf[lo]) and $C0) = $80 do inc(lo);
192+ if hi - lo > ShownBytes then hi := lo + ShownBytes;
193+ while (hi < stop) and ((byte(buf[hi]) and $C0) = $80) do inc(hi);
194+ end;
184195 write(StdErr, gutter, ' ');
185- for i := start to stop - 1 do write(StdErr, buf[i]);
196+ if lo > start then write(StdErr, '...');
197+ for i := lo to hi - 1 do write(StdErr, buf[i]);
198+ if hi < stop then write(StdErr, '...');
186199 writeln(StdErr);
187200 write(StdErr, Paint(Blue, ' |'), ' ');
188- for i := start to p.a - 1 do
201+ if lo > start then write(StdErr, ' ');
202+ for i := lo to p.a - 1 do
189203 if buf[i] = #9 then write(StdErr, #9)
190204 else if (byte(buf[i]) and $C0) <> $80 then write(StdErr, ' ');
191- if p.b < stop then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, stop);
205+ if p.b < hi then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, hi);
192206 if n < 1 then n := 1;
193207 writeln(StdErr, Paint(kindColour, StringOfChar('^', n)));
194208 end;

src/item.pas modified +26 -4

@@ -411,6 +411,20 @@
411411 if x.ro then MarkAt(x.pos, Source(x.pos) + ' is ' + NameOf(x.obj^.module^.name) + '''s, and can''t be changed outside it');
412412 end;
413413
414+var
415+ passing: PObj; { the parameter the argument at passingAt goes to }
416+ passingAt: TPos;
417+
418+{ An error in x's type; if x is an argument, a note at the parameter
419+ it goes to. }
420+procedure Mismatch(const x: TItem; const msg: shortstring);
421+begin
422+ Error(x.pos, msg);
423+ if (passing <> nil) and (x.pos.f = passingAt.f) and (x.pos.a = passingAt.a) and (x.pos.b = passingAt.b) then
424+ Note(passing^.pos, 'it goes to ' + NameOf(passing^.name) + ', declared here');
425+ Fail;
426+end;
427+
414428 procedure Coerce(var x: TItem; t: PType);
415429 var s: PType; tmp: int64;
416430 begin
@@ -426,7 +440,7 @@
426440 CopyTo(FrameAdr(tmp), x.val);
427441 if t^.len > x.val then ZeroVar(FrameAdr(tmp + x.val), t^.len - x.val);
428442 TempItem(x, t, tmp);
429- end else MarkAt(x.pos, 'can''t use a string as ' + TypeName(t));
443+ end else Mismatch(x, 'can''t use a string as ' + TypeName(t));
430444 exit;
431445 end;
432446 if x.mode in [mType, mBuiltin, mNone, mCase] then NotValue(x);
@@ -447,8 +461,12 @@
447461 if x.odd then MarkAt(x.pos, 'can''t make a slice of a field of a packed record');
448462 Address(x);
449463 SliceOf(x, t, s^.len);
450- end else
451- MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t));
464+ end else if (x.mode = mProc) and (t^.form <> fProc) and (s^.base = nil) then
465+ MarkAt(x.pos, Source(x.pos) + ' is a procedure, and returns nothing')
466+ else if (x.mode = mProc) and (t^.form <> fProc) then
467+ MarkHelp(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t), 'to call it, write ' + Source(x.pos) + '()')
468+ else
469+ Mismatch(x, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t));
452470 end;
453471
454472 { Coerce where the types must be the same, as in a for loop, INC and
@@ -663,6 +681,8 @@
663681 SeqSlice(x)
664682 else if (op = sPlus) and (x.mode = mStr) then
665683 { two string constants to be joined: nothing to compute }
684+ else if (op = sPlus) and IsSeq(x.typ) then
685+ MarkHelp(x.pos, '+ doesn''t join ' + What(x), 'strings are joined in a Buf: Buf.str(b, s)')
666686 else if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then
667687 NotValue(x)
668688 else if x.mode <> mConst then
@@ -1070,11 +1090,13 @@
10701090 exit;
10711091 end;
10721092 c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar;
1093+ passing := p;
1094+ passingAt := a.pos;
10731095 if p^.isVar then begin
10741096 NotReadOnly(a);
10751097 if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable');
10761098 if a.odd then MarkAt(a.pos, 'a field of a packed record can''t be a var parameter');
1077- if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ) + ', found ' + What(a));
1099+ if not Same(a.typ, p^.typ) then Mismatch(a, 'a var parameter needs exactly ' + TypeName(p^.typ) + ', found ' + What(a));
10781100 if a.vol then MarkAt(a.pos, 'can''t pass through a volatile pointer to a var parameter');
10791101 Address(a);
10801102 s := AllocTemp(8, 8);

src/parse.pas modified +73 -19

@@ -87,6 +87,9 @@
8787 deferred: array[0..63] of TDeferred;
8888 numDeferred: longint;
8989 making: boolean; { reading an instance's arguments, at its first use }
90+ stray: boolean; { an "end" in this procedure stood left of its statement's line }
91+ strayAt: TPos; { ... the first such statement }
92+ elseIf: boolean; { an "else if" in this procedure }
9093 useAt: TPos; { ... which is here }
9194
9295 procedure Expression(var x: TItem; want: PType); forward;
@@ -110,6 +113,29 @@
110113 Next;
111114 end;
112115
116+{ The end of a block statement at start, whose line is indented to
117+ ind. An "end" left of that was most likely meant for a block around
118+ the statement, which leaves the statement's own "end" missing: the
119+ first such is kept for EndMissing. }
120+procedure CloseEnd(const start: TPos; ind: longint);
121+begin
122+ if (tok = sEnd) and not stray and (Indent < ind) then begin
123+ stray := true;
124+ strayAt := start;
125+ end;
126+ Expect(sEnd);
127+end;
128+
129+{ The error of a procedure or module whose own "end" isn't where it
130+ should be, with what CloseEnd saw }
131+procedure EndMissing(const p: TPos; const msg: shortstring);
132+begin
133+ Error(p, msg);
134+ if stray then Note(strayAt, 'is this statement''s "end" missing? one further left closes it');
135+ if elseIf then Help('raz writes elsif: "else if" begins an if that needs its own "end"');
136+ Fail;
137+end;
138+
113139 function Name(const s: shortstring): longint;
114140 begin
115141 Name := Intern(@s[1], length(s));
@@ -305,6 +331,7 @@
305331 Error(p, NameOf(n) + ' isn''t declared');
306332 if ModuleFile(n, dir, f) then Help(NameOf(n) + ' is a module: import ' + NameOf(n))
307333 else if (NameOf(n) = 'elif') or (NameOf(n) = 'elseif') then Help('raz writes elsif')
334+ else if Reserved(Name(LowerCase(NameOf(n)))) then Help('a reserved word is written in lower case: ' + LowerCase(NameOf(n)))
308335 else DidYouMean(Closest(n, -1));
309336 end;
310337
@@ -824,6 +851,20 @@
824851 end else if f <> nil then MarkAt(at, NameOf(c^.name) + ' needs its fields');
825852 end;
826853
854+{ x, before ".", has no fields; tok is what follows. Other languages
855+ write p.f through a pointer and s.len for a length. }
856+procedure FieldOfWhat(const x: TItem);
857+var msg, f: shortstring;
858+begin
859+ msg := 'expected a record, found ' + What(x);
860+ if tok = sIdent then f := NameOf(id) else f := '';
861+ if (x.typ^.form = fPtr) and (x.typ^.base^.form = fRecord) then
862+ MarkHelp(x.pos, msg, 'through a pointer, write ' + Source(x.pos) + '^.' + f)
863+ else if (x.typ^.form in [fArray, fSlice]) and ((f = 'len') or (f = 'length') or (f = 'size') or (f = 'count')) then
864+ MarkHelp(x.pos, msg, 'its length is LEN(' + Source(x.pos) + ')');
865+ MarkAt(x.pos, msg);
866+end;
867+
827868 { A designator, with any selectors and calls after it. called tells
828869 whether the last thing done was a call. }
829870 procedure Designator(var x: TItem; var called: boolean);
@@ -845,7 +886,7 @@
845886 case tok of
846887 sPeriod: begin
847888 Next;
848- if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'expected a record, found ' + What(x));
889+ if (x.mode <> mVar) or (x.typ^.form <> fRecord) then FieldOfWhat(x);
849890 if tok <> sIdent then Expected('a field');
850891 f := FieldOf(x.typ);
851892 Next;
@@ -1154,7 +1195,7 @@
11541195 for i := numDefers - 1 downto base do RunDefer(defers[i]);
11551196 end;
11561197
1157-procedure IfStatement;
1198+procedure IfStatement(const start: TPos; ind: longint);
11581199 var x: TItem; L, endL: longint;
11591200 begin
11601201 Next;
@@ -1178,13 +1219,14 @@
11781219 Jump(endL);
11791220 Fix(L);
11801221 Next;
1222+ if tok = sIf then elseIf := true;
11811223 Statements;
11821224 end else Fix(L);
1183- Expect(sEnd);
1225+ CloseEnd(start, ind);
11841226 Fix(endL);
11851227 end;
11861228
1187-procedure WhileStatement;
1229+procedure WhileStatement(const start: TPos; ind: longint);
11881230 var x: TItem; top, L: longint; lp: TLoop; old: PLoop;
11891231 begin
11901232 Next;
@@ -1196,7 +1238,7 @@
11961238 Loop(lp, old);
11971239 Statements;
11981240 JumpBack(top);
1199- Expect(sEnd);
1241+ CloseEnd(start, ind);
12001242 Fix(L);
12011243 Fix(lp.brk);
12021244 curLoop := old;
@@ -1218,7 +1260,7 @@
12181260 Fix(lp.brk);
12191261 end;
12201262
1221-procedure ForStatement;
1263+procedure ForStatement(const start: TPos; ind: longint);
12221264 var
12231265 o: PObj; v, a, b, s: TItem; bslot, step: int64; top, exitL: longint;
12241266 lp: TLoop; old: PLoop;
@@ -1260,7 +1302,7 @@
12601302 Loop(lp, old);
12611303 Statements;
12621304 curLoop := old;
1263- Expect(sEnd);
1305+ CloseEnd(start, ind);
12641306 ForNext(o, bslot, step, exitL, top);
12651307 Fix(exitL);
12661308 Fix(lp.brk);
@@ -1319,7 +1361,7 @@
13191361 Fix(L);
13201362 end;
13211363
1322-procedure MatchStatement;
1364+procedure MatchStatement(const start: TPos; ind: longint);
13231365 var
13241366 x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n: longint;
13251367 seen: array[0..255] of boolean; hasElse: boolean; endAt: TPos; ls: TLabels;
@@ -1383,7 +1425,7 @@
13831425 end;
13841426 end;
13851427 endAt := TokPos;
1386- Expect(sEnd);
1428+ CloseEnd(start, ind);
13871429 if (t^.form = fInt) and not hasElse then
13881430 MarkHelp(endAt, 'a match on an integer needs an else arm', 'it may be empty: | else:');
13891431 if not hasElse then begin
@@ -1409,6 +1451,8 @@
14091451 array constant, nor any part of one. }
14101452 procedure Assignable(const x: TItem; n: longint);
14111453 begin
1454+ if (x.mode = mConst) and (Subject(x, n) = NameOf(n)) then
1455+ MarkAt(x.pos, NameOf(n) + ' is a constant, and can''t be changed');
14121456 if (x.mode = mVar) and (x.obj <> nil) and (x.obj^.cls = oConst) then
14131457 MarkAt(x.pos, NameOf(x.obj^.name) + ' is a constant, and can''t be changed');
14141458 if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, n));
@@ -1532,11 +1576,11 @@
15321576 else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement');
15331577 end else Discard(x);
15341578 end;
1535- sIf: IfStatement;
1536- sWhile: WhileStatement;
1579+ sIf: IfStatement(start, Indent);
1580+ sWhile: WhileStatement(start, Indent);
15371581 sRepeat: RepeatStatement;
1538- sFor: ForStatement;
1539- sMatch: MatchStatement;
1582+ sFor: ForStatement(start, Indent);
1583+ sMatch: MatchStatement(start, Indent);
15401584 sReturn: begin
15411585 Next;
15421586 if deferring then MarkAt(SpanFrom(start), 'return can''t leave a deferred statement');
@@ -1567,7 +1611,7 @@
15671611 Jump(curLoop^.brk);
15681612 end;
15691613 sDefer: Defer;
1570- else if AtLineStart then Expected('"end"')
1614+ else if AtLineStart then EndMissing(MissingPos, 'expected "end", found ' + Found)
15711615 else Expected('a statement');
15721616 end;
15731617 ReleaseTemps(m);
@@ -1691,6 +1735,7 @@
16911735 old := curResult;
16921736 curResult := sig^.base;
16931737 EnterBody(p^.chunk, line);
1738+ stray := false; elseIf := false;
16941739 Statements;
16951740 NoteLine(CurLine, CurCol);
16961741 Expect(sEnd);
@@ -1762,7 +1807,8 @@
17621807 CodeBody(p, sig, at);
17631808 end else if checkMode then SkipBody else Body(p, sig, line);
17641809 if tok = sIdent then begin
1765- if id <> n then Mark('expected ' + NameOf(n) + ', found ' + NameOf(id));
1810+ if id = curModule^.name then EndMissing(TokPos, NameOf(n) + ' has no "end": this one closes the module')
1811+ else if id <> n then EndMissing(TokPos, 'expected ' + NameOf(n) + ', found ' + NameOf(id));
17661812 Next;
17671813 end;
17681814 end;
@@ -2188,14 +2234,15 @@
21882234 st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint;
21892235 oldMod: PModule; oldCheck, oldChecks: boolean; m: PModule;
21902236 lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs;
2191- generic: boolean; argsAt: TScanState;
2237+ generic: boolean; argsAt: TScanState; why: shortstring;
21922238 begin
21932239 SaveScan(st);
21942240 SaveScopes(d, saved);
21952241 oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks;
21962242 checks := true;
21972243 curFile := Name(path);
2198- if not Open(path) then Fatal('can''t read ' + path);
2244+ why := Open(path);
2245+ if why <> '' then Fatal('can''t read ' + path + ': ' + why);
21992246 New(m);
22002247 FillChar(m^, SizeOf(TModule), 0);
22012248 m^.name := n;
@@ -2298,13 +2345,14 @@
22982345 deferSlot := 0;
22992346 curResult := nil;
23002347 EnterBody(body, line);
2348+ stray := false; elseIf := false;
23012349 Statements;
23022350 NoteLine(CurLine, CurCol);
23032351 Expect(sEnd);
23042352 EndProc(body);
23052353 end;
23062354 end else Expect(sEnd);
2307- if (tok <> sIdent) or (id <> n) then Expected(NameOf(n));
2355+ if (tok <> sIdent) or (id <> n) then EndMissing(MissingPos, 'expected ' + NameOf(n) + ', found ' + Found);
23082356 Next;
23092357 if tok <> sPeriod then Expected('"."');
23102358 o := m^.first;
@@ -2445,7 +2493,13 @@
24452493 if m <> nil then exit(m);
24462494 for i := 0 to numPending - 1 do
24472495 if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself');
2448- if not ModuleFile(name, dir, f) then MarkAt(args.at, 'can''t find module ' + NameOf(name));
2496+ if not ModuleFile(name, dir, f) then begin
2497+ Error(args.at, 'can''t find module ' + NameOf(name));
2498+ dir := ShownPath(SearchDir(-1));
2499+ for i := 0 to numInc do dir := dir + ', ' + ShownPath(SearchDir(i));
2500+ Help('looked for ' + NameOf(name) + '.raz in ' + dir);
2501+ Fail;
2502+ end;
24492503 CheckOneModule(name, dir, f, args.at);
24502504 m := CompileFile(dir + '/' + f, name, args, false);
24512505 CheckSiblings(dir, f, name, m, args);

src/scan.pas modified +37 -8

@@ -65,13 +65,15 @@
6565
6666 function Intern(p: PChar; n: longint): longint;
6767 function NameOf(n: longint): shortstring;
68-function Open(const path: shortstring): boolean;
68+function Reserved(n: longint): boolean;
69+function Open(const path: shortstring): shortstring;
6970 procedure Next;
7071 procedure Mark(const msg: shortstring);
7172 procedure MarkAt(const p: TPos; const msg: shortstring);
7273 procedure MarkHelp(const p: TPos; const msg, hint: shortstring);
7374 procedure Fail;
7475 function AtLineStart: boolean;
76+function Indent: longint;
7577 function SymText(s: TSym): shortstring;
7678 function Found: shortstring;
7779
@@ -334,16 +336,37 @@
334336 AtLineStart := cur.tokPos = cur.tokLineStart;
335337 end;
336338
339+{ The column the current symbol's line is indented to }
340+function Indent: longint;
341+var i: longint;
342+begin
343+ i := cur.tokLineStart;
344+ while cur.buf[i] in [' ', #9] do inc(i);
345+ Indent := i - cur.tokLineStart + 1;
346+end;
347+
337348 { Files }
338349
339-function Open(const path: shortstring): boolean;
350+{ Name n is a reserved word }
351+function Reserved(n: longint): boolean;
352+begin
353+ Reserved := n < NumWords;
354+end;
355+
356+{ Reads the file at path to scan it; '' if it can, else why not }
357+function Open(const path: shortstring): shortstring;
340358 var fd: cint; st: Stat; n, got, r: longint; p: shortstring;
341359 begin
342360 p := path + #0;
343361 fd := FpOpen(@p[1], O_RDONLY);
344- if fd < 0 then exit(false);
345- if FpFStat(fd, st) <> 0 then begin FpClose(fd); exit(false) end;
346- if (st.st_mode and S_IFMT) <> S_IFREG then begin FpClose(fd); exit(false) end;
362+ if fd < 0 then
363+ case FpGetErrno of
364+ ESysENOENT: exit('there is no such file');
365+ ESysEACCES: exit('permission denied');
366+ else exit('it can''t be opened');
367+ end;
368+ if FpFStat(fd, st) <> 0 then begin FpClose(fd); exit('it can''t be opened') end;
369+ if (st.st_mode and S_IFMT) <> S_IFREG then begin FpClose(fd); exit('it isn''t a file') end;
347370 n := st.st_size;
348371 cur.buf := GetMem(n + 1);
349372 got := 0;
@@ -362,7 +385,7 @@
362385 cur.tokLine := 1;
363386 cur.tokLineStart := 0;
364387 cur.f := AddFile(path, cur.buf, n);
365- Open := true;
388+ Open := '';
366389 end;
367390
368391 procedure SaveScan(var st: TScanState);
@@ -724,7 +747,7 @@
724747 end;
725748
726749 procedure Next;
727-var c: char; start, h, v: longint;
750+var c: char; start, h, v, i: longint;
728751 begin
729752 cur.prevEnd := cur.pos;
730753 repeat
@@ -758,7 +781,13 @@
758781 inc(cur.pos);
759782 if cur.buf[cur.pos] = '''' then LexError('empty character');
760783 v := LitChar(false);
761- if cur.buf[cur.pos] <> '''' then LexError('character not closed');
784+ if cur.buf[cur.pos] <> '''' then begin
785+ { 'ab': several characters, as some languages write a string }
786+ i := cur.pos;
787+ while not (cur.buf[i] in ['''', #10, #0]) do inc(i);
788+ if cur.buf[i] = '''' then MarkBytes(cur.tokPos, i + 1, 'a character is one character: the string is "' + Text(cur.tokPos + 1, i) + '"')
789+ else LexError('character not closed');
790+ end;
762791 inc(cur.pos);
763792 tok := sChar;
764793 ival := v;

src/sym.pas modified +13 -1

@@ -466,7 +466,19 @@
466466 TypeName := s + ')';
467467 end;
468468 fVariant: TypeName := 'variant';
469- fProc: TypeName := 'proc';
469+ fProc: begin
470+ s := 'proc(';
471+ f := t^.fields;
472+ while f <> nil do begin
473+ if f^.isVar then s := s + 'var ';
474+ s := s + TypeName(f^.typ);
475+ f := f^.next;
476+ if f <> nil then s := s + ', ';
477+ end;
478+ s := s + ')';
479+ if t^.base <> nil then s := s + ': ' + TypeName(t^.base);
480+ TypeName := s;
481+ end;
470482 else TypeName := '?';
471483 end;
472484 end;

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

@@ -1,4 +1,4 @@
11 test/err/DeclManyElements.raz:5:2059: error: more than 1024 elements
2- 5 | a := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64 end;
3- | ^^^
2+ 2 | ...a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64 end;
3+ | ^^^
44 raz: 1 error

test/err/ExprJoinStrings.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+test/err/ExprJoinStrings.raz:7:13: error: + doesn't join []U8
2+ 7 | Out.str(s + "def");
3+ | ^
4+help: strings are joined in a Buf: Buf.str(b, s)
5+raz: 1 error

test/err/ExprJoinStrings.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module ExprJoinStrings;
2+import Out;
3+proc main*;
4+var s: []U8;
5+begin
6+ s := "abc";
7+ Out.str(s + "def");
8+end;
9+end ExprJoinStrings.

test/err/ExprNoField.err (history) added +9 -0

@@ -0,0 +1,9 @@
1+test/err/ExprNoField.raz:7:10: error: expected a record, found ^R
2+ 7 | n := p.x;
3+ | ^
4+help: through a pointer, write p^.x
5+test/err/ExprNoField.raz:8:10: error: expected a record, found []U8
6+ 8 | n := s.len;
7+ | ^
8+help: its length is LEN(s)
9+raz: 2 errors

test/err/ExprNoField.raz (history) added +10 -0

@@ -0,0 +1,10 @@
1+module ExprNoField;
2+type R = record x: I64; end;
3+proc main*;
4+var r: R; p: ^R; s: []U8; n: I64;
5+begin
6+ p := ADR(r);
7+ n := p.x;
8+ n := s.len;
9+end;
10+end ExprNoField.

test/err/ExprProcValue.err (history) added +8 -0

@@ -0,0 +1,8 @@
1+test/err/ExprProcValue.raz:10:10: error: Out.ln is a procedure, and returns nothing
2+ 10 | a := Out.ln;
3+ | ^^^^^^
4+test/err/ExprProcValue.raz:11:10: error: can't use proc(): (I64, I64) as I64
5+ 11 | a := pair;
6+ | ^^^^
7+help: to call it, write pair()
8+raz: 2 errors

test/err/ExprProcValue.raz (history) added +13 -0

@@ -0,0 +1,13 @@
1+module ExprProcValue;
2+import Out;
3+proc pair: (I64, I64);
4+begin
5+ return 1, 2;
6+end;
7+proc main*;
8+var a: I64;
9+begin
10+ a := Out.ln;
11+ a := pair;
12+end;
13+end ExprProcValue.

test/err/NameKeywordCase.err (history) added +9 -0

@@ -0,0 +1,9 @@
1+test/err/NameKeywordCase.raz:7:5: error: Begin isn't declared
2+ 7 | Begin
3+ | ^^^^^
4+help: a reserved word is written in lower case: begin
5+test/err/NameKeywordCase.raz:9:1: error: End isn't declared
6+ 9 | End;
7+ | ^^^
8+help: a reserved word is written in lower case: end
9+raz: 2 errors

test/err/NameKeywordCase.raz (history) added +10 -0

@@ -0,0 +1,10 @@
1+module NameKeywordCase;
2+import Out;
3+proc main*;
4+var a: I64;
5+begin
6+ a := 1;
7+ Begin
8+ Out.int(a);
9+End;
10+end NameKeywordCase.

test/err/StmtElseIf.err (history) added +8 -0

@@ -0,0 +1,8 @@
1+test/err/StmtElseIf.raz:12:5: error: main has no "end": this one closes the module
2+ 12 | end StmtElseIf.
3+ | ^^^^^^^^^^
4+test/err/StmtElseIf.raz:6:5: note: is this statement's "end" missing? one further left closes it
5+ 6 | if x > 0 then
6+ | ^^
7+help: raz writes elsif: "else if" begins an if that needs its own "end"
8+raz: 1 error

test/err/StmtElseIf.raz (history) added +12 -0

@@ -0,0 +1,12 @@
1+module StmtElseIf;
2+import Out;
3+proc main*;
4+var x: I64;
5+begin
6+ if x > 0 then
7+ Out.ln;
8+ else if x < 0 then
9+ Out.ln;
10+ end;
11+end;
12+end StmtElseIf.

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

@@ -0,0 +1,7 @@
1+test/err/StmtEndMissing.raz:9:5: error: main has no "end": this one closes the module
2+ 9 | end StmtEndMissing.
3+ | ^^^^^^^^^^^^^^
4+test/err/StmtEndMissing.raz:6:5: note: is this statement's "end" missing? one further left closes it
5+ 6 | if x > 0 then
6+ | ^^
7+raz: 1 error

test/err/StmtEndMissing.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module StmtEndMissing;
2+import Out;
3+proc main*;
4+var x: I64;
5+begin
6+ if x > 0 then
7+ Out.int(x);
8+end;
9+end StmtEndMissing.

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

@@ -1,4 +1,4 @@
11 test/err/StmtManyDefers.raz:9:173: error: more than 64 deferred statements in one procedure
2- 9 | defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1;
3- | ^^^^^
2+ 9 | ...a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1;
3+ | ^^^^^
44 raz: 1 error

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

@@ -1,4 +1,4 @@
11 test/err/StmtManyNames.raz:2:315: error: more than 64 names in one declaration
2- 2 | var a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64;
3- | ^^^
2+ 2 | ...a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64;
3+ | ^^^
44 raz: 1 error

test/msg/AtArgType.err (history) modified +3 -0

@@ -1,4 +1,7 @@
11 conform/err/AtArgType.raz:7:8: error: can't use BOOL as I64
22 7 | Id(b);
33 | ^
4+conform/err/AtArgType.raz:2:9: note: it goes to a, declared here
5+ 2 | proc Id(a: I64): I64;
6+ | ^
47 raz: 1 error

test/msg/AtPCantAssign.err (history) modified +1 -1

@@ -1,4 +1,4 @@
1-conform/err/AtPCantAssign.raz:7:8: error: can't assign to k
1+conform/err/AtPCantAssign.raz:7:8: error: k is a constant, and can't be changed
22 7 | a, k := two();
33 | ^
44 raz: 1 error

test/msg/GenVarExact.err (history) modified +3 -0

@@ -1,4 +1,7 @@
11 conform/err/GenVarExact.raz:6:7: error: a var parameter needs exactly I64, found I32
22 6 | P(x);
33 | ^
4+conform/err/GenVarExact.raz:2:12: note: it goes to a, declared here
5+ 2 | proc P(var a: I64); begin end;
6+ | ^
47 raz: 1 error

test/msg/ScanCharOpen.err (history) modified +2 -2

@@ -1,4 +1,4 @@
1-conform/err/ScanCharOpen.raz:5:10: error: character not closed
1+conform/err/ScanCharOpen.raz:5:10: error: a character is one character: the string is "ab"
22 5 | c := 'ab';
3- | ^^
3+ | ^^^^
44 raz: 1 error

test/msg/StmtAssignConst.err (history) modified +1 -1

@@ -1,4 +1,4 @@
1-conform/err/StmtAssignConst.raz:5:5: error: can't assign to k
1+conform/err/StmtAssignConst.raz:5:5: error: k is a constant, and can't be changed
22 5 | k := 2;
33 | ^
44 raz: 1 error

test/msg/StmtNoModule.err (history) modified +1 -0

@@ -1,4 +1,5 @@
11 conform/err/StmtNoModule.raz:2:8: error: can't find module Nothing
22 2 | import Nothing;
33 | ^^^^^^^
4+help: looked for Nothing.raz in conform/err, conform/err/mods, lib
45 raz: 1 error

test/run/StackOverflow.stderr (history) modified +1 -14

@@ -1,18 +1,5 @@
11 test/run/StackOverflow.raz:7:1: stopped by a stack overflow
22 in StackOverflow.down at test/run/StackOverflow.raz:7:1
33 in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 14
4- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 13
5- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 12
6- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 11
7- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 10
8- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 9
9- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 8
10- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 7
11- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 6
12- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 5
13- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 4
14- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 3
15- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 2
16- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 1
17- in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 0
4+ and 14 more the same
185 in StackOverflow.main at test/run/StackOverflow.raz:16:5

test/run/ThreadOverflow.stderr (history) modified +3 -18

@@ -1,21 +1,6 @@
11 test/run/ThreadOverflow.raz:6:1: stopped by a stack overflow
22 in ThreadOverflow.down at test/run/ThreadOverflow.raz:6:1
33 in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1926
4- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1925
5- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1924
6- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1923
7- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1922
8- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1921
9- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1920
10- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1919
11- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1918
12- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1917
13- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1916
14- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1915
15- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1914
16- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1913
17- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1912
18- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1911
19- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1910
20- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1909
21- in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1908
4+ and 1926 more the same
5+ in ThreadOverflow.work at test/run/ThreadOverflow.raz:15:5: _arg = nil
6+ in Thread.run at lib/Thread.linux-x86_64.raz:78:5: arg = 0x?, t = 0x?

test/scantest.pas modified +1 -1

@@ -4,7 +4,7 @@
44 uses diag, scan;
55 var i: longint;
66 begin
7- if not Open(ParamStr(1)) then Fatal('no file');
7+ if Open(ParamStr(1)) <> '' then Fatal('no file');
88 repeat
99 Next;
1010 write(LineOf(TokPos), ':', TokPos.a, ' ', ord(tok));