harec

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

commit 5acb5c6f08f6ebfe939b1028d647ec7611d26a04
parent 6d73e30888daeb6e5ac93d66ec3e31cf5e60de7e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 20 Dec 2020 14:32:31 -0500

check: add expression lists

Diffstat:
Minclude/ast.h | 2+-
Minclude/expr.h | 6++++++
Msrc/check.c | 33+++++++++++++++++++++++++++++++++
Msrc/parse.c | 2+-
4 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/include/ast.h b/include/ast.h @@ -98,7 +98,7 @@ struct ast_constant_expression { }; struct ast_expression_list { - struct ast_expression *exp; + struct ast_expression *expr; struct ast_expression_list *next; }; diff --git a/include/expr.h b/include/expr.h @@ -42,12 +42,18 @@ union expression_constant { // TODO: Array, slice, struct constants }; +struct expression_list { + struct expression *expr; + struct expression_list *next; +}; + struct expression { const struct type *result; enum expr_type type; bool terminates; union { union expression_constant constant; + struct expression_list list; }; }; diff --git a/src/check.c b/src/check.c @@ -27,6 +27,9 @@ expect(bool constraint, char *fmt, ...) } } +static void check_expression(struct context *ctx, + const struct ast_expression *aexpr, struct expression *expr); + static void check_expr_constant(struct context *ctx, const struct ast_expression *aexpr, @@ -76,6 +79,33 @@ check_expr_constant(struct context *ctx, } static void +check_expr_list(struct context *ctx, + const struct ast_expression *aexpr, + struct expression *expr) +{ + trenter(TR_CHECK, "expression-list"); + expr->type = EXPR_LIST; + + struct expression_list *list = &expr->list; + struct expression_list **next = &list->next; + + const struct ast_expression_list *alist = &aexpr->list; + while (alist) { + struct expression *lexpr = calloc(1, sizeof(struct expression)); + check_expression(ctx, alist->expr, lexpr); + + alist = alist->next; + if (alist) { + *next = calloc(1, sizeof(struct expression_list)); + list = *next; + next = &list->next; + } + } + + trleave(TR_CHECK, NULL); +} + +static void check_expression(struct context *ctx, const struct ast_expression *aexpr, struct expression *expr) @@ -100,7 +130,10 @@ check_expression(struct context *ctx, case EXPR_FUNC: case EXPR_IF: case EXPR_INDEX: + assert(0); // TODO case EXPR_LIST: + check_expr_list(ctx, aexpr, expr); + break; case EXPR_MATCH: case EXPR_MEASURE: case EXPR_SLICE: diff --git a/src/parse.c b/src/parse.c @@ -408,7 +408,7 @@ parse_expression_list(struct parser *par, struct ast_expression *exp) struct ast_expression *curexp = calloc(1, sizeof(struct ast_expression)); parse_scope_expression(par, curexp); - cur->exp = curexp; + cur->expr = curexp; struct token tok = {0}; want(par, T_SEMICOLON, &tok);