mescc: Proper support for i++,++i,i--,--i.
* module/language/c99/compiler.mes (ast->info): Bugfix: locals. Add i--, --i. Properly support i++, ++i. * module/mes/libc-i386.mes (i386:function-locals): Support 8 local vars. * scaffold/t.c (test): Test it.
This commit is contained in:
parent
c83ef66265
commit
7667fb95c0
|
@ -221,7 +221,8 @@
|
||||||
(locals (.locals info))
|
(locals (.locals info))
|
||||||
(text (.text info)))
|
(text (.text info)))
|
||||||
(define (add-local name)
|
(define (add-local name)
|
||||||
(acons name (1+ (or (and=> (member 1 (map cdr locals)) length) 0)) locals))
|
(let ((locals (acons name (1+ (length (filter positive? (map cdr locals)))) locals)))
|
||||||
|
locals))
|
||||||
|
|
||||||
;; (stderr "\nS=~a\n" o)
|
;; (stderr "\nS=~a\n" o)
|
||||||
;; (stderr " text=~a\n" text)
|
;; (stderr " text=~a\n" text)
|
||||||
|
@ -377,17 +378,43 @@
|
||||||
(list (lambda (f g t d)
|
(list (lambda (f g t d)
|
||||||
(i386:accu-zero?)))))))
|
(i386:accu-zero?)))))))
|
||||||
|
|
||||||
|
;; FIXME
|
||||||
|
((post-inc ,expr) ((ast->info info) `(expr-stmt ,o)))
|
||||||
|
((post-dec ,expr) ((ast->info info) `(expr-stmt ,o)))
|
||||||
|
((pre-inc ,expr) ((ast->info info) `(expr-stmt ,o)))
|
||||||
|
((pre-dec ,expr) ((ast->info info) `(expr-stmt ,o)))
|
||||||
|
|
||||||
;; i++
|
;; i++
|
||||||
((expr-stmt (post-inc (p-expr (ident ,name))))
|
((expr-stmt (post-inc (p-expr (ident ,name))))
|
||||||
(clone info #:text
|
(clone info #:text
|
||||||
(append text (list (lambda (f g t d)
|
(append text (list (lambda (f g t d)
|
||||||
(i386:local-add (assoc-ref locals name) 1))))))
|
(append (i386:local->accu (assoc-ref locals name))
|
||||||
|
(i386:local-add (assoc-ref locals name) 1)
|
||||||
|
(i386:accu-zero?)))))))
|
||||||
|
|
||||||
;; ++i -- same for now FIXME
|
;; ++i
|
||||||
((expr-stmt (pre-inc (p-expr (ident ,name))))
|
((expr-stmt (pre-inc (p-expr (ident ,name))))
|
||||||
(clone info #:text
|
(clone info #:text
|
||||||
(append text (list (lambda (f g t d)
|
(append text (list (lambda (f g t d)
|
||||||
(i386:local-add (assoc-ref locals name) 1))))))
|
(append (i386:local-add (assoc-ref locals name) 1)
|
||||||
|
(i386:local->accu (assoc-ref locals name))
|
||||||
|
(i386:accu-zero?)))))))
|
||||||
|
|
||||||
|
;; i--
|
||||||
|
((expr-stmt (post-dec (p-expr (ident ,name))))
|
||||||
|
(clone info #:text
|
||||||
|
(append text (list (lambda (f g t d)
|
||||||
|
(append (i386:local->accu (assoc-ref locals name))
|
||||||
|
(i386:local-add (assoc-ref locals name) -1)
|
||||||
|
(i386:accu-zero?)))))))
|
||||||
|
|
||||||
|
;; --i
|
||||||
|
((expr-stmt (pre-dec (p-expr (ident ,name))))
|
||||||
|
(clone info #:text
|
||||||
|
(append text (list (lambda (f g t d)
|
||||||
|
(append (i386:local-add (assoc-ref locals name) -1)
|
||||||
|
(i386:local->accu (assoc-ref locals name))
|
||||||
|
(i386:accu-zero?)))))))
|
||||||
|
|
||||||
((not ,expr)
|
((not ,expr)
|
||||||
(let* ((test-info ((ast->info info) expr)))
|
(let* ((test-info ((ast->info info) expr)))
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#x89 #xe5)) ; mov %esp,%ebp
|
#x89 #xe5)) ; mov %esp,%ebp
|
||||||
|
|
||||||
(define (i386:function-locals)
|
(define (i386:function-locals)
|
||||||
'(#x83 #xec #x10)) ; sub $0x10,%esp -- 4 local vars
|
'(#x83 #xec #x20)) ; sub $0x10,%esp -- 8 local vars
|
||||||
|
|
||||||
(define (i386:ref-global o)
|
(define (i386:ref-global o)
|
||||||
`(#x68 ,@(int->bv32 o))) ; push $0x<o>
|
`(#x68 ,@(int->bv32 o))) ; push $0x<o>
|
||||||
|
|
16
scaffold/t.c
16
scaffold/t.c
|
@ -122,6 +122,13 @@ test ()
|
||||||
puts ("t: if (1 && 0)\n");
|
puts ("t: if (1 && 0)\n");
|
||||||
if (1 && 0) return 1;
|
if (1 && 0) return 1;
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
puts ("t: if (i++)\n");
|
||||||
|
if (i++) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (--i)\n");
|
||||||
|
if (--i) return 1;
|
||||||
|
|
||||||
puts ("t: if (1)\n");
|
puts ("t: if (1)\n");
|
||||||
if (1) goto ok0;
|
if (1) goto ok0;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -167,8 +174,15 @@ test ()
|
||||||
return 1;
|
return 1;
|
||||||
ok8:
|
ok8:
|
||||||
|
|
||||||
|
puts ("t: if (++i)\n");
|
||||||
|
if (++i) goto ok9;
|
||||||
|
ok9:
|
||||||
|
|
||||||
|
puts ("t: if (i--)\n");
|
||||||
|
if (i--) goto ok10;
|
||||||
|
ok10:
|
||||||
|
|
||||||
puts ("t: for (i=0; i<4; ++i)\n");
|
puts ("t: for (i=0; i<4; ++i)\n");
|
||||||
int i;
|
|
||||||
for (i=0; i<4; ++i);
|
for (i=0; i<4; ++i);
|
||||||
if (i != 4) return i;
|
if (i != 4) return i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue