2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
19 #include "isl_stream.h"
20 #include "isl_map_private.h"
25 struct variable *next;
34 static struct vars *vars_new(struct isl_ctx *ctx)
37 v = isl_alloc_type(ctx, struct vars);
46 static void variable_free(struct variable *var)
49 struct variable *next = var->next;
56 static void vars_free(struct vars *v)
64 static void vars_drop(struct vars *v, int n)
75 struct variable *next = var->next;
83 static struct variable *variable_new(struct vars *v, const char *name, int len,
87 var = isl_alloc_type(v->ctx, struct variable);
90 var->name = strdup(name);
91 var->name[len] = '\0';
100 static int vars_pos(struct vars *v, const char *s, int len)
107 for (q = v->v; q; q = q->next) {
108 if (strncmp(q->name, s, len) == 0 && q->name[len] == '\0')
115 v->v = variable_new(v, s, len, v->n);
123 static struct vars *read_var_list(struct isl_stream *s, struct vars *v)
125 struct isl_token *tok;
127 while ((tok = isl_stream_next_token(s)) != NULL) {
131 if (tok->type != ISL_TOKEN_IDENT)
134 p = vars_pos(v, tok->u.s, -1);
138 isl_stream_error(s, tok, "expecting unique identifier");
142 tok = isl_stream_next_token(s);
143 if (!tok || tok->type != ',')
149 isl_stream_push_token(s, tok);
158 static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
160 struct isl_token *tok = NULL;
164 aff = isl_vec_alloc(v->ctx, 1 + v->n);
165 isl_seq_clr(aff->el, aff->size);
170 tok = isl_stream_next_token(s);
172 isl_stream_error(s, NULL, "unexpected EOF");
175 if (tok->type == ISL_TOKEN_IDENT) {
177 int pos = vars_pos(v, tok->u.s, -1);
181 isl_stream_error(s, tok, "unknown identifier");
185 isl_int_add_ui(aff->el[1 + pos],
186 aff->el[1 + pos], 1);
188 isl_int_sub_ui(aff->el[1 + pos],
189 aff->el[1 + pos], 1);
191 } else if (tok->type == ISL_TOKEN_VALUE) {
192 struct isl_token *tok2;
195 tok2 = isl_stream_next_token(s);
196 if (tok2 && tok2->type == ISL_TOKEN_IDENT) {
197 pos = vars_pos(v, tok2->u.s, -1);
201 isl_stream_error(s, tok2,
202 "unknown identifier");
203 isl_token_free(tok2);
206 isl_token_free(tok2);
208 isl_stream_push_token(s, tok2);
210 isl_int_neg(tok->u.v, tok->u.v);
211 isl_int_add(aff->el[1 + pos],
212 aff->el[1 + pos], tok->u.v);
214 } else if (tok->type == '-') {
216 } else if (tok->type == '+') {
219 isl_stream_push_token(s, tok);
231 static __isl_give isl_mat *accept_affine_list(struct isl_stream *s,
236 struct isl_token *tok = NULL;
238 vec = accept_affine(s, v);
239 mat = isl_mat_from_row_vec(vec);
244 tok = isl_stream_next_token(s);
246 isl_stream_error(s, NULL, "unexpected EOF");
249 if (tok->type != ',') {
250 isl_stream_push_token(s, tok);
255 vec = accept_affine(s, v);
256 mat = isl_mat_vec_concat(mat, vec);
267 static struct isl_basic_map *add_div_definition(struct isl_stream *s,
268 struct vars *v, struct isl_basic_map *bmap, int k)
270 struct isl_token *tok;
274 if (isl_stream_eat(s, '['))
277 tok = isl_stream_next_token(s);
280 if (tok->type == '(') {
284 isl_stream_push_token(s, tok);
286 aff = accept_affine(s, v);
290 isl_seq_cpy(bmap->div[k] + 1, aff->el, aff->size);
294 if (seen_paren && isl_stream_eat(s, ')'))
296 if (isl_stream_eat(s, '/'))
299 tok = isl_stream_next_token(s);
302 if (tok->type != ISL_TOKEN_VALUE) {
303 isl_stream_error(s, tok, "expected denominator");
304 isl_stream_push_token(s, tok);
307 isl_int_set(bmap->div[k][0], tok->u.v);
310 if (isl_stream_eat(s, ']'))
313 if (isl_basic_map_add_div_constraints(bmap, k) < 0)
318 isl_basic_map_free(bmap);
322 static struct isl_basic_map *read_defined_var_list(struct isl_stream *s,
323 struct vars *v, struct isl_basic_map *bmap)
325 struct isl_token *tok;
327 while ((tok = isl_stream_next_token(s)) != NULL) {
331 unsigned total = isl_basic_map_total_dim(bmap);
333 if (tok->type != ISL_TOKEN_IDENT)
336 p = vars_pos(v, tok->u.s, -1);
340 isl_stream_error(s, tok, "expecting unique identifier");
345 bmap = isl_basic_map_cow(bmap);
346 bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
349 if ((k = isl_basic_map_alloc_div(bmap)) < 0)
351 isl_seq_clr(bmap->div[k], 1 + 1 + total);
353 tok = isl_stream_next_token(s);
354 if (tok && tok->type == '=') {
356 bmap = add_div_definition(s, v, bmap, k);
357 tok = isl_stream_next_token(s);
360 if (!tok || tok->type != ',')
366 isl_stream_push_token(s, tok);
371 isl_basic_map_free(bmap);
375 static struct vars *read_tuple(struct isl_stream *s, struct vars *v)
377 struct isl_token *tok;
379 tok = isl_stream_next_token(s);
380 if (!tok || tok->type != '[') {
381 isl_stream_error(s, tok, "expecting '['");
385 v = read_var_list(s, v);
386 tok = isl_stream_next_token(s);
387 if (!tok || tok->type != ']') {
388 isl_stream_error(s, tok, "expecting ']'");
401 static struct isl_basic_map *add_constraints(struct isl_stream *s,
402 struct vars *v, struct isl_basic_map *bmap);
404 static struct isl_basic_map *add_exists(struct isl_stream *s,
405 struct vars *v, struct isl_basic_map *bmap)
407 struct isl_token *tok;
414 tok = isl_stream_next_token(s);
417 if (tok->type == '(') {
421 isl_stream_push_token(s, tok);
423 bmap = read_defined_var_list(s, v, bmap);
427 if (isl_stream_eat(s, ':'))
429 bmap = add_constraints(s, v, bmap);
430 if (seen_paren && isl_stream_eat(s, ')'))
434 isl_basic_map_free(bmap);
438 static __isl_give isl_basic_map *construct_constraint(
439 __isl_take isl_basic_map *bmap, enum isl_token_type type,
440 isl_int *left, isl_int *right)
448 len = 1 + isl_basic_map_total_dim(bmap);
451 k = isl_basic_map_alloc_inequality(bmap);
454 if (type == ISL_TOKEN_LE)
455 isl_seq_combine(bmap->ineq[k], ctx->negone, left,
458 else if (type == ISL_TOKEN_GE)
459 isl_seq_combine(bmap->ineq[k], ctx->one, left,
462 else if (type == ISL_TOKEN_LT) {
463 isl_seq_combine(bmap->ineq[k], ctx->negone, left,
466 isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
467 } else if (type == ISL_TOKEN_GT) {
468 isl_seq_combine(bmap->ineq[k], ctx->one, left,
471 isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
473 isl_seq_combine(bmap->ineq[k], ctx->one, left,
476 isl_basic_map_inequality_to_equality(bmap, k);
481 isl_basic_map_free(bmap);
485 static int is_comparator(struct isl_token *tok)
502 static struct isl_basic_map *add_constraint(struct isl_stream *s,
503 struct vars *v, struct isl_basic_map *bmap)
506 unsigned total = isl_basic_map_total_dim(bmap);
507 struct isl_token *tok = NULL;
508 struct isl_mat *aff1 = NULL, *aff2 = NULL;
510 tok = isl_stream_next_token(s);
513 if (tok->type == ISL_TOKEN_EXISTS) {
515 return add_exists(s, v, bmap);
517 isl_stream_push_token(s, tok);
520 bmap = isl_basic_map_cow(bmap);
522 aff1 = accept_affine_list(s, v);
525 tok = isl_stream_next_token(s);
526 if (!is_comparator(tok)) {
527 isl_stream_error(s, tok, "missing operator");
529 isl_stream_push_token(s, tok);
533 isl_assert(aff1->ctx, aff1->n_col == 1 + total, goto error);
535 aff2 = accept_affine_list(s, v);
538 isl_assert(aff2->ctx, aff2->n_col == 1 + total, goto error);
540 bmap = isl_basic_map_extend_constraints(bmap, 0,
541 aff1->n_row * aff2->n_row);
542 for (i = 0; i < aff1->n_row; ++i)
543 for (j = 0; j < aff2->n_row; ++j)
544 bmap = construct_constraint(bmap, tok->type,
545 aff1->row[i], aff2->row[j]);
550 tok = isl_stream_next_token(s);
551 if (!is_comparator(tok)) {
553 isl_stream_push_token(s, tok);
565 isl_basic_map_free(bmap);
569 static struct isl_basic_map *add_constraints(struct isl_stream *s,
570 struct vars *v, struct isl_basic_map *bmap)
572 struct isl_token *tok;
575 bmap = add_constraint(s, v, bmap);
578 tok = isl_stream_next_token(s);
580 isl_stream_error(s, NULL, "unexpected EOF");
583 if (tok->type != ISL_TOKEN_AND)
587 isl_stream_push_token(s, tok);
593 isl_basic_map_free(bmap);
597 static struct isl_basic_map *read_disjunct(struct isl_stream *s,
598 struct vars *v, __isl_take isl_dim *dim)
600 struct isl_basic_map *bmap;
602 bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
606 bmap = add_constraints(s, v, bmap);
607 bmap = isl_basic_map_simplify(bmap);
608 bmap = isl_basic_map_finalize(bmap);
612 static struct isl_map *read_disjuncts(struct isl_stream *s,
613 struct vars *v, __isl_take isl_dim *dim)
615 struct isl_token *tok;
618 tok = isl_stream_next_token(s);
620 isl_stream_error(s, NULL, "unexpected EOF");
623 if (tok->type == '}') {
624 isl_stream_push_token(s, tok);
625 return isl_map_universe(dim);
627 isl_stream_push_token(s, tok);
629 map = isl_map_empty(isl_dim_copy(dim));
631 struct isl_basic_map *bmap;
634 bmap = read_disjunct(s, v, isl_dim_copy(dim));
635 map = isl_map_union(map, isl_map_from_basic_map(bmap));
637 vars_drop(v, v->n - n);
639 tok = isl_stream_next_token(s);
640 if (!tok || tok->type != ISL_TOKEN_OR)
645 isl_stream_push_token(s, tok);
654 static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map *bmap, int pos)
656 if (pos < isl_basic_map_dim(bmap, isl_dim_out))
657 return 1 + isl_basic_map_dim(bmap, isl_dim_param) +
658 isl_basic_map_dim(bmap, isl_dim_in) + pos;
659 pos -= isl_basic_map_dim(bmap, isl_dim_out);
661 if (pos < isl_basic_map_dim(bmap, isl_dim_in))
662 return 1 + isl_basic_map_dim(bmap, isl_dim_param) + pos;
663 pos -= isl_basic_map_dim(bmap, isl_dim_in);
665 if (pos < isl_basic_map_dim(bmap, isl_dim_div))
666 return 1 + isl_basic_map_dim(bmap, isl_dim_param) +
667 isl_basic_map_dim(bmap, isl_dim_in) +
668 isl_basic_map_dim(bmap, isl_dim_out) + pos;
669 pos -= isl_basic_map_dim(bmap, isl_dim_div);
671 if (pos < isl_basic_map_dim(bmap, isl_dim_param))
677 static __isl_give isl_basic_map *basic_map_read_polylib_constraint(
678 struct isl_stream *s, __isl_take isl_basic_map *bmap)
681 struct isl_token *tok;
691 nparam = isl_basic_map_dim(bmap, isl_dim_param);
692 dim = isl_basic_map_dim(bmap, isl_dim_out);
694 tok = isl_stream_next_token(s);
695 if (!tok || tok->type != ISL_TOKEN_VALUE) {
696 isl_stream_error(s, tok, "expecting coefficient");
698 isl_stream_push_token(s, tok);
701 if (!tok->on_new_line) {
702 isl_stream_error(s, tok, "coefficient should appear on new line");
703 isl_stream_push_token(s, tok);
707 type = isl_int_get_si(tok->u.v);
710 isl_assert(s->ctx, type == 0 || type == 1, goto error);
712 k = isl_basic_map_alloc_equality(bmap);
715 k = isl_basic_map_alloc_inequality(bmap);
721 for (j = 0; j < 1 + isl_basic_map_total_dim(bmap); ++j) {
723 tok = isl_stream_next_token(s);
724 if (!tok || tok->type != ISL_TOKEN_VALUE) {
725 isl_stream_error(s, tok, "expecting coefficient");
727 isl_stream_push_token(s, tok);
730 if (tok->on_new_line) {
731 isl_stream_error(s, tok,
732 "coefficient should not appear on new line");
733 isl_stream_push_token(s, tok);
736 pos = polylib_pos_to_isl_pos(bmap, j);
737 isl_int_set(c[pos], tok->u.v);
743 isl_basic_map_free(bmap);
747 static __isl_give isl_basic_map *basic_map_read_polylib(struct isl_stream *s,
751 struct isl_token *tok;
752 struct isl_token *tok2;
755 unsigned in = 0, out, local = 0;
756 struct isl_basic_map *bmap = NULL;
761 tok = isl_stream_next_token(s);
763 isl_stream_error(s, NULL, "unexpected EOF");
766 tok2 = isl_stream_next_token(s);
769 isl_stream_error(s, NULL, "unexpected EOF");
772 n_row = isl_int_get_si(tok->u.v);
773 n_col = isl_int_get_si(tok2->u.v);
774 on_new_line = tok2->on_new_line;
775 isl_token_free(tok2);
777 isl_assert(s->ctx, !on_new_line, return NULL);
778 isl_assert(s->ctx, n_row >= 0, return NULL);
779 isl_assert(s->ctx, n_col >= 2 + nparam, return NULL);
780 tok = isl_stream_next_token_on_same_line(s);
782 if (tok->type != ISL_TOKEN_VALUE) {
783 isl_stream_error(s, tok,
784 "expecting number of output dimensions");
785 isl_stream_push_token(s, tok);
788 out = isl_int_get_si(tok->u.v);
791 tok = isl_stream_next_token_on_same_line(s);
792 if (!tok || tok->type != ISL_TOKEN_VALUE) {
793 isl_stream_error(s, tok,
794 "expecting number of input dimensions");
796 isl_stream_push_token(s, tok);
799 in = isl_int_get_si(tok->u.v);
802 tok = isl_stream_next_token_on_same_line(s);
803 if (!tok || tok->type != ISL_TOKEN_VALUE) {
804 isl_stream_error(s, tok,
805 "expecting number of existentials");
807 isl_stream_push_token(s, tok);
810 local = isl_int_get_si(tok->u.v);
813 tok = isl_stream_next_token_on_same_line(s);
814 if (!tok || tok->type != ISL_TOKEN_VALUE) {
815 isl_stream_error(s, tok,
816 "expecting number of parameters");
818 isl_stream_push_token(s, tok);
821 nparam = isl_int_get_si(tok->u.v);
823 if (n_col != 1 + out + in + local + nparam + 1) {
824 isl_stream_error(s, NULL,
825 "dimensions don't match");
829 out = n_col - 2 - nparam;
830 bmap = isl_basic_map_alloc(s->ctx, nparam, in, out, local, n_row, n_row);
834 for (i = 0; i < local; ++i) {
835 int k = isl_basic_map_alloc_div(bmap);
840 for (i = 0; i < n_row; ++i)
841 bmap = basic_map_read_polylib_constraint(s, bmap);
843 bmap = isl_basic_map_simplify(bmap);
844 bmap = isl_basic_map_finalize(bmap);
847 isl_basic_map_free(bmap);
851 static struct isl_map *map_read_polylib(struct isl_stream *s, int nparam)
853 struct isl_token *tok;
854 struct isl_token *tok2;
858 tok = isl_stream_next_token(s);
860 isl_stream_error(s, NULL, "unexpected EOF");
863 tok2 = isl_stream_next_token(s);
866 isl_stream_error(s, NULL, "unexpected EOF");
869 if (!tok2->on_new_line) {
870 isl_stream_push_token(s, tok2);
871 isl_stream_push_token(s, tok);
872 return isl_map_from_basic_map(basic_map_read_polylib(s, nparam));
874 isl_stream_push_token(s, tok2);
875 n = isl_int_get_si(tok->u.v);
878 isl_assert(s->ctx, n >= 1, return NULL);
880 map = isl_map_from_basic_map(basic_map_read_polylib(s, nparam));
882 for (i = 1; i < n; ++i)
883 map = isl_map_union(map,
884 isl_map_from_basic_map(basic_map_read_polylib(s, nparam)));
889 static struct isl_dim *set_names(struct isl_dim *dim, struct vars *vars,
890 enum isl_dim_type type, int offset, int n)
895 for (i = 0, v = vars->v; i < offset; ++i, v = v->next)
897 for (i = n - 1; i >= 0; --i, v = v->next)
898 dim = isl_dim_set_name(dim, type, i, v->name);
903 static struct isl_dim *dim_from_vars(struct vars *vars,
904 int nparam, int n_in, int n_out)
908 dim = isl_dim_alloc(vars->ctx, nparam, n_in, n_out);
909 dim = set_names(dim, vars, isl_dim_param, n_out + n_in, nparam);
910 dim = set_names(dim, vars, isl_dim_in, n_out, n_in);
911 dim = set_names(dim, vars, isl_dim_out, 0, n_out);
916 static struct isl_map *map_read(struct isl_stream *s, int nparam)
918 struct isl_dim *dim = NULL;
919 struct isl_map *map = NULL;
920 struct isl_token *tok;
921 struct vars *v = NULL;
925 tok = isl_stream_next_token(s);
927 isl_stream_error(s, NULL, "unexpected EOF");
930 if (tok->type == ISL_TOKEN_VALUE) {
931 isl_stream_push_token(s, tok);
932 return map_read_polylib(s, nparam);
934 v = vars_new(s->ctx);
935 if (tok->type == '[') {
936 isl_stream_push_token(s, tok);
937 v = read_tuple(s, v);
941 isl_assert(s->ctx, nparam == v->n, goto error);
943 tok = isl_stream_next_token(s);
944 if (!tok || tok->type != ISL_TOKEN_TO) {
945 isl_stream_error(s, tok, "expecting '->'");
947 isl_stream_push_token(s, tok);
951 tok = isl_stream_next_token(s);
955 if (!tok || tok->type != '{') {
956 isl_stream_error(s, tok, "expecting '{'");
958 isl_stream_push_token(s, tok);
962 v = read_tuple(s, v);
966 tok = isl_stream_next_token(s);
967 if (tok && tok->type == ISL_TOKEN_TO) {
969 v = read_tuple(s, v);
972 n2 = v->n - n1 - nparam;
975 isl_stream_push_token(s, tok);
979 dim = dim_from_vars(v, nparam, n1, n2);
980 tok = isl_stream_next_token(s);
982 isl_stream_error(s, NULL, "unexpected EOF");
985 if (tok->type == ':') {
987 map = read_disjuncts(s, v, isl_dim_copy(dim));
988 tok = isl_stream_next_token(s);
990 map = isl_map_universe(isl_dim_copy(dim));
991 if (tok && tok->type == '}') {
994 isl_stream_error(s, tok, "unexpected isl_token");
1011 static struct isl_basic_map *basic_map_read(struct isl_stream *s, int nparam)
1013 struct isl_map *map;
1014 struct isl_basic_map *bmap;
1016 map = map_read(s, nparam);
1020 isl_assert(map->ctx, map->n <= 1, goto error);
1023 bmap = isl_basic_map_empty_like_map(map);
1025 bmap = isl_basic_map_copy(map->p[0]);
1035 __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
1036 FILE *input, int nparam)
1038 struct isl_basic_map *bmap;
1039 struct isl_stream *s = isl_stream_new_file(ctx, input);
1042 bmap = basic_map_read(s, nparam);
1047 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
1048 FILE *input, int nparam)
1050 struct isl_basic_map *bmap;
1051 bmap = isl_basic_map_read_from_file(ctx, input, nparam);
1054 isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
1055 return (struct isl_basic_set *)bmap;
1057 isl_basic_map_free(bmap);
1061 struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
1062 const char *str, int nparam)
1064 struct isl_basic_map *bmap;
1065 struct isl_stream *s = isl_stream_new_str(ctx, str);
1068 bmap = basic_map_read(s, nparam);
1073 struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
1074 const char *str, int nparam)
1076 struct isl_basic_map *bmap;
1077 bmap = isl_basic_map_read_from_str(ctx, str, nparam);
1080 isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
1081 return (struct isl_basic_set *)bmap;
1083 isl_basic_map_free(bmap);
1087 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
1088 FILE *input, int nparam)
1090 struct isl_map *map;
1091 struct isl_stream *s = isl_stream_new_file(ctx, input);
1094 map = map_read(s, nparam);
1099 __isl_give isl_map *isl_map_read_from_str(struct isl_ctx *ctx,
1100 const char *str, int nparam)
1102 struct isl_map *map;
1103 struct isl_stream *s = isl_stream_new_str(ctx, str);
1106 map = map_read(s, nparam);
1111 __isl_give isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
1112 FILE *input, int nparam)
1114 struct isl_map *map;
1115 map = isl_map_read_from_file(ctx, input, nparam);
1118 isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
1119 return (struct isl_set *)map;
1125 struct isl_set *isl_set_read_from_str(struct isl_ctx *ctx,
1126 const char *str, int nparam)
1128 struct isl_map *map;
1129 map = isl_map_read_from_str(ctx, str, nparam);
1132 isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
1133 return (struct isl_set *)map;
1139 static char *next_line(FILE *input, char *line, unsigned len)
1144 if (!(p = fgets(line, len, input)))
1146 while (isspace(*p) && *p != '\n')
1148 } while (*p == '#' || *p == '\n');
1153 static struct isl_vec *isl_vec_read_from_file_polylib(struct isl_ctx *ctx,
1156 struct isl_vec *vec = NULL;
1165 isl_assert(ctx, next_line(input, line, sizeof(line)), return NULL);
1166 isl_assert(ctx, sscanf(line, "%u", &size) == 1, return NULL);
1168 vec = isl_vec_alloc(ctx, size);
1170 p = next_line(input, line, sizeof(line));
1171 isl_assert(ctx, p, goto error);
1173 for (j = 0; j < size; ++j) {
1174 n = sscanf(p, "%s%n", val, &offset);
1175 isl_assert(ctx, n != 0, goto error);
1176 isl_int_read(vec->el[j], val);
1186 struct isl_vec *isl_vec_read_from_file(struct isl_ctx *ctx,
1187 FILE *input, unsigned input_format)
1189 if (input_format == ISL_FORMAT_POLYLIB)
1190 return isl_vec_read_from_file_polylib(ctx, input);
1192 isl_assert(ctx, 0, return NULL);