DMD range support?

Sergey Gromov snake.scaly at gmail.com
Mon Jan 12 09:02:49 PST 2009


Mon, 12 Jan 2009 11:43:11 -0500, Steven Schveighoffer wrote:

> "Sergey Gromov" wrote
>> struct Generator(int start, int step, int end)
>> {
>>  private int head_ = start;
>>  int head() { return head_; }
>>  void next() { head_ += step; }
>>  bool empty() { return head_ > end; }
>> }
>>
>> import std.stdio;
>>
>> void main()
>> {
>>  Generator!(2, 7, 50) gen;
>>  foreach (i; gen)
>>    writefln(i);
>> }
> 
> I'd really like to know the code generation -- A delegate probably isn't 
> generated anymore?  I agree more documentation is sorely needed in the spec.

non-optimized asm:

__Dmain	comdat
	assume	CS:__Dmain
L0:		enter	4,0
		mov	EAX,_D4test24__T9GeneratorVi2Vi7Vi50Z9Generator6__initZ
		mov	-4[EBP],EAX
		mov	-4[EBP],EAX
LF:		lea	EAX,-4[EBP]
		call	near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator5emptyMFZb
		xor	AL,1
		je	L32
		lea	EAX,-4[EBP]
		call	near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator4headMFZi
		call	near ptr _D3std5stdio15__T8writeflnTiZ8writeflnFiZv
		lea	EAX,-4[EBP]
		call	near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator4nextMFZv
		jmp short	LF
L32:		xor	EAX,EAX
		leave
		ret
__Dmain	ends

optimized asm (-O -release -inline):

__Dmain	comdat
	assume	CS:__Dmain
L0:		push	EAX
		mov	EAX,_D4test24__T9GeneratorVi2Vi7Vi50Z9Generator6__initZ
		cmp	EAX,032h
		mov	[ESP],EAX
		jg	L25
LE:		push	[ESP]
		mov	EAX,0Ah
		call	near ptr _D3std5stdio15__T6writefTiTaZ6writefFiaZv
		add	[ESP],7
		cmp	[ESP],032h
		jle	LE
L25:		pop	ECX
		xor	EAX,EAX
		ret
__Dmain	ends

*Pretty* nice.



More information about the Digitalmars-d mailing list