Issue #9: Fixes. And more fixes.
Summary
Topics:
make_unique()
- Bits in Boolean context
- All-zero bit string literals
and Register set specifiers in assembler and disassembler
This week was spent on bug fixes, and enhancing memory tightness of the core VM.
make_unique()
There were many places in the VM where the following construction was used:
It was unfortunate, since this construction can lead to memory leaks if an exception is thrown
between the construction of new viua::something::Something
and
the moment it becomes guarded by the unique_ptr
.
Viua strives to correctly manage its memory, and account for every resource it allocates, so this
was clearly unacceptable.
The solution came in the form of std::make_unique()
.
This function safely allocates memory, constructs an object, and wraps it in a unique_ptr
.
It also leads to shorter code and less repetition:
Bits in Boolean context
An embarrassing omission managed to slip past tests: bit strings always evaluated to false when used a Boolean values. This obviously incorrect behaviour was fixed. Bit strings containing at least one enabled bit evaluate to true, bit strings with all zeroes evaluate to false.
All-zero bit string literals
Another bug managed to sneak into the assembler: literal bit strings that were all zeroes were reduced to zero-width strings. This is fixed now, and literal all-zero bit strings are (correctly) reduced to one-zero strings. Examples:
After stripping leading zeroes the width of the literal bit string is expanded to the nearest multiple of 8. This behaviour did not change.
Register set specifiers in assembler and disassembler
Disassembly was fixed for if
, streq
, insert
, and remove
instructions.
Their target registers were not disassembled with register set specifiers, which could change the meaning of the program being
disassembled.
The if
instruction also did not support register set specifiers in source code at all.
This is now fixed.
Next: #10: Binary arithmetic
Previous: #8: Bit manipulation