From f2adafb2645ebddda155a091f5e41cb34c5dba2e Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 28 Aug 2017 01:21:02 -0400 Subject: [PATCH] prebirth: Allow toplevel function applications So we can invoke the main function for the program. * build-aux/bootstrap/prebirth.js (Compiler#_cdfn): Handle non-`define' applications. (Compiler#assertApply): Remove function. --- build-aux/bootstrap/prebirth.js | 41 ++++++++++----------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/build-aux/bootstrap/prebirth.js b/build-aux/bootstrap/prebirth.js index 25d5492..8e9cbe2 100644 --- a/build-aux/bootstrap/prebirth.js +++ b/build-aux/bootstrap/prebirth.js @@ -319,7 +319,18 @@ class Compiler */ _cdfn( t ) { - this.assertApply( t, 'define' ); + // an application must be an s-expression + if ( !Array.isArray( t ) ) { + throw Error( + `\`${name}' application expected, found symbol \`${t.value}'` + ); + } + + // 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; @@ -441,34 +452,6 @@ class Compiler // final function application return `${idfn}(${argstr})`; } - - - /** - * Determine whether T is an application of a symbol NAME, or error - * - * @param {*} t hopefully a token or token list - * @param {string} name function name to assert against - */ - assertApply( t, name ) - { - // an application must be an s-expression - if ( !Array.isArray( t ) ) { - throw Error( - `\`${name}' application expected, found symbol \`${t.value}'` - ); - } - - // if there's a match, we can stop here - if ( t[ 0 ].value === name ) { - return; - } - - // otherwise, provide an informative error of what we found and what - // we should have found - throw Error( - `\`${name}' expected, found \`${t[ 0 ].value}'` - ); - } }