2 #+TITLE: Hacking GNU Mes
4 Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
6 Copying and distribution of this file, with or without modification,
7 are permitted in any medium without royalty provided the copyright
8 notice and this notice are preserved.
11 guix environment -l .guix.scm #64 bit + 32bit
15 guix environment --system=i686-linux -l .guix.scm #32 bit only
19 guix package --profile=~/.config/guix/mes --manifest=build-aux/manifest.scm
20 . ~/.config/guix/mes/etc/profile
23 There are two major modes to build Mes: true bootstrap and
27 To help development we assume ./configure sets these variables for make
29 CC -- gcc (or i686-unknown-linux-gnu-gcc sans libc)
36 Mes is supposed to serve as a full equivalent for Guile, however Mes
37 is still about 2 to 10 times slower than Guile. That's why we usually
38 don't use Mes during development.
40 Gcc is used to verify the sanity of our C sources.
42 i686-unknown-linux-gnu-gcc is used to compare hex/assembly, to test
43 the gcc variant of Mes C Libirary.
44 Target prefix: x86-mes-gcc.
46 gcc -nostdinc,-nostdlib is used to compare hex/assembly, to test the
47 64bit variant of Mes C Library. Target prefix: x86_64-mes-gcc.
49 Guile is used to develop MesCC, the C compiler in Scheme that during
50 bootstrapping will be executed by Mes.
54 ./configure.sh [--prefix=PREFIX]
58 In bootstrap mode, we don't have gcc (CC), we don't have a 32 bit gcc,
59 we have no guile (GUILE)...but we should have hex2, M1, and mes.M1.
60 That's a bootstrap problem which is currently ignored by using the
61 mes-seed package. mes.M1 will be produced by M2-Planet from mes.c.
66 *** release 0.x, unsorted
67 - mes: prepare src/mes.c for M2-Planet transpiler,
68 Jeremiah branched-out from mes; see https://github.com/oriansj/mes-m2.
69 - mes/mescc: proper docstrings, api reference documentation.
70 - replace bootstrap-binaries with Gash: bash, coreutils, grep, gzip,
72 - mes: real module support, Guile compatible (define-module,
73 define-public, export).
74 - mescc: ARMv7/AArch64 support.
76 - replace initial gcc-2.95.3 with gcc-3.x or 4.x
77 - use 3rd party libc (ucLibc, dietlibc, ...) after Mes and reduce
78 need for bootstrappably-rich Mes C Library?
79 - mes/mescc: bootstrap a `bootstrap-Guile' before bootstrapping tcc?
80 - tcc: remove or upstream patches from tcc-boot.
81 - tcc: build 0.9.27 directly instead of via 0.9.26, see tinycc
82 wip-bootstrappable@0.9.27 branch
83 - mes/mescc: bootstrap a minimal-Guile?
84 + libguile/{eval,init,list,strings,values,..}.
86 - mescc: have mes-tcc pass all scaffold/tests, scaffold/tinycc tests.
87 - syntax-case bootstrap problem
88 + resolve portable syntax-case bootstrap, or
89 + get full source syntax-case up (Andre van Tonder?)
90 https://srfi.schemers.org/srfi-72/srfi-72.html, or
92 - mescc: the Hurd support.
94 *** 0.19 GNU mes now compiles TinyCC in ~8min and supports building Bash and GNU Tar.
95 *** 0.18 GNU mes now supports GuixSD bootstrap (x86,x86_64) and has native x86_64 support.
96 *** 0.17.1 GNU Mes now allows removing glibc, binutils and gcc from the GuixSD bootstrap.
97 *** 0.17 GNU Mes is now an official GNU project and bootstraps gcc-4.7.4.
98 *** 0.16.1 Mes now has info docs and installs ootb on Debian buster/testing.
99 *** 0.16 Mes Lib C now bootstraps glibc-2.2.5, binutils-2.20.1, gcc-4.1.0.
100 *** 0.15: MesCC now has a libc+gnu that supports compiling binutils-2.14, gcc-2.95.3 and glibc-2.2.5.
101 *** 0.14: Mes+MesCC now compiles a slightly patched self-hosting tcc.
102 *** 0.13: Mes+MesCC now compiles a modified, functional tcc.c (~25,000LOC) in 1h30'.
103 *** 0.12: Mes+MesCC now compiles mes.c (~3000LOC) in ~4min.
104 *** 0.11: MesCC now compiles a mes-tcc that passes 26/69 of mescc's C tests.
105 *** 0.10: Mescc now compiles a mes-tcc that compiles a trivial C to a running a.out.
106 *** 0.9: Mescc now writes M1 macro assembly files and compiles tcc.
107 *** 0.8: Mescc now writes object files in stage0's labeled hex2 format.
108 *** 0.7: Mescc supports -E, -c, -o options, include more complete set of header files,
109 enough to work on compiling tinycc's tcc.c albeit a somewhat modified version.
110 *** 0.6: Work with unmodified, unbundled Nyacc; compile 33/55 tinycc's tests/test2 suite.
111 *** 0.5: Mutual self-hosting Scheme interpreter and C compiler: mes.c and mescc,
112 Support call-with-current-continuation, refactor catch/throw
113 *** 0.4: Support Nyacc, Gcc-compiled Mes compiles minimal main.c using nyacc
114 *** 0.3: Garbage collector
115 *** 0.2: Support psyntax
116 *** 0.1: Mes eval/apply feature complete; support syntax-rules, compile main.c using LALR, dump ELF
120 MES_DEBUG=<level> mes
124 - included SCM modules and sources
130 - parsed, expanded program
133 - opened input strings
135 5) usage of opened input strings
139 ** mes: performance, Mes is now 2-10x slower than Guile.
140 ** mes/mescc lack support for the Hurd.
141 ** mes: gcc-x86_64 compiled mes segfaults with small arena, or gc_up_arena.
142 ** mes: gcc-x86 compiled, tests/srfi-13.test number->string INT-MIN fails:
143 test: number->string INT-MIN: fail
144 expected: -2147483648
146 ** tcc: tcc-built lib/libc+tcc.c segfaults with mes, with tcc.
147 ** mes: remove pmatch-car/pmatch-cdr hack.
148 ** mescc: softcode stack frame size, now hardcoded and very large
149 ** mes+mescc: parse tcc.c->tcc.E works, compile tcc.E -> tcc.M1 segfaults.
150 time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH ../mes/scripts/mescc -E -o tcc.E -I . -I ../mes/lib -I ../mes/include -D 'CONFIG_TCCDIR="usr/lib/tcc"' -D 'CONFIG_TCC_CRTPREFIX="usr/lib:{B}/lib:."' -D 'CONFIG_TCC_ELFINTERP="/gnu/store/70jxsnpffkl7fdb7qv398n8yi1a3w5nx-glibc-2.26.105-g0890d5379c/lib/ld-linux.so.2"' -D 'CONFIG_TCC_LIBPATHS="/home/janneke/src/tinycc/usr/lib:{B}/lib:."' -D 'CONFIG_TCC_SYSINCLUDEPATHS="../mes/include:usr/include:{B}/include"' -D CONFIG_USE_LIBGCC=1 -D 'TCC_LIBGCC="/home/janneke/src/tinycc/usr/lib/libc+tcc-gcc.mlibc-o"' -D CONFIG_TCC_STATIC=1 -D ONE_SOURCE=yes -D TCC_TARGET_I386=1 -D BOOTSTRAP=1 tcc.c
151 time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH MES_ARENA=200000000 ../mes/scripts/mescc -c -o tcc.M1 tcc.E
152 ** mescc: 7n-struct-struct-array.c: struct file f = {"first.h"};
153 ** test/match.test ("nyacc-simple"): hygiene problem in match
154 * OLD: Booting from LISP-1.5 into Mes
156 Mes started out experimenting with booting from a hex-coded minimal
157 LISP-1.5 (prototype in mes.c), into an almost-RRS Scheme.
159 When EOF is read, the LISP-1.5 machine calls loop2 from loop2.mes,
160 which reads the rest of stdin and takes over control. The functions
161 readenv, eval and apply-env in mes.mes introduced define, define-macro
162 quasiquote and macro expansion.
164 While this works, it's amazingly slow. We implemented a full reader
165 in mes.c, which makes running mes:apply-env mes:eval somewhat
166 bearable, still over 1000x slower than running mes.c.
168 Bootstrapping has been removed and mes.c implements enough of RRS to
169 run a macro-based define-syntax and syntax-rules.
171 loop.mes and mes.mes are unused and lagging behind. Probably it's not
172 worth considering this route without a VM. GNU Epsilon is taking the
173 more usual VM-route to provide multiple personas. While that sounds
174 neat, Lisp/Scheme, bootstrapping and trusted binaries are probably not
175 in scope as there is no mention of such things; only ML is mentioned
176 while Guile is used for bootstrapping.
178 * Assorted ideas and info
179 ** Using GDB on assembly/a.out
183 set disassemble-next-line on
184 gdb-display-disassembly-buffer
186 ** Create memory dump with 32 bit Gcc compiled Mes
187 make out/i686-unknown-linux-gnu-mes
188 out/i686-unknown-linux-gnu-mes --dump < module/mes/read-0.mes > module/mes/read-0-32.mo
190 x/s *((char **)($rsp+8))
193 *** [[https://savannah.gnu.org/projects/nyacc][nyacc]]
194 *** PEG: [[http://piumarta.com/software/peg/][parse C using PEG]]
195 *** [[https://en.wikipedia.org/wiki/Tiny_C_Compiler][Tiny C Compiler]]
196 *** [[http://www.t3x.org/subc/index.html][Sub C]]
197 *** [[https://groups.google.com/forum/#!topic/comp.lang.lisp/VPuX0VsjTTE][C intepreter in LISP/Scheme/Python]]
199 ** C assembler/linker
200 *** [[http://www.tldp.org/HOWTO/Assembly-HOWTO/linux.html][Assembly HOWTO]]
203 *** [[http://www.muppetlabs.com/~breadbox/software/tiny/][Small ELF programs]]
204 *** [[http://www.cirosantilli.com/elf-hello-world/][Elf hello world]]
205 ** SC - c as s-expressions
206 sc: http://sph.mn/content/3d3
208 *** [[http://www.scheme-reports.org/][Scheme Reports]]
209 *** [[ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-349.pdf][Scheme - Report on Scheme]]
210 *** [[ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-452.pdf][RRS - Revised Report on Scheme]]
213 http://forum.osdev.org/viewtopic.php?f=15&t=19937
215 http://www.stripedgazelle.org/joey/dreamos.html
216 http://armpit.sourceforge.net/
217 http://common-lisp.net/project/movitz/movitz.html
219 <civodul> janneke: https://github.com/namin/inc looks interesting [15:18]
221 <OriansJ> janneke: also, if you look at
222 https://github.com/oriansj/stage0/tree/master/stage2/High_level_prototypes
223 [the garbage collected lisp I implemented], if there are any pieces
224 I could add to finish off your mes lisp bootstrap just let me know
225 because I would be more than happy to do that :D
226 <janneke> OriansJ: that's what I'm hoping for, that our efforts can be
227 complementary and we can work together
228 *** lfam (~lfam@2601:47:4180:2ffb:7c05:17de:cf5f:23ef) has quit: Ping timeout:
230 <janneke> exciting times! [00:23]
231 <janneke> OriansJ: i looked a few times and saw 'LISP empty', so thanks for
233 <civodul> OriansJ, janneke: from that page, there's also:
234 https://web.archive.org/web/20160604035203fw_/http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html
237 https://web.archive.org/web/20160604041431/http://homepage.ntlworld.com/edmund.grimley-evans/cc500/cc500.c
238 https://github.com/rswier/c4/blob/master/c4.c
239 ** Compilers for free
240 http://codon.com/compilers-for-free
242 *** [[https://www.mirrorservice.org/sites/www.bitsavers.org/bits/TI/Explorer/zeta-c/][ZETA-C]]
245 *** [[https://github.com/rui314/8cc][8cc]] -- a C11 compiler, but simple
246 8cc is a compiler for the C programming language. It's intended to
247 support all C11 language features while keeping the code as small and
251 https://miyuki.github.io/2017/10/04/gcc-archaeology-1.html
252 *** [[http://tack.sourceforge.net/][ack]]
253 <rain1> it may be possible to compile like this: mes |> ack |> pcc |> tcc |>
254 gcc 4.7.4 |> gcc later version... up to modern
255 *** [[https://web.archive.org/web/20160402225843/http://homepage.ntlworld.com/edmund.grimley-evans/cc500/][cc500]]
256 ** rain1's Bootstrapping Wiki: https://bootstrapping.miraheze.org/wiki/Main_Page
258 https://notabug.org/rain1/hex86/src/master/tests/hex0b3.hex86
259 ** <pdewacht> janneke, have you ever tried testing mescc with csmith? [10:55]
260 ** <pdewacht> e.g. as described here
261 https://jamey.thesharps.us/2016/07/15/testing-strategies-for-corrode/
262 ("Randomized testing with Csmith and C-Reduce") [10:58]