Commit graph

213 commits

Author SHA1 Message Date
Jan Nieuwenhuizen e8969af4ca
mescc: Tinycc support: sizeof: Bugfix for c-array.
* module/language/c99/compiler.mes (->size): Bugfix for c-array.
* scaffold/tests/85-sizeof.c: Test it.
2018-05-12 11:25:35 +02:00
Jan Nieuwenhuizen ad9f171c49
mescc: Tinycc support: Implement ((struct foo*)p)->bar.
* module/language/c99/compiler.mes (expr->accu*):
* scaffold/tests/7p-struct-cast.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-05-12 00:20:51 +02:00
Jan Nieuwenhuizen 057607ca0a
mescc: Tinycc support: Implement (foo--)->bar and permutations.
* module/language/c99/info.scm (clone): Add post field.
  (make): Handle post parameter.
* module/language/c99/compiler.mes (clone): Handle post parameter.
  (expr->accu*): Set it to support foo--/foo--.
  (expr->accu): Read it to support foo--/foo--.
* scaffold/tests/7o-struct-pre-post.c: Test it.
* build-aux/check-mescc.sh: Run it.
2018-05-13 13:50:32 +02:00
Jan Nieuwenhuizen ec13ccc19f
mescc: Tinycc support: Function variables. 2018-05-11 18:53:54 +02:00
Jan Nieuwenhuizen 8cc406c9ff
mescc: Tinycc support: Pointer typedefs. 2018-05-11 18:36:35 +02:00
Jan Nieuwenhuizen b42ecbd928
mescc: Tinycc support: Array typedefs. 2018-05-11 18:26:01 +02:00
Jan Nieuwenhuizen 6bcc9a91e3
mescc: Tinycc support: Sizeof struct destruct. 2018-05-11 17:13:07 +02:00
Jan Nieuwenhuizen 07e73b8f9a
mescc: Tinycc support: Anonymous union initialization. 2018-05-11 15:52:30 +02:00
Jan Nieuwenhuizen e3a8316184
mescc: Tinycc support: Fix for ?-operator. 2018-05-11 15:13:55 +02:00
Jan Nieuwenhuizen 70cb56025f
mescc: Tinycc support: Valued function assign. 2018-05-11 13:34:45 +02:00
Jan Nieuwenhuizen a1862f749f
mescc: Refactor type system: WIP
* module/language/c99/compiler.mes (): WIP
* module/language/c99/info.scm (): WIP
2018-05-10 12:40:07 +02:00
Jan Nieuwenhuizen b75dd7eca2
mescc: Refactor type system: introduce <array>, <pointer>, <var>.
* module/language/c99/info.scm (<array>, <pointer>, <var>): New type.
* module/language/c99/compiler.mes (ast-><type>): New function.
  (ast-type): Use it.
2018-05-09 21:31:23 +02:00
Jan Nieuwenhuizen c9ba7a619b
mescc: Refactor variable declaration.
* module/language/c99/compiler.mes (decl->info): Refactor.
2018-05-05 12:30:06 +02:00
Jan Nieuwenhuizen 1b8d59fd0f
mescc: Handle sizeof expression.
* module/language/c99/compiler.mes (expr->accu): Handle sizeof
  expression.
* scaffold/tests/85-sizeof.c: Test it.
2018-05-05 00:59:31 +02:00
Jan Nieuwenhuizen 2311b8bd20
mescc: Handle struct field lists.
* module/language/c99/compiler.mes (struct-field): Return list of
  fields.  Update callers.
* scaffold/tests/84-struct-field-list.c: Test it.
* build-aux/check-mescc.sh (tests): Add it.
2018-05-05 00:14:47 +02:00
Jan Nieuwenhuizen 13edbaf4d8
mescc: Support heterogeneous variable init.
* module/language/c99/compiler.mes (decl->info): Support heterogeneous
  variable init.
* scaffold/tests/83-heterogenoous-init.c: Test it.
* build-aux/check-mescc.sh (tests): Add it.
2018-05-04 22:38:01 +02:00
Jan Nieuwenhuizen 5fba6d1a70
mescc: Handle (Skip) global static.
* module/language/c99/compiler.mes (decl->info): Handle (Skip) global
  static.
