author | Alan Dipert
<alan@dipert.org> 2019-11-11 17:28:19 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-11-11 17:28:19 UTC |
parent | 83433da172c25328cbe33588db262d478685daa1 |
jacl.js | +14 | -6 |
diff --git a/jacl.js b/jacl.js index f595457..6336f65 100644 --- a/jacl.js +++ b/jacl.js @@ -1689,18 +1689,26 @@ const emitNode = (print, node) => { emitNode(print, stmt); } if (node.tags.size) { - const firstTag = () => { - const name = node.tags.entries().next().value[0]; - return typeof name === 'number' ? name : `'${escapeSingle(name)}'`; - }; - print(`tagbody_${node.id}_to=${firstTag()};\n`); + const formatTag = x => typeof x === 'number' + ? x.toString() + : `'${escapeSingle(x)}'`; + const firstTag = formatTag(node.tags.entries().next().value[0]); + print(`tagbody_${node.id}_to=${firstTag};\n`); print(`tagbody_${node.id}:while(true){\n`); - print(`break;`); + print(`switch(tagbody_${node.id}_to){\n`); + for (const [tag, stmts] of node.tags) { + print(`case ${formatTag(tag)}:\n`); + for (const stmt of stmts) emitNode(print, stmt); + } + print(`default:\nbreak tagbody_${node.id};\n`); + print('}\n'); print('}\n'); } } //if (context !== 'sval') print(';\n'); break; + } case 'go': { + throw new Error('TODO emit go'); } default: throw new Error(`Unknown op: ${op}`); }