Commit Graph

90 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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 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 da3ccf9703 mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
  (assert_defined, check_formals, check_apply, load_env,
  bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
  math.c, mini-posix.h, posix.c.
  (greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
  logior, ash): Remove.
  (ungetchar, peekchar, peek_byte, read_byte, write_byte,
  string_to_cstring, getenv_, open_input_file, current_input_port,
  set_current_input_port, force_output): Remove.
  (mes_builtins): include mini-lib.i, mini-lib.environment.i.
  mini-math.i, mini-math.environment.i mini-posix.i,
  mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 15:01:24 +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 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 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 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 81999fbf28 mini-mes: Fix for assq.
* scaffold/mini-mes.c (assq): Use eq_p iso ==.  Fixes
  tests/display.test ("write alarm").
2017-04-02 13:18:22 +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 3f60c2ec95 core: Increase MAX_ARENA_SIZE and GC safety.
* mes.c (MAX_ARENA_SIZE): Double to 40000000.
 (GC_SAFETY): Set to 10000 cells (WAS: 1000).
* scaffold/mini-mes.c (MAX_ARENA_SIZE, GC_SAFETY): Likewise.
* gc.c (gc)[MES_DEBUG]: Also print safety area.
2017-04-01 19:10:28 +02:00
Jan Nieuwenhuizen 28fd45b7b0 core: Increase GC safety.
* mes.c (GC_SAFETY): Set to 1000 cells (WAS: 100).
* scaffold/mini-mes.c (GC_SAFETY): Likewise.
2017-04-01 16:51:48 +02:00
Jan Nieuwenhuizen 091c1ccd31 doc: Add Roamdmap.
* HACKING: Add roadmap.
2017-03-29 08:05:18 +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 408696f380 mini-mes: Debugging to stderr.
* scaffold/mini-mes.c (error, bload_env, main): Send debug info to
  stderr.

throw/catch dinges: URG
2017-03-26 22:12:24 +02:00
Jan Nieuwenhuizen 773efafd8f mini-mes: Include and enable gc.
* scaffold/mini-mes.c: Set MES_GC=1.
 (ARENA_SIZE)[MES_GC]: Reduce to 10,000 cells (WAS: 1,000,000,000
 chars).
 (g_news): New global.
 (NTYPE, NCAR, NVALUE, NLENGTH, NCDR, NVECTOR): New macros.
 (mes_symbols)[MES_GC]: Call gc_init_news.
 (mes_builtins): Include gc.i, gc.environment.i.
2017-03-26 16:03:41 +02:00
Jan Nieuwenhuizen 934260fc27 mini-mes: Workarounds for gc.c.
* gc.c (gc_copy)[!__GNUC__]: Avoid by value assignment from array-of
  struct entry.
* scaffold/mini-mes.c (gc_init_cells): Workarounds.
2017-04-01 23:30: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 ddf96c3958 mini-mes: Support vectors.
* scaffold/mini-mes.c (REF, MAKE_REF): New macro.
  Include vector.h, vector.c.
  (mes_builtins): Include vector.i, vector.environment.i.
2017-03-25 14:05:17 +01:00
Jan Nieuwenhuizen 6c6df16ca3 mini-mes: Workarounds for vector.c.
* vector.c (make_vector, vector_set_x, list_to_vector)[!__GNUC__]: Avoid
  by value assignment from array-of struct entry.
2017-03-25 17:15:07 +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 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 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 efc02d9746 mini-mes: Update display_.
* doc/examples/mini-mes.c (display_): Add separator, nicer recursion.
* mes.c (display_): Update.
2017-03-22 07:09:58 +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