Update documentation.
[mes.git] / HACKING
1 -*-mode:org-*-
2
3 * Fully source-based bootstrapping
4
5 ** R5RS-like scheme interpreter
6 This first part is prototyped in C by the mes.c core and Scheme
7 bootstrap code in module/.  Of course, while mes.c is pretty small it
8 cannot serve as a fully source-based solution.
9
10 The initial idea was to have the minimal core support LISP-1.5 (or
11 something very close to that as a tribute to John McCarthy) and extend
12 eval/apply from LISP-1.5 source with define, define-macro etc. and
13 metamorphose into R6RS.  It seemed to work but performance of the
14 LISP-intepreted RRS was so bad (~1000x slower than initial LISP-1.5)
15 that this track was abandoned after the initial ANNOUNCE.
16
17 The route changed trying strike a balance between core size and
18 performance: still writing as much as possible in Scheme, but having a
19 mescc compiler that takes not more than some seconds to run.
20
21 Now that the important bits of R5RS are done and R6RS's syntax-case
22 comes in scope, mes.c has grown into ~1500LOC, some effort must
23 probably be directed into making that smaller.
24
25 ** Move mes.c into hex?
26 One idea is to use OrianJ's amazing self-hosting [[https://github.com/oriansj/stage0][stage0]] hex assembler
27 and minimal bootstrap binaries and rewrite the mes.c core to directly
28 bootstrap into Scheme.
29
30 ** Rewrite mes.c and generate hex?
31 Another idea (thanks Rutger!) is to rewrite the mes.c core in a
32 C/Assembly variant and have mescc produce the simple, annotated
33 bootstrap binary.
34
35 ** R6RS's syntax-case
36
37 Having syntax-case should enable Mes to run [[https://savannah.gnu.org/projects/nyacc][nyacc]], which comes with a
38 full C parser.
39
40 *** Get Andre van Tonder's portable syntax-case up.
41     + This would avoid the psyntax.ss -> psyntax.pp -> psyntax.ss
42       bootstrap problem with an elegantly small implementation.
43
44     - Does this support the idea of a minimal mes.c core, or is too
45       much Scheme support required in the core?
46 *** Get a version of portable psyntax.pp up.
47     + Fully standard complient R6RS macros.
48     + Minimal mes.c core required (not even quasiquote?).
49     - Sloooowwwww with intepreter?
50
51 * Bugs
52 ** Core is too fat
53 mes.c is ~1500 lines (~10,000LOC Assembly) which seems much too big to
54 start translating it to assembly/hex.
55
56 ** (mes-use-module ...) is a fake, see module/mes/base.mes.
57 All top level scripts and test files (scripts/*.mes tests/*.test)
58 now include appropriate (mes-use-module ...) stanzas.
59
60 This hack allows for scripts/includes.mes to generate the list of
61 files to be prepended.  Previously, this information was put in
62 GNUmakefile.
63 ** Garbage collection?
64 Mes is using malloc without freeing anything, memory is patient these
65 days :-)
66 ** find/fix hygiene problem: see module/mes/match.scm ;; X vs x
67 **
68 ** Actually do something useful, build: [[https://en.wikipedia.org/wiki/Tiny_C_Compiler][Tiny C Compiler]]
69
70 * OLD: Booting from LISP-1.5 into Mes
71
72 Mes started out experimenting with booting from a hex-coded minimal
73 LISP-1.5 (prototype in mes.c), into an almost-RRS Scheme.
74
75 When EOF is read, the LISP-1.5 machine calls loop2 from loop2.mes,
76 which reads the rest of stdin and takes over control.  The functions
77 readenv, eval and apply-env in mes.mes introduced define, define-macro
78 quasiquote and macro expansion.
79
80 While this works, it's amazingly slow.  We implemented a full reader
81 in mes.c, which makes running mes:apply-env mes:eval somewhat
82 bearable, still over 1000x slower than running mes.c.
83
84 Bootstrapping has been removed and mes.c implements enough of RRS to
85 run a macro-based define-syntax and syntax-rules.
86
87 loop.mes and mes.mes are unused and lagging behind.  Probably it's not
88 worth considering this route without a VM.  GNU Epsilon is taking the
89 more usual VM-route to provide multiple personas.  While that sounds
90 neat, Lisp/Scheme, bootstrapping and trusted binaries are probably not
91 in scope as there is no mention of such things; only ML is mentioned
92 while Guile is used for bootstrapping.
93
94 * Assorted ideas and info 
95 ** C parser/compiler
96 *** [[https://savannah.gnu.org/projects/nyacc][nyacc]]
97 *** PEG: [[http://piumarta.com/software/peg/][parse C using PEG]]
98 *** [[https://en.wikipedia.org/wiki/Tiny_C_Compiler][Tiny C Compiler]]
99 *** [[http://www.t3x.org/subc/index.html][Sub C]]
100 *** [[https://groups.google.com/forum/#!topic/comp.lang.lisp/VPuX0VsjTTE][C intepreter in LISP/Scheme/Python]]
101
102 ** C assembler/linker
103 *** [[http://www.tldp.org/HOWTO/Assembly-HOWTO/linux.html][Assembly HOWTO]]
104 *** System call clue bat
105 Basically, you issue an int 0x80, with the __NR_syscallname number
106 (from asm/unistd.h) in eax, and parameters (up to six) in ebx, ecx,
107 edx, esi, edi, ebp respectively.
108 *** ELF
109 7f 45 4c 46
110 *** [[http://www.muppetlabs.com/~breadbox/software/tiny/][Small ELF programs]]
111 *** [[http://www.cirosantilli.com/elf-hello-world/][Elf hello world]]
112
113 ** RNRS
114 *** [[http://www.scheme-reports.org/][Scheme Reports]] 
115 *** [[ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-349.pdf][Scheme - Report on Scheme]]
116 *** [[ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-452.pdf][RRS - Revised Report on Scheme]]
117