harec

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

commit 09174ff3024cdf55c1c8b0bb277b154c214e1818
parent efff186c9e49be1e0fa20afb0a0397361d8f4ccf
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  3 Oct 2021 10:25:04 +0200

gen: implement proper type comparisons

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 7+++++++
Mtests/34-reflect.ha | 7+++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -818,6 +818,7 @@ gen_expr_binarithm(struct gen_context *ctx, const struct expression *expr) } assert((ltype->storage == STORAGE_STRING) == (rtype->storage == STORAGE_STRING)); + assert((ltype->storage == STORAGE_TYPE) == (rtype->storage == STORAGE_TYPE)); if (ltype->storage == STORAGE_STRING) { struct qbe_value rtfunc = mkrtfunc(ctx, "rt.strcmp"); pushi(ctx->current, &qresult, Q_CALL, @@ -829,6 +830,12 @@ gen_expr_binarithm(struct gen_context *ctx, const struct expression *expr) assert(expr->binarithm.op == BIN_LEQUAL); } return result; + } else if (ltype->storage == STORAGE_TYPE) { + struct qbe_value qltmp = mkqtmp(ctx, ctx->arch.ptr, ".%d"); + struct qbe_value qrtmp = mkqtmp(ctx, ctx->arch.ptr, ".%d"); + pushi(ctx->current, &qltmp, Q_LOADL, &qlval, NULL); + pushi(ctx->current, &qrtmp, Q_LOADL, &qrval, NULL); + qlval = qltmp, qrval = qrtmp; } enum qbe_instr instr = binarithm_for_op(ctx, expr->binarithm.op, expr->binarithm.lvalue->result); diff --git a/tests/34-reflect.ha b/tests/34-reflect.ha @@ -206,6 +206,12 @@ fn tuples() void = { assert(tu[2].type_ == type(int)); }; +fn comparisons() void = { + // Tests that comparisons between non-static typeinfos work (since the + // pointer address will differ) + assert(type(struct { x: int, y: int}) == type(struct { x: int, y: int})); +}; + export fn main() void = { builtins(); aliases(); @@ -217,4 +223,5 @@ export fn main() void = { struct_union(); tagged(); tuples(); + comparisons(); };