Commit graph

1134 commits

Author SHA1 Message Date
Jan Nieuwenhuizen 4175579d08 core: Add logand, lognot.
* src/math.c (logand, lognot): New function.
2017-08-27 12:53:01 +02:00
Jan Nieuwenhuizen 989bfdbd25 mescc: Tinycc support: array of struct of any size.
* module/language/c99/compiler.mes (accu*value): New function
  (expr->accu*): Use it to support array of struct of any size.
* scaffold/tests/7l-struct-any-size-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-27 11:23:45 +02:00
Jan Nieuwenhuizen 21e9bf833c mescc: Tinycc support: stdint.h: declare size_t.
* mlibc/include/stdint.h (size_t)[!__MES_SIZE_T]: Declare.
2017-08-27 11:29:07 +02:00
Jan Nieuwenhuizen 69073e1954 mescc: Tinycc support: pointer arithmetic with pointer-variable.
* module/language/c99/compiler.mes (expr->accu): pointer arithmetic with pointer-variable.
* scaffold/tests/76-pointer-arithmetic.c (test): Test it.
* mlibc/include/stdarg.h (va_start): Update for fixed pointer arithmetic.
2017-08-26 10:16:53 +02:00
Jan Nieuwenhuizen 8649f7a923 mescc: Tinycc support: pointer arithmetic with &variable.
* module/language/c99/compiler.mes (expr->pointer): Handle ref.
* scaffold/tests/76-pointer-arithmetic.c: Test it.
2017-08-25 06:58:15 +02:00
Jan Nieuwenhuizen 0875ce655a mescc: Tinycc support: pointer arithmetic with variable.
* module/language/c99/compiler.mes (expr->accu): Support pointer
  arithmetic with variable: p + i, p - i, p += i, p -= i.
* scaffold/tests/76-pointer-arithmetic.c (test): Test it.
2017-08-23 07:08:16 +02:00
Jan Nieuwenhuizen 1e23dbaf17 mescc: Tinycc support: handle pointerness, siziness for cast foo*.
* module/language/c99/compiler.mes (expr->pointer): Support cast foo*.
  (expr->size): Likewise.
* scaffold/tests/7k-for-each-elem.c: Test it
* make.scm (add-scaffold-test): Build it.
2017-08-23 06:55:25 +02:00
Jan Nieuwenhuizen 93714ad0a4 mescc: Tinycc support: strtoull.
* mlibc/include/mlibc.h (_atoi): Declare.
* mlibc/include/ctype.h (isxdigit): Declare.
* mlibc/libc-gcc.c (isxdigit, _atoi): New function.
  (atoi): Use it.
* mlibc/libc-mes.c (isxdigit, _atoi): New function.
  (atoi): Use it.
* scaffold/tests/7j-strtoull.c (test): Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-19 10:51:24 +02:00
Jan Nieuwenhuizen 70e3e83581 mescc: Tinycc support: snprintf.
* mlibc/include/stdarg.h (vsprintf): Declare.
* mlibc/libc-gcc.c (vsprintf): New function.
  (sprintf): Use it.
* mlibc/libc-mes+tcc.c (snprintf): Implement.
* mlibc/libc-mes.c (vsprintf): New function
  (sprintf): Use it.
2017-08-12 17:38:44 +02:00
Jan Nieuwenhuizen 3392f7241a mescc: Tinycc support: struct.struct.
* module/language/c99/compiler.mes (field:name):
  (field:pointer):
  (field:size):
  (field:type):
  (field-field):
  (field-offset):
  (struct-field): Support struct.struct.
* scaffold/tests/7i-struct-struct.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-10 21:36:49 +02:00
Jan Nieuwenhuizen 5230ddc93b mescc: Fix compile warnings.
* mlibc/include/stdio.h (fdputs): Declare.
* mlibc/libc-gcc.c (malloc):
  (memcpy): Fix compile warning.
2017-08-10 21:00:22 +02:00
Jan Nieuwenhuizen 8fcf2b36b2 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.
2017-08-10 20:57:43 +02:00
Jan Nieuwenhuizen b16c9dbf16 mescc: Tinycc support: word array assignment.
* stage0/x86.M1 (movzwl_(%eax),%eax): New define.
* module/mes/as-i386.mes (i386:word-mem->accu): New function.
* module/mes/as-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): word array assignment.
  (expr->accu*): word array assignment.
* scaffold/tests/7a-struct-char-array.c (test): Test it.
2017-08-08 10:00:13 +02:00
Jan Nieuwenhuizen 082c81dbbb mescc: Tinycc support: struct char array assignment.
* module/language/c99/compiler.mes (expr->accu): struct char array assignment.
* scaffold/tests/7a-struct-char-array.c (test): Test it.
2017-08-07 19:43:59 +02:00
Jan Nieuwenhuizen 11d240e756 mescc: Tinycc support: struct assign by value.
* module/language/c99/compiler.mes (base->ident): Remove.
  (accu->ident): Use them to support assign of size >4 by value.
* scaffold/tests/7h-struct-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
* module/mes/as-i386.mes (i386:base->local): Remove.
  (i386:accu*n->local):
  (i386:accu*n->label): New functions.
* module/mes/as-i386.scm: Export them.
* stage0/x86.M1: (mov____%ebx,0x32):
  (mov____%ebx,0x32(%ebp)):
  (mov____%ebx,0x8(%ebp)):
  (mov____%ebx,0x8(%edx)):
  (mov____%ecx,0x32(%ebp)):
  (mov____%ecx,0x8(%ebp)):
  (mov____0x32(%eax),%ebx):
  (mov____0x32(%eax),%ecx):
  (mov____0x8(%eax),%ebx): New define.
2017-08-06 18:49:19 +02:00
Jan Nieuwenhuizen e616d6120b mescc: Tinycc support: eputc.
* mlibc/include/stdio.h (eputc): Declare.
* mlibc/libc-gcc.c (eputc):
* mlibc/libc-mes.c (eputc): New function.
2017-08-06 13:53:56 +02:00
Jan Nieuwenhuizen ba50d4bd25 mescc: Move simple main to scaffold.
* scaffold/main.c (main): Move from doc/examples/main.c
* make.scm: Build it.
* README: Update.
* guile/mescc.scm (main):
* scripts/mescc.mes (main): Remove fallback doc/examples/main.c
2017-08-06 13:14:09 +02:00
Jan Nieuwenhuizen 12b41e0e86 mescc: Tinycc support: byte and word struct fields.
* stage0/x86.M1 (mov____%al,0x8(%edx)):
  (mov____%ax,(%edx)):
  (mov____%ax,0x32(%edx)):
  (mov____%ax,0x8(%edx)):
  (movzbl_0x32(%eax),%eax):
  (movzbl_0x8(%eax),%eax):
  (movzwl_0x32(%eax),%eax):
  (movzwl_0x8(%eax),%eax): New define.
* module/mes/as-i386.mes (i386:word-accu->base-mem):
  (i386:byte-accu->base-mem+n):
  (i386:word-accu->base-mem+n):
  (i386:byte-mem+n->accu):
  (i386:word-mem+n->accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (struct-field): Use actual size for
  simple types (WAS: 4).
  (decl->info):
  (expr->accu): Respect byte and word struct field sizes.
* scaffold/tests/7g-struct-byte-word-field.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-06 12:27:16 +02:00
Jan Nieuwenhuizen 513180eb2c mescc: Tinycc support: eputs as function for gcc.
* mlibc/libc-gcc.c (eputs)[POSIX]: New function.
* mlibc/include/stdio.h (eputs)[POSIX]: Remove define.
2017-08-06 12:16:34 +02:00
Jan Nieuwenhuizen dd66f9b5d2 mescc: Tinycc support: fixes for foo.bar[baz].
* module/language/c99/compiler.mes (expr->accu, expr->accu*): fixes for foo.bar[baz].
* scaffold/tests/7c-dynarray.c: Test it.
2017-08-05 21:09:19 +02:00
Jan Nieuwenhuizen 95f107282d mescc: Tinycc support: fixes for foo->bar[baz].
* module/language/c99/compiler.mes (expr->accu, expr->accu*): fixes
  for foo->bar[baz].
  (expr->pointer): Support i-sel.
  (p-expr->type): Support add, sub, de-ref, ref-to.
* scaffold/tests/7f-struct-pointer-arithmetic.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-05 19:10:00 +02:00
Jan Nieuwenhuizen 31c69b8b00 mescc: Tinycc support: foo.bar[baz], foo->bar[baz] for typedef'd struct bar.
* module/language/c99/compiler.mes (expr->accu): foo.bar[baz],
  foo->bar[baz] for typedef'd struct bar.
* scaffold/tests/7c-dynarray.c: Test it.
2017-08-05 12:39:36 +02:00
Jan Nieuwenhuizen 3f4cc96a7b mescc: Tinycc support: foo[index]->bar for array bar.
* module/language/c99/compiler.mes (expr->accu*): foo[index]->bar for array bar.
* scaffold/tests/7e-struct-array-access.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-08-04 21:45:29 +02:00
Jan Nieuwenhuizen 50af730e00 Revert "mescc: Tinycc support: workaround for nyacc "\0" bug."
This reverts commit b160540e221dbeb96908823b5a3504bdbfd7f751.

Fixed by: https://lists.gnu.org/archive/html/guile-user/2017-08/msg00007.html
2017-08-04 11:45:15 +02:00
Jan Nieuwenhuizen 5c61c040c9 guix: use nyacc 0.80.41.
* guix.scm (nyacc): use 0.80.41.
2017-08-04 08:59:09 +02:00
Jan Nieuwenhuizen d64a304a83 mescc: Tinycc support: ((unsigned char*)str)[i].
* module/language/c99/compiler.mes (expr->accu*): Consider size of
  expr array deref.
* scaffold/tests/7d-cast-char.c: Test it.
2017-08-04 11:40:04 +02:00
Jan Nieuwenhuizen 949e320622 mescc: Tinycc support: ((unsigned char*)str)[0].
* module/language/c99/compiler.mes (expr->accu): Consider size of
  expr array deref.
* stage0/x86.M1 (movzbl_0x32(%ebp),%eax): New define.
* scaffold/tests/7d-cast-char.c: Test it.
2017-08-04 11:34:01 +02:00
Jan Nieuwenhuizen 5fadb4cbbf mescc: Tinycc support: define __linux__.
* module/language/c99/compiler.mes (c99-input->full-ast): Add
  "__linux__=1" to cpp-defs.
2017-08-04 11:33:34 +02:00
Jan Nieuwenhuizen cb99e3ca6e mescc: Tinycc support: strcat.
* mlibc/libc-mes+tcc.c (strcat): Implement.
2017-08-01 13:26:17 +02:00
Jan Nieuwenhuizen 4fbd16aaac mescc: Tinycc support: vsnprintf.
* module/language/c99/compiler.mes (ast-type->type): Support *p++ in test.
* mlibc/libc-mes+tcc.c (vsnprintf): Implement.
2017-08-01 13:24:23 +02:00
Jan Nieuwenhuizen 0b60a58809 mescc: Tinycc support: support foo.bar[baz], foo->bar[baz] for struct bar.
* module/language/c99/compiler.mes (struct-field): Use negative
  pointer for struct array fields.
  (expr->accu): support: support foo.bar[baz], foo->bar[baz] for struct bar.
* scaffold/tests/7c-dynarray.c: Test it.
2017-08-01 11:26:00 +02:00
Jan Nieuwenhuizen c23a9ee01f mescc: drop naive realloc.
* mlibc/libc-gcc.c (free, memcpy): Move from libc-mes+tcc.c.
  (realloc): Use realloc from libc-mes+tcc.c
* mlibc/libc-gcc+tcc.c (free, memcpy, realloc): Remove.
* mlibc/libc-mes+tcc.c (free, memcpy, realloc): Remove.
* scaffold/tests/79-int-array.c (test): Update.
* scaffold/tests/7a-struct-char-array.c (test): Update.
2017-08-01 11:08:14 +02:00
Jan Nieuwenhuizen 1e37c9d9ea mescc: Tinycc support: ((foo*) p) + n.
* module/language/c99/compiler.mes init-declr->pointer, expr->pointer,
  expr->size): support: ((foo*) p) + n.
  (expr->accu*): Consider field size for foo.bar[baz].
* scaffold/tests/7b-struct-int-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-31 12:19:23 +02:00
Jan Nieuwenhuizen edb6bbcd9c mescc: Tinycc support: field size of foo.bar[baz], foo->bar[baz].
Inspired by a patch from rain1 for foo->bar[baz].

* module/language/c99/compiler.mes (expr->accu):
  (expr->accu*): Consider field size for foo.bar[baz].
* scaffold/tests/7a-struct-char-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-30 18:04:25 +02:00
Jan Nieuwenhuizen 6b5fcfb814 mescc: Tinycc support: fwrite.
* mlibc/libc-mes+tcc.c (fwrite): Implement.
2017-07-30 14:52:35 +02:00
Jan Nieuwenhuizen 63eded82e1 mescc: Tinycc support: fclose.
* mlibc/libc-mes+tcc.c (fclose): Implement.
2017-07-30 14:51:59 +02:00
rain1 7c233246d6 mescc: Tinycc support: fgetc.
* mlibc/libc-mes.c (fgetc): Implement.
2017-07-30 08:28:19 -04:00
rain1 0957094280 mescc: Tinycc support: fprintf.
* mlibc/libc-mes+tcc.c (fprintf): Implement.
2017-07-30 08:28:19 -04:00
rain1 ae9ce4e645 mescc: allow complicated enums expressions.
* module/language/c99/compiler.mes (p-expr->number): Support lshift, rshift, ash.
  (enum-def-list->constants): Refactor using p-expr->number.
2017-07-30 08:28:19 -04:00
rain1 3f188d7268 mescc: support \x00 strings in M1.
* module/mes/M1.mes (object->m1): Support \x00 strings.
2017-07-30 08:28:19 -04:00
Jan Nieuwenhuizen ec3c031b2f mescc: Tinycc support: memmove.
* mlibc/libc-mes+tcc.c (memmove): Implement.
2017-07-30 13:59:06 +02:00
Jan Nieuwenhuizen af8335dc7a mescc: Tinycc support: strrchr.
* mlibc/libc-mes+tcc.c (strrchr): Implement.
2017-07-30 13:09:19 +02:00
Jan Nieuwenhuizen 8991e927c3 mescc: Tinycc support: strchr.
* mlibc/libc-mes+tcc.c (strchr): Implement.
2017-07-30 12:55:58 +02:00
Jan Nieuwenhuizen 18cb982687 mescc: Tinycc support: noisy stubs.
* mlibc/libc-mes+tcc.c: Noisy stubs.
2017-07-27 18:53:44 +02:00
Jan Nieuwenhuizen 9c4519af8d mescc: Tinycc support: int foo[bar] = {baz,...}.
* scaffold/tests/79-int-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
* module/language/c99/compiler.mes (init-declr->count): New function.
  (decl->info): Support int foo[bar] = {baz,...}.
2017-07-30 08:27:05 +02:00
Jan Nieuwenhuizen bd3ab85e98 mescc: Tinycc support: union.struct.
* module/language/c99/compiler.mes (decl->info): Support struct inside union.
* scaffold/tests/78-union-struct.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-29 22:50:00 +02:00
Jan Nieuwenhuizen 042022419e mescc: Tinycc support: fix accu value after comparison.
* stage0/x86.M1 (setg___%al,, setge__%al, setl___%al, setle__%al): New
  defines.
* module/mes/as-i386.mes (i386:g?->accu, i386:ge?->accu,
  i386:l?->accu, i386:le?->accu, i386:jumpl, i386:jumple): New functions.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (expr->accu): Use them to fix accu
  value after comparisons.
  (test-jump-label->info): Update comparison jumps.
2017-07-29 20:46:16 +02:00
Jan Nieuwenhuizen f29479dfa2 mescc: Tinycc support: memcmp.
* mlibc/libc-mes+tcc.c (memcmp): Implement.
2017-07-29 11:09:00 +02:00
Jan Nieuwenhuizen 7d0d3a2221 mescc: Tinycc support: bugfix *++foo,*--foo.
* module/language/c99/compiler.mes (c99-input->full-ast): Pre-define NULL.
  (expr->pointer, expr->size): Handle pre/post-inc/dec.
2017-07-29 10:45:16 +02:00
Jan Nieuwenhuizen f1d9a7a42c mescc: Tinycc support: uniquify strings per compilation unit.
* module/mes/M1.mes (object->M1): Add file-name to string id.
2017-07-29 09:08:44 +02:00