harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit da0a098729a3d960c393e9cf7634e9a5c50e40f1
parent c77ca2f0b265f4421cacedd6b10fce3e6adb8515
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed, 11 Aug 2021 09:42:26 +0000

eval: implement tuple access

Also enable 21-tuples

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Minclude/expr.h | 1+
Msrc/check.c | 1+
Msrc/eval.c | 12+++++++++++-
Mtests/configure | 2+-
4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/expr.h b/include/expr.h @@ -61,6 +61,7 @@ struct expression_access { struct { struct expression *tuple; const struct type_tuple *tvalue; + size_t tindex; }; }; }; diff --git a/src/check.c b/src/check.c @@ -237,6 +237,7 @@ check_expr_access(struct context *ctx, "No such tuple value '%zu'", aexpr->access.value->constant.uval); } + expr->access.tindex = aexpr->access.value->constant.uval; expr->result = expr->access.tvalue->type; break; diff --git a/src/eval.c b/src/eval.c @@ -28,7 +28,17 @@ eval_access(struct context *ctx, struct expression *in, struct expression *out) case ACCESS_FIELD: assert(0); // TODO case ACCESS_TUPLE: - assert(0); // TODO + out->type = EXPR_CONSTANT; + struct expression tmp = {0}; + enum eval_result r = eval_expr(ctx, in->access.tuple, &tmp); + if (r != EVAL_OK) { + return r; + } + const struct tuple_constant *tuple = tmp.constant.tuple; + for (size_t i = in->access.tindex; i > 0; --i) { + tuple = tuple->next; + } + return eval_expr(ctx, tuple->value, out); } return EVAL_OK; diff --git a/tests/configure b/tests/configure @@ -60,6 +60,7 @@ EOF 18-match \ 19-append \ 20-if \ + 21-tuples \ 24-imports \ 25-promotion \ 26-gen \ @@ -67,7 +68,6 @@ EOF 29-unarithm # Disabled tests - #21-tuples \ #22-delete \ #23-errors \ #28-insert \