[Ecls-list] Tighter c/c++ integration, toplevel inline c/c++ code ???

Seth Burleigh seth at tewebs.com
Mon May 3 11:54:21 UTC 2010


Lets say i have a file called test.lisp and in it is this code:

(in-package :utils2)

(FFI:C-INLINE NIL
              NIL
              :VOID
              "void add (a b) {
       return a+b;
       }"
              :ONE-LINER
              NIL
              :SIDE-EFFECTS
              T)

If :side-effects is nil, ecl ignores the above statement. So, now what
does it produce in the c code? It places the above function which we
want in the global scope of the c file into the fasl initialization
function:




/*	Compiler: ECL 10.4.2                                          */
/*	Date: 2010/5/3 06:50 (yyyy/mm/dd)                             */
/*	Machine: Linux 2.6.31-20-generic i686                         */
/*	Source: /home/seth/install/test.lisp                          */
#include <ecl/ecl-cmp.h>
#include "/home/seth/install/test.h"
	
#include "/home/seth/install/test.data"
#ifdef __cplusplus
extern "C"
#endif
ECL_DLLEXPORT void init_fas_CODE(cl_object flag)
{ VT1 VLEX1 CLSR1 STCK1
	const cl_env_ptr cl_env_copy = ecl_process_env();
	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;
	flag->cblock.cfuns_size = compiler_cfuns_size;
	flag->cblock.cfuns = compiler_cfuns;
	flag->cblock.source =
make_constant_base_string("/home/seth/install/test.lisp");
	return;}
	#ifdef ECL_DYNAMIC_VV
	VV = Cblock->cblock.data;
	#endif
	Cblock->cblock.data_text = "@EcLtAg:init_fas_CODE@";
	VVtemp = Cblock->cblock.temp_data;
	(void)si_select_package(_ecl_static_0)    /*  SELECT-PACKAGE  */;
	void add (a b) {
       return a+b;
       }
}


As you can see, add is in the scope of the initialization function, not
in the 'toplevel' of the c file, i.e. outside of initialization
function.

Code which is required to be outside of initialization function includes
global scope c functions and c++ methods. Most everything else, i
believe, can go in the header file.








More information about the ecl-devel mailing list