From: <spl...@us...> - 2009-06-13 13:14:36
|
Revision: 11251 http://swig.svn.sourceforge.net/swig/?rev=11251&view=rev Author: sploving Date: 2009-06-13 12:18:35 +0000 (Sat, 13 Jun 2009) Log Message: ----------- add support for constants Modified Paths: -------------- branches/gsoc2009-sploving/Doc/Manual/Scilab.html branches/gsoc2009-sploving/Examples/Makefile.in branches/gsoc2009-sploving/Examples/scilab/simple/runme.sci branches/gsoc2009-sploving/Lib/scilab/scilab.swg branches/gsoc2009-sploving/Lib/scilab/scitypemaps.swg branches/gsoc2009-sploving/Source/Modules/scilab.cxx Added Paths: ----------- branches/gsoc2009-sploving/Examples/scilab/constants/ branches/gsoc2009-sploving/Examples/scilab/constants/example.i branches/gsoc2009-sploving/Examples/scilab/constants/makefile branches/gsoc2009-sploving/Examples/scilab/constants/runme.sci branches/gsoc2009-sploving/Examples/scilab/simple/makefile branches/gsoc2009-sploving/Examples/scilab/variables/ branches/gsoc2009-sploving/Examples/scilab/variables/example.c branches/gsoc2009-sploving/Examples/scilab/variables/example.i branches/gsoc2009-sploving/Examples/scilab/variables/makefile branches/gsoc2009-sploving/Examples/scilab/variables/runme.sci branches/gsoc2009-sploving/Lib/scilab/sciprimtypes.swg Modified: branches/gsoc2009-sploving/Doc/Manual/Scilab.html =================================================================== --- branches/gsoc2009-sploving/Doc/Manual/Scilab.html 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Doc/Manual/Scilab.html 2009-06-13 12:18:35 UTC (rev 11251) @@ -23,6 +23,7 @@ <li><a href="#Scilab_nn8">Modules</a> <li><a href="#Scilab_nn9">Functions</a> <li><a href="#scilab_nn10">Global variables</a> +<li><a href="#Scilab_nn11">Constants</a> </ul> </ul> </div> @@ -66,7 +67,7 @@ <div class="shell"><pre>$ swig -scilab example.i </pre></div> <p> -This creates a C source file <tt>example_wrap.c</tt>and a interface file <tt>builder.sce</tt>. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C application (in this case, the gcd implementation) to create an extension module. And the builder.sce is used to generate the *.so file. +This creates a C source file <tt>example_wrap.c</tt> and a interface file <tt>builder.sce</tt>. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C application (in this case, the gcd implementation) to create an extension module. And the builder.sce is used to generate the *.so file. </p> <p> @@ -89,7 +90,7 @@ <p> where builder.sce is the interface file generated by the swig. It looks like the following: </p> -<div class="shell"><pre> +<div class="code"><pre> ilib_name = "examplelib"; files = ["example_wrap.c","example.o"]; libs = []; @@ -97,16 +98,21 @@ ilib_build(ilib_name,table,files,libs); </pre></div> - -<p> -"ilib_name" is the name of the lib we want to build. "table" contains the name of the C file and its wrapper file. "files" represent the .o file we want to compile, and"libs" is other libs we want to use. +<p>ilib_build(lib_name,table,files,libs) is used to create shared libraries and to generate a loader file which can be used to dynamically load the shared library into Scilab with addinter. </p> +<ul> +<li><tt><b>ilib_name</b></tt>: a character string, the generic name of the library without path and extension.</li> +<li><tt><b>files</b></tt>: string matrix giving objects files needed for shared library creation.</li> +<li><tt><b>libs</b></tt>: string matrix giving extra libraries needed for shred library creation.</li> +<li><tt><b>table</b></tt>: two column string matrix giving the table of pairs 'scilab-name', 'interface name'.</li> +</ul> + <p> "exec builder.sce" will produce *.so,and a file called "loader.sce" which contains how to load the module. Loading it into Scilab is then a matter of invoking </p> - <div class="targetlang"><pre>Scilab:1> exec loader.sce</pre></div> + <div class="shell"><pre>Scilab:1> exec loader.sce</pre></div> <H3><a name="Scilab_nn6"></a>36.2.2 Using your module</H3> @@ -119,9 +125,12 @@ <div class="targetlang"><pre> Scilab:2>gcd(4,6) ans = 2 + Scilab:3>Foo_get ans = 3 + Scilab:4>Foo_set(4); + Scilab:5>Foo_get ans = 4 </pre></div> @@ -135,7 +144,7 @@ The SWIG module directive specifies the name of the Scilab module. If you want to load the module, you'll need a file called "loader.sce" which is usually generated by the command "exec builder.sce". The loader.sce looks as following: </p> - <div class="targetlang"><pre> + <div class="code"><pre> // ------------------------------------------------------ // generated by builder.sce: Please do not edit this file // ------------------------------------------------------ @@ -153,6 +162,15 @@ // ------------------------------------------------------ </pre></div> +<p>addinter (files,spname,fcts) performs incremental linking of a compiled C new Scilab interface routine. +</p> +<ul> +<li><tt><b>files</b></tt>: a character string or a vector of character string contain object files used to define the new Scilab interface routine (interface code, user routines or libraries, system libraries).</li> +<li><tt><b>spname</b></tt>: a character string. Name of interface routine entry point.</li> +<li><tt><b>fcts</b></tt>: vector of character strings. The name of new Scilab function implemented in the new interface.</li> +</ul> + + <p> After you run the command "exec loader.sce", you could use the module. </pre> @@ -176,16 +194,55 @@ <H3><a name="scilab_nn10"></a>27.3.3 Global variables</H3> <p> - To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_set would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variables onto the C variable. + To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_get would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variables onto the C variable. </p> <div class="targetlang"><pre>scilab:1> exec loader.sce; -scilab:2> c=Foo -c = 3 -scilab:3> Foo=4; +scilab:2> c=Foo_get(); + +scilab:3> Foo_set(4); + scilab:4> c c = 3 -scilab:5> Foo + +scilab:5> Foo_get() ans = 4</pre></div> +<H3><a name="Scilab_nn11"></a>27.3.4 Constants</H3> +<p> + C constants are not really constant in Scilab. They are actually just a copy of the value into the Scilab interpreter. Therefore they can be changed just as any other value. For example given some constants: +</p> + + <div class="code"><pre>%module example +%constant int ICONST=42; +#define SCONST "Hello World" +</pre></div> + +<p> + This is 'effectively' converted into the following code in the wrapper file: +</p> + + <div class="code"><pre>.... +const int ICONST=42; +const char * SCONST="Hello World"; +.... +int ICONST_get (char *fname,unsigned long fname_len) {..} +int SCONST_get (char *fname,unsigned long fname_len) {..} +.... </pre></div> +<p>It is easy to use the C constants as global variables:</p> + + <div class="targetlang"><pre> +scilab:1> ICONST +ant = 42 + +scilab:2> SCONST +ant= Hello world + +scilab:3> c=SCONST() +c = Hello World +</pre></div> + + + + Modified: branches/gsoc2009-sploving/Examples/Makefile.in =================================================================== --- branches/gsoc2009-sploving/Examples/Makefile.in 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Examples/Makefile.in 2009-06-13 12:18:35 UTC (rev 11251) @@ -1135,3 +1135,28 @@ rm -f *.@OBJEXT@ *@SO@ NAMESPACE rm -f $(RRSRC) runme.Rout .RData +################################################################## +##### SCILAB ###### +################################################################## + +# Make sure these locate your Octave installation +SCILAB_INCLUDE= $(DEFS) @SCILABINCLUDE@ +SCILAB_LIB = @SCILABLIB@ +SCILAB = @SCILAB@ + + +# ---------------------------------------------------------------- +# Build a C dynamically loadable module +# ---------------------------------------------------------------- + +scilab: $(SRCS) + $(SWIG) -scilab $(SWIGOPT) $(INTERFACEPATH) + + +# ----------------------------------------------------------------- +# Cleaning the scilab examples +# ----------------------------------------------------------------- + +scilab_clean: + rm -f *_wrap* + Added: branches/gsoc2009-sploving/Examples/scilab/constants/example.i =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/constants/example.i (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/constants/example.i 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,27 @@ +/* File : example.i */ +%module example + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; + + Added: branches/gsoc2009-sploving/Examples/scilab/constants/makefile =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/constants/makefile (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/constants/makefile 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,15 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.i +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean:: + $(MAKE) -f $(TOP)/Makefile scilab_clean + rm -f *.sce *.so lib*lib.c + +check: all Added: branches/gsoc2009-sploving/Examples/scilab/constants/runme.sci =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/constants/runme.sci (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/constants/runme.sci 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,32 @@ +// builder the *.so +exec builder.sce; + +//loader the *.so +exec loader.sce; + +printf("ICONST = %i (should be 42)\n", ICONST()); +printf("FCONST = %f (should be 2.1828)\n", FCONST()); +printf("CCONST = %c (should be x)\n", CCONST()); +printf("CCONST2 = %s (this should be on a new line)\n", CCONST2()); +printf("SCONST = %s (should be Hello World)\n", SCONST()); +printf("SCONST2 = %s (should be Hello World)\n", SCONST2()); +printf("EXPR = %f (should be 48.5484)\n", EXPR()); +printf("iconst = %i (should be 37)\n", iconst()); +printf("fconst = %f (should be 3.14)\n", fconst()); + +try + printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN()); +catch + printf("EXTERN is not defined (good)\n"); + +try + printf("FOO = %i (Arg! This should not printf(anything)\n", FOO()); +catch + printf("FOO is not defined (good)\n"); + + + + + + + Added: branches/gsoc2009-sploving/Examples/scilab/simple/makefile =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/simple/makefile (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/simple/makefile 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,15 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean:: + $(MAKE) -f $(TOP)/Makefile scilab_clean + rm -f *.sce *.so lib*lib.c + +check: all Modified: branches/gsoc2009-sploving/Examples/scilab/simple/runme.sci =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/simple/runme.sci 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Examples/scilab/simple/runme.sci 2009-06-13 12:18:35 UTC (rev 11251) @@ -5,6 +5,7 @@ exec loader.sce; // Call our gcd() function + x = 42; y = 105; g = gcd(x,y); @@ -16,8 +17,8 @@ Foo_get() // Change its value -Foo_set = 3.1415926 +Foo_set(3.1415926) //See if the change took effect -Foo_get +Foo_get() Added: branches/gsoc2009-sploving/Examples/scilab/variables/example.c =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/variables/example.c (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/variables/example.c 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,46 @@ +/* File : example.c */ + +/* I'm a file containing some C global variables */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include <stdio.h> +#include <stdlib.h> +#include "sciprint.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar=0; + + +/* A debugging function to print out their values */ + +void print_vars() { + sciprint("ivar = %d\n", ivar); + sciprint("svar = %d\n", svar); + sciprint("lvar = %ld\n", lvar); + sciprint("uivar = %u\n", uivar); + sciprint("usvar = %u\n", usvar); + sciprint("ulvar = %lu\n", ulvar); + sciprint("scvar = %d\n", scvar); + sciprint("ucvar = %u\n", ucvar); + sciprint("fvar = %g\n", fvar); + sciprint("dvar = %g\n", dvar); + sciprint("cvar = %c\n", cvar); + sciprint("strvar = %s\n",strvar); +} + + + Added: branches/gsoc2009-sploving/Examples/scilab/variables/example.i =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/variables/example.i (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/variables/example.i 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,27 @@ +/* File : example.i */ +%module example + +#pragma SWIG nowarn=SWIGWARN_TYPEMAP_SWIGTYPELEAK + +/* Some global variable declarations */ +%inline %{ + extern int ivar; + extern short svar; + extern long lvar; + extern unsigned int uivar; + extern unsigned short usvar; + extern unsigned long ulvar; + extern signed char scvar; + extern unsigned char ucvar; + extern char cvar; + extern float fvar; + extern double dvar; + extern char *strvar; +%} + + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +%} + Added: branches/gsoc2009-sploving/Examples/scilab/variables/makefile =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/variables/makefile (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/variables/makefile 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,15 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean:: + $(MAKE) -f $(TOP)/Makefile scilab_clean + rm -f *.sce *.so lib*lib.c + +check: all Added: branches/gsoc2009-sploving/Examples/scilab/variables/runme.sci =================================================================== --- branches/gsoc2009-sploving/Examples/scilab/variables/runme.sci (rev 0) +++ branches/gsoc2009-sploving/Examples/scilab/variables/runme.sci 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1,45 @@ +// builder the *.so +exec builder.sce + +//loader the *.so +exec loader.sce + +// Try to set the values of some global variables + +ivar_set (42); +svar_set (31000); +lvar_set (65537); +uivar_set (123456); +usvar_set (61000); +ulvar_set (654321); +scvar_set (-13); +ucvar_set (251); +cvar_set ("S"); +fvar_set (3.14159); +dvar_set (2.1828); +strvar_set("Hello World"); + +// Now print out the values of the variables + +printf("Variables (values printed from Scilab)\n"); + +printf("ivar = %i\n", ivar_get()); +printf("svar = %i\n", svar_get()); +printf("lvar = %i\n", lvar_get()); +printf("uivar = %i\n", uivar_get()); +printf("usvar = %i\n", usvar_get()); +printf("ulvar = %i\n", ulvar_get()); +printf("scvar = %i\n", scvar_get()); +printf("ucvar = %i\n", ucvar_get()); +printf("fvar = %f\n", fvar_get()); +printf("dvar = %f\n", dvar_get()); +printf("cvar = %s\n", cvar_get()); +printf("strvar = %s\n", strvar_get()); + +printf("\nVariables (values printed from C)\n"); + +print_vars() + + + + Modified: branches/gsoc2009-sploving/Lib/scilab/scilab.swg =================================================================== --- branches/gsoc2009-sploving/Lib/scilab/scilab.swg 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Lib/scilab/scilab.swg 2009-06-13 12:18:35 UTC (rev 11251) @@ -1,5 +1,5 @@ %include <typemaps/swigmacros.swg> %include <typemaps/fragments.swg> -%include <sciprimtype.swg> +%include <sciprimtypes.swg> %include <scitypemaps.swg> Added: branches/gsoc2009-sploving/Lib/scilab/sciprimtypes.swg =================================================================== --- branches/gsoc2009-sploving/Lib/scilab/sciprimtypes.swg (rev 0) +++ branches/gsoc2009-sploving/Lib/scilab/sciprimtypes.swg 2009-06-13 12:18:35 UTC (rev 11251) @@ -0,0 +1 @@ + Modified: branches/gsoc2009-sploving/Lib/scilab/scitypemaps.swg =================================================================== --- branches/gsoc2009-sploving/Lib/scilab/scitypemaps.swg 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Lib/scilab/scitypemaps.swg 2009-06-13 12:18:35 UTC (rev 11251) @@ -12,131 +12,115 @@ //%include <typemaps/swigtypemaps.swg> -%typemap(in) char (int *piAddrVar, int iRows, int iCols), - signed char (int *piAddrVar, int iRows, int iCols), - unsigned char(int *piAddrVar, int iRows, int iCols) -{ - char* _piData8; - getVarAddressFromNumber($argnum, &piAddrVar); - getVarDimension(piAddrVar, &iRows, &iCols); - if(getVarType(piAddrVar) != sci_matrix || iRows1 != 1 || iCols1 != 1 || isVarComplex(piAddrVar)) - { - Scierror(999,_("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); - } - getMatrixOfInteger8(piAddrVar, &iRows, &iCols, &_piData8); - $1=_piData8[0]; +%typemap(in) signed char (int *piAddrVar, int iRows, int iCols), + unsigned char (int *piAddrVar, int iRows, int iCols), + short (int *piAddrVar, int iRows, int iCols), + unsigned short (int *piAddrVar, int iRows, int iCols), + int (int *piAddrVar, int iRows, int iCols), + unsigned int (int *piAddrVar, int iRows, int iCols), + long (int *piAddrVar, int iRows, int iCols), + unsigned long (int *piAddrVar, int iRows, int iCols), + float (int *piAddrVar, int iRows, int iCols), + double (int *piAddrVar, int iRows, int iCols) { + double* _piData; + getVarAddressFromNumber($argnum, &piAddrVar); + getVarDimension(piAddrVar, &iRows, &iCols); + + if (getVarType(piAddrVar) != sci_matrix || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) { + Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); + } + getMatrixOfDouble(piAddrVar, &iRows, &iCols, &_piData); + $1=($1_ltype)*_piData; } -%typemap(in) short (int *piAddrVar, int iRows, int iCols), - unsigned short (int *piAddrVar, int iRows, int iCols) - -{ short* _piData16; - getVarAddressFromNumber($argnum, &piAddrVar); - getVarDimension(piAddrVar, &iRows, &iCols); - if(getVarType(piAddrVar) != sci_matrix || iRows1 != 1 || iCols1 != 1 || isVarComplex(piAddrVar)) - { - Scierror(999,_("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); - } - getMatrixOfInteger16(piAddrVar, &iRows, &iCols, &_piData16); - $1= _piData16[0]; +%typemap(in) char (int *piAddrVar, int iRows, int iCols) { + char* _pstStrings; + int _piLength; + getVarAddressFromNumber($argnum, &piAddrVar); + getVarDimension(piAddrVar, &iRows, &iCols); + + if (getVarType(piAddrVar) != sci_strings || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) { + Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); + } + getMatrixOfString(piAddrVar, &iRows, &iCols,&_piLength, &_pstStrings); + $1=($1_ltype)*_pstStrings; } -%typemap(in) int (int *piAddrVar, int iRows, int iCols), - unsigned int (int *piAddrVar, int iRows, int iCols) - -{ int* _piData32; - getVarAddressFromNumber($argnum, &piAddrVar); - getVarDimension(piAddrVar, &iRows, &iCols); - if(getVarType(piAddrVar) != sci_matrix || iRows1 != 1 || iCols1 != 1 || isVarComplex(piAddrVar)) - { - Scierror(999,_("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); - } - getMatrixOfInteger16(piAddrVar, &iRows, &iCols, &_piData32); - $1= _piData32[0]; - +%typemap(out) signed char (int iRowsOut,int iColsOut,int* _piAddress) { + char temp; + temp=(char)$1; + iRowsOut=1; + iColsOut=1; + createMatrixOfInteger8(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress); + LhsVar(1)=Rhs+1; } -%typemap(in) long(int* piAddrVar,int iRows,int iCols), - unsigned long(int* piAddrVar,int iRows,int iCols), - double(int* piAddrVar,int iRows,int iCols), - float (int* piAddrVar,int iRows,int iCols) - -{ double *pdblReal; - getVarAddressFromNumber($argnum, &piAddrVar); - getVarDimension(piAddrVar, &iRows, &iCols); - if(getVarType(piAddrVar) != sci_matrix || iRows1 != 1 || iCols1 != 1 || isVarComplex(piAddrVar)) - { - Scierror(999,_("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); - } - getMatrixOfDouble(piAddrVar, &iRows, &iCols, &pdblReal); - $1= pdblReal[0]; - +%typemap(out) short (int iRowsOut,int iColsOut,int* _piAddress), + unsigned char (int iRowsOut,int iColsOut,int* _piAddress) { + short temp; + temp=(short)$1; + iRowsOut=1; + iColsOut=1; + createMatrixOfInteger16(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress); + LhsVar(1)=Rhs+1; } -/* -%typemap(in) char *(int m,int n,int l) -{ - if (GetType($argnum) == sci_strings) - { - GetRhsVar($argnum,STRING_DATATYPE,&m,&n,&l); - $1=($1_ltype)strdup(cstk(l)); - } - else - Scierror(999,"error ...\n"); - -}*/ - - -%typemap(out) char (int iRowsOut,int iColsOut,int* _piAddress), - signed char (int iRowsOut,int iColsOut,int* _piAddress), - unsigned char(int iRowsOut,int iColsOut,int* _piAddress) -{ +%typemap(out) int (int iRowsOut,int iColsOut,int* _piAddress), + unsigned int (int iRowsOut,int iColsOut,int* _piAddress), + unsigned short (int iRowsOut,int iColsOut,int* _piAddress), + unsigned long (int iRowsOut,int iColsOut,int* _piAddress), + long (int iRowsOut,int iColsOut,int* _piAddress) { + int temp; + temp=(int)$1; iRowsOut=1; iColsOut=1; - createMatrixOfInteger8(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress); + createMatrixOfInteger32(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress); LhsVar(1)=Rhs+1; - PutLhsVar(); } -%typemap(out) short (int iRowsOut,int iColsOut,int* _piAddress), - unsigned short(int iRowsOut,int iColsOut,int* _piAddress) - -{ - iRowsOut=1; - iColsOut=1; - createMatrixOfInteger16(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress); - LhsVar(1)=Rhs+1; - PutLhsVar(); + +%typemap(out) double (int iRowsOut,int iColsOut,int* _piAddress), + float (int iRowsOut,int iColsOut,int* _piAddress) { + double temp; + temp=(double)$1; + iRowsOut=1; + iColsOut=1; + createMatrixOfDouble(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress); + LhsVar(1)=Rhs+1; } -%typemap(out) int (int iRowsOut,int iColsOut,int* _piAddress), - unsigned int(int iRowsOut,int iColsOut,int* _piAddress) - -{ - iRowsOut=1; - iColsOut=1; - createMatrixOfInteger32(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress); - LhsVar(1)=Rhs+1; - PutLhsVar(); +%typemap(out) char (int iRowsOut,int iColsOut,int* _piAddress) { + char* temp; + temp=(char*)&$1; + iRowsOut=1; + iColsOut=1; + createMatrixOfString(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress); + LhsVar(1)=Rhs+1; } -%typemap(out) long(int iRowsOut,int iColsOut,int* _piAddress), - unsigned long(int iRowsOut,int iColsOut,int* _piAddress), - double(int iRowsOut,int iColsOut,int* _piAddress), - float(int iRowsOut,int iColsOut,int* _piAddress) -{ - iRowsOut=1; - iColsOut=1; - createMatrixDouble(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress); - LhsVar(1)=Rhs+1; - PutLhsVar(); +%typemap(out,noblock=1) void { } +%typemap(in) char *(int *piAddrVar, int iRows, int iCols) { + char* _pstStrings; + int _piLength; + getVarAddressFromNumber($argnum, &piAddrVar); + getVarDimension(piAddrVar, &iRows, &iCols); + + if (getVarType(piAddrVar) != sci_strings || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) { + Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, 1); + } + getMatrixOfString(piAddrVar, &iRows, &iCols,&_piLength, &_pstStrings); + $1=strdup(_pstStrings); +} -%typemap(out,noblock=1) void -{ +%typemap(out) char *(int iRowsOut,int iColsOut,int* _piAddress){ + iRowsOut=1; + iColsOut=1; + createMatrixOfString(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress); + LhsVar(1)=Rhs+1; } Modified: branches/gsoc2009-sploving/Source/Modules/scilab.cxx =================================================================== --- branches/gsoc2009-sploving/Source/Modules/scilab.cxx 2009-06-07 19:31:37 UTC (rev 11250) +++ branches/gsoc2009-sploving/Source/Modules/scilab.cxx 2009-06-13 12:18:35 UTC (rev 11251) @@ -72,7 +72,7 @@ f_begin = NewFile(outfile, "w", SWIG_output_files()); /*Another output file to generate the .so or .dll */ - String *builder = NewString("builder.sce"); + String *builder = NewStringf("%sbuilder.sce",SWIG_output_directory()); f_builder=NewFile(builder,"w",SWIG_output_files()); /* Initialize all of the output files */ @@ -99,7 +99,10 @@ Printf(f_runtime, "#include \"stack-c.h\"\n"); Printf(f_runtime, "#include \"sciprint.h\"\n"); Printf(f_runtime, "#include \"Scierror.h\"\n"); + Printf(f_runtime, "#include \"variable_api.h\"\n"); + Printf(f_runtime, "#include \"localization.h\"\n"); + /*Initialize the builder.sce file*/ Printf(f_builder,"ilib_name = \"%slib\";\n",module); Printf(f_builder,"files = [\"%s\",\"%s.o\"];\n", outfile,module); @@ -166,7 +169,7 @@ if (overloaded) Append(overname, Getattr(n, "sym:overname")); - Printv(f->def, "int ", overname, " (char *fname){", NIL); + Printv(f->def, "int ", overname, " (char *fname,unsigned long fname_len) {", NIL); // Emit all of the local variables for holding arguments emit_parameter_variables(l, f); @@ -209,8 +212,8 @@ } String *getargs = NewString(""); Printv(getargs, tm, NIL); - Printv(f->code, getargs, "\n", NIL); - Delete(getargs); + Printv(f->code, getargs, "\n", NIL); + Delete(getargs); p = Getattr(p, "tmap:in:next"); continue; } else { @@ -228,22 +231,19 @@ //Insert the return variable emit_return_variable(n, d, f); - if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) { + if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) { Printf(f->code, "%s\n", tm); } - else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname); + else { + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname); } /* Insert argument output code */ String *outarg = NewString(""); for (p = l; p;) { if ((tm = Getattr(p, "tmap:argout"))) { - Replaceall(tm, "$result", "_outp"); - //Replaceall(tm, "$arg", Getattr(p, "emit:input")); - //Replaceall(tm, "$input", Getattr(p, "emit:input")); Printv(outarg, tm, "\n", NIL); p = Getattr(p, "tmap:argout:next"); } else { @@ -290,21 +290,20 @@ String *getname = Swig_name_get(iname); String *setname = Swig_name_set(iname); - Printv(setf->def, "int ", setname, " (char *fname){", NIL); + Printv(setf->def, "int ", setname, " (char *fname,unsigned long fname_len) {", NIL); Wrapper_add_local(setf, "piAddrVar", "int *piAddrVar"); Wrapper_add_local(setf, "iRows", "int iRows"); Wrapper_add_local(setf, "iCols", "int iCols"); - // Wrapper_add_local(setf, "pdblReal", "double *pdblReal"); + - if (is_assignable(n)) { Setattr(n, "wrap:name", setname); if ((tm = Swig_typemap_lookup("in", n, name, 0))) { Replaceall(tm, "$source", "args(0)"); Replaceall(tm, "$target", name); Replaceall(tm, "$input", "args(0)"); - Replaceall(tm, "$argnum", "1"); + Replaceall(tm, "$argnum", "1"); //if (Getattr(n, "tmap:varin:implicitconv")) { //Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); //} @@ -319,11 +318,11 @@ } Append(setf->code, "}\n"); Wrapper_print(setf, f_wrappers); - Printf(f_builder, "\"%s\",\"%s\";",iname,setname); + Printf(f_builder, "\"%s\",\"%s\";",setname,setname); Setattr(n, "wrap:name", getname); int addfail = 0; - Printv(getf->def, "int ", getname, " (char *fname){", NIL); + Printv(getf->def, "int ", getname, " (char *fname,unsigned long fname_len){", NIL); Wrapper_add_local(getf, "piAddrOut", "int* _piAddress"); Wrapper_add_local(getf, "iRows", "int iRowsOut"); @@ -338,20 +337,59 @@ } else { Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); } - //Append(getf->code, " return obj;\n"); - //if (addfail) { - //Append(getf->code, "fail:\n"); - //Append(getf->code, " return octave_value_list();\n"); - //} + Append(getf->code, "}\n"); Wrapper_print(getf, f_wrappers); - Printf(f_builder, "\"%s\",\"%s\";",iname,getname); + Printf(f_builder, "\"%s\",\"%s\";",getname,getname); return SWIG_OK; } + /* ----------------------------------------------------------------------- + * constantWrapper() + * ----------------------------------------------------------------------- */ + + virtual int constantWrapper(Node *n) { + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; + + if (!addSymbol(iname, n)) + return SWIG_ERROR; + + Wrapper *getf = NewWrapper(); + String *getname = Swig_name_get(iname); + + Setattr(n, "wrap:name", getname); + Printv(getf->def, "int ", getname, " (char *fname,unsigned long fname_len) {", NIL); + + Wrapper_add_local(getf, "piAddrOut", "int* _piAddress"); + Wrapper_add_local(getf, "iRows", "int iRowsOut"); + Wrapper_add_local(getf, "iColsOut", "int iColsOut "); + + if ((tm = Swig_typemap_lookup("out", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "obj"); + Replaceall(tm, "$result", "obj"); + emit_action_code(n, getf->code, tm); + Delete(tm); + } else { + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(type, 0)); + } + + Append(getf->code, "}\n"); + Wrapper_print(getf, f_wrappers); + Printf(f_header, "const %s %s=%s;\n",SwigType_str(type,0),iname,value); + Printf(f_builder, "\"%s\",\"%s\";",iname,getname); + + return SWIG_OK; + } + }; extern "C" Language *swig_scilab(void) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |