From 5939ce6971607b83b33c2ac0ede627a83670113a Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 23 Oct 2010 19:53:03 -0700 Subject: Move std_complex.i to gnuradio-core/src/lib/swig/guile. Seems to basically work. There's some simple test code inline in gnuradio_core_general.i. --- gnuradio-core/src/lib/swig/.gitignore | 77 +++++++++------------- gnuradio-core/src/lib/swig/Makefile.am | 4 ++ gnuradio-core/src/lib/swig/gnuradio.i | 6 +- gnuradio-core/src/lib/swig/gnuradio_core_general.i | 20 ++++++ gnuradio-core/src/lib/swig/guile/std_complex.i | 30 +++++++++ 5 files changed, 89 insertions(+), 48 deletions(-) create mode 100644 gnuradio-core/src/lib/swig/guile/std_complex.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/swig/.gitignore b/gnuradio-core/src/lib/swig/.gitignore index 0018a2a54..75d6ce5b7 100644 --- a/gnuradio-core/src/lib/swig/.gitignore +++ b/gnuradio-core/src/lib/swig/.gitignore @@ -10,51 +10,34 @@ /swigrun.py /swigrun_wrap.c /Makefile.swigdeps.new -/gnuradio_core_runtime.d -/gnuradio_core_general.d -/gnuradio_core_gengen.d -/gnuradio_core_filter.d -/gnuradio_core_io.d /gnuradio_swig_bug_workaround.h -/gnuradio_core_runtime.cc -/gnuradio_core_runtime.h -/gnuradio_core_runtime.py -/gnuradio_core_general.cc -/gnuradio_core_general.h -/gnuradio_core_general.py -/gnuradio_core_gengen.cc -/gnuradio_core_gengen.h -/gnuradio_core_gengen.py -/gnuradio_core_filter.cc -/gnuradio_core_filter.h -/gnuradio_core_filter.py -/gnuradio_core_io.cc -/gnuradio_core_io.h -/gnuradio_core_io.py -/gnuradio_core_hier.cc -/gnuradio_core_hier.h -/gnuradio_core_hier.py -/gnuradio_core_filter_python.cc -/gnuradio_core_filter_python.h -/gnuradio_core_general_python.cc -/gnuradio_core_general_python.h -/gnuradio_core_gengen_python.cc -/gnuradio_core_gengen_python.h -/gnuradio_core_hier_python.cc -/gnuradio_core_hier_python.h -/gnuradio_core_io_python.cc -/gnuradio_core_io_python.h -/gnuradio_core_runtime_python.cc -/gnuradio_core_runtime_python.h -/gnuradio_core_filter.scm -/gnuradio_core_filter_guile.cc -/gnuradio_core_general.scm -/gnuradio_core_general_guile.cc -/gnuradio_core_gengen.scm -/gnuradio_core_gengen_guile.cc -/gnuradio_core_hier.scm -/gnuradio_core_hier_guile.cc -/gnuradio_core_io.scm -/gnuradio_core_io_guile.cc -/gnuradio_core_runtime.scm -/gnuradio_core_runtime_guile.cc +gnuradio_core_filter.cc +gnuradio_core_filter.d +gnuradio_core_filter.h +gnuradio_core_filter.py +gnuradio_core_filter.scm +gnuradio_core_general.cc +gnuradio_core_general.d +gnuradio_core_general.h +gnuradio_core_general.py +gnuradio_core_general.scm +gnuradio_core_gengen.cc +gnuradio_core_gengen.d +gnuradio_core_gengen.h +gnuradio_core_gengen.py +gnuradio_core_gengen.scm +gnuradio_core_hier.cc +gnuradio_core_hier.d +gnuradio_core_hier.h +gnuradio_core_hier.py +gnuradio_core_hier.scm +gnuradio_core_io.cc +gnuradio_core_io.d +gnuradio_core_io.h +gnuradio_core_io.py +gnuradio_core_io.scm +gnuradio_core_runtime.cc +gnuradio_core_runtime.d +gnuradio_core_runtime.h +gnuradio_core_runtime.py +gnuradio_core_runtime.scm diff --git a/gnuradio-core/src/lib/swig/Makefile.am b/gnuradio-core/src/lib/swig/Makefile.am index fb8577f72..f30b877a1 100644 --- a/gnuradio-core/src/lib/swig/Makefile.am +++ b/gnuradio-core/src/lib/swig/Makefile.am @@ -50,6 +50,10 @@ swiginclude_HEADERS = \ gr_swig_block_magic.i \ gr_shared_ptr.i +# SWIG headers that get installed in ${prefix}/include/gnuradio/swig/... +nobase_swiginclude_HEADERS = \ + guile/std_complex.i + if GUILE # This is the top level guile file, which loads all the other scm files diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index ec0264107..a30655f45 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -42,8 +42,12 @@ // non-local SWIG files %include -%include %include +#ifdef SWIGGUILE +%include +#else +%include +#endif typedef std::complex gr_complex; typedef std::complex gr_complexd; diff --git a/gnuradio-core/src/lib/swig/gnuradio_core_general.i b/gnuradio-core/src/lib/swig/gnuradio_core_general.i index a82f1f5b3..3edca69ef 100644 --- a/gnuradio-core/src/lib/swig/gnuradio_core_general.i +++ b/gnuradio-core/src/lib/swig/gnuradio_core_general.i @@ -29,6 +29,26 @@ %include "general.i" + // Simple test case for complex input and output +%inline +%{ + std::complex complexf_add_2j(std::complex x) + { + return std::complex(x.real(), x.imag() + 2); + } + + std::complex complexd_add_2j(std::complex x) + { + return std::complex(x.real(), x.imag() + 2); + } + + std::complex complexf_add_x_2j(float x, std::complex y) + { + return std::complex(x + y.real(), y.imag() + 2); + } + +%} + #if SWIGGUILE %scheme %{ (load-extension "libguile-gnuradio_core_general" "SWIG_init") diff --git a/gnuradio-core/src/lib/swig/guile/std_complex.i b/gnuradio-core/src/lib/swig/guile/std_complex.i new file mode 100644 index 000000000..cafcfeae3 --- /dev/null +++ b/gnuradio-core/src/lib/swig/guile/std_complex.i @@ -0,0 +1,30 @@ +%{ +#include +%} + +// To the target language, complex number conversion +%typemap(out) complex, complex, std::complex { + $result = scm_make_rectangular( gh_double2scm ($1.real ()), + gh_double2scm ($1.imag ()) ); +} + +// To the target language, complex number conversion +%typemap(out) complex, complex, std::complex { + $result = scm_make_rectangular( gh_double2scm ($1.real ()), + gh_double2scm ($1.imag ()) ); +} + +// From the target language, complex number conversion +%typemap(in) complex, complex, std::complex { + $1 = std::complex( gh_scm2double (scm_real_part ($input)), + gh_scm2double (scm_imag_part ($input)) ); +} + +// From the target language, complex number conversion +%typemap(in) complex, complex, std::complex { + $1 = std::complex( gh_scm2double (scm_real_part ($input)), + gh_scm2double (scm_imag_part ($input)) ); +} + +%typemaps_primitive(%checkcode(CPLXDBL), std::complex); +%typemaps_primitive(%checkcode(CPLXFLT), std::complex); -- cgit