mes.git
5 years agomescc: scaffold: misc cleanups.
Jan Nieuwenhuizen [Sun, 3 Dec 2017 22:03:09 +0000 (23:03 +0100)]
mescc: scaffold: misc cleanups.

* scaffold/tests/44-switch.c (swits): More case labels.
* scaffold/tests/60-math.c: Discriminate return values.
* scaffold/tests/77-pointer-assign.c (memset)[__TINYC__]: Remove.
* scaffold/tests/79-int-array.c (test): Discriminate return values.

5 years agomlibc: Tinycc support: __udivdi3, __umoddi3.
Jan Nieuwenhuizen [Sun, 3 Dec 2017 19:40:49 +0000 (20:40 +0100)]
mlibc: Tinycc support: __udivdi3, __umoddi3.

* lib/libc+tcc-gcc.c (__udivdi3, __umoddi3): Fix signature, do not
  crash on simple integer devisions.

5 years agomescc: Tinycc support: Respect word size better.
Jan Nieuwenhuizen [Sun, 3 Dec 2017 15:33:35 +0000 (16:33 +0100)]
mescc: Tinycc support: Respect word size better.

* stage0/x86.M1 (movzwl_0x32(%ebp),%eax,movzwl_0x8(%ebp),%eax): New
  define.
* module/mes/as-i386.mes (i386:push-word-local-de-ref,
  i386:word-local->accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (push-local-de-ref): Respect word size.
  (ident->accu): Likewise.

5 years agomlibc: New library layout; remove duplication.
Jan Nieuwenhuizen [Sun, 3 Dec 2017 12:56:21 +0000 (13:56 +0100)]
mlibc: New library layout; remove duplication.

* lib/libc+tcc-gcc.c: New file: Libc bits for GCC from libc-mes+tcc.c.
* lib/libc+tcc-mes.c: New file: Libc bits for MesCC from libc-mes+tcc.c.
* lib/libc+tcc.c: New file: Libc bits from libc-mes+tcc.c.
* lib/libc.c: New file: Merged from libc-mes.c, libc-gcc.c.
  (abtoi): New function: Rename from _atoi.
* lib/linux+tcc-gcc.c: New file:  Linux bits from libc-gcc+tcc.c.
* lib/linux+tcc-mes.c: New file: Linux bits from libc-mes+tcc.c.
* lib/linux-gcc.c: New file: Linux bits from libc-gcc.c.
* lib/linux-mes.c: New file: Linux bits from libc-mes.c.
* lib/mini-libc-gcc.c: New file.
* lib/mini-libc.c: New file: Libc bits from mini-libc-mes.c.
* lib/mini-linux-gcc.c: New file.
* lib/mini-linux-mes.c: New file: Linux bits from mini-libc-mes.c.
* lib/libc-gcc.c: Remove duplication using include now.
* lib/libc-mes.c: Likewise.
* lib/mini-libc-mes.c: Likewise.
* include/stdio.h (puts)[POSIX]: Remomve macro.
  (fputc, fputs)[!POSIX]: New macro.
  (fputc, fputs): Remove declaration.
* scaffold/tests/7j-strtoull.c (strtoull, test): Use abtoi.
* src/lib.c (fputs)[__MESC__]: Remove define.
* guile/guix/make.scm: Update for new library layout.
* make.scm: Likewise.
* build.sh: Likewise.
* install.sh: Likewise.

5 years agomlibc: Tinycc support: itoab, for debugging.
Jan Nieuwenhuizen [Sun, 3 Dec 2017 09:33:05 +0000 (10:33 +0100)]
mlibc: Tinycc support: itoab, for debugging.

* lib/libc-gcc.c (itoab): New function.
* lib/libc-mes.c (itoab): New function.

5 years agomescc: prefix string labels with _.
Jan Nieuwenhuizen [Sat, 2 Dec 2017 13:04:41 +0000 (14:04 +0100)]
mescc: prefix string labels with _.

* module/mes/M1.mes (object->M1): Prefix string lables with _.

5 years agomescc: prefix local labels with _.
Jan Nieuwenhuizen [Sat, 2 Dec 2017 11:59:07 +0000 (12:59 +0100)]
mescc: prefix local labels with _.

* module/language/c99/compiler.mes (expr->accu): prefix local labels with _.

5 years agobootstrap: Update build script.
Jan Nieuwenhuizen [Sat, 2 Dec 2017 07:48:34 +0000 (08:48 +0100)]
bootstrap: Update build script.

* build.sh: Add blood-elf, use -o.

5 years agomlibc: Mescc-tools support: fix for [v]fprintf.
Jan Nieuwenhuizen [Sat, 2 Dec 2017 07:46:41 +0000 (08:46 +0100)]
mlibc: Mescc-tools support: fix for [v]fprintf.

* lib/libc-mes+tcc.c (vfprintf): Bugfix: print to fd.

5 years agomes: resurrect full reader in C core.
Jan Nieuwenhuizen [Wed, 29 Nov 2017 20:42:50 +0000 (21:42 +0100)]
mes: resurrect full reader in C core.

* module/mes/read-0.mes (defined?): New function.
  (eat-whitespace, read-env, read-word, read-block-comment,
  read-line-comment, read-list, read-character, read-hex, read-octal,
  reader:read-string, lookup, read-hash, read-word): Only define if
  not %c-reader.
* module/mes/base-0.mes (defined?): Remove.
* src/mes.c[MES_C_READER]: Set ARENA_SIZE=10000000.
  (scm_symbol_quasiquote scm_symbol_unquote,
  scm_symbol_unquote_splicing, scm_symbol_syntax,
  scm_symbol_quasisyntax, scm_symbol_unsyntax,
  scm_symbol_unsyntax_splicing): New symbol.
  (scm_symbol_c_reader): New symbol.
  (MAKE_KEYWORD)[MES_C_READER]: New define.
  (mes_symbols): Define %c_reader.
* src/reader.c (read_word_)[MES_C_READER]: Extend to full Scheme
  reader.
  (eat_whitespace)[MES_C_READER]: Likewise.
  (read_block_comment, read_hash, read_word, read_character,
  read_octal, read_hex, append_char, read_string)[MES_C_READER]:
  Likewise.
* make.scm (bin.gcc,bin.mescc): Define MES_C_READER=1.

5 years agomescc: Mescc-tools support: char foo[BAR] = {'a', 'b', 'c'}.
Jan Nieuwenhuizen [Mon, 27 Nov 2017 18:51:18 +0000 (19:51 +0100)]
mescc: Mescc-tools support: char foo[BAR] = {'a', 'b', 'c'}.

* stage0/x86.M1 (mov____%al,0x8(%ebp), mov____%al,0x32(%ebp),
  mov____%ax,0x8(%ebp), mov____%ax,0x32(%ebp)): New define.
* module/mes/as-i386.mes (i386:accu->local+n,i386:byte-accu->local+n,
  i386:word-accu->local+n): New function.
* module/language/c99/compiler.mes (accu->local+n): New function.
  (initzer->data): Return char as single byte.
  (decl->info): Support char foo[BAR] = {'a', 'b', 'c'}.
* scaffold/tests/66-local-char-array.c: Test it.
* make.scm (add-scaffold-test): Build it.

5 years agomlibc: Mescc-tools support: chmod.
Jan Nieuwenhuizen [Sun, 26 Nov 2017 17:45:10 +0000 (18:45 +0100)]
mlibc: Mescc-tools support: chmod.

* stage0/x86.M1 (SYS_chmod): New define.
* lib/libc-gcc.c (chmod): New function.
* lib/libc-mes.c (chmod): New function.

5 years agomlibc: GNU Gcc support: setjmp, longjmp.
Jan Nieuwenhuizen [Sun, 26 Nov 2017 12:10:46 +0000 (13:10 +0100)]
mlibc: GNU Gcc support: setjmp, longjmp.

* stage0/x86.M1 (jmp____*%ebx): New macro.
  (mov____0x8(%ebp),%ebp): New macro.
  (mov____0x8(%ebp),%esp): New macro.
* include/setjmp.h (jmp_buf): Redefine as struct.
* lib/libc-mes+tcc.c (longjmp, setjmp): Implement.
* scaffold/tests/80-setjmp.c: Test it.
* make.scm ("80-setjmp"): Build it.
* .gitignore: Ignore *.tcc-guile.

5 years agomlibc: GNU Gcc support: ferror.
Jan Nieuwenhuizen [Sat, 25 Nov 2017 21:57:18 +0000 (22:57 +0100)]
mlibc: GNU Gcc support: ferror.

* lib/libc-mes+tcc.c (ferror): New function.
* include/stdio.h (ferror): Declare it.

5 years agobootstrap: Add bootstrap build scripts.
Jan Nieuwenhuizen [Fri, 24 Nov 2017 18:02:58 +0000 (19:02 +0100)]
bootstrap: Add bootstrap build scripts.

* build.sh: New file.
* check-mescc.sh: New file.
* check.sh: New file.
* install.sh: New File.

5 years agoremove obsolete Nyacc link.
Jan Nieuwenhuizen [Thu, 23 Nov 2017 18:49:12 +0000 (19:49 +0100)]
remove obsolete Nyacc link.

* guile/nyacc: Remove.

5 years agobuild: mlib/include to include, move mlib to lib.
Jan Nieuwenhuizen [Wed, 22 Nov 2017 15:23:48 +0000 (16:23 +0100)]
build: mlib/include to include, move mlib to lib.

* include: Move from mlib/include.
* lib: Move from mlib.
* BOOTSTRAP: Update.
* HACKING: Update.
* guile/guix/make.scm: Update.
* make.scm: Update.
* module/language/c99/compiler.mes: Update.

5 years agomes: Resurrect running mes tests tests/*.test with Guile.
Jan Nieuwenhuizen [Tue, 21 Nov 2017 18:13:14 +0000 (19:13 +0100)]
mes: Resurrect running mes tests tests/*.test with Guile.

* tests/tests/base.test-guile: New file to resurrect running Mes test with Guile.
* tests/catch.test-guile: Symlink for same purpose.
* tests/closure.test-guile: Likewise.
* tests/cwv.test-guile: Likewise.
* tests/display.test-guile: Likewise.
* tests/fluids.test-guile: Likewise.
* tests/guile.test-guile: Likewise.
* tests/let-syntax.test-guile: Likewise.
* tests/let.test-guile: Likewise.
* tests/match.test-guile: Likewise.
* tests/math.test-guile: Likewise.
* tests/module.test-guile: Likewise.
* tests/optargs.test-guile: Likewise.
* tests/peg.test-guile: Likewise.
* tests/pmatch.test-guile: Likewise.
* tests/psyntax.test-guile: Likewise.
* tests/quasiquote.test-guile: Likewise.
* tests/read.test-guile: Likewise.
* tests/record.test-guile: Likewise.
* tests/scm.test-guile: Likewise.
* tests/srfi-1.test-guile: Likewise.
* tests/srfi-13.test-guile: Likewise.
* tests/srfi-14.test-guile: Likewise.
* tests/vector.test-guile: Likewise.
* make.scm (add-guile-test): New function.  Use it to run running tests/*.test-guile.

5 years agomes: resurrect running MesCC: handle \t in strings.
Jan Nieuwenhuizen [Mon, 20 Nov 2017 22:22:53 +0000 (23:22 +0100)]
mes: resurrect running MesCC: handle \t in strings.

* module/mes/read-0.mes (reader:read-string): Handle \t.  Fixex M1 output.

5 years agomes: Nyacc support: with-fluids.
Jan Nieuwenhuizen [Mon, 20 Nov 2017 22:21:25 +0000 (23:21 +0100)]
mes: Nyacc support: with-fluids.

* module/mes/fluids.mes (with-fluids): New macro.
* tests/fluids.test ("with-fluids"): Test it.

5 years agomes: resurrect running MesCC: update info interface.
Jan Nieuwenhuizen [Mon, 20 Nov 2017 22:17:50 +0000 (23:17 +0100)]
mes: resurrect running MesCC: update info interface.

* module/language/c99/info.mes (type?, global?, local?): New function.
  (make-global): Remove name parameter.
* module/nyacc/lang/c99/pprint.mes: New file.

5 years agomes: Add last.
Jan Nieuwenhuizen [Sun, 17 Dec 2017 12:32:17 +0000 (13:32 +0100)]
mes: Add last.

* module/srfi/srfi-1.mes (last): New funcion.

5 years agomes: Add reverse-list->string.
Jan Nieuwenhuizen [Mon, 20 Nov 2017 05:49:27 +0000 (06:49 +0100)]
mes: Add reverse-list->string.

* module/srfi/srfi-13.mes (reverse-list->string): New function.

5 years agobootstrap: Unbundle necessary M1 sources.
Jan Nieuwenhuizen [Mon, 20 Nov 2017 05:47:46 +0000 (06:47 +0100)]
bootstrap: Unbundle necessary M1 sources.

* mlibc/crt1.M1: Remove.
* mlibc/libc-mes.M1: Remove.
* src/mes.M1: Remove.

5 years agomlibc: Mescc-tools support: fix fgetc.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 15:54:59 +0000 (16:54 +0100)]
mlibc: Mescc-tools support: fix fgetc.

* mlibc/libc-mes.c (fgetc): Fix from completely fubar.

5 years agomlibc: Mescc-tools support: strtol: partly implement stub.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 15:54:13 +0000 (16:54 +0100)]
mlibc: Mescc-tools support: strtol: partly implement stub.

* mlibc/libc-mes+tcc.c (strtol): Partly implement stub.

5 years agomlibc: Mescc-tools support: getopt, getopt_long.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 15:48:37 +0000 (16:48 +0100)]
mlibc: Mescc-tools support: getopt, getopt_long.

* mlibc/getopt.c: Move to ANSI C.  Remove GETOPT_COMPAT and
  non-POSIXLY_CORRECT options.
* mlibc/include/getopt.h: New file.
* mlibc/libc-gcc+tcc.c: Include getopt.c.
* mlibc/libc-mes+tcc.c: Likewise.

5 years agomlibc: Mescc-tools support: import getopt_long.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 13:09:21 +0000 (14:09 +0100)]
mlibc: Mescc-tools support: import getopt_long.

* mlibc/getopt.c: Import from gcc-2.0.

5 years agoRevert "mescc: Grok char foo[] parameter."
Jan Nieuwenhuizen [Sun, 19 Nov 2017 19:50:06 +0000 (20:50 +0100)]
Revert "mescc: Grok char foo[] parameter."

This reverts commit c4cc75105db48b550cd515751b766b2e7a88ddc3.

5 years agomescc: Grok char foo[] parameter.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 18:59:18 +0000 (19:59 +0100)]
mescc: Grok char foo[] parameter.

* module/language/c99/compiler.mes (function->text+data): Grok char
  foo[] parameter.

5 years agomescc: Grok char *const foo[];
Jan Nieuwenhuizen [Sun, 19 Nov 2017 15:46:43 +0000 (16:46 +0100)]
mescc: Grok char *const foo[];

* module/language/c99/compiler.mes (ast-strip-const): Grok char *const argv[];

5 years agomlibc: Mescc-tools support: endianness.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 13:06:32 +0000 (14:06 +0100)]
mlibc: Mescc-tools support: endianness.

* mlibc/include/endian.h: New file.
* mlibc/include/ctype.h[!(__GNUC__ && POSIX)]: Include it.
* mlibc/include/stdlib.h: Likewise.
* mlibc/include/sys/types.h: Likewise.

5 years agomlibc: Mescc-tools support: exit stati.
Jan Nieuwenhuizen [Sun, 19 Nov 2017 13:05:33 +0000 (14:05 +0100)]
mlibc: Mescc-tools support: exit stati.

* mlibc/include/stdlib.h (EXIT_FAILURE, EXIT_SUCCESS): New define.

5 years agomescc: cleanup obsolete Nyacc 0.7x compatibility.
Jan Nieuwenhuizen [Sat, 18 Nov 2017 20:05:43 +0000 (21:05 +0100)]
mescc: cleanup obsolete Nyacc 0.7x compatibility.

* module/language/c99/compiler.mes (ast-type->type, ast->type
  expr->accu, struct-field, decl->info,): Remove obsolete Nyacc 0.7x
  patterns.

5 years agoguix: Release update.
Jan Nieuwenhuizen [Sat, 18 Nov 2017 12:53:50 +0000 (13:53 +0100)]
guix: Release update.

* guix.scm (mes): Update commit, hash and version.  Add
  'make-git-source-writable stage.

5 years agoRelease 0.11. v0.11
Jan Nieuwenhuizen [Sat, 18 Nov 2017 12:14:20 +0000 (13:14 +0100)]
Release 0.11.

* configure (VERSION): Bump to 0.11.

5 years agodoc: Release udpate.
Jan Nieuwenhuizen [Sat, 11 Nov 2017 12:09:26 +0000 (13:09 +0100)]
doc: Release udpate.

* HACKING: Update.
* INSTALL: Update.
* NEWS: Update.
* README: Update.
* doc/ANNOUNCE-0.11: New file.

5 years agobuild: fix for 07-include, thanks rain1!
Jan Nieuwenhuizen [Sat, 18 Nov 2017 14:02:21 +0000 (15:02 +0100)]
build: fix for 07-include, thanks rain1!

* make.scm (add-scaffold-test): New keyword parameter: includes.
  ("07-include"): Use it.

5 years agobuild: support gcc -m32, thanks rain1!
Jan Nieuwenhuizen [Sat, 18 Nov 2017 13:50:56 +0000 (14:50 +0100)]
build: support gcc -m32, thanks rain1!

* guile/guix/make.scm (%CC32): fallback to %CC.
  (%C32-FLAGS): Add -m32, to suppor gcc -m32.
  (LINK.gcc): Use it.

5 years agobootstrap: Update necessary M1 sources.
Jan Nieuwenhuizen [Sat, 18 Nov 2017 11:14:07 +0000 (12:14 +0100)]
bootstrap: Update necessary M1 sources.

   M1 -f stage0/x86.M1 -f mlibc/crt1.M1 --LittleEndian --Architecture=1 > mlibc/crt1.hex2
   M1 -f stage0/x86.M1 -f mlibc/mini-libc-mes.M1 --LittleEndian --Architecture=1  > mlibc/libc-mes.hex2
   M1 -f stage0/x86.M1 -f src/mes.M1 --LittleEndian --Architecture=1 > src/mes.hex2
   hex2 --LittleEndian --Architecture=1 --BaseAddress=0x1000000 -f stage0/elf32-header.hex2 -f mlibc/crt1.hex2 -f mlibc/libc-mes.hex2 -f src/mes.hex2 -f stage0/elf32-footer-single-main.hex2 > src/mes-mes
   exec_enable src/mes-mes

* mlibc/libc-mes.M1: Update.
* src/mes.M1: Udate.

5 years agomescc: Tinycc support: test #include.
Jan Nieuwenhuizen [Sat, 18 Nov 2017 10:55:47 +0000 (11:55 +0100)]
mescc: Tinycc support: test #include.

* scaffold/tests/exit-42.i: New file.
* scaffold/tests/07-include.c: New file.
* make.scm ("07-include"): Build it.

5 years agomescc: Tinycc support: struct struct array.
Jan Nieuwenhuizen [Fri, 17 Nov 2017 14:24:45 +0000 (15:24 +0100)]
mescc: Tinycc support: struct struct array.

Support

  struct foo
  {
    struct bar baz[N];
    struct bar bla*[M];
  };

* module/language/c99/compiler.mes (expr->accu):
* scaffold/tests/7n-struct-struct-array.c: Test it.
* make.scm (add-scaffold-test): Build it.

5 years agomlibc: Tinycc support: support, most syscalls stubbed.
Jan Nieuwenhuizen [Thu, 16 Nov 2017 21:11:07 +0000 (22:11 +0100)]
mlibc: Tinycc support: support, most syscalls stubbed.

* mlibc/libc-gcc.c (exit, write)[__TINYC__]: tcc-compatible gcc-style
  asm implementation.
  (read,open,access,brk,fsync)[__TINYC__]: Stub body.
* mlibc/libc-gcc+tcc.c (close,unlink, lseek, getcwd)[__TINYC__]: Stub
  body.
* mlibc/libc-mes+tcc.c: Support tinycc.
* mlibc/include/00-test.i (main) [__TINYC__]: Support tcc.

5 years agomescc: Tinycc support: empty for.
Jan Nieuwenhuizen [Thu, 16 Nov 2017 04:52:47 +0000 (05:52 +0100)]
mescc: Tinycc support: empty for.

* module/language/c99/compiler.mes (test-jump-label->info): Handle
  empty expression.
* make.scm (add-tcc-test "45_empty_for"): Test it.

5 years agotinycc: scaffold/main.c: running mes-tcc compiled binary #6.
Jan Nieuwenhuizen [Thu, 16 Nov 2017 04:33:11 +0000 (05:33 +0100)]
tinycc: scaffold/main.c: running mes-tcc compiled binary #6.

* scaffold/main.c (main): Use variable, if, argc, ++, +=, function call to return 42.

5 years agotinycc: scaffold/main.c: running mes-tcc compiled binary #5.
Jan Nieuwenhuizen [Wed, 15 Nov 2017 22:06:23 +0000 (23:06 +0100)]
tinycc: scaffold/main.c: running mes-tcc compiled binary #5.

* scaffold/main.c (main): Use function call and variable to return 42.

5 years agotinycc: scaffold/main.c: running mes-tcc compiled binary #4.
Jan Nieuwenhuizen [Tue, 14 Nov 2017 18:42:08 +0000 (19:42 +0100)]
tinycc: scaffold/main.c: running mes-tcc compiled binary #4.

* scaffold/main.c (main): Use variables to return 42.

5 years agomescc: Tinycc support: workaround lack of long long support.
Jan Nieuwenhuizen [Tue, 14 Nov 2017 18:39:46 +0000 (19:39 +0100)]
mescc: Tinycc support: workaround lack of long long support.

* module/language/c99/compiler.mes (i386:type-alist): Use size=4 for
  long long as a workaround.

5 years agomescc: refactor expr->accu, expr->accu*, fixes nontrivial struct by value assign.
Jan Nieuwenhuizen [Sat, 11 Nov 2017 12:45:53 +0000 (13:45 +0100)]
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.

5 years agomlibc: errno.h: declare errno without extern.
Jan Nieuwenhuizen [Sat, 11 Nov 2017 12:42:42 +0000 (13:42 +0100)]
mlibc: errno.h: declare errno without extern.

* mlibc/include/errno.h: drop extern.  Fixes tcc compile.

5 years agoguix: nyacc: Update to 0.82.4.
Jan Nieuwenhuizen [Sat, 11 Nov 2017 12:20:25 +0000 (13:20 +0100)]
guix: nyacc: Update to 0.82.4.

* guix.scm (nyacc): Update to 0.82.4.

5 years agoguix: Release update.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 19:59:16 +0000 (21:59 +0200)]
guix: Release update.

* guix.scm (mes): Update commit, hash and version.

5 years agoRelease 0.10. v0.10
Jan Nieuwenhuizen [Sun, 10 Sep 2017 19:55:05 +0000 (21:55 +0200)]
Release 0.10.

* configure (VERSION): Bump to 0.10.

5 years agodoc: Release udpate.
Jan Nieuwenhuizen [Sat, 26 Aug 2017 11:29:07 +0000 (13:29 +0200)]
doc: Release udpate.

* HACKING: Update.
* INSTALL: Update.
* NEWS: Update.
* doc/ANNOUNCE-0.10: New file.
* BOOTSTRAP: New file.
* make.scm: Install them.

5 years agobootstrap: Include necessary M1 sources.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 19:17:17 +0000 (21:17 +0200)]
bootstrap: Include necessary M1 sources.

   M1 -f stage0/x86.M1 -f mlibc/crt1.M1 --LittleEndian --Architecture=1 > mlibc/crt1.hex2
   M1 -f stage0/x86.M1 -f mlibc/mini-libc-mes.M1 --LittleEndian --Architecture=1  > mlibc/libc-mes.hex2
   M1 -f stage0/x86.M1 -f src/mes.M1 --LittleEndian --Architecture=1 > src/mes.hex2
   hex2 --LittleEndian --Architecture=1 --BaseAddress=0x1000000 -f stage0/elf32-header.hex2 -f mlibc/crt1.hex2 -f mlibc/libc-mes.hex2 -f src/mes.hex2 -f stage0/elf32-footer-single-main.hex2 > src/mes-mes
   exec_enable src/mes-mes

* mlibc/crt1.M1: New File.
* mlibc/libc-mes.M1: New File.
* src/mes.M1: New File.

5 years agoguix: Bump Nyacc to 0.82.0.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 19:10:08 +0000 (21:10 +0200)]
guix: Bump Nyacc to 0.82.0.

* guix.scm (nyacc): Bump to 0.82.0.

5 years agomescc: Support Nyacc-0.81.0.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 19:09:23 +0000 (21:09 +0200)]
mescc: Support Nyacc-0.81.0.

* module/language/c99/compiler.mes (ast->info): Handle asm-expr from
  Nyacc 0.81.0.

5 years agotinycc: scaffold/main.c: running tcc-compiled binary #3.
Jan Nieuwenhuizen [Sun, 3 Sep 2017 08:43:02 +0000 (10:43 +0200)]
tinycc: scaffold/main.c: running tcc-compiled binary #3.

* scaffold/main.c (main): Remove asm.

5 years agomescc: Tinycc support: struct by value assign.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 14:59:53 +0000 (16:59 +0200)]
mescc: Tinycc support: struct by value assign.

* module/language/c99/compiler.mes (expr->accu): warn for unsupported
  sizes.
* scaffold/tests/7h-struct-assign.c (test): Test it.

5 years agotinycc: scaffold/main.c: running tcc-compiled binary #2.
Jan Nieuwenhuizen [Sat, 2 Sep 2017 22:37:39 +0000 (00:37 +0200)]
tinycc: scaffold/main.c: running tcc-compiled binary #2.

* scaffold/main.c (main)[__i386__]: Rename from _start.

5 years agobuild: compile crt1.c, libc-mesc.c and <input>.c separately.
Jan Nieuwenhuizen [Sun, 10 Sep 2017 14:59:43 +0000 (16:59 +0200)]
build: compile crt1.c, libc-mesc.c and <input>.c separately.

* mlibc/crt1.c: New file.
* mlibc/libc-mes.c (_start): Remove.
* mlibc/libc-gcc.c (_start): Remove.
* make.scm (LINK.hex2, bin.mescc): Move from guile/guix/make.scm.
* guile/guix/make.scm (LINK.hex2, bin.mescc): Remove.

5 years agomescc: Tinycc support: refactor _start.
Jan Nieuwenhuizen [Sun, 3 Sep 2017 06:18:18 +0000 (08:18 +0200)]
mescc: Tinycc support: refactor _start.

* mlibc/libc-mes.c (_start): Refactor.
  (_env): Remove.
* stage0/x86.M1:

5 years agotinycc: scaffold/main.c: first running tcc-compiled binary.
Jan Nieuwenhuizen [Sat, 19 Aug 2017 09:35:58 +0000 (11:35 +0200)]
tinycc: scaffold/main.c: first running tcc-compiled binary.

* scaffold/main.c (_start): Exit 42 using asm.

5 years agomescc: Tinycc support: fix *--p = 'x'.
Jan Nieuwenhuizen [Sun, 27 Aug 2017 14:58:56 +0000 (16:58 +0200)]
mescc: Tinycc support: fix *--p = 'x'.

* module/language/c99/compiler.mes (expr->accu): Respect size in *--p = 'x'.
* scaffold/tests/23-pointer.c (test): Test it.

5 years agomescc: Tinycc support: initializer arithmetic.
Jan Nieuwenhuizen [Sun, 27 Aug 2017 10:57:50 +0000 (12:57 +0200)]
mescc: Tinycc support: initializer arithmetic.

* module/language/c99/compiler.mes (p-expr->bool): New function
  (p-expr->number): Support bitwise-and, bitwise-not, cast, cond-expr.

5 years agocore: Add logand, lognot.
Jan Nieuwenhuizen [Sun, 27 Aug 2017 10:53:01 +0000 (12:53 +0200)]
core: Add logand, lognot.

* src/math.c (logand, lognot): New function.

5 years agomescc: Tinycc support: array of struct of any size.
Jan Nieuwenhuizen [Sun, 27 Aug 2017 09:23:45 +0000 (11:23 +0200)]
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.

5 years agomescc: Tinycc support: stdint.h: declare size_t.
Jan Nieuwenhuizen [Sun, 27 Aug 2017 09:29:07 +0000 (11:29 +0200)]
mescc: Tinycc support: stdint.h: declare size_t.

* mlibc/include/stdint.h (size_t)[!__MES_SIZE_T]: Declare.

5 years agomescc: Tinycc support: pointer arithmetic with pointer-variable.
Jan Nieuwenhuizen [Sat, 26 Aug 2017 08:16:53 +0000 (10:16 +0200)]
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.

5 years agomescc: Tinycc support: pointer arithmetic with &variable.
Jan Nieuwenhuizen [Fri, 25 Aug 2017 04:58:15 +0000 (06:58 +0200)]
mescc: Tinycc support: pointer arithmetic with &variable.

* module/language/c99/compiler.mes (expr->pointer): Handle ref.
* scaffold/tests/76-pointer-arithmetic.c: Test it.

5 years agomescc: Tinycc support: pointer arithmetic with variable.
Jan Nieuwenhuizen [Wed, 23 Aug 2017 05:08:16 +0000 (07:08 +0200)]
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.

5 years agomescc: Tinycc support: handle pointerness, siziness for cast foo*.
Jan Nieuwenhuizen [Wed, 23 Aug 2017 04:55:25 +0000 (06:55 +0200)]
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.

5 years agomescc: Tinycc support: strtoull.
Jan Nieuwenhuizen [Sat, 19 Aug 2017 08:51:24 +0000 (10:51 +0200)]
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.

5 years agomescc: Tinycc support: snprintf.
Jan Nieuwenhuizen [Sat, 12 Aug 2017 15:38:44 +0000 (17:38 +0200)]
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.

5 years agomescc: Tinycc support: struct.struct.
Jan Nieuwenhuizen [Thu, 10 Aug 2017 19:36:49 +0000 (21:36 +0200)]
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.

5 years agomescc: Fix compile warnings.
Jan Nieuwenhuizen [Thu, 10 Aug 2017 19:00:22 +0000 (21:00 +0200)]
mescc: Fix compile warnings.

* mlibc/include/stdio.h (fdputs): Declare.
* mlibc/libc-gcc.c (malloc):
  (memcpy): Fix compile warning.

5 years agomescc: Tinycc support: --*p, ++*p.
Jan Nieuwenhuizen [Thu, 10 Aug 2017 18:57:43 +0000 (20:57 +0200)]
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.

5 years agomescc: Tinycc support: word array assignment.
Jan Nieuwenhuizen [Tue, 8 Aug 2017 08:00:13 +0000 (10:00 +0200)]
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.

5 years agomescc: Tinycc support: struct char array assignment.
Jan Nieuwenhuizen [Mon, 7 Aug 2017 17:43:59 +0000 (19:43 +0200)]
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.

5 years agomescc: Tinycc support: struct assign by value.
Jan Nieuwenhuizen [Sun, 6 Aug 2017 16:49:19 +0000 (18:49 +0200)]
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.

5 years agomescc: Tinycc support: eputc.
Jan Nieuwenhuizen [Sun, 6 Aug 2017 11:53:56 +0000 (13:53 +0200)]
mescc: Tinycc support: eputc.

* mlibc/include/stdio.h (eputc): Declare.
* mlibc/libc-gcc.c (eputc):
* mlibc/libc-mes.c (eputc): New function.

5 years agomescc: Move simple main to scaffold.
Jan Nieuwenhuizen [Sun, 6 Aug 2017 11:14:09 +0000 (13:14 +0200)]
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

5 years agomescc: Tinycc support: byte and word struct fields.
Jan Nieuwenhuizen [Sun, 6 Aug 2017 10:27:16 +0000 (12:27 +0200)]
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.

5 years agomescc: Tinycc support: eputs as function for gcc.
Jan Nieuwenhuizen [Sun, 6 Aug 2017 10:16:34 +0000 (12:16 +0200)]
mescc: Tinycc support: eputs as function for gcc.

* mlibc/libc-gcc.c (eputs)[POSIX]: New function.
* mlibc/include/stdio.h (eputs)[POSIX]: Remove define.

5 years agomescc: Tinycc support: fixes for foo.bar[baz].
Jan Nieuwenhuizen [Sat, 5 Aug 2017 19:09:19 +0000 (21:09 +0200)]
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.

5 years agomescc: Tinycc support: fixes for foo->bar[baz].
Jan Nieuwenhuizen [Sat, 5 Aug 2017 17:10:00 +0000 (19:10 +0200)]
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.

5 years agomescc: Tinycc support: foo.bar[baz], foo->bar[baz] for typedef'd struct bar.
Jan Nieuwenhuizen [Sat, 5 Aug 2017 10:39:36 +0000 (12:39 +0200)]
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.

5 years agomescc: Tinycc support: foo[index]->bar for array bar.
Jan Nieuwenhuizen [Fri, 4 Aug 2017 19:45:29 +0000 (21:45 +0200)]
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.

5 years agoRevert "mescc: Tinycc support: workaround for nyacc "\0" bug."
Jan Nieuwenhuizen [Fri, 4 Aug 2017 09:45:15 +0000 (11:45 +0200)]
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

5 years agoguix: use nyacc 0.80.41.
Jan Nieuwenhuizen [Fri, 4 Aug 2017 06:59:09 +0000 (08:59 +0200)]
guix: use nyacc 0.80.41.

* guix.scm (nyacc): use 0.80.41.

5 years agomescc: Tinycc support: ((unsigned char*)str)[i].
Jan Nieuwenhuizen [Fri, 4 Aug 2017 09:40:04 +0000 (11:40 +0200)]
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.

5 years agomescc: Tinycc support: ((unsigned char*)str)[0].
Jan Nieuwenhuizen [Fri, 4 Aug 2017 09:34:01 +0000 (11:34 +0200)]
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.

5 years agomescc: Tinycc support: define __linux__.
Jan Nieuwenhuizen [Fri, 4 Aug 2017 09:33:34 +0000 (11:33 +0200)]
mescc: Tinycc support: define __linux__.

* module/language/c99/compiler.mes (c99-input->full-ast): Add
  "__linux__=1" to cpp-defs.

5 years agomescc: Tinycc support: strcat.
Jan Nieuwenhuizen [Tue, 1 Aug 2017 11:26:17 +0000 (13:26 +0200)]
mescc: Tinycc support: strcat.

* mlibc/libc-mes+tcc.c (strcat): Implement.

5 years agomescc: Tinycc support: vsnprintf.
Jan Nieuwenhuizen [Tue, 1 Aug 2017 11:24:23 +0000 (13:24 +0200)]
mescc: Tinycc support: vsnprintf.

* module/language/c99/compiler.mes (ast-type->type): Support *p++ in test.
* mlibc/libc-mes+tcc.c (vsnprintf): Implement.

5 years agomescc: Tinycc support: support foo.bar[baz], foo->bar[baz] for struct bar.
Jan Nieuwenhuizen [Tue, 1 Aug 2017 09:26:00 +0000 (11:26 +0200)]
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.

5 years agomescc: drop naive realloc.
Jan Nieuwenhuizen [Tue, 1 Aug 2017 09:08:14 +0000 (11:08 +0200)]
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.

5 years agomescc: Tinycc support: ((foo*) p) + n.
Jan Nieuwenhuizen [Mon, 31 Jul 2017 10:19:23 +0000 (12:19 +0200)]
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.

5 years agomescc: Tinycc support: field size of foo.bar[baz], foo->bar[baz].
Jan Nieuwenhuizen [Sun, 30 Jul 2017 16:04:25 +0000 (18:04 +0200)]
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.

5 years agomescc: Tinycc support: fwrite.
Jan Nieuwenhuizen [Sun, 30 Jul 2017 12:52:35 +0000 (14:52 +0200)]
mescc: Tinycc support: fwrite.

* mlibc/libc-mes+tcc.c (fwrite): Implement.