Gregofi / camel

Custom dynamic programming language
MIT License
6 stars 1 forks source link

Better error messages #39

Closed Gregofi closed 2 years ago

Gregofi commented 2 years ago

Currently, the interpreter often prints not very helpful error messages like wrong data types for operator. Make the error messages better

For example

Runtime error; 15:18: Wrong types for operator `&&`, expected boolean, got int
if (is_even(x) && x) {
                  ^

Suggestion: Try x != 0

This would be ideal, but anything better that what is there currently is fine. At the very least the location and line should be printed.

This will require passing the source file to the VM, and also a array of every instruction index corresponding to a place in the source code. Only character index in the file should be passed (not line and column). The VM will then open the file and find it manually. This can be slow but it is not a concern, since it'll happen only when error happens.