Lines Matching refs:cx

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