That is rather neat. It beats ( 1<<13 | 1<<14 | 1<<15 ) for conciseness, and even more readable as long as one recognises the curly braces as bit numbers. I assume the use of SET to define bits and the use of SET in IOSET is just coincidental. I could imagine a different architecture with LPC.IOCLR, { 13..15 } or similar
Exactly. IOSET is the name used in the LPC2xxx microcontroller manual. The Blinker example module has a constant declaration:
CONST
(* led(s) connected to pin P0.13, P0.14 and P0.15 *)
ledBits = {13..15};
... and an infinite main loop:
WHILE TRUE DO
SYSTEM.PUT(LPC.IOCLR, ledBits);
Timer.MSecDelay(500);
SYSTEM.PUT(LPC.IOSET, ledBits);
Timer.MSecDelay(500)
END
IOCLR and IOSET are absolute memory addresses declared as constants in a separate, imported, LPC module:
IOSET* = 0E0028004H;
IODIR* = 0E0028008H;
IOCLR* = 0E002800CH;
The asterisk indicates that the values are exported from the module.
This is a great notation, I'm very interested in adopting this into the IPL grammar. This is exactly the kind of hardware "friendly" stuff I've been seeking, stuff that helps in real life problems, pragmatic. In IPL (taken from PL/I) there are "bit strings", arbitrary length sequences of bits (either aligned or not) that could be manipulated by this "set" notation, it's very attractive.
There's no reason too, why one could not have this arbitrarily defined, no need to be concerned that it's 32 bits or 64 or anything:
dcl interrupt_control bit(45); // usual PL/I syntax
interrupt_control = {}; // set all bits OFF
interrupt_control = {0..4,19..30}; // Wirthian notation
IPL does not yet use { or } or .. either and so this is pretty straightforward to add to the grammar, it seems to me that this is primarily a notation, its implementation, semantics are relatively simple.
I have questions though, look:
flags = {0..5, 7..9};
That effectively sets bits 0, 1, 2, 3, 4, 5 and 7, 8, 9 to "on". How would I express "turn off bit 3 in flags"?
flags = flags - {3};
would that be it? (in Oberon anyway).
PL/I and Imperium too, support the ability to access a "bit string" via a subscript:
dcl control_reg bit(32);
control_reg = get_reg(X);
control_reg(4) = ON;
control_reg(19) = ON;
control_reg(28) = OFF;
But setting several ON/OFF at once isn't really supported, there's no short notation for it anyway.
With Wirth's notation we could code:
dcl control_reg bit(32);
control_reg = get_reg(X);
control_reg = control_reg + {4,19} - {28};
So I'm seeing this as an additional notation for setting and unsetting bits, not a change or alternative way to implement bit strings (as they are termed) but a very neat additional notation one can use.