[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Error when using EXPORT UNQUALIFIED in an FFI def. module
From: |
Gaius Mulley |
Subject: |
Re: Error when using EXPORT UNQUALIFIED in an FFI def. module |
Date: |
Wed, 03 Apr 2024 02:50:39 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Alice Osako <alicetrillianosako@gmail.com> writes:
> When working on the FFI definition file for stdio for M2PP:
>
> https://github.com/m2sf/m2pp/blob/master/src/posix/stdio.gm2.iso.def
>
> the code as currently written includes an extensive EXPORT UNQUALIFIED
> statement for several of the constants, types, and procedures defined therein.
> According to Benjamin Kowarsch, this was originally done because - at the
> time the code was written - a gm2 FFI definition file did not allow
> unqualified
> imports without explicitly permitting it.
>
> However, with the current build of gm2, this causes a peculiar error message,
> indicating a possible parsing error:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> make -f Makefile bfsys
>
> /home/schol-r-lea/opt/bin/gm2 -g -fiso -freport-bug
> -fdebug-function-line-numbers -Isrc/ -c src/imp/BasicFileSys.mod \
> -o obj/BasicFileSys.o
> src/stdio.def:20:1: warning: In definition module ‘stdio’: syntax warning,
> ‘END’ missing
> 20 | FROM SYSTEM IMPORT
> | ^~~~
> src/stdio.def:20:13: warning: syntax warning, ‘.’ missing
> 20 | FROM SYSTEM IMPORT
> | ^~~~~~
> src/stdio.def:3:27: error: module name at beginning ‘stdio’ does not match
> the name at end ‘SYSTEM’
> 3 | DEFINITION MODULE FOR "C" stdio; (* GNU Modula-2 ISO version *)
> | ^~~~~
> src/stdio.def:20:1: error: syntax error, found ‘FROM’
> 20 | FROM SYSTEM IMPORT
> | ^~~~
> src/stdio.def:20:6: error: module name at end ‘SYSTEM’ does not match the
> name at beginning ‘stdio’
> 20 | FROM SYSTEM IMPORT
> | ^~~~~~
> src/stdio.def:20:13: error: no scope active: syntax error, found ‘IMPORT’
> 20 | FROM SYSTEM IMPORT
> | ^~~~~~
> src/stdio.def:146:11: error: compilation failed
> 146 | END stdio.
> | ^
> make: *** [Makefile:93: bfsys] Error 1
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> It appears to cause the parser to treat the rest of the source file as
> garbage. When the EXPORT statement is deleted, compilation proceeds normally.
>
> This appears to be a bug, though just what the correct behavior should be
> here isn't clear to me - either the statement is redundant, and should be
> removed
> anyway, or it is still necessary and should not raise an error, or else it is
> an error and should be flagged as such. I am assuming that the EXPORT is
> merely
> unneeded here; from what I was told, EXPORT should only normally be used in
> nested modules, anyway, but should still be syntactically valid in outer
> modules (just ignored).
>
> Sorry to bring yet more things up here.
all valuable feedback thanks!
I set up the source dir via:
$ mkdir build
$ cd build
$ cp ../src/posix/stdio.gm2.pim.def stdio.def
$ cp ../src/Size.longint.def Size.def
$ cp ../src/imp/BasicFileSys.mod .
$ gm2 -g -I../src/ -fsources -c BasicFileSys.mod
Compiling: BasicFileSys.mod
Pass 0: lexical analysis, parsing, modules and associated filenames
Module SYSTEM :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2cor/SYSTEM.def [m2cor]
Module M2RTS :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/M2RTS.def [m2pim]
Module RTExceptions :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/RTExceptions.def
[m2pim]
Module BasicFileSys : ../src/BasicFileSys.def
Module BasicFileSys : BasicFileSys.mod
Module COROUTINES :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/COROUTINES.def
[m2pim] (for C)
Module Size : ./Size.def
Module FileSystem :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2log/FileSystem.def
[m2log]
Module FIO :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/FIO.def [m2pim]
Module DynamicStrings :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/DynamicStrings.def
[m2pim]
Pass 1: scopes, enumerated types, imports and exports
Pass 2: constants and types
Pass C: aggregate constants
Pass 3: quadruple generation
Pass 4: gcc tree generation
symbols to gcc trees
statements to gcc trees
terminate called after throwing an instance of 'unsigned int'
cc1gm2: internal compiler error: Aborted
and the error is the relop in the const expression as reported before.
I had to fix a couple of bugs in BasicFileSys.mod
$ diff -ruw ../src/imp/BasicFileSys/BasicFileSys.pim.mod BasicFileSys.mod
--- ../src/imp/BasicFileSys/BasicFileSys.pim.mod 2024-03-31
19:08:22.851442410 +0100
+++ BasicFileSys.mod 2024-04-03 02:24:20.015001955 +0100
@@ -22,7 +22,7 @@
exist then we have to close it again. Bad design. *)
BEGIN
- FileSystem.Lookup(f, path, false);
+ FileSystem.Lookup(f, path, FALSE);
found := (f.res = FileSystem.done);
IF FileSystem.opened IN f.flags THEN
@@ -46,7 +46,7 @@
highFactor, highWeight : FileSize;
BEGIN
- FileSystem.Lookup(f, path, false);
+ FileSystem.Lookup(f, path, FALSE);
found := (f.res = FileSystem.done);
IF NOT found THEN
@@ -60,7 +60,7 @@
ELSE
status := Failure;
RETURN
- END (* IF *)
+ END ; (* IF *)
IF high = 0 THEN
IF wouldOverflowFileSize(low) THEN
@@ -146,7 +146,7 @@
RETURN
END; (* IF *)
- FileSystem.Lookup(f, path, false);
+ FileSystem.Lookup(f, path, FALSE);
FileSystem.Rename(f, path);
IF f.res = FileSystem.done THEN
@@ -198,6 +198,16 @@
END wouldOverflowFileSize;
+(*
+ valueWouldOverflowFS - needs implementing --fixme--.
+*)
+
+PROCEDURE valueWouldOverflowFS (x: CARDINAL) : BOOLEAN ;
+BEGIN
+ RETURN FALSE (* --fixme-- *)
+END valueWouldOverflowFS ;
+
+
PROCEDURE addWouldOverflowFS ( n, m : CARDINAL ) : BOOLEAN;
BEGIN
regards,
Gaius