mescc: Struct by value assignment fixes.
authorJan Nieuwenhuizen <janneke@gnu.org>
Wed, 22 Mar 2017 06:13:34 +0000 (07:13 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Wed, 22 Mar 2017 06:13:34 +0000 (07:13 +0100)
* module/language/c99/compiler.mes (ast->info): Remove g_function
  hardcoding, fix struct assignment.
* doc/examples/t.c (struct_test): Test it.

module/language/c99/compiler.mes
module/mes/as-i386.mes
scaffold/t.c

index 28a4a80c9f6466e82848a59c5e7f117639574bb6..9c3424a7de75780d4578cb23feee15f0a35526d6 100644 (file)
@@ -2117,18 +2117,25 @@ _)))))
                                   (i386:accu+base)))
                          (list (lambda (f g ta t d)
                                  (i386:pop-base)))
-                         (cond ((equal? array "g_functions") ;; FIXME
-                                (list (lambda (f g ta t d)
-                                        (append
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)))))
-                               (else (list (lambda (f g ta t d)
-                                             (i386:base->accu-address)))))))))
+                         (if (eq? size 1) (list (lambda (f g ta t d)
+                                                  (i386:byte-base->accu-address)))
+                             (append
+                              (list (lambda (f g ta t d)
+                                      (i386:base-address->accu-address)))
+                              (if (> size 4)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())
+                              (if (> size 8)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())))))))
 
         ;; g_cells[i] = c;
         ((expr-stmt (assn-expr (array-ref (p-expr (ident ,index)) (p-expr (ident ,array))) (op ,op) ,b))
@@ -2161,18 +2168,25 @@ _)))))
                                   (i386:accu+base)))
                          (list (lambda (f g ta t d)
                                  (i386:pop-base)))
-                         (cond ((equal? array "g_functions") ;; FIXME
-                                (list (lambda (f g ta t d)
-                                        (append
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)))))
-                               (else (list (lambda (f g ta t d)
-                                             (i386:base->accu-address)))))))))
+                         (if (eq? size 1) (list (lambda (f g ta t d)
+                                                  (i386:byte-base->accu-address)))
+                             (append
+                              (list (lambda (f g ta t d)
+                                      (i386:base-address->accu-address)))
+                              (if (> size 4)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())
+                              (if (> size 8)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())))))))
 
         ;; g_functions[g_function++] = g_foo;
         ((expr-stmt (assn-expr (array-ref (post-inc (p-expr (ident ,index))) (p-expr (ident ,array))) (op ,op) ,b))
@@ -2204,19 +2218,25 @@ _)))))
                                   (i386:accu+base)))
                          (list (lambda (f g ta t d)
                                  (i386:pop-base)))
-                         ;; FIXME
-                         (cond ((equal? array "g_functions") ;; FIXME
-                                (list (lambda (f g ta t d)
-                                        (append
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)
-                                         (i386:accu+n 4)
-                                         (i386:base+n 4)
-                                         (i386:base-address->accu-address)))))
-                               (else (list (lambda (f g ta t d)
-                                             (i386:base->accu-address)))))
+                         (if (eq? size 1) (list (lambda (f g ta t d)
+                                                  (i386:byte-base->accu-address)))
+                             (append
+                              (list (lambda (f g ta t d)
+                                      (i386:base-address->accu-address)))
+                              (if (> size 4)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())
+                              (if (> size 8)
+                                  (list (lambda (f g ta t d)
+                                          (append
+                                           (i386:accu+n 4)
+                                           (i386:base+n 4)
+                                           (i386:base-address->accu-address))))
+                                  '())))
                          ((ident-add info) index 1)))))
 
         ;; DECL
index 7343614b7da78e9fb4731eb32508ae51c6f46784..9b1a63dfd99855ffa28d6af0c5c8d72bcd2b8bbf 100644 (file)
   '(#x50))                              ; push %eax
 
 (define (i386:pop-base)
-  '(#x5a))                              ; pop %eax
+  '(#x5a))                              ; pop %edx
 
 (define (i386:push-base)
-  '(#x52))                              ; push %eax
+  '(#x52))                              ; push %edx
 
 (define (i386:ret)
   '(#xc9                                ; leave
index 7b2d95e4e27d2362c200e33ae4c649c906002be1..db43cd8ec7cf7bf30d3eb91ce7223e375c1f142e 100644 (file)
@@ -323,14 +323,26 @@ struct_test ()
   functiony = g_functions[g_cells[fn].cdr].function;
   if ((functiony) (1) != 0) return 16;
 
-  puts ("t: g_functions[<bar>].arity;");
+  puts ("t: g_functions[<bar>].arity\n");
   if (g_functions[fn].arity != 1) return 18;
 
+  // fake name
+  scm_fun.car = 33;
   scm_fun.cdr = g_function;
-  g_functions[g_function++] = g_fun;
+  //g_functions[g_function++] = g_fun;
+  g_functions[g_function] = g_fun;
   cell_fun = g_free++;
   g_cells[cell_fun] = scm_fun;
 
+  puts ("t: TYPE (cell_fun)\n");
+  if (TYPE (cell_fun) != TFUNCTION) return 1;
+
+  puts ("t: CAR (cell_fun)\n");
+  if (CAR (cell_fun) != 33) return 1;
+
+  puts ("t: CDR (cell_fun)\n");
+  if (CDR (cell_fun) != g_function) return 1;
+
   return make_tmps_test  (g_cells);
 }