harec

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

commit d00a7b6007503bb9686d4692db5020b39c4cc9bd
parent 8efc042aa4887ab24299cb60ad8ca74704cec15e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri,  1 Jan 2021 13:38:04 -0500

Fix aggregate type dereference, add string test

Diffstat:
Msrc/gen.c | 6++++--
Mtests/03-pointers.ha | 2--
Atests/04-strings.ha | 23+++++++++++++++++++++++
Mtests/configure | 3++-
4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -309,7 +309,7 @@ gen_expr_access_index(struct gen_context *ctx, qval_deref(&obj); } gen_loadtemp(ctx, &temp, &obj, - qtype_for_type(ctx, atype->array.members, true), + qtype_for_type(ctx, atype->array.members, false), type_is_signed(atype->array.members)); gen_store(ctx, out, &temp); } @@ -988,7 +988,9 @@ gen_expr_unarithm(struct gen_context *ctx, res = op; // no-op break; case UN_DEREF: - qval_deref(&op); + if (!type_is_aggregate(expr->result)) { + qval_deref(&op); + } gen_load(ctx, &res, &op, type_is_signed(expr->result)); break; case UN_ADDRESS: diff --git a/tests/03-pointers.ha b/tests/03-pointers.ha @@ -1,5 +1,3 @@ -fn compfail(src: str) void; - fn basics() void = { let x = 42; let y: *int = &x; diff --git a/tests/04-strings.ha b/tests/04-strings.ha @@ -0,0 +1,23 @@ +fn measurements() void = { + let x = "Hello!"; + assert(len(x) == 6z); +}; + +fn charptr() void = { + let x = "Hello!"; + let y = x: *const char; + let z = y: *[*]u8; + // XXX: Update me when implicit deref is implemented + assert((*z)[0] == 'H': u32: u8); + assert((*z)[1] == 'e': u32: u8); + assert((*z)[2] == 'l': u32: u8); + assert((*z)[3] == 'l': u32: u8); + assert((*z)[4] == 'o': u32: u8); + assert((*z)[5] == '!': u32: u8); +}; + +export fn main() void = { + // TODO: Expand this test (blocked on structs, more or less) + measurements(); + charptr(); +}; diff --git a/tests/configure b/tests/configure @@ -6,7 +6,8 @@ tests() { 00-constants \ 01-arrays \ 02-integers \ - 03-pointers + 03-pointers \ + 04-strings do cat <<EOF tests/$t: rt tests/$t.ha