mescc: refactor expr->accu, expr->accu*, fixes nontrivial struct by value assign.

* module/language/c99/compiler.mes: (pke): New function.
  (expr->number): Rename from p-expr->number.  Update callers.
  (decl->info, init-declr->pointer, struct-field): Several pointeryness fixes.
  (expr->accu*, expr->accu): Remove special-casing for foo.bar,
  foo->bar, foo[bar].  Fixes struct by value assign for non-trival
  expressions.
  (accu->ident, ident-address->accu, ident->accu):
  (base->ident-address, ident->base): Remove.
* scaffold/tests/7k-for-each-elem.c (test): Test it.
* scaffold/tests/7c-dynarray.c (test): Test it.
* scaffold/tests/7m-struct-char-array-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
This commit is contained in:
Jan Nieuwenhuizen 2017-11-11 13:45:53 +01:00
parent 6a16258f78
commit dc65de59ce
5 changed files with 1077 additions and 1557 deletions

View file

@ -244,7 +244,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
"7i-struct-struct"
"7j-strtoull"
"7k-for-each-elem"
"7l-struct-any-size-array"))
"7l-struct-any-size-array"
"7m-struct-char-array-assign"))
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))

File diff suppressed because it is too large Load diff

View file

@ -46,9 +46,18 @@ add (void *ptab, int *nb_ptr, void *data)
*nb_ptr = nb;
}
typedef struct file {
typedef struct file4 {
char name[4];
} file_struct;
} file4_struct;
typedef struct file12 {
int foo;
int bar;
char name[4];
} file12_struct;
//#define file file4
#define file file12
struct state {
int bla;
@ -81,9 +90,10 @@ test ()
eputs ("&PATHS="); eputs (itoa (&s->paths)); eputs ("\n");
eputs ("&FILES="); eputs (itoa (&s->files)); eputs ("\n");
struct file *fs;
eputs ("foo\n");
fs = s->files[0];
// struct file *fs;
// eputs ("foo\n");
// fs = s->files[0];
struct file *fs = s->files[0];
eputs ("add s= "); eputs (itoa (s)); eputs ("\n");
eputs ("add fs= "); eputs (itoa (fs)); eputs ("\n");
eputs ("&fs->[0]="); eputs (itoa (fs->name)); eputs ("\n");

View file

@ -31,7 +31,8 @@ struct sym {
};
struct sym tab[3] = {"foo", 0, "bar", 1, "baz", 2};
struct sym tab3[3] = {"foo", 0, "bar", 1, "baz", 2};
struct sym tab[] = {"foo", 0, "bar", 1, "baz", 2};
struct section section;
@ -45,10 +46,11 @@ struct section section;
int
test ()
{
struct sym* p;
p = tab3;
section.data = tab;
section.offset = 24;
struct sym* p;
int size = sizeof (struct sym);
eputs ("size="); eputs (itoa (size)); eputs ("\n");
if (size != 8) return 1;

View file

@ -0,0 +1,42 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "30-test.i"
struct file {
char *ptr;
char buffer[20];
};
int
test ()
{
struct file f;
f.ptr = f.buffer;
eputs ("***\n");
f.ptr[0] = 'X';
eputs ("***\n");
f.ptr[1] = 'X';
eputs (f.ptr); eputs ("\n");
return 0;
}