replug funptr, newfun and clearfun 90/15190/3
Antoine ELIAS [Tue, 9 Sep 2014 14:59:25 +0000 (16:59 +0200)]
Change-Id: I359ef755b33cc887baa5a7d3e47f2d1d485fb192

25 files changed:
scilab/modules/ast/includes/symbol/context.hxx
scilab/modules/ast/includes/symbol/libraries.hxx
scilab/modules/ast/includes/symbol/variables.hxx
scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/core/Makefile.am
scilab/modules/core/Makefile.in
scilab/modules/core/includes/core_gw.hxx
scilab/modules/core/includes/gw_core.h
scilab/modules/core/sci_gateway/c/sci_clearfun.c [deleted file]
scilab/modules/core/sci_gateway/c/sci_funptr.c [deleted file]
scilab/modules/core/sci_gateway/c/sci_newfun.c [deleted file]
scilab/modules/core/sci_gateway/cpp/core_gw.cpp
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj.filters
scilab/modules/core/sci_gateway/cpp/sci_clear.cpp
scilab/modules/core/sci_gateway/cpp/sci_clearfun.cpp [new file with mode: 0644]
scilab/modules/core/sci_gateway/cpp/sci_funptr.cpp [new file with mode: 0644]
scilab/modules/core/sci_gateway/cpp/sci_newfun.cpp [new file with mode: 0644]
scilab/modules/core/tests/unit_tests/clearfun.dia.ref
scilab/modules/core/tests/unit_tests/clearfun.tst
scilab/modules/core/tests/unit_tests/funptr.dia.ref
scilab/modules/core/tests/unit_tests/funptr.tst
scilab/modules/core/tests/unit_tests/newfun.dia.ref
scilab/modules/core/tests/unit_tests/newfun.tst
scilab/modules/functions/macros/fun2string.sci

index 81a3f0b..80b04ed 100644 (file)
@@ -36,6 +36,9 @@ namespace symbol
 class EXTERN_AST Context
 {
 public :
+    typedef std::map<Symbol, Variable*> VarList;
+    typedef std::stack<VarList*> VarStack;
+
     static Context* getInstance(void);
 
     static void destroyInstance(void);
@@ -120,8 +123,6 @@ private :
     types::InternalType* get(const Symbol& key, int _iLevel);
     bool clearCurrentScope(bool _bClose);
 
-    typedef std::map<Symbol, Variable*> VarList;
-    typedef std::stack<VarList*> VarStack;
     std::list<Symbol>* globals;
     VarStack varStack;
     Variables variables;
index b2037c0..e1a6314 100644 (file)
@@ -35,6 +35,8 @@ struct ScopedLibrary
 
 struct Library
 {
+    typedef std::stack<ScopedLibrary*> StackLib;
+
     Library(const Symbol& _name) : name(_name) {};
 
     void put(types::Library* _pLib, int _iLevel)
@@ -95,7 +97,6 @@ struct Library
     }
 
 private :
-    typedef std::stack<ScopedLibrary*> StackLib;
     StackLib stack;
     Symbol name;
     bool m_global;
@@ -103,6 +104,8 @@ private :
 
 struct Libraries
 {
+    typedef std::map<Symbol, Library*> MapLibs;
+
     Libraries() {};
 
     Library* getOrCreate(const Symbol& _key)
@@ -203,7 +206,6 @@ struct Libraries
     }
 
 private:
-    typedef std::map<Symbol, Library*> MapLibs;
     MapLibs libs;
 };
 }
index c925bce..1c88a03 100644 (file)
@@ -33,6 +33,8 @@ struct ScopedVariable
 
 struct Variable
 {
+    typedef std::stack<ScopedVariable*> StackVar;
+
     Variable(const Symbol& _name) : name(_name), m_Global(false), m_GlobalValue(NULL) {};
     ~Variable()
     {
@@ -183,12 +185,13 @@ private :
     Symbol name;
     types::InternalType* m_GlobalValue;
     bool m_Global;
-    typedef std::stack<ScopedVariable*> StackVar;
     StackVar stack;
 };
 
 struct Variables
 {
+    typedef std::map<Symbol, Variable*> MapVars;
+
     Variables() {};
 
     Variable* getOrCreate(const Symbol& _key)
@@ -451,7 +454,6 @@ struct Variables
     }
 
 private:
-    typedef std::map<Symbol, Variable*> MapVars;
     MapVars vars;
 };
 }
index 2193613..48b5936 100644 (file)
@@ -275,7 +275,7 @@ bool Context::putInPreviousScope(Variable* _var, types::InternalType* _pIT)
 bool Context::addFunction(types::Function *_info)
 {
     Variable* var = variables.getOrCreate(Symbol(_info->getName()));
-    variables.putInPreviousScope(var, _info, 1);
+    variables.putInPreviousScope(var, _info, 0);
     return true;
 }
 
