digitalmars.D.learn - Several questions (about inline assembly, ddoc for templates, and foreach)
- Marcio (14/14) Aug 19 2006 Hi all,
- Chris Nicholson-Sauls (24/41) Aug 19 2006 I'm not sure. Of course, pending a real solution from someone who knows...
- Marcio (20/46) Aug 19 2006 Yes, that's what I'm doing currently.
- Thomas Kuehne (18/33) Aug 19 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Sean Kelly (9/35) Aug 20 2006 I think this is actually required. According to the ABI
- Thomas Kuehne (17/31) Aug 20 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Sean Kelly (7/38) Aug 20 2006 The whole ABI needs a rewrite in terms of pointer size rather than fixed...
- Chris Nicholson-Sauls (27/44) Aug 19 2006 Huh. I could've sworn it used to work that way... but no matter, I just...
- Marcio (17/31) Aug 19 2006 Thanks! It must've been my fault, perhaps I was doing something wrong an...
- Thomas Kuehne (23/49) Aug 19 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Marcio (3/17) Aug 19 2006 That only works for dynamically created arrays, but thanks anyway!
Hi all, I have several questions I cannot find elsewhere: 1 - Using inline assembly, how can I access the "ptr" attribute of an array? For example: void main() { int[] array; asm { mov EAX, array.ptr; } } The compiler says: "identifier expected". 2 - Is Ddoc working for templates? If it is, I can't make it generate the documentation for some template functions... 3 - Is there a way to manually increment the index of a foreach loop? I ask this because the index cannot be made inout, only the value. Thanks,
Aug 19 2006
Marcio wrote:Hi all, I have several questions I cannot find elsewhere: 1 - Using inline assembly, how can I access the "ptr" attribute of an array? For example: void main() { int[] array; asm { mov EAX, array.ptr; } } The compiler says: "identifier expected".I'm not sure. Of course, pending a real solution from someone who knows better, you could do this:2 - Is Ddoc working for templates? If it is, I can't make it generate the documentation for some template functions... 3 - Is there a way to manually increment the index of a foreach loop? I ask this because the index cannot be made inout, only the value.Any reason why you can't make the index inout? I've done it often enough myself to this very effect. Of course, I'm sure its undefined behavior with associative arrays, but with fixed/variable-length arrays it works just fine.Thanks,
Aug 19 2006
Chris Nicholson-Sauls wrote:(...) I'm not sure. Of course, pending a real solution from someone who knows better,you coulddo this:Yes, that's what I'm doing currently.this because the index cannot be made inout,3 - Is there a way to manually increment the index of a foreach loop? I askto thisonly the value.Any reason why you can't make the index inout? I've done it often enough myselfvery effect. Of course, I'm sure its undefined behavior with associativearrays, but withfixed/variable-length arrays it works just fine.Are you sure that works? I've just tested the following code with DMD v0.164 (in Linux): void main() { char[] arr = "test"; foreach (inout i, inout c; arr) { if (i == 0) { i++; continue; } } } And the compiler says: "foreach: key cannot be out". Did you use the last version?
Aug 19 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Marcio schrieb am 2006-08-19:Chris Nicholson-Sauls wrote:It's implemntation dependent. Phobos, GPhobos and Ares currently use Thus you could write(32-bit systems only): Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE527pLK5blCcjpWoRAm6eAJ44HPK1AmaPJ6Zdair6dTd7rnbaGwCfT6oR AgavCz0umlrBm+skjkL7H7I= =7N6c -----END PGP SIGNATURE-----(...) I'm not sure. Of course, pending a real solution from someone who knows better,you coulddo this:Yes, that's what I'm doing currently.
Aug 19 2006
Thomas Kuehne wrote:-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Marcio schrieb am 2006-08-19:I think this is actually required. According to the ABI (http://www.digitalmars.com/d/abi.html): Arrays A dynamic array consists of: offset contents 0 array dimension 4 pointer to array data SeanChris Nicholson-Sauls wrote:It's implemntation dependent. Phobos, GPhobos and Ares currently use(...) I'm not sure. Of course, pending a real solution from someone who knows better,you coulddo this:Yes, that's what I'm doing currently.
Aug 20 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sean Kelly schrieb am 2006-08-20:Thomas Kuehne wrote:Thus on a 64bit system, an array may only contain (2^32 - 1) elements and every access suffers from a bad alignment of the data pointer? Walter's ABI and Phobos are going to require quite a bit of a makeover if they are ported to a non-32bit system. A sample: Phobos: dmd/src/phobos/internal/aaA.d:454 long _aaValues(AA aa, size_t keysize, size_t valuesize) GPhobos(from gdc): d/phobos/internal/aaA.d:456 Array _aaValues(AA aa, size_t keysize, size_t valuesize) Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE6NYlLK5blCcjpWoRArjhAJ9EcyU1PZPbjLyIhdV8dwGMlC4uLgCghW82 6f8fgglEHaIwkLc9HBbGklk= =5i4c -----END PGP SIGNATURE-----It's implementation dependent. Phobos, GPhobos and Ares currently useI think this is actually required. According to the ABI (http://www.digitalmars.com/d/abi.html): Arrays A dynamic array consists of: offset contents 0 array dimension 4 pointer to array data
Aug 20 2006
Thomas Kuehne wrote:-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sean Kelly schrieb am 2006-08-20:The whole ABI needs a rewrite in terms of pointer size rather than fixed offset.Thomas Kuehne wrote:Thus on a 64bit system, an array may only contain (2^32 - 1) elements and every access suffers from a bad alignment of the data pointer?It's implementation dependent. Phobos, GPhobos and Ares currently useI think this is actually required. According to the ABI (http://www.digitalmars.com/d/abi.html): Arrays A dynamic array consists of: offset contents 0 array dimension 4 pointer to array dataWalter's ABI and Phobos are going to require quite a bit of a makeover if they are ported to a non-32bit system. A sample: Phobos: dmd/src/phobos/internal/aaA.d:454 long _aaValues(AA aa, size_t keysize, size_t valuesize) GPhobos(from gdc): d/phobos/internal/aaA.d:456 Array _aaValues(AA aa, size_t keysize, size_t valuesize)Yup. Fortunately, most of the pointer size-related diffs between Phobos and GPhobos are in this file, so the changes shouldn't be too onerous. Particularly since they can all be revealed by a diff between the two. Sean
Aug 20 2006
Marcio wrote:Are you sure that works? I've just tested the following code with DMD v0.164 (in Linux): void main() { char[] arr = "test"; foreach (inout i, inout c; arr) { if (i == 0) { i++; continue; } } } And the compiler says: "foreach: key cannot be out". Did you use the last version?Huh. I could've sworn it used to work that way... but no matter, I just wrote the following and it worked fine (DMD 0.164): Turns out the 'inout' isn't neccessary anyhow. This prints, as I expected: [ 0] 1 [ 1] 2 [ 4] 4 [ 5] 5 [ 8] 7 [ 9] 8 [12] 10 -- Chris Nicholson-Sauls
Aug 19 2006
Chris Nicholson-Sauls wrote:Huh. I could've sworn it used to work that way... but no matter, I just wrote the following and it worked fine (DMD 0.164): (...) Turns out the 'inout' isn't neccessary anyhow. This prints, as I expected: (...)Thanks! It must've been my fault, perhaps I was doing something wrong and I couldn't get it to work. Thomas Kuehne wrote:It's implemntation dependent. Phobos, GPhobos and Ares currently use Thus you could write(32-bit systems only):Just tested the following code, using DMD v0.164 (in Linux), and it didn't work: //---------------------------------------------------- void main() { static uint[3] array = [0xC0DE, 0xBEEF, 0xF00D]; uint* a = null; asm { mov EAX, [array + 4]; mov a, EAX; } writefln(a); // Prints: BEEF } //---------------------------------------------------- Any ideas?
Aug 19 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Marcio schrieb am 2006-08-19:Thomas Kuehne wrote:Static arrays are special :X Try And replace with something like Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE55u3LK5blCcjpWoRAvqHAJ4jCwdfq4eiMY3Q9nRZShIbhR7q5wCgk/rL PmehAwIRT8emFAesQwWU2Vs= =0uiF -----END PGP SIGNATURE-----It's implemntation dependent. Phobos, GPhobos and Ares currently use Thus you could write(32-bit systems only):Just tested the following code, using DMD v0.164 (in Linux), and it didn't work: //---------------------------------------------------- void main() { static uint[3] array = [0xC0DE, 0xBEEF, 0xF00D]; uint* a = null; asm { mov EAX, [array + 4]; mov a, EAX; } writefln(a); // Prints: BEEF } //---------------------------------------------------- Any ideas?
Aug 19 2006
Thomas Kuehne wrote:Static arrays are special :X Try And replace with something likeThat only works for dynamically created arrays, but thanks anyway! So there's really no way to do something like that with a static array?
Aug 19 2006