[med-svn] [cnrun] 18/25: WIP

andrei zavada hmmr-guest at moszumanska.debian.org
Thu Nov 6 22:08:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch WIP
in repository cnrun.

commit f67f771f9d6028430bb46231f9ed64c6601ef45f
Author: andrei zavada <andrei.zavada at massivesolutions.eu>
Date:   Tue Sep 30 20:24:49 2014 +0300

    WIP
---
 upstream/{make_vesrion => make_version}   |   0
 upstream/src/Makefile.am                  |  12 --
 upstream/src/cnrun/Makefile.am            |   9 +-
 upstream/src/cnrun/cnrun.hh               |  16 +-
 upstream/src/cnrun/interpreter.cc         | 112 +----------
 upstream/src/cnrun/main.cc                | 226 +++-------------------
 upstream/src/{ => cnrun}/print_version.cc |   2 +-
 upstream/src/libcn/base-unit.cc           |  23 ++-
 upstream/src/libcn/base-unit.hh           |   6 +-
 upstream/src/libcn/hosted-synapses.cc     |   8 +-
 upstream/src/libcn/hosted-synapses.hh     |  10 +-
 upstream/src/libcn/model-struct.cc        |  16 +-
 upstream/src/libcn/model.hh               |   6 -
 upstream/src/libcn/standalone-neurons.cc  |   8 +-
 upstream/src/libcn/standalone-neurons.hh  |   2 -
 upstream/src/libcn/standalone-synapses.cc |  10 +-
 upstream/src/libcn/standalone-synapses.hh |   2 -
 upstream/src/libstilton/Makefile.am       |   3 -
 upstream/src/libstilton/exprparser.cc     | 311 ------------------------------
 upstream/src/libstilton/exprparser.hh     | 117 -----------
 20 files changed, 81 insertions(+), 818 deletions(-)

diff --git a/upstream/make_vesrion b/upstream/make_version
similarity index 100%
rename from upstream/make_vesrion
rename to upstream/make_version
diff --git a/upstream/src/Makefile.am b/upstream/src/Makefile.am
index 92ebb6c..884db3b 100644
--- a/upstream/src/Makefile.am
+++ b/upstream/src/Makefile.am
@@ -4,15 +4,3 @@ SUBDIRS = libstilton libcn cnrun
 if DO_TOOLS
 SUBDIRS += tools
 endif
-
-libicing_a_CXXFLAGS := \
-	$(AM_CXXFLAGS) -DGIT_DESCRIBE_TAGS=\"$(shell git describe --tags)\"
-
-noinst_LIBRARIES := \
-	libicing.a
-
-libicing_a_SOURCES := \
-	print_version.cc
-
-print_version.o: FORCE
-FORCE:
diff --git a/upstream/src/cnrun/Makefile.am b/upstream/src/cnrun/Makefile.am
index 8737de8..04bd11b 100644
--- a/upstream/src/cnrun/Makefile.am
+++ b/upstream/src/cnrun/Makefile.am
@@ -11,13 +11,16 @@ endif
 bin_PROGRAMS := \
 	cnrun
 cnrun_SOURCES := \
-	interpreter.cc commands.cc cnrun.hh main.cc
+	interpreter.cc commands.cc cnrun.hh main.cc print_version.cc
 cnrun_LDADD := \
-	$(top_srcdir)/src/libicing.a \
 	$(top_srcdir)/src/libcn/libcn.la \
 	$(top_srcdir)/src/libstilton/libstilton.la \
 	$(LIBCN_LIBS) \
 	$(LUA_LIB)
 
-cnrun_LDFLAAGS := \
+print_version.o: CXXFLAGS = $(AM_CXXFLAGS) -DGIT_DESCRIBE_TAGS=\"$(shell ../../make_version)\"
+print_version.o: FORCE
+FORCE:
+
+cnrun_LDFLAGS := \
 	-shared
diff --git a/upstream/src/cnrun/cnrun.hh b/upstream/src/cnrun/cnrun.hh
index 3074637..86c4c0e 100644
--- a/upstream/src/cnrun/cnrun.hh
+++ b/upstream/src/cnrun/cnrun.hh
@@ -29,16 +29,14 @@ namespace cnrun {
 
 struct SInterpOptions
   : public cnrun::SModelOptions {
-        bool    dump_params:1,
-                list_units:1;
+        bool    list_units:1;
         string  working_dir;
 
         list<string>
                 scripts;
 
         SInterpOptions ()
-              : dump_params (false),
-                list_units (false),
+              : list_units (false),
                 working_dir (".")
                 {}
 };
@@ -47,6 +45,8 @@ struct SInterpOptions
 class CInterpreterShell
   : public cnrun::stilton::C_verprintf {
 
+        DELETE_DEFAULT_METHODS (CInterpreterShell)
+
     public:
         CInterpreterShell (const SInterpOptions& options_);
        ~CInterpreterShell ();
@@ -58,6 +58,7 @@ class CInterpreterShell
                 ok, file_error, compile_error, stack_error, call_error
         };
         TScriptExecResult exec_script( const string& script_fname);
+        int run();
       // individual commands
         struct SArg {
                 char type;
@@ -132,9 +133,6 @@ class CInterpreterShell
         map<string, CModel*>
                 models;
 
-        const string
-                current_script;
-
         lua_State
                *lua_state;
 
@@ -146,9 +144,7 @@ class CInterpreterShell
         static list<string> list_commands();
 };
 
-//char** cnrun_completion( const char *text, int start, int end);
-
-}  // namespace cnrun
+}
 
 #endif
 
diff --git a/upstream/src/cnrun/interpreter.cc b/upstream/src/cnrun/interpreter.cc
index 279d8d8..2f43fd0 100644
--- a/upstream/src/cnrun/interpreter.cc
+++ b/upstream/src/cnrun/interpreter.cc
@@ -247,118 +247,16 @@ exec_script( const string& script_fname)
 }
 
 
