The most twisted D code (you've) ever written
BCS
ao at pathlink.com
Fri Oct 12 07:53:31 PDT 2007
Reply to Downs,
> What's the most badly garbled, mangled or otherwise hideously
> disfigured D code you've ever written that still worked as intended?
>
> The point of this thread is to find out how badly it's possible to
> twist the D language without making the compiler commit Seppuku.
>
> Note: intentional obfuscation doesn't count :)
>
> Give us your worst.
> --downs
> PS: Here's my entry
> ([&update]~([1, 2] /map/ (int e) { return &prefetch /fix/
> (currentStrip
> + e); })) /map/ &Pool.addTask;
here is two I like:
#1: http://svn.dsource.org/projects/scrapple/trunk/bignum/bignum.d
#2:
struct TerminalStub
{
static assert(0 == TerminalStub.tupleof.length, "TerminalStub must have
no memebers");
/**
This union is used to pack data into a pointer for use when constructing
a delegate
*/
union pack
{
static assert(pack.sizeof == (void*).sizeof, "To mutch data in TerminalStub.pack");
struct
{
ushort l;
ushort h;
}
TerminalStub* TsPt;
}
/******************************************************************************
Eat a given length string from a CodeStream and place a given token in a
CodeSequence.
******************/
bool TextEaterGeneral(CodeStream ins, CodeSequence code)
{
pack pk;
pk.TsPt = this;
Token cons;
cons.type = cast(TokenType)pk.l;
cons.line = ins.getLine;
ins.Discard(pk.h);
code.Append(cons);
return true;
}
/***************************************
build a delegate with non-pointer data in the this pointer
params:
t = The token ID to generate
str = The string to remove
***************************************/
static OperatorParcer TextEater(TokenType t, dchar[] str)
{
TerminalStub.pack pk;
pk.h = str.length;
pk.l = t;
assert(pk.h == str.length, "value is to big: "~.toString(str.length));
assert(pk.l == t, "value is to big: "~.toString(cast(int)t));
return &pk.TsPt.TextEaterGeneral;
}
}
More information about the Digitalmars-d
mailing list