[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Assignment to array/record constants.
From: |
Gaius Mulley |
Subject: |
Re: Assignment to array/record constants. |
Date: |
Tue, 29 Nov 2022 15:20:04 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Guy <guyfieri@getbackinthe.kitchen> writes:
> Hello again Gaius, due to my lack of experience with mailing lists I'm afraid
> I just recently realized that when attempting to reply to your response to
> me, I accidentally replied directly to your personal email instead of the
> mailing list. Due to my email address's domain name, I think that it probably
> ended up in your junk/spam folder, my mistake.
>
> However since then I have installed Debian and was indeed able to compile the
> project mostly without issue, so in hindsight it seems that the latest GCC
> sources just aren't too well suited for macOS (though I'm sure there were
> quite a few things I was missing on my end).
>
> So today, the issue/question I had is a bit different and instead related to
> the actual compiler frontend's behavior. One of the first things I happened
> to try after the successful compilation was some features that I made
> frequent use of in other languages I have used, that being array/record
> constants. I saw from a Modula-2 ISO reference that the language also
> supported this via what it calls
> "constant constructors". Just to see how the compiler would respond, I tried
> assigning a value to some test constants I made, but to my surprise it didn't
> complain and actually replaced its value with the new one from the program
> body.
>
> More specifically, assignments to the constants in the body of the program
> via a constant constructor ("constant := TypeName{...}") replaced the current
> value, but assignments to individual components of the array/record didn't
> actually have an effect on the values. Running the test program in GDB. I
> noticed the main procedure of executable programs seemed to be named
> _M2_<program_name>_init, and was wondering if all array/record constructors
> (whether for a constant or not), were being moved into some sort of
> pre-"main" area of code. When stepping through the program, the
> new/additional assignments to the constant identifiers via constructors don't
> appear in the places they do in the source.
Hello Guy,
a small followup to say that the bug has been fixed in the git repro
with an improved error location and message:
$ gm2 another.mod
another.mod:8:17: error: In program module ‘another’: cannot assign a constant
designator expression with an expression ‘2.0’
8 | Fractions[2] := 2.0
| ~~~~~~~~~~~~~^~~~~~
$ gm2 constants.mod
constants.mod:34:14: error: In program module ‘Constants_Example’: cannot
assign a constant designator ‘Test_Point’ with an expression constructor
34 | Test_Point := TPoint{100.0, 80.0};
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
constants.mod:62:14: error: cannot assign a constant designator ‘Test_Color’
with an expression constructor
62 | Test_Color := TColor{0, 0, 0};
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
constants.mod:64:25: error: cannot assign a constant designator expression with
an expression ‘54’
64 | Test_Color[Color_Red] := 54;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~
constants.mod:65:27: error: cannot assign a constant designator expression with
an expression ‘97’
65 | Test_Color[Color_Green] := 97;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
constants.mod:66:26: error: cannot assign a constant designator expression with
an expression ‘182’
66 | Test_Color[Color_Blue] := 182;
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
I see that a similar test with constant record also exhibits a failure -
so will fix this using a similar route (designator record vs designator
array)
regards,
Gaius