digitalmars.D.learn - No mixin inside asm blocks
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (7/7) Jan 30 2013 A friend of mine is trying to figure out the D equivalent of using
- Philippe Sigaud (9/14) Jan 30 2013 do
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (43/57) Jan 30 2013 you do
A friend of mine is trying to figure out the D equivalent of using macros with asm blocks in C: #define NEXT() __asm__("jmp *%0"::"r"((++ip)->jmp)); goto *ip->jmp D's asm blocks are very restrictive: mixins are not allowed. What do you do in D? Thank you, Ali
Jan 30 2013
On Wed, Jan 30, 2013 at 4:01 PM, Ali =C3=87ehreli <acehreli yahoo.com> wrot= e:A friend of mine is trying to figure out the D equivalent of using macros with asm blocks in C: #define NEXT() __asm__("jmp *%0"::"r"((++ip)->jmp)); goto *ip->jmp D's asm blocks are very restrictive: mixins are not allowed. What do you =doin D?Is it possible to enclose an asm statement into a mixin? mixin(" asm { .... code to include }");
Jan 30 2013
On 01/30/2013 11:08 AM, Philippe Sigaud wrote:On Wed, Jan 30, 2013 at 4:01 PM, Ali Çehreli<acehreli yahoo.com> wrote:macrosA friend of mine is trying to figure out the D equivalent of usingyou dowith asm blocks in C: #define NEXT() __asm__("jmp *%0"::"r"((++ip)->jmp)); goto *ip->jmp D's asm blocks are very restrictive: mixins are not allowed. What doThanks! It is almost there, except that one needs to use a compile-time "macro expansion" solution, which I am too lazy to try now. :) I am confident that the following program will work after doing that. (Of course also after replacing 'writeln' with 'mixin'.) import std.stdio; import std.regex; string expandNexts(string input) { enum e = ctRegex!("Next;", "g"); // NOTE: This is an example. Of course, the second string below should be // whatever the "macro" should be expanded as. return replace(input, e, "cmp EAX,0;"); } void main() { writeln (expandNexts(q{ asm { mov EAX, 10000; Next; Next; Next; Next; Next; } })); } The program prints asm { mov EAX, 10000; cmp EAX,0; cmp EAX,0; cmp EAX,0; cmp EAX,0; cmp EAX,0; } Aliin D?Is it possible to enclose an asm statement into a mixin? mixin(" asm { .... code to include }");
Jan 30 2013