From e9ac52dfdaa52aba242dee7a1d078763cf819bb2 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 1 Apr 2017 23:12:37 +0200 Subject: [PATCH] mescc: Fix by value assignment from array-of struct entry. * module/language/c99/compiler.mes (expr->accu): Fix by value assignment from array-of struct entry. * scaffold/t.c (struct_test): Test it. * vector.c (make_vector, list_to_vector, vector_to_list): Use it; remove workarounds. * gc.c (gc_copy): Likewise. --- gc.c | 28 ++----------------- module/language/c99/compiler.mes | 24 +++++++++------- scaffold/t.c | 25 +++++++++++++++++ vector.c | 48 +++++++++----------------------- 4 files changed, 55 insertions(+), 70 deletions(-) diff --git a/gc.c b/gc.c index d2800bc1..6aba0d3f 100644 --- a/gc.c +++ b/gc.c @@ -70,39 +70,17 @@ gc_copy (SCM old) ///((internal)) { if (TYPE (old) == TBROKEN_HEART) return g_cells[old].car; SCM new = g_free++; -#if 0 g_news[new] = g_cells[old]; -#else - SCM y = new; - SCM z = old; - SCM zz = TYPE (z); - NTYPE (y) = zz; - zz = CAR (z); - NCAR (y) = zz; - zz = CDR (z); - NCDR (y) = zz; -#endif if (NTYPE (new) == TVECTOR) { NVECTOR (new) = g_free; for (int i=0; iaccu size)))))))) ;; c+p expr->arg + ;; g_cells[0] ((array-ref (p-expr (fixed ,index)) (p-expr (ident ,array))) (let* ((index (cstring->number index)) (type (ident->type info array)) @@ -561,11 +562,13 @@ (list (lambda (f g ta t d) (append (i386:value->accu (* size index)) - (if (eq? size 1) - (i386:byte-base-mem->accu) - (i386:base-mem->accu))))))))) + (case size + ((1) (i386:byte-base-mem->accu)) + ((4) (i386:base-mem->accu)) + (else (i386:accu+base)))))))))) ;; c+p expr->arg + ;; g_cells[i] ((array-ref (p-expr (ident ,index)) (p-expr (ident ,array))) (let* ((type (ident->type info array)) (size (type->size info type))) @@ -575,15 +578,16 @@ (append (i386:base->accu) (if (< size 4) '() - (append ;; FIXME - (i386:accu+accu) - (if (= size 12) (i386:accu+base) - '())))))) + (append + (i386:accu+accu) + (if (= size 12) (i386:accu+base) '()) + (i386:accu-shl 2)))))) ((ident->base info) array) (list (lambda (f g ta t d) - (if (eq? size 1) - (i386:byte-base-mem->accu) - (i386:base-mem->accu)))))))) + (case size + ((1) (i386:byte-base-mem->accu)) + ((4) (i386:base-mem->accu)) + (else (i386:accu+base))))))))) ;; f.field ((d-sel (ident ,field) (p-expr (ident ,array))) diff --git a/scaffold/t.c b/scaffold/t.c index d88672dc..1d470844 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -290,8 +290,33 @@ make_tmps_test (struct scm* cells) int struct_test () { + puts ("t: g_cells[0] = g_cells[1]\n"); + TYPE (1) = 1; + CAR (1) = 2; + CDR (1) = 3; + g_cells[0] = g_cells[1]; + if (TYPE (0) != 1) return 1; + if (CAR (0) != 2) return 2; + if (CDR (0) != 3) return 3; + + puts ("t: g_cells[i] = g_cells[j]\n"); + int i = 0; + int j = 1; + TYPE (1) = 4; + CAR (1) = 5; + CDR (1) = 6; + g_cells[i] = g_cells[j]; + if (TYPE (0) != 4) return 1; + if (CAR (0) != 5) return 2; + if (CDR (0) != 6) return 3; + g_cells[0].type = TNUMBER; + g_cells[0].car = 0; + g_cells[0].cdr = 0; g_cells[1].type = TNUMBER; + g_cells[1].car = 0; + g_cells[1].cdr = 0; + puts ("t: TYPE (0) != TYPE (1)\n"); if (TYPE (0) == TYPE (1)) goto ok; return 1; diff --git a/vector.c b/vector.c index fc2fea5e..26acf804 100644 --- a/vector.c +++ b/vector.c @@ -25,21 +25,15 @@ make_vector (SCM n) VALUE (tmp_num) = TVECTOR; SCM v = alloc (k); SCM x = make_cell_ (tmp_num, k, v); -#if 0 - //__GNUC__ +#if __GNUC__ for (int i=0; i