harec

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

commit 5abe0fb26cf641d69178d5aa1a89e69cb1400071
parent 6012e0647956251649e030eacc61499f6e8ba0a2
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 25 Jan 2021 16:26:43 -0500

eval: expand casts

Diffstat:
Msrc/eval.c | 12+++++++-----
Msrc/typedef.c | 4+++-
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -307,8 +307,6 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out) return EVAL_OK; } assert(0); // TODO - case TYPE_STORAGE_CHAR: - case TYPE_STORAGE_ENUM: case TYPE_STORAGE_F32: case TYPE_STORAGE_F64: case TYPE_STORAGE_I16: @@ -316,15 +314,19 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out) case TYPE_STORAGE_I64: case TYPE_STORAGE_I8: case TYPE_STORAGE_INT: - case TYPE_STORAGE_NULL: - case TYPE_STORAGE_RUNE: - case TYPE_STORAGE_SIZE: case TYPE_STORAGE_U16: case TYPE_STORAGE_U32: case TYPE_STORAGE_U64: case TYPE_STORAGE_U8: case TYPE_STORAGE_UINT: case TYPE_STORAGE_UINTPTR: + case TYPE_STORAGE_SIZE: + out->constant.uval = itrunc(to, in->constant.uval); + return EVAL_OK; + case TYPE_STORAGE_CHAR: + case TYPE_STORAGE_ENUM: + case TYPE_STORAGE_NULL: + case TYPE_STORAGE_RUNE: case TYPE_STORAGE_ARRAY: case TYPE_STORAGE_SLICE: case TYPE_STORAGE_TAGGED_UNION: diff --git a/src/typedef.c b/src/typedef.c @@ -36,6 +36,8 @@ storage_to_suffix(enum type_storage storage) return "u8"; case TYPE_STORAGE_UINT: return "u"; + case TYPE_STORAGE_UINTPTR: + return "u64: uintptr"; default: assert(0); } @@ -72,6 +74,7 @@ emit_const(const struct expression *expr, FILE *out) case TYPE_STORAGE_U64: case TYPE_STORAGE_U8: case TYPE_STORAGE_UINT: + case TYPE_STORAGE_UINTPTR: fprintf(out, "%lu%s", val->uval, storage_to_suffix(expr->result->storage)); break; @@ -91,7 +94,6 @@ emit_const(const struct expression *expr, FILE *out) case TYPE_STORAGE_CHAR: case TYPE_STORAGE_FUNCTION: case TYPE_STORAGE_POINTER: - case TYPE_STORAGE_UINTPTR: case TYPE_STORAGE_TAGGED_UNION: assert(0); // Invariant }