gm2
[Top][All Lists]
Advanced

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

Translating Modula-2 identifiers to C


From: Benjamin Kowarsch
Subject: Translating Modula-2 identifiers to C
Date: Mon, 8 May 2023 00:47:43 +0900

Except for a few loose ends, I have now completed a library to translate Modula-2 identifiers to C. It consists of two modules representing a user level and a lower level.

The user level module uses the lower level module and its conversion facility to generate C identifiers for import guards, macro constants including qualified enumeration values in MACRO_CASE; and for types, variables and functions in snake_case; across three use cases: (1) qualified identifiers with the module as a prefix, (2) local identifiers with a local suffix and (3) top scope static identifiers without module prefix nor local suffix.

https://github.com/m2sf/m2c/blob/main/src/m2c-ident-xlat.h

The lower level module implements a key/value dictionary to store and retrieve unqualified Modula-2 identifiers in any of lower/upper/camel/title/mixed case and their C translations in snake case. Every identifier is automatically converted and checked into the dictionary upon the first retrieval request.

https://github.com/m2sf/m2c/blob/main/src/lib/string/snake-case-conv.h

The purpose of this library is to facilitate the generation of authentic human readable C code from Modula-2 source code. I wrote this for my Modula-2 to C translator/via-C compiler, but it could also benefit GM2.

The library is written in C99 and is LGPL licensed.

Due to the license it could be incorporated into GM2 and then facilitate the development of libraries to be used from C but written in Modula-2 and built with GM2. For this, the symbols should conform to C conventions, which at present isn't the case. Note that any such symbol translation could always be switched off by compiler switch. But if the feature is available, it would make GM2 more useful for cases where somebody needs to deliver some C library but would rather write it in Modula-2.

For anybody interested in the actual mapping of identifiers, the specification is here:

https://github.com/m2sf/m2c/wiki/Mapping-Modula-2-Identifiers-to-C

I also intend to add a pragma so that one can supply a custom name.

Gaius, I know you have plenty of work already, but perhaps you want to consider incorporating this facility. If you need any adaptation, just drop me a mail.

regards
benjamin

reply via email to

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