Commit Graph

794 Commits

Author SHA1 Message Date
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 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 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
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 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 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
Jan Nieuwenhuizen 683d5bf1d2 mescc: Tinycc support: foo.bar = foo.baz = bla.
* module/language/c99/compiler.mes (expr->base*): New function.
 (expr->accu): Use it to have value in accu for assignments.
* scaffold/tests/77-pointer-assign.c (test): Test it.
* stage0/x86.M1 (mov____%ecx,(%edx), mov___(%eax),%ecx): New define.
* module/mes/as-i386.mes (accu-mem->base->mem): New function.
  (i386:byte-base->accu-mem+n):
  (i386:byte-base->accu-mem):
  (i386:base-mem->accu-mem):
  (i386:base->accu-mem):
  (i386:value->accu-mem+n):
  (i386:value->accu-mem):
  (i386:accu->base-mem+n):
  (i386:byte-accu->base-mem):
  (i386:accu->base-mem): Rename from accu-address, base-address.
  Update callers.
* module/mes/as-i386.scm (mes): Update exports.
2017-07-28 22:45:32 +02:00
Jan Nieuwenhuizen b6375aa016 mescc: Tinycc support: workaround for nyacc "\0" bug.
* module/language/c99/compiler.mes (fix-null): Replace "\nul" with "\0".
  (initzer->data): Use it.
  (expr->global): Use it.
2017-07-28 21:39:39 +02:00
Jan Nieuwenhuizen 03eadd6fa6 mescc: Tinycc support: bugfix foo % bar.
* stage0/x86.M1 (mov____%edx,%ebx): Typo
  (idiv___%ebx): Replace div____%ebx.
* module/mes/as-i386.mes (i386:accu/base): Update.
  (i386:accu%base): Update.
2017-07-28 20:36:21 +02:00
Jan Nieuwenhuizen e102ef94ca mescc: Tinycc support: fix foo[bar]->baz.
* module/language/c99/compiler.mes (expr->accu*): Lose one indirection.
* scaffold/tests/72-typedef-struct-def.c: Test it.
2017-07-29 08:37:34 +02:00
Jan Nieuwenhuizen abd1272a31 mescc: Tinycc support: foo *bar[baz].
* module/language/c99/compiler.mes (decl->info): Support foo *bar[baz].
* module/language/c99/compiler.mes (push-global): Support push of -2,
  -1.  Change signature to take info.  Update callers.
  (push-global-address): Change signature to take info.  Update callers.
2017-07-28 18:04:39 +02:00
Jan Nieuwenhuizen 73148c6f78 mescc: Tinycc support: bugfix foo[bar] = baz, with foo*[].
* module/language/c99/compiler.mes (expr->accu): Support size for more expressions.
  (expr->pointer):
  (expr->size): Support more expressions.
* scaffold/tests/77-pointer-assign.c (add0): Test it.
2017-07-28 18:00:46 +02:00
Jan Nieuwenhuizen 17e0e0cab7 mescc: Tinycc support: bugfix *foo = bar.
* module/language/c99/compiler.mes (base->ident-address): Typo, fixes (non-char*)*x = y.
* scaffold/tests/77-pointer-assign.c (test): Test it.
2017-07-28 15:45:22 +02:00
Jan Nieuwenhuizen 2e0c1c0aff mescc: Tinycc support: bugfix *(cast)foo = bar.
* module/language/c99/compiler.mes (expr->accu): Thinko for de-ref assign.
* stage0/x86.M1: Fix typos.
* module/mes/as-i386.mes: Update for typos.
* scaffold/tests/77-pointer-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-28 15:27:25 +02:00
Jan Nieuwenhuizen c7547dfd52 mescc: Tinycc support: pointer arithmetic.
* module/language/c99/compiler.mes (ident->size, expr->size): New function.
  (expr->accu): Use them for ++,--,add, sub.
  (i386:type-alist): Set void size to 1.
* scaffold/tests/71-struct-array.c (test):
* scaffold/tests/76-pointer-arithmetic.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-07-28 10:40:30 +02:00
Jan Nieuwenhuizen ce980c8239 mescc: Tinycc support: compile tcc with TCC_IS_NATIVE.
* mlibc/include/string.h (strcat): Declare.
* mlibc/libc-mes+tcc.c (dlclose, dlopen, mprotect, sigaction,
  sigemptyset, strcat, vfprintf): Move from libc-gcc+tcc.c.
