New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Adopt C++ name mangling conventions for better compatibility #120

Closed
philix opened this Issue Dec 2, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@philix
Contributor

philix commented Dec 2, 2017

Issue: It's not possible to encode all valid Lisp identifiers, type names differentiating overloaded functions, namespaces directly in C because C identifiers are very strict, so Carp is creating its own name mangling strategy.

Suggestion: adopt the C++ name mangling scheme.

The C++ name mangling strategy has two advantages: already exists and is understood by many tools.

Even Rust has adopted it https://github.com/rust-lang/rust/blob/76affa5d6f5d1b8c3afcd4e0c6bbaee1fb0daeb4/src/librustc_trans/back/symbol_names.rs#L358

@eriksvedang

This comment has been minimized.

Collaborator

eriksvedang commented Dec 3, 2017

That seems like a pretty good idea. Do you have a link to some kind of understandable spec for it?

@hellerve

This comment has been minimized.

Contributor

hellerve commented Dec 4, 2017

The C++ standard does not specify a mangling scheme, and we will have to implement it in a few different ways to be able to be compatible with different compilers. This is neither an argument for nor against it—I have no opinion on this—, just a remark.

@bagucode

This comment has been minimized.

Contributor

bagucode commented Dec 5, 2017

Hello Carp people!
This is the de-facto standard documentation for calling conventions and name mangling.
http://www.agner.org/optimize/calling_conventions.pdf

@hellerve

This comment has been minimized.

Contributor

hellerve commented Dec 5, 2017

Another thing to consider: when we write C code that interfaces with Carp, we mangle by hand. This would mean we would have to provide different versions for the core functions (because of the names) or autogenerate core.h, as well as doing that for any C code that interfaces with Carp. This sounds tedious to me, and I’m not sure what we gain from it.

Still I have no informed opinion about this, but I’d like to say that right now it is fairly comfortable to write C that interfaces with Carp. It would be prudent to keep it that way, so to whatever system we change, this should be our primary concern.

@eriksvedang

This comment has been minimized.

Collaborator

eriksvedang commented Dec 5, 2017

Agreed. My idea with the current naming scheme is that it's fairly close to how people name their C libraries. In theory that means better usage of Carp libraries from C code and nicer wrapping of existing C libraries. For instance, the SDL library could be wrapped in a SDL module with shorter function names since all its functions begin with SDL_. I'll read through the C++ mangling doc for ideas, but won't change any of this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment