add support for constants
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11251 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
25f17ae463
commit
4e9cbd8a7c
15 changed files with 470 additions and 142 deletions
|
|
@ -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 @@ To build an Scilab module, run SWIG using the <tt>-scilab</tt> option.
|
|||
<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 @@ $ ./scilab
|
|||
<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 @@ table = ["gcd","_wrap_gcd";"Foo_set","_wrap_Foo_set";"Foo_get","_wrap_Foo_get";]
|
|||
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 @@ Assuming all goes well, you will be able to do this:
|
|||
<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 @@ ans = 4 </pre></div>
|
|||
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 @@ clear get_file_path;
|
|||
// ------------------------------------------------------
|
||||
|
||||
</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 @@ ant=24 </pre></div>
|
|||
<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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1135,3 +1135,28 @@ r_clean:
|
|||
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*
|
||||
|
||||
|
|
|
|||
27
Examples/scilab/constants/example.i
Normal file
27
Examples/scilab/constants/example.i
Normal file
|
|
@ -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;
|
||||
|
||||
|
||||
15
Examples/scilab/constants/makefile
Normal file
15
Examples/scilab/constants/makefile
Normal file
|
|
@ -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
|
||||
32
Examples/scilab/constants/runme.sci
Normal file
32
Examples/scilab/constants/runme.sci
Normal file
|
|
@ -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");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
Examples/scilab/simple/makefile
Normal file
15
Examples/scilab/simple/makefile
Normal file
|
|
@ -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
|
||||
|
|
@ -5,6 +5,7 @@ exec builder.sce;
|
|||
exec loader.sce;
|
||||
|
||||
// Call our gcd() function
|
||||
|
||||
x = 42;
|
||||
y = 105;
|
||||
g = gcd(x,y);
|
||||
|
|
@ -16,8 +17,8 @@ printf("The gcd of %d and %d is %d\n",x,y,g);
|
|||
Foo_get()
|
||||
|
||||
// Change its value
|
||||
Foo_set = 3.1415926
|
||||
Foo_set(3.1415926)
|
||||
|
||||
//See if the change took effect
|
||||
Foo_get
|
||||
Foo_get()
|
||||
|
||||
|
|
|
|||
46
Examples/scilab/variables/example.c
Normal file
46
Examples/scilab/variables/example.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
27
Examples/scilab/variables/example.i
Normal file
27
Examples/scilab/variables/example.i
Normal file
|
|
@ -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();
|
||||
%}
|
||||
|
||||
15
Examples/scilab/variables/makefile
Normal file
15
Examples/scilab/variables/makefile
Normal file
|
|
@ -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
|
||||
45
Examples/scilab/variables/runme.sci
Normal file
45
Examples/scilab/variables/runme.sci
Normal file
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
%include <typemaps/swigmacros.swg>
|
||||
%include <typemaps/fragments.swg>
|
||||
%include <sciprimtype.swg>
|
||||
%include <sciprimtypes.swg>
|
||||
%include <scitypemaps.swg>
|
||||
|
||||
|
|
|
|||
1
Lib/scilab/sciprimtypes.swg
Normal file
1
Lib/scilab/sciprimtypes.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -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(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(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)
|
||||
{
|
||||
iRowsOut=1;
|
||||
iColsOut=1;
|
||||
createMatrixOfInteger8(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress);
|
||||
LhsVar(1)=Rhs+1;
|
||||
PutLhsVar();
|
||||
%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(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();
|
||||
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(out) int (int iRowsOut,int iColsOut,int* _piAddress),
|
||||
unsigned 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;
|
||||
createMatrixOfInteger32(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress);
|
||||
createMatrixOfInteger32(Rhs+1, iRowsOut, iColsOut, &temp, &_piAddress);
|
||||
LhsVar(1)=Rhs+1;
|
||||
PutLhsVar();
|
||||
}
|
||||
|
||||
|
||||
%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) 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) 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,noblock=1) void
|
||||
{
|
||||
%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) char *(int iRowsOut,int iColsOut,int* _piAddress){
|
||||
iRowsOut=1;
|
||||
iColsOut=1;
|
||||
createMatrixOfString(Rhs+1, iRowsOut, iColsOut, &$1, &_piAddress);
|
||||
LhsVar(1)=Rhs+1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class SCILAB:public Language {
|
|||
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,6 +99,9 @@ class SCILAB:public Language {
|
|||
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);
|
||||
|
|
@ -166,7 +169,7 @@ class SCILAB:public Language {
|
|||
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 @@ class SCILAB:public Language {
|
|||
}
|
||||
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 @@ class SCILAB:public Language {
|
|||
//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,13 +290,12 @@ class SCILAB:public Language {
|
|||
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);
|
||||
|
|
@ -304,7 +303,7 @@ class SCILAB:public Language {
|
|||
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 @@ class SCILAB:public Language {
|
|||
}
|
||||
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 @@ class SCILAB:public Language {
|
|||
} 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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue