Lines Matching refs:cx

38 clear(Cx_t* cx)
40 if (cx->include)
41 cx->include->next = cx->include->last = cx->include->base = 0;
49 next(Cx_t* cx)
53 if (cx->eof || !cx->include)
57 while (cx->include->next >= cx->include->last)
59 if (cx->include->newline > 1)
61 cx->include->newline--;
64 if (cx->include->prompt)
66 if (cx->include->head)
68 cx->include->head = 0;
69 sfputr(sfstderr, cx->disc->ps1, -1);
72 sfputr(sfstderr, cx->disc->ps2 ? cx->disc->ps2 : "> ", -1);
74 if ((cx->include->base = sfgetr(cx->include->sp, '\n', 0)) && !(cx->include->newline = 0) || (cx->include->base = sfgetr(cx->include->sp, '\n', -1)) && (cx->include->newline = 2))
76 cx->include->next = cx->include->base;
77 cx->include->last = cx->include->base + sfvalue(cx->include->sp);
79 if (cx->flags & (CX_DEBUG|CX_TRACE))
80 sfprintf(sfstderr, "+%d+ %-.*s%s", error_info.line, cx->include->last - cx->include->next, cx->include->base, cx->include->newline ? "\n" : "");
82 else if (cx->include->final || !cx->include->pop)
84 cx->include->eof = 1;
87 else if (cxpop(cx, cx->include) <= 0)
94 * cx->include->last is on the boundary of an
100 c = *cx->include->next;
101 cx->include->next++;
102 if (c != '\\' || cx->include->next >= cx->include->last)
104 if ((c = *cx->include->next++) != '\\' || cx->include->next >= cx->include->last)
107 if (*cx->include->next == '\r' && ++cx->include->next >= cx->include->last)
109 if (*cx->include->next != '\n')
111 if (++cx->include->next >= cx->include->last)
120 _trace_next(Cx_t* cx)
125 c = next(cx);
128 error(-2, "cxcomp next include=%p eof=%d '%s'", cx->include, cx->include->eof, c ? fmtesc(buf) : "\\0");
141 back(Cx_t* cx)
143 if (cx->include->next > cx->include->base)
145 if (cx->include && cx->include->newline == 1)
146 cx->include->newline++;
148 cx->include->next--;
157 peek(Cx_t* cx, int span)
161 while (isspace(c = next(cx)) && (c != '\n' || span));
163 back(cx);
172 cxcontext(Cx_t* cx)
177 for (t = cx->include->next; t > cx->include->base && *(t-1) == '\n'; t--);
178 if ((t - cx->include->base) < 40)
179 sfprintf(cx->tp, "%-.*s<<<", t - cx->include->base, cx->include->base);
182 for (s = t - 30; s > cx->include->base && (cx->ctype[*(unsigned char*)s] & (CX_CTYPE_ALPHA|CX_CTYPE_DIGIT)); s--);
183 sfprintf(cx->tp, ">>>%-.*s<<<", t - s, s);
185 if (!(s = sfstruse(cx->tp)))
278 cxcodetrace(Cx_t* cx, const char* fun, Cxinstruction_t* pc, unsigned int offset, Cxoperand_t* bp, Cxoperand_t* sp)
293 else if (pc->type == cx->state->type_string)
295 else if (pc->type == cx->state->type_number)
297 else if (pc->type != cx->state->type_void)
303 if ((sp-1)->type == cx->state->type_string)
305 else if ((sp-1)->type == cx->state->type_number)
307 else if ((sp-1)->type != cx->state->type_void)
311 if (sp->type == cx->state->type_string)
313 else if (sp->type == cx->state->type_number)
315 else if (sp->type != cx->state->type_void)
355 cxpush(Cx_t* cx, const char* file, Sfio_t* sp, const char* buf, ssize_t len, Cxflags_t flags)
366 if (buf && cx->disc->errorf)
367 (*cx->disc->errorf)(NiL, cx->disc, 1, "both file and buffer specified -- buffer ignored");
376 if (cx->disc->errorf)
377 (*cx->disc->errorf)(NiL, cx->disc, 2, "out of space");
389 prompt = cx->disc->ps1 && isatty(sffileno(sp));
395 else if (!(path = pathfind(file, cx->id, NiL, tmp, sizeof(tmp))))
397 if (cx->disc->errorf)
398 (*cx->disc->errorf)(NiL, cx->disc, 2, "%s: include file not found", file);
403 if (cx->disc->errorf)
404 (*cx->disc->errorf)(NiL, cx->disc, 2, "%s: cannot read", path);
409 if (!(ip = vmnewof(cx->vm, 0, Cxinclude_t, 1, path ? strlen(path) : 0)))
413 if (cx->disc->errorf)
414 (*cx->disc->errorf)(NiL, cx->disc, 2, "out of space");
424 ip->eof = cx->eof;
425 cx->eof = 0;
426 ip->interactive = cx->interactive;
427 cx->interactive = ip->prompt = prompt;
428 ip->pop = cx->include;
429 cx->include = ip;
442 cxpop(Cx_t* cx, void* pop)
447 if (!(ip = cx->include))
449 cx->eof = 1;
456 cx->include = ip->pop;
459 cx->interactive = ip->interactive;
460 vmfree(cx->vm, ip);
461 } while (ip != pp && (ip = cx->include));
462 cx->eof = !cx->include;
463 return cx->include ? 1 : 0;
467 * add (*donef)(cx,data,disc) to the list to be called at cxfree(cx,expr)
472 cxatfree(Cx_t* cx, Cxexpr_t* expr, Cxdone_f donef, void* data)
480 if (cx->disc->errorf)
481 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
492 (*dp->donef)(cx, dp->data, cx->disc);
505 identifier(Cx_t* cx, Cxcompile_t* cc, register int c, Cxoperand_t* r)
509 c = next(cx);
510 if (!cx->referencef)
512 if (cx->disc->errorf)
513 (*cx->disc->errorf)(cx, cx->disc, 2, "%s variables not supported", cxcontext(cx));
517 sfputc(cx->tp, c);
524 sfputc(cx->tp, c);
525 } while (cx->ctype[c = next(cx)] & (CX_CTYPE_ALPHA|CX_CTYPE_DIGIT));
528 if (next(cx) != ':')
530 back(cx);
534 sfputc(cx->tp, c);
536 back(cx);
538 r->type = cx->state->type_string;
539 r->value.string.size = sfstrtell(cx->tp);
540 r->value.string.data = sfstruse(cx->tp);
549 variable(Cx_t* cx, Cxcompile_t* cc, int c, Cxtype_t* m, Cxtype_t** type)
555 if (identifier(cx, cc, c, &a))
560 if (!(r.value.variable = cxfunction(cx, a.value.string.data, cx->disc)))
566 if (type && (*type = (Cxtype_t*)dtmatch(cx->types, a.value.string.data)) || (*cx->referencef)(cx, NiL, &r, &b, &a, NiL, cx->disc))
577 cast(Cx_t* cx, Cxinstruction_t* pc, Cxoperand_t* r, Cxoperand_t* a, Cxoperand_t* b, void* data, Cxdisc_t* disc)
579 if ((*r->type->internalf)(cx, r->type, NiL, &r->type->format, r, r->value.string.data, r->value.string.size, cx->em, cx->disc) < 0)
581 (*cx->disc->errorf)(cx, cx->disc, 2, "cannot cast from %s to %s", r->type->name, r->type->fundamental->name);
592 edit(Cx_t* cx, Cxinstruction_t* pc, Cxoperand_t* r, Cxoperand_t* a, Cxoperand_t* b, void* data, Cxdisc_t* disc)
594 return cxsuball(cx, (Cxpart_t*)pc->data.pointer, r);
602 codecast(Cx_t* cx, Cxcompile_t* cc, Cxtype_t* t, Cxcallout_f cast, void* pointer)
611 if ((cx->flags & CX_DEBUG) && sfstrtell(cc->xp))
612 cxcodetrace(cx, "comp", &c, (unsigned int)sfstrtell(cc->xp) / sizeof(c), 0, 0);
622 code(Cx_t* cx, Cxcompile_t* cc, Cxexpr_t* expr, int op, int pp, Cxtype_t* type1, Cxtype_t* type2, void* pointer, Cxnumber_t number, Cxvariable_t* ref)
639 x.type = cx->table->comparison[op] ? cx->state->type_number : type1;
652 if (((f = cxrecode(cx, op, type1, type2, cx->disc)) || (f = cxrecode(cx, op, cx->state->type_void, cx->state->type_void, cx->disc))) && (*f)(cx, expr, &x, NiL, NiL, NiL, cx->disc))
668 if ((i1->op == CX_GET || i1->op == CX_CAST && (i1 - 1)->op == CX_GET) && (f = cxrecode(cx, op, type1, type2, cx->disc)))
672 if ((*f)(cx, expr, &x, i1, i2, NiL, cx->disc))
685 if (x.callout = cxcallout(cx, op, type1, type2, cx->disc))
690 if (x.callout = cxcallout(cx, op, type1, type2, cx->disc))
695 if (v1 && (c.callout = cxcallout(cx, CX_CAST, type1, type2, cx->disc)) && (x.callout = cxcallout(cx, op, type2, type2, cx->disc)))
702 if ((cx->flags & CX_DEBUG) && sfstrtell(cc->xp))
703 cxcodetrace(cx, "comp", &c, (unsigned int)sfstrtell(cc->xp) / sizeof(c), 0, 0);
705 if ((cx->flags & CX_DEBUG) && sfstrtell(cc->xp))
706 cxcodetrace(cx, "comp", &t, (unsigned int)sfstrtell(cc->xp) / sizeof(c), 0, 0);
710 if (x.callout = cxcallout(cx, op, type1, type1, cx->disc))
712 if (v1 && v1->format.map && cxisstring(type2) && !cxstr2num(cx, &v1->format, i2->data.string.data, i2->data.string.size, &m))
715 i2->type = cx->state->type_number;
719 if (v2 && v2->format.map && cxisstring(type1) && !cxstr2num(cx, &v2->format, i1->data.string.data, i1->data.string.size, &m))
722 i1->type = cx->state->type_number;
731 i2->type = cx->state->type_number;
737 if ((*type1->internalf)(cx, type1, NiL, &format, &r, i2->data.string.data, i2->data.string.size, cc->vm, cx->disc) < 0)
740 i2->type = cx->state->type_number;
747 if (i1->op == CX_STR && i1->data.string.size == 1 && (x.callout = cxcallout(cx, op, type2, type2, cx->disc)))
750 i1->type = cx->state->type_number;
756 if (type1->fundamental == type2->fundamental && (x.callout = cxcallout(cx, op, type1->fundamental, type1->fundamental, cx->disc)))
758 if (v1 && cxisstring(type1) && !v2 && cxisnumber(type2) && (x.callout = cxcallout(cx, op, type1->fundamental, type1->fundamental, cx->disc)) && !cxnum2str(cx, &v1->format, i2->data.number, &s))
764 if (cx->disc->errorf)
765 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
771 if (v2 && cxisstring(type2) && !v1 && cxisnumber(type1) && (x.callout = cxcallout(cx, op, type2->fundamental, type2->fundamental, cx->disc)) && !cxnum2str(cx, &v2->format, i1->data.number, &s))
777 if (cx->disc->errorf)
778 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
784 if (cxisstring(type2) && type1->internalf && (x.callout = cxcallout(cx, op, type1->fundamental, type1->fundamental, cx->disc)))
786 if (cxisnumber(type1) && v1 && v1->format.map && !cxstr2num(cx, &v1->format, i2->data.string.data, i2->data.string.size, &m))
796 if ((*type1->internalf)(cx, type1, NiL, &format, &r, i2->data.string.data, i2->data.string.size, cc->vm, cx->disc) < 0)
804 if (cxisstring(type1) && type2->internalf && (x.callout = cxcallout(cx, op, type2->fundamental, type2, cx->disc)))
806 if (cxisnumber(type2) && v2 && v2->format.map && !cxstr2num(cx, &v2->format, i1->data.string.data, i1->data.string.size, &m))
816 if ((*type2->internalf)(cx, type2, NiL, &format, &r, i1->data.string.data, i1->data.string.size, cc->vm, cx->disc) < 0)
825 if (x.callout = cxcallout(cx, op, cx->state->type_void, cx->state->type_void, cx->disc))
827 if (cx->disc->errorf)
828 (*cx->disc->errorf)(cx, cx->disc, 2, "%s %s not supported [%d:%d] %p", cxcontext(cx), cxopname(op, type1, type2), cxrepresentation(type1), cxrepresentation(type2), cxcallout(cx, op, cx->state->type_string, cx->state->type_string, cx->disc));
831 if ((cx->flags & CX_DEBUG) && sfstrtell(cc->xp))
832 cxcodetrace(cx, "comp", &x, (unsigned int)sfstrtell(cc->xp) / sizeof(x), 0, 0);
835 if (cx->disc->errorf)
836 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
840 codecast(cx, cc, v1->type, edit, v1->format.map->part);
853 prototype(Cx_t* cx, Cxcompile_t* cc, Cxvariable_t* v, Cxtype_t** tp, char** sp, char** ep, int* op)
898 t = cx->state->type_void;
905 t = cx->state->type_void;
909 else if (c == '&' && (cx->ctype[*(unsigned char*)s] & CX_CTYPE_ALPHA) || (cx->ctype[c] & CX_CTYPE_ALPHA))
913 for (u = buf; (cx->ctype[*(unsigned char*)s] & (CX_CTYPE_ALPHA|CX_CTYPE_DIGIT)); s++)
917 if (t = cxtype(cx, buf, cx->disc))
920 t = cx->state->type_reference;
925 if (cx->disc->errorf)
926 (*cx->disc->errorf)(cx, cx->disc, 2, "%s %s: unknown prototype type name", cxcontext(cx), buf);
944 parse(Cx_t* cx, Cxcompile_t* cc, Cxexpr_t* expr, int precedence, Cxvariable_t** ref)
969 t = cx->state->type_void;
975 while (c = next(cx))
977 if (o = cx->table->opcode[c])
980 if ((p = next(cx)) == c)
982 p = next(cx);
999 back(cx);
1008 back(cx);
1015 if (cx->disc->errorf)
1016 (*cx->disc->errorf)(cx, cx->disc, 2, "%s operator requires lvalue", cxcontext(cx));
1019 if (!(v = variable(cx, cc, 0, m, 0)))
1026 if (!code(cx, cc, expr, CX_GET, 1, v->type, cx->state->type_void, v, 0, NiL))
1028 if (!code(cx, cc, expr, CX_NUM, 1, cx->state->type_number, cx->state->type_void, NiL, 1.0, NiL))
1030 if (!code(cx, cc, expr, o & ~CX_X2, -1, v->type, cx->state->type_number, NiL, 0, NiL))
1032 if (!code(cx, cc, expr, CX_SET, 0, cx->state->type_void, v->type, v, 0, NiL))
1036 if (!code(cx, cc, expr, CX_NUM, 1, cx->state->type_number, cx->state->type_void, NiL, -1.0, NiL))
1038 if (!code(cx, cc, expr, o & ~CX_X2, -1, v->type, cx->state->type_number, NiL, 0, NiL))
1047 if (o == CX_AND && precedence == cx->table->precedence[CX_CALL])
1050 back(cx);
1053 if ((o & CX_ASSIGN) && !cx->table->comparison[o])
1057 if (cx->disc->errorf)
1058 (*cx->disc->errorf)(cx, cx->disc, 2, "%s assignment requires lvalue", cxcontext(cx));
1061 p = cx->table->precedence[CX_SET];
1067 if (!code(cx, cc, expr, CX_GET, 1, v->type, cx->state->type_void, v, 0, NiL))
1073 if (!(v = variable(cx, cc, 0, m, 0)))
1076 if (!code(cx, cc, expr, CX_REF, 1, cx->state->type_reference, cx->state->type_void, v, 0, NiL))
1086 if (!code(cx, cc, expr, CX_NUM, 1, cx->state->type_type_t, cx->state->type_void, t, 0, NiL))
1093 if (!code(cx, cc, expr, CX_GET, 1, v->type, cx->state->type_void, v, 0, NiL))
1097 p = cx->table->precedence[o];
1103 if (cx->disc->errorf)
1106 (*cx->disc->errorf)(cx, cx->disc, 2, "%s operand expected [o=%04x]", cxcontext(cx), o);
1108 (*cx->disc->errorf)(cx, cx->disc, 2, "%s unknown operator", cxcontext(cx));
1125 back(cx);
1129 if (!(o & CX_UNARY) && cx->table->logical[o])
1131 if (cc->type != cx->state->type_number && !code(cx, cc, expr, CX_LOG, 0, cc->type, cx->state->type_void, NiL, 0, NiL))
1136 if (!code(cx, cc, expr, (o == CX_ANDAND) ? CX_SC0 : CX_SC1, 0, cx->state->type_number, cx->state->type_void, NiL, 0, NiL))
1141 if (parse(cx, cc, expr, p, NiL) != cx->state->type_void || cx->error)
1143 if (cx->table->logical[o] && cc->type != cx->state->type_number && !code(cx, cc, expr, CX_LOG, 0, cc->type, cx->state->type_void, NiL, 0, NiL))
1145 if (o != CX_SET && ((o & CX_UNARY) ? !code(cx, cc, expr, o, 0, cc->type, cx->state->type_void, NiL, 0, NiL) : !code(cx, cc, expr, o, -1, t, cc->type, NiL, 0, h)))
1147 if (cx->table->comparison[o] || cx->table->logical[o])
1153 if (v->type != cx->state->type_void)
1155 if (cx->disc->errorf)
1156 (*cx->disc->errorf)(cx, cx->disc, 2, "%s cannot assign %s to %s", cxcontext(cx), cc->type->name, v->type->name);
1161 if (!code(cx, cc, expr, CX_SET, 0, cx->state->type_void, cc->type, v, 0, NiL))
1169 else if (cx->ctype[c] & CX_CTYPE_DIGIT)
1174 sfputc(cx->tp, c);
1175 while (cx->ctype[c = next(cx)] & (CX_CTYPE_ALPHA|CX_CTYPE_DIGIT|CX_CTYPE_FLOAT))
1177 sfputc(cx->tp, c);
1191 if ((c = next(cx)) == '-' || c == '+')
1192 sfputc(cx->tp, c);
1194 back(cx);
1199 back(cx);
1200 s = sfstruse(cx->tp);
1207 if (cx->disc->errorf)
1208 (*cx->disc->errorf)(cx, cx->disc, 2, "%s: invalid numeric constant", s);
1211 if (!code(cx, cc, expr, CX_NUM, 1, cx->state->type_number, cx->state->type_void, NiL, n, NiL))
1215 else if ((cx->ctype[c] & CX_CTYPE_ALPHA) && c != '.')
1220 if (!(v = variable(cx, cc, c, m, &t)))
1231 while ((c = next(cx)) == ' ' || c == '\t' || c == '\r');
1242 back(cx);
1245 c = next(cx);
1246 if (v->type != cx->state->type_void && !code(cx, cc, expr, CX_NUM, 1, cx->state->type_number, cx->state->type_void, NiL, 0, NiL))
1251 if ((r = prototype(cx, cc, v, &t, &s, &e, &o)) < 0)
1261 if (parse(cx, cc, expr, cx->table->precedence[CX_CALL], NiL) != cx->state->type_void || cx->error)
1270 while (cc->type != t && t != cx->state->type_void)
1272 if (o && r > 0 && (r = prototype(cx, cc, v, &t, &s, &e, &o)) > 0)
1280 if (cx->disc->errorf)
1283 (*cx->disc->errorf)(cx, cx->disc, 2, "%s too many arguments for %s(%s)", cxcontext(cx), v->name, v->prototype);
1285 (*cx->disc->errorf)(cx, cx->disc, 2, "%s argument type mismatch for %s(%s)", cxcontext(cx), v->name, v->prototype);
1291 if ((r = prototype(cx, cc, v, &t, &s, &e, &o)) < 0)
1298 if (!(c = next(cx)))
1300 if (cx->disc->errorf)
1301 (*cx->disc->errorf)(cx, cx->disc, 2, "%s EOF in formal argument list", cxcontext(cx));
1309 back(cx);
1315 if (cx->disc->errorf)
1316 (*cx->disc->errorf)(cx, cx->disc, 2, "%s missing %s in formal argument list", cxcontext(cx), p == '\n' ? "statement terminator" : ")");
1322 if (cx->disc->errorf)
1323 (*cx->disc->errorf)(cx, cx->disc, 2, "%s not enough arguments for %s(%s)", cxcontext(cx), v->name, v->prototype);
1327 back(cx);
1328 if (!code(cx, cc, expr, CX_CALL, -i, v->type, cx->state->type_void, v, 0, NiL))
1332 if (codecast(cx, cc, g, cast, NiL))
1340 if (cx->disc->errorf)
1341 (*cx->disc->errorf)(cx, cx->disc, 2, "%s: unknown function", v->name);
1345 back(cx);
1354 if (!x && !v && (v = variable(cx, cc, c, m, 0)))
1360 if (cx->disc->errorf)
1361 (*cx->disc->errorf)(cx, cx->disc, 2, "%s struct or union variable expected", cxcontext(cx));
1364 if (!code(cx, cc, expr, CX_GET, 1, v->type, cx->state->type_void, v, 0, NiL))
1372 next(cx);
1375 if (!code(cx, cc, expr, CX_POP, -1, cx->state->type_void, cx->state->type_void, NiL, 0, NiL))
1385 clear(cx);
1393 else if (precedence <= cx->table->precedence[CX_CALL] || precedence > cx->table->precedence[CX_PAREN] && x)
1403 e = cx->include->next;
1404 if (cx->ctype[c = next(cx)] & CX_CTYPE_ALPHA)
1406 if (!identifier(cx, cc, c, &w) && (c = next(cx)) == ')' && ((c = next(cx)) == '(' || (cx->ctype[c] & CX_CTYPE_ALPHA)))
1408 if (!(g = cxtype(cx, w.value.string.data, cx->disc)))
1410 if (cx->disc->errorf)
1411 (*cx->disc->errorf)(cx, cx->disc, 2, "%s unknown type cast", cxcontext(cx), w.value.string.data);
1418 cx->include->next = e;
1421 cx->include->next = e;
1427 u = parse(cx, cc, expr, cx->table->precedence[CX_PAREN], &f);
1431 if (u != cx->state->type_void || cx->error)
1435 switch (next(cx))
1447 if (!(c = next(cx)) || c == ';' || c == '\n')
1454 s = cx->include->next;
1455 back(cx);
1459 if (s >= cx->include->last || *s == '{')
1464 back(cx);
1465 if (cx->disc->errorf)
1466 (*cx->disc->errorf)(cx, cx->disc, 2, "%s closing ) expected", cxcontext(cx));
1473 if (cx->disc->errorf)
1474 (*cx->disc->errorf)(cx, cx->disc, 2, "%s cast not implemented yet", cxcontext(cx));
1481 if (cx->disc->errorf)
1482 (*cx->disc->errorf)(cx, cx->disc, 2, "%s too many )'s", cxcontext(cx));
1489 if (precedence >= cx->table->precedence[CX_TST])
1491 if ((c = next(cx)) != ':')
1493 back(cx);
1494 if (parse(cx, cc, expr, cx->table->precedence[CX_TST], NiL) != cx->state->type_void || cx->error)
1496 if (next(cx) != ':')
1498 back(cx);
1499 if (cx->disc->errorf)
1500 (*cx->disc->errorf)(cx, cx->disc, 2, "%s : expected for ? operator", cxcontext(cx));
1504 else if (!code(cx, cc, expr, CX_NOP, 0, cx->state->type_void, cx->state->type_void, NiL, 0, NiL))
1506 if (parse(cx, cc, expr, cx->table->precedence[CX_TST], NiL) != cx->state->type_void || cx->error)
1508 if (!code(cx, cc, expr, CX_TST, 0, cx->state->type_void, cx->state->type_void, NiL, 0, NiL))
1519 while ((p = next(cx)) != c)
1523 if (cx->disc->errorf)
1524 (*cx->disc->errorf)(cx, cx->disc, 2, "%s EOF in string literal", cxcontext(cx));
1527 sfputc(cx->tp, p);
1528 if (p == '\\' && (p = next(cx)))
1529 sfputc(cx->tp, p);
1531 stresc(s = sfstruse(cx->tp));
1534 if (cx->disc->errorf)
1535 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
1538 if (!code(cx, cc, expr, CX_STR, 1, cx->state->type_string, cx->state->type_void, s, 0, NiL))
1543 if (cx->disc->errorf)
1544 (*cx->disc->errorf)(cx, cx->disc, 2, "syntax error: '%c' not expected: %s", c, cxcontext(cx));
1558 if (!x && precedence > cx->table->precedence[CX_CALL])
1561 back(cx);
1564 if (!code(cx, cc, expr, CX_NUM, 1, cx->state->type_type_t, cx->state->type_void, t, 0, NiL))
1571 if (!code(cx, cc, expr, CX_GET, 1, v->type, cx->state->type_void, v, 0, NiL))
1573 if (g && codecast(cx, cc, g, cast, NiL))
1579 return cx->state->type_void;
1581 if (cx->disc->errorf)
1582 (*cx->disc->errorf)(cx, cx->disc, 2, "%s undefined variable", cxcontext(cx));
1587 if (cx->disc->errorf)
1588 (*cx->disc->errorf)(cx, cx->disc, 2, "%s operator expected", cxcontext(cx));
1591 if (cx->disc->errorf)
1592 (*cx->disc->errorf)(cx, cx->disc, 2, "%s operand expected", cxcontext(cx));
1594 cx->error = cxtell(cx);
1596 back(cx);
1598 clear(cx);
1608 node(Cx_t* cx, Cxcompile_t* cc, size_t n)
1614 if (cx->disc->errorf)
1615 (*cx->disc->errorf)(NiL, cx->disc, 2, "out of space");
1626 compile(Cx_t* cx, Cxcompile_t* cc, int balanced)
1634 cc->type = cx->state->type_void;
1635 if (!(expr = node(cx, cc, sizeof(Cxquery_t))))
1639 if (!code(cx, cc, expr, CX_END, 0, cx->state->type_void, cx->state->type_void, NiL, 0, NiL))
1642 if (parse(cx, cc, expr, 0, NiL) != cx->state->type_void || cx->error)
1653 if (pc->op == CX_GET && !code(cx, cc, expr, CX_LOG, 0, pc->type, cx->state->type_void, NiL, 0, NiL))
1657 if (!code(cx, cc, expr, CX_END, 0, cx->state->type_void, cx->state->type_void, NiL, 0, NiL))
1662 if (cx->disc->errorf)
1663 (*cx->disc->errorf)(NiL, cx->disc, 2, "out of space");
1672 if (cx->disc->errorf)
1673 (*cx->disc->errorf)(cx, cx->disc, 2, "out of space");
1685 compose(Cx_t* cx, Cxcompile_t* cc, int prec)
1710 switch (c = next(cx))
1722 if (!(c = next(cx)))
1733 if (!(fp = compose(cx, cc, '}')))
1735 if (next(cx) != '}')
1737 if (cx->disc->errorf)
1738 (*cx->disc->errorf)(cx, cx->disc, 2, "unbalanced {...}: %s", cxcontext(cx));
1741 while (isspace(c = next(cx)));
1742 back(cx);
1745 if (cx->disc->errorf)
1746 (*cx->disc->errorf)(NiL, cx->disc, 2, "operator expected: %s", cxcontext(cx));
1752 if (!(fp = node(cx, cc, 0)))
1765 back(cx);
1766 if (!(fp = compile(cx, cc, 0)))
1768 if (!(c = next(cx)))
1770 back(cx);
1780 if (next(cx) == c)
1786 back(cx);
1808 if (cx->disc->errorf)
1809 (*cx->disc->errorf)(cx, cx->disc, 2, "unterminated %c quote: %s", q, cxcontext(cx));
1825 if (cx->disc->errorf)
1826 (*cx->disc->errorf)(NiL, cx->disc, 2, "out of space");
1833 sfwrite(cx->tp, &p, sizeof(p));
1841 else if (next(cx) == '>')
1845 back(cx);
1853 back(cx);
1854 return node(cx, cc, 0);
1860 m = sfstrtell(cx->tp) / sizeof(p);
1861 if (!(fp = node(cx, cc, (m + 1) * sizeof(char*) + n)))
1866 x = (int*)sfstrseek(cx->tp, 0, SEEK_SET);
1870 if (!(fp->query = cxquery(cx, s, cx->disc)) && !(cx->test & 0x00000400))
1872 if (cx->disc->errorf)
1873 (*cx->disc->errorf)(cx, cx->disc, 2, "%s: query not found", s);
1876 if (fp->query->ref && (*fp->query->ref)(cx, fp, fp->argv, cx->disc))
1885 if (cx->disc->errorf)
1886 (*cx->disc->errorf)(cx, cx->disc, ERROR_SYSTEM|2, "%s: cannot write", f);
1900 back(cx);
1908 back(cx);
1914 back(cx);
1919 if (!(fp = fp->next = compose(cx, cc, c)))
1924 if (peek(cx, 1) != ':' && !(fp->pass = compose(cx, cc, c)))
1926 if (peek(cx, 1) == ':')
1928 next(cx);
1929 if (!(fp->fail = compose(cx, cc, c)))
1933 else if (!(fp->pass = compose(cx, cc, c)))
1947 if (cx->disc->errorf)
1950 (*cx->disc->errorf)(cx, cx->disc, 2, "syntax error: '%c' not expected: %s", c, cxcontext(cx));
1952 (*cx->disc->errorf)(cx, cx->disc, 2, "syntax error: unterminated expression: %s", cxcontext(cx));
2051 cxlist(Cx_t* cx, Cxexpr_t* expr, Sfio_t* sp)
2063 cxcomp(Cx_t* cx)
2069 error(-1, "cxcomp push include=%p file=%s eof=%d", cx->include, cx->include ? cx->include->file : 0, cx->eof);
2070 if (cx->eof || !cx->include && (cx->eof = 1))
2073 if (!(cc = vmnewof(cx->vm, 0, Cxcompile_t, 1, 0)) || !(cc->tp = sfstropen()) || !(cc->xp = sfstropen()))
2075 cx->error = 0;
2076 cc->reclaim = !!(cx->deletef = cxcallout(cx, CX_DEL, cx->state->type_void, cx->state->type_void, cx->disc));
2077 cx->returnf = cxcallout(cx, CX_RET, cx->state->type_void, cx->state->type_void, cx->disc);
2078 cx->referencef = cxcallout(cx, CX_REF, cx->state->type_string, cx->state->type_void, cx->disc);
2079 if (sfsync(cx->op) < 0)
2081 if (cx->disc->errorf)
2082 (*cx->disc->errorf)(cx, cx->disc, 2, "write error");
2087 cx->include->head = 1;
2088 if (!(c = peek(cx, !cx->interactive)))
2090 if (!cx->include->pop)
2091 cx->eof = 1;
2096 if (!(expr = compose(cx, cc, 0)))
2098 clear(cx);
2100 else if (!(expr = compile(cx, cc, cx->flags & CX_BALANCED)))
2106 if (cx->disc->errorf)
2107 (*cx->disc->errorf)(cx, cx->disc, ERROR_SYSTEM|2, "out of space");
2109 if (!cx->include && !(cx->flags & CX_BALANCED))
2110 cx->eof = 1;
2119 vmfree(cx->vm, cc);
2121 error(-1, "cxcomp done include=%p file=%s eof=%d", cx->include, cx->include ? cx->include->file : 0, cx->eof);
2130 cxfree(Cx_t* cx, Cxexpr_t* expr)
2134 cxatfree(cx, expr, NiL, NiL);
2141 cxtell(Cx_t* cx)
2145 if (cx->eof)
2147 if (cx->error)
2148 return cx->error;
2149 if (!(ip = cx->include))