prebirth, birth, rebirth: Consistently use "es" instead of "js"

I've been torn on this for a bit, but we're using "es" (ECMAScript) in a lot
of important places.  Thinks like "js:console" I was considering leaving
because "console" is not an ECMAScript thing---it is JavaScript.  But now we
will take "es:" to mean "outputting in ECMAScript".

* build-aux/bootstrap/birth.scm, build-aux/bootstrap/rebirth.scm,
  build-aux/bootstrap/prebirth.js:
    s/js:/es:/g.
* build-aux/bootstrap/libprebirth.js: s/\$\$js\$/\$\$es\$/g.
master
Mike Gerwitz 2017-12-12 01:03:37 -05:00
parent 462d99fb99
commit 1060247f0b
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
4 changed files with 47 additions and 47 deletions

View File

@ -59,8 +59,8 @@
(if x #f #t))
;; for convenience
(define (js:match-regexp re s)
(js:match (js:regexp re) s))
(define (es:match-regexp re s)
(es:match (es:regexp re) s))
@ -75,7 +75,7 @@
;;
;; This implementation was originally recursive and immutable, but the stack
;; was being exhausted, so it was refactored into an inferior
;; implementation. Note the use of `js:while' and `js:break'---these are
;; implementation. Note the use of `es:while' and `es:break'---these are
;; quick fixes to the problem of stack exhaustion in browsers (where we have
;; no control over the stack limit); proper tail call support will come
;; later when we have a decent architecture in place.
@ -83,8 +83,8 @@
;; The result is a list of tokens. See `token' for the format.
(define (lex src pos)
(let ((toks (list)))
(js:while #t ; browser stack workaround
(let* ((ws (or (js:match-regexp "^\\s+"
(es:while #t ; browser stack workaround
(let* ((ws (or (es:match-regexp "^\\s+"
src)
(list "")))
(ws-len (string-length (car ws)))
@ -92,7 +92,7 @@
(newpos (+ pos ws-len))) ; adj pos to account for removed ws
(if (string=? "" trim)
(js:break) ; EOF and we're done
(es:break) ; EOF and we're done
;; normally we'd use `string-ref' here, but then we'd have to
;; implement Scheme characters, so let's keep this simple and keep
@ -100,7 +100,7 @@
(let* ((ch (substring trim 0 1))
(t (case ch
;; comments extend until the end of the line
((";") (let ((eol (js:match-regexp "^(.*?)(\\n|$)" trim)))
((";") (let ((eol (es:match-regexp "^(.*?)(\\n|$)" trim)))
(make-token "comment" (cadr eol) trim newpos)))
;; left and right parenthesis are handled in the same
@ -112,7 +112,7 @@
;; strings are delimited by opening and closing ASCII
;; double quotes, which can be escaped with a
;; backslash
(("\"") (let ((str (js:match-regexp
(("\"") (let ((str (es:match-regexp
"^\"(|(?:.|\\\n)*?[^\\\\])\""
trim)))
(or str (parse-error
@ -129,7 +129,7 @@
;; anything else is considered a symbol up until
;; whitespace or any of the aforementioned
;; delimiters
(let ((symbol (js:match-regexp "^[^\\s()\"]+"
(let ((symbol (es:match-regexp "^[^\\s()\"]+"
trim)))
(make-token "symbol" symbol trim newpos))))))
@ -276,10 +276,10 @@
;; reliably distinguished from one-another. Remember: this is temporary
;; code.
(define (tname->id name)
(if (js:match (js:regexp "^\\d+$") name)
(if (es:match (es:regexp "^\\d+$") name)
name
(string-append
"$$" (js:replace (js:regexp "[^a-zA-Z0-9_]" "g")
"$$" (es:replace (es:regexp "[^a-zA-Z0-9_]" "g")
(lambda (c)
(case c
(("-") "$_$")
@ -375,7 +375,7 @@
;; the future (Rebirth).
(define (fnmap fn args t)
(case fn
(("js:console")
(("es:console")
(string-append "console.log(" (map sexp->es args) ")"))
;; only expands `else' clauses; this is just to facilitate its use
@ -391,7 +391,7 @@
;; yes, there are more important things to do until we get to the
;; point where it's worth implementing proper tail calls
(("js:while")
(("es:while")
(let ((pred (car args))
(body (cdr args)))
(string-append
@ -400,7 +400,7 @@
(body->es body #f) " if (__whilebrk) break;\n"
"}\n"
"})(false)")))
(("js:break") "__whilebrk=true")
(("es:break") "__whilebrk=true")
;; fortunately ES6+ has native symbol support :)
;; we don't (yet?) need list quoting in Prebirth
@ -556,13 +556,13 @@
;; output libprebirth and compiled output, wrapped in a self-executing
;; function to limit scope
(string-append "(function(){"
(js:file->string "libprebirth.js") "\n\n"
(es:file->string "libprebirth.js") "\n\n"
(join "\n\n" (map sexp->es ast))
"})();"))
;; at this point, this program can parse itself and output a CST (sans
;; whitespace)
(js:console (birth->ecmascript
(es:console (birth->ecmascript
(parse-lisp
(js:file->string "/dev/stdin"))))
(es:file->string "/dev/stdin"))))

View File

@ -134,9 +134,9 @@ const $$map = ( f, ...xs ) =>
xs.map( x => x[ i ] ) ) );
const $$js$regexp = ( s, opts ) => new RegExp( s, opts );
const $$js$match = ( r, s ) => s.match( r ) || false;
const $$js$replace = ( r, repl, s ) => s.replace( r, repl );
const $$es$regexp = ( s, opts ) => new RegExp( s, opts );
const $$es$match = ( r, s ) => s.match( r ) || false;
const $$es$replace = ( r, repl, s ) => s.replace( r, repl );
// the variable __fsinit, if defined, can be used to stub the filesystem
@ -152,7 +152,7 @@ const fs = ( typeof require !== 'undefined' )
}
// file->string
const $$js$file$_$$g$string = ( path ) =>
const $$es$file$_$$g$string = ( path ) =>
{
if ( fsdata[ path ] !== undefined ) {
return fsdata[ path ];

View File

@ -318,7 +318,7 @@ class Compiler
* Initialize with function map
*
* The function map will be used to map certain functions into other
* names or forms. For example, `js:console' may map to `console.log'
* names or forms. For example, `es:console' may map to `console.log'
* and `if' to an `if' statement+expression.
*
* @param {Object} fnmap function map
@ -554,17 +554,17 @@ class Compiler
* @type {Object}
*/
const fnmap = {
'js:console': 'console.log',
'es:console': 'console.log',
// yes, there are more important things to do until we get to the point
// where it's worth implementing proper tail calls
'js:while': ( [ pred, ...body ], stoes, btoes ) =>
'es:while': ( [ pred, ...body ], stoes, btoes ) =>
"(function(__whilebrk){" +
`while (${stoes(pred)}){\n` +
`${btoes(body, false)} if (__whilebrk) break;\n` +
"}\n" +
"})(false)",
'js:break': () => '__whilebrk=true',
'es:break': () => '__whilebrk=true',
// fortunately ES6+ has native symbol support :)
// we don't (yet?) need list quoting in Prebirth
@ -730,7 +730,7 @@ if ( typeof module !== 'undefined' ) {
* Here is an example Hello, World!:
*
* (define (hello x)
* (js:console "Hello," x, "!"))
* (es:console "Hello," x, "!"))
*
*
* ¹ This term should invoke visuals of an abstract being entering existence

View File

@ -193,11 +193,11 @@
(string->es
"$$xs[0].map((_, i) => $$f.apply(null, $$xs.map(x => x[i])))")))
(define (js:regexp s opts)
(define (es:regexp s opts)
(string->es "new RegExp($$s, $$opts)"))
(define (js:match r s)
(define (es:match r s)
(string->es "$$s.match($$r) || false"))
(define (js:replace r repl s)
(define (es:replace r repl s)
(string->es "$$s.replace($$r, $$repl)"))
(define *fsdata*
@ -221,7 +221,7 @@
(string->es "const fsdata = $$$k$fsdata$k$")
(string->es "const fs = $$$k$fs$k$")
(define (js:file->string path)
(define (es:file->string path)
(if (string->es "fsdata[$$path] === undefined")
(string->es
"fsdata[$$path] = fs.readFileSync($$path).toString()")
@ -468,8 +468,8 @@
(if x #f #t))
;; for convenience
(define (js:match-regexp re s)
(js:match (js:regexp re) s))
(define (es:match-regexp re s)
(es:match (es:regexp re) s))
@ -484,7 +484,7 @@
;;
;; This implementation was originally recursive and immutable, but the stack
;; was being exhausted, so it was refactored into an inferior
;; implementation. Note the use of `js:while' and `js:break'---these are
;; implementation. Note the use of `es:while' and `es:break'---these are
;; quick fixes to the problem of stack exhaustion in browsers (where we have
;; no control over the stack limit); proper tail call support will come
;; later when we have a decent architecture in place.
@ -492,8 +492,8 @@
;; The result is a list of tokens. See `token' for the format.
(define (lex src pos)
(let ((toks (list)))
(js:while #t ; browser stack workaround
(let* ((ws (or (js:match-regexp "^\\s+"
(es:while #t ; browser stack workaround
(let* ((ws (or (es:match-regexp "^\\s+"
src)
(list "")))
(ws-len (string-length (car ws)))
@ -501,7 +501,7 @@
(newpos (+ pos ws-len))) ; adj pos to account for removed ws
(if (string=? "" trim)
(js:break) ; EOF and we're done
(es:break) ; EOF and we're done
;; normally we'd use `string-ref' here, but then we'd have to
;; implement Scheme characters, so let's keep this simple and keep
@ -509,7 +509,7 @@
(let* ((ch (substring trim 0 1))
(t (case ch
;; comments extend until the end of the line
((";") (let ((eol (js:match-regexp "^(.*?)(\\n|$)" trim)))
((";") (let ((eol (es:match-regexp "^(.*?)(\\n|$)" trim)))
(make-token "comment" (cadr eol) trim newpos)))
;; left and right parenthesis are handled in the same
@ -521,7 +521,7 @@
;; strings are delimited by opening and closing ASCII
;; double quotes, which can be escaped with a
;; backslash
(("\"") (let ((str (js:match-regexp
(("\"") (let ((str (es:match-regexp
"^\"(|(?:.|\\\n)*?[^\\\\])\""
trim)))
(or str (parse-error
@ -538,7 +538,7 @@
;; anything else is considered a symbol up until
;; whitespace or any of the aforementioned
;; delimiters
(let ((symbol (js:match-regexp "^[^\\s()\"]+"
(let ((symbol (es:match-regexp "^[^\\s()\"]+"
trim)))
(make-token "symbol" symbol trim newpos))))))
@ -682,10 +682,10 @@
;; reliably distinguished from one-another. Remember: this is temporary
;; code.
(define (tname->id name)
(if (js:match (js:regexp "^\\d+$") name)
(if (es:match (es:regexp "^\\d+$") name)
name
(string-append
"$$" (js:replace (js:regexp "[^a-zA-Z0-9_]" "g")
"$$" (es:replace (es:regexp "[^a-zA-Z0-9_]" "g")
(lambda (c)
(case c
(("-") "$_$")
@ -963,9 +963,9 @@
;; the future (Rebirth).
(define (fnmap fn args t)
(case fn
(("js:console")
(("es:console")
(string-append "console.log(" (map sexp->es args) ")"))
(("js:error")
(("es:error")
(string-append "console.error(" (map sexp->es args) ")"))
;; very primitive cond-expand
@ -977,7 +977,7 @@
;; yes, there are more important things to do until we get to the
;; point where it's worth implementing proper tail calls
(("js:while")
(("es:while")
(let ((pred (car args))
(body (cdr args)))
(string-append
@ -986,7 +986,7 @@
(body->es body #f) " if (__whilebrk) break;\n"
"}\n"
"})(false)")))
(("js:break") "__whilebrk=true")
(("es:break") "__whilebrk=true")
;; note that the unquote forms are only valid within a quasiquote; see
;; that procedure for the handling of those forms
@ -1150,6 +1150,6 @@
;; at this point, this program can parse itself and output a CST (sans
;; whitespace)
(js:console (rebirth->ecmascript
(es:console (rebirth->ecmascript
(parse-lisp
(js:file->string "/dev/stdin"))))
(es:file->string "/dev/stdin"))))