* scaffold/tests/48-global-static.c: Test it.
2018-05-04 20:40:04 +02:00
Jan Nieuwenhuizen e53f55f002
mescc: Support functions in expression.
* module/language/c99/info.scm (<function>): New type.
* module/language/c99/compiler.mes (ast->type): Support function.
  (expr->type-size): Likewise.
  (expr->type): Likewise.
  (expr->accu*): Likewise.
  (function->info): Create <function>.
* module/mes/M1.mes (object->M1): Grok <function>.
* scaffold/tests/47-function-expression.c: Test it.
* build-aux/check-mescc.sh: Add it.
2018-05-04 13:58:27 +02:00
Jan Nieuwenhuizen be60b3e49b
mescc: Support function-static variables.
* module/language/c99/info.scm (make): Add statics field.
  (<global>): Add name and function fields.  Update callers.
  (global->string): New function.
* module/mes/M1.mes (object->M1): Update.
* module/language/c99/compiler.mes (clone): Add statics field.
  (ident->accu): For <global>, use global in text (WAS: name).
  (ident-address->accu): Likewise.
  (ident-address->base): Likewise.
  (decl-local->info): New function.
  (decl->info): New function.
  (ast->info): Use them.
  (function->info): Keep globals in object (WAS: global:value only).
* scaffold/tests/46-function-static.c: Test it.
2018-05-04 20:45:27 +02:00
Jan Nieuwenhuizen 7b476693c2
core: Have core:eval expand macros.
* src/mes.c (core:eval-expand): Remove
  (core:eval-expanded): New variable.
  (eval_apply): Have core:eval expand macros; core:eval-expanded evals
  expanded sexps.
2018-04-28 18:31:10 +02:00
Jan Nieuwenhuizen 1400489a94
Revert "core: Remove pmatch-car, pmatch-cdr hack."
This reverts commit be1e84624ea4a158173f34af923e3c4a3793412a.
2018-04-29 07:46:40 +02:00
Jan Nieuwenhuizen c03449ac5a
core: Remove pmatch-car, pmatch-cdr hack.
* src/mes.c (scm_vm_eval_pmatch_car, scm_vm_eval_pmatch_cdr): Remove
  (eval_apply): Remove cell_vm_eval_pmatch_car,
  cell_vm_eval_pmatch_cdr hack.
  (mes_symbols): Remove cell_symbol_pmatch_car, cell_symbol_pmatch_cdr.
* scaffold/mini-mes.c: Likewise.
* module/mes/guile.scm (mes): Remove pmatch-car, pmatch-cdr.
* module/mes/pmatch.scm (ppat): Use plain car, cdr.
2018-04-28 12:19:40 +02:00
Jan Nieuwenhuizen 99718a8b7a
core: Fixes for int-max, int-min.
* src/math.c (greater_p): Fix INT_MAX > 0.
  (less_p): Fix INT_MIN < 0.
* tests/math.test ("< INT-MIN"): Test it.
  ("< INT-MAX"):
  ("> INT-MAX"):
  ("> INT-MAX 0"):
  ("> INT-MIN"):
* tests/srfi-13.test ("string->number INT-MAX"): Test it.
  ("string->number INT-MIN"):
  ("number->string INT-MAX"):
  ("number->string INT-MIN"):
* scaffold/tests/60-math.c (test): Test it.
2018-05-02 23:11:27 +02:00
Jan Nieuwenhuizen 98417537a2
test: enable all tests, use expect count, add tinycc tests.
* build-aux/check-mescc.sh (tests): Add tinycc tests.
* build-aux/diff.scm: Naive diff for tinycc tests.
* build-aux/test.sh: Run diff when .expect found.
2018-05-01 16:50:29 +02:00
Jan Nieuwenhuizen a937d18c38
build: Simplify, drop make.scm experiment.
* build.sh: Rewrite.
* build-aux/build-cc.sh: New file.
* build-aux/build-mes.sh: New file.
* build-aux/build-mlibc.sh: New file.
* build-aux/cc.sh: New file.
* build-aux/cc-mes.sh: New file.
* build-aux/cc-mlibc.sh: New file.
* install.sh: Update.
* make.scm: Remove.
* guile/guix/make.scm: Remove.
* guile/guix/records.scm: Remove.
* guile/guix/shell-utilsg.scm: Remove.
2018-04-29 18:38:57 +02:00
Jan Nieuwenhuizen 8911af4aa8
core: Use single definition rule for cell-type.
* src/mes.c (scm_type_char, scm_type_closure, scm_type_continuation,
  scm_type_function, scm_type_keyword, scm_type_macro,
  scm_type_number, scm_type_pair, scm_type_ref, scm_type_special,
  scm_type_string, scm_type_symbol, scm_type_values,
  scm_type_variable, scm_type_vector): New symbol.
  (mes_symbols): Add them.
* module/mes/type-0.mes (<cell:char>, <cell:char>, <cell:closure>,
  <cell:continuation>, <cell:function>, <cell:keyword>, <cell:macro>,
  <cell:number>, <cell:pair>, <cell:ref>, <cell:special>,
  <cell:string>, <cell:symbol>, <cell:values>, <cell:variable>,
  <cell:vector>, <cell:broken-heart): Remove.
* module/mes/boot-0.scm: Likewise.
* module/mes/boot-01.scm: Likewise.
* module/mes/boot-02.scm: Likewise.
* scaffold/boot/20-define-quote.scm: Likewise.
* scaffold/boot/37-closure-lambda.scm: Likewise.
* scaffold/boot/38-simple-format.scm: Likewise.
* scaffold/boot/4c-quasiquote.scm:
* scaffold/boot/4e-string-split.scm: Likewise.
* scaffold/boot/51-module.scm: Likewise.
* scaffold/boot/52-define-module.scm: Likewise.
* scaffold/boot/60-let-syntax.scm: Likewise.
* module/mes/guile.scm: Add some of them.
2018-04-29 13:22:02 +02:00
Jan Nieuwenhuizen 75444afc21
core: Compile minimal mes with MES_MINI=1.
* src/mes.c: Compile minimal mes with MES_MINI=1.
2018-04-10 21:43:19 +02:00
Jan Nieuwenhuizen 6be49a294b
core: display_helper: Display escaped characters.
* src/lib.c (display_helper): Display escaped characters.
2018-04-21 23:58:28 +02:00
Jan Nieuwenhuizen b65e57be31
core: Tune debug printing.
* src/mes.c: Tune debug printing.
* src/gc.c: Likewise.
* module/mes/guile.mes: Likewise.
* HACKING: Describe it.
2018-04-09 07:12:38 +02:00
Jan Nieuwenhuizen ad135d3752 doc: Release udpate.
* HACKING: Update.
* INSTALL: Update.
* NEWS: Update.
* README: Update.
* doc/ANNOUNCE-0.12: New file.
* throughout: (janneke) coming out.
2017-11-21 19:22:26 +01:00
Jan Nieuwenhuizen bd82d5988d core: Add setenv.
* lib/libc.c (setenv): New function.
* include/stdlib.h (setenv): Declare it.
* scaffold/tests/61-array.c (test): Test it.
2018-04-07 09:21:51 +02:00
Jan Nieuwenhuizen 9fc27ee25a mes: Single environment lookup for variables, SICP chapter 3.
* src/mes.c (t): Add TVARIABLE.
  (scm_vm_eval_deref): New vm special.
  (make_vref_): New internal function.
  (eval_apply): WIP: replace symbols with their variable reference.
* src/gc.c (gc_loop): Handle TVARIABLE.
* src/lib.c (display_helper): Handle TVARIABLE.
* module/mes/type-0.mes (<cell:variable>): New variable.
  (cell:type-alist): Add it.
  (variable?): New function.
