多级JavaScript
Multi-Stage JavaScript
摘要:
多阶段语言通过在实际解释或编译使用它们的程序之前的过程中评估的宏来支持生成元编程。宏通过发出代码来更新其宿主程序的源代码,这些代码在文件中占据它们的位置,而它们的代码也可以全部或部分由嵌套的宏生成。同一嵌套中的所有宏都属于同一级,外层收集的宏只影响主程序。我们用staging注释扩展了JavaScript,并在Spider Monkey中实现了它们,发出纯JavaScript代码作为stage计算的最终结果。我们讨论了如何最小限度地影响原来的蜘蛛猴系统的语法,解析器和内部AST结构的扩展,并增加了一个unparser,一个分级循环,一些库函数和调试器后端组件AST检查。由于stages具有生成元编程的作用,因此我们没有预见到与浏览器DOM的任何相互作用,因此没有理由在每次页面加载时重复它们的评估。因此,这样的JavaScript扩展仅用于开发时,生成可以在任何浏览器中运行的纯JavaScript代码。最后,为了在任何浏览器中启用调试阶段,我们实现了一个纯JavaScript客户端,与扩展的Spider Monkey通信,并提供浏览器调试器不提供的必要AST显示和解解析。
英文摘要:
Multi-stage languages support generative metaprogramming via macros evaluated in a process preceding the actual interpretation or compilation of the program in which they are used. Macros update the source of their hosting program by emitting code that takes their place in the file, while their code may also be produced, fully or partially, by nested macros. All macros at the same nesting belong to the same stage, with the outer stage collecting the macros affect-ing only the main program. We extended JavaScript with staging annotations and implemented them in Spider Monkey, emitting pure JavaScript code as the final outcome of stage computation. We discuss how the original Spider Monkey system is minimally affected with extensions in the syntax, parser and internal AST structures, and the addition of an unparser, a staging loop, some library functions and a debugger backend component for AST inspection. Since stages have a generative metaprogramming role we do not foresee any interplay with the browser DOM, and thus there is no reason to repeat their evalua-tion on every page load. Hence, such JavaScript extensions are meant only for development-time, emitting pure JavaScript code that can be run in any browser. Finally, to enable debugging stages in any browser we implemented a pure JavaScript client, communicating with the extended Spider Monkey, and offering the necessary AST display and unparsing that a browser debugger does not provide.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。