Skip to content

Commit

Permalink
Merge branch 'master' into hines/hoc-class-instance-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nrnhines authored Sep 5, 2024
2 parents 6e658b5 + 1d812c8 commit 5334b9b
Show file tree
Hide file tree
Showing 32 changed files with 941 additions and 1,054 deletions.
67 changes: 33 additions & 34 deletions src/ivoc/checkpnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ data depending on type. eg for VAR && NOTUSER it is
#endif
#include "checkpnt.h"

#include "redef.h"
#include "hoclist.h"
#include "parse.hpp"
#include "code.h"
Expand All @@ -109,55 +108,55 @@ static struct HocInst {
Pfrv pi;
const char* signature;
} hoc_inst_[] = {{0, 0}, // 0
{nopop, 0},
{eval, 0},
{add, 0},
{hoc_nopop, 0},
{hoc_eval, 0},
{hoc_add, 0},
{hoc_sub, 0},
{mul, 0},
{hoc_mul, 0},
{hoc_div, 0},
{hoc_negate, nullptr},
{power, 0},
{hoc_power, 0},
{hoc_assign, nullptr},
{bltin, "s"}, // requires change
{varpush, "s"}, // 10
{constpush, "s"},
{pushzero, 0},
{print, 0},
{varread, "s"},
{prexpr, 0},
{prstr, 0},
{gt, 0},
{hoc_bltin, "s"}, // requires change
{hoc_varpush, "s"}, // 10
{hoc_constpush, "s"},
{hoc_pushzero, 0},
{hoc_print, 0},
{hoc_varread, "s"},
{hoc_prexpr, 0},
{hoc_prstr, 0},
{hoc_gt, 0},
{hoc_lt, nullptr},
{hoc_eq, nullptr}, // 20
{ge, 0},
{le, 0},
{ne, 0},
{hoc_ge, 0},
{hoc_le, 0},
{hoc_ne, 0},
{hoc_and, 0},
{hoc_or, 0},
{hoc_not, 0},
{ifcode, "iii"},
{forcode, "iii"},
{shortfor, "ii"},
{call, "si"}, // 30
{hoc_ifcode, "iii"},
{hoc_forcode, "iii"},
{hoc_shortfor, "ii"},
{hoc_call, "si"}, // 30
{hoc_arg, "i"},
{argassign, "i"},
{funcret, 0},
{procret, 0},
{hoc_argassign, "i"},
{hoc_funcret, 0},
{hoc_procret, 0},
{hoc_stringarg, "i"},
{hoc_push_string, "s"},
{Break, 0},
{Continue, 0},
{Stop, 0},
{assstr, 0}, // 40
{hoc_Break, 0},
{hoc_Continue, 0},
{hoc_Stop, 0},
{hoc_assstr, 0}, // 40
{hoc_evalpointer, 0},
{hoc_newline, 0},
{hoc_delete_symbol, "s"},
{hoc_cyclic, 0},
{dep_make, 0},
{eqn_name, 0},
{eqn_init, 0},
{eqn_lhs, 0}, // 50
{eqn_rhs, 0},
{hoc_dep_make, 0},
{hoc_eqn_name, 0},
{hoc_eqn_init, 0},
{hoc_eqn_lhs, 0}, // 50
{hoc_eqn_rhs, 0},
{hoc_objectvar, "s"},
{hoc_object_component, "siis"},
{hoc_object_eval, 0},
Expand Down
67 changes: 39 additions & 28 deletions src/nmodl/nocpout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,35 +428,10 @@ extern void nrn_promote(Prop*, int, int);\n\
defs_list,
"double get_loc_point_process(void*); return (get_loc_point_process(_vptr));\n}\n");
}
/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}
std::string hoc_setdata_arg = point_process ? "void*" : "";
Sprintf(buf, "static void _hoc_setdata(%s);\n", hoc_setdata_arg.c_str());
Lappendstr(defs_list, buf);

/* functions */
Lappendstr(defs_list, "/* connect user functions to hoc names */\n");
Expand Down Expand Up @@ -755,6 +730,42 @@ extern void nrn_promote(Prop*, int, int);\n\
}
}

/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
if (!artificial_cell) {
Lappendstr(defs_list,
"Node * _node = _nrn_mechanism_access_node(_prop);\n"
"v = _nrn_mechanism_access_voltage(_node);\n");
}
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}


