On 2010-12-15 08:57, Don wrote:
Jacob Carlborg wrote:
On 2010-12-14 13:05, Don wrote:
Graham St Jack wrote:
On 14/12/10 20:33, Vladimir Panteleev wrote:
On Tue, 14 Dec 2010 09:30:46 +0200, Graham St Jack
<graham.stj...@internode.on.net> wrote:

There is of course the worry that it could get so easy that everyone
starts doing it, and we have (relatively) impenetrable code
everywhere
instead of just deep in the bowels of framework libraries.

TBH, I'm more excited by AST macros which I understood are planned for
D3, as mentioned here:
http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf
They seem to promise the power of mixins, but without the mess.


I took a look at the pdf, but couldn't see how the AST macros could
come
close to the kinds of things that are possible (but difficult) with
mixins.

That fact was recognized at the conference, on the following day. As a
result, AST macros were dropped from D2.

Do you have an example that would work with string mixins but not with
AST macros?

Well, it's a bit hard without a formal definition of AST macros.
But the stuff I talked about at the conference, I have no idea how to do
with AST macros.

There's code like this, which generates an asm instruction.

------
mixin( opToSSE[operations[done+1]] ~ suffix ~ " " ~ XMM(numOnStack-1) ~
", " ~ indexedSSEVector(ranklist, operations[done], vectorsize));
-------

using the functions:
============
const char [][5] vectorRegister = ["ECX", "EDX", "EBX", "ESI", "EDI"];

char [] indexedSSEVector(char [] ranklist, char var, char [] vecsize)
{
return "[" ~ vectorRegister[vectorNum(ranklist, var)] ~ " + " ~ vecsize
~"*EAX]";
}

char [] XMM(int k) { return "XMM"~ itoa(k); }

char [][char] opToSSE() {
return ['*':"mulp"[], '+': "addp", '-': "subp", '/': "divp"]; }

int vectorNum(char [] ranklist, char var)
{
int numVecs=0;
for (int i=0; i<var-'A'; ++i) {
if (ranklist[i]=='1') ++numVecs;
}
return numVecs;
}
============

I can't quite visualize how the final code will look like and as you say it's hard without a formal definition of AST macros. But I think somehow it would be possible, I mean instead of combining strings one combine expressions/syntax. But I don't know if it would be possible to combine incomplete expressions.

They need to roughly match string mixins in power. At this stage, there
is no proposal for how they should work.

I think someone, Nick Sabalausky perhaps, suggested to have something
like the hygiene macros in Nemerle:
http://nemerle.org/wiki/index.php?title=Macros

 From an implementation point of view, the differences between Nemerle
macros and string mixins are mostly syntactic.
The one thing about them that I find really impressive is the IDE
integration, especially that they got syntax highlighting to work. I
don't know they've done that.

As far as I can see the content of a macro in Nemerle is just code. But if you're referring to the syntax expression/statement which adds new syntax to the language then I agree.

--
/Jacob Carlborg

Reply via email to