On Thu, 28 Mar 2024 at 05:52, Alice Osako wrote:
I know that ISO Modula-2 added both exceptions and optionally, generics.
Exceptions are part of the ISO M2 base standard while generics are an additional standard on top of the base standard.
Further, I know that GNU Modula-2 also supports optional parameters and
optional return values, but as far as I can tell those are unique to
GM2.
Yes, those are GM2 extensions, not available elsewhere.
My question is, which compilers support the ISO generics,
To my knowledge only the p1 Modula-2 compiler for Macintosh implemented the generics extension.
what options would I have
for support under non-ISO compilers, if any?
Static generics can always be done using a simple text templating utility that replaces placeholders in a template text with specific translations to generate a target text. This is almost trivial. I have written several such utilities. Most notably, one in Objective-C, one in C and one in Modula-2 (PIM & ISO).
So my question is, what are my options with Modula-2? I know that M2PP
is one possibility, but I would prefer to stay within the core language
if possible. However, I am guessing that M2PP is my best option for
working with compilers that only support PIM.
I think you will find that template expansion by placeholder replacement is VASTLY SUPERIOR to any static generics facility in any language. And once you have worked on this basis, you will never ever want to go back to anything that is built into or bolted onto the language.
Any static generics facility built into a language is nothing else but text replacement anyway. It doesn't do anything different. However, it hides what it does from you. You are blind. You cannot see what it has generated. You may think you know what the actual source code is that the compiler is translating, but it may be something quite different and you won't know. And this poses a very serious problem when debugging.
With a template expansion utility, you will see what the compiler sees.
And, you can inject text into comments, so that the expanded source code tells you what version it is.
Thus, from a usability perspective alone, an external template expansion utility is already superior.
Then, there is the aspect of implementation and complexity/reliability of the compiler. Why should the compiler be burdened with the task of expanding templates? Why should the compiler have to check the syntax of the template? The only thing that matters is whether the generated source is syntactically correct. The compiler doesn't need to care whether the template is correct. Furthermore, there is no need to expand a template over and over and over again, once it has been expanded.
Keeping template expansion out of the compiler significantly reduces implementation complexity and thus reliability.
And then you can always add features to the template engine utility for common use cases that make things easier. The compiler will not be impacted by that at all. The compiler always expects correct Modula-2 input and the job of the template and template expansion is to generate correct Modula-2.
So, I'd recommend you try working with an external template expansion utility and then see how this works out.
regards
benjamin