Issue #14: More, better error messages
Summary
Topics: New verifier and Compilation with Clang 5
This week resulted in almost nothing new being introduced into the VM code base, at least from the user's point of view. On the back end, however, the VM has received some pretty substantial improvements.
New verifier is now on the devel
branch (the parts that were ready to be deployed, that is),
Clang 5 target has been added to the CI build matrix, and the Makefile Viua uses is now shorter (and
hopefully easier to understand and maintain).
New verifier
The new verifier is now used for the majority of basic, pre-SA verification of assembler's input ( the source code that is to be turned into Viua bytecode).
Compared with the old, token-based verifier the new one does not add much yet; it is an almost one-to-one port to the parsed-source-based pipeline. The switch away from primitive, token-based analysis without any preprocessing of input (even the most rudimentary parsing) yields small but visible profits, though. Mostly in the quality-of-life department.
"Blue" notes
If you have written anything for Viua, it is highly probable that you made an error once, and the assembler complained about it to you. For example:
sample/asm/errors/global_rs_used_in_lib.asm:21:10: error: global register set used by a library function
sample/asm/errors/global_rs_used_in_lib.asm:21:10: note: library functions may only use 'local' and 'static' register sets
19
20 .function: foo/0
>>>> 21 ress global
^~~~~~
22 return
23 .end
sample/asm/errors/global_rs_used_in_lib.asm:20:12: error: in function foo/0
18 ;
19
>>>> 20 .function: foo/0
^~~~~
21 ress global
22 return
Notice the note:
line.
This is the new element.
Errors from the assembler may now include notes. Note that notes are not "hints"; the assembler is not playing with you by "hinting" and making you guess what triggered the error. These are additional information that it provides in an attempt to better communicate what it expected at a given location, what caused it to throw the error, etc.
The end goal is to convert into notes and errors as much of the assembler's knowledge and assumptions as reasonably possible to provide precise error traces, and not only tell what triggered the error, but also to explain how the assembler came to the conclusion that an error should be triggered.
Aside notes
Aside notes are another addition to the assembler's arsenal when it comes to generating error messages.
They are "educated guesses" about what would be a fix to the error, or extra gobbets of information that the assembler has but
which fit neither the error:
nor note:
lines, and are best provided in the immediate context of the
source code listing.
bar.asm:2:5: error: unknown instruction
1 .function: main/0
>>>> 2 iztore %1 local 42
^~~~~~
^ did you mean 'istore'?
3
bar.asm:1:12: error: in function main/0
>>>> 1 .function: main/0
^~~~~~
2 iztore %1 local 42
3
Compilation with Clang 5
Quick news: Viua is now compiled with Clang 5 (the next major version of the Clang compiler) on Travis CI. This means that the code is now compiled by three different compiler versions: GCC 7, Clang 4, and Clang 5. More will versions be added as they become available in Ubuntu PPAs that can be used on Travis.