Ok, so val () = basically says the result must be void aka (), and not
ignored. Makes sense.
I have a similar problem passing a value used in an arrayref. In the code
below, if I do this:
crcLookupTable[n8(u8(4)]
it will print the value in the forth element of the array.
If I call pec_add(u8(4)), it prints 0. Basically, it seems not to pass into
the call, or the cast somehow turns a 4 into a 0.
I assume the arrayref is ok or hard coding u8(4) would fail.
What can make 4 become zero?
// SATS file
fun pec_add (old: uint8, new: uint8): uint8
// DATS file
extern fun{} n8 (x: uint8): natLt(256)
implement{} n8 (x) = cast{natLt(256)}(x) // Can’t go wrong because they
are the same size
%{^
const uint8_t crcLookupTable[256] PROGMEM = { 0, 7, 14, 9, 28, 27, 18, 21,
56, 63, 54, 49, 36, 35, 42, 45,
112, 119, 126, 121, 108, 107, 98,
101,…
};
%}
macdef crcLookupTable =
$extval(arrayref(uint8,256),“crcLookupTable”)
implement pec_add (old, new) = crcLookupTable[n8(new)]
// APP DATS File
val pec = pec_add(ZERO, u8(4))
val _ = print! pecOn Monday, October 12, 2015 at 8:36:04 PM UTC-6, gmhwxi wrote:
This example actually shows why it is good idea to write
val () = !a := b
instead of
val _ = !a := b
In the case where := is replaced with =, the former results in a type-error
while the latter may be well-typed.
On Monday, October 12, 2015 at 9:45:55 PM UTC-4, Mike Jones wrote:
I tried to make a reference to some memory per our previous discussion,
but the value is zero afterwards.
This code reveals the problem. “by” prints out the value 2. And
“!packetCount” prints out zero. Further debugging a loop that takes the
value !packetCount confirms it is zero.
Am I using incorrect syntax for “val _ = !packetCount = by”
%{^
const uint8_t packet[131];
const uint8_t *packetCount = packet;
const uint8_t *packetHeader = packet + 1;
const uint8_t *packetContents = packet + 2;
%}
macdef packet =
$extval(arrayref(uint8, 131),“packet”)
macdef packetCount =
$extval(ref(uint8),“packetCount”)
val by = serial_poll_for_byte(): uint8
val _ = print! by
val _ = !packetCount = by
val _ = print! (!packetCount)