From 639948da0201c56505047442d15c72b50f3e3ccc Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 5 Dec 2017 00:35:54 -0500 Subject: [PATCH] birth,rebirth: Add cond-expand, string->es `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. --- build-aux/bootstrap/birth.scm | 4 ++++ build-aux/bootstrap/rebirth.scm | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/build-aux/bootstrap/birth.scm b/build-aux/bootstrap/birth.scm index 3b2ae07..378d6c0 100644 --- a/build-aux/bootstrap/birth.scm +++ b/build-aux/bootstrap/birth.scm @@ -377,6 +377,10 @@ (("js:console") (string-append "console.log(" (map sexp->es args) ")")) + ;; always expands into nothing; this is just to facilitate its use + ;; moving forward + (("cond-expand") "") + ;; yes, there are more important things to do until we get to the ;; point where it's worth implementing proper tail calls (("js:while") diff --git a/build-aux/bootstrap/rebirth.scm b/build-aux/bootstrap/rebirth.scm index aa4514a..18927de 100644 --- a/build-aux/bootstrap/rebirth.scm +++ b/build-aux/bootstrap/rebirth.scm @@ -398,6 +398,19 @@ (("js:console") (string-append "console.log(" (map sexp->es args) ")")) + ;; very primitive cond-expand + (("cond-expand") + (let* ((clause (car args)) + (feature (token-value (car clause))) + (body (cdr clause))) + (case feature + (("string->es") (body->es body #f)) + (else "")))) + + ;; output raw code into the compiled ECMAScript (what could go wrong?) + (("string->es") + (token-value (car args))) + ;; yes, there are more important things to do until we get to the ;; point where it's worth implementing proper tail calls (("js:while")