* 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.
* 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.
* 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.
* 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.
* 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.
* module/language/c99/compiler.mes (ast-strip-const): New function.
(c99-input->ast): Use it.
(type->size, type->description, ast->info): Remove const handling.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
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.
* 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.
* 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.
* 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:
* 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.
* 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.
* 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.
* 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.
* 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.
* 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].
* 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.
* 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 ().
* 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.