mescc: Struct by value assignment fixes.

* module/language/c99/compiler.mes (ast->info): Remove g_function
  hardcoding, fix struct assignment.
* doc/examples/t.c (struct_test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-22 07:13:34 +01:00
parent bcf1b2a356
commit 76f6fdc43e
3 changed files with 73 additions and 41 deletions

View 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

View file

@ -72,10 +72,10 @@
'(#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

View 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);
}