我正在设计一种编译为中间字节码的编程语言。 然而,我在设计字节码结构时遇到了很多麻烦。 有人知道如何用二进制表示程序吗? 或者,是否有任何关于如何执行此操作的资源(最好是免费的)? 我发现的最接近的是 Lua 解释器的描述字节码。
编辑:更多信息:我正在实现我自己的垃圾收集方案,该方案针对不变性和并发性进行了大量优化。 为了提高效率,我需要一些独特的字节码指令,允许程序与垃圾收集方案进行交互。
I'm designing a programming language which compiles to an intermediary bytecode. However, I'm having a lot of trouble designing the bytecode structure. Does anybody have any pointers on how to represent a program in binary? Alternatively, are there any resources (preferably free) on how to do this? The closest I've found is the description of the Lua interpreter's bytecode.
EDIT: A bit more information: I'm implementing my own garbage collection scheme which is heavily optimized for immutability and concurrency. For efficiencies' sake I need some unique bytecode instructions that allow programs to interact with the garbage collection scheme.
发布评论
评论(4)
不要设计你的字节码这是不必要的!
我建议查看 LLVM 和 GNU Lightning 为您做了很多艰苦的工作,只要求您在注释完内容并解决范围等之后创建一个类似 AST 的翻译模式。
龙书还包括一些关于字节码的章节。 计算机编程的艺术也可能有所帮助,因为 Mix 语言陈述了一些(过时的)但重要的设计决策。
实际上,您的中间代码应该是:
这完全取决于您的要求,除非需要,否则不要设计自己的 IR/字节码。 如果有其他合适的东西,就使用它! 你不需要维护它!
Don't design your bytecode it is unnecessary!
I would recommend looking into LLVM and GNU Lightning that do alot of the hard-work for you and just demand you create an AST-like schema for translation after you have annotated things out and resolved scope and so on.
The dragon book also includes some sections on bytecode. The Art of Computer Programming might also help as the Mix language states some (dated) but important design decisions.
Really, your intermediate code should be:
It is all about your requirements, don't design your own IR/bytecode unless you need to. If something else fits, use it! You don't need to maintain it!
本文介绍了 GNU Smalltalk VM 及其字节码。 谷歌搜索“smalltalk bytecode”会找到其他资源。
This article describes the GNU Smalltalk VM and its bytecode. Googling for "smalltalk bytecode" will come up with other resources.
您可以查看python 字节码指令列表,以及使用 dis 模块 查看为简单程序生成的字节码。
请参阅how-many-places-are-optimized-in -pythons-bytecodeversion-2-5 用于讨论字节码优化。
You can go over a list of python bytecode instructions, and use the dis module to see what bytecodes are generated for simple programs.
See how-many-places-are-optimized-in-pythons-bytecodeversion-2-5 for discussion of bytecode optimiztaion.
您可能会发现查看有关字节码的 Wikipedia 文章很有用 http://en.wikipedia.org/wiki/Bytecode" 并遵循对该时代和风格的语言的一些引用你对。。。感兴趣。
You may find it useful to look at the Wikipedia article on Bytecode http://en.wikipedia.org/wiki/Bytecode" and follow some of the references to languages of the age and style you are interested in.