python字节码、解释器和虚拟机

发布于 2024-10-02 02:59:40 字数 376 浏览 0 评论 0原文

这是一个非常广泛的问题,我主要是在寻找可以了解以下内容的更多资源。

我知道 python 解释器是用 C 编写的,并生成在同样用 C 编写的 python 虚拟机上运行的字节码(对吗?)。我的问题是可以用 python 本身实现这两个功能吗?我想我要去的地方是用Python在操作系统上编写类似的东西的(技术)可能性,特别是在不静态编译任何东西的情况下?

如果我理解正确的话,python 没有汇编器,而汇编器也必须用 python 编写。这些事情在技术上(可行吗?) 可以完成吗?或者 python 的动态类型会带来某种问题吗?

我对微处理器体系结构、汇编和机器代码了解一些,这些都是最近的 EE 毕业生在学校学到的知识。但是对于像 python 这样的高级语言,我在看全局时会迷失方向。

This is a really vast question and I'm mostly looking for resources where I can learn more about the following.

I know the python interpreter is written in C and produces bytecode to be run on the python virtual machine also written in C (right?). My question is would it be possible to implement both of these in python itself? I guess where I'm going with this is the (technical) possibility of writing something like on OS in python, particularly WITHOUT statically compiling anything?

If I understand correctly, python doesn't have an assembler which would have to be written as well in python. Are these things something that could technically (feasibly?) be done? Or would the dynamic typing of python pose some kind of problem?

I know a bit about microprocessor architecture, assembly and machine code, what a recent EE grad learns in school. But I get lost looking at the whole picture for higher level languages like python.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

痴骨ら 2024-10-09 02:59:40

编译器,而不是解释器。但您正在寻找 PyPy

Compiler, not interpreter. But you're looking for PyPy.

复古式 2024-10-09 02:59:40

您首先需要使用任何语言(最好是 Python)编写一个 Python 编译器(而不是解释器)。编译器的第一次运行需要通过解释器运行。

然后,您可以自行编译编译器,从而生成不需要解释器的本机编译器。

然后,您可以使用编译器将任何 Python 编译为本机代码。

这个过程称为引导,并且被许多(如果不是大多数)主要编译器用于许多语言。

您可以在此处阅读有关此过程的更多信息: http://en.wikipedia.org/wiki/ Bootstrapping_(compilers)

至于创建操作系统,如果您想避免编译代码,则至少需要实现一个 Python 解释器。如果将 Python 解释器编写为微内核,则可以用 Python 编写操作系统的其余部分。 (编辑:我只是无意中描述了贾罗提到的克莱斯:))

You would first need to write a Python compiler (not interpreter), in any language, preferably Python. The first run of the compiler would need to be run throught the interpreter.

You would then compile your compiler with itself, leading to a native compiler that needs no interpreter.

You could then use the compiler to compile any Python to native code.

This process is called bootstrapping, and is used by many, if not most, major compilers for many languages.

You can read more about this process here: http://en.wikipedia.org/wiki/Bootstrapping_(compilers)

As for creating an operating system, you would need to implement, as a bare minimum, a Python interpreter, if you want to avoid compiled code. If you write a Python interpreter as a microkernel, you could write the rest of the operating system in Python. (Edit: I just inadvertently described Cleese, which Jiaaro mentioned :))

谎言 2024-10-09 02:59:40

James Tauber 还用 Python 构建了一个名为 Cleese 的概念验证操作系统,并且最近开始努力实现它致力于 Pypy (用 python 编写的 python 解释器)

James Tauber has also built a proof of concept OS in python called Cleese, and has recently begun an effort to get it working on Pypy (python interpreter written in python)

分開簡單 2024-10-09 02:59:40

关于操作系统的实现问题,你需要一种系统编程语言来实现操作系统。除非你能想出一个 python 汇编器并将 python 转换为不需要虚拟机的直接可执行二进制文件,否则用纯 python 完成这一切是不可能的。

如果您想用汇编语言编写代码并让 python 为您汇编它,请查看稍微过时的实验性

Regarding the OS implementation question, you need a system programming language to implement an OS. Doing it all in pure python will not be possible unless you can dream up a python assembler and convert python to directly executable binaries no VM needed.

If you want to code in assembly and get python to assemble it for you, have a look at slightly dated and experimental pyasm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文