prebirth: Allow nested defines

This just reorganizes things slightly to allow for nested `define's.  This
is a common means of encapsulation, and will Just Work™ because JS has
pretty much identical block scoping rules in this regard.

* build-aux/bootstrap/prebirth.js (compile): Invoke `#_sexpsToEs' directly
    instead of `#_cdfn' on tree.
  (_cdfn): Remove non-`define' check to proxy to `#_sexpsToEs'.
  (_sexpsToEs): Treat `define' as a special case, invoking `#_cdfn'.
master
Mike Gerwitz 2017-09-02 01:25:31 -04:00
parent 5fca236834
commit dd34498808
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 5 additions and 7 deletions

View File

@ -328,7 +328,7 @@ class Compiler
{
// map every definition to a ES function definition and delimit them
// (for readability) by two newlines
return tree.map( this._cdfn.bind( this ) )
return tree.map( this._sexpToEs.bind( this ) )
.join( "\n\n" ) + "\n";
}
@ -351,12 +351,6 @@ class Compiler
);
}
// if it's not a definition, then it's a top-level application
if ( t[ 0 ].value !== 'define' )
{
return this._sexpToEs( t ) + ';';
}
// e.g. (define (foo ...) body)
const [ , [ { value: name }, ...params ], ...body ] = t;
@ -496,6 +490,10 @@ class Compiler
}
}
if ( t[ 0 ].value === 'define' ) {
return this._cdfn( t );
}
// simple function application (fn ...args)
const [ { value: fn }, ...args ] = t;