* mlibc/libc-gcc+tcc.c: Remove them.
* module/language/c99/compiler.mes (c99-input->full-ast): Define __i386__=1.
  (i386:type-alist): Parse `long long int', `unsigned short int',
  `unsigned long long int'.
  (struct-field): Support void**.
  (init-declr->name):
  (init-declr->pointer): Support function declaration.
2017-07-28 08:07:41 +02:00
Jan Nieuwenhuizen 28f056fdde mescc: bump default maximum for M1-strings to 80.
* module/mes/M1.mes (object->M1): bump default maximum for M1-strings to 80.
2017-08-26 13:40:30 +02:00
Jan Nieuwenhuizen c52b16daf5 mescc: Bugfix: output M1-strings if possible.
* module/mes/M1.mes (object->M1): Typo.  Also disallow \return in M1-strings.
2017-07-27 00:02:54 +02:00
Jan Nieuwenhuizen e1e8f03735 doc: Release udpate.
* HACKING: Update.
* INSTALL: Update.
* NEWS: Update.
* README: Update.
* doc/ANNOUNCE-0.9: New file.
* make.scm: Install it.
* guix.scm (mescc-tools): Bump to 0.2.
2017-07-26 15:57:38 +02:00
Jan Nieuwenhuizen 4b1de28449 build: Install and installed-run fixes.
* guile/mescc.scm (%datadir,%docdir,%moduledir,%version): Remove.
* scripts/mescc.mes: Likewise.
* module/language/c99/compiler.mes: Likewise.
 (%prefix): Prefer environment setting.
 (c99-input->full-ast): Remove unnecessary includes.
 Remove unnecessary defines.
* make.scm (%scm-files): Add mes/guile.scm.
 (src/mes.gcc, src/mes.mlibc-gcc, src/mes.guile):  Update  MODULEDIR,
 add -I src.
* src/mes.c (load_env): Use temporary variable for MODULEDIR concatenation.
  (bload_env): Likewise.
2017-07-26 15:57:38 +02:00
Jan Nieuwenhuizen b7cc9d375d mescc: Tinycc support: bugfix struct.array.
* module/language/c99/compiler.mes (struct-field): Update pointer
  info.
  (field:name,field:pointer,field:size,field:type): Rely on pointer
  info.
  (field:pointer): New function.
 (expr->accu): Use it.
* scaffold/tests/71-struct-array.c (test): Test it.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen d2f701b825 mescc: Tinycc support: bugfix struct pointer.
* module/language/c99/compiler.mes (decl->info): Only set non-pointer struct to -1.
* scaffold/tests/23-pointer.c (test): Test it.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 10e65b35ce mescc: Tinycc support: more function stack space.
* module/mes/as-i386.mes (function-locals): Increase local space from
  64 (16 vars) to 2*1025 + 80 (20 vars).
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 7e795763f3 mescc: Tinycc support: bugfix for char **pp = *p.
* module/language/c99/compiler.mes (ptr-declr->pointer): Grok ***.
  (decl->info): Bugfix for char **pp = *p, cleanup.
* mlibc/libc-mes.c (getenv): Update for bugfix.
* scaffold/tests/23-pointer.c (test): Test it.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen a13b2ad28c mescc: Tinycc support: function parameters.
* module/language/c99/compiler.mes (.name): Handle function parameters.
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen 97164b473d mescc: Tinycc support: jump 32.
* module/mes/as-i386.mes (i386:jump-byte-z): Use jne32 (was: jne8).
2017-07-26 11:36:45 +02:00
Jan Nieuwenhuizen ee4471058f mescc: Tinycc support: arithmetic in initializes.
* module/language/c99/compiler.mes (p-expr->number): Handle
  bitwise-or, constants.
  (initzer-data): Refactor, use p-expr->number.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen accf4159a4 mescc: Tinycc support: multi-byte [local] offsets.
* stage0/x86.M1: Add 32bit variants for all 8bit instructions.
* module/mes/as-i386.mes: Use them, switch on size.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen af626da19a mescc: Naming fix.
* stage0/x86.M1 (je8): Rename from jne8.
* module/mes/as-i386.mes (i386:jump-byte-z): Update.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen 31758dd03c mescc: Tinycc support: remove warnings for foo (void), foo (...).
* module/language/c99/compiler.mes (.name, .type): Expect foo (void), foo (...).
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen 4ec2532ad5 mescc: Tinycc support: multiple statements in default case.
* module/language/c99/compiler.mes (clause->info): Support multiple
  statements in default case.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen a7a3de05f6 mescc: Tinycc support: array[<const-expr>].
* module/language/c99/compiler.mes (p-expr->number): New function.
  (struct-field, decl->info): Use it to support const expressions in array size.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen d1a7527eaf mescc: Use "tag" for tag namespace.
* module/language/c99/compiler.mes: Use "tag" for tag namespace (WAS: "struct").
  Move enums to "tag" namespace.
2017-07-26 11:36:44 +02:00
Jan Nieuwenhuizen 2756dd9071 mescc: Tinycc support: sizeof (struct.field).
* module/language/c99/compiler.mes (expr->accu): Support sizeof (struct.field).
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 1d996c7131 mescc: Tinycc support: struct.union.
* module/language/c99/compiler.mes (struct-field): Add struct tag to
  struct/union types.
  (field-type, field-size, field-offset, field-field, ast-type->type):
  Ascertain struct tag with type.
* (expr->accu*): Do not add struct tag.
* scaffold/tests/75-struct-union.c: Test it.
* scaffold/tests/71-struct-array.c: Update.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 1c01a65d8b mescc: Tinycc support: sizeof ("foo").
* module/language/c99/compiler.mes (expr->accu): Support sizeof (string).
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen ce3233f998 mescc: Tinycc support: struct foo {int bar; int baz} = {0}.
* module/language/c99/compiler.mes (decl->info): struct foo {int bar; int baz} = {0}.
* scaffold/tests/72-typedef-struct-def.c (test):
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen dcce4bae8a mescc: Tinycc support: generalize neg.
* module/language/c99/compiler.mes (expr->accu): Generalize neg.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen fd4f4f87be mescc: Tinycc support: >>=, <<=.
* module/language/c99/compiler.mes (expr->accu): Support >>= <<=.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen b44825a035 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]).
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 3af652a4d0 mescc: Tinycc support: foo[i].bar.baz.
* module/language/c99/compiler.mes (init-declr->pointer): Use -1 for array.
 (expr->accu): Implement foo[i].bar.baz.
* scaffold/tests/72-typedef-struct-def.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 137547afa7 mescc: Tinycc support: *global =.
* module/language/c99/compiler.mes (base->ident-address):
  Support *global = ...
* scaffold/tests/74-multi-line-string.c: Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 73726b2e27 mescc: Tinycc support: anonymous union.
* module/language/c99/compiler.mes (field:name): New function.
  (decl->info): Use it.
  (struct-field): Support anonymous union.
  (field:size): Update.
  (field-field): Update.
  (field-offset): Update.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen ef4868eb13 mescc: Tinycc support: ignore [ULL], UL, LL, L.
* module/language/c99/compiler.mes (cstring->number): Drop suffix.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen eff1e97cdf mescc: Tinycc support: ~, ^=.
* module/mes/as-i386.mes (i386:accu-not): New function.
  (i386:accu-negate): Rename from i386:accu-not.
* module/mes/as-i386.scm (mes): Export them.
* module/language/c99/compiler.mes (expr->accu): Support ~, ^=.
* scaffold/tests/60-math.c (test): Test it.
* stage0/x86.M1 (not____%eax): New define.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen cccbfe4c61 mescc: Tinycc support: struct.struct.
* module/language/c99/compiler.mes (expr->accu): Support &*,
  bar.foo.i, p->foo.i, p->pf->i (*pp)->foo.i, [slightly modified] offsetof.
* scaffold/tests/72-typedef-struct-def.c (test): Test them.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen b87cd56376 mescc: Tinycc support: ***parameter.
* module/language/c99/compiler.mes (.name): Support ***parameter.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 11fb4e03dc mescc: Tinycc support: bitwise-or initializer.
* module/language/c99/compiler.mes (initzer->value): New function.
  (initzer->data): Use it to support bitwise-or initializer.
* scaffold/tests/74-multi-line-string.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 3687740b64 mescc: Tinycc support: char*[] in function.
* module/language/c99/compiler.mes (c99-input->full-ast): Add NULL.
  (decl->info): Support char* [] in function scope.
* scaffold/tests/71-struct-array.c (test) Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen e8023cd2ef mescc: Tinycc support: more list initializers.
* module/language/c99/compiler.mes (init-declr->name): Handle array,
  pointer array.
  (init-declr->pointer): Likewise.
  (decl->info): Generalize list initializers, add pointer variant.
  FIXME: AST-rewriting?
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 8ec7e1225b mescc: Tinycc support: sizeof struct field.
* module/language/c99/compiler.mes (expr->accu): Sizeof struct field.
* scaffold/tests/72-typedef-struct-def.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen d393785381 mescc: Tinycc support: sizeof typename.
* module/language/c99/compiler.mes (expr->accu): Sizeof typename.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 0fa425ed5e mescc: Tinycc support: pre/post-inc/dec more.
* module/language/c99/compiler.mes (expr-add): New function.
  (expr->pointer): New function.
  (expr->accu): Use it to support broader pre/post-inc/dec..
* scaffold/tests/72-typedef-struct-def.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 59e663021a mescc: Tinycc support: comma operator.
* module/language/c99/compiler.mes (expr->accu): Handle comma operator.
* scaffold/tests/74-multi-line-string.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 3cdfdd7407 mescc: Tinycc support: assign pointer to struct field.
* module/language/c99/compiler.mes (expr->accu, expr->accu*): Support
  pointer field selection.
* scaffold/tests/72-typedef-struct-def.c (test): Test it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 9b66421ce8 mescc: Tinycc support: multi-line strings.
* module/language/c99/compiler.mes (initzer->data, expr->global):
  Handle multi-line strings.
* scaffold/tests/74-multi-line-string.c: New file.
* make.scm (add-scaffold-test): Build it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 3ae27f52e4 mescc: Tinycc support: union.
* scaffold/tests/73-union.c: New file.
* module/language/c99/compiler.mes (union->type-entry): New
  function.
  (decl->info): Support unions.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 07ee1fbf4f mescc: Tinycc support: struct.
* scaffold/tests/72-typedef-struct-def.c: New file.
* module/language/c99/compiler.mes (decl->info): Struct support for tinycc.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 94b3c828d3 mescc: Refactor decl.
* module/mes/as-i386.mes (i386:mem->base, i386:nop): New functions.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes:
* stage0/x86.M1 (nop,mov____(%edx),%edx,movzbl_(%edx),%edx): New defines.
* scaffold/tests/23-pointer.c: New file.
* scaffold/tests/t.c: New file.
* make.scm: Build them.
* module/language/c99/compiler.mes (init-declr->name): Handle array.
  (init-declr->pointer): Likewise.
  (ident->accu): Simplify.
  (ident->base): Simplify.
  (ident-address->base): Typo.
  (expr->accu): Simplify.
  (decl->info): Simplify.
* mlibc/libc-mes.c (getenv): Remove superfluous statement.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 69e997047a mescc: Use records for Guile: <local>.
* module/language/c99/info.scm (<local>): New record.
* module/language/c99/compiler.mes (make-local-entry): Rename from
  make-local.  Update callers.
  (local-var?): Rename from local?. Update callers.
* module/language/c99/info.mes (make-local, local:type, local:pointer,
  local:id): Move from compiler.mes.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen d2650c8ebf mescc: Use records for Guile: <global>.
* module/language/c99/info.scm (<global>): New record.
* module/language/c99/compiler.mes (make-global-entry): Rename from
  make-global.  Update callers.
* module/language/c99/info.mes (make-global, global:type,
  global:pointer, global:value): Move from compiler.mes.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen c0fb6d247d mescc: Use records for Guile: <type>.
* module/language/c99/info.scm (<type>): New record.
* module/language/c99/compiler.mes (make-type-entry): Rename from
  make-type.  Update-callers.
* module/language/c99/info.mes (make-type, type:type, type:size,
  type:pointer, type:description): Move from compiler.mes.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 5d54461f67 mescc: Use records for Guile: <info>.
* module/language/c99/info.scm (<info>): Make immutable record.
  Update users.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 52b09c5f17 mescc: Use records for Guile: preparation.
* module/language/c99/info.mes: New file.
* module/mes/M1.mes: Use it.
* scripts/mescc.mes: Use it.
* module/language/c99/compiler.mes: Use it.  (<info>, <types>,
  <constants>, <functions>, <globals>, <locals>, <function>, <text>,
  <break>, <continue>, make, info?, .info, .types, .constants,
  .functions, .globals, .locals, .function, .text, .break, .continue):
  Remove.
* module/language/c99/info.scm: New file.
* module/language/c99/compiler.scm: Use it.
* guile/mescc.scm: Use it.
* module/mes/M1.scm: Use it.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 81f3fb0ecf mescc: Refactor decl.
* module/language/c99/compiler.mes (decl->info, ptr-declr->pointer):
  New function.
  (ast->info): Use decl->info.
2017-07-26 11:36:08 +02:00
Jan Nieuwenhuizen 2de207076b build: Add make install.
* guile/guix/make.scm (method-cp, install, install-target?): New functions.
* make.scm: Use them.
2017-07-26 11:36:07 +02:00
Jan Nieuwenhuizen 1bddb52c75 build: Resurrect guile-2.0. Thanks rain1!
* module/mes/guile.scm: New file.
* module/mes/elf.scm: Include it.
* module/mes/bytevectors.scm: : Include it.
* module/mes/as.scm: Include it.
* module/mes/as-i386.scm: Include it.
* module/mes/M1.scm: Include it.
* module/language/c99/compiler.scm: Include it.
* make.scm: Update.
2017-07-26 11:36:07 +02:00
Jan Nieuwenhuizen aef03ebd39 build: Use released M0 intead of M1. 2017-07-26 11:36:07 +02:00
Jan Nieuwenhuizen 637c40aeb9 mescc: Avoid warnings in recursve functions.
* module/language/c99/compiler.mes (expr->accu): Avoid warnings in recursve functions.
2017-07-09 11:01:30 +02:00
Jan Nieuwenhuizen f8865ab276 mescc: undefine __GNUC__.
* module/language/c99/compiler.mes (c99-input->full-ast): Remove
  __GNUC__=0.  Should help compiling pcc, libguile/eval.c.
2017-07-09 09:26:04 +02:00
Jan Nieuwenhuizen ebb15c72a3 mescc: Support stdarg.
* mlibc/include/stdarg.h (va_list): New type.
  (va_start, va_arg, va_end, va_copy): New macro.
  (vprintf): New declaration.
* mlibc/libc-mes.c (vprintf): New function.
  (printf): Rewrite using vprintf.
* module/language/c99/compiler.mes (expr->accu, expr->accu*): Handle
  any array.  Limitation: element size must be 4/sizeof (expression).
  (make-type): Add value pointer to type.
  (type:type, type:size, type:pointer, type:description): New functions.
  (ast->info): Handle typedef with pointer.
2017-07-05 18:48:08 +02:00
Jan Nieuwenhuizen fa4fdad623 build: Remove make.
* GNUmakefile: trivial convenience-frontend to ./make.scm
* make/*.make: Remove.
* */*.make: Remove.
2017-07-02 12:03:29 +02:00
Jan Nieuwenhuizen 83a43b81b3 mescc: Produce M1 output instead of hex2.
Use: ./make.scm [TARGET]
     ./make.scm check

* stage0/x86.M1: New file.
* mlibc/mini-libc-mes.c (exit, write): Use M1 instead of .byte.
* mlibc/libc-mes.c (_start, exit, read, write, open, access, brk,
  fsync, printf): Use M1 instead of .byte.
* module/mes/as-i386.mes: Use M1.
* module/mes/make.scm: New file.
* make.scm: New file.
* guile/guix/records.scm: New File.
* guile/guix/shell-utils.scm: New file.
* module/mes/M1.mes: Rename from hex2.mes.
* module/mes/M1.scm: Rename from hex2.scm.
* scripts/mescc.mes: Update callers.
* guile/mescc.scm: Update callers.
2017-07-02 16:25:14 +02:00
Jan Nieuwenhuizen c44df4ed8a mescc: Remove ELF creation, handled by hex2 now.
* module/language/c99/compiler.scm (make-global, global:type,
  global:pointer, global:value): Move from elf-util.mes
* module/mes/as.mes: New file.
* module/mes/as-i386.mes: Use it.
* module/mes/as-i386.scm: Use it.
* module/mes/elf-util.mes: Remove.
* module/mes/elf.mes (elf32-addr, elf32-half, elf32-off, elf32-word,
  make-elf, write-any, object->elf): Remove
  (hex2->elf): New function with dummy implementation.
* module/mes/elf.scm: Update exports.
* module/mes/hex2.mes (object->elf): New function.
* module/mes/hex2.scm: Export it.
2017-06-25 09:26:25 +02:00
Jan Nieuwenhuizen 1de0f33020 mescc: Produce object files in hex2 format, remove hex3.
* GNUmakefile (HEX2_FLAGS): New variable.
* make/mescc-guile.make ($(OUT)/$(TARGET)): Use HEX2 for linking.
* make/mescc-mes.make ($(OUT)/$(TARGET)): Likewise.
* guile/mescc.scm (main): Remove hex3 support.
* scripts/mescc.mes (main): Likewise.
* stage0/elf32-0header.hex2: New file, merging of elf32.hex and elf32-header.hex2.
* stage0/elf-0footer.hex2: New file.
* stage0/elf32-header.hex2: Rename from elf32-header-exit-42.hex2,
  repurpose as generic debug heder.
* stage0/elf32-footer-single-main.hex2: Rename from elf32-footer-exit-42.hex2,
  repurpose as generic debug footer for single-main source.
* stage0/exit-42.c: New file.
* stage0/stage0.make ($(OUT)/0exit-42): Test 0header, 0footer.
  ($(OUT)/exit-42.guile): Test generic debug header, footer.
* stage0/elf32.hex2: Remove.
2017-06-25 09:33:55 +02:00
Jan Nieuwenhuizen 77dfdd44b7 mescc: Remove jump calculation, use labels: rename jumps.
* module/mes/as-i386.mes (i386:jump, i386:jump-byte-z, i386:jump-g,
  i386:jump-ge, i386:jump-nc, i386:jump-ncz, i386:jump-nz,
  i386:jump-z): Rename from i386:jump-label*.
* module/mes/as-i386.scm (mes): Update exports.
* module/language/c99/compiler.mes (ast->info): Update callers.
2017-06-13 20:31:03 +02:00
Jan Nieuwenhuizen 5bbcce7c67 mescc: Remove jump calculation, use labels: remove offset-jumps.
* module/mes/as-i386.mes (i386:XXjump, i386:Xjump, i386:Xjump-c,
  i386:Xjump-cz, i386:Xjump-g, i386:Xjump-ge, i386:Xjump-l,
  i386:Xjump-le, i386:Xjump-nc, i386:Xjump-ncz, i386:Xjump-ncz",
  i386:Xjump-nz, i386:Xjump-z, i386:jump, i386:jump-byte-nz,
  i386:jump-byte-z, i386:jump-c, i386:jump-cz, i386:jump-le,
  i386:jump-nc, i386:jump-ncz, i386:jump-nz, i386:jump-z,
  i386:test-jump-z): Remove.
* module/mes/as-i386.scm: Remove export.
2017-06-13 20:27:40 +02:00
Jan Nieuwenhuizen bdd80babb8 mescc: Remove jump calculation, use labels: cleanup.
* module/language/c99/compiler.mes (test->jump->info): Remove.
2017-06-12 20:58:49 +02:00
Jan Nieuwenhuizen 7d7126bf0d mescc: Remove jump calculation, use labels: switch.
* module/language/c99/compiler.mes (expr->accu): Refactor (switch ...).
  (clause->info): Refactor.
2017-06-13 20:20:38 +02:00
Jan Nieuwenhuizen 36e0219af3 mescc: Remove jump calculation, use labels: and, or.
* module/language/c99/compiler.mes (expr->accu): Refactor (and
  ...), (or ...).
2017-06-12 22:11:19 +02:00
Jan Nieuwenhuizen 0a94b499fa mescc: Remove jump calculation, use labels: if.
* module/language/c99/compiler.mes (ast->info): Refactor (if ...)
  using test-jump-label->info.
2017-06-12 20:11:37 +02:00
Jan Nieuwenhuizen 4e564c3ce3 mescc: Remove jump calculation, use labels: for.
* module/language/c99/compiler.mes (ast->info): Refactor (for ...)
  using test-jump-label->info.
2017-06-12 19:46:35 +02:00
Jan Nieuwenhuizen 0f19aba1a8 mescc: Remove jump calculation, use labels: do while.
* module/language/c99/compiler.mes (ast->info): Refactor (do-while
  ...)  using test-jump-label->info.
2017-06-12 19:00:24 +02:00
Jan Nieuwenhuizen 42ca62b075 mescc: Remove jump calculation, use labels: ?.
* module/language/c99/compiler.mes (ast->info): Refactor (cond-expr
  ...)  using test-jump-label->info.
2017-06-12 18:43:25 +02:00
Jan Nieuwenhuizen 44a97b03d9 mescc: Support continue in while.
* module/language/c99/compiler.mes (make): Add continue field.
  (.continue): New function.
  (clone): Support continue field.
  (ast->info): Support continue.
* scaffold/t.c (test): Test it.
2017-06-12 17:10:29 +02:00
Jan Nieuwenhuizen 9843f88d74 mescc: Remove jump calculation, use labels: while.
* module/language/c99/compiler.mes (ast->info): Refactor (while ...)
  using test-jump-label->info.
2017-06-12 21:06:12 +02:00
Jan Nieuwenhuizen 5bf3c92938 mescc: Remove jump calculation, use labels: prepare.
* module/language/c99/compiler.mes (test-jump-label->info): New
  function.
* module/mes/as-i386.mes (i386:jump-label-z,i386:jump-label-byte-z,
  i386:jump-label-g, i386:jump-label-ge,i386:jump-label-nz): New
  functions.
* module/mes/as-i386.scm: Export them.
2017-06-12 21:00:50 +02:00
Jan Nieuwenhuizen 7cce8c6090 mescc: Remove duplication of string globals.
* module/language/c99/compiler.mes (expr->global): Curry-in globals.
  Update callers.
  (initzer->global): Likewise.
2017-06-12 10:49:31 +02:00
Jan Nieuwenhuizen d46994f2fe mescc: Unify labels.
* module/language/c99/compiler.mes: Use (#:address label) (#local
  label) (#:relative label) thoughout.
* module/mes/elf-util.mes (add-s:-prefix, drop-s:-prefix): Remove.
  (function->text): Update.
* module/mes/hex2.mes (write-hex2): Update.
2017-06-11 18:05:56 +02:00
Jan Nieuwenhuizen 1263d6e278 mescc: Write object files in hex2 or hex3 format.
* stage0/elf32.hex2: New file.
* module/mes/hex2.mes: New file.
* module/mes/hex2.scm: New file.
* module/language/c99/compiler.mes: Eradicate object lamdas.
  (current-eval, dec-xhex, function:-object->text, object->elf,
  object->objects, merge-objects, alist-add): Remove.
* module/mes/elf.mes (object->elf): New function, move from compiler.mes.
* module/mes/elf.scm: Export it.
* guile/mescc.scm (parse-opts): Add -g.
  (main): Use it.
* scripts/mescc.mes: Likewise.
* scripts/mescc-guile.make (MESCC.scm, MESLD.scm): Add -g flag.
* scripts/mescc-mes.make (MESCC.mes, MESLD.mes): Likewise.
* scaffold/m.c: Add proper includes.
* scaffold/argv.c: New file.
* scaffold/hello.c: Simplify.
* scaffold/micro-mes.c: Add proper includes.
* scaffold/t.c: Add proper includes.
2017-06-11 13:11:40 +02:00
Jan Nieuwenhuizen 4479540aed mescc: Put _start at top of mlibc.
* mlibc/libc-mes.c (_start): Move to top.
* mlibc/mini-libc-mes.c (_start): Likewise.
* module/mes/elf-util.mes (function-prefix): Update for _start == 0.
  (function-offset): Likewise.
2017-06-11 13:01:46 +02:00
Jan Nieuwenhuizen 01b4c0846b mes: Add list-index.
* module/srfi/srfi-1.scm (list-index): New function.
2017-06-11 14:45:01 +02:00
Jan Nieuwenhuizen c1d91c722d mescc: Support for non-Guix[SD] builds.
* module/language/c99/compiler.mes (c99-input->full-ast): Cater for
  C_INCLUDE_PATH not set.  Fixes non-Guix[SD] builds.
2017-06-20 19:42:37 +02:00
Jan Nieuwenhuizen 86b891ecb6 mescc: Bugfix for merging objects.
* mlibc/libc-mes.c (main): Declare.
* mlibc/mini-libc-mes.c (g_stdin): Define.
  (main): Declare.
* module/language/c99/compiler.mes (alist-add): Thinko.  Fixes merging
  objects when first declares function of next.
2017-06-05 11:42:15 +02:00
Jan Nieuwenhuizen 4d1df9cbcb mescc: move include into share/mlibc, allows installing alongside gcc.
* mlibc: Rename from libc.
* HACKING: Update for name change.
* make/bin.make: Likewise.
* make/mescc-guile.make: Likewise.
* make/mescc-mes.make: Likewise.
* scaffold/scaffold.make: Likewise.
* make/install.make: Likewise.
  (install): Install mlibc into share/mlibc.
2017-06-03 12:27:53 +02:00
Jan Nieuwenhuizen 0a07a01b29 mescc: Handle any const, by ignoring.
* module/language/c99/compiler.mes (ast-strip-const): New function.
  (c99-input->ast): Use it.
  (type->size, type->description, ast->info): Remove const handling.
2017-06-02 13:12:56 +02:00
Jan Nieuwenhuizen 6f842c6051 mescc: Support array in struct.
* module/language/c99/compiler.mes: (field:size, field-offset): New
  functions.  Update callers, use them throughout.
  (ast->info): Support declaration of struct and typedef'ed struct
  variable with array fields.
  (expr->accu, expr->accu*): Support foo.bar[baz], foo->bar[baz].
* scaffold/t-tcc.c: Test it.
2017-05-31 20:52:48 +02:00
Jan Nieuwenhuizen 9f56b8b102 core: Always include reader.c, drop binary read-0-32.mo dependency.
* module/language/c99/compiler.mes (c99-input->full-ast): Remove
  obsolete __NYACC__ and MES_FULL defines.
* src/mes.c [!MES_FULL]: Include reader-mes.h.
  (mes_builtins) [!MES_FULL]: Include reader.mes.i, reader.me.environment.i.
  [!MES_FULL]: Include reader.c.
  (main) [!MES_FULL]: By default call load_env, only call bload_env
  when --load is supplied.  WAS: Always bload read-0-32.mo.
* src/reader.c (__end_of__mes_): Remove.
  (dump): Remove option of dumping tiny test program.
* make/mescc-mes.make ($(OUT)/$(TARGET), mescc.mes-ccompile,
  mescc.mes.c-compile-E): Depend on $(OUT)/mes, scripts/mes.
* src/src.make (mes.guile): Remove module/mes/read-32-0 dependency.
  Do not build $(OUT)/mes.mes.
* module/module.make (module/mes/read-0.mo, module/mes/read-0-32.mo,
  module/mes/tiny-0-32.mo): Remove targets.
  (CLEAN): Do not add them.  Neither install $(OUT)/mes.mes.
* .gitignore: Remove exceptions for them.
* make/install.make (install): Do not install them.
* HACKING: Update info about creating module/mes/read-32-0.mo.
* scaffold/mini-mes.c: Remove.
* scaffold/tiny-mes.c: Remove.
* scaffold/cons-mes.c: Remove.
* scaffold/scaffold.make (tiny-mes.libc, tiny-mes.guile, tiny-mes.mes,
  mini-mes.libc, mini-mes.guile, mini-mes.mes): Reemove targets.
2017-05-28 16:03:45 +02:00
Jan Nieuwenhuizen f6671eaf3e mescc: Add missing builtins.
* module/language/c99/compiler.mes (i386:type-alist): Add missing
  builtins.  TODO: identify and handle unsigned.
2017-05-27 09:28:08 +02:00
Jan Nieuwenhuizen bade7d5519 mescc: Support typedef and many TCC declaration variants.
* module/language/c99/compiler.mes (ast->info): Register typedefs in types.
  (enum-def-list->constants): Support addition and substraction in
  enum field values.
  (get-type): New function.  Use throughout.
2017-05-25 07:32:29 +02:00
Jan Nieuwenhuizen 3b4e7cd8a8 mescc: Handle comments anywhere.
* module/language/c99/compiler.mes (c99-input->full-ast): Rename from c99-input->full-ast.
  (ast-strip-comment, c99-input->ast): New functions.
  (ast->info): Remove comment exceptions.
2017-05-25 19:48:26 +02:00
Jan Nieuwenhuizen 92a330ff07 mescc: Support anonymous enums.
* module/language/c99/compiler.mes (enum-def-list->constants): New function.
  (ast->info): Support anonymous enum.
2017-05-25 07:57:26 +02:00
Jan Nieuwenhuizen 6af7556d51 mescc: C99 header files and declaraions.
* libc/include/assert.h (assert_fail):
* libc/include/stdio.h:
+int eputs (char const* s);
+int fputs (char const* s);
+int puts (char const* s);
+int putchar (int c);
+int fputc (int c, int fd);
+int getchar ();
* libc/include/stdlib.h:
+char* getenv (char const* s)
+int atoi (char const *s);
+int *malloc (size_t);
+int *realloc (int *p, int size);
* libc/include/unistd.h (access):
* src/lib.c (display_helper):
* src/mes.c (read_input_file_env):
* src/posix.c: Include unistd.h.
2017-05-23 07:16:08 +02:00
Jan Nieuwenhuizen cf51f3f5bd mescc: support -E.
* guile/mescc.scm (parse-opts): Add -E.
  (source->ast): New function.
  (main): Use it.
* scripts/mescc.mes (parse-opts): Add -E.
  (source->ast): New function.
  (main): Use it.
2017-05-22 19:22:18 +02:00
Jan Nieuwenhuizen 3c880bbb56 mescc: Refactor mlibc compilation.
* libc/libc-mes.c: New file.  Contents from module/mes/libc.mes, module/mes/libc-i386.mes.
* libc/libc-gcc.c: Rename from libc/mlibc.c, include libc/mstart.c
* libc/mstart.c: Remove.
* module/mes/libc-i386.mes: Remove.
* module/mes/libc-i386.scm: Remove.
* module/mes/libc.mes: Remove.
* module/mes/libc.scm: Remove.
* GNUmakefile (CFLAGS): Include libc-gcc.c (WAS: mlibc.c).
* make/bin-mlibc.make (C_FLAGS): Remove start.c include.
* make/mescc-guile.make: Rewrite using compile, link.
* make/mescc-mes.make: Likewise.
* scaffold/m.c: Update.
2017-05-21 22:25:02 +02:00
Jan Nieuwenhuizen 2027754a59 mescc: support -c, -o.
* module/language/c99/compiler.mes: Throughout: quote lambda's.
  (current-eval): New function.
  Thanks Andy!
  (object->list): New function.  Update callers.
  (c99-input->info): Dump a.o.
  (initzer->non-const, function:object->list): New functions.
  (info:object->list): New function.
  (c99-input->elf): Call it.
* module/mes/as-i386: Throughout: quote lambda's.
* scripts/mescc.mes (main): Rewrite.
* guile/mescc.scm (main): Likewise.
2017-05-17 13:56:25 +02:00
Jan Nieuwenhuizen bdd160241b mes: Bugifx for number->string radix > 10.
* module/mes/scm.mes (number->string): Bugfix for `10' -> hex/radix > 10.
2017-05-23 06:28:37 +02:00
Jan Nieuwenhuizen 21aff4c7ad mes: Simplify read-string.
* module/mes/guile.mes (read-string): Simplify, probably fix even.
2017-05-21 12:21:07 +02:00
Jan Nieuwenhuizen 78a066ff3f mescc: Remove LALR C frontend prototype.
* module/language/c/compiler.mes: Remove.
* module/language/c/lexer.mes: Remove.
* module/language/c/parser.mes: Remove.
2017-05-21 12:38:29 +02:00
Jan Nieuwenhuizen 11311bcaa7 mes: Add negate.
* module/mes/scm.mes (negate): New function.
2017-05-21 12:33:16 +02:00
Jan Nieuwenhuizen 45ce77df85 core: Add current-output-port, open-output-file, set-current-output-port.
* libc/include/fcntl.h: Declare it.  Add some fcntl defines.
* libc/include/stdio.h: Remove fcntl defines, Declare g_stdout.
* module/language/c99/compiler.mes (c99-input->ast): Define O_WRONLY, O_RDWR.
* module/mes/guile.mes (with-output-to-file, with-output-to-port): New functions.
* src/posix.c (current_output_port, open_output_file,
  set_current_output_port): New functions.
