Constructor instruction naming is now more consistent. The work on giving Viua reliable arithmetic is resumed.
Renamed constructor instructions
Some constructor instructions (i.e. instructions that create completely new values, instead of modifying existing ones, or making modified copies) were renamed to better express what they do, and to make the naming consistent. Now all constructors are spelled as nouns naming the value they create.
The following instructions were renamed:
Resumed work on the implementation of arithmetic
Delayed for quite some time, work on the implementation of arithmetic was resumed this week. Static analyser gained support for arithmetic instructions, and new tests for them were written.
However, implementing arithmetic takes time. Both signed and unsigned types must be considered, and then there are several variants of arithmetic.
Wrapping arithmetic is the usual kind used when
programming. When your value goes "out of range", you get overflow and
the value is reduced modulo 2N where N is the width of the
integer (which effectively means that only the n least-significant
bits are actually used to store the result).
This type of arithmetic has its uses, and is what you typically expect when coming from a C or C++ background.
Checked arithmetic works like you expect it to;
2 plus 2 still gives four, but (assuming unsigned integers are used) 255 plus
1 does not wrap to zero but throws an exception.
This kind of arithmetic is useful when you need to stay in range no matter what happens and you need to be notified when you would venture into the land of wraparound if not for the overflow checks performed by checked arithmetic.
Saturating arithmetic ensures that you stay in range, but
does not throw exceptions when you would go out of it - the value simply becomes
For example (assuming 8 bit unsigned integers) 253 + 8 gives 255 as 255 is the
maximum representable value; similarly, 4 - 8 does not produce wraparound, it simply
Saturating arithmetic is useful when "clipping" values is preferable to getting bogus results, e.g. increasing audio volume using the analog knob should not, after some time, result in the audio being muted - it should just reach the maximum level and stop increasing.
Expanding arithmetic is the "natural" one. In contrast to the previous three kinds it does not operate on fixed-size integers. Under expanding arithmetic there is no wraparound, no saturation, and no "out of range" errors - values just grow as needed and the range of representable integers is limited only be the memory available to the program. In practice, though, Viua is expected to be able to handle numbers that can be represented using 264 binary digits (which still gives you plenty of wiggle room for fancy calculations).