After a few months of break, over the last week or so I finally had some time to work on my pet programming language #Rocket again.
My main goal was to fix a bug that prevented some built-in types (ints, booleans, ...) from being used as instances of a protocol (as in #Python - think interfaces in #Java, traits in #Rust or ...). The reason was that for these types I didn't have any runtime type info. If they were stored in a variable (or function parameter) of type `MyProtocol` that was that - there was no more information on the type except just that: It implements the protocol `MyProtocol`. No way of knowing the actual type or finding the implementation of the methods required by the protocol.
So I had to refactor how ints and booleans were represented internally. As you can imagine, that's a change quite deep in the language. It affected arrays (which store their length - an integer), strings (which under the hood ultimately are arrays of integers) and some other stuff. Changing the representation of booleans required adjustments in parts of the language that deal with booleans: lazily evaluating logical `and`s and `or`s, `if` statements, `while` loops, etc.
Anyway, after the refactoring I think the code is a bit cleaner. And once I had this, fixing the bug was literally a two line change (plus imports and tests).
Also found and fixed another bug: When importing two submodules of the same top-level module (e.g. `import mymodule.submodule_1; import mymodule.submodule_2`) the second import statement used to fail because the name `mymodule` already existed (was already taken) in the code doing the imports (it was created by the first import statement).
And then there was a third bug I introduced in the refactoring of the representation of ints. It lead to `-some_unsigned_int` to be treated as another unsigned int (rather than a signed one) in some regards. My test case converting `-9223372036854775808` (the minimum value a signed 64 bit integer can hold) to a string caught it.
On a side node: I'm so grateful I started writing lots of test cases for this project. The amount of bugs they've caught that would have gone unnoticed otherwise is worth a million. Always write test cases if you care about your software.
