[Ecls-list] About Embed ECL into C programs

David_Creelman at pa.com.au David_Creelman at pa.com.au
Mon Nov 20 03:14:28 UTC 2006


Hi Huang,
I think cl_def_c_function is used to import a C function into ECL (at least
that's what I used it for), but here it looks like you're trying to use it
to go the other way (so, I don't think it will work)
Since you've got a complete ECL environment once you've done, cl_boot, you
could try doing a cl_eval of "(play-cards args)" in C and getting back it's
result?
If you want it to go more quickly, you could compile the lisp and load a
.fas file rather than the lisp.
I'd do it here to show you what I mean, but I can't get CVS access and the
latest tarball doesn't work for me on Cygwin (I'm on Win32).
Good luck.
DC



                                                                                                                                            
                      "Huang Jianshi"                                                                                                       
                      <hadeshuang at gmail.com>              To:       "Juan Jose Garcia-Ripoll" <juanjose.garciaripoll at googlemail.com>        
                      Sent by:                            cc:       ecls-list at lists.sourceforge.net                                         
                      ecls-list-bounces at lists.sour        Subject:  Re: [Ecls-list] About Embed ECL into C programs                         
                      ceforge.net                                                                                                           
                                                                                                                                            
                                                                                                                                            
                      20/11/2006 11:32 AM                                                                                                   
                                                                                                                                            
                                                                                                                                            




Ok, let me state my problem clear. I have a poker game client written
in C and I want to add some logic to the client. I wrote the logic
part in Lisp and left the communication part in C.

I need to submit it in the form of source code so the people there
could make a standalone program on their machine (I'm in a programming
contest actually). I use ECL to generate the player.c from lisp code.
Actually, it has two entries: change-cards-entry and play-cards-entry,
and after the lisp-to-C compilation, their name became
L1change_cards_entry and L2play_cards_entry, in player.c

So I wrote the interface for the 2 functions in lisp_interface.c.
Their function is just to wrap the C array into cl_array, and the
element type is fixnum. For testing, change-cards-entry and
play-cards-entry simply print out the data they receive.

That's the senarios. And I got these compilation errors. I could paste
the code here. So here it is:

[lisp_interface.c]

#include <ecl.h>
#include "lisp/player.c"


void cl_select_cards_to_change(int cards[8][15]) {

  int i,j;

  cl_object element_type = cl_make_symbol(make_base_string_copy("fixnum"));
  cl_object table = si_make_pure_array(6, element_type, Cnil, Cnil,
Cnil, 8, 15);

  /* boxing */
  for (i = 0; i < 8; i++) {
             for (j = 0; j < 15; j++) {
               cl_object value = make_integer(cards[i][j]);
               aset(aref(table, i), j, value); /* fill the data into the
cl_array */
             }
  }

  /* here, call the lisp function */
  table = L1change_cards_entry(table);

  /* unboxing */
  for (i = 0; i < 8; i++) {
             for (j = 0; j < 15; j++) {
               int value = fixint(aref(aref(table, i), j));
               cards[i][j] = value;                    /* change the cards
*/
             }
  }


}




void cl_select_cards_to_play(int cards[8][15]) {

  int i,j;

  cl_object element_type = cl_make_symbol(make_base_string_copy("fixnum"));
  cl_object table = si_make_pure_array(6, element_type, Cnil, Cnil,
Cnil, 8, 15);

  /* boxing */
  for (i = 0; i < 8; i++) {
             for (j = 0; j < 15; j++) {
               cl_object value = make_integer(cards[i][j]);
               aset(aref(table, i), j, value); /* fill the data into the
cl_array */
             }
  }

  /* here, call the lisp function */
  table = L2play_cards_entry(table);

  /* unboxing */
  for (i = 0; i < 8; i++) {
             for (j = 0; j < 15; j++) {
               int value = fixint(aref(aref(table, i), j));
               cards[i][j] = value;                    /* change the cards
*/
             }
  }


}


[player.lisp]

(defun change-cards-entry (table)
  (let ((row-dim (array-dimension table 0))
                         (col-dim (array-dimension table 1)))
             (dotimes (i row-dim)
               (dotimes (j col-dim)
                         (princ (aref table i j))))))

(defun play-cards-entry (table)
  (let ((row-dim (array-dimension table 0))
                         (col-dim (array-dimension table 1)))
             (dotimes (i row-dim)
               (dotimes (j col-dim)
                         (princ (aref table i j))))))



[player.c] -- generated by player.lisp


/*           function definition for CHANGE-CARDS-ENTRY
*/
static cl_object L1change_cards_entry(cl_object V1)
{ VT2 VLEX2 CLSR2
             cl_object value0;
             {
TTL:
             {cl_object V2;                            /*  ROW-DIM
                        */
             cl_object V3;                             /*  NIL
                         */
             cl_fixnum V4;                             /*  COL-DIM
                         */
             V3= cl_array_dimension(V1,MAKE_FIXNUM(0)) /*  ARRAY-DIMENSION
*/;
             V4= object_to_fixnum(cl_array_dimension(V1,MAKE_FIXNUM(1)) /*
ARRAY-DIMENSION */);
             V2= V3;
             {cl_object V5;                            /*  I
                        */
             V5= MAKE_FIXNUM(0);
             goto L9;
L8:;
             {cl_object V6;                            /*  %DOTIMES-VAR
                        */
             cl_object V7;                             /*  J
                         */
             V6= MAKE_FIXNUM(V4);
             V7= MAKE_FIXNUM(0);
             goto L15;
L14:;
             T0= cl_aref(3,V1,V5,V7)                   /*  AREF
               */;
             princ(T0,Cnil);
             V7= one_plus(V7);
L15:;
             if(!(number_compare(V7,V6)<0)){           goto L19;}
             goto L14;
L19:;
             goto L10;
             }
L10:;
             V5= one_plus(V5);
L9:;
             if(!(number_compare(V5,V2)<0)){           goto L23;}
             goto L8;
L23:;
             value0=Cnil; NVALUES=1;
             return value0;
             }
             }
             }
}
/*           function definition for PLAY-CARDS-ENTRY
*/
static cl_object L2play_cards_entry(cl_object V1)
{ VT3 VLEX3 CLSR3
             cl_object value0;
             {
TTL:
             {cl_object V2;                            /*  ROW-DIM
                        */
             cl_object V3;                             /*  NIL
                         */
             cl_fixnum V4;                             /*  COL-DIM
                         */
             V3= cl_array_dimension(V1,MAKE_FIXNUM(0)) /*  ARRAY-DIMENSION
*/;
             V4= object_to_fixnum(cl_array_dimension(V1,MAKE_FIXNUM(1)) /*
ARRAY-DIMENSION */);
             V2= V3;
             {cl_object V5;                            /*  I
                        */
             V5= MAKE_FIXNUM(0);
             goto L34;
L33:;
             {cl_object V6;                            /*  %DOTIMES-VAR
                        */
             cl_object V7;                             /*  J
                         */
             V6= MAKE_FIXNUM(V4);
             V7= MAKE_FIXNUM(0);
             goto L40;
L39:;
             T0= cl_aref(3,V1,V5,V7)                   /*  AREF
               */;
             princ(T0,Cnil);
             V7= one_plus(V7);
L40:;
             if(!(number_compare(V7,V6)<0)){           goto L44;}
             goto L39;
L44:;
             goto L35;
             }
L35:;
             V5= one_plus(V5);
L34:;
             if(!(number_compare(V5,V2)<0)){           goto L48;}
             goto L33;
L48:;
             value0=Cnil; NVALUES=1;
             return value0;
             }
             }
             }
}

#include
"/Users/huangjianshi/tmp/daihinmin20061106/client/lisp/player.data"
#ifdef __cplusplus
extern "C"
#endif
void init_CODE(cl_object flag)
{ VT1 CLSR1
             cl_object value0;
             cl_object *VVtemp;
             if (!FIXNUMP(flag)){          Cblock=flag;
             #ifndef ECL_DYNAMIC_VV
             flag->cblock.data = VV;
             #endif
             flag->cblock.data_size = VM;
             flag->cblock.temp_data_size = VMtemp;
             flag->cblock.data_text = compiler_data_text;
             flag->cblock.data_text_size = compiler_data_text_size;
             return;}
             #ifdef ECL_DYNAMIC_VV
             VV = Cblock->cblock.data;
             #endif
             VVtemp = Cblock->cblock.temp_data;
             cl_def_c_function(VV[0],(void*)L1change_cards_entry,1);
             cl_def_c_function(VV[1],(void*)L2play_cards_entry,1);
}



Regards,
p-s.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Ecls-list mailing list
Ecls-list at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list










More information about the ecl-devel mailing list