[Issue 752] Assertion failure: 'e->type->ty != Ttuple' on line 4518 in file 'mtype.c'

BCS nothing at pathlink.com
Mon Jan 1 14:21:21 PST 2007


Walter Bright wrote:
> BCS wrote:
>> p.s. while I'm thinking about features, while writing that parser 
>> generator (see my last post) I realized that allowing a template to 
>> mixin a specialization for a template and have it overload with other 
>> templates would be *vary* powerful. mixin and overload can already be 
>> done for a function by way of an alias.
>>
>> I'd be interested in your thought on the subject.
> 
> It sounds very complicated :-(


What about it?

If you are referring to the parser code:
	Most of it is string manipulation templates. The last template
	is just parser for a sudo-BNF and a brain dead implementation of
	that grammar.

	As bad is this implementation is, I think it still beats the
	~1.5MB of code it takes in C++.



If you are referring to allowing overloading of specializations from mixins:
	here is a short example of what it would looks like:

template Foo(int i, char[] str)
{
	int Bar(char[] a: str)(int j)
	{
		return j+i;
	}
}

template Fig(int i, char[] str)
{
	int Bar(char[] a: str)(int j)
	{
		return j-i;
	}
}

struct Fog
{
	mixin Foo!(1, "hi") A
	alias A.Bar Bar;
	// having an implicit form of the alias would be VARY nice.
	// maybe: alias mixin Foo!(1, "hi");

	mixin Fig!(1, "bye") B
	alias B.Bar Bar;

	auto i = Bar!("hi")(3);	// uses Bar from Foo giving 4
	auto j = Bar!("bye")(3);// uses Bar from Fig giving 2
}

The other important thing that would make this vary powerfully is a way 
to allow forward reference to specializations. This would let mixins 
reference code in other mixins by knowing the name of the template to be 
used and the string to specialize it on.


void DoActionList(char[] str)()
{
	foreach(a; SplitOn!(',', str))
		Action!(a)();
}

DoActionList!("Fig,Farm,Foe")();
	// does Action!("fig"),  Action!("farm"),  Action!("foe");

mixin Baz!("fig"); // adds Action(char[] : "fig")


The importance of forward reference comes when cyclical calling is 
needed, as with a recursive decent parser.



More information about the Digitalmars-d-bugs mailing list