* libc/mlibc.c (open): Add optional mode parameter.
* module/mes/libc-i386.mes (i386:open): Forward third parameter.
* scaffold/mini-mes.c (main): Init g_stdout.
* src/mes.c (main): Likewise.
2017-05-19 06:56:47 +02:00
Jan Nieuwenhuizen 44c8f26bf0 mes: Support octal numbers in reader.
* module/mes/read-0.mes (read-octal): New function.
  (read-word): Use it.
* tests/read.test: Test it.
2017-05-19 21:10:08 +02:00
Jan Nieuwenhuizen 8dc593ab18 mes: Add getopt-long.
* module/mes/getopt-long.scm: New file, imported from Guile-1.8,
* module/mes/getopt-long.mes: Include it.
* AUTHORS: Mention it.
2017-05-18 22:03:02 +02:00
Jan Nieuwenhuizen dda7a7cd62 mes: Add string-rindex.
* module/srfi/srfi-13.mes (string-rindex): New function.
2017-05-19 00:41:01 +02:00
Jan Nieuwenhuizen 20b3c349bf mes: Support predicate with string-index.
* module/srfi/srfi-13.mes (string-index): Support predicate.
2017-05-19 00:51:23 +02:00
Jan Nieuwenhuizen 8f4b64fda7 mes: Add string-suffix?
* module/mes/scm.mes (string-prefix?): Refactor.
  (string-suffix?): New function.
2017-05-19 00:23:13 +02:00
Jeremiah Orians cd5c16cf74 Purging binary blobs
* mes.mes: Remove.
* module/mes/read-0-32.mo: Remove.
2017-05-27 07:29:20 +02:00
Jan Nieuwenhuizen 7241756945 mescc: Minimal support for short.
* module/language/c99/compiler.mes (i386:type-alist): Add short.
2017-05-08 21:34:08 +02:00
Jan Nieuwenhuizen ae7a42671a mescc: Add strcpy.
* libc/include/string.h (strcpy): Declare.
* libc/mlibc.c (strcpy): New function.
* module/mes/libc.mes (strcpy): New function.
  (libc): Add it.
* scaffold/t.c (string_test): Test it.
2017-05-08 21:15:53 +02:00
Jan Nieuwenhuizen 5d0202bbf7 mescc: Enhance sizeof support.
* module/language/c99/compiler.mes (expr->accu): Support sizeof (simple-type),
  sizeof (var).
2017-05-08 21:32:32 +02:00
Jan Nieuwenhuizen ed3aa5be35 mescc: Support void return.
* module/language/c99/compiler.mes (ast-info): Support `return'.
2017-05-08 20:06:20 +02:00
Jan Nieuwenhuizen c64691797b nyacc: Unbundle.
* configure (check-version): Use keyword parameters, add #:command
  parameter.
  (main): Check for Nyacc.
* INSTALL: Mention Nyacc as dependency.
* make/guile.make (all-go): Compile in guile dir.
* module/module.make (SCM_FILES): Remove Nyacc filters.
* module/nyacc/BUGS: Remove.
* module/nyacc/ChangeLog: Remove.
* module/nyacc/README: Remove.
* module/nyacc/README.nyacc: Remove.
* module/nyacc/bison.scm: Remove.
* module/nyacc/export.scm: Remove.
* module/nyacc/import.scm: Remove.
* module/nyacc/lalr.scm: Remove.
* module/nyacc/lalr2.scm: Remove.
* module/nyacc/lang/c99/README: Remove.
* module/nyacc/lang/c99/body.scm: Remove.
* module/nyacc/lang/c99/cpp.scm: Remove.
* module/nyacc/lang/c99/cppmach.scm: Remove.
* module/nyacc/lang/c99/mach.d/c99act.scm: Remove.
* module/nyacc/lang/c99/mach.d/c99tab.scm: Remove.
* module/nyacc/lang/c99/mach.d/c99xact.scm: Remove.
* module/nyacc/lang/c99/mach.d/c99xtab.scm: Remove.
* module/nyacc/lang/c99/mach.d/cppact.scm: Remove.
* module/nyacc/lang/c99/mach.d/cpptab.scm: Remove.
* module/nyacc/lang/c99/mach.scm: Remove.
* module/nyacc/lang/c99/parser.scm: Remove.
* module/nyacc/lang/c99/pprint.scm: Remove.
* module/nyacc/lang/c99/util1.scm: Remove.
* module/nyacc/lang/c99/util2.scm: Remove.
* module/nyacc/lang/c99/xparser.scm: Remove.
* module/nyacc/lang/calc/parser.scm: Remove.
* module/nyacc/lang/util.scm: Remove.
* module/nyacc/lex.scm: Remove.
* module/nyacc/parse.scm: Remove.
* module/nyacc/util.scm: Remove.
2017-05-07 10:04:32 +02:00
Jan Nieuwenhuizen ec935e5667 mes: Consider GUILE_LOAD_PATH for include-from-path.
* module/mes/guile.scm (include-from-path): New macro.
2017-05-07 08:23:20 +02:00
Jan Nieuwenhuizen df878c59d9 mescc: Bugfixes for local char[].
* module/language/c99/compiler.mes (push-ident): Cater for local arrays.
  (expr->accu): Avoid post-inc/post-dec twice on rhs of assignment.
  Fix size lookup for local char arrayns.
2017-05-07 07:36:44 +02:00
Jan Nieuwenhuizen d1cacdc91e nyacc: Update to 0.78. 2017-05-06 22:35:46 +02:00
Jan Nieuwenhuizen 92c363701b mes: Add srfi-16 to Nyacc Guile support.
* module/mes/guile.mes: Include srfi-16 for Nyacc.
2017-05-06 22:47:45 +02:00
Jan Nieuwenhuizen c84f95beee mes: Basic support for string-index.
* module/srfi/srfi-13.mes (string-index): New function.
* tests/srfi-13.test ("string-index"): Test it.
2017-05-06 23:00:27 +02:00
Jan Nieuwenhuizen 529ab8caa1 mes: Support #\cr short form in reader.
* module/mes/read-0.mes (read-character): Support #\cr short form for #\return.
* module/mes/read-0-32.mo: Regenerate.
2017-05-06 22:49:08 +02:00
Jan Nieuwenhuizen 073f886203 mes: Support case-lambda.
* module/srfi/srfi-16.scm: New file.
* AUTHORS: Mention it.
* module/srfi/srfi-16.mes: New file.
2017-05-06 22:42:21 +02:00
Jan Nieuwenhuizen 0bc2c05dba mescc: Enhance enum support.
* module/language/c99/compiler.mes (ast->info): Support enum variable
  declaration.  Respect field value overrides.
2017-05-06 19:31:00 +02:00
Jan Nieuwenhuizen 390059a42d mescc: Support binary constants.
* module/language/c99/compiler.mes (cstring->number): Support binary 0bxxx values.
* scaffold/t.c (math_test): Test it.
2017-05-06 18:16:24 +02:00
Jan Nieuwenhuizen 2eae07de72 mescc: Support ==, != as expression value.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (expr->accu): Set accu to 0/1 for eq, ne.
* module/mes/as-i386.mes (i386:nz->accu, i386:z->accu,
  i386:accu<->stack): New functions.
* scaffold/t.c (math_test): Test it.
2017-05-06 17:30:14 +02:00
Jan Nieuwenhuizen be6e30a8fa mescc: Support &, ^.
* module/mes/as-i386.mes (i386:accu-and-base, i386:accu-xor-base): New functions.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (expr->accu): Support bitwise-and, bitwise-xor.
2017-05-06 14:57:39 +02:00
Jan Nieuwenhuizen 6272356959 mescc: Support struct pointers.
* module/language/c99/compiler.mes (expr->accu): Support
  &struct.field, struct->field.
  (ast->info): Support struct *foo = &bar;
* scaffold/t.c (struct_test): Test it.
2017-05-06 11:01:58 +02:00
Jan Nieuwenhuizen 5246de5e39 mescc: Support struct definition with variable declaration.
* module/language/c99/compiler.mes (ast->info): Support `struct foo {} bar;'.
2017-05-06 09:27:28 +02:00
Jan Nieuwenhuizen 68528219cb mescc: Support void functions.
* module/language/c99/compiler.mes (function->info): Add return if
  missing.  Fixes calling void functions (and functions where return
  is missing).
* scaffold/t.c (void_func): Test it.
2017-05-06 09:11:42 +02:00
Jan Nieuwenhuizen 6dc19bd040 mescc: Bugfix for break in switch not in compound.
* module/language/c99/compiler.mes (clause->jump-info): Rename from
  case->jump-info.
  (statements->clauses): New function.
  (ast->info): Use it.  Fixes switch statement with break in a case
  outside of a compound.
* scaffold/t.c (swits): Test it.
2017-05-06 08:39:04 +02:00
Jan Nieuwenhuizen f5372bdeff mescc: Enhance [int/pointer] array support.
* module/language/c99/compiler.mes (p-expr->type): Handle array-ref
  with any index.
  (ast->info): Support plain array declerations.
  (expr->accu): For size == 4, assume value in accu.  Fixes int/pointer arrays.
* scaffold/t.c: Test it.
2017-05-05 09:24:19 +02:00
Jan Nieuwenhuizen 03211ee91d mescc: Enhance struct support.
* module/language/c99/compiler.mes (expr->accu): Remove struct scm
  hardcoding.
  (p-expr->type): New function.
  (ast->info): Support struct variable declaration without
  initializer.  Set struct type for all struct declarations.
