Re: Passing Arrays of Structs to NCI Subs

2004-04-28 Thread Leopold Toetsch
Chromatic [EMAIL PROTECTED] wrote:

 No problem.  Fair warning, though: nci_test doesn't build by default on
 Linux PPC.  I had to build it manually then copy it into
 runtime/parrot/dynext/.

That's the current procedure, yes. I don't know, if all platforms
support dynamic loading - probably not. So we need some config setting
for this.

 After adding a signature for vpP to src/nci_call.txt and rebuilding,
 only test 5 fails.  That might be due to differences in the size of
 shorts on this platform as compared to i386; just a guess.  (The return
 value is 128, while the test expects -128).

Signed vs unsigned char probably. I've changed the test bit.

 Anyhow, I've attached a new test which shows of more or less my idea for
 what this should do.  It may be horribly wrong, but it's wrong in a way
 that has actual code, not just vague ideas.

Not very wrong, but ... Anyway the syntax is:

  Px[Rect; 0; x] # rect[0].x  named access of Rect
  Px[  0   ; 2; h] # rect[2].h  idx

Constructions differs too.
Please have a look at the test.

#29200 applied.

 On the other hand, I'm really *not* a C programmer.

 -- c

Thanks,
leo


Re: Passing Arrays of Structs to NCI Subs

2004-04-28 Thread chromatic
On Wed, 2004-04-28 at 03:06, Leopold Toetsch wrote:

 Not very wrong, but ... Anyway the syntax is:
 
   Px[Rect; 0; x] # rect[0].x  named access of Rect
   Px[  0   ; 2; h] # rect[2].h  idx
 
 Constructions differs too.
 Please have a look at the test.

Ahh, that makes sense after squinting the right way for a minute.  I've
updated my SDL Parrot snapshot; the working code is now in
SDL::Surface::update_rects().

http://wgz.org/chromatic/parrot/sdl/

Building the array of rects is a little cumbersome, but now it's nicely
encapsulated where I don't have to think about it.

Thanks, Leo!

-- c



Re: Passing Arrays of Structs to NCI Subs

2004-04-27 Thread chromatic
On Tue, 2004-04-20 at 02:13, Leopold Toetsch wrote:

 Can you provide some test code (s. t/pmc/nci.t and src/nci_test.c) for
 signatures similar to the real:

  extern DECLSPEC void SDLCALL SDL_UpdateRects
  (SDL_Surface *screen, int numrects, SDL_Rect *rects);

No problem.  Fair warning, though: nci_test doesn't build by default on
Linux PPC.  I had to build it manually then copy it into
runtime/parrot/dynext/.

After commenting out the skipall() which doesn't like my platform, tests
5 and 27-29 fail.  More importantly, the other tests pass.

After adding a signature for vpP to src/nci_call.txt and rebuilding,
only test 5 fails.  That might be due to differences in the size of
shorts on this platform as compared to i386; just a guess.  (The return
value is 128, while the test expects -128).

Anyhow, I've attached a new test which shows of more or less my idea for
what this should do.  It may be horribly wrong, but it's wrong in a way
that has actual code, not just vague ideas.

On the other hand, I'm really *not* a C programmer.

-- c


Index: t/pmc/nci.t
===
RCS file: /cvs/public/parrot/t/pmc/nci.t,v
retrieving revision 1.35
diff -u -u -r1.35 nci.t
--- t/pmc/nci.t	8 Mar 2004 00:20:09 -	1.35
+++ t/pmc/nci.t	28 Apr 2004 04:06:07 -
@@ -17,7 +17,7 @@
 
 =cut
 
-use Parrot::Test tests = 29;
+use Parrot::Test tests = 30;
 use Parrot::Config;
 
 print STDERR $PConfig{jitcpuarch},  JIT CPU\n;
 output_is('CODE', 'OUTPUT', nci_d_d);
@@ -1014,6 +1015,63 @@
 user data: 42
 external data: 77
 done.
