From 8fcf2b36b29e3c33ef080d83f888403621d06ee8 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 10 Aug 2017 20:57:43 +0200 Subject: [PATCH] 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. --- module/language/c99/compiler.mes | 51 ++++---------------------- scaffold/tests/76-pointer-arithmetic.c | 11 ++++++ 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index a7f06ee8..96f2d46c 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -697,14 +697,6 @@ ((2) (i386:word-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) (let* ((info ((expr->accu info) expr)) (ptr (expr->pointer info expr)) @@ -749,42 +741,6 @@ ((cond-expr . ,cond-expr) ((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) (let* ((info (append ((expr->accu info) expr))) (info (append-text info (wrap-as (i386:push-accu)))) @@ -1090,6 +1046,13 @@ (define (expr->accu* info) (lambda (o) (pmatch o + + ((p-expr (ident ,name)) + (append-text info ((ident-address->accu info) name))) + + ((de-ref ,expr) + ((expr->accu info) expr)) + ;; foo[bar] ((array-ref ,index (p-expr (ident ,array))) (let* ((info ((expr->accu info) index)) diff --git a/scaffold/tests/76-pointer-arithmetic.c b/scaffold/tests/76-pointer-arithmetic.c index 8e0c278a..28b63344 100644 --- a/scaffold/tests/76-pointer-arithmetic.c +++ b/scaffold/tests/76-pointer-arithmetic.c @@ -19,6 +19,9 @@ */ #include "30-test.i" +#include + +char *list[2] = {"foo\n", "bar\n"}; int test () @@ -43,5 +46,13 @@ test () if (ppv + 1 != 8) return 11; 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; }