2017-05-04 19:39:23 +02:00
Jan Nieuwenhuizen 0077c9aed6 mescc: Fix itoa for negative numbers, using workaround.
* module/mes/libc.mes (itoa): Avoid `sign = x < 0;' FIXME, todo.
* scaffold/t.c (test): Test it.
2017-05-03 23:01:49 +02:00
Jan Nieuwenhuizen fe727301c5 mescc: Support regular C99 compile, headers + mlibc.
* libc/include/assert.h: New file.
* libc/include/ctype.h: New file.
* libc/include/errno.h: New file.
* libc/include/fcntl.h: New file.
* libc/include/limits.h: New file.
* libc/include/mlibc.h: New file.
* libc/include/stdio.h: New file.
* libc/include/stdlib: New file.
* libc/include/string.h: New file.
* libc/include/unistd.h: New file.
* libc/mlibc.c: Remove declarations.
* make/bin.make (INCLUDES): Factor out standard includes.
* make/bin-mlibc.make: New file.
* scaffold/scaffold.make: Use it.
* src/src.make: Use it.
* module/language/c99/compiler.mes (ast-info): Handle more function declarations.
* scaffold/cons-mes.c: Remove mlibc definitionsa and mlibc.c include.
  Instead include <mlibc.h>.
* scaffold/hello.c: Likewise.
* scaffold/m.c: Likewise.
* scaffold/malloc.c: Likewise.
* scaffold/micro-mes.c: Likewise.
* scaffold/mini-mes.c: Likewise.
* scaffold/t.c: Likewise.
* scaffold/tiny-mes.c: Likewise.
* src/gc.c: Likewise.
* src/lib.c: Likewise.
* src/math.c: Likewise.
* src/mes.c: Likewise.
* src/posix.c: Likewise.
* src/reader.c: Likewise.
2017-05-02 23:30:46 +02:00
Jan Nieuwenhuizen d9780e66cd mescc: Support list of initializers.
* module/language/c99/compiler.mes (ast->info): Support list of initializers.
2017-05-03 08:09:19 +02:00
Jan Nieuwenhuizen 4e0042cae6 mescc: Basic printf support.
* module/mes/libc-i386.mes (i386:va-arg): New function.
* module/mes/libc-i386.scm (mes): Export it.
* module/mes/libc.mes (printf): New function.
  (libc): Add it.
* libc/include/stdio.h: New file.
* module/language/c99/compiler.mes (c99-input->ast): Add libc/include
  to include path.
  (ast-info): Handle (skip) ellipsis in function declaration.
2017-05-02 17:00:07 +02:00
Jan Nieuwenhuizen 243d358b03 bootstrap: Regenerate.
* module/mes/read-0-32.mo: Regenerate.
2017-04-27 12:08:16 +02:00
Jan Nieuwenhuizen d9e5e2d21f doc: Release update.
* AUTHORS: Mention Nyacc and GuixSD.
* NEWS: Update.
* README: Update.
* doc/ANNOUNCE-0.5 New file.
* HACKING: Add pointers, update TODO/DONE.
2017-04-27 12:08:16 +02:00
Jan Nieuwenhuizen 26dcf7136b mescc: Parse mlibc early, show progress.
* module/mes/libc.mes (_start, strlen, getchar, assert_fail, ungetc,
  putchar, fputc, eputs, fputs, puts, strcmp, itoa, isdigit, atoi,
  malloc, realloc, strncmp, c:getenv): Change to function, add
  progress.  Update callers.
* module/language/c99/compiler.mes (c99-input->info): Compile libc separately.
* guile/mescc.scm: Update progress.
* scripts/mescc.mes: Update progress.
2017-04-24 19:09:54 +02:00
Jan Nieuwenhuizen 777fbc9d70 mescc: Avoid duplication of globals.
* module/language/c99/compiler.mes (globals:add-string): New function.
  (expr->arg): Use it to avoid globals duplication.
  (expr->accu): Do not pre-add globals.
2017-04-23 13:53:36 +02:00
Jan Nieuwenhuizen 7f3e44e361 mescc: Fix global creation in AND/OR clause.
* module/language/c99/compiler.mes (test->jump->info): Retain globals
  created in AND/OR test.
2017-04-23 13:53:08 +02:00
Jan Nieuwenhuizen e0a0a3798a core: Move some debugging to MES_DEBUG=2.
* module/mes/base-0.mes (load): Add ;;;.
* src/gc.c (gc_flip): Test on g_debug > 1.
  (gc): Likewise.
* src/mes.c (mes_builtins): Likewise.
  (main): Likewise.
* src/reader.c (dump): Likewise.
2017-04-17 23:32:02 +02:00
Jan Nieuwenhuizen 707c3a31cd mescc: Add atoi.
* libc/mlibc.c (atoi): New function.
* module/mes/libc.mes (atoi): New function.
  (libc): Add it.
2017-04-17 23:29:54 +02:00
Jan Nieuwenhuizen 996c449a81 mescc: Add getenv.
* module/mes/libc-i386.mes (i386:_start): Push environment pointer.
* module/mes/libc.mes (g_environment): New global.
  (_env): New function.
  (_start): Use it to set g_environment.
  (getenv): New function.
* lib/mlibc.c (strncmp): New function.
  (getenv): Implement.
* lib/mstart.c (_start): Set g_environment.
* module/mes/libc.mes (strncmp): New function.
  (libc): Add it.
* scaffold/t.c: (array_ref): Test it.
2017-04-17 02:24:20 +02:00
Jan Nieuwenhuizen d47f0f65c5 mescc: Support pointer arrays and some arithmetic.
* module/language/c99/compiler.mes (.name): Support **; handle type size.
  (.statements): Likewise.
  (push-local-de-ref): Likewise.
  (push-ident-de-ref): Likewise.
  (expr->arg): Likewise.
  (ident->accu):  Likewise.
  (base->ident-address):  Likewise.
  (ident-add): Likewise.
  (expr->accu):  Likewise.
  (decl->type):  Likewise.
  (formal->text):  Likewise.
  (int->global, ident-address->accu, ident-address->base): New functions.
  (ast->info): Support *, *[] ** declarations.
  (push-local-de-de-ref,  push-ident-de-de-ref): New functions.
* module/mes/as-i386.mes (i386:push-byte-local-de-ref): Rename from
  i386:push-local-de-ref.  Update callers.
  (i386:push-local-de-ref, i386:push-byte-local-de-de-ref,
  i386:accu-mem-add): New functions.
* module/mes/as-i386.scm (mes): Export them.
* scaffold/t.c (array_test): Test it.
2017-04-17 02:15:11 +02:00
Jan Nieuwenhuizen 9918ffab92 Add access?
* libc/mlibc.c (access): New function.
* module/mes/libc-i386.mes (i386:access): New function.
  (i386:libc): Add it.
* src/posix.c (access_p): New function.
* module/mes/posix.mes: New file.
* module/mes/base-0.mes (mes): Include it.
* module/mes/read-0-32.mo: Regenerate.
2017-04-16 09:51:45 +02:00
Jan Nieuwenhuizen 133772d992 bootstrap: Regenerate
* module/mes/read-0-32.mo: Regenerate.
2017-04-25 23:44:23 +02:00
Jan Nieuwenhuizen 38d30a3e42 build: Refactor.
* GNUmakefile (OUT,QUIET,SUBDIRS): New variables.
  include make/common.make
* .gitignore: Remove toplevel targets.
* build-aux/compile-all.scm: Import from GNU Guix.
* configure (gulp-pipe): Check exit status.  Actually test for CC,
  CC32.
* make/bin.make: New file.
* make/check.make: New file.
* make/clean.make: New file.
* make/common.make: New file.
* make/compile.make: New file.
* make/guile.make: New file.
* make/mescc-guile.make: New file.
* make/mescc-mes.make: New file.
* make/reset.make: New file.
* lib/mlibc.c: Rename from top.
* lib/start.c: Rename from top.
* module/module.make: New file.
* scaffold/scaffold.make: New file.
* scripts/scripts.make: New file.
* src/mes.c: Rename from top.
* src/src.make: New file.
* src/mes.c: Rename from top.
* src/gc..c: Rename from top.
* src/lib.c: Rename from top.
* src/posix.c: Rename from top.
* src/reader.c: Rename from top.
* src/vector.c: Rename from top.
* tests/tests.make: New file.
2017-04-12 21:27:59 +02:00
Jan Nieuwenhuizen 8460c4ab52 mescc: Add fsync.
* module/mes/libc-i386.mes (i386:fsync): New function.
  (i386:libc): Export it.
* mlibc.c (fsync): New function.
2017-04-15 15:13:38 +02:00
Jan Nieuwenhuizen b41e35cf6f core/mini-mes: Merge merge mes.c and mini-mes.c.
* mes.c:
* scaffold/mini-mes.c:
* gc.c:
* GNUmakefile:
2017-04-10 19:13:20 +02:00
Jan Nieuwenhuizen c4b14d66d3 mescc: Allow usage of const by ignoring.
* module/language/c99/compiler.mes (ast->info): Support const
  declarations (by ignoring them).
* lib.c (display_helper)[!__GNUC__]: Remove branch.
* posix.c (write_byte)[!__GNUC__]: Likewise.
2017-04-10 08:06:33 +02:00
Jan Nieuwenhuizen 39d334d51b mescc: Support break in while.
* module/language/c99/compiler.mes (make): Add break field.
  (.break): New function.
  (clone): Support break field.
  (ast->info): Support break.
* scaffold/t.c (test): Test it.
* scaffold/mini-mes.c (lookup_symbol_): Use it; remove goto workaround.
2017-04-10 06:59:50 +02:00
Jan Nieuwenhuizen 6009cf95fe mescc: Refactor switch.
* module/language/c99/compiler.mes (case->jump-info): Refactor.
  Support multiple case statements.
* scaffold/t.c (swits): Test it.
* lib.c (display_helper)[__NYACC__]: Remove branch.
2017-04-09 06:52:39 +02:00
Jan Nieuwenhuizen 2deca502ed mescc: Refactor assignment.
* module/language/c99/compiler.mes (expr->accu): Refactor assignment.
  Support multiple operators.
* scaffold/t.c (math_test): Test it.
* scaffold/mini-mes.c (minus, divide, modulo, multiply,
  logior)[!__GNUC__]: Remove branch.
2017-04-08 06:31:12 +02:00
Jan Nieuwenhuizen da931b4faa mescc: Factor-out array-ref.
* module/language/c99/compiler.mes: Factor-out array-ref.
2017-04-07 23:06:09 +02:00
Jan Nieuwenhuizen 1eeec4a327 mescc: Refactor expr->base.
* module/language/c99/compiler.mes (expr->base): Rename from
  expr->+base.  Use throughout.
2017-04-07 14:41:47 +02:00
Jan Nieuwenhuizen c4697b0e9d mescc: Refactor binary operators.
* module/language/c99/compiler.mes (binop->accu): Rename from
  compare->accu.  Update callers.
  (expr->accu): Use it for binary operators.
* scaffold/t.c (math_test): Test it.
2017-04-07 14:31:35 +02:00
Jan Nieuwenhuizen 68d90aa645 mescc: Factor-out append-text.
* module/language/c99/compiler.mes: Use append-text throughout.
2017-04-07 09:53:56 +02:00
Jan Nieuwenhuizen 7ccbc00047 mescc: Factor-out wrap-as.
* module/language/c99/compiler.mes (wrap-as): Rename from wrap.  Use throughout.
2017-04-07 09:36:30 +02:00
Jan Nieuwenhuizen a2b6830ecb mescc: Refactor comparisons.
* module/language/c99/compiler.mes (compare->accu, append-text, wrap):
  New functions.
  (expr->accu): Use them to implement construct like 1 == inc (0).
* scaffold/t.c (math_test): Test them.
2017-04-07 07:06:35 +02:00
Jan Nieuwenhuizen 25a02752f5 mescc: Refactor array ref.
* module/language/c99/compiler.mes (expr->accu, expr->accu*): Remove
  duplication, use expression as array index.
* scaffold/t.c (struct_test): Test it.
* vector.c (vector_length, list_to_vector)[!__GNUC__]: Remove branch.
2017-04-06 23:05:44 +02:00
Jan Nieuwenhuizen 6b4e604441 mescc: Refactor expressions.
* module/language/c99/compiler.mes (expr->accu, ast->info): Remove
  duplication, separate concerns.
2017-04-06 09:12:50 +02:00
Jan Nieuwenhuizen b13cd87700 mescc: Refactor pre/post inc/dec.
* module/language/c99/compiler.mes: Refactor pre/post inc/dec.
2017-04-05 23:05:16 +02:00
Jan Nieuwenhuizen 61a536406d bootstrap: Regenerate.
* mes-mini-mes: Regenerate.
* module/mes/read-0-32.mes: Regenerate.
2017-04-05 22:43:41 +02:00
Jan Nieuwenhuizen ab25c53e6e mescc: function call.
* module/language/c99/compiler.mes (expr->accu): Move function call
  from ast->info.
2017-04-05 20:11:13 +02:00
Jan Nieuwenhuizen c4fe8d8239 mescc: Support expression as lhs array index.
* module/language/c99/compiler.mes (expr->accu): Treat array index as expression.
* scaffold/t.c (struct_test): Test it.
* gc.c (gc_copy)[!__GNUC__]: Remove branch.
* vector.c (list_to_vector)[!__GNUC__]: Likewise.
2017-04-05 14:24:34 +02:00
Jan Nieuwenhuizen 71da0bfb78 mescc: Remove duplication.
* module/language/c99/compiler.mes (expr->arg): Use expr->accu for
  most expressions.
2017-04-04 14:37:17 +02:00
Jan Nieuwenhuizen 0f27e12672 scm: Do not quote list of strings.
* module/mes/display.mes (display): Check value of write?, fixes
  quoting display string.
2017-04-03 07:19:38 +02:00
Jan Nieuwenhuizen 56b19c76ff mescc: Do not return ELF text.
* module/language/c99/compiler.mes (info->exe): Do not return ELF text.
2017-04-03 07:09:03 +02:00
Jan Nieuwenhuizen b4a4e39050 build: Update Guix build and install.
* guix.scm (%source-dir): New variable.
  (git-file?): New function.
  (mes): Use them to simplify building/installing from git.
* make/install.make (READMES): Add INSTALL, README.
* (install): Install mescc.scm and read-0-32.mo.
2017-04-02 18:50:07 +02:00
Jan Nieuwenhuizen f9aedd1466 bootstrap: Regenerate.
* module/mes/read-0-32.mo: Regenerate.
2017-04-02 13:21:01 +02:00
Jan Nieuwenhuizen 05cae56813 core: Remove append.
* lib.c (append): Remove.
* scaffold/mini-mes.c (append): Remove.
* module/mes/base-0.mes (append): New function.
* module/mes/read-0.mo: Regenerate.
* module/mes/read-0-32.mo: Regenerate.
2017-04-02 08:05:55 +02:00
Jan Nieuwenhuizen e9ac52dfda mescc: Fix by value assignment from array-of struct entry.
* module/language/c99/compiler.mes (expr->accu): Fix by value
  assignment from array-of struct entry.
* scaffold/t.c (struct_test): Test it.
* vector.c (make_vector, list_to_vector, vector_to_list): Use it;
  remove workarounds.
* gc.c (gc_copy): Likewise.
2017-04-01 23:12:37 +02:00
Jan Nieuwenhuizen 3b527affa3 scm: Support test failure expectation.
* module/mes/test.mes (result): Take second argument to mean expected
  failure count.
2017-04-01 15:01:59 +02:00
Jan Nieuwenhuizen 08c04ff845 scm: Evaluate arguments of OR only once.
* module/mes/base.mes (or): Evaluate arguments only once.
* module/mes/read-0.mes (or): Likewise.
* tests/base.test ("or only once"): Test it.
* module/mes/read-0-32.mo: Regenerate.
2017-04-02 16:47:22 +02:00
Jan Nieuwenhuizen 232e87bd9d scm: Have char-set-contains? strictly return boolean.
* module/srfi/srfi-14.mes (char-set-contains?): Return #t rather than
  memq result.
2017-04-01 09:36:34 +02:00
Jan Nieuwenhuizen a8587b6453 scm: Fix bug in assq-set!
* module/mes/scm.mes (assq-set!): Bugfix.
2017-04-01 07:23:10 +02:00
Jan Nieuwenhuizen 4d933001d5 scm: Add c????r.
* module/mes/base-0.mes (caar, cadr, cdar, cddr, map): Remove.  Update callers.
* module/mes/base.mes (): Remove.
* module/mes/base.mes (cadadr, cddadr, cdddar): New function.
2017-04-02 09:35:47 +02:00
Jan Nieuwenhuizen 2c25f45678 scm: Add access?
* module/mes/guile.mes (access?): New dummy function.  Fixes Nyacc's #include.
2017-03-31 21:41:32 +02:00
Jan Nieuwenhuizen d938b38d5e scm: Add open-input-string, read-string.
* module/mes/guile.mes (open-input-string, read-string): New functions.
* tests/guile.test: New file.
* GNUmakefile (TESTS): Add it.
2017-04-01 12:51:35 +02:00
Jan Nieuwenhuizen fc263de433 build: Cleanup, use gcc-specific snarfing.
* .gitignore: Ignore *.o-32, mes-mini-mes.
* scripts/nyacc-calc.mes: Remove.
* scripts/nyacc.mes: Remove.
* scripts/paren.mes: Remove.
* make/install.make (install): Remove them.
p* module/mes/mes-0.mes: Remove.
* module/mes/loop-0.mes: Remove.
* build-aux/mes-snarf.scm (main): Add --mini option.
* GNUmakefile (mini-mes): Use it.
2017-04-02 17:01:22 +02:00
Jan Nieuwenhuizen b99f756367 core: Fix error message when macro is missing.
* mes.c (scm_vm_eval_check_func): New symbol.
  (eval_apply): In eval, evaluate car before evlis.  Fixes error
  message when macro match is missing in (match ... (car x)).
  (mes_symbols): Add cell_call_with_values, cell_current_module to environment.
* scaffold/mini-mes.c (eval_apply): Likewise.
2017-03-27 20:14:48 +02:00
Jan Nieuwenhuizen b45d7b599f nyacc: prefix globals. 2017-03-28 20:26:16 +02:00
Jan Nieuwenhuizen 1f1b850640 scm: Bugfix display of named characters: add port.
* module/mes/display.mes (display): Typo, add port.
2017-03-27 21:41:44 +02:00
Jan Nieuwenhuizen 4d4c793018 nyacc: Add missing (mes pmatch) include.
* module/nyacc/lang/c99/cpp.mes (mes): Include (mes pmatch).
2017-03-27 21:01:22 +02:00
Jan Nieuwenhuizen 2e007d3727 nyacc: Use pmatch rather than match for cpp.
* module/nyacc/lang/c99/cpp.scm (nyacc lang c99 cpp): Import (system
  base pmatch) rather than (ice-9 match).
  (rtokl->string): Rewrite using pmatch.
2017-04-01 12:16:09 +02:00
Jan Nieuwenhuizen 945fb39d18 scm: Bugfix drain-input.
* module/mes/guile.mes (drain-input): Bugfix: return string.
2017-03-27 21:00:49 +02:00
Jan Nieuwenhuizen a53e878435 scm: Add assoc-set!
* module/mes/scm.mes (assoc-set!): New function.
* tests/scm.test ("assoc-set!", "assoc-set! new"): New tests.
2017-03-27 07:01:15 +02:00
Jan Nieuwenhuizen 58dfe0b7bd scm: Add compose.
* module/mes/scm.mes (compose): New function.
* tests/scm.test ("compose"): New test.
2017-03-27 00:35:36 +02:00
Jan Nieuwenhuizen 22880ac831 scm: Support reading negative hex numbers.
* module/mes/read-0.mes (read-hex): Support negative hex numbers.
* tests/math.test ("#x-10"): New test.
* tests/read.test: Add test.
2017-03-27 00:11:05 +02:00
Jan Nieuwenhuizen 44755ceff2 scm: Support map4.
* module/mes/base-0.mes (map): Remove.  Update callers.
* module/mes/base.mes (map): Support map4.
2017-03-26 23:48:15 +02:00
Jan Nieuwenhuizen cf356a553c nyacc: Add simple split-cppdef for Mes.
* module/nyacc/lang/c99/body.scm: Add non-regexp split-cppdef for Mes.
2017-03-26 23:09:44 +02:00
Jan Nieuwenhuizen 6b3328c71c scm: Add with-throw-handler hack.
* module/mes/catch.mes (with-throw-handler): Add hack for Nyacc 0.75
2017-03-26 23:09:11 +02:00
Jan Nieuwenhuizen 3cbadcda86 scm: Add list->char-set.
* module/srfi/srfi-14.mes (list->char-set): New function.
* tests/srfi-14.test ("list->char-set!"): Test it.
2017-03-26 22:33:51 +02:00
Jan Nieuwenhuizen 6a816687e8 core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros.
  (mes_builtins): Add comment on .i include order.
* module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0.
* gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs
  rather than fprintf.
  (gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector.
* gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c
  implementation.
2017-03-26 15:55:12 +02:00
Jan Nieuwenhuizen 17f89b2c78 mescc: Bugfix for realloc.
* module/mes/libc.mes (realloc): Thinko.
2017-03-26 15:49:45 +02:00
Jan Nieuwenhuizen f015150cd8 mescc: Bugfix for neg.
* module/language/c99/compiler.mes (expr->accu): Fix neg.
* scaffold/t.c (math_test): Test it.
* scaffold/mini-mes.c (ash): Remove workaround.
2017-03-25 19:03:03 +01:00
Jan Nieuwenhuizen c39c04cb56 mescc: Support rshift, have guile-mini-mes pass math test.
* module/mes/as-i386.mes (i386:accu>>base): New function.
* module/mes/as-i386.scm (mes): Export it.
* module/language/c99/compiler.mes (expr->accu): Support rshift.
* scaffold/t.c (math_test): Test it.
* scaffold/mini-mes.c (ash): Use it.
2017-03-25 18:48:40 +01:00
Jan Nieuwenhuizen 30743ce141 mini-mes: Fully remove reader from core.
* scaffold/mini-mes.c (lookup_): Remove.
* mes.c: Likewise.
* reader.c (lookup_): Enable.
* mlib.c (putc): New function.
* module/mes/libc.mes (putc): New function.
2017-03-25 15:58:44 +01:00
Jan Nieuwenhuizen 040b9aedfc mescc: Support bitwise or.
* module/mes/as-i386.mes (i386:accu-or-base): New function.
* module/mes/as-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): Use it; support bitwise or.
* scaffold/t.c (math_test): Test it.
* scaffold/mini-mes.c (logior): Use it.
2017-03-24 23:15:01 +01:00
Jan Nieuwenhuizen ca633abdda mescc: Lshift support non-fixed shift value.
* module/mes/as-i386.mes (i386:accu<<base): New function.
* module/mes/as-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): Use it.
* scaffold/t.c (math_test): Test it.
2017-03-24 22:32:02 +01:00
Jan Nieuwenhuizen ce55c198c0 mescc: Use signed integer comparison.
* module/language/c99/compiler.mes (test->jump->info):
* module/mes/as-i386.mes (i386:Xjump-le, i386:Xjump-g, i386:Xjump-l,
  i386:Xjump-ge): New functions.
* module/mes/as-i386.scm: Export them.
* scaffold/t.c (math_test): Test them.
* tests/scm.test ("iota -1"): Enable for mesc.
2017-03-24 21:45:19 +01:00
Jan Nieuwenhuizen 66b53669f8 mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
  read_input_file.
  (getenv_, open_input_file, current_input_port,
  set_current_input_port force_output, exit_, values, arity_, xassq,
  is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
  (mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 21:13:01 +02:00
Jan Nieuwenhuizen 9896f9eb92 scm+test: Factor-out math and vector.
* module/mes/base-0.mes (quotient): Remove.
* module/mes/scm.mes (quotient): Add.
* tests/scm.test: Remove arithmetic/math tests.
* tests/math.test: New file.
* GNUmakefile (TESTS): Add it
2017-04-02 11:34:40 +02:00
Jan Nieuwenhuizen dbd987ab19 mescc: Have ungetc remember 2 positions.
* doc/examples/t.c (read_test): Test it.
* doc/examples/mini-mes.c:
* mlibc.c (getchar, ungetc): Support 2 ungetc positions.
* module/mes/libc.mes (getchar, ungetc): Likewise.
2017-03-23 18:57:06 +01:00
Jan Nieuwenhuizen 0685c9e7e8 mescc: Add brk, naive malloc.
* scaffold/mini-mes.c (gc_init_cells): Use malloc to init g_cells.
* scaffold/malloc.c: New file.
* GNUmakefile (malloc, guile-malloc): New targets.
* module/mes/libc-i386.mes (i386:brk): New function.
  (i386:libc): Add it.
* mlibc.c (brk): New function.
  (malloc): Use it.
  (realloc): New function.
* module/mes/libc.mes (malloc, realloc): New functions.
2017-04-02 12:31:15 +02:00
Jan Nieuwenhuizen b1d6e19eca mescc: Struct fixes.
* module/language/c99/compiler.mes (expr->arg, expr->accu, ast->info):
  Fixes for struct assignment.
2017-03-23 18:48:19 +01:00
Jan Nieuwenhuizen a7f40f71ff mescc: Add missing defines.
* module/language/c99/compiler.mes (mescc): Set STDIN, STDOUT, STDERR,
  INT_MIN, INT_MAX.
2017-03-22 07:54:45 +01:00
Jan Nieuwenhuizen 76f6fdc43e mescc: Struct by value assignment fixes.
* module/language/c99/compiler.mes (ast->info): Remove g_function
  hardcoding, fix struct assignment.
* doc/examples/t.c (struct_test): Test it.
2017-03-22 07:13:34 +01:00
Jan Nieuwenhuizen bcf1b2a356 mescc: Fix struct field comparison.
* module/language/c99/compiler.mes (expr->accu, ast->info): Some
  push/pop fixes, fixes struct field comparisons.
* doc/examples/t.c (struct_test): Test it.
2017-03-22 07:10:54 +01:00
Jan Nieuwenhuizen 9a02352a15 mescc: Run full scheme reader read-0.mes.
* lib.c (load_env)[MINI_MES]: Load full reader, module/mes/read-0.mes.
* GNUmakefile (module/mes/read-0-32.mo): Update dependency.
* module/mes/mini-0.mes: Remove.
* doc/examples/t.c (struct_test):
* module/mes/read-0-32.mo: New file: bootstrap binary reader.
2017-03-22 06:59:50 +01:00
Jan Nieuwenhuizen 98f64ae516 mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
  (test->jump->info): Add le, ge.
  (ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
  i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
  (getchar): Support it.
  (assert_fail, isdigit): New functions.
  (libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
  (getchar): Support it.
  (assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
  peek_byte read_byte unread_byte greater_p less_p): Move functions
  needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
  unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 06:39:24 +01:00
Jan Nieuwenhuizen 240f2814f4 mescc: Cleanup mini-mes build and test.
* GNUmakefile (guile-cons-mes guile-m guile-main guile-micro-mes
  guile-mini-mes guile-t guile-tiny-mes): New targets.
  (clean): Clean them.
* .gitignore: Ignore them.
* HACKING: Update.
* scaffold/tiny-mes.c (bload_env): Read module/mes/tiny-0-32.mo.
* scaffold/cons-mes.c (simple_bload_env): Likewise.
* lib.c (dump)[MES_TINY]: Write crafted dump: module/mes/tiny-0-32.mo.
  (load_env): Read module/mes/mini-0.mes.
  (bload_env): Read module/mes/read-0-32.mo.
* module/mes/mini-0.mes: New file.
* module/mes/tiny-0.mes : New file.
2017-03-19 13:41:56 +01:00
Jan Nieuwenhuizen 4e12e14b85 mescc: Refactor libc.
* GNUmakefile (mini-mes): Add include.
* mlibc.c: New file: libc bits for GNUC -nostdlib.
* mstart.c: New file: _start for GNUC -nostdlib.
* scaffold/cons-mes.c: Remove GNUC libc bits.
* scaffold/m.c: Likewise.
* scaffold/mini-mes.c: Likewise.
* scaffold/t.c: Likewise.
* scaffold/tiny-mes.c: Litkewise.
* module/language/c99/compiler.mes (libc, i386:libc): Remove.
* module/language/c99/compiler.scm
* module/mes/libc-i386.mes: Remove assembly bits.
  (_start): New function.
* module/mes/libc-i386.scm: Export it, remove assembly exports.
* module/mes/as-i386.mes: New file: assembly bits from libc-i386.mes.
* module/mes/as-i386.scm: New file: export them.
* module/mes/libc.mes (libc,_start): New functions from compiler.mes.
* module/mes/libc.scm: Export them.
2017-04-02 12:29:09 +02:00
Jan Nieuwenhuizen 124352e087 mescc: Refactor ret.
* module/mes/libc-i386.mes (i386:ret): Refactor.
* module/language/c99/compiler.mes (ast->info): Use it.
2017-03-19 10:27:18 +01:00
Jan Nieuwenhuizen a010203f0d mescc: Cache text generation.
* module/mes/elf-util.mes (functions->text): Add cache.
2017-03-18 23:00:04 +01:00
Jan Nieuwenhuizen 2397e0c8e2 mescc: Refactor function-offset.
* module/mes/elf-util.mes (function-offset): Recurse down.  Factor 5
  speedup on mini-mes.c.
2017-03-18 19:12:25 +01:00
Jan Nieuwenhuizen 4b349fabf1 mescc: Cache data-offset too.
* module/mes/elf-util.mes (data-offset): Add cache.
2017-03-18 08:58:15 +01:00
Jan Nieuwenhuizen a14c3d937a mescc: Support assignment with comparison.
* module/language/c99/compiler.mes (expr->accu): Handle assignment -> accu.
* doc/examples/t.c (test): Test it.
* doc/examples/mini-mes.c (eval_apply): Use it.
2017-03-18 08:25:15 +01:00
Jan Nieuwenhuizen 4c59078002 mescc: Support assignment test.
* module/language/c99/compiler.mes (test->jump->info): Handle assignment.
* doc/examples/t.c (test): Test it.
2017-03-18 08:17:18 +01:00
Jan Nieuwenhuizen b22eee36df mescc: Fix simple value tests.
* module/language/c99/compiler.mes (test->jump->info): Test accu
  before jumping.  Fixes simple value tests.
2017-03-17 23:49:29 +01:00
Jan Nieuwenhuizen f03a2e7500 mescc: Struct by value.
* build-aux/mes-snarf.scm (symbol->names, function->header,
  function->environment): Remove struct by value assignment
  workarounds.
* module/language/c99/compiler.mes (ast->info): Remove struct by value
  assignment debug printing.
2017-03-17 22:45:48 +01:00
Jan Nieuwenhuizen a4d65166c0 mescc: Support generic initializer.
* module/language/c99/compiler.mes (ast->info): Support generic
  declaration using initializer.  Supports struct field initializer.
* doc/examples/t.c (struct_test): Test it.
* doc/examples/mini-mes.c (call_lambda, eval_apply, write_byte,
  display_): Use it.  (call_lambda): (eval_apply,
  list_of_char_equal_p): Use it.
2017-03-17 17:54:37 +01:00
Jan Nieuwenhuizen ddd880bdc8 mescc: Remove last hardcodings for identifiers.
* module/language/c99/compiler.mes (ident->accu, ident->base):
  Use local:ptr, type->size to remove hard coding of functionx, c1.
  (expr->accu): Use type->size to remove hard coding of size byte.
  (decl->type): Also handle typename, bail out if type not found.
  (type->size): Print identifier and and bail out if type not found.
  (formal:ptr): New function.
  (formals->locals): Use it to set pointer value of parameter.  WAS: 0.
  (ast->info): Remove functionx hardcoding.
  (getchar): Rename c1 to c.
* doc/examples/t.c: Test it.
2017-03-17 17:32:23 +01:00
Jan Nieuwenhuizen cbee04c4b8 mescc: Support function call with enum value.
* doc/examples/mini-mes.c: Remove debug printing.
* module/language/c99/compiler.mes (push-global, push-local,
  push-global-address, push-local-address, push-local-de-ref): Return
  list of lambda.
  (push-ident): Support push constant.  Fixes mini-mes,
  cstring_to_list.
* doc/examples/t.c (test): Test it.
2017-03-17 08:37:45 +01:00
Jan Nieuwenhuizen a2f180ba4a mescc: Fix d-sel comparisons.
* module/language/c99/compiler.mes (ast->info): Save base while
computing accu. Fix comparison using d-sel in second argument.
* doc/examples/t.c: Test it.
* doc/examples/mini-mes.c (assq): Use it.
2017-03-14 00:15:13 +01:00
Jan Nieuwenhuizen d039b00349 mescc: Fix for character array s[0].
* module/language/c99/compiler.mes (expr->arg, expr->accu, ast->info):
  Use type size to calculate index.
* doc/examples/t.c: Test it.
* doc/examples/mini-mes.c (cstring_to_list): Simplify.
2017-03-13 19:38:38 +01:00
Jan Nieuwenhuizen 03c37b2e22 mescc: Support mini-mes running scheme program with builtins.
Mini-mes, compiled with either gcc or mescc, now runs a memory dump of
this mini-0.mes program

	(begin
	  (write-byte (make-cell 0 0 65))
	  (write-byte (make-cell 0 0 66))
          (write-byte (make-cell 0 0 67))
 	  (write-byte (make-cell 0 0 10))
	  #f)

when read and dumped by (gcc-compiled) mes-32.

* build-aux/mes-snarf.scm: FIXES ..collapse?
* module/language/c99/compiler.mes (ast->info): Bail out on unhandled
  declarations.  Was: verbosely skip.
2017-03-12 12:02:12 +01:00
Jan Nieuwenhuizen 1322d99c22 mescc: Support [for] itoa.
* module/mes/libc-i386.mes (i386:accu%base): New function.
* module/mes/libc-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): Use it to support mod.
* doc/examples/t.c (itoa): New function.
  (test): Test it.
* doc/examples/mini-mes.c (itoa)[!__GNUC__]: New function.
2017-03-12 11:05:20 +01:00
Jan Nieuwenhuizen 3268027e46 mescc: Support do .. while.
* module/language/c99/compiler.mes (ast->info): Support do-while.
* doc/examples/t.c (test): Test it.
2017-03-12 11:05:00 +01:00
Jan Nieuwenhuizen 76f1a89cef core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
  function->source, function->environment): Add workarounds to
  avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
  mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
  Add snarfable symbol/special definitions.
  (type_t): Prefix all types with `T', update users.
  (assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
  as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
  list_of_char_equal_p, lookup_macro, write_byte): New functions (from
  mes.c).
  (assq): Add debugging, workaround.
