harec

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

commit 10a990f1934a8f7c02636be388e3e55fae2cada3
parent bc9c794edc814f0b6d59723b48811deba258046d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 12 Feb 2021 18:15:50 -0500

add \Uxxxxxxxx rune form

Diffstat:
Msrc/eval.c | 4++--
Msrc/lex.c | 15++++++++++++++-
Msrc/typedef.c | 4+++-
3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -18,6 +18,7 @@ itrunc(const struct type *type, uintmax_t val) case TYPE_STORAGE_U16: return (uint16_t)val; case TYPE_STORAGE_U32: + case TYPE_STORAGE_RUNE: return (uint32_t)val; case TYPE_STORAGE_U64: return (uint64_t)val; @@ -52,7 +53,6 @@ itrunc(const struct type *type, uintmax_t val) case TYPE_STORAGE_F64: case TYPE_STORAGE_FCONST: case TYPE_STORAGE_FUNCTION: - case TYPE_STORAGE_RUNE: case TYPE_STORAGE_SLICE: case TYPE_STORAGE_STRING: case TYPE_STORAGE_STRUCT: @@ -333,6 +333,7 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out) case TYPE_STORAGE_UINT: case TYPE_STORAGE_UINTPTR: case TYPE_STORAGE_SIZE: + case TYPE_STORAGE_RUNE: out->constant.uval = itrunc(to, val.constant.uval); return EVAL_OK; case TYPE_STORAGE_ARRAY: @@ -346,7 +347,6 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out) case TYPE_STORAGE_CHAR: case TYPE_STORAGE_ENUM: case TYPE_STORAGE_NULL: - case TYPE_STORAGE_RUNE: case TYPE_STORAGE_TAGGED: assert(0); // TODO case TYPE_STORAGE_ALIAS: diff --git a/src/lex.c b/src/lex.c @@ -445,7 +445,7 @@ finalize: static uint32_t lex_rune(struct lexer *lexer) { - char buf[5]; + char buf[9]; char *endptr; uint32_t c = next(lexer, NULL, false); assert(c != UTF8_INVALID); @@ -492,6 +492,19 @@ lex_rune(struct lexer *lexer) c = strtoul(&buf[0], &endptr, 16); assert(*endptr == '\0'); return c; + case 'U': + buf[0] = next(lexer, NULL, false); + buf[1] = next(lexer, NULL, false); + buf[2] = next(lexer, NULL, false); + buf[3] = next(lexer, NULL, false); + buf[4] = next(lexer, NULL, false); + buf[5] = next(lexer, NULL, false); + buf[6] = next(lexer, NULL, false); + buf[7] = next(lexer, NULL, false); + buf[8] = '\0'; + c = strtoul(&buf[0], &endptr, 16); + assert(*endptr == '\0'); + return c; default: assert(0); // Invariant } diff --git a/src/typedef.c b/src/typedef.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include "check.h" @@ -89,7 +90,8 @@ emit_const(const struct expression *expr, FILE *out) fprintf(out, "void"); break; case TYPE_STORAGE_RUNE: - assert(0); // TODO + fprintf(out, "\'\\U%08" PRIx32 "\'", (uint32_t)val->uval); + break; case TYPE_STORAGE_ALIAS: case TYPE_STORAGE_ARRAY: case TYPE_STORAGE_ENUM: