[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gm2 rejecting a constant statement as variable
From: |
Alice Osako |
Subject: |
Re: gm2 rejecting a constant statement as variable |
Date: |
Tue, 2 Apr 2024 09:34:01 -0400 |
User-agent: |
Mozilla Thunderbird |
Gaius Mulley:
Alice Osako <alicetrillianosako@gmail.com> writes:
Now, curiously enough, with the latest build for the compiler, the lines
CONST
BitsInUse =
ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
Still give the error:
src/imp/Hash.mod:35:13: error: In implementation module ‘Hash’: in
assignment, cannot assign a variable to a constant ‘BitsInUse’
35 | BitsInUse =
| ^
src/imp/Hash.mod:35:3: error: designator ‘BitsInUse’ is declared as a CONST
35 | BitsInUse =
However, it works exactly as expected if written as:
CONST
BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
interesting - what are the values (declarations) of MaxBits and
AddressableBits?
MaxBits is defined in Hash.def:
CONST MaxBits = 32; (* upper limit for hash values *)
AddressableBits is defined locally as
(*
---------------------------------------------------------------------------
* number of bits available for use
*
------------------------------------------------------------------------ *)
CONST
AddressableBits = Size.AddressableBits;
Where the definition in Size.def is... rather complicated:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(*
---------------------------------------------------------------------------
* compile time calculation of the bit width of type Size
*
------------------------------------------------------------------------ *)
CONST
MaxSizeDivPow2Of8 = MAX(Size) DIV 256;
MaxSizeDivPow2Of16 = MaxSizeDivPow2Of8 DIV 256;
MaxSizeDivPow2Of24 = MaxSizeDivPow2Of16 DIV 256;
MaxSizeDivPow2Of32 = MaxSizeDivPow2Of24 DIV 256;
MaxSizeDivPow2Of40 = MaxSizeDivPow2Of32 DIV 256;
MaxSizeDivPow2Of48 = MaxSizeDivPow2Of40 DIV 256;
MaxSizeDivPow2Of56 = MaxSizeDivPow2Of48 DIV 256;
MaxSizeDivPow2Of64 = MaxSizeDivPow2Of56 DIV 256;
MaxSizeDivPow2Of72 = MaxSizeDivPow2Of64 DIV 256;
MaxSizeDivPow2Of80 = MaxSizeDivPow2Of72 DIV 256;
MaxSizeDivPow2Of88 = MaxSizeDivPow2Of80 DIV 256;
MaxSizeDivPow2Of96 = MaxSizeDivPow2Of88 DIV 256;
MaxSizeDivPow2Of104 = MaxSizeDivPow2Of96 DIV 256;
MaxSizeDivPow2Of112 = MaxSizeDivPow2Of104 DIV 256;
MaxSizeDivPow2Of120 = MaxSizeDivPow2Of112 DIV 256;
BW8 = (MAX(Size) <= 255);
BW16 = (MaxSizeDivPow2Of8 > 0) AND (MaxSizeDivPow2Of8 <= 255);
BW24 = (MaxSizeDivPow2Of16 > 0) AND (MaxSizeDivPow2Of16 <= 255);
BW32 = (MaxSizeDivPow2Of24 > 0) AND (MaxSizeDivPow2Of24 <= 255);
BW40 = (MaxSizeDivPow2Of32 > 0) AND (MaxSizeDivPow2Of32 <= 255);
BW48 = (MaxSizeDivPow2Of40 > 0) AND (MaxSizeDivPow2Of40 <= 255);
BW56 = (MaxSizeDivPow2Of48 > 0) AND (MaxSizeDivPow2Of48 <= 255);
BW64 = (MaxSizeDivPow2Of56 > 0) AND (MaxSizeDivPow2Of56 <= 255);
BW72 = (MaxSizeDivPow2Of64 > 0) AND (MaxSizeDivPow2Of64 <= 255);
BW80 = (MaxSizeDivPow2Of72 > 0) AND (MaxSizeDivPow2Of72 <= 255);
BW88 = (MaxSizeDivPow2Of80 > 0) AND (MaxSizeDivPow2Of80 <= 255);
BW96 = (MaxSizeDivPow2Of88 > 0) AND (MaxSizeDivPow2Of88 <= 255);
BW104 = (MaxSizeDivPow2Of96 > 0) AND (MaxSizeDivPow2Of96 <= 255);
BW112 = (MaxSizeDivPow2Of104 > 0) AND (MaxSizeDivPow2Of104 <= 255);
BW120 = (MaxSizeDivPow2Of112 > 0) AND (MaxSizeDivPow2Of112 <= 255);
BW128 = (MaxSizeDivPow2Of120 > 0) AND (MaxSizeDivPow2Of120 <= 255);
Bitwidth = (* storage size *)
8*ORD(BW8) + 16*ORD(BW16) + 24*ORD(BW24) + 32*ORD(BW32) +
40*ORD(BW40) + 48*ORD(BW48) + 56*ORD(BW56) + 64*ORD(BW64) +
72*ORD(BW72) + 80*ORD(BW80) + 88*ORD(BW88) + 96*ORD(BW96) +
104*ORD(BW104) + 112*ORD(BW112) + 120*ORD(BW120) + 128*ORD(BW128);
AddressableBits = Bitwidth; (* addressable size *)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Aside from the question of why this contradicts your earlier
explanation, the problem of treating a constant assignment with a
newline immediately after the equals sign as if there were a variable
in the expression still persists, and seems to be independent of the
constants issue.
Yes indeed I'll investigate.
Thank you.