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
parent
5fca236834
commit
dd34498808
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue