[RFC] Symbol mangling schema

Mohammad-Reza Nabipoor mnabipoor@gnu.org
Sun Nov 9 20:49:13 GMT 2025


Hi Jose.

On Sun, Nov 09, 2025 at 07:02:25PM +0100, Jose E. Marchesi wrote:
> 
> 5. Symbols corresponding to publicized identifiers and indicants always
>    start with the name of the definition module publicizing them,
>    followed by an underscore character.  For example, in the module:
> 
>      module Json =
>      def
>          pub mode JSON_Val = union (void,bool,int,string.JSON_Arr,JSON_Obj),
>          pub mode JSON_Arr = struct (JSON_Elm elements),
>          ...;
> 
>          pub proc json_new_obj = JSON_Val: heap JSON_Obj;
>          ...
>      fed
> 
>    The mode JSON_Val will mangle to a symbol JSON_JSONVAL.
>    The identifier json_new_obj will mangle to a symbol JSON_jsonnewobj.
> 
> 6. Publicized symbols that are intended to be used by the compiler or
>    runtime are preceded by the mangled name of the module followed by
>    two underscore characters.  For example, the prelude and postlude for
>    the above module will be accessible via the mangled symbols
>    JSON__prelude and JSON__postlude.
> 


I propose to have `ga68_' or `GA68_' prefix for all module symbols.
Also I'd suggest to have a compiler option to overwrite this, so if a user
want an empty string, be able achieve it with ease.

The good thing about this is that, if in future, we want to change the mangling
scheme, we can easily change `ga68_' to something like `ga682_', and no headache
after that. Versioning of interfaces is important and is my main motivation here.

So we'll have `GA68_JSON_jsonnewobj' or `ga68_JSON_jsonnewobj' by default.


> 7. Operator symbols, the monads and nomads, are mangled to letter codes
>    symbolizing the symbols:
> 
>      %    (p)ercentage
>      ^    (c)aret
>      &    (a)mpersand
>      +    (p)lus
>      -    (m)inus
>      ~    (t)ilde
>      !    (b)ang
>      ?    (q)uestion mark
>      >    bi(g)ger than
>      <    (l)ess than
>      /    (s)lash
>      =    (e)qual
>      :    c(o)lon
>      *    sta(r)
> 
>    Each letter code is followed by a single underscore character.  So
>    for example, in the following module:
> 
>      module Foo =
>      def
>          int ss;
>          op // = (int a, b) int: a + b;
>          ...
>      fed
> 
>    The identifier ss will mangle to a symbol FOO_ss.
>    The operator // will mangle to a symbol FOO_s_s_.
> 


The tricky part here is overloading. Operators can be overloaded for different
modes, and those modes should somehow be reflected in the name.

E.g., with a simplisitic (and unusable) approach, operator // should be something
like `GA68_FOO_s_s_21i1i': first 2 is saying operator is dyadic, and 1s are saying
how many characters are part of first/second modes.
For complete encoding of modes, we probably have to do things similar to BER encoding.
Detailed to be discussed.


Other than these, the rest sounds reasonable to me :)


More information about the Algol68 mailing list