The most twisted D code (you've) ever written

Daniel Keep daniel.keep.lists at gmail.com
Fri Oct 12 22:13:02 PDT 2007



downs wrote:
> 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

Sadly, I tend to actually try to write nice looking code, even if it
happens to be pure evil.

I suppose in that respect, the most terrifying thing I've ever
written[1] was a program that compiled new functions at runtime; a proof
of concept for turning a delegate into a function pointer that was
inspired by Tioport's need to call arbitrary native functions given only
a run-time description of their types.  Not bad looking, just really,
really evil.

One of these days, I might actually finish it.  :P

Here's the program itself: http://drk.is-a-geek.net/~drk/d/selfmod.d

And here's the in-memory x86 assembler it depends on:
http://drk.is-a-geek.net/~drk/d/x86.d

Historically speaking, though, the nastiest thing I've ever done
in-language was probably my collection of function unpacking templates.
 They abused IFTI in the nastiest way I could think of in order to work
out what types a function returned, took as arguments, and how many
arguments it took.

At least Kirk found them useful!  ;)

	-- Daniel

[1] The fake closures stuff comes a close second, though.



More information about the Digitalmars-d mailing list