commit dc9974fb600d123869216885a9ae182adee84b31
parent 7fd8589fc3330fe7c0f73b80989c3811f269c594
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 19 Dec 2020 13:22:13 -0500
Implement rune literal checking
Diffstat:
4 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/ast.h b/include/ast.h
@@ -89,6 +89,7 @@ struct ast_constant_expression {
union {
intmax_t ival;
uintmax_t uval;
+ uint32_t rune;
struct {
size_t len;
char *value;
diff --git a/include/expr.h b/include/expr.h
@@ -1,5 +1,6 @@
#ifndef HAREC_EXPR_H
#define HAREC_EXPR_H
+#include <stdint.h>
#include "types.h"
enum expr_type {
@@ -37,6 +38,7 @@ union expression_constant {
double fval;
intmax_t ival;
uintmax_t uval;
+ uint32_t rune;
// TODO: Array, slice, struct constants
};
diff --git a/src/check.c b/src/check.c
@@ -53,7 +53,8 @@ check_expr_constant(struct context *ctx,
expr->constant.uval = aexpr->constant.uval;
break;
case TYPE_STORAGE_RUNE:
- assert(0); // TODO
+ expr->constant.rune = aexpr->constant.rune;
+ break;
case TYPE_STORAGE_BOOL:
case TYPE_STORAGE_F32:
case TYPE_STORAGE_F64:
diff --git a/src/parse.c b/src/parse.c
@@ -362,6 +362,9 @@ parse_simple_expression(struct parser *par, struct ast_expression *exp)
case TYPE_STORAGE_INT:
exp->constant.ival = (intmax_t)tok.ival;
break;
+ case TYPE_STORAGE_RUNE:
+ exp->constant.rune = tok.rune;
+ break;
case TYPE_STORAGE_STRING:
exp->constant.string.len = tok.string.len;
exp->constant.string.value = tok.string.value;