The Gamma Language
Posted by RossBencina 4 days ago
Comments
Comment by masot 20 hours ago
Gamma was an experiment in templates without having to parse C. This led to some big annoyances that I guess aren't mentioned on that site but are in the PagedOut page[1]: when you instantiate a template "bar::[struct foo]" Gamma does a pretty bad job of knowing to copy the definition of "struct foo" (and all type definitions that "struct foo" depends on) from the caller into the template before compiling the instantiated template. (It gets even worse with circular dependencies, e.g., a "struct tree_node" that contains a "list::[struct tree_node]".)
More recently I've been writing MaC[2], which solves those problems by fully parsing the "header file" for each template. So it knows about all of the types in the program and can copy them between template instantiations as needed, but in the "main body" of the template you can use arbitrary GNU-C features. This has been a lot more reliable. As a test program for it I'm currently in the middle of writing an LR[k] parser generator[3] in MaC.
The big thing that gets annoying about all of these "don't-parse-the-code" approaches is there's no good way to do type inference. So you can't do multiple dispatch, e.g., have "print(x->foo(bar));" forwarded to the 'right' print function based on the type of its argument. (Actually, I've experimented with doing dynamic dispatch based on DWARF information, but that's a huge can of worms itself!)
[1] https://pagedout.institute/download/PagedOut_007.pdf#page=44 [2] https://lair.masot.net/mac/ [3] https://lair.masot.net/git/mac.git/tree/examples/lrk (sorry about the unreadable color scheme, still tuning it ...)
Comment by sfpotter 20 hours ago
I used to very down on C++ but have stopped caring quite so much... Just using C++ and restricting oneself to templates seems like a better bet than this. Or you could use D and have a language whose template experience is much better than C++'s...
Any language this is going to need debug info eventually. One could step through the generated C code, but this is much less pleasant than stepping through the original source.
I also wonder how name mangling is handled?
Comment by masot 20 hours ago
But yes --- for a real project I would absolutely recommend someone use D over this !
Comment by sfpotter 20 hours ago
Comment by xigoi 4 hours ago
for (int j = i; j --> 0;)Comment by wosined 13 hours ago
Comment by wosined 13 hours ago