On Sun, 14 Jul 2024 at 21:58, Alcor <alcor@tilde.club> wrote:
Hi all,
The following program (Test.mod) causes an ICE on gm2 (GCC) 15.0.1 20240707 (x86_64, Arch Linux):
--
MODULE Test;
IMPORT SYSTEM;
TYPE
T = POINTER TO CONS;
CONS = RECORD
CAR: SYSTEM.ADDRESS;
CDR: T;
END;
PROCEDURE POP(VAR LST: T): SYSTEM.ADDRESS;
CONST CAR = LST.CAR;
First, a CONST definition defines a compile time constant and this is a runtime _expression_.
VAR car : SYSTEM.ADDRESS;
Then, pointers must explicitly be dereferenced:
BEGIN
car := LST^.CAR
I am not sure what you are trying to achieve with this code though. since you always return NIL.
Probably you want
IF LST = NIL
RETURN NIL
ELSE
RETURN LST^.CAR
END
Also note that in Modula-2 all-uppercase names are considered bold names and are intended for reserved words of the language. predefined identifiers of the language, and in some cases important identifiers of the standard library. Ideally, definition of all-uppercase names should be avoided. Use lowercase, camelCase and TitleCase instead.
Here is a rudimentary name convention typically used in Wirthian languages
Constants in TitleCase
Variables in lowercase or camelCase
For procedures and functions there are two schools of thought
(1) procedures lowercase/camelCase and functions in TitleCase, or
(2) procedures in TitleCase and functions in lowercase/camelCase,
whichever one uses, it should be consistent throughout one's code
regards
benjamin