mescc: Tinycc support: --*p, ++*p.
* module/language/c99/compiler.mes (expr->accu): Remove specific --/++. (expr->accu*): Support p, *p. * scaffold/tests/76-pointer-arithmetic.c (test): Test it.
This commit is contained in:
parent
b16c9dbf16
commit
8fcf2b36b2
|
@ -697,14 +697,6 @@
|
||||||
((2) (i386:word-mem->accu))
|
((2) (i386:word-mem->accu))
|
||||||
(else (i386:mem->accu))))))))
|
(else (i386:mem->accu))))))))
|
||||||
|
|
||||||
((de-ref (post-inc (p-expr (ident ,name))))
|
|
||||||
(let* ((info ((expr->accu info) `(de-ref (p-expr (ident ,name)))))
|
|
||||||
(type (ident->type info name))
|
|
||||||
(ptr (ident->pointer info name))
|
|
||||||
(size (if (= ptr 1) (ast-type->size info type)
|
|
||||||
4)))
|
|
||||||
(append-text info ((ident-add info) name size))))
|
|
||||||
|
|
||||||
((de-ref ,expr)
|
((de-ref ,expr)
|
||||||
(let* ((info ((expr->accu info) expr))
|
(let* ((info ((expr->accu info) expr))
|
||||||
(ptr (expr->pointer info expr))
|
(ptr (expr->pointer info expr))
|
||||||
|
@ -749,42 +741,6 @@
|
||||||
((cond-expr . ,cond-expr)
|
((cond-expr . ,cond-expr)
|
||||||
((ast->info info) `(expr-stmt ,o)))
|
((ast->info info) `(expr-stmt ,o)))
|
||||||
|
|
||||||
((post-inc (p-expr (ident ,name)))
|
|
||||||
(let* ((type (ident->type info name))
|
|
||||||
(ptr (ident->pointer info name))
|
|
||||||
(size (cond ((= ptr 1) (ident->size info name))
|
|
||||||
((> ptr 1) 4)
|
|
||||||
(else 1))))
|
|
||||||
(append-text info (append ((ident->accu info) name)
|
|
||||||
((ident-add info) name size)))))
|
|
||||||
|
|
||||||
((post-dec (p-expr (ident ,name)))
|
|
||||||
(let* ((type (ident->type info name))
|
|
||||||
(ptr (ident->pointer info name))
|
|
||||||
(size (cond ((= ptr 1) (ident->size info name))
|
|
||||||
((> ptr 1) 4)
|
|
||||||
(else 1))))
|
|
||||||
(append-text info (append ((ident->accu info) name)
|
|
||||||
((ident-add info) name (- size))))))
|
|
||||||
|
|
||||||
((pre-inc (p-expr (ident ,name)))
|
|
||||||
(let* ((type (ident->type info name))
|
|
||||||
(ptr (ident->pointer info name))
|
|
||||||
(size (cond ((= ptr 1) (ident->size info name))
|
|
||||||
((> ptr 1) 4)
|
|
||||||
(else 1))))
|
|
||||||
(append-text info (append ((ident-add info) name size)
|
|
||||||
((ident->accu info) name)))))
|
|
||||||
|
|
||||||
((pre-dec (p-expr (ident ,name)))
|
|
||||||
(let* ((type (ident->type info name))
|
|
||||||
(ptr (ident->pointer info name))
|
|
||||||
(size (cond ((= ptr 1) (ident->size info name))
|
|
||||||
((> ptr 1) 4)
|
|
||||||
(else 1))))
|
|
||||||
(append-text info (append ((ident-add info) name (- size))
|
|
||||||
((ident->accu info) name)))))
|
|
||||||
|
|
||||||
((post-inc ,expr)
|
((post-inc ,expr)
|
||||||
(let* ((info (append ((expr->accu info) expr)))
|
(let* ((info (append ((expr->accu info) expr)))
|
||||||
(info (append-text info (wrap-as (i386:push-accu))))
|
(info (append-text info (wrap-as (i386:push-accu))))
|
||||||
|
@ -1090,6 +1046,13 @@
|
||||||
(define (expr->accu* info)
|
(define (expr->accu* info)
|
||||||
(lambda (o)
|
(lambda (o)
|
||||||
(pmatch o
|
(pmatch o
|
||||||
|
|
||||||
|
((p-expr (ident ,name))
|
||||||
|
(append-text info ((ident-address->accu info) name)))
|
||||||
|
|
||||||
|
((de-ref ,expr)
|
||||||
|
((expr->accu info) expr))
|
||||||
|
|
||||||
;; foo[bar]
|
;; foo[bar]
|
||||||
((array-ref ,index (p-expr (ident ,array)))
|
((array-ref ,index (p-expr (ident ,array)))
|
||||||
(let* ((info ((expr->accu info) index))
|
(let* ((info ((expr->accu info) index))
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "30-test.i"
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char *list[2] = {"foo\n", "bar\n"};
|
||||||
|
|
||||||
int
|
int
|
||||||
test ()
|
test ()
|
||||||
|
@ -43,5 +46,13 @@ test ()
|
||||||
if (ppv + 1 != 8) return 11;
|
if (ppv + 1 != 8) return 11;
|
||||||
if (ppi + 1 != 8) return 12;
|
if (ppi + 1 != 8) return 12;
|
||||||
|
|
||||||
|
char **p = list;
|
||||||
|
++*p;
|
||||||
|
eputs (*p);
|
||||||
|
if (strcmp (*p, "oo\n")) return 1;
|
||||||
|
--*p;
|
||||||
|
eputs (*p);
|
||||||
|
if (strcmp (*p, "foo\n")) return 2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue