author | Alan Dipert
<alan@dipert.org> 2019-11-16 21:19:31 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-11-16 21:19:31 UTC |
parent | 2980fa75ce4baffac2ed235abc4b21a08e279373 |
jacl.js | +21 | -0 |
diff --git a/jacl.js b/jacl.js index 0546e8b..a8a5fcf 100644 --- a/jacl.js +++ b/jacl.js @@ -770,6 +770,7 @@ const SPECIAL_FORMS = [ '%DOT', '%LAMBDA', '%LET', + '%NEW', '%PROG', '%SET', '%TAGBODY', @@ -1144,6 +1145,13 @@ const analyzeSpecials = new Map([ node.template = templateStr; return node; }], + [JACLPKG.intern('%NEW'), (env, parent, form) => { + const [, ctor, ...args] = form; + const node = makeNode('new', { env: env, parent: parent, form: form }); + node.ctor = analyze(env.withContext('expr'), node, ctor); + node.args = args.map(x => analyze(env.withContext('expr'), node, x)); + return node; + }], [JACLPKG.intern('%LET'), (env, parent, form) => { const [, bindings, ...body] = form; const node = makeNode('let', { @@ -1518,6 +1526,19 @@ const emitNode = (print, node) => { } if (context !== 'expr') print(';\n'); break; + case 'new': + if (context === 'return') print('return '); + print('(new '); + emitNode(print, node.ctor); + print('('); + for (let i = 0; i < node.args.length; i++) { + emitNode(print, node.args[i]); + if (i < node.args.length-1) print(','); + } + print(')'); + print(')'); + if (context !== 'expr') print(';\n'); + break; case 'let': if (context === 'expr') print('(function()'); print('{');