* module/mes/display.mes (display): Handle <variable>.
2017-12-09 08:33:50 +01:00
Jan Nieuwenhuizen 9c8e2dbd9f mes: Add incremental test suite.
* check-boot.sh: New file.
* check.sh: Invoke it.
* module/srfi/srfi-16.mes: New file.
* scaffold/boot/00-zero.scm: New file.
* scaffold/boot/01-true.scm: New file.
* scaffold/boot/02-symbol.scm: New file.
* scaffold/boot/03-string.scm: New file.
* scaffold/boot/04-cons.scm: New file.
* scaffold/boot/04-quote.scm: New file.
* scaffold/boot/05-list.scm: New file.
* scaffold/boot/06-tick.scm: New file.
* scaffold/boot/07-if.scm: New file.
* scaffold/boot/08-if-if.scm: New file.
* scaffold/boot/10-cons.scm: New file.
* scaffold/boot/11-list.scm: New file.
* scaffold/boot/12-car.scm: New file.
* scaffold/boot/13-cdr.scm: New file.
* scaffold/boot/14-exit.scm: New file.
* scaffold/boot/15-display.scm: New file.
* scaffold/boot/16-if-eq-quote.scm: New file.
* scaffold/boot/20-define-quote.scm: New file.
* scaffold/boot/20-define-quoted.scm: New file.
* scaffold/boot/20-define.scm: New file.
* scaffold/boot/21-define-procedure.scm: New file.
* scaffold/boot/22-define-procedure-2.scm: New file.
* scaffold/boot/23-begin.scm: New file.
* scaffold/boot/24-begin-define.scm: New file.
* scaffold/boot/25-begin-define-2.scm: New file.
* scaffold/boot/26-begin-define-later.scm: New file.
* scaffold/boot/26-define-define.scm: New file.
* scaffold/boot/27-lambda-define.scm: New file.
* scaffold/boot/28-define-define.scm: New file.
* scaffold/boot/29-lambda-define.scm: New file.
* scaffold/boot/2a-lambda-lambda.scm: New file.
* scaffold/boot/2b-define-lambda.scm: New file.
* scaffold/boot/2c-define-lambda-recurse.scm: New file.
* scaffold/boot/2d-define-lambda-set.scm: New file.
* scaffold/boot/2e-define-second.scm: New file.
* scaffold/boot/30-capture.scm: New file.
* scaffold/boot/31-capture-define.scm: New file.
* scaffold/boot/32-capture-modify-close.scm: New file.
* scaffold/boot/33-procedure-override-close.scm: New file.
* scaffold/boot/34-cdr-override-close.scm: New file.
* scaffold/boot/35-closure-modify.scm: New file.
* scaffold/boot/36-closure-override.scm: New file.
* scaffold/boot/37-closure-lambda.scm: New file.
* scaffold/boot/38-simple-format.scm: New file.
* scaffold/boot/40-define-macro.scm: New file.
* scaffold/boot/41-when.scm: New file.
* scaffold/boot/42-if-when.scm: New file.
* scaffold/boot/43-or.scm: New file.
* scaffold/boot/44-or-if.scm: New file.
* scaffold/boot/45-pass-if.scm: New file.
* scaffold/boot/46-report.scm: New file.
* scaffold/boot/47-pass-if-eq.scm: New file.
* scaffold/boot/48-let.scm: New file.
* scaffold/boot/49-macro-override.scm: New file.
* scaffold/boot/4a-define-macro-define-macro.scm: New file.
* scaffold/boot/4b-define-macro-define.scm: New file.
* scaffold/boot/4c-quasiquote.scm: New file.
* scaffold/boot/50-primitive-load.scm: New file.
* scaffold/boot/51-module.scm: New file.
* scaffold/boot/52-define-module.scm: New file.
* scaffold/boot/53-closure-display.scm: New file.
* scaffold/boot/60-let-syntax.scm: New file.
* scaffold/boot/closure.scm: New file.
* scaffold/boot/compose.scm: New file.
* scaffold/boot/data/bar.mes: New file.
* scaffold/boot/data/i.scm: New file.
* scaffold/boot/data/module.mes: New file.
* scaffold/boot/foo.scm: New file.
* scaffold/boot/lambda-star.scm: New file.
* scaffold/boot/vector.scm: New file.
* tests/boot.test: New file.
* tests/boot.test-guile: New file.
* tests/srfi-16.test: New file.
* tests/srfi-16.test-guile: New file.
2018-01-25 06:58:44 +01:00
Jan Nieuwenhuizen 71906fb735 mescc: M4 support: scaffold/tests/82-define.c.
* scaffold/tests/82-define.c: New file; inspired by M4.  Thanks, Ricardo!
* make.scm ("82-define"): Build it.
* check-mescc.sh: Add 82-define.
2017-12-04 23:19:32 +01:00
Jan Nieuwenhuizen 05c33b052a mlibc: Tinycc support: qsort.
* lib/libc+tcc.c (qswap, qpart): New function
  (qsort): Implement.
