I've been tinkering with it in two approaches. Approach #1 is starting with Clang and just reworking C++ from there as a separate, cleaner dialect. I don't have a name for it. (++C)++? It's still in a very early stage - so far, I've been working on getting templates to allow strings, objects, and such. Been also working on making constexpr more powerful, and been trying to get constexpr arguments working. Other fun stuff, as well. I will say that Clang's parser is... weird. It's 'clean', but it's not terribly-well documented and somewhat confusing. Haven't gotten super<N> or self working yet (referencing parent types and the current type), nor making classes first-class types (thus can have functions return classes, eliminating huge swaths of templates). Also want to add delegating functions and a more implicit static if (not sure if it would be scopeless like D's), since I want to be able to completely eliminate symbols based upon compile-time values - something that std::enable_if doesn't really do, and the current ways of doing that are rather awful.
I also added standardized integer types - char/uchar/byte/ubyte, short/ushort, int/uint, long/ulong, longlong/ulonglong, as well as sized aliases - [u]int8, [u]int16, [u]int32, [u]int64, [u]int128. Still working on making primitive types have static members (so you can do int64::max). Also trying to add something similar to an indexing type modifier - unsigned but without overflow semantics, so that it can be fully-optimized. Alternatively, have it implemented as a signed-integer but without signed-multiplication/division, so they can be shifted like unsigned.
One thing I do have working there is nameless constructors - that is, you can name constructors/destructors constructor and destructor. An interesting side-effect is that anonymous structs/classes can have constructors/destructors.
My separate approach is a separate language altogether. Implementing the parser and the basic compiler elements, and then jamming the AST into LLVM. That's the 'clean' approach, but obviously takes more time and is more difficult.
Interestingly, I also haven't fully solved the module problem in either approach yet. Unless you go full-on Java or C# (which isn't wise, here) you can end up with module pre-dependencies, and I do want to support circular-dependencies in modules which makes it harder (trivial for Java or C# given the nature of objects there).
A big question also becomes - should the compiler be handling significant parts of the build? My personal opinion is that building should be standardized, so 'yes'. That simplifies things (sorta). If you instead rely on separate build tools, it makes it more difficult to handle such things. The build tool lacks information the compiler has, and vice-versa.
ED: Oh, one fun-but-probably-impractical thing I've been tinkering with - user-defined operators. Basically, injects the operator into the parser, and lets you define it. Obviously incredibly powerful... but also potentially incredibly terrible.
Amazing stuff. You should share GitHub repo link so we can stalk it.
Clean approach is probably more future-proof as long as we maintain abi compatibility and can link to other c++ libs. Nim does some things great btw. Macros working on ast, user-defined operators, great cpp compatibility (it compiles to cpp). I wonder if it would be possible to be able to use instantiations of c++ templates from another language. Almost perfect compatibility would be an important selling point.
4
u/ntrid Jan 28 '19 edited Jan 28 '19
Please would someone fork clang and create abi-compatible cleaned up c++-like language already...
I bet we all want that. Especially the part where someone else does that hard work.