2017-03-10 20:56:18 +01:00
Matt Wette b43380c8d8 nyacc: removed start from lalr-spec -- not needed 2017-03-05 13:22:51 -08:00
Matt Wette 2f1e0e6360 nyacc: working javascript interpreter in guile 2017-03-03 17:07:29 -08:00
Matt Wette 07310be6d0 nyacc: lex fixes for char-lit 2017-03-02 16:23:44 -08:00
Matt Wette 9c4e5247c2 nyacc: cleaned up documentation 2017-03-01 18:11:40 -08:00
Matt Wette be4d33f022 nyacc: working on C99 UG as a memo 2017-02-28 17:19:48 -08:00
Matt Wette 6c536c0e9d nyacc: new release 0.76.5 2017-02-28 09:57:49 -08:00
Matt Wette 953a57b663 nyacc: fixed bug in pretty-print-c99 wrt i-sel 2017-02-28 09:53:41 -08:00
Matt Wette f7ab751dcd nyacc: merge from 0.76.4 2017-02-25 07:36:57 -08:00
Matt Wette 72b0dbe2bd nyacc: new release 0.76.4 2017-02-23 17:31:24 -08:00
Matt Wette 14d6407bc9 nyacc: new release 0.76.3 2017-02-23 05:38:49 -08:00
Matt Wette e00dc59ac0 nyacc: more bugs in cpp tokl->string 2017-02-23 05:37:25 -08:00
Matt Wette 7bb78f15b8 nyacc: new release 0.76.2 2017-02-22 17:14:07 -08:00
Matt Wette 8580e706f8 nyacc: fixed more CPP issues 2017-02-22 17:12:32 -08:00
Matt Wette f7fb6ac395 nyacc: new release 0.76.1 2017-02-22 08:26:40 -08:00
Matt Wette 2c6a6dc47d nyacc: fixed C99 CPP to deal with numbers correctly 2017-02-22 08:23:27 -08:00
Matt Wette 62154122b3 nyacc: merge master 0.76.0 2017-02-20 13:45:45 -08:00
Matt Wette 34c0f46c62 nyacc: new release 0.76.0 2017-02-19 08:28:25 -08:00
Matt Wette a301ce53df nyacc: worked c99/util2.scm udecl->mspec 2017-02-19 08:26:30 -08:00
Matt Wette 047590bd5e nyacc: new release 0.75.6 2017-02-18 17:11:12 -08:00
Matt Wette bed639f680 nyacc: fixed some c99/util2 items 2017-02-18 17:06:50 -08:00
Matt Wette 5bf49dfb54 nyacc: merged in 0.75.5 from master and inc version 2017-02-17 10:21:52 -08:00
Matt Wette 9559240282 nyacc: new release 0.75.5 2017-02-17 08:30:20 -08:00
Matt Wette 883a93ce60 nyacc: new release 0.74.4 2017-02-16 16:14:42 -08:00
Matt Wette f831edafe9 nyacc: minor cpp fixes 2017-02-16 16:12:40 -08:00
Matt Wette 5b34d2b2e7 nyacc: merge from 0.75.3 2017-02-16 11:03:11 -08:00
Matt Wette 16bf996c93 nyacc: new release 0.75.3 2017-02-16 06:26:10 -08:00
Matt Wette 2d35221753 nyacc: new release 0.75.2 2017-02-16 06:24:56 -08:00
Matt Wette 49a7200b72 nyacc: new release 0.75.1 2017-02-16 06:12:32 -08:00
Matt Wette 2b57b3dc6e nyacc: new release 0.74.0 2017-02-15 20:49:07 -08:00
Matt Wette 1ae749b25f nyacc: I think cpp is working now 2017-02-15 19:58:29 -08:00
Matt Wette 5baa7f33b1 nyacc: working cpp now, I hope 2017-02-14 19:24:59 -08:00
Matt Wette 8a821d03d6 nyacc: CPP not yet working for file mode 2017-02-12 14:29:18 -08:00
Matt Wette ea7f0b3a01 nyacc: working on cpp issues 2017-02-11 13:04:38 -08:00
Matt Wette d03ea06c84 nyacc: C99 CPP for code is better 2017-02-05 07:52:44 -08:00
Matt Wette e534225328 nyacc: starting to work on reframing 2017-01-20 14:51:55 -08:00
Matt Wette 85cb3731cc nyacc: more CPP fixes 2017-01-18 17:26:41 -08:00
Matt Wette 50fc6f6966 nyacc: redesign lang/c99/cppbocy.scm:scan-cpp-input 2017-01-17 05:50:45 -08:00
Jan Nieuwenhuizen f738d4381d mescc: Support goto in while body.
* module/language/c99/compiler.mes (ast->info): Support goto in while
  body.
