www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - mixins as inline functions

reply Serg Kovrov <kovrov no.spam> writes:
First time I looked at mixins in D reference, I thought that it could be 
used as inline function. Like a big C macro. But better =)

It has its own scope, it has access to parent scope, everything seems 
fit. Except that in mixins it is not possible to use assign operations. 
Could this restriction be removed in future? Is there any plans for 
mixins evolution?

-- 
serg.
Aug 18 2006
next sibling parent "Craig Black" <cblack ara.com> writes:
There should definitely be plans for the evolution of mixins.  The feature 
is way jacked up and unusable for a lot of things that should work.  I don't 
forsee anything changing for 1.0 though.

-Craig

"Serg Kovrov" <kovrov no.spam> wrote in message 
news:ec402d$pgv$1 digitaldaemon.com...
 First time I looked at mixins in D reference, I thought that it could be 
 used as inline function. Like a big C macro. But better =)

 It has its own scope, it has access to parent scope, everything seems fit. 
 Except that in mixins it is not possible to use assign operations. Could 
 this restriction be removed in future? Is there any plans for mixins 
 evolution?

 -- 
 serg. 
Aug 18 2006
prev sibling parent reply Walter Bright <newshound digitalmars.com> writes:
Serg Kovrov wrote:
 First time I looked at mixins in D reference, I thought that it could be 
 used as inline function. Like a big C macro. But better =)
 
 It has its own scope, it has access to parent scope, everything seems 
 fit. Except that in mixins it is not possible to use assign operations. 
 Could this restriction be removed in future? Is there any plans for 
 mixins evolution?
Why not just use inline functions?
Aug 18 2006
parent reply Serg Kovrov <kovrov no.spam> writes:
Walter Bright wrote:
 Serg Kovrov wrote:
 First time I looked at mixins in D reference, I thought that it could 
 be used as inline function. Like a big C macro. But better =)

 It has its own scope, it has access to parent scope, everything seems 
 fit. Except that in mixins it is not possible to use assign 
 operations. Could this restriction be removed in future? Is there any 
 plans for mixins evolution?
Why not just use inline functions?
Er... Because there is no inline functions? =) But if seriously, does virtual methods (accessing 'this') can be inlined? -- serg.
Aug 18 2006
next sibling parent Sean Kelly <sean f4.ca> writes:
Serg Kovrov wrote:
 Walter Bright wrote:
 Serg Kovrov wrote:
 First time I looked at mixins in D reference, I thought that it could 
 be used as inline function. Like a big C macro. But better =)

 It has its own scope, it has access to parent scope, everything seems 
 fit. Except that in mixins it is not possible to use assign 
 operations. Could this restriction be removed in future? Is there any 
 plans for mixins evolution?
Why not just use inline functions?
Er... Because there is no inline functions? =) But if seriously, does virtual methods (accessing 'this') can be inlined?
In some cases, yes, if the compiler can determine that the result will be correct. However, use of function pointers and delegates is not inlined. For this reason, I sometimes use a struct with opCall defined instead (as these calls are inlined by DMD in many cases). I haven't figured out the magic formula for having an opCall be inlined however (I should really look at the DMD front-end code and figure it out). Sometimes simply adding "static" to the opCall declaration is enough to have the function go from inlined to not, and in other cases an opCall that is inlined in one routine is not inlined in another. I'm currently wrestling with this in a quicksort implementation I've been tweaking. If you don't mind the work, the best thing is to simply experiment (compile with "-inline -release -O") and view the output with obj2asm. Sean
Aug 18 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
Serg Kovrov wrote:
 Walter Bright wrote:
 Serg Kovrov wrote:
 First time I looked at mixins in D reference, I thought that it could 
 be used as inline function. Like a big C macro. But better =)

 It has its own scope, it has access to parent scope, everything seems 
 fit. Except that in mixins it is not possible to use assign 
 operations. Could this restriction be removed in future? Is there any 
 plans for mixins evolution?
Why not just use inline functions?
Er... Because there is no inline functions? =)
All functions are candidates for inlining.
 But if seriously, does virtual methods (accessing 'this') can be inlined?
Functions accessed through the virtual function pointer table cannot be inlined. Mixins can't fix that. To access a function directly, rather than through virtual dispatch, declare it to be 'final'.
Aug 18 2006