Commit Graph

319 Commits

Author SHA1 Message Date
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 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 61e14e6e24 mini-mes: gcc: run (cons 0 1). 2017-01-18 07:38:45 +01: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 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 6ffca4bf61 mescc: Add open/read C-tests.
* scaffold/m.c: New file.
* scaffold/tiny-mes.c: New file.
* GNUmakefile (m, tiny-mes): New targets.
* scaffold/micro-mes.c: Update gcc-libc bits.
* scaffold/mini-mes.c: Likewise.
2017-04-02 12:10:38 +02: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 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 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 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 0315d42306 mini-mes: Parse with Nyacc.
* doc/examples/mini-mes.c: Parse with Nyacc.
2017-01-02 07:50:44 +01:00
Jan Nieuwenhuizen 8989dab8b0 mescc: Scaffolding of Nyacc compile experiments.
* scaffold/micro-mes.c: New file.
* scaffold/mini-mes.c: New file.
* GNUmakefile (mini-mes, micro-mes): New targets.
* .gitignore: Ignore them.
2017-04-02 12:01:33 +02:00