* doc/examples/t.c (test): Test it.
2017-03-10 07:01:51 +01:00
Jan Nieuwenhuizen f612feec47 core+mini-mes: Move function name to struct function.
* module/language/c99/compiler.mes (expr->arg): Handle char arguments.
* doc/examples/cons-mes.c (struct function): Add name field.
* doc/examples/mini-mes.c: Likewise.
  (mes_builtins): Update.
* mes.c: Likewise.
* build-aux/mes-snarf.scm: Update.
2017-03-09 23:27:12 +01:00
Jan Nieuwenhuizen e9560e95a5 mescc: Support strings in struct initialization.
* module/mes/elf-util.mes (add-s:-prefix, drop-s:-prefix): New functions.
* module/mes/elf-util.scm: Export them.
* module/language/c99/compiler.mes (string->global): Add `s:' prefix
  to global strings.  Update users.
  (expr->arg): Update.
  (expr->accu): Handle string expressions.
  (initzer->global): New function.
  (struct-field): Handle string field.
* doc/examples/t.c: Test it.
* doc/examples/mini-mes.c: Use it.

dun!
2017-03-09 08:14:27 +01:00
Jan Nieuwenhuizen 64e73dcf29 mescc: Display sexps better.
* module/mes/elf.mes (make-elf): Only display data sections smaller
  than 200 bytes.
* doc/examples/mini-mes.c (simple_bload_env): Read mini-0-32.mes.
* doc/examples/cons-mes.c (display_): Support symbols and specials.
* doc/examples/tiny-mes.c: Likewise.
* lib.c:
* mes.c:
2017-03-07 22:33:59 +01:00
Jan Nieuwenhuizen dd52f580fb mescc: Compile all of mini-mes.
* module/language/c99/compiler.mes (case->jump-info): Support single statement.
* module/mes/elf-util.mes (function-prefix): Workaround for reversed
  functions.  FIXME!
* module/mes/elf.mes:
* scaffold/mini-mes.c (type_t): Rename FUNCTION to TFUNCTION for Nyacc.
  Add missing symbols.
  (eval_apply): Uncomment most.
* scaffold/tiny-mes.c:
* scaffold/cons-mes.c: Remove cruft.
2017-03-06 07:14:15 +01:00
Jan Nieuwenhuizen 78e70f9024 mescc: Support struct assignment.
* module/mes/libc-i386.mes (i386:base-address->accu-address,
  i386:accu+n, i386:base+n): New functions.
* module/mes/libc-i386.scm: Export them.
* module/language/c99/compiler.mes (ast->info): Use them.
* doc/examples/t.c: Test them.
* doc/examples/cons-mes.c: Drop workarounds.
* doc/examples/mini-mes.c: Likewise.
* mes.c:
2017-03-02 20:26:13 +01:00
Jan Nieuwenhuizen 08ea0da745 mescc: Fix add, sub, lshift.
* module/language/c99/compiler.mes (expr->accu): Fix add, sub, lshift.
* doc/examples/t.c: Test them.
* doc/examples/cons-mes.c:
* doc/examples/mini-mes.c:
2017-03-02 20:19:53 +01:00
Jan Nieuwenhuizen c9b251616a mescc: Support any expression as arg.
* module/language/c99/compiler.mes (expr->arg): Also push parameter,
  always return info.
  (ast->info): Loop over args.  Fixes using function calls in arguments.
* module/mes/libc-i386.mes (i386:push-arg): Remove.
  (i386:call, i386:call-accu): Remove arguments parameter.
* doc/examples/t.c: Test it.
2017-02-27 07:50:33 +01:00
Jan Nieuwenhuizen 394a3925be mescc: Rename expr->accu*.
* module/language/c99/compiler.mes (expr->accu*): Rename from expr->accuX.
2017-03-02 06:41:19 +01:00
Jan Nieuwenhuizen 07c4b02fa3 mescc: Fixes for goto.
* module/mes/libc-i386.mes (XXjump): New function.
* module/mes/libc-i386.scm: Export it.
* module/language/c99/compiler.mes (case->jump-info, ast->info): Use it.
* scaffold/t.c: Test it.
* GNUmakefile (cons-mes): New target.
* scaffold/cons-mes.c: New file.
* scaffold/mini-mes.c:
2017-04-02 12:13:04 +02:00
Jan Nieuwenhuizen 184c9f2641 mescc: Mini-mes runs (cons 0 1) dump.
* module/mes/libc-i386.mes (i386:Xjump-z, i386:Xjump-c,
  i386:Xjump-nc): New functions.
* module/mes/libc-i386.scm: Export them.
* module/language/c99/compiler.mes (case->jump-info, test-jump->info,
  ast->info): Use them.
* doc/examples/t.c: Test it.
* doc/examples/mini-mes.c: Run it.
2017-02-24 13:27:39 +01:00
Jan Nieuwenhuizen 70e4aec861 mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
  (test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
  (lambda/label->list): Add text-address parameter.  Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
  (.init): New function.
  (ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
  i386:byte-accu->base-ref, i386:accu->base-ref+n,
  i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
  i386:global-add, i386:global->accu):, i386:local-ref->accu,
  i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 15:22:39 +01:00
Jan Nieuwenhuizen 452b231645 mescc: bugfix: arg as function call.
* module/language/c99/compiler.mes (expr->arg):
2017-01-21 13:17:24 +01:00
Matt Wette e00d18b59f nyacc: new release 0.74.3 2017-01-15 08:51:21 -08:00
Matt Wette 50301b8fd7 nyacc: CPP working better now 2017-01-15 08:47:49 -08:00
Matt Wette 7e39956858 nyacc: something working 2017-01-14 15:16:28 -08:00
Matt Wette 532687f6d8 nyacc: still debugginug 2017-01-14 13:30:47 -08:00
Matt Wette bd3f15af64 nyacc: working # and ## I think, but lots of debug output too 2017-01-11 16:37:58 -08:00
Matt Wette 5652db7984 nyacc: exceptions worked on.. still need to fix # 2017-01-11 08:14:45 -08:00
Matt Wette d644043ef8 nyacc: new release 0.74.2 2017-01-10 20:10:32 -08:00
Matt Wette 91023edbf4 nyacc: fixed C99 use of 'defined XYZ' (no parens) 2017-01-10 20:06:28 -08:00
Matt Wette 09b9c41dba nyacc: merged master 2017-01-10 18:57:27 -08:00
Matt Wette cc5f5ac96f nyacc: working on fixes 2017-01-10 18:56:00 -08:00
Jan Nieuwenhuizen c210959c49 mescc: Read and display sexp dumped by mes.
* lib.c (dump)[MES_HACK]: Dump small hello-world sexp, to be handled by
* doc/examples/tiny-mes.c (display_): New function.
* module/mes/libc-i386.mes (i386:accu->base, i386:mem->accu,
  i386:mem+n->accu): New functions.
* module/mes/libc-i386.scm: Export them.
* GNUmakefile (mes-32): New target.
2017-01-10 20:05:47 +01:00
Jan Nieuwenhuizen 2bb9f2b818 mescc: Support global pointer assignments.
* module/mes/libc-i386.mes (base->accu-ref, local-ref->base): New functions.
* module/mes/libc-i386.scm: Export them.
* module/language/c99/compiler.mes (base->ident-ref, ident-ref->base):
  New functions.
2017-01-17 18:57:41 +01:00
Jan Nieuwenhuizen bf9539c565 mescc: Add data as loadable ELF section.
* module/mes/elf.mes (make-elf): Add data as loadable section too.
2017-01-17 18:48:54 +01:00
Jan Nieuwenhuizen 11f7f67a45 mescc: Support switch.
* module/language/c99/compiler.mes (case->jump-info): New function.
  (ast->info): Use it.
* doc/examples/t.c (swits): Test it.
2017-01-17 19:03:08 +01:00
Jan Nieuwenhuizen 04218971c5 mescc: Handle enums.
* module/language/c99/compiler.mes (<types>, <constants>): New slots for info.
 (make, clone): Add them.
 (.types, .constants): New accessors.
2017-01-10 22:44:01 +01:00
Jan Nieuwenhuizen 961559f32e mescc: Update for.
* module/language/c99/compiler.mes (ast->info): Rewrite for to use
  test->jump->info.
2017-01-10 20:51:29 +01:00
Jan Nieuwenhuizen 5fae0f7bff scm: Add string-delete.
* module/srfi/srfi-13.mes (string-delete): New function.
2017-01-17 18:48:28 +01:00
Jan Nieuwenhuizen c3eacb58df mescc: Support ?.
* module/language/c99/compiler.mes (ast->info): Support cond-expr.
* scaffold/t.c (test): Test it.
2017-01-10 20:27:44 +01:00
Jan Nieuwenhuizen b0e0ab014f mescc: Support open, read.
* module/mes/libc-i386.mes (i386:write): Fix comment.
  (i386:open, i386:read): New functions.
* module/mes/libc-i386.scm: Export them.
* module/language/c99/compiler.mes (i386:libc): Add them.
  (getchar, putchar): New libc functions.
  (libc): Add them.
2017-01-10 20:35:52 +01:00
Jan Nieuwenhuizen 4726a6c9ce mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
  procedure and give more debug information.
  (ref-local, ref-global): Remove.
  (push-global-ref, push-global, push-ident-ref): New functions.
  (push-ident): New function.
  (expr->arg): Use them.
  (ident->accu, ident->accu, accu->ident, value->ident, ident->base):
  Take info parameter, also handle globals.
  (ident-address->accu, ident->global, cstring->number): New functions.
  (ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
  (i386:push-global-ref): Rename from i386:ref-global.
  (i386:push-local): Rename from i386:ref-local.
  (i386:value->local): Rename from i386:local-assign.
  (i386:push-global, i386:push-local-ref, i386:value->global,
  i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 20:12:06 +01:00
Jan Nieuwenhuizen 36f9d584c5 mescc: Small ELF tweaks allowing debugging with gdb.
* module/mes/elf.mes (make-elf): Change note section to comment.  Fixes
  readelf.  Add SHF-ALLOC to .text and .data.
2017-01-09 20:06:32 +01:00
Jan Nieuwenhuizen b98a2dda6e mescc: Handle && in if and while.
* scaffold/t.c (test): Add strcmp tests.
* module/language/c99/compiler.mes (expr->arg):
  (test->jump->info): New function.
  (ast->info): Use it.
* module/mes/libc-i386.mes (i386:global->accu):
  (i386:base-mem->accu): Rename from i386:mem->accu.
  (i386:byte-base-mem->accu): Rename from i386:base-mem->accu.
  (i386:accu-not, i386:global->accu, i386:xor-accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-08 17:51:40 +01:00
Jan Nieuwenhuizen 7667fb95c0 mescc: Proper support for i++,++i,i--,--i.
* module/language/c99/compiler.mes (ast->info): Bugfix: locals.
  Add i--, --i.  Properly support i++, ++i.
* module/mes/libc-i386.mes (i386:function-locals): Support 8 local vars.
* scaffold/t.c (test): Test it.
2017-01-07 21:53:12 +01:00
Jan Nieuwenhuizen c83ef66265 mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
  (make): Add <function> slot.
  (.function): New accessor.
  (clone): Handle it.
  (function->info): Set it.
  (ast->info): Make tests generic in if, for, while.  Add goto, label,
  !, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
  (text->list): Use it.
  (functions->text, function-prefix): New function.
  (function-offset): Use it.
  (label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
  (i386:byte-base-sub): Rename from sub-byte-base.
  (i386:byte-jump-z): Rename from i386:Xjump-byte-z.
  (i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
  (i386:byte-mem->base): Rename from i386:Xmem-byte->base.
  (i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
  i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
  i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
  i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
  i386:xor-zf): New functions.
2017-04-02 12:23:00 +02:00
Jan Nieuwenhuizen 8d1e001ab2 mescc: Have micro-mes use strcmp to print help.
* doc/examples/micro-mes.c (main): Add --help.
* module/language/c99/compiler.mes (info?): New function.
  (expr->accu): Handle function call and sub.
  (ast->info): Handle if not, and, de-ref, eq, sub, return f ().
* module/mes/libc-i386.mes (i386:accu-zero?, i386:Xmem-byte->accu,
  i386:Xmem-byte->base, i386:jump-byte-nz, i386:jump-byte-z,
  i386:test-byte-base, i386:Xjump-byte-z, i386:sub-byte-base): New
  functions.
* module/mes/libc-i386.scm: Export them.
2017-01-06 00:20:05 +01:00
Jan Nieuwenhuizen 107795b13c mescc: Compile specific for loop.
* module/language/c99/compiler.mes (ast->info): Handle for, pre-inc.
* GNUmakefile (main): New target.
* doc/examples/main.c:
  (exit, write, strlen,puts)[__GNUC__]: New functions; import from micro-mes.c
  (_start): New function.
2017-01-05 21:24:56 +01:00
Jan Nieuwenhuizen 4a3e419e30 mescc: Refactor compiler.
* module/language/c99/compiler.mes (make, clone): Lightweight functional
  GOOPS-like list-based info structure.
  (make-text+globals+locals): Remove.
  (ast->info): Rename from statement->text+globals+locals, refactor.
  Update callers.
  (function->info): Rename from function->globals, refactor.  Update
  callers.
  (ast-list->info): New function.
2017-01-05 00:55:46 +01:00
Jan Nieuwenhuizen 21a6f2ca52 scm: Fix psyntax/keyword/optargs interaction bug.
* module/mes/psyntax-0.mes (self-evaluating?): Add keyword?.
* module/mes/pmatch.mes (mes): Add missing psyntax dependency.
* module/mes/optargs.scm (rest-arg->keyword-binding-list): Make error
  messages non-constant.
* tests/optargs.test ("clone <info>"): New test.
2017-01-07 01:08:29 +01:00
Jan Nieuwenhuizen 3c35f59e63 nyacc: Add cpp to c99 mes module.
* module/nyacc/lang/c99/parser.mes: Include (nyacc lang c99 cpp).
2017-01-03 22:12:12 +01:00
Jan Nieuwenhuizen f106dbfdae mescc: Rename symbols to globals.
* module/language/c99/compiler.mes:
2017-01-03 18:34:49 +01:00
Jan Nieuwenhuizen 38dc229a01 mescc: Have micro-mes use if not to segfault.
* module/language/c99/compiler.mes (write-any): Check explicitly on
  number?, report error otherwise.
  (statement->text+symbols+locals): Remove statement-offset.
  Handle compounds.  Handle very specific if.
  (function->symbols): Remove unused text-offset.
* doc/examples/micro-mes.c (main): If argc > 1 print argv1.  Fixes
  segfault :-)
* module/mes/elf-util.mes (symbols->text): Loop rather than map,
  feed text-offset.
* module/mes/libc-i386.mes (i386:local-test, i386:jump-le): New
  functions.
* module/mes/libc-i386.scm: Export them.
2017-01-03 18:22:56 +01:00
Jan Nieuwenhuizen 296449c615 mescc: Have micro-mes print argv.
* module/language/c99/compiler.mes (expr->arg): Bugfix argv: Use
  size=4 (int).
  (statement->text+symbols+locals): Bugfixes: array-ref, initialize with
  immediate, initialize with local.
  (formals->locals): Bugfix: formals counted down from -1 [WAS: down to
  -1].
* module/mes/libc-i386.mes (i386:call): Reverse args pushes to match
  formals index changes.
  (i386:write): Update for changed formals push order.
  (i386:mem->accu, i386:value->accu): New functions.
* module/mes/libc-i386.scm (mes): Export them.
* doc/examples/micro-mes.c (eputs, puts, fputs): Make identical with
  mescc's implementations.
  (main): Print argv[0] and (unconditionally; crash if not given) argv[1].
2017-01-03 12:33:34 +01:00
Jan Nieuwenhuizen 01177f7324 mescc: Have micro-mes print argc.
* module/language/c99/compiler.mes (accu->ident): New function.
  (statement->text+symbols+locals): Use it to implement initialization
  with immediate, local.
  (_start): Call main with argc,argv [WAS: 0,0].
* module/mes/libc-i386.mes (i386:push-accu, i386:accu->local): New
  functions.
* module/mes/libc-i386.scm: Export them.
* doc/examples/micro-mes.c (main): Return argc as exit status.
2017-01-03 12:52:59 +01:00
Jan Nieuwenhuizen b93d5188ea mescc: Support literal .byte in asm ().
* module/language/c99/compiler.mes (expr->arg): Handle array-ref (int
  only).
  (byte->hex, asm->hex): New functions.
  (statement->text+symbols+locals): Use it to implement asm ().
2017-01-03 12:45:47 +01:00
Jan Nieuwenhuizen ea7e3f4952 mescc: Remove data section from disassembly.
* module/mes/elf.mes (make-elf): Remove executable bit from data.
2017-01-03 12:43:00 +01:00
Jan Nieuwenhuizen 109cbdd1e7 mescc: Formals, local variables.
* module/language/c99/compiler.mes (statement->text+symbols+locals):
  Rename from statement->text+symbols.  Handle locals.
  (formals->text): Add proper function preamble.
  (formals->locals): Add formals as locals.
  (expr->accu, ident->accu, ident->base, ident-ref, global-ref): New
  functions.
  (strlen, eputs, fputs, puts): New functions.
  (libc): New variable.
  (i386:libc): Rename from libc.  Remove eputs and puts.
* module/mes/libc-i386.mes (i386:eputs, i386:puts: Remove.
  (i386:call, i386:ret): Handle locals as argument.
  (i386:function-locals, i386:function-preamble, i386:jump,
  i386:local->accu, i386:local-add, i386:local-assign,
  i386:local->base, i386:ref-global, i386:ref-local, i386:ret-local,
  i386:mem-byte->accu, i386:test-jump, i386:write): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-02 23:21:33 +01:00
Jan Nieuwenhuizen 57e11b3147 mescc: Nicer functions/parameters.
* module/mes/libc-i386.mes (eputs, exit, puts): Save stack pointer,
  fill parameter registers from stack.
* module/language/c99/compiler.mes (formal->text): Fill parameter
  registers from stack memory.
  (formals->text): Save stack pointer.
2017-01-02 07:41:56 +01:00
Jan Nieuwenhuizen eb3fed2a00 mescc: Nyacc updates, factor-out elf-util.
* module/mes/bytevectors.mes
* module/mes/elf-util.mes: New file.
* module/mes/elf.mes: Use it.
  (make-elf): Generate symbol-table string-table.
* module/mes/elf-util.scm: New file.
* module/mes/elf.scm: Use it.
* module/language/c99/compiler.mes: Include it.
* module/language/c99/compiler.scm: Include it.
* module/mes/libc-i386.mes (call, eputs, exit, puts): New functions.
* module/mes/libc-i386.scm: Export them.
2017-04-02 11:55:37 +02:00
Jan Nieuwenhuizen 7ec42c3cc7 mescc: Use Nyacc frontend.
* module/language/c99/compiler.mes: New file.
* module/language/c99/compiler.scm: Include it.
* module/mes/elf.mes: Move (mes-use-module) into cond-expand.
* module/mes/elf.scm: New file.
* module/mes/libc-i386.scm: New file.
* module/nyacc/lang/c99/parser.mes: Add missing module includes.
* module/nyacc/lang/util.mes: Add missing module include.
* scripts/mescc.mes: Use Nyacc.
* guile/mescc.scm: New file.
* GNUmakefile (guile-mescc): Run it.
2016-12-31 09:03:07 +01:00
Jan Nieuwenhuizen cd44770258 scm: Avoid xpath's shadowing of filter.
* module/sxml/xpath.scm (xpath:filter): Rename from filter.  Fixes
  shadowing of core filter.
2017-01-03 22:18:22 +01:00
Matt Wette 5e988b4ebf nyacc: fixes didn't get in in 0.74.0 2017-01-08 16:59:20 -08:00
Matt Wette c5b99d79b7 nyacc: ugh. fixes did not take, why? 2017-01-08 16:56:24 -08:00
Matt Wette 16755c68b5 nyacc: new release 0.74.0 2017-01-08 13:06:33 -08:00
Matt Wette cafdfbb0bb nyacc: minor fixes 2017-01-08 13:00:57 -08:00
Matt Wette 9c32a41370 nyacc: lots of C99/CPP fixes. now more robust for code mode 2017-01-08 12:16:28 -08:00
Matt Wette 0b46949f48 nyacc: lots of fixes to make CPP more robust; now need to test 2017-01-07 16:06:09 -08:00
Matt Wette baea80d962 nyacc: updates for cpp-ok/not-ok 2017-01-06 08:03:41 -08:00
Matt Wette 2df0f57a30 nyacc: fixed c99/CPP bug: need to skip space before lparen 2017-01-02 07:42:23 -08:00
Matt Wette 7b665385c9 nyacc: have something working for in-place include 2017-01-01 19:40:27 -08:00
Matt Wette f5d1522166 nyacc: working on cpp-include fix 2017-01-01 07:54:21 -08:00
Matt Wette 6309b99aaa nyacc: creating fixes for 0.73.0 2016-12-31 08:33:07 -08:00
Matt Wette 5251e707ab nyacc: new release 0.73.0 2016-12-25 19:34:40 -08:00
Matt Wette e589c81c8d nyacc: misc updates; see ChangeLog 2016-12-25 19:31:09 -08:00
Matt Wette 4c4706f17e nyacc: multiple fixes 2016-12-03 07:19:35 -08:00
Matt Wette 4d5102dffd nyacc: starting devel on 0.72.0 2016-08-09 05:45:52 -07:00
Jan Nieuwenhuizen 1e8d27fb7d nyacc: Move README.nyacc.
* module/nyacc/README.nyacc: Moved from README.nyacc.
2016-12-26 08:06:49 +01:00