124
124
(pointer) = NULL; \
127
#define GE_POP_STACKNF(thectx,pointer) { \
128
if((thectx)->topstack != (gpointer *)(thectx)->stack || \
129
ge_remove_stack_array(ctx)) { \
130
-- (thectx)->topstack; \
131
*((thectx)->topstack) = NULL; \
132
(pointer) = *(-- (thectx)->topstack); \
133
*((thectx)->topstack) = NULL; \
127
138
#else /* MEM_DEBUG_FRIENDLY */
128
139
#define GE_POP_STACK(thectx,pointer,flag) { \
129
140
if G_LIKELY ((thectx)->topstack != (gpointer *)(thectx)->stack || \
1178
/* we know we are a row matrix */
1180
quick_wide_expand (GelETree *n)
1184
GelMatrixW *nm = n->mat.matrix;
1188
for (i = 0; i < gel_matrixw_width (nm); i++) {
1189
GelETree *et = gel_matrixw_get_index (nm, i, 0);
1194
} else if (et->type == GEL_MATRIX_NODE) {
1195
if (gel_matrixw_height (et->mat.matrix) > h)
1196
h = gel_matrixw_height (et->mat.matrix);
1197
w += gel_matrixw_width (et->mat.matrix);
1198
} else if (et->type != GEL_NULL_NODE) {
1205
gel_matrixw_make_private (nm, FALSE /* kill_type_caches */);
1207
m = gel_matrix_new();
1208
gel_matrix_set_size(m, w, h, TRUE /* padding */);
1211
for (i = 0; i < gel_matrixw_width (nm); i++) {
1212
GelETree *et = gel_matrixw_get_index (nm, i, 0);
1215
} else if (et->type == GEL_MATRIX_NODE) {
1216
int hh = gel_matrixw_height (et->mat.matrix);
1217
int ww = gel_matrixw_width (et->mat.matrix);
1219
GelMatrixW *mm = et->mat.matrix;
1221
gel_matrixw_make_private (mm,
1222
FALSE /* kill_type_caches */);
1224
for (ii = 0; ii < ww; ii++) {
1226
for (jj = 0; jj < hh; jj++) {
1228
gel_matrixw_get_index (mm, ii, jj);
1229
gel_matrix_index (m, j+ii, jj) = e;
1230
gel_matrixw_set_index (mm, ii, jj) = NULL;
1233
for (; jj < h; jj++) {
1235
gel_matrix_index (m, j+ii, jjj);
1237
gel_matrix_index (m, j+ii, jj) = gel_copynode (e);
1243
} else if (et->type != GEL_NULL_NODE) {
1245
gel_matrixw_set_index (nm, i, 0) = NULL;
1246
gel_matrix_index (m, j, 0) = et;
1247
for (jj = 1; jj < h; jj++) {
1248
gel_matrix_index (m, j, jj) = gel_copynode (et);
1254
freetree_full (n, TRUE, FALSE);
1256
n->type = GEL_MATRIX_NODE;
1257
n->mat.matrix = gel_matrixw_new_with_matrix (m);
1258
n->mat.quoted = FALSE;
1156
1261
/*evaluate a matrix (or try to), it will try to expand the matrix and
1157
1262
put 0's into the empty, undefined, spots. For example, a matrix such
1158
1263
as if b = [8,7]; a = [1,2:3,b] should expand to, [1,2,2:3,8,7] */
1209
1319
cols = gel_matrixw_width (nm);
1211
1321
for (i = 0, k = 0; i < h; i++) {
1213
w = expand_row (m, nm, k, i, &need_colwise);
1323
kk = expand_row (m, nm, k, i, &need_colwise);
1390
1500
logicalxorop(GelCtx *ctx, GelETree *n, GelETree *l, GelETree *r)
1392
1502
gboolean bad_node = FALSE;
1393
gboolean ret = gel_isnodetrue (l, &bad_node) != gel_isnodetrue (r,& bad_node);
1503
gboolean ret = gel_isnodetrue (l, &bad_node) != gel_isnodetrue (r, &bad_node);
1395
1505
if G_UNLIKELY (bad_node || gel_error_num) {
1396
1506
gel_error_num = GEL_NO_ERROR;
1924
2034
n->op.oper == GEL_E_ELTPLUS ||
1925
2035
n->op.oper == GEL_E_MINUS ||
1926
2036
n->op.oper == GEL_E_ELTMINUS)
1927
gel_errorout (_("Can't add/subtract two matricies of different sizes"));
2037
gel_errorout (_("Can't add/subtract two matrices of different sizes"));
1929
gel_errorout (_("Can't do element by element operations on two matricies of different sizes"));
2039
gel_errorout (_("Can't do element by element operations on two matrices of different sizes"));
1932
2042
l->mat.quoted = l->mat.quoted || r->mat.quoted;
3425
3536
f = d_lookup_global(n->id.id);
3426
3537
if G_UNLIKELY (f == NULL) {
3428
if (strcmp (n->id.id->token, "i") == 0) {
3429
gel_errorout (_("Variable 'i' used uninitialized. "
3430
"Perhaps you meant to write '1i' for "
3431
"the imaginary number (square root of "
3433
} else if ((similar = gel_similar_possible_ids (n->id.id->token))
3435
gel_errorout (_("Variable '%s' used uninitialized, "
3436
"perhaps you meant %s."),
3539
if ( ! n->id.uninitialized) {
3540
if (strcmp (n->id.id->token, "i") == 0) {
3541
gel_errorout (_("Variable 'i' used uninitialized. "
3542
"Perhaps you meant to write '1i' for "
3543
"the imaginary number (square root of "
3545
} else if ((similar = gel_similar_possible_ids (n->id.id->token))
3547
gel_errorout (_("Variable '%s' used uninitialized, "
3548
"perhaps you meant %s."),
3442
gel_errorout (_("Variable '%s' used uninitialized"),
3554
gel_errorout (_("Variable '%s' used uninitialized"),
3558
/* save that we have determined that this was
3560
n->id.uninitialized = TRUE;
3447
3563
return iter_do_var(ctx,n,f);
3459
3575
f = d_lookup_global(l->id.id);
3460
3576
if G_UNLIKELY (f == NULL) {
3461
3577
char *similar = gel_similar_possible_ids (l->id.id->token);
3462
if (similar != NULL) {
3463
gel_errorout (_("Variable '%s' used uninitialized, "
3464
"perhaps you meant %s."),
3578
if ( ! l->id.uninitialized) {
3579
if (similar != NULL) {
3580
gel_errorout (_("Variable '%s' used uninitialized, "
3581
"perhaps you meant %s."),
3470
gel_errorout (_("Variable '%s' used uninitialized"),
3587
gel_errorout (_("Variable '%s' used uninitialized"),
3591
/* save that we have determined that this was
3593
l->id.uninitialized = TRUE;
3473
3594
} else if G_UNLIKELY (f->nargs != 0) {
3474
3595
gel_errorout (_("Call of '%s' with the wrong number of arguments!\n"
3475
3596
"(should be %d)"), f->id ? f->id->token : "anonymous", f->nargs);
3979
4101
GelEvalFor *evf = data;
3981
mpw_add(evf->x,evf->x,evf->by);
4102
gboolean done = FALSE;
4104
mpw_add (evf->x, evf->x, evf->by);
3983
mpw_add_ui(evf->x,evf->x,1);
3985
if(mpw_cmp(evf->x,evf->to) == -evf->init_cmp) {
4106
mpw_add_ui (evf->x, evf->x, 1);
4107
/* we know we aren't dealing with complexes */
4108
if (mpw_is_real_part_float (evf->x)) {
4109
int thecmp = mpw_cmp (evf->x, evf->to);
4110
if (mpw_cmp (evf->x, evf->to) == -evf->init_cmp) {
4111
/* maybe we just missed it, let's look back within 2^-20 of the by and see */
4113
if (evf->by != NULL) {
4115
/* by is definitely mpfr */
4116
mpw_init_set (tmp, evf->by);
4117
f = mpw_peek_real_mpf (tmp);
4118
mpfr_mul_2si (f, f, -20, GMP_RNDN);
4121
mpw_set_d (tmp, 1.0/1048576.0 /* 2^-20 */);
4124
mpw_sub (tmp, evf->x, tmp);
4126
done = (mpw_cmp(tmp,evf->to) == -evf->init_cmp);
4128
/* don't use x, but use the to, x might be too far */
4130
mpw_set (evf->x, evf->to);
4139
done = (mpw_cmp(evf->x,evf->to) == -evf->init_cmp);
3987
4144
GE_POP_STACK(ctx,data,flag);
3988
4145
g_assert ((flag & GE_MASK) == GE_POST);
4478
4638
GEL_GET_L(l,ll);
4479
4639
f = d_lookup_global(ll->id.id);
4480
4640
if (f == NULL) {
4481
if G_UNLIKELY ( ! silent) {
4641
if G_UNLIKELY ( ! silent &&
4642
! ll->id.uninitialized) {
4482
4643
gel_errorout (_("Variable '%s' used uninitialized"),
4483
4644
ll->id.id->token);
4645
/* save that we have determined that this was
4647
ll->id.uninitialized = TRUE;
4486
} else if(f->type != GEL_REFERENCE_FUNC) {
4650
} else if (f->type != GEL_REFERENCE_FUNC) {
4487
4651
if G_UNLIKELY ( ! silent) {
4488
4652
gel_errorout (_("Can't dereference '%s'!"),
4489
4653
ll->id.id->token);
4877
5042
} else if(init_cmp==0) {
5045
if (mpw_is_real_part_float (from->val.value) ||
5046
mpw_is_real_part_float (to->val.value)) {
5047
/* ensure all float */
5048
mpw_make_float (to->val.value);
5049
mpw_make_float (from->val.value);
4880
5051
evf = evf_new(type, from->val.value,to->val.value,NULL,init_cmp,
4881
5052
gel_copynode(body),body,ident->id.id);
4883
5054
int sgn = mpw_sgn(by->val.value);
5055
/*if no iterations*/
4884
5056
if((sgn>0 && init_cmp>0) || (sgn<0 && init_cmp<0)) {
4885
5057
d_addfunc(d_makevfunc(ident->id.id,gel_copynode(from)));
4886
5058
freetree_full(n,TRUE,FALSE);
4897
5069
if(init_cmp == 0)
4898
5070
init_cmp = -sgn;
5071
if (mpw_is_real_part_float (from->val.value) ||
5072
mpw_is_real_part_float (to->val.value) ||
5073
mpw_is_real_part_float (by->val.value)) {
5074
/* ensure all float */
5075
mpw_make_float (to->val.value);
5076
mpw_make_float (from->val.value);
5077
mpw_make_float (by->val.value);
4899
5079
evf = evf_new(type, from->val.value,to->val.value,by->val.value,
4900
5080
init_cmp,gel_copynode(body),body,ident->id.id);
5523
5703
} else if(l->op.oper == GEL_E_GET_ELEMENT) {
5524
5704
GelMatrixW *mat;
5525
GelETree *m, *index1, *index2;
5526
GEL_GET_LRR (l, m, index1, index2);
5705
GelETree *index1, *index2;
5706
GEL_GET_XRR (l, index1, index2);
5528
5708
if (index1->type == GEL_VALUE_NODE &&
5529
5709
index2->type == GEL_VALUE_NODE) {
5814
5994
} else if(l->op.oper == GEL_E_GET_ELEMENT) {
5815
5995
GelMatrixW *mat;
5816
GelETree *m, *index1, *index2;
5817
GEL_GET_LRR (l, m, index1, index2);
5996
GelETree *index1, *index2;
5997
GEL_GET_XRR (l, index1, index2);
5819
5999
if (index1->type == GEL_VALUE_NODE &&
5820
6000
index2->type == GEL_VALUE_NODE) {
5977
6157
rf->data.user = tmp;
5978
6158
} else if(r->op.oper == GEL_E_GET_ELEMENT) {
5979
6159
GelMatrixW *mat;
5980
GelETree *m, *index1, *index2;
5981
GEL_GET_LRR (r, m, index1, index2);
6160
GelETree *index1, *index2;
6161
GEL_GET_XRR (r, index1, index2);
5983
6163
if (index1->type == GEL_VALUE_NODE &&
5984
6164
index2->type == GEL_VALUE_NODE) {
6064
6244
if (l->op.oper == GEL_E_GET_ELEMENT) {
6065
GelETree *m, *index1, *index2;
6066
GEL_GET_LRR (l, m, index1, index2);
6245
GelETree *index1, *index2;
6246
GEL_GET_XRR (l, index1, index2);
6068
6248
if (index1->type == GEL_VALUE_NODE &&
6069
6249
index2->type == GEL_VALUE_NODE) {
6098
6278
if (r->op.oper == GEL_E_GET_ELEMENT) {
6099
GelETree *m, *index1, *index2;
6100
GEL_GET_LRR (r, m, index1, index2);
6279
GelETree *index1, *index2;
6280
GEL_GET_XRR (r, index1, index2);
6102
6282
if (index1->type == GEL_VALUE_NODE &&
6103
6283
index2->type == GEL_VALUE_NODE) {
6203
6383
static inline void
6204
6384
iter_push_indexes_and_arg(GelCtx *ctx, GelETree *n)
6208
6388
GEL_GET_L(n,l);
6210
6390
if (l->op.oper == GEL_E_GET_ELEMENT) {
6211
6391
GelETree *ll,*rr;
6213
GEL_GET_LRR(l,ident,ll,rr);
6393
GEL_GET_XRR(l,ll,rr);
6215
6395
GE_PUSH_STACK(ctx,n->op.args->any.next,GE_PRE);
6216
6396
GE_PUSH_STACK(ctx,rr,GE_PRE);
6238
6418
static inline void
6239
6419
iter_do_push_index (GelCtx *ctx, GelETree *l)
6243
6421
if (l->op.oper == GEL_E_GET_ELEMENT) {
6244
6422
GelETree *ll,*rr;
6246
GEL_GET_LRR(l,ident,ll,rr);
6424
GEL_GET_XRR(l,ll,rr);
6248
6426
GE_PUSH_STACK(ctx,rr,GE_PRE);
6249
6427
GE_PUSH_STACK(ctx,ll,GE_PRE);
8111
8289
(respect_type &&
8112
8290
(mpw_is_complex (l->val.value) ||
8113
8291
mpw_is_complex (r->val.value) ||
8114
mpw_is_float (l->val.value) ||
8115
mpw_is_float (r->val.value))))
8292
mpw_is_real_part_float (l->val.value) ||
8293
mpw_is_real_part_float (r->val.value))))
8118
8296
(*func)(res,l->val.value,r->val.value);