-/*
-#define CNRUN_HISTORY ".cnrun-history"
 
 int
 cnrun::CInterpreterShell::
-exec_script( const string& script_fname)
+run()
 {
-        int retval = 0;
-
-        if ( script_fname != "-" ) {
-                ifstream script_stream( script_fname.c_str());
-                if ( !script_stream.good() ) {
-                        vp( -1, "Failed to open script file \"%s\"", script_fname);
-                        return -1;
-                }
-                vp( 1, "execing %s\n", script_fname.c_str());
-
-                current_line = 0;
-                string buf;
-                while ( getline( script_stream, buf) || script_stream.gcount() ) {
-                        ++current_line;
-                        if ( buf.size() ) {
-
-                                char    *pp = strchr( (char*)buf.c_str(), '#');
-                                if ( pp )
-                                        buf.resize( pp - buf.c_str());
-                                size_t  buflen = buf.size();
-                                while ( strlen(buf.c_str()) && isspace(buf[buflen-1]) )
-                                        buf[--buflen] = '\0';
-
-                                char    *_stmt = &buf[0],
-                                        *stmt;
-                                while ( _stmt - &buf[0] < (int)buflen && (stmt = strtok( _stmt, ";\n")) ) {
-                                        _stmt = _stmt + strlen(_stmt)+1;
-
-                                        retval = do_single_cmd( stmt, our_variables, level, script_fname, lineno);
-                                        if ( retval == CN_INTERP_EXIT ||
-                                             (retval < CN_INTERP_WARN && howstrict == CN_INTRP_STRICT) )
-                                                break;
-                                }
-                        }
-                }
-        } else {
-                if ( level == 0 ) {
-                        using_history();
-                        read_history( CNRUN_HISTORY);
-                        rl_attempted_completion_function = cnrun_completion;
-                        rl_bind_key( '\t', rl_complete);
-                }
-                HISTORY_STATE *the_history_state = history_get_history_state();
-                if ( the_history_state && the_history_state->length == 0 )
-                        printf( "Hit TAB for context completions\n");
-
-                char *buf, prompt[256];
-                while ( snprintf( prompt, 255, "%s @%g%.*s ",
-                                  Model ? Model->name.c_str() : "-",
-                                  Model ? Model->model_time() : 0,
-                                  level+1, "]]]]]]]"),
-                        (buf = readline( prompt)) ) {
-
-                        the_history_state = history_get_history_state();
-                        if ( the_history_state &&
-                             (the_history_state->length < 2 ||
-                              (the_history_state->length > 1 &&
-                               *buf &&
-                               strcmp( history_get( the_history_state->length)->line, buf) != 0) ) ) {
-                                add_history( buf);
-                        }
-
-                        char    *pp = strchr( buf, '#');
-                        if ( pp )
-                                *pp = '\0';
-                        size_t        buflen = strlen( buf);
-                        while ( buflen && strchr( " \t", buf[buflen-1]) )
-                                buf[--buflen] = '\0';
-                        if ( !buflen )
-                                continue;
-
-                        char        *_stmt = buf,  // will hold the pointer to the next statement
-                                *stmt;
-                        while ( _stmt - buf < (int)buflen  &&  (stmt = strtok( _stmt, ";\n")) ) {
-                                _stmt += (strlen(_stmt) + 1);
-
-                                retval = do_single_cmd( stmt, our_variables, level, nullptr, -1);
-                                if ( retval == CN_INTERP_EXIT ) {
-                                        free( buf);
-                                        goto out;
-                                }
-                        }
-                        free( buf);
-                        if ( level == 0 ) {
-//                                rl_attempted_completion_function = cnrun_completion;
-                                rl_bind_key( '\t', rl_complete);
-                        }
-                }
-        out:
-                if ( level == 0 )
-                        write_history( CNRUN_HISTORY);
-                printf( "\n");
-        }
-
-        if ( env_export ) {
-              // update varlist
-                varlist.merge( our_variables);
-                varlist.sort();
-                varlist.unique();
-        }
-        current_shell_variables = &varlist;
-
-        return retval;
+        for ( const auto& S : options.scripts )
+                if ( exec_script(S) != TScriptExecResult::ok )
+                        return 1;
+        return 0;
 }
-*/
 
 // Local Variables:
 // Mode: c++
diff --git a/upstream/src/cnrun/main.cc b/upstream/src/cnrun/main.cc
index 3ee0184..ed02e90 100644
--- a/upstream/src/cnrun/main.cc
+++ b/upstream/src/cnrun/main.cc
@@ -10,20 +10,20 @@
  */
 
 
-#include <unistd.h>
-#include <stdlib.h>
-#include <argp.h>
+#if HAVE_CONFIG_H && !defined(VERSION)
+#  include "config.h"
+#endif
+
 #include <cstdarg>
+#include <cstdlib>
 #include <list>
 #include <string>
+#include <unistd.h>
 
-#include "libstilton/exprparser.hh"
 #include "cnrun.hh"
 
-#if HAVE_CONFIG_H && !defined(VERSION)
-#  include "config.h"
-#endif
-
+// needs to go after <algorithm>
+#include <argp.h>
 
 using namespace std;
 using namespace cnrun;
@@ -32,7 +32,7 @@ using namespace cnrun;
 // argparse
 
 const char
-        *argp_program_version = PACKAGE_STRING;
+        *argp_program_version = PACKAGE_STRING,
         *argp_program_bug_address = PACKAGE_BUGREPORT;
 
 static char doc[] =
@@ -41,19 +41,8 @@ static char doc[] =
 namespace opt {
 enum TOptChar {
         list_units            = 'U',
-        dump_model_units      = 'u',
-        dir                   = 'C',
-        listen_dt             = 'E',
-        log_spiking           = 'k',
-        log_spiking_threshold = '\0',
-        log_option            = 'L',
-        precision             = 'e',
-        dt_max                = 'M',
-        dt_min                = 'm',
-        dt_xcap               = '\0',
-        sort_units            = '\0',
+        chdir                 = 'C',
         verbosely             = 'v',
-        help                  = 'h',
 };
 }  // namespace opt, strictly to enclose enum TOptChar
 
@@ -63,46 +52,9 @@ static struct argp_option options[] = {
         {"list-units",       opt::list_units, NULL,         0,
          "List all available units and exit." },
 
-        {"chdir",            opt::dir,        "DIR",        0,
+        {"chdir",            opt::chdir,       "DIR",        0,
          "Change to DIR before executing script."},
 
-        {"dump-model-units", opt::dump_model_units, NULL,   0,
-         "Dump all unit types in the model and exit."},
-
-        {"listen-dt",        opt::listen_dt,   "MSEC",      0,
-         "Listen at this interval (default 1 msec; set to 0 "
-         "to listen every cycle, which can slow cnrun down considerably)."},
-
-        {"log-spiking",      opt::log_spiking, "l|0",       0,
-         "Write a model-wide log of spiking neurons, using labels (l) "
-         "or unit ids (0)."},
-
-        {"log-spiking-threshold", opt::log_spiking_threshold, "",       0,
-         "Write a model-wide log of spiking neurons, using labels (l) "
-         "or unit ids (0)."},
-
-        {"log-option",       opt::log_option,  "1dbL",      0,
-         "1, only log the first variable; "
-         "d, defer writing to disk until done rather than write continuously; "
-         "b, write in native binary form rather than in ASCII; "
-         "L, log integrator dt."},
-
-        {"precision",        opt::precision,   "N",         0,
-         "Precision for floating point printed output."},
-
-        {"dt-max",           opt::dt_max,      "MSEC",      0,
-         "Max time step (default 0.5)."},
-        {"dt-min",           opt::dt_min,      "MSEC",      0,
-         "Min time step (default 1e-5)."},
-        {"dt-xcap",          opt::dt_xcap,     "TIMES",     0,
-         "Cap dt increase by current dt value x this (default 5)."},
-
-        {"sort-units",       opt::sort_units,   NULL,       0,
-         "Sort units in any bulk output." },
-
-        {"define",           opt::defvar,      "VAR=EXPR",   0,
-         "Define a variable with an initial value."},
-
         {"verbose",          opt::verbosely,   "LEVEL",     0,
          "Verbosity level (default 1; values up to 7 are meaningful).  Use a"
          " negative value to show the progress percentage only,"
@@ -125,99 +77,16 @@ static struct argp argp = {
 
 
 static error_t
-parse_opt( int key, const char *arg, struct argp_state *state)
+parse_opt( int key, char *arg, struct argp_state *state)
 {
-        auto& Q = *(SOptions*)state->input;
+        auto& Q = *(cnrun::SInterpOptions*)state->input;
 
         char *endp = nullptr;
         switch ( key ) {
-        case opt::dt_max:
-                if ( Q.integration_dt_max = strtof( arg, &endp), *endp ) {
-                        fprintf( stderr, "Expected a floating-point value for dt-max arg, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-        case opt::dt_min:
-                if ( Q.integration_dt_min = strtof( arg, &endp), *endp ) {
-                        fprintf( stderr, "Expected a floating-point value for dt-min arg, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-        case opt::dt_xcap:
-                if ( Q.integration_dt_max_cap = strtof( arg, &endp), *endp ) {
-                        fprintf( stderr, "Expected a floating-point value for dt-xcap arg, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-
-        case opt::log_option:
-                if ( strchr( arg, 'd') )
-                        Q.listen_deferwrite = true;
-                if ( strchr( arg, '1') )
-                        Q.listen_1varonly = true;
-                if ( strchr( arg, 'b') )
-                        Q.listen_binary = true;
-                if ( strchr( arg, 'L') )
-                        Q.log_dt = true;
-                break;
-
-        case opt::listen_dt:
-                if ( Q.listen_dt( arg, &endp), *endp ) {
-                        fprintf( stderr, "Expected a floating-point value for listen-dt arg, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-
-        case opt::precision:
-                Q.precision = strtoul( arg, &endp, 10);
-                if ( *endp || Q.precision > 16 ) {
-                        fprintf( stderr, "Expected an unsigned int <= 16, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-
-        case opt::log_spiking:
-                Q.log_spikers = true;
-                switch ( *arg ) {
-                case '0': Q.log_spikers_use_serial_id = true;  break;
-                case 'l': Q.log_spikers_use_serial_id = false; break;
-                default:
-                        fprintf( stderr, "Expecting a '0' or 'l' for log-spiking spec, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-        case opt::log_spiking_threshold:
-                Q.spike_threshold = strtof( arg+1, &endp);
-                if ( *endp ) {
-                        fprintf( stderr, "Expecting an FP value for log-spiking-threshold, got \"%s\"", arg);
-                        return (error_t)ARGP_ERR_UNKNOWN;
-                }
-                break;
-
-        case opt::list_units:
-                Q.list_units = true;
-                break;
-
-        case opt::sort_units:
-                Q.sort_units = true;
-                break;
-
         case opt::chdir:
                 Q.working_dir = arg;
                 break;
 
-        case opt::defvar:
-        {
-                double  unused;
-                CExpression
-                        expr;
-                if ( expr( arg, unused, &Variables) ) {
-                        fprintf( stderr, "Malformed variable assignment with -D");
-                        return CNRUN_CLPARSE_ERROR;
-                }
-        }
-        break;
-
         case opt::verbosely:
                 Q.verbosely = strtol( arg, &endp, 10);
                 break;
@@ -244,86 +113,37 @@ main( int argc, char *argv[])
 {
         print_version( "cnrun");
 
-        cnrun::SOptions Options;
+        cnrun::SInterpOptions Options;
         argp_parse( &argp, argc, argv, 0, NULL, (void*)&Options);
 
       // purely informational, requires no model
-        if ( Q.list_units ) {
+        if ( Options.list_units ) {
                 cnmodel_dump_available_units();
                 return 0;
         }
 
       // cd as requested
         char *pwd = nullptr;
-        if ( Q.working_dir ) {
+        if ( Options.working_dir.size() ) {
                 pwd = getcwd( nullptr, 0);
-                if ( chdir( Q.working_dir.c_str()) ) {
-                        fprintf( stderr, "Failed to cd to \"%s\"", Q.working_dir.c_str());
-                        return -1;
+                if ( chdir( Options.working_dir.c_str()) ) {
+                        fprintf( stderr, "Failed to cd to \"%s\"", Options.working_dir.c_str());
+                        return 2;
                 }
         }
 
-        __cn_verbosely = Q.verbosely;
-        __cn_default_unit_precision = Q.precision;
+        cnrun::global::verbosely = Options.verbosely;
 
-        for ( const auto& F : Options.scripts )
-                interpreter_run(
-                        F, 0, Options,
-                        true, true);
+        cnrun::CInterpreterShell Interp (Options);
+        int ret = Interp.run();
 
         if ( pwd )
                 if ( chdir( pwd) )
                         fprintf( stderr, "Failed to cd back to \"%s\"", pwd);
 
-        return 0;
+        return ret;
 }
 
-
-
-
-// namespace {
-// void
-// usage( const char *argv0)
-// {
-//         cout << "Usage: " << argv0 << "\n" <<
-//                 " -e <script_fname>\tExecute script\n"
-//                 " -D \t\t\tDump all unit types in the model and exit\n"
-//                 " -C <dir>\t\tWork in dir\n"
-//                 " -s \t\t\tSort units\n"
-//                 "\n"
-//                 " -L[d1Lx] \t\tLogging & listeners:\n"
-//                 "    d \t\t\tdefer writing to disk until done rather than writing continuously\n"
-//                 "    1\t\t\tonly log the first variable\n"
-//                 "    x\t\t\twrite in native binary form rather than in ASCII\n"
-//                 "    L\t\t\tlog integrator dt\n"
-//                 " -E<double>\t\tListen at this interval (default " << Options.listen_dt << ";\n"
-//                 "\t\t\t   set to 0 to listen every cycle)\n"
-//                 "\n"
-//                 " -kl \t\t\tWrite a model-wide log of spiking neurons, using labels\n"
-//                 " -k0 \t\t\t... use unit id instead\n"
-//                 " -kS<double>\t\tSpike detection threshold (default " << Options.spike_threshold << ")\n"
-//                 "\n"
-//                 " -e <uint>\t\tSet precision for all output (default " << Options.precision << ")\n"
-//                 "\n"
-//                 " -tT <double>\t\tdt_max (default " << Options.integration_dt_max << ")\n"
-//                 " -tt <double>\t\tdt_min (default " << Options.integration_dt_min << ")\n"
-//                 " -tx <double>\t\tCap dt by current dt value x this (default " << Options.integration_dt_max_cap << ")\n"
-//                 "\n"
-//                 " -D EXPR\t\tAny valid expression, will inject whatever variables get assigned in it\n"
-//                 "\n"
-//                 " -v <int>\t\tSet verbosity level (default " << Options.verbosely << ")\n"
-//                 "\t\t\t Use a negative value to show the progress percentage only,\n"
-//                 " -v[%[-]t[-]]\t\tDisplay (with -, suppress) progress percent and/or time\n"
-//                 "\t\t\t indented on the line at 8 x (minus) this value.\n"
-//                 "\n"
-//                 " -U \t\t\tList available unit types with parameter names\n"
-//                 "\t\t\t  and values, and exit\n"
-//                 " -h \t\t\tDisplay this help\n"
-//                 "\n";
-// }
-// } // namespace
-
-
 // Local Variables:
 // indent-tabs-mode: nil
 // tab-width: 8
diff --git a/upstream/src/print_version.cc b/upstream/src/cnrun/print_version.cc
similarity index 96%
rename from upstream/src/print_version.cc
rename to upstream/src/cnrun/print_version.cc
index aea64cc..f7a7467 100644
--- a/upstream/src/print_version.cc
+++ b/upstream/src/cnrun/print_version.cc
@@ -21,6 +21,6 @@ print_version( const char* this_program)
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: nil
-// tab-width: nil
+// tab-width: 8
 // c-basic-offset: 8
 // End:
diff --git a/upstream/src/libcn/base-unit.cc b/upstream/src/libcn/base-unit.cc
index b000f54..03fdd67 100644
--- a/upstream/src/libcn/base-unit.cc
+++ b/upstream/src/libcn/base-unit.cc
@@ -28,26 +28,29 @@
 
 
 using namespace std;
+using namespace cnrun;
 using cnrun::alg::member;
 
+unsigned short cnrun::global::precision = 4;
+int cnrun::global::verbosely = 1;
 
 cnrun::C_BaseUnit::
-C_BaseUnit (TUnitType intype, const string& inlabel,
-            CModel* inM, int s_mask)
-      : precision (cn_default_unit_precision),
-        _type (intype), _status (0 |/* CN_UENABLED |*/ s_mask),
-        M (inM),
+C_BaseUnit (TUnitType type_, const string& label_,
+            CModel* M_, int s_mask)
+      : precision (global::precision),
+        _type (type_), _status (0 |/* CN_UENABLED |*/ s_mask),
+        M (M_),
         _binwrite_handle (-1), _listener_disk (nullptr), _listener_mem (nullptr)
 {
         memset( _label, 0, max_label_size);
-        if ( inlabel.size() )
-                strncpy( _label, inlabel.c_str(), max_label_size);
+        if ( label_.size() )
+                strncpy( _label, label_.c_str(), max_label_size);
         else
                 snprintf( _label, max_label_size-1, "fafa%p", this);
 
-        if ( inM && inM->unit_by_label( _label) ) {
-                fprintf( stderr, "Model %s already has a unit labelled \"%s\"\n", inM->name.c_str(), _label);
-                _status |= CN_UERROR;
+        if ( M_ && M_->unit_by_label( label_) ) {
+                fprintf( stderr, "Model %s already has a unit labelled \"%s\"\n", M_->name.c_str(), label_.c_str());
+                throw "Duplicate unit label";
         }
 
         reset_params();
diff --git a/upstream/src/libcn/base-unit.hh b/upstream/src/libcn/base-unit.hh
index fff96a3..a60f03f 100644
--- a/upstream/src/libcn/base-unit.hh
+++ b/upstream/src/libcn/base-unit.hh
@@ -34,8 +34,10 @@ using cnrun::stilton::str::sasprintf;
 
 namespace cnrun {
 
-extern unsigned short cn_default_unit_precision;
-extern int cn_verbosely;
+namespace global {
+extern unsigned short precision;
+extern int verbosely;
+}
 
 // for all units
 #define CN_UERROR                        (1 << 0)
diff --git a/upstream/src/libcn/hosted-synapses.cc b/upstream/src/libcn/hosted-synapses.cc
index ac42ed2..9cfbbf6 100644
--- a/upstream/src/libcn/hosted-synapses.cc
+++ b/upstream/src/libcn/hosted-synapses.cc
@@ -28,11 +28,11 @@ using namespace std;
 
 // the base synapse here
 cnrun::C_HostedSynapse::
-C_HostedSynapse (TUnitType intype,
-                 C_BaseNeuron *insource, C_BaseNeuron *intarget,
-                 double ing, CModel *inM, int s_mask,
+C_HostedSynapse (const TUnitType type_,
+                 C_BaseNeuron *source_, C_BaseNeuron *target_,
+                 const double g_, CModel *M_, int s_mask,
                  TIncludeOption include_option)
-      : C_BaseSynapse (intype, insource, intarget, ing, inM, s_mask),
+      : C_BaseSynapse (type_, source_, target_, g_, M_, s_mask),
         C_HostedAttributes()
 {
         if ( M )
diff --git a/upstream/src/libcn/hosted-synapses.hh b/upstream/src/libcn/hosted-synapses.hh
index 25d8fee..b86eb6c 100644
--- a/upstream/src/libcn/hosted-synapses.hh
+++ b/upstream/src/libcn/hosted-synapses.hh
@@ -39,13 +39,11 @@ class C_HostedSynapse
         DELETE_DEFAULT_METHODS (C_HostedSynapse)
 
     protected:
-        C_HostedSynapse (TUnitType intype,
-                         C_BaseNeuron *insource, C_BaseNeuron *intarget,
-                         double ing, CModel*, int s_mask = 0,
-                         TIncludeOption include_option = TIncludeOption::is_last);
+        C_HostedSynapse (TUnitType type_,
+                         C_BaseNeuron *source_, C_BaseNeuron *target_,
+                         double g_, CModel*, int s_mask = 0,
+                         TIncludeOption = TIncludeOption::is_last);
     public:
-       ~C_HostedSynapse();
-
         void reset_vars();
         double &var_value( size_t);
         const double &get_var_value( size_t) const;
diff --git a/upstream/src/libcn/model-struct.cc b/upstream/src/libcn/model-struct.cc
index 2fe4ff0..90c4fac 100644
--- a/upstream/src/libcn/model-struct.cc
+++ b/upstream/src/libcn/model-struct.cc
@@ -779,16 +779,12 @@ finalize_additions()
         for ( auto& U : hosted_synapses )
                 U->reset_vars();
 
-        if ( options.sort_units ) {
-                units.sort(
-                        [] (C_BaseUnit *&lv, C_BaseUnit *&rv) {
-                                return strcmp( lv->label(), rv->label()) < 0;
-                        });
-                // hosted_neurons.sort( cmp);
-                // hosted_synapses.sort( cmp);
-                // standalone_neurons.sort( cmp);
-                // standalone_synapses.sort( cmp);
-        }
+        // if ( options.sort_units ) {
+        //         units.sort(
+        //                 [] (C_BaseUnit *&lv, C_BaseUnit *&rv) {
+        //                         return strcmp( lv->label(), rv->label()) < 0;
+        //                 });
+        // }
 
         _integrator->prepare();
 }
diff --git a/upstream/src/libcn/model.hh b/upstream/src/libcn/model.hh
index faf109c..9f59be3 100644
--- a/upstream/src/libcn/model.hh
+++ b/upstream/src/libcn/model.hh
@@ -36,7 +36,6 @@ parameters.
 
 #include "gsl/gsl_rng.h"
 
-#include "libstilton/exprparser.hh"
 #include "libstilton/misc.hh"
 #include "forward-decls.hh"
 #include "base-neuron.hh"
@@ -56,7 +55,6 @@ struct SModelOptions {
         bool    listen_1varonly:1,
                 listen_deferwrite:1,
                 listen_binary:1,
-                sort_units:1,
                 log_dt:1,
                 log_spikers:1,
                 log_spikers_use_serial_id:1,
@@ -76,12 +74,8 @@ struct SModelOptions {
                 sdf_sigma;
         int     verbosely;
 
-        list<cnrun::stilton::SVariable>
-                variables;
-
         SModelOptions ()
               : listen_1varonly (true), listen_deferwrite (false), listen_binary (false),
-                sort_units (true),
                 log_dt (false),
                 log_spikers (false), log_spikers_use_serial_id (false),
                 log_sdf (false),
diff --git a/upstream/src/libcn/standalone-neurons.cc b/upstream/src/libcn/standalone-neurons.cc
index c84f2e8..b2d3e49 100644
--- a/upstream/src/libcn/standalone-neurons.cc
+++ b/upstream/src/libcn/standalone-neurons.cc
@@ -25,11 +25,11 @@
 
 
 cnrun::C_StandaloneNeuron::
-C_StandaloneNeuron (TUnitType intype, const string& inlabel,
+C_StandaloneNeuron (TUnitType type_, const string& label_,
                     double x, double y, double z,
-                    CModel *inM, int s_mask)
-      : C_BaseNeuron( intype, inlabel, x, y, z, inM, s_mask),
-        C_StandaloneAttributes( __CNUDT[intype].vno)
+                    CModel *M_, int s_mask)
+      : C_BaseNeuron( type_, label_, x, y, z, M_, s_mask),
+        C_StandaloneAttributes( __CNUDT[type_].vno)
 {
         reset_vars();
         if ( M )
diff --git a/upstream/src/libcn/standalone-neurons.hh b/upstream/src/libcn/standalone-neurons.hh
index 7eaf700..83b7f49 100644
--- a/upstream/src/libcn/standalone-neurons.hh
+++ b/upstream/src/libcn/standalone-neurons.hh
@@ -38,8 +38,6 @@ class C_StandaloneNeuron
                             CModel*, int s_mask);
 
     public:
-       ~C_StandaloneNeuron ();
-
         double &var_value( size_t v)                  {  return V[v];  }
         const double &get_var_value( size_t v) const  {  return V[v];  }
         void reset_vars()
diff --git a/upstream/src/libcn/standalone-synapses.cc b/upstream/src/libcn/standalone-synapses.cc
index e8ccb6b..565a96c 100644
--- a/upstream/src/libcn/standalone-synapses.cc
+++ b/upstream/src/libcn/standalone-synapses.cc
@@ -23,11 +23,11 @@
 
 
 cnrun::C_StandaloneSynapse::
-C_StandaloneSynapse (TUnitType intype,
-                     C_BaseNeuron* insource, C_BaseNeuron* intarget,
-                     double ing, CModel* inM, int s_mask)
-      : C_BaseSynapse (intype, insource, intarget, ing, inM, s_mask),
-        C_StandaloneAttributes (__CNUDT[intype].vno)
+C_StandaloneSynapse (TUnitType type_,
+                     C_BaseNeuron* source_, C_BaseNeuron* target_,
+                     double g_, CModel* M_, int s_mask)
+      : C_BaseSynapse (type_, source_, target_, g_, M_, s_mask),
+        C_StandaloneAttributes (__CNUDT[type_].vno)
 {
         reset_vars();
         if ( M )
diff --git a/upstream/src/libcn/standalone-synapses.hh b/upstream/src/libcn/standalone-synapses.hh
index 391ff6f..8a0057f 100644
--- a/upstream/src/libcn/standalone-synapses.hh
+++ b/upstream/src/libcn/standalone-synapses.hh
@@ -40,8 +40,6 @@ class C_StandaloneSynapse
                              double ing, CModel*, int s_mask = 0);
 
     public:
-       ~C_StandaloneSynapse ();
-
         double &var_value( size_t v)                        { return V[v]; }
         const double &get_var_value( size_t v) const        { return V[v]; }
         double  S() const                                   { return V[0]; }
diff --git a/upstream/src/libstilton/Makefile.am b/upstream/src/libstilton/Makefile.am
index b7cf695..82a3a6a 100644
--- a/upstream/src/libstilton/Makefile.am
+++ b/upstream/src/libstilton/Makefile.am
@@ -7,8 +7,6 @@ libstilton_la_SOURCES = \
 	alg.hh \
 	containers.hh \
 	lang.hh \
-	exprparser.hh \
-	exprparser.cc \
 	libcommon.cc \
 	misc.hh
 
@@ -22,7 +20,6 @@ BUILT_SOURCES = \
 	alg.hh.gch \
 	containers.hh.gch \
 	lang.hh.gch \
-	exprparser.hh.gch \
 	misc.hh.gch
 
 CLEANFILES = $(BUILT_SOURCES)
diff --git a/upstream/src/libstilton/exprparser.cc b/upstream/src/libstilton/exprparser.cc
deleted file mode 100644
index f0328bc..0000000
--- a/upstream/src/libstilton/exprparser.cc
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- *       File name:  libstilton/exprparser.cc
- *         Project:  cnrun
- *          Author:  Andrei Zavada <johnhommer at gmail.com>
- * Initial version:  2008-12-02
- *
- *         Purpose:  Expression parser
- *
- *         License:  GPL
- */
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-#  include "config.h"
-#endif
-
-#include <cstdlib>
-#include <cstdio>
-#include <array>
-#include <iostream>
-
-#include "exprparser.hh"
-
-
-using namespace std;
-
-
-const char* const
-cnrun::stilton::CExpression::error_strings[] = {
-        "",
-        "Missing operand",
-        "Unbalanced parentheses",
-        "Unparsable value or missing operator",
-        "Unary operator used as binary",
-        "Undefined variable",
-        "Non-lvalue in assignment",
-        "varlist is NULL",
-        0,
-};
-
-
-
-
-enum TOperator {
-        OP_VOID = -1,
-        OP_NEG,
-        OP_UNARYMINUS,
-        OP_MULT,
-        OP_DIV,
-        OP_ADD,
-        OP_SUBTRACT,
-        OP_LT,
-        OP_GT,
-        OP_ASSIGN,
-        OP_LE,
-        OP_GE,
-        OP_EQ,
-};
-
-struct SOp {
-        char    literal[4];
-        int     prio;
-        bool    assoc_ltr,
-                is_binary;
-
-        SOp( const char *l, int p, bool a, bool b)
-              : prio (p), assoc_ltr (a), is_binary (b)
-                { strncpy( literal, l, 3); }
-
-        bool isat( const char *where) const
-                { return (strncmp( where, literal, strlen( literal)) == 0); }
-};
-
-
-
-inline namespace {
-const array<SOp, 12> Ops {
-        {
-                SOp("!", 1, false, false),
-                SOp("-", 1, false, false),
-                SOp("*", 3, true, true),
-                SOp("/", 3, true, true),
-                SOp("+", 5, true, true),
-                SOp("-", 5, true, true),
-                SOp("<", 7, true, true),
-                SOp(">", 7, true, true),
-                SOp("=", 9, false, true),
-                SOp("<=", 7, true, true),
-                SOp(">=", 7, true, true),
-                SOp("==", 7, true, true)
-        }
-};
-
-} // inline namespace
-
-
-
-cnrun::stilton::TExprParserError
-cnrun::stilton::CExpression::
-_do_parse( const string& str, double& parsed,
-           list<cnrun::stilton::SVariable> *varlist)
-{
-        if ( str.empty() ) {
-                parsed = 0;
-                return status = EXPARSE_OK;
-        }
-
-        parsed = NAN;
-        _var = "";
-
-        string  workbuf = str;
-        char   *p = &workbuf[0];
-
-        p += strspn( p, " \t");
-        if ( !*p ) {
-                parsed = 0;
-                return status = EXPARSE_EMPTY;
-        }
-
-        char   *expr1 = p,
-               *expr2 = nullptr;
-        TExprParserError subexpr_retval;
-
-      // determine subexpressions, if any, at top level
-        int     level = 0;
-        char   *tl_op_at = nullptr;
-        TOperator
-                tl_op = OP_VOID;
-        bool    last_token_was_operator = true;
-
-        while ( *p ) {
-                if ( *p == eol_comment_delim ) {
-                        *p = '\0';
-                        break;
-                }
-                if      ( *p == '(' )        ++level;
-                else if ( *p == ')' )        --level;
-
-                if ( level < 0 )
-                        return status = EXPARSE_UNBALANCED;
-                if ( level > 0 || isspace( *p) )
-                        goto end_detect;
-
-              // detect exponent (e-4)
-                if ( strncasecmp( p, "e-", 2) == 0 ) {
-                        p++;
-                        goto end_detect;
-                }
-              // serve the case of unary -: part one
-                if ( *p == '-' && last_token_was_operator ) {
-                        char *pp = p;
-                        while ( pp > &workbuf[0] && !isspace(*pp) )
-                                --pp;
-                        char *tp;
-                        if ( strtod( pp, &tp) )
-                                ;
-                        if ( tp > p ) { // we have indeed read a number
-                                p = tp - 1;
-                                last_token_was_operator = false;
-                                goto end_detect;
-                        }
-                }
-
-                int o;
-                for ( o = Ops.size()-1; o >= 0; --o ) // check for multibyte operators first (those are at end)
-                        if ( Ops[o].isat( p) ) {
-                                char *pp = p;
-                                p += strlen( Ops[o].literal) - 1; // anticipate general p++
-
-                                if ( o == OP_SUBTRACT && last_token_was_operator ) {
-                                        o = OP_UNARYMINUS;
-                                } else
-                                        if ( !last_token_was_operator && !Ops[o].is_binary ) {
-                                                if ( !silent ) fprintf( stderr, "Unary %s used after an operand\n", Ops[o].literal);
-                                                return status = EXPARSE_UNASSOC;
-                                        }
-
-                                if ( tl_op == OP_VOID ||
-                                     (Ops[o].assoc_ltr && Ops[tl_op].prio <= Ops[o].prio) ||
-                                     (!Ops[o].assoc_ltr && Ops[tl_op].prio < Ops[o].prio) ) {
-//                                        cerr << "current tlop: " << Ops[o].literal << endl;
-                                        tl_op_at = pp;
-                                        tl_op = (TOperator)o;
-                                }
-                                last_token_was_operator = true;
-                                goto end_detect;
-                        }
-
-                last_token_was_operator = false;
-
-        end_detect:
-                ++p;
-        }
-
-        if ( level > 0 ) {
-                if ( !silent ) fprintf( stderr, "Expression lacks some `)''\n");
-                return status = EXPARSE_UNBALANCED;
-        }
-
-        list<cnrun::stilton::SVariable>::iterator V;
-
-        if ( tl_op != OP_VOID ) {
-                *tl_op_at = '\0';
-                expr2 = tl_op_at + strlen( Ops[tl_op].literal);
-                double opd1, opd2;
-
-//                cerr << "parsing [" << expr1 << "] "<< Ops[tl_op].literal << " [" << expr2 << "]\n";
-
-              // second subexpr must always be good
-                subexpr_retval = _do_parse( expr2, opd2, varlist);
-                if ( subexpr_retval )
-                        return status = subexpr_retval;
-
-              // first subexpr must be empty, but only in the case of OP_NEG
-                subexpr_retval = _do_parse( expr1, opd1, varlist);
-
-                switch ( subexpr_retval ) {
-                case EXPARSE_OK:
-                        break;
-                case EXPARSE_EMPTY:
-                        if ( !Ops[tl_op].is_binary ) {
-//                                cerr << "was a unary op\n";
-                                break;
-                        } else
-                                return subexpr_retval;
-                case EXPARSE_UNDEFVAR:
-                        if ( tl_op == OP_ASSIGN )
-                                break;
-                        else {
-                                // have it reported here (in deeper _do_parse where it is flagged), we don't know yet
-                                // if an undefined var is going to be defined
-                                if ( !silent ) fprintf( stderr, "Undefined variable `%s'\n", strtok( expr1, " \t"));
-                                return status = subexpr_retval;
-                        }
-                      break;
-                default:
-                        return subexpr_retval;
-                }
-
-                switch ( tl_op ) {
-                case OP_VOID:        break;
-                case OP_UNARYMINUS: parsed = -opd2;              break;
-                case OP_ADD:        parsed = opd1 +  opd2;       break;
-                case OP_SUBTRACT:   parsed = opd1 -  opd2;       break;
-                case OP_MULT:       parsed = opd1 *  opd2;       break;
-                case OP_DIV:        parsed = opd1 /  opd2;       break;
-                case OP_LT:         parsed = opd1 <  opd2;       break;
-                case OP_LE:         parsed = opd1 <= opd2;       break;
-                case OP_GT:         parsed = opd1 >  opd2;       break;
-                case OP_GE:         parsed = opd1 >= opd2;       break;
-                case OP_EQ:         parsed = opd1 == opd2;       break;
-                case OP_NEG:        parsed = !opd2;              break;
-                case OP_ASSIGN:
-                        if ( !varlist ) {
-                                if ( !silent )
-                                        fprintf( stderr, "Variable assignment reqires a user varlist\n");
-                                return status = EXPARSE_VARLISTNULL;
-                        }
-                        if ( _var == "" ) {
-                                if ( !silent )
-                                        fprintf( stderr, "Non-lvalue in assignment\n");
-                                return status = EXPARSE_NONLVAL;
-                        }
-                        parsed = opd2;
-                        for ( V = varlist->begin(); V != varlist->end(); V++ )
-                                if ( strcmp( V->name, _var.c_str()) == 0 ) { // _var has been cached by a previous call to _do_parse
-                                        V->value = opd2;
-                                        toplevel_op = tl_op;
-                                        return status = EXPARSE_OK;
-                                }
-                        varlist->push_back( SVariable( _var.c_str(), opd2));
-                    break;
-                }
-                toplevel_op = tl_op;
-                return status = EXPARSE_OK;
-        }
-
-      // single expression, possibly in parentheses
-        if ( *expr1 == '(' ) {
-                *strrchr( ++expr1, ')') = '\0';  // parentheses have been checked in the by-char parser loop above
-                return _do_parse( expr1, parsed, varlist);
-        }
-
-      // bare expression
-        expr1 = strtok( expr1, " \t");
-        char *tailp;
-        parsed = strtod( expr1, &tailp);
-        if ( tailp == nullptr || strspn( tailp, " \t\n\r;") == strlen( tailp) )   // digits followed by whitespace
-                return status = EXPARSE_OK;
-
-        if ( tailp == expr1 && varlist ) { // no digits at front: check if that's a variable
-                for ( V = varlist->begin(); V != varlist->end(); V++ ) {
-                        if ( strcmp( V->name, expr1) == 0 ) {
-                                parsed = V->value;
-                                _var = V->name;
-                                return status = EXPARSE_OK;
-                        }
-                }
-                _var = expr1;  // possibly to be assigned in caller; parsed remains NAN
-                return status = EXPARSE_UNDEFVAR;
-        }
-
-      // some digits followed by rubbish
-        return status = EXPARSE_BAD;
-}
-
-// Local Variables:
-// Mode: c++
-// indent-tabs-mode: nil
-// tab-width: 8
-// c-basic-offset: 8
-// End:
diff --git a/upstream/src/libstilton/exprparser.hh b/upstream/src/libstilton/exprparser.hh
deleted file mode 100644
index f5e3630..0000000
--- a/upstream/src/libstilton/exprparser.hh
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *       File name:  libstilton/exprparser.hh
- *         Project:  cnrun
- *          Author:  Andrei Zavada <johnhommer at gmail.com>
- * Initial version: 2008-12-02
- *
- *         Purpose:  Expression parser
- *
- *         License:  GPL
- */
-
-#ifndef CNRUN_LIBSTILTON_EXPRPARSER_H_
-#define CNRUN_LIBSTILTON_EXPRPARSER_H_
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-#  include "config.h"
-#endif
-
-#include <cmath>
-#include <cstring>
-#include <string>
-#include <list>
-
-using namespace std;
-
-namespace cnrun {
-namespace stilton {
-
-
-enum TExprParserError {
-        EXPARSE_OK = 0,
-        EXPARSE_EMPTY,
-        EXPARSE_UNBALANCED,
-        EXPARSE_BAD,
-        EXPARSE_UNASSOC,
-        EXPARSE_UNDEFVAR,
-        EXPARSE_NONLVAL,
-        EXPARSE_VARLISTNULL
-};
-
-
-#define STILTON_MAX_VAR_LEN        32
-
-struct SVariable {
-        char name[STILTON_MAX_VAR_LEN];
-        double value;
-        SVariable( const char *inname, double invalue = NAN)
-              : value (invalue)
-                {
-                        strncpy( name, inname, STILTON_MAX_VAR_LEN-1);
-                }
-        bool operator== ( const SVariable &rv) const
-                {
-                        return strcmp( name, rv.name /*, STILTON_MAX_VAR_LEN */ ) == 0;
-                }
-        bool operator< ( const SVariable &rv) const
-                {
-                        return strcmp( name, rv.name /*, STILTON_MAX_VAR_LEN */ ) == -1;
-                }
-};
-
-
-class CExpression {
-
-    public:
-        TExprParserError status;
-
-        CExpression()
-              : status (EXPARSE_OK),
-                silent (false),
-                eol_comment_delim ('#'),
-                toplevel_op (' '),
-                _parsed_value (NAN)
-                {}
-        const char *error_string() const
-                {
-                        return error_strings[status];
-                }
-
-        double operator() ( const char *str, list<SVariable> *varlist = nullptr)
-                {
-                        return ( _do_parse( str, _parsed_value, varlist) == EXPARSE_OK )
-                                ? _parsed_value : NAN;
-                }
-        int operator() ( const char *str, double& parsed, list<SVariable> *varlist = nullptr)
-                {
-                        _do_parse( str, parsed, varlist);
-                        return status;
-                }
-
-        bool    silent;
-        char    eol_comment_delim;
-        char    toplevel_op;
-
-        static const char *const error_strings[];
-        const char *status_s() const
-                {
-                        return error_strings[status];
-                }
-
-    private:
-        double  _parsed_value;
-        string  _var;
-        TExprParserError _do_parse( const string& str, double& parsed, list<SVariable>*);
-};
-
-}
-}
-
-#endif
-
-// Local Variables:
-// Mode: c++
-// indent-tabs-mode: nil
-// tab-width: 8
-// c-basic-offset: 8
-// End:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/cnrun.git



More information about the debian-med-commit mailing list