gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dialect & Target Specific M2 Code


From: Gaius Mulley
Subject: Re: Dialect & Target Specific M2 Code
Date: Tue, 09 Jan 2024 14:27:03 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Benjamin Kowarsch <trijezdci@gmail.com> writes:

> Further to my comments on (1) foreign function interfacing within M2 and (2) 
> using M2 from C and thus targeting C, I would also like to comment on a
> related subject matter: writing dialect specific and target specific M2 code, 
> in particular within the context of conditional compilation.
>
> I used to work on cross-platform code in C and the prevailing approach there 
> is to use conditional compilation via the C pre-processor to support multiple
> platforms.
>
> At first I found the conditional compilation approach using #if #else #end 
> pragmas directly within the C source code quite convenient and I felt that 
> this was a
> feature that should also be supported by Modula-2 compilers, ideally using a 
> common specification so as to make the code also work across different
> compilers.
>
> Over time I found out that such sources will become more and more unwieldy, 
> difficult to read and eventually unmaintainable. So, I moved to an alternative
> approach: Each platform specific source file contains only the code for one 
> specific platform and for each platform to be supported there is a platform 
> specific
> version of every file that contains platform specific code.
>
> Later, I used the very same approach for source files that contain dialect 
> specific code: Each dialect specific source file contains only the code for 
> one dialect
> and for each dialect to be supported there is a dialect specific version of 
> every file that contains dialect specific code.
>
> This means no conditional compilation directives are needed. When writing 
> code, the author can focus on the platform and dialect of the source file 
> being
> edited, reducing mental load. When reading and maintaining code, the reader 
> or maintainer can focus on the platform and dialect of the source file being
> read or maintained, also reducing mental load. When testing code, the tests 
> can focus on the platform and dialect of the source file being tested, 
> reducing
> mental load for the tester and decreasing the chance that important test 
> cases are omitted as a result of the "can't see the forest for the trees" 
> effect. Also,
> unit tests do not need to be retested when an unrelated test case for a 
> different platform or dialect has been added or modified. Only tests specific 
> to the
> tested platform and dialect need to be tested for each source file.  
>
> I don't know if GM2 supports conditional compilation nor if it is
> planned to be added in case it isn't supported, but I would advise
> against supporting/using it.

Hi Benjamin,

it does support the preprocessor (but you have to enable this feature
using the option -fcpp).  This turns on a restricted C pre processor
(the same technique is used in gnu fortran iirc).  gm2 doesn't use it
when bootstrapping (and none of the libraries require this feature to
build).

The libgm2 instead uses modula-2 which sits on top of C wrappers (the C
wrappers contain all the conditional code - making use of automake,
autoconf, C preprocessor and friends).  The target coverage appears
quite successful using this approach.  The C wrappers present a unified
interface to the m2 source.

I'm not sure how many targets GCC supports - although there is an
indication here: https://gcc.gnu.org/install/specific.html.  Many of the
targets also have different abi's (ppc64le has 3 floating point
representations of (long double) LONGREAL for example :-).  Of course
then there is the issue of canadian cross compilation.  Different
releases of OSs can behave differently (OSX and select).  Loads of fun!

regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]