[m-dev.] Name mangling (was Re: [m-rev.] For review: Convert Mercury terms to XML)

Ralph Becket rafe at cs.mu.OZ.AU
Tue Dec 7 11:36:39 AEDT 2004

Ian MacLarty, Monday,  6 December 2004:
> > It would be helpful to give some examples of the mangling scheme in the
> > comment here.  Name mangling seems to be one of those things that is
> > prone to break easily, so it is important that this bit is documented
> > thoroughly.
> > 
> +%
> +% So for example "my-functor!" would become "my-45functor-33" while
> +% "MyFunctor" would become "Tag_MyFunctor", presuming we were using
> +% "Tag_" as the prefix for strings that started with capital letters.
> +%

It seems to me that we've needed a generic name mangling library for
some time.  Ideally the mangler would do minimal mangling and produce
easily readable, C compiler-friendly output wherever possible.

Can I propose the following scheme:

Unmangled character		Mangled output
-------------------		--------------
Z				ZZ
c in [a-zA-Y0-9_]		c
c not in [a-zA-Z0-9]		Z## (where ## is the ASCII hex code for c)

(`Z' is very nearly the least frequently used letter in English and sits
in a conveniently mnemonic place in the alphabet.)

If we want to gracefully handle other characters (e.g. [+-/*$@#]) we
we could extend the scheme fairly easily, perhaps by passing a
dictionary parameter to the mangler:

	+	<------>	_PLUS_
	-	<------>	_MINUS_
	/	<------>	_DIV_
	*	<------>	_STAR_

whith the patterns on the right being inserted after a `Z' during
mangling and tested for after a `Z' when demangling.

This would clear up mangling issues across the board (at the moment, any
change to the mangling scheme has to be mirrored in three different
places and in two different languages... and I still don't understand
how the demangling code works, despite spending some time staring at

> > I would leave some space around the `..`
> > 
> Can do.

Can't we make `..' an infix operator?

-- Ralph
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list