* scaffold/tests/81-qsort.c: Test it.
* make.scm ("81-qsort"): Build it.
2017-12-04 19:01:39 +01:00
Jan Nieuwenhuizen 8b5e1dde3c mescc: scaffold: misc cleanups.
* scaffold/tests/44-switch.c (swits): More case labels.
* scaffold/tests/60-math.c: Discriminate return values.
* scaffold/tests/77-pointer-assign.c (memset)[__TINYC__]: Remove.
* scaffold/tests/79-int-array.c (test): Discriminate return values.
2017-12-03 23:03:09 +01:00
Jan Nieuwenhuizen 808af5001f mlibc: New library layout; remove duplication.
* lib/libc+tcc-gcc.c: New file: Libc bits for GCC from libc-mes+tcc.c.
* lib/libc+tcc-mes.c: New file: Libc bits for MesCC from libc-mes+tcc.c.
* lib/libc+tcc.c: New file: Libc bits from libc-mes+tcc.c.
* lib/libc.c: New file: Merged from libc-mes.c, libc-gcc.c.
  (abtoi): New function: Rename from _atoi.
* lib/linux+tcc-gcc.c: New file:  Linux bits from libc-gcc+tcc.c.
* lib/linux+tcc-mes.c: New file: Linux bits from libc-mes+tcc.c.
* lib/linux-gcc.c: New file: Linux bits from libc-gcc.c.
* lib/linux-mes.c: New file: Linux bits from libc-mes.c.
* lib/mini-libc-gcc.c: New file.
* lib/mini-libc.c: New file: Libc bits from mini-libc-mes.c.
* lib/mini-linux-gcc.c: New file.
* lib/mini-linux-mes.c: New file: Linux bits from mini-libc-mes.c.
* lib/libc-gcc.c: Remove duplication using include now.
* lib/libc-mes.c: Likewise.
* lib/mini-libc-mes.c: Likewise.
* include/stdio.h (puts)[POSIX]: Remomve macro.
  (fputc, fputs)[!POSIX]: New macro.
  (fputc, fputs): Remove declaration.
* scaffold/tests/7j-strtoull.c (strtoull, test): Use abtoi.
* src/lib.c (fputs)[__MESC__]: Remove define.
* guile/guix/make.scm: Update for new library layout.
* make.scm: Likewise.
* build.sh: Likewise.
* install.sh: Likewise.
2017-12-03 13:56:21 +01:00
Jan Nieuwenhuizen 74c4197467 mescc: Mescc-tools support: char foo[BAR] = {'a', 'b', 'c'}.
* stage0/x86.M1 (mov____%al,0x8(%ebp), mov____%al,0x32(%ebp),
  mov____%ax,0x8(%ebp), mov____%ax,0x32(%ebp)): New define.
* module/mes/as-i386.mes (i386:accu->local+n,i386:byte-accu->local+n,
  i386:word-accu->local+n): New function.
* module/language/c99/compiler.mes (accu->local+n): New function.
  (initzer->data): Return char as single byte.
  (decl->info): Support char foo[BAR] = {'a', 'b', 'c'}.
