Implement compound assignment operators for mutable constants

Fixes #943
This commit is contained in:
Rangi
2021-11-18 19:40:23 -05:00
committed by Eldred Habert
parent b76819792d
commit 8e2a164a32
7 changed files with 220 additions and 39 deletions

View File

@@ -1036,6 +1036,25 @@ COUNT = COUNT*2
Note that colons
.Ql \&:
following the name are not allowed.
.Pp
Mutable constants can be conveniently redefined by compound assignment operators like in C:
.Bl -column -offset indent "*= /= %="
.It Sy Operator Ta Sy Meaning
.It Li += -= Ta Compound plus/minus
.It Li *= /= %= Ta Compound multiply/divide/modulo
.It Li <<= >>= Ta Compound shift left/right
.It Li &= \&|= ^= Ta Compound and/or/xor
.El
.Pp
Examples:
.Bd -literal -offset indent
DEF x = 10
DEF x += 1 ; x == 11
DEF y = x - 1 ; y == 10
DEF y *= 2 ; y == 20
DEF y >>= 1 ; y == 10
DEF x ^= y ; x == 1
.Ed
.Ss Offset constants
The RS group of commands is a handy way of defining structure offsets:
.Bd -literal -offset indent