This provides preliminary support for traditional Lisp macros, _not_ Scheme
macros as we know them today; this implementation is easy to implement, and
gives us a great foundation for moving forward.
There are caveats to this simple and naive implementation, documented
ad nauseam. It's probably worth a read if you're studying Rebirth in any
level of detail for whatever reason.
This is a pretty exciting change---it liberates us from rigid compiler
changes and will allow us to rewrite fnmap into macros almost as-is. The
change is fairly elegant, all things considered---the amount of code is
minimal; most of the change consists of comments describing it and its
caveats. This is a defining step in Rebirth, and brings it a step closer to
being an actual Lisp rather than a fragment of one. (Though I still don't
know if Rebirth Lisp will ever actually be a full Lisp. Please hold the
arguments about Scheme not being a Lisp or I'll respond very immaturely with
"your mom is not a Lisp", and we'll both be very confused and somewhat
offended by one-another, with a net loss overall. Oh, wait, you're actually
reading this?)
Anyway, changes:
* build-aux/bootstrap/rebirth.scm: Some rephrasing of toplevel comments,
and addition of macro comments.
(_macros): New ECMAScript variable.
(cdfn-macro, macro-compile-result, list->ast): New procedures. Little
full of comments. Lots of sap.
(parse-lisp): Fix typo. Add third argument to `cdfn-proc' (#f).
(cdfn-proc): Add third argument `id-override'. Use it in place of token
value, if set. Remove semicolon from generated ES function (it was
unneeded to begin with) so that it can be used in macro ES expressions.
(macro?): New procedure, conditional based on availability of
`string->es'.
(apply-proc-or-macro): New procedure. Conditionally apply macro during
compiler runtime or compile output for a procedure application.
(fnmap)[define-macro]: Apply `cdfn-macro'. This will try to apply it even
if the procedure isn't defined yet (e.g. first Rebirth pass), so don't
call it until then!
[else]: Use `apply-proc-or-macro'.
This will crudely detect "features" by seeing if the requested feature is a
definition. Ideally that definition would be a procedure, but we don't
check for that. This does what we need it to do.
Obviously this is a poor implementation and will not persist past Rebirth.
* build-aux/bootstrap/rebirth.scm (es:defined?): New procedure.
(expand-cond-expand): New procedure. If first Rebirth pass, only support
`string->es' and `else'; otherwise detect features using `es:defined?'.
(fnmap)[cond-expand]: Use it.
Since we don't have reader support for ",@", this will have to do for now.
* build-aux/bootstrap/rebirth.scm (%quote-maybe): Add `unquote@'.
Rename from `-quote-maybe'.
(%sexp-maybe-type): Rename from `-sexp-maybe-type'.
They were just out of date, having been copied from Prebirth.
* build-aux/bootstrap/birth.scm
(prebirth->ecmascript, birth>ecmascript): Former renamed to latter.
* build-aux/bootstrap/rebirth.scm
(prebirth->ecmascript, rebirth>ecmascript): Former renamed to latter.
Many of the procedures were encapsulated within `prebirth->ecmascript';
these have been moved out so that they can be accessed by other procedures,
allowing me to organize the code how I please.
Which also makes me realize that the procedure name is incorrect.
* build-aux/bootstrap/rebirth.scm: Move all procedures out of
`prebirth->ecmascript'.
This was pretty much a prerequisite for introducing macros (in commits to
follow)---the code would otherwise be far too verbose.
Note that this does _not_ introduce the shorthand forms ("'", "`", ",",
",@"), as implementing those in a reasonable manner would require
preprocesing the AST, which is not what I want to focus on right now. So
macros will still be a bit verbose, using the full
"(quasiquote ... (unquote-splicing ...))" and such instead of simply
"`(... ,@(...))"
* build-aux/bootstrap/rebirth.scm
(quote-sexp, quasiquote-sexp): Add procedures.
(fnmap)[quote]: Use `quote-sexp'.
[quasiquote]: Add special form.
This re-implements libprebirth in Rebirth Lisp, finally cutting the
cord. (Are these birth puns getting out of control?) We are finally purely
in Lisp land!
* build-aux/bootstrap/rebirth.scm: Define libprebith primitives when
`string->es' is available (using `cond-expand').
(prebirth->ecmascript): Do not include `libprebirth.js' in output.
This modifies each of the three lexers just to avoid confusion, even
though prebirth has no need for it. Birth does have a need, however, since
rebirth will contain newlines---despite the relevant rebirth code (next
commit) not being expanded, it still has to go through the lexer, which
otherwise errors out.
* build-aux/bootstrap/birth.scm (lex): Permit newlines in string regex.
* build-aux/bootstrap/prebirth.js (lex): Permit newlines in string regex.
* build-aux/bootstrap/rebirth.scm (lex): Permit newlines in string regex.
`cond-expand' allows moving forward with implementing features based on the
current bootstrapped state of the system---rebirth will be able to
recursively compile itself and introduce new features along the way.
`string->es' allows outputting raw ECMAScript, which gives us more control
over the code that is generated without having to hard-code it in the
compiler itself.
* build-aux/bootstrap/birth.scm
(fnmap)[cond-expand]: Always yield the empty string (do nothing).
* build-aux/bootstrap/rebirth.scm
(fnmap)[cond-expand]: Expand `string->es' only.
(fnmap)[string->es]: Add macro.
`define' can now be used to define values in addition to the procedure
short-hand.
* build-aux/bootstrap/rebirth.scm
(cdfn): New procedure. Renamed original `cdfn' to `cdfn-proc'.
(cdfn-var): New procedure.
(cdfn-proc): Renamed from `cdfn'.