One of the features I had been meaning to get around to for some time was improvements to the logging. The original system had one enum value per error. It gets quite tedious pretty quickly when you have to write out redundant messages with only a single word changed. Since it would be nice to have the messages be localized (i.e. translated into different languages), I used an enum, but obviously, I needed to shorten the process.
The result of my long evening of work was a rewrite of part of the logging system that resulting in an easily extensible interface for which I created pretty print logging (which you can see in the feature image of this post).
The implementation involves passing a struct to the print function. Since it’s one argument, I never have to worry about changing the print function. On the other hand, it can be tedious to instantiate a struct. To make it simpler, I used builder notation to construct the components before passing. I’ll admit that – while it certainly made the job easy – it bloated some of the code and made things harder to read in short methods. I would have a 4+ line readable print call where I used to have a 1-liner, thereby dwarfing the 1-2 other operations going on in the same region. Oh well. On the bright side, I did stumble on a bug or two that went unnoticed for awhile. (Nothing that would crash, but certainly not wanted.)
Finally, I was able to finish converting the remaining text logging messages (mostly for the new functions like math) to enum value logging messages.
Also related to the logging functionality: Printing function bodies for debugging! I have now added the optional ability to the engine to print tokens as they are compiled, thereby improving the user’s ability to debug the code. It currently prints the entirety of the function’s execution body upon compilation, so no runtime error debugging. I considered the latter, but by that time, the execution body is now a bunch of opcodes, which are meaningless to the user.
Given how easy it was to implement this new debugging tool, I’m starting to wonder if there are other useful debugging tools I can add to the current system. Even though – after programming a full application with it – Copper turned out to be really easy to debug, debugging is still one of those holes I’d really like to fill in as best as I can.
Regarding other fixes: Strings now check for being assigned to themselves. No more accidentally deleting themselves before assignment.