From b44825a0359265085407b9e119611060fab1e8ca Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 23 Jul 2017 08:44:48 +0200 Subject: [PATCH] mescc: Bugfix non-char* *x x[] test. * module/language/c99/compiler.mes (expr->pointer): New function. (test-jump-label->info): Use it to fix non char* while (*x | x[i]). --- module/language/c99/compiler.mes | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 921694d5..2ab55fd6 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1151,6 +1151,7 @@ (define (ast-type->type info o) (pmatch o + ((p-expr ,expr) (ast-type->type info (p-expr->type info o))) ((decl-spec-list (type-spec (fixed-type ,type))) (ast-type->type info type)) ((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type))) @@ -1342,11 +1343,19 @@ (info (append-text info (wrap-as `((#:label ,skip-b-label)))))) info)) - ((array-ref . _) ((jump i386:jump-byte-z - (wrap-as (i386:accu-zero?))) o)) + ((array-ref ,index ,expr) (let* ((ptr (expr->pointer info expr)) + (size (if (= ptr 1) (ast-type->size info expr) + 4))) + ((jump (if (= size 1) i386:jump-byte-z + i386:jump-z) + (wrap-as (i386:accu-zero?))) o))) - ((de-ref _) ((jump i386:jump-byte-z - (wrap-as (i386:accu-zero?))) o)) + ((de-ref ,expr) (let* ((ptr (expr->pointer info expr)) + (size (if (= ptr 1) (ast-type->size info expr) + 4))) + ((jump (if (= size 1) i386:jump-byte-z + i386:jump-z) + (wrap-as (i386:accu-zero?))) o))) ((assn-expr (p-expr (ident ,name)) ,op ,expr) ((jump i386:jump-z @@ -1448,6 +1457,11 @@ (if local (local:pointer local) (or (and=> (ident->decl info o) global:pointer) 0)))) +(define (expr->pointer info o) + (pmatch o + ((p-expr (ident ,name)) (ident->pointer info name)) + (_ (stderr "expr->pointer: unsupported: ~s\n" o) 0))) + (define (p-expr->type info o) (pmatch o ((p-expr (ident ,name)) (ident->type info name))