/******** what normally goes into cabvars.h structures */

/*declaration of the range variables names to HOC */
Expand Down
2 changes: 1 addition & 1 deletion src/nrniv/glinerec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void GLineRecord::fill_pd1() {
rangevarevalpointer();
pd = hoc_pxpop();
hoc_pushx(*pd);
} else if (pc1->pf == varpush) {
} else if (pc1->pf == hoc_varpush) {
Symbol* sym = hoc_pc->sym;
if (strcmp(sym->name, "t") == 0) {
saw_t_ = true;
Expand Down
5 changes: 5 additions & 0 deletions src/nrnoc/membfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ void Memb_func::invoke_initialize(neuron::model_sorted_token const& sorted_token
long& _nrn_mechanism_access_alloc_seq(Prop* prop) {
return prop->_alloc_seq;
}

Node* _nrn_mechanism_access_node(Prop* prop) {
return prop->node;
}

double& _nrn_mechanism_access_a(Node* node) {
return node->a();
}
Expand Down
1 change: 1 addition & 0 deletions src/nrnoc/membfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ namespace _get {
// See https://github.com/neuronsimulator/nrn/issues/2234 for context of how this might be done
// better in future...
[[nodiscard]] long& _nrn_mechanism_access_alloc_seq(Prop*);
[[nodiscard]] Node* _nrn_mechanism_access_node(Prop* prop);
[[nodiscard]] double& _nrn_mechanism_access_a(Node*);
[[nodiscard]] double& _nrn_mechanism_access_b(Node*);
[[nodiscard]] double& _nrn_mechanism_access_d(Node*);
Expand Down
7 changes: 5 additions & 2 deletions src/nrnoc/section.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,20 @@ struct Node {
#include "hocdec.h" /* Prop needs Datum and Datum needs Symbol */
#endif


#define PROP_PY_INDEX 10
struct Prop {
// Working assumption is that we can safely equate "Prop" with "instance
// of a mechanism" apart from a few special cases like CABLESECTION
Prop(short type)
: _type{type} {
Prop(Node* node, short type)
: node(node)
, _type{type} {
if (type != CABLESECTION) {
m_mech_handle = neuron::container::Mechanism::owning_handle{
neuron::model().mechanism_data(type)};
}
}
Node* node; /* The node this property belongs to. */
Prop* next; /* linked list of properties */
short _type; /* type of membrane, e.g. passive, HH, etc. */
int dparam_size; /* for notifying hoc_free_val_array */
Expand Down
2 changes: 1 addition & 1 deletion src/nrnoc/treeset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Prop* prop_alloc(Prop** pp, int type, Node* nd) {
nrn_alloc_node_ = nd; // this might be null
v_structure_change = 1;
current_prop_list = pp;
auto* p = new Prop{static_cast<short>(type)};
auto* p = new Prop{nd, static_cast<short>(type)};
p->next = *pp;
p->ob = nullptr;
p->_alloc_seq = -1;
Expand Down
59 changes: 29 additions & 30 deletions src/oc/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ axis.cpp,v
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "hoc.h"
#include "gui-redirect.h"

#define CLIP 1e9
Expand Down Expand Up @@ -201,8 +200,8 @@ static void close_regraph(void) {
static void do_regraph(void) {
int i;
for (i = 0; i < regraph_index; i++) {
if (regraph_color[i] != color) {
set_color(regraph_color[i]);
if (regraph_color[i] != hoc_color) {
hoc_set_color(regraph_color[i]);
}
PLOT(regraph_narg[i], regraph_mode[i], regraph_x[i], *regraph_y[i]);
}
Expand All @@ -211,7 +210,7 @@ static void save_regraph_item(int narg, int mode, double x) {
regraph_narg[regraph_index] = narg;
regraph_mode[regraph_index] = mode;
regraph_x[regraph_index] = x;
regraph_color[regraph_index] = color;
regraph_color[regraph_index] = hoc_color;
if (narg == 1 && regraph_index < max_regraph_index) {
regraph_y[regraph_index] = &ystart;
regraph_index++;
Expand Down Expand Up @@ -282,7 +281,7 @@ static int PLOT(int narg, int mode, double x, double y) {
x = xorg + xscale * x;
y = yorg + yscale * y;
if (x <= xhigh && x >= xlow && y <= yhigh && y >= ylow) {
plt(mode, x, y);
hoc_plt(mode, x, y);
} else if (mode > 0) {
lastmode = 1;
ok = 0;
Expand Down Expand Up @@ -349,19 +348,19 @@ void hoc_axis(void) {
y0 = yorg;

if (!ifarg(1)) {
plt(1, XORG, y0);
hoc_plt(1, XORG, y0);
for (x = xstart; x <= xstop + 1e-10; x = x + (xstop - xstart) / xinc) {
i = xorg + xscale * x;
plt(2, i, y0);
plt(2, i, y0 + 10.);
plt(1, i, y0);
hoc_plt(2, i, y0);
hoc_plt(2, i, y0 + 10.);
hoc_plt(1, i, y0);
}
plt(1, x0, YORG);
hoc_plt(1, x0, YORG);
for (y = ystart; y <= ystop + 1e-10; y = y + (ystop - ystart) / yinc) {
j = yorg + yscale * y;
plt(2, x0, j);
plt(2, x0 + 10., j);
plt(1, x0, j);
hoc_plt(2, x0, j);
hoc_plt(2, x0 + 10., j);
hoc_plt(1, x0, j);
}

width = WIDTH;
Expand All @@ -376,9 +375,9 @@ void hoc_axis(void) {
offset = width * (int) strlen(s) / 2;
if (i == x0 && y0 != YORG)
offset = -width / 2;
plt(1, i - offset, y0 - 1.5 * height);
plt(-2, 0., 0.);
plprint(s);
hoc_plt(1, i - offset, y0 - 1.5 * height);
hoc_plt(-2, 0., 0.);
hoc_plprint(s);
}

for (y = ystart; y <= ystop + 1e-10; y = y + (ystop - ystart) / yinc) {
Expand All @@ -389,13 +388,13 @@ void hoc_axis(void) {
offset = width * (int) strlen(s) + width;
j = yorg + yscale * y;
if (j == y0 && x0 != XORG)
plt(1, x0 - offset, j + 2.);
hoc_plt(1, x0 - offset, j + 2.);
else
plt(1, x0 - offset, j - 6.);
plt(-2, 0., 0.);
plprint(s);
hoc_plt(1, x0 - offset, j - 6.);
hoc_plt(-2, 0., 0.);
hoc_plprint(s);
}
plt(-1, 0., 0.);
hoc_plt(-1, 0., 0.);
}
Ret(1.);
}
Expand Down Expand Up @@ -543,13 +542,13 @@ static void plotflush(int contin) {
for (i = 0; i < NPARAM; i++) {
parsav[i] = param[i];
}
savcolor = color;
savcolor = hoc_color;
for (g = glist_head; g != (Grph*) 0; g = g->g_next) {
for (i = 0; i < NPARAM; i++) {
param[i] = g->g_param[i];
}
if (color != g->g_color) {
IGNORE(set_color(g->g_color));
if (hoc_color != g->g_color) {
IGNORE(hoc_set_color(g->g_color));
}
IGNORE(PLOT(1, 1, 0., 0.));
for (i = 0; i < pcnt; i++) {
Expand All @@ -562,8 +561,8 @@ static void plotflush(int contin) {
for (i = 0; i < NPARAM; i++) {
param[i] = parsav[i];
}
if (savcolor != color) {
IGNORE(set_color(savcolor));
if (savcolor != hoc_color) {
IGNORE(hoc_set_color(savcolor));
}
if (contin == 2 && pcnt > 0) {
lx[0] = lx[pcnt - 1];
Expand All @@ -585,19 +584,19 @@ static void do_setup(void) {
for (i = 0; i < NPARAM; i++) {
parsav[i] = param[i];
}
savcolor = color;
savcolor = hoc_color;
for (g = glist_head; g != (Grph*) 0; g = g->g_next) {
hoc_run_stmt(g->g_setup);
for (i = 0; i < NPARAM; i++) {
g->g_param[i] = param[i];
}
g->g_color = color;
g->g_color = hoc_color;
}
for (i = 0; i < NPARAM; i++) {
param[i] = parsav[i];
}
if (savcolor != color) {
IGNORE(set_color(savcolor));
if (savcolor != hoc_color) {
IGNORE(hoc_set_color(savcolor));
}
initialized = 1;
}
Loading

0 comments on commit 5334b9b

Please sign in to comment.