From 240f2814f42c0b0ac13420764247b2f7f0821ac5 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 19 Mar 2017 13:41:56 +0100 Subject: [PATCH] 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. --- .gitignore | 21 ++++++++++++++-- GNUmakefile | 56 +++++++++++++++++++++++++++++++++++++++---- HACKING | 4 +++- lib.c | 7 +++--- module/mes/mini-0.mes | 7 ++++++ module/mes/tiny-0.mes | 1 + scaffold/cons-mes.c | 4 ++-- scaffold/mini-mes.c | 3 +-- scaffold/tiny-mes.c | 4 ++-- 9 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 module/mes/mini-0.mes create mode 100644 module/mes/tiny-0.mes diff --git a/.gitignore b/.gitignore index 5bc1b3e6..cbf2a3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,11 +13,28 @@ /ChangeLog /a.out /mes +/mes-32 + +/cons-mes +/m +/main /micro-mes /mini-mes +/t /tiny-mes -/module/mes/hack-32.mo -/module/mes/read-0-32.mo + +/guile-cons-mes +/guile-m +/guile-main +/guile-micro-mes +/guile-mini-mes +/guile-t +/guile-tiny-mes + +/module/mes/tiny-0-32.mo +#keep this: bootstrap +#/module/mes/read-0-32.mo +/module/mes/mini-0.mo /module/mes/read-0.mo /out ? diff --git a/GNUmakefile b/GNUmakefile index 08f04b41..0f9a634e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -15,6 +15,7 @@ CFLAGS:=-std=c99 -O3 -finline-functions include .config.make include make/install.make +CPPFLAGS+=-I. CPPFLAGS+=-DPREFIX='"$(PREFIX)"' CPPFLAGS+=-DVERSION='"$(VERSION)"' @@ -37,6 +38,10 @@ mes.o: reader.c reader.h reader.i reader.environment.i clean: rm -f mes *.o *.environment.i *.symbols.i *.environment.h *.cat a.out + rm -f mes-32 + rm -f cons-mes m main micro-mes mini-mes t tiny-mes + rm -f guile-cons-mes guile-m guile-main guile-micro-mes guile-mini-mes guile-t guile-tiny-mes + rm -f module/mes/*.mo distclean: clean rm -f .config.make @@ -90,13 +95,16 @@ module/mes/read-0.mo: module/mes/read-0.mes mes dump: module/mes/read-0.mo -mes-32: +mes-32: mes.c lib.c rm -f mes mes.o guix environment --system=i686-linux --ad-hoc gcc-toolchain -- bash -c 'make mes CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=$${PATH%%/bin:*}/lib' mv mes mes-32 -module/mes/hack-32.mo: mes-32 - MES_HACK=1 ./mes-32 --dump < module/mes/read-0.mes > module/mes/hack-32.mo +module/mes/read-0-32.mo: module/mes/mini-0.mes mes-32 + MES_MINI=1 ./mes-32 --dump < $< > $@ + +module/mes/tiny-0-32.mo: module/mes/tiny-0.mes mes-32 + MES_TINY=1 ./mes-32 --dump < $< > $@ guile-check: set -e; for i in $(TESTS); do\ @@ -117,43 +125,81 @@ mescc-check: t-check build-aux/mes-snarf.scm $< mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i +mini-mes: mlibc.c mstart.c mini-mes: GNUmakefile -mini-mes: doc/examples/mini-mes.c +mini-mes: module/mes/read-0-32.mo +mini-mes: scaffold/mini-mes.c rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -I. -o $@ '-DVERSION="0.4"' $< + # gcc -nostdlib --std=gnu99 -m32 -g -o $@ '-DPREFIX=' '-DVERSION='"$(VERSION)"' $< + gcc -nostdlib -I. --std=gnu99 -m32 -g -I. -o $@ $(CPPFLAGS) $< chmod +x $@ +guile-mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i +guile-mini-mes: module/mes/read-0-32.mo +guile-mini-mes: scaffold/mini-mes.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + +cons-mes: module/mes/tiny-0-32.mo cons-mes: scaffold/cons-mes.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-cons-mes: module/mes/tiny-0-32.mo +guile-cons-mes: scaffold/cons-mes.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + +tiny-mes: module/mes/tiny-0-32.mo tiny-mes: scaffold/tiny-mes.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-tiny-mes: module/mes/tiny-0-32.mo +guile-tiny-mes: scaffold/tiny-mes.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + m: scaffold/m.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< # gcc --std=gnu99 -g -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-m: scaffold/m.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + micro-mes: scaffold/micro-mes.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-micro-mes: scaffold/micro-mes.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + main: doc/examples/main.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-main: doc/examples/main.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + +t: mlibc.c t: scaffold/t.c GNUmakefile rm -f $@ gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< chmod +x $@ +guile-t: scaffold/t.c + guile/mescc.scm $< > $@ || rm -f $@ + chmod +x $@ + MAIN_C:=doc/examples/main.c mescc: all $(MAIN_C) rm -f a.out diff --git a/HACKING b/HACKING index 38cf92dd..17009485 100644 --- a/HACKING +++ b/HACKING @@ -82,7 +82,9 @@ gdb-display-disassembly-buffer b *0x804a79d ** Create memory dump with 32 bit Gcc compiled Mes guix environment --ad-hoc --system=i686-linux gcc-toolchain -- bash -c 'make mes CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=${PATH%%/bin:*}/lib' -MES_HACK=1 ./mes-32 --dump < module/mes/read-0.mes > module/mes/read-0-32.mo +mv mes mes-32 +MES_TINY=1 ./mes-32 --dump < module/mes/tiny-0.mes > module/mes/tiny-0-32.mo +./mes-32 --dump < module/mes/read-0.mes > module/mes/read-0-32.mo ** C parser/compiler *** [[https://savannah.gnu.org/projects/nyacc][nyacc]] *** PEG: [[http://piumarta.com/software/peg/][parse C using PEG]] diff --git a/lib.c b/lib.c index 10ee9f7b..3c9f49c9 100644 --- a/lib.c +++ b/lib.c @@ -172,7 +172,8 @@ dump () fputc ('S', stdout); fputc (g_stack >> 8, stdout); fputc (g_stack % 256, stdout); - if (getenv ("MES_HACK")) + // See HACKING, simple crafted dump for tiny-mes.c + if (getenv ("MES_TINY")) { TYPE (9) = 0x2d2d2d2d; CAR (9) = 0x2d2d2d2d; @@ -210,7 +211,7 @@ load_env (SCM a) ///((internal)) { r0 = a; if (getenv ("MES_MINI")) - g_stdin = fopen ("mini-0.mes", "r"); + g_stdin = fopen ("module/mes/mini-0.mes", "r"); else { g_stdin = fopen ("module/mes/read-0.mes", "r"); @@ -226,7 +227,7 @@ SCM bload_env (SCM a) ///((internal)) { #if MES_MINI - g_stdin = fopen ("mini-0.mo", "r"); + g_stdin = fopen ("module/mes/read-0-32.mo", "r"); #else g_stdin = fopen ("module/mes/read-0.mo", "r"); g_stdin = g_stdin ? g_stdin : fopen (PREFIX "module/mes/read-0.mo", "r"); diff --git a/module/mes/mini-0.mes b/module/mes/mini-0.mes new file mode 100644 index 00000000..3844b8e3 --- /dev/null +++ b/module/mes/mini-0.mes @@ -0,0 +1,7 @@ +(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 + ) diff --git a/module/mes/tiny-0.mes b/module/mes/tiny-0.mes new file mode 100644 index 00000000..636640af --- /dev/null +++ b/module/mes/tiny-0.mes @@ -0,0 +1 @@ +(cons 0 1) diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c index 080bd425..94d21ece 100644 --- a/scaffold/cons-mes.c +++ b/scaffold/cons-mes.c @@ -844,11 +844,11 @@ SCM simple_bload_env (SCM a) ///((internal)) { puts ("reading: "); - char *mo = "module/mes/hack-32.mo"; + char *mo = "module/mes/tiny-0-32.mo"; puts (mo); puts ("\n"); g_stdin = open (mo, 0); - if (g_stdin < 0) {eputs ("no such file: module/mes/read-0-32.mo\n");return 1;} + if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} char *p = (char*)g_cells; int c; diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index d44c3828..a406cb3b 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -1117,8 +1117,7 @@ mes_builtins (SCM a) ///((internal)) SCM bload_env (SCM a) ///((internal)) { - char *mo = "mini-0-32.mo"; - //char *mo = "module/mes/read-0-32.mo"; + char *mo = "module/mes/read-0-32.mo"; g_stdin = open (mo, 0); if (g_stdin < 0) {eputs ("no such file: ");eputs (mo);eputs ("\n");return 1;} assert (getchar () == 'M'); diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index 5fefedd2..3498e1c2 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -313,11 +313,11 @@ SCM bload_env (SCM a) ///((internal)) { puts ("reading: "); - char *mo = "module/mes/hack-32.mo"; + char *mo = "module/mes/tiny-0-32.mo"; puts (mo); puts ("\n"); g_stdin = open (mo, 0); - if (g_stdin < 0) {eputs ("no such file: module/mes/read-0-32.mo\n");return 1;} + if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} // BOOM //char *p = arena;