自托管的概念
The concept of Self-Hosting
所以我正在开发一种小型编程语言,并试图掌握 "Self-Hosting" 的概念。
维基百科指出:
The first self-hosting compiler (excluding assemblers) was written for Lisp by Hart and Levin at MIT in 1962. They wrote a Lisp compiler in Lisp, testing it inside an existing Lisp interpreter. Once they had improved the compiler to the point where it could compile its own source code, it was self-hosting.
据此,我了解到有人拥有 Lisp 解释器(让我们在 Python 中说)。
Python 程序然后读取一个 Lisp 程序,该程序反过来也可以读取 Lisp 程序。
术语 "Self-Hosting",这当然不能意味着 Python 程序可以停止使用,因为删除它会删除 运行 Lisp 的能力读取其他 Lisp 程序的程序!
因此,程序如何能够直接在 OS 上托管自己?可能是我理解的不正确。
在这种情况下,术语自托管适用于他们编写的 Lisp 编译器,而不是解释器。
Python Lisp 解释器(如您的示例)将 Lisp 源代码作为输入,并直接执行它。
Lisp 编译器(用 lisp 编写)可以将任何 Lisp 源作为输入并生成本地机器二进制文件[1]作为输出(然后可以 运行 无需解释器)。
有了这两块,消除Python就变得可行了。流程如下:
python.exe lispinterpret.py lispcompiler.lisp -i lispcompiler.lisp -o lispcompiler.exe
我们要求 Python 从源代码 (lispcompiler.lisp) 解释一个 lisp 程序,然后我们将 lispcompiler.lisp 本身作为输入。 lispcompiler.lisp 然后输出 lispcompiler.exe 作为输出,这是一个本地机器二进制文件(并且不依赖于 Python)。
下次要编译编译器,命令为:
lispcompiler.exe -i lispcompiler.lisp -o lispcompiler2.exe
并且您将拥有一个不使用 Python 的新编译器。
[1] 或者您可以生成汇编代码,然后传递给汇编程序。
所以我正在开发一种小型编程语言,并试图掌握 "Self-Hosting" 的概念。
维基百科指出:
The first self-hosting compiler (excluding assemblers) was written for Lisp by Hart and Levin at MIT in 1962. They wrote a Lisp compiler in Lisp, testing it inside an existing Lisp interpreter. Once they had improved the compiler to the point where it could compile its own source code, it was self-hosting.
据此,我了解到有人拥有 Lisp 解释器(让我们在 Python 中说)。
Python 程序然后读取一个 Lisp 程序,该程序反过来也可以读取 Lisp 程序。
术语 "Self-Hosting",这当然不能意味着 Python 程序可以停止使用,因为删除它会删除 运行 Lisp 的能力读取其他 Lisp 程序的程序!
因此,程序如何能够直接在 OS 上托管自己?可能是我理解的不正确。
在这种情况下,术语自托管适用于他们编写的 Lisp 编译器,而不是解释器。
Python Lisp 解释器(如您的示例)将 Lisp 源代码作为输入,并直接执行它。
Lisp 编译器(用 lisp 编写)可以将任何 Lisp 源作为输入并生成本地机器二进制文件[1]作为输出(然后可以 运行 无需解释器)。
有了这两块,消除Python就变得可行了。流程如下:
python.exe lispinterpret.py lispcompiler.lisp -i lispcompiler.lisp -o lispcompiler.exe
我们要求 Python 从源代码 (lispcompiler.lisp) 解释一个 lisp 程序,然后我们将 lispcompiler.lisp 本身作为输入。 lispcompiler.lisp 然后输出 lispcompiler.exe 作为输出,这是一个本地机器二进制文件(并且不依赖于 Python)。
下次要编译编译器,命令为:
lispcompiler.exe -i lispcompiler.lisp -o lispcompiler2.exe
并且您将拥有一个不使用 Python 的新编译器。
[1] 或者您可以生成汇编代码,然后传递给汇编程序。