+OUTPUT
+
+output_is('CODE', 'OUTPUT', 'array of structs');
+  loadlib P1, libnci
+  dlfunc P0, P1, nci_pip, pip
+.include datatypes.pasm
+  new P3, .OrderedHash
+  set  P3[x], .DATATYPE_INT
+  push P3, 0
+  push P3, 0
+  set  P3[y], .DATATYPE_INT
+  push P3, 0
+  push P3, 0
+  set  P3[w], .DATATYPE_INT
+  push P3, 0
+  push P3, 0
+  set  P3[h], .DATATYPE_INT
+  push P3, 0
+  push P3, 0
+
+  new P5, .ManagedStruct, P3
+  set P5['x'], 100
+  set P5['y'], 100
+  set P5['w'], 100
+  set P5['h'], 100
+
+  new P6, .ManagedStruct, P3
+  set P6['x'], 200
+  set P6['y'], 200
+  set P6['w'], 200
+  set P6['h'], 200
+
+  new P7, .ManagedStruct, P3
+  set P7['x'], 300
+  set P7['y'], 300
+  set P7['w'], 300
+  set P7['h'], 300
+
+  new P8, .ManagedStruct, P3
+  set P8['x'], 400
+  set P8['y'], 400
+  set P8['w'], 400
+  set P8['h'], 400
+
+  set I5, 4
+  set I0, 1
+  set I1, 1
+  set I3, 4
+
+  invoke
+
+CODE
+Count: 4
+X: 100
+Y: 200
+W: 300
+H: 400
 OUTPUT
 } # SKIP
 
Index: src/nci_test.c
===
RCS file: /cvs/public/parrot/src/nci_test.c,v
retrieving revision 1.22
diff -u -u -r1.22 nci_test.c
--- src/nci_test.c	9 Feb 2004 15:54:47 -	1.22
+++ src/nci_test.c	28 Apr 2004 04:06:38 -
@@ -28,6 +28,14 @@
 typedef void (*cb_D1_func)(void*, const char*);
 void nci_cb_D1(cb_D1_func, void*);
 
+typedef struct
+{
+	int x, y;
+	int w, h;
+} Rect_Like;
+
+void nci_pip (int count, Rect_Like *rects);
+
 double nci_dd(double d) {
 return d * 2.0;
 }
@@ -255,6 +263,12 @@
 const char *result = succeeded;
 /* call the cb synchronously */
 (cb)(user_data, result);
+}
+
+void nci_pip (int count, Rect_Like *rects)
+{
+	printf( Count: %d\nX: %d\nY: %d\nW: %d\nH: %d, 
+		count, rects[0].x, rects[1].y, rects[2].w, rects[3].h );
 }
 
 #ifdef TEST
Index: src/call_list.txt
===
RCS file: /cvs/public/parrot/src/call_list.txt,v
retrieving revision 1.29
Index: src/call_list.txt
===
RCS file: /cvs/public/parrot/src/call_list.txt,v
retrieving revision 1.29
diff -u -u -r1.29 call_list.txt
--- src/call_list.txt	30 Mar 2004 10:23:25 -	1.29
+++ src/call_list.txt	28 Apr 2004 04:08:21 -
@@ -209,3 +209,7 @@
 # Used by library/sdl.imc
 p	iiil
 i	ppl
+
+# used by t/pmc/nci.t
+v	pP
+p	ip


Passing Arrays of Structs to NCI Subs

2004-04-20 Thread chromatic
What's the secret syntax for passing and retriving arrays of things to
and from NCI?  I have this signature:

extern DECLSPEC void SDLCALL SDL_UpdateRects
(SDL_Surface *screen, int numrects, SDL_Rect *rects);

That'd be *very* handy to expose.

(Yeah, Dan, I know you said you had something in mind.)

-- c




Re: Passing Arrays of Structs to NCI Subs

2004-04-20 Thread Leopold Toetsch
Chromatic [EMAIL PROTECTED] wrote:
 What's the secret syntax for passing and retriving arrays of things to
 and from NCI?  I have this signature:

There is no secret syntax:

,--[ docs/pmc/struct.pod ]-
|Array Size
|The second initializer item, if set to a value greater
|then 1, defines the struct element to consist of an
|array of the given data type.
`--

*but* it's just not implemented for arrays of struct or struct* :)

Somewhere after unmanagedstruct.pmc:136 the Ccount has to be considered,
probably by incrementing Cp by the needed size.

Can you provide some test code (s. t/pmc/nci.t and src/nci_test.c) for
signatures similar to the real:

   extern DECLSPEC void SDLCALL SDL_UpdateRects
   (SDL_Surface *screen, int numrects, SDL_Rect *rects);

leo