* scaffold/tests/66-local-char-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-11-27 19:51:18 +01:00
Jan Nieuwenhuizen e8884d83e1 mlibc: GNU Gcc support: setjmp, longjmp.
* stage0/x86.M1 (jmp____*%ebx): New macro.
  (mov____0x8(%ebp),%ebp): New macro.
  (mov____0x8(%ebp),%esp): New macro.
* include/setjmp.h (jmp_buf): Redefine as struct.
* lib/libc-mes+tcc.c (longjmp, setjmp): Implement.
* scaffold/tests/80-setjmp.c: Test it.
* make.scm ("80-setjmp"): Build it.
* .gitignore: Ignore *.tcc-guile.
2017-11-26 13:10:46 +01:00
Jan Nieuwenhuizen ada6ac99dd mescc: Tinycc support: test #include.
* scaffold/tests/exit-42.i: New file.
* scaffold/tests/07-include.c: New file.
* make.scm ("07-include"): Build it.
2017-11-18 11:55:47 +01:00
Jan Nieuwenhuizen 02e70486a1 mescc: Tinycc support: struct struct array.
Support

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

* module/language/c99/compiler.mes (expr->accu):
* scaffold/tests/7n-struct-struct-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-11-17 15:24:45 +01:00
Jan Nieuwenhuizen d393fd3743 tinycc: scaffold/main.c: running mes-tcc compiled binary #6.
* scaffold/main.c (main): Use variable, if, argc, ++, +=, function call to return 42.
2017-11-16 05:33:11 +01:00
Jan Nieuwenhuizen cf107cb2b2 tinycc: scaffold/main.c: running mes-tcc compiled binary #5.
* scaffold/main.c (main): Use function call and variable to return 42.
2017-11-15 23:06:23 +01:00
Jan Nieuwenhuizen a2bc80fe7b tinycc: scaffold/main.c: running mes-tcc compiled binary #4.
* scaffold/main.c (main): Use variables to return 42.
2017-11-14 19:42:08 +01:00
Jan Nieuwenhuizen dc65de59ce mescc: refactor expr->accu, expr->accu*, fixes nontrivial struct by value assign.
* module/language/c99/compiler.mes: (pke): New function.
  (expr->number): Rename from p-expr->number.  Update callers.
  (decl->info, init-declr->pointer, struct-field): Several pointeryness fixes.
  (expr->accu*, expr->accu): Remove special-casing for foo.bar,
  foo->bar, foo[bar].  Fixes struct by value assign for non-trival
  expressions.
  (accu->ident, ident-address->accu, ident->accu):
  (base->ident-address, ident->base): Remove.
* scaffold/tests/7k-for-each-elem.c (test): Test it.
* scaffold/tests/7c-dynarray.c (test): Test it.
* scaffold/tests/7m-struct-char-array-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-11-11 13:45:53 +01:00
Jan Nieuwenhuizen 7e6408534f tinycc: scaffold/main.c: running tcc-compiled binary #3.
* scaffold/main.c (main): Remove asm.
2017-09-03 10:43:02 +02:00
Jan Nieuwenhuizen 9555d90174 mescc: Tinycc support: struct by value assign.
* module/language/c99/compiler.mes (expr->accu): warn for unsupported
  sizes.
* scaffold/tests/7h-struct-assign.c (test): Test it.
2017-09-10 16:59:53 +02:00
Jan Nieuwenhuizen 2896ce46c4 tinycc: scaffold/main.c: running tcc-compiled binary #2.
* scaffold/main.c (main)[__i386__]: Rename from _start.
2017-09-03 00:37:39 +02:00
Jan Nieuwenhuizen 9aa8d8bd9d tinycc: scaffold/main.c: first running tcc-compiled binary.
* scaffold/main.c (_start): Exit 42 using asm.
2017-08-19 11:35:58 +02:00
Jan Nieuwenhuizen 3560ee6c95 mescc: Tinycc support: fix *--p = 'x'.
* module/language/c99/compiler.mes (expr->accu): Respect size in *--p = 'x'.
* scaffold/tests/23-pointer.c (test): Test it.
2017-08-27 16:58:56 +02:00