index 4777ac9..22a2835 100644 (file)
@@ -139,6 +139,9 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/core_gw.cpp \
        sci_gateway/cpp/sci_getmodules.cpp \
        sci_gateway/cpp/sci_clear.cpp \
+       sci_gateway/cpp/sci_clearfun.cpp \
+       sci_gateway/cpp/sci_newfun.cpp \
+       sci_gateway/cpp/sci_funptr.cpp \
        sci_gateway/cpp/sci_banner.cpp \
        sci_gateway/cpp/sci_quit.cpp \
        sci_gateway/cpp/sci_exit.cpp \
index 204e7c6..9b1f1ce 100644 (file)
@@ -284,6 +284,9 @@ am__objects_4 = sci_gateway/c/libscicore_la-gw_core.lo \
 am__objects_5 = sci_gateway/cpp/libscicore_la-core_gw.lo \
        sci_gateway/cpp/libscicore_la-sci_getmodules.lo \
        sci_gateway/cpp/libscicore_la-sci_clear.lo \
+       sci_gateway/cpp/libscicore_la-sci_clearfun.lo \
+       sci_gateway/cpp/libscicore_la-sci_newfun.lo \
+       sci_gateway/cpp/libscicore_la-sci_funptr.lo \
        sci_gateway/cpp/libscicore_la-sci_banner.lo \
        sci_gateway/cpp/libscicore_la-sci_quit.lo \
        sci_gateway/cpp/libscicore_la-sci_exit.lo \
@@ -833,6 +836,9 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/core_gw.cpp \
        sci_gateway/cpp/sci_getmodules.cpp \
        sci_gateway/cpp/sci_clear.cpp \
+       sci_gateway/cpp/sci_clearfun.cpp \
+       sci_gateway/cpp/sci_newfun.cpp \
+       sci_gateway/cpp/sci_funptr.cpp \
        sci_gateway/cpp/sci_banner.cpp \
        sci_gateway/cpp/sci_quit.cpp \
        sci_gateway/cpp/sci_exit.cpp \
@@ -1414,6 +1420,15 @@ sci_gateway/cpp/libscicore_la-sci_getmodules.lo:  \
 sci_gateway/cpp/libscicore_la-sci_clear.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscicore_la-sci_clearfun.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscicore_la-sci_newfun.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscicore_la-sci_funptr.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscicore_la-sci_banner.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1537,6 +1552,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_argn.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_banner.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clear.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clearfun.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clearglobal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_errclear.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_error.Plo@am__quote@
@@ -1544,6 +1560,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_exit.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_format.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_funcprot.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_funptr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_getmd5.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_getmemory.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_getmodules.Plo@am__quote@
@@ -1556,6 +1573,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_isglobal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_lasterror.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_mode.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_newfun.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_pause.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_quit.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_sciargs.Plo@am__quote@
@@ -2197,6 +2215,27 @@ sci_gateway/cpp/libscicore_la-sci_clear.lo: sci_gateway/cpp/sci_clear.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_clear.lo `test -f 'sci_gateway/cpp/sci_clear.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_clear.cpp
 
+sci_gateway/cpp/libscicore_la-sci_clearfun.lo: sci_gateway/cpp/sci_clearfun.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscicore_la-sci_clearfun.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clearfun.Tpo -c -o sci_gateway/cpp/libscicore_la-sci_clearfun.lo `test -f 'sci_gateway/cpp/sci_clearfun.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_clearfun.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clearfun.Tpo sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_clearfun.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_clearfun.cpp' object='sci_gateway/cpp/libscicore_la-sci_clearfun.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_clearfun.lo `test -f 'sci_gateway/cpp/sci_clearfun.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_clearfun.cpp
+
+sci_gateway/cpp/libscicore_la-sci_newfun.lo: sci_gateway/cpp/sci_newfun.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscicore_la-sci_newfun.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_newfun.Tpo -c -o sci_gateway/cpp/libscicore_la-sci_newfun.lo `test -f 'sci_gateway/cpp/sci_newfun.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_newfun.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_newfun.Tpo sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_newfun.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_newfun.cpp' object='sci_gateway/cpp/libscicore_la-sci_newfun.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_newfun.lo `test -f 'sci_gateway/cpp/sci_newfun.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_newfun.cpp
+
+sci_gateway/cpp/libscicore_la-sci_funptr.lo: sci_gateway/cpp/sci_funptr.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscicore_la-sci_funptr.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_funptr.Tpo -c -o sci_gateway/cpp/libscicore_la-sci_funptr.lo `test -f 'sci_gateway/cpp/sci_funptr.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_funptr.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_funptr.Tpo sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_funptr.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_funptr.cpp' object='sci_gateway/cpp/libscicore_la-sci_funptr.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_funptr.lo `test -f 'sci_gateway/cpp/sci_funptr.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_funptr.cpp
+
 sci_gateway/cpp/libscicore_la-sci_banner.lo: sci_gateway/cpp/sci_banner.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscicore_la-sci_banner.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_banner.Tpo -c -o sci_gateway/cpp/libscicore_la-sci_banner.lo `test -f 'sci_gateway/cpp/sci_banner.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_banner.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_banner.Tpo sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_banner.Plo
index fec28bd..e249ea3 100644 (file)
@@ -63,5 +63,8 @@ CPP_GATEWAY_PROTOTYPE(sci_where);
 CPP_GATEWAY_PROTOTYPE(sci_getmemory);
 CPP_GATEWAY_PROTOTYPE(sci_errclear);
 CPP_GATEWAY_PROTOTYPE(sci_intppty);
+CPP_GATEWAY_PROTOTYPE(sci_newfun);
+CPP_GATEWAY_PROTOTYPE(sci_clearfun);
+CPP_GATEWAY_PROTOTYPE(sci_funptr);
 
 #endif /* __CORE_GW_HXX__ */
index 0e1b11c..7bd4862 100644 (file)
@@ -59,7 +59,7 @@ int C2F(sci_comp)(char *fname, unsigned long fname_len);
 
 //C_GATEWAY_PROTOTYPE(sci_typename); -> c++
 int C2F(sci_funcprot)(char *fname, void* pvApiCtx);
-int C2F(sci_newfun)(char *fname, void* pvApiCtx);
+//int C2F(sci_newfun)(char *fname, void* pvApiCtx); -> C++
 
 //Yasp
 C_GATEWAY_PROTOTYPE(sci_type);
diff --git a/scilab/modules/core/sci_gateway/c/sci_clearfun.c b/scilab/modules/core/sci_gateway/c/sci_clearfun.c
deleted file mode 100644 (file)
index 1384e1f..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.  The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-#include "gw_core.h"
-#include "stack-c.h"
-#include "stack-def.h"
-#include "MALLOC.h"
-#include "hashtable_core.h"
-#include "Scierror.h"
-#include "Funtab.h"
-#include "localization.h"
-/*--------------------------------------------------------------------------*/
-int C2F(sci_clearfun)(char *fname, unsigned long fname_len)
-{
-    static int l1 = 0, n1 = 0, m1 = 0;
-    int *Status = NULL;
-
-    CheckRhs(1, 1);
-    CheckLhs(1, 1);
-
-    if (GetType(1) == sci_strings)
-    {
-        char *VarName = NULL;
-        int id[nsiz];
-        int zero = 0;
-        int fptr = 0;
-        int job = 0;
-
-        GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
-        VarName = cstk(l1);
-
-        Status = (int*)MALLOC(sizeof(int));
-
-        C2F(cvname)(id, VarName, &zero, (unsigned long)strlen(VarName));
-        job = SCI_HFUNCTIONS_FIND; /* Find function & returns fptr value */
-        C2F(funtab)(id, &fptr, &job, "NULL_NAME", 0);
-
-        if (fptr != 0)
-        {
-            job = SCI_HFUNCTIONS_DELETE; /* delete function entry */
-            C2F(funtab)(id, &fptr, &job, "NULL_NAME", 0);
-            *Status = TRUE;
-        }
-        else /* fptr = 0 function doesn't exist */
-        {
-            *Status = FALSE;
-        }
-        m1 = 1;
-        n1 = 1;
-        CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &Status);
-        LhsVar(1) = Rhs + 1;
-
-        if (Status)
-        {
-            FREE(Status);
-            Status = NULL;
-        }
-        PutLhsVar();
-    }
-    else
-    {
-        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
-        return 0;
-    }
-
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
-
diff --git a/scilab/modules/core/sci_gateway/c/sci_funptr.c b/scilab/modules/core/sci_gateway/c/sci_funptr.c
deleted file mode 100644 (file)
index 188df1b..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.  The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-#include "gw_core.h"
-#include "stack-c.h"
-#include "localization.h"
-#include "hashtable_core.h"
-#include "Scierror.h"
-#include "Funtab.h"
-#include "stack-def.h"
-/*--------------------------------------------------------------------------*/
-int C2F(sci_funptr) (char *fname, unsigned long fname_len)
-{
-    CheckRhs(1, 1);
-    CheckLhs(1, 1);
-
-    if ( GetType(1) == sci_strings )
-    {
-        char *VarName = NULL;
-        int m1 = 0, n1 = 0, l1 = 0;
-        int id[nsiz];
-        int funptr = 0;
-        int zero = 0;
-        int one = 1;
-        int job = SCI_HFUNCTIONS_FIND; /* Find function & returns fptr value */
-
-        GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
-        VarName = cstk(l1);
-
-        C2F(cvname)(id, VarName, &zero, (unsigned long)strlen(VarName));
-        C2F(funtab)(id, &funptr, &job, "NULL_NAME", 0);
-
-        CreateVar(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &l1);
-        *istk(l1) = funptr;
-
-        LhsVar(1) = Rhs + 1;
-        PutLhsVar();
-    }
-    else
-    {
-        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
-    }
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/sci_gateway/c/sci_newfun.c b/scilab/modules/core/sci_gateway/c/sci_newfun.c
deleted file mode 100644 (file)
index 602aeb2..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2006 - 2008 - INRIA - Allan CORNET
-* Copyright (C) 2008 - INRIA - Bruno JOFRET
-* Copyright (C) 2009 - DIGITEO - Allan CORNET
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-*
-*/
-#include <string.h>
-#include <ctype.h>
-#include "gw_core.h"
-#include "BOOL.h"
-#include "api_scilab.h"
-#include "Funtab.h"
-#include "IsAScalar.h"
-#include "hashtable_core.h"
-#include "Scierror.h"
-#include "localization.h"
-#include "MALLOC.h"
-/*--------------------------------------------------------------------------*/
-static BOOL Is_a_correct_function_name(char *functionname);
-/*--------------------------------------------------------------------------*/
-int C2F(sci_newfun) (char *fname, void* pvApiCtx)
-{
-    SciErr sciErr;
-    int m1 = 0, n1 = 0;
-    int iType1                                         = 0;
-    int *piAddressVarOne       = NULL;
-    char *pStVarOne                            = NULL;
-    int lenStVarOne                            = 0;
-
-    int m2 = 0, n2 = 0;
-    int iType2                                         = 0;
-    int *piAddressVarTwo       = NULL;
-    double *pdVarTwo                   = NULL;
-
-    int ifptr = 0;
-
-    CheckRhs(2, 2);
-    CheckLhs(1, 1);
-
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
-    }
-
-    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-        return 0;
-    }
-
-    sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
-    }
-
-    sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-        return 0;
-    }
-
-    if ( iType1 != sci_strings )
-    {
-        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
-        return 0;
-    }
-
-    if ( iType2 != sci_matrix )
-    {
-        Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2);
-        return 0;
-    }
-
-    sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, NULL);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
-    }
-
-    if ( (m1 != 1) || (n1 != 1) )
-    {
-        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
-        return 0;
-    }
-
-    sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdVarTwo);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-        return 0;
-    }
-
-    if ( (m2 != 1) || (n2 != 1) )
-    {
-        Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1);
-        return 0;
-    }
-
-    ifptr = (int) * pdVarTwo;
-    if (*pdVarTwo != (double)ifptr)
-    {
-        Scierror(999, _("%s: Wrong value for input argument #%d: An integer expected.\n"), fname, 2);
-        return 0;
-    }
-
-    pStVarOne = (char*)MALLOC(sizeof(char) * (lenStVarOne + 1));
-    if (pStVarOne)
-    {
-        sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, &pStVarOne);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-            return 0;
-        }
-    }
-    else
-    {
-        Scierror(999, _("%s: Memory allocation error.\n"), fname);
-        return 0;
-    }
-
-    if (ifptr > 0)
-    {
-        if (Is_a_correct_function_name(pStVarOne))
-        {
-            //int id[nsiz];
-            //int i = 0;
-            //int zero = 0;
-            //int fptr = ifptr;
-            //int job = 0 ;
-
-            ///* initialize id */
-            //for(i = 0; i < nsiz; i++) id[i] = 0;
-
-            //C2F(cvname)(id, pStVarOne,&zero,(unsigned long)strlen(pStVarOne));
-            //job = SCI_HFUNCTIONS_ENTER;
-            //C2F(funtab)(id,&fptr,&job,pStVarOne,(unsigned long)strlen(pStVarOne));
-            //if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;};
-
-            //LhsVar(1) = 0;
-            //PutLhsVar();
-        }
-        else
-        {
-            if (pStVarOne)
-            {
-                FREE(pStVarOne);
-                pStVarOne = NULL;
-            };
-            Scierror(999, _("%s: function-name is incorrect.\n"), fname);
-            return 0;
-        }
-    }
-    else
-    {
-        Scierror(999, _("%s: Wrong value for input argument #%d: Must be %s.\n"), fname, 2, "> 0");
-        return 0;
-    }
-
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
-static BOOL Is_a_correct_function_name(char *functionname)
-{
-    // FIX ME
-    return FALSE;
-}
-/*--------------------------------------------------------------------------*/
index acabfc1..283ba35 100644 (file)
@@ -58,5 +58,8 @@ int CoreModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"getmemory", &sci_getmemory, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"errclear", &sci_errclear, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"intppty", &sci_intppty, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"newfun", &sci_newfun, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"clearfun", &sci_clearfun, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"funptr", &sci_funptr, MODULE_NAME));
     return 1;
 }
index f123f78..37e8b59 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="sci_clearfun.cpp" />
     <ClCompile Include="sci_errclear.cpp" />
     <ClCompile Include="sci_format.cpp" />
     <ClCompile Include="sci_funcprot.cpp" />
+    <ClCompile Include="sci_funptr.cpp" />
     <ClCompile Include="sci_getmemory.cpp" />
     <ClCompile Include="sci_ieee.cpp" />
     <ClCompile Include="sci_mode.cpp" />
+    <ClCompile Include="sci_newfun.cpp" />
     <ClCompile Include="sci_sciargs.cpp" />
     <ClCompile Include="..\c\sci_getdebuginfo.c" />
     <ClCompile Include="..\c\sci_type.c" />
index 524b500..c7eeac7 100644 (file)
     <ClCompile Include="sci_intppty.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_newfun.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_clearfun.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_funptr.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\banner.hxx">
index 8bc6dc2..f7c38cc 100644 (file)
@@ -50,10 +50,9 @@ Function::ReturnValue sci_clear(types::typed_list &in, int _iRetCount, types::ty
             Scierror(999, _("%s: Wrong size for input argument #%d: Single string expected.\n"), "clear", iWrongType);
             return Function::Error;
         }
-        iWrongType++;
     }
 
-    for (inIterator = in.begin() ; inIterator != in.end() ; iWrongType++, inIterator++)
+    for (inIterator = in.begin() ; inIterator != in.end() ; inIterator++)
     {
         symbol::Context::getInstance()->remove(symbol::Symbol((*inIterator)->getAs<types::String>()->get(0, 0)));
     }
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_clearfun.cpp b/scilab/modules/core/sci_gateway/cpp/sci_clearfun.cpp
new file mode 100644 (file)
index 0000000..701325b
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "core_gw.hxx"
+#include "function.hxx"
+#include "callable.hxx"
+#include "context.hxx"
+#include "string.hxx"
+#include "bool.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+#include "charEncoding.h"
+}
+
+using namespace types;
+
+Function::ReturnValue sci_clearfun(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "clearfun" , 1);
+        return Function::Error;
+    }
+
+    InternalType* pIT1 = in[0];
+    if (pIT1->isString() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "clearfun", 1);
+        return Function::Error;
+    }
+
+    String* pS1 = pIT1->getAs<String>();
+    if (pS1->isScalar() == false)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), "clearfun", 1);
+        return Function::Error;
+    }
+
+    wchar_t* pwcsName = pS1->get(0);
+
+    bool bDeleted = false;
+    symbol::Context* pCtx = symbol::Context::getInstance();
+
+    symbol::Variable* pVar = pCtx->getOrCreate(symbol::Symbol(pwcsName));
+    symbol::Variable::StackVar stack;
+
+    //unstack all elements and stack them in new stack ( reverse order )
+    while (pVar->empty() == false)
+    {
+        stack.push(pVar->top());
+        pVar->pop();
+    }
+
+    if (stack.empty() == false)
+    {
+        symbol::ScopedVariable* pSV = stack.top();
+        if (pSV->m_iLevel == 0 && pSV->m_pIT->isFunction())
+        {
+            //remove
+            pSV->m_pIT->DecreaseRef();
+            pSV->m_pIT->killMe();
+            stack.pop();
+            bDeleted = true;
+        }
+
+        //move all elements at orginal place and order
+        while (stack.empty() == false)
+        {
+            pSV = stack.top();
+            stack.pop();
+            pSV->m_pIT->DecreaseRef();
+            pVar->put(pSV->m_pIT, pSV->m_iLevel);
+            delete pSV;
+        }
+    }
+
+    out.push_back(new Bool(bDeleted ? 1 : 0));
+    return Function::OK;
+}
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_funptr.cpp b/scilab/modules/core/sci_gateway/cpp/sci_funptr.cpp
new file mode 100644 (file)
index 0000000..bc612b3
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "core_gw.hxx"
+#include "function.hxx"
+#include "callable.hxx"
+#include "context.hxx"
+#include "string.hxx"
+#include "bool.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+#include "charEncoding.h"
+}
+
+using namespace types;
+
+Function::ReturnValue sci_funptr(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "funptr" , 1);
+        return Function::Error;
+    }
+
+    InternalType* pIT1 = in[0];
+    if (pIT1->isString() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "funptr", 1);
+        return Function::Error;
+    }
+
+    String* pS1 = pIT1->getAs<String>();
+    if (pS1->isScalar() == false)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), "funptr", 1);
+        return Function::Error;
+    }
+
+    wchar_t* pwcsName = pS1->get(0);
+
+    symbol::Context* pCtx = symbol::Context::getInstance();
+
+    symbol::Variable* pVar = pCtx->getOrCreate(symbol::Symbol(pwcsName));
+    symbol::Variable::StackVar stack;
+    bool bExist = false;
+
+    while (pVar->empty() == false)
+    {
+        stack.push(pVar->top());
+        pVar->pop();
+    }
+
+    if (stack.empty() == false)
+    {
+        symbol::ScopedVariable* pSV = stack.top();
+        if (pSV->m_iLevel == 0 && pSV->m_pIT->isFunction())
+        {
+            bExist = true;
+        }
+
+        //move all elements at orginal place and order
+        while (stack.empty() == false)
+        {
+            pSV = stack.top();
+            stack.pop();
+            pSV->m_pIT->DecreaseRef();
+            pVar->put(pSV->m_pIT, pSV->m_iLevel);
+            delete pSV;
+        }
+    }
+
+    if (bExist)
+    {
+        out.push_back(new String(pwcsName));
+    }
+    else
+    {
+        out.push_back(new Double(0));
+    }
+
+    return Function::OK;
+}
\ No newline at end of file
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_newfun.cpp b/scilab/modules/core/sci_gateway/cpp/sci_newfun.cpp
new file mode 100644 (file)
index 0000000..f65f4ab
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#include "core_gw.hxx"
+#include "configvariable.hxx"
+#include "double.hxx"
+#include "string.hxx"
+#include "function.hxx"
+#include "context.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+}
+
+using namespace types;
+/*--------------------------------------------------------------------------*/
+bool isValidName(wchar_t* _pwstName)
+{
+    if (_pwstName == NULL)
+    {
+        return false;
+    }
+
+    if (isdigit(_pwstName[0]))
+    {
+        return false;
+    }
+
+    int size = (int)wcslen(_pwstName);
+    for (int i = 1 ; i < size ; ++i)
+    {
+        wchar_t c = _pwstName[i];
+        if (c != L'_' && c != L'?' && c != L'!' && isalnum(c) == false)
+        {
+            return false;
+        }
+
+    }
+    return true;
+}
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_newfun(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 2)
+    {
+        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "newfun" , 2);
+        return Function::Error;
+    }
+
+    InternalType* pIT1 = in[0];
+    InternalType* pIT2 = in[1];
+
+    if (pIT1->isString() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 1);
+        return Function::Error;
+    }
+
+    String* pS1 = pIT1->getAs<String>();
+    if (pS1->isScalar() == false)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 1);
+        return Function::Error;
+    }
+
+    wchar_t* pwcsNewName = pS1->get(0);
+
+    //check is a valid name
+    if (isValidName(pwcsNewName) == false)
+    {
+        Scierror(999, _("%s: Wrong value for input argument #%d: Valid function name expected.\n"), "newfun", 1);
+        return Function::Error;
+    }
+
+    if (pIT2->isString() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 2);
+        return Function::Error;
+    }
+
+    String* pS2 = pIT2->getAs<String>();
+    if (pS2->isScalar() == false)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 2);
+        return Function::Error;
+    }
+
+    wchar_t* pwcsName = pS2->get(0);
+
+    Function* pFunc = NULL;
+    symbol::Context* pCtx = symbol::Context::getInstance();
+
+    symbol::Variable* pVar = pCtx->getOrCreate(symbol::Symbol(pwcsName));
+    symbol::Variable::StackVar stack;
+
+    //get original function
+
+    //unstack all elements and stack them in new stack ( reverse order )
+    while (pVar->empty() == false)
+    {
+        stack.push(pVar->top());
+        pVar->pop();
+    }
+
+    if (stack.empty() == false)
+    {
+        symbol::ScopedVariable* pSV = stack.top();
+        if (pSV->m_iLevel == 0 && pSV->m_pIT->isFunction())
+        {
+            pFunc = pSV->m_pIT->getAs<Function>();
+        }
+
+        //move all elements at orginal place and order
+        while (stack.empty() == false)
+        {
+            pSV = stack.top();
+            stack.pop();
+            pSV->m_pIT->DecreaseRef();
+            pVar->put(pSV->m_pIT, pSV->m_iLevel);
+            delete pSV;
+        }
+    }
+
+    if (pFunc == NULL)
+    {
+        Scierror(999, _("%s: function-name is incorrect.\n"), "newfun");
+        return Function::Error;
+    }
+
+    //new function
+    pVar = pCtx->getOrCreate(symbol::Symbol(pwcsNewName));
+    if (pVar->empty())
+    {
+        pVar->put(pFunc, 0);
+    }
+    else
+    {
+        //unstack all elements and stack them in new stack ( reverse order )
+        while (pVar->empty() == false)
+        {
+            stack.push(pVar->top());
+            pVar->pop();
+        }
+
+        symbol::ScopedVariable* pSV = stack.top();
+        if (pSV->m_iLevel == 0)
+        {
+            stack.pop();
+            //clear current var and insert new one
+            InternalType* pIT = pSV->m_pIT;
+            pIT->DecreaseRef();
+            pIT->killMe();
+        }
+
+        pVar->put(pFunc, 0);
+
+        //move all elements at orginal place and order
+        while (stack.empty() == false)
+        {
+            pSV = stack.top();
+            stack.pop();
+            pSV->m_pIT->DecreaseRef();
+            pVar->put(pSV->m_pIT, pSV->m_iLevel);
+            delete pSV;
+        }
+    }
+    return Function::OK;
+}
+/*--------------------------------------------------------------------------*/
index 41f3025..8de2f07 100644 (file)
@@ -11,7 +11,7 @@ if clearfun('myfunctionname') <> %F then bugmes();quit;end
 //================================================
 ptr = funptr('pwd');
 newfun("MY_PWD",ptr);
-if clearfun("MY_PWD") <> %T then bugmes();quit;end
+assert_checktrue(clearfun("MY_PWD"));
 //================================================
-ierr = execstr('a = clearfun(2);','errcatch');
-if ierr <> 999 then bugmes();quit;end
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "clearfun", 1);
+assert_checkerror('a = clearfun(2);', errmsg);
index 7ca6d72..65f135f 100644 (file)
@@ -13,8 +13,7 @@ if clearfun('myfunctionname') <> %F then pause,end
 ptr = funptr('pwd');
 newfun("MY_PWD",ptr);
 
-if clearfun("MY_PWD") <> %T then pause,end
+assert_checktrue(clearfun("MY_PWD"));
 //================================================
-
-ierr = execstr('a = clearfun(2);','errcatch');
-if ierr <> 999 then pause,end
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "clearfun", 1);
+assert_checkerror('a = clearfun(2);', errmsg);
index c13da57..fca1478 100644 (file)
@@ -7,10 +7,10 @@
 //================================================
 // test funptr
 //================================================
-ptr = funptr('pwd');
-if ptr <> 34031 then bugmes();quit;end
-ierr = execstr('ptr = funptr(1)','errcatch');
-if ierr <> 999 then bugmes();quit;end
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "funptr", 1);
+assert_checkerror('ptr = funptr(1)', errmsg);
+ptr = funptr("pwd");
+assert_checkequal(ptr, "pwd");
 ptr = funptr('FCT_NOT_IN_SCILAB');
-if ptr <> 0 then bugmes();quit;end
+assert_checkequal(ptr, 0);
 //================================================
index d0c6023..2b5618e 100644 (file)
@@ -8,13 +8,13 @@
 //================================================
 // test funptr
 //================================================
-ptr = funptr('pwd');
-if ptr <> 34031 then pause,end
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "funptr", 1);
+assert_checkerror('ptr = funptr(1)', errmsg);
 
-ierr = execstr('ptr = funptr(1)','errcatch');
-if ierr <> 999 then pause,end
+ptr = funptr("pwd");
+assert_checkequal(ptr, "pwd");
 
 ptr = funptr('FCT_NOT_IN_SCILAB');
-if ptr <> 0 then pause,end
+assert_checkequal(ptr, 0);
 
 //================================================
index 9f181b3..b7e01b4 100644 (file)
@@ -7,18 +7,40 @@
 // =============================================================================
 fptr_cos = funptr("cos");
 newfun("cosAlias",fptr_cos);
-if cos(2*%pi) <> cosAlias(2*%pi)                then bugmes();quit;end
-if clearfun("cosAlias") <> %T                   then bugmes();quit;end
+assert_checkequal(cos(2*%pi), cosAlias(2*%pi));
+assert_checktrue(clearfun("cosAlias"));
 if execstr("cosAlias(2*%pi)","errcatch") ==  0  then bugmes();quit;end
-ierr = execstr('newfun(''more_than_twenty_four_characters_function_name'',fptr_cos)','errcatch');
-if ierr <> 999 then bugmes();quit;end
-ierr = execstr('newfun(''1_function_name'',fptr_cos)','errcatch');
-if ierr <> 999 then bugmes();quit;end
-ierr = execstr('newfun(''new_function_name'',[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then bugmes();quit;end
-ierr = execstr('newfun([''new_function_name'',''new_function_name''],[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then bugmes();quit;end
-ierr = execstr('newfun(1,[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then bugmes();quit;end
-ierr = execstr('newfun(1,''fptr_cos'')','errcatch');
-if ierr <> 999 then bugmes();quit;end
+errmsg =  msprintf(gettext("%s: Wrong value for input argument #%d: Valid function name expected.\n"), "newfun", 1);
+assert_checkerror('newfun(''1_function_name'',fptr_cos)', errmsg);
+errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 2);
+assert_checkerror('newfun(''new_function_name'',[fptr_cos,fptr_cos])', errmsg);
+errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 1);
+assert_checkerror('newfun([''new_function_name'',''new_function_name''],[fptr_cos,fptr_cos])', errmsg);
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 1);
+assert_checkerror('newfun(1,[fptr_cos,fptr_cos])', errmsg);
+function test_1(x)
+    newfun(x, "cos");
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
+test_1("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
+function test_2(x)
+    test_1(x);
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
+test_2("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
+function test_3(x)
+    test_2(x);
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
+test_3("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
+myvar = 3;
+newfun("myvar", fptr_cos);
+assert_checkequal(myvar, 3);
+clear myvar
+assert_checkequal(myvar(0), cos(0));
index 888948a..6019871 100644 (file)
@@ -5,28 +5,55 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-
 fptr_cos = funptr("cos");
 newfun("cosAlias",fptr_cos);
 
-if cos(2*%pi) <> cosAlias(2*%pi)                then pause,end
-if clearfun("cosAlias") <> %T                   then pause,end
+assert_checkequal(cos(2*%pi), cosAlias(2*%pi));
+assert_checktrue(clearfun("cosAlias"));
 if execstr("cosAlias(2*%pi)","errcatch") ==  0  then pause,end
 
-ierr = execstr('newfun(''more_than_twenty_four_characters_function_name'',fptr_cos)','errcatch');
-if ierr <> 999 then pause,end
+errmsg =  msprintf(gettext("%s: Wrong value for input argument #%d: Valid function name expected.\n"), "newfun", 1);
+assert_checkerror('newfun(''1_function_name'',fptr_cos)', errmsg);
+
+errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 2);
+assert_checkerror('newfun(''new_function_name'',[fptr_cos,fptr_cos])', errmsg);
+
+errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "newfun", 1);
+assert_checkerror('newfun([''new_function_name'',''new_function_name''],[fptr_cos,fptr_cos])', errmsg);
+
+errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 1);
+assert_checkerror('newfun(1,[fptr_cos,fptr_cos])', errmsg);
+
+function test_1(x)
+    newfun(x, "cos");
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
+
+test_1("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
+
+function test_2(x)
+    test_1(x);
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
 
-ierr = execstr('newfun(''1_function_name'',fptr_cos)','errcatch');
-if ierr <> 999 then pause,end
+test_2("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
 
-ierr = execstr('newfun(''new_function_name'',[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then pause,end
+function test_3(x)
+    test_2(x);
+    assert_checkequal(eval(x + "(1)"), cos(1));
+endfunction
 
-ierr = execstr('newfun([''new_function_name'',''new_function_name''],[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then pause,end
+test_3("cosAlias");
+assert_checkequal(cosAlias(1), cos(1));
+assert_checktrue(clearfun("cosAlias"));
 
-ierr = execstr('newfun(1,[fptr_cos,fptr_cos])','errcatch');
-if ierr <> 999 then pause,end
 
-ierr = execstr('newfun(1,''fptr_cos'')','errcatch');
-if ierr <> 999 then pause,end
+myvar = 3;
+newfun("myvar", fptr_cos);
+assert_checkequal(myvar, 3);
+clear myvar
+assert_checkequal(myvar(0), cos(0));
index 413c748..e4f62da 100644 (file)
@@ -380,7 +380,7 @@ function [stk,txt,ilst]=exp2sci(lst,ilst)
                             stk(top)=list(op(2),"0")
                             m=%f
                         elseif type(stk(top)(1))==10 then
-                            testOK = (op(4)=="1" & ~funptr(op(2)) & ~exists(op(2)))
+                            testOK = (op(4)=="1" & funptr(op(2)) == 0 & ~exists(op(2)))
                             if ~testOK then
                                 testOK = execstr("tmp = evstr(op(2))", "errcatch")==0
                                 if testOK