在Python虚拟机中创建新语言 [英] Creating a new language within the Python virtual machine

查看:188
本文介绍了在Python虚拟机中创建新语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为Python虚拟机创建新语言?我正在阅读 http://late.am/post/2012/03/26/exploring-python-code-objects ,博主在其中讨论Python代码对象.在其中,他讨论了将代码对象分解为字节码以及其中的符号的含义.

Is it possible to create a new language for the Python Virtual Machine? I was reading over http://late.am/post/2012/03/26/exploring-python-code-objects , where the blogger discusses Python code objects. In it, he discusses a disassembly of a code object into bytecode and what the symbols in it mean.

这使我认为可以使用替代方法来构造此字节码.我很好奇能否在Python字节码中创建沙盒语言,以便Python可以加载它的能力.使用Python本身进行沙箱似乎几乎是不可能的,但这似乎为另一种实现语言铺平了道路.

This made me think there could be alternative ways to construct this bytecode. I was curious about the ability to create a sandboxed language within Python bytecode so that Python could load it up. Using Python itself for sandboxing seems darn near impossible, but this appears to make a pathway for another implementation language.

如果我想从事这项事业,我将从何处开始?什么是更好的方法?在其他方法中我可以从哪里找到更多信息?

Where would I start if I wanted to pursue this venture? What might be a better approach, and where would I find more on other approaches?

推荐答案

为什么幸运的僵硬一旦一起入侵一个脚本,该脚本会将Ruby代码编译为Python字节码.我记得它对于简单的Ruby脚本非常有效.您可以查看资料来源,了解他的工作方式.

Why the lucky stiff once hacked together a script that would compile Ruby code into Python bytecode. I remember that it worked well for simple Ruby scripts. You can look at the sources to see how he did it.

编辑:所以他要做的是让Ruby VM生成Ruby字节码,而不是将该字节码转换为Python.仍然很有趣,看看Python字节码是如何组装的:)

EDIT: So what he does is let the Ruby VM generate Ruby bytecode, than translate that bytecode to Python. Could still be interesting to see how the Python bytecode is assembled :)

这篇关于在Python虚拟机中创建新语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