这个三行 Forth 模块系统是如何工作的?
How does this three line Forth module system work?
我已经开始阅读 Thinking Forth. In the book the author mentions a three-line module system with a reference to the proceedings of a Forth conference. Here's a PDF containing a description of the module system 从第 14 页开始,(印刷为 132)。
这里是关于如何使用三个定义词 INTERNAL
、EXTERNAL
和 MODULE
的说明。
A module is a portion of a program between the words INTERNAL and
MODULE. Definitions of constants, variables and routines which are
local to the module are written between the words INTERNAL and
EXTERNAL. Definitions which are to be used outside the module are
written between the words EXTERNAL and MODULE. [Local variables for a
routine] are defined between INTERNAL and EXTERNAL. The routine which
references them is defined between EXTERNAL and MODULE.
这是代码本身:
: INTERNAL ( --> ADDR) CURRENT @ @ ;
: EXTERNAL ( --> ADDR) HERE ;
: MODULE( ADDRl ADDR2 --> )PFA LFA ! ;
我读这本书是为了了解如何编写一般软件的想法,而不是如何在 Forth 的任何特定实现中进行编程,所以我不熟悉代码中使用的内置词,但我对这个模块系统很好奇。有人可以解释一下它是如何工作的吗?
我会改写描述。模块应如下所示:
INTERNAL
... code ...
EXTERNAL
... more code ...
MODULE
实现此模块系统的代码假定字典是一个传统的单 linked 列表。 INTERNAL
保存指向当前单词的指针,例如INTERNAL
之前的那个。 EXTERNAL
保存指向 EXTERNAL
之后的单词的指针。 MODULE
获取两个指针,并修补 EXTERNAL
之后单词的 link 字段以指向 INTERNAL
之前的单词。实际上,它使字典跳过 INTERNAL
和 EXTERNAL
.
之间的所有单词
这在现代 Forth 中可能行不通,因为单词 CURRENT
、PFA
和 LFA
没有标准化。而且,HERE
可能不是下一个词的 header 的正确地址。
我已经开始阅读 Thinking Forth. In the book the author mentions a three-line module system with a reference to the proceedings of a Forth conference. Here's a PDF containing a description of the module system 从第 14 页开始,(印刷为 132)。
这里是关于如何使用三个定义词 INTERNAL
、EXTERNAL
和 MODULE
的说明。
A module is a portion of a program between the words INTERNAL and MODULE. Definitions of constants, variables and routines which are local to the module are written between the words INTERNAL and EXTERNAL. Definitions which are to be used outside the module are written between the words EXTERNAL and MODULE. [Local variables for a routine] are defined between INTERNAL and EXTERNAL. The routine which references them is defined between EXTERNAL and MODULE.
这是代码本身:
: INTERNAL ( --> ADDR) CURRENT @ @ ;
: EXTERNAL ( --> ADDR) HERE ;
: MODULE( ADDRl ADDR2 --> )PFA LFA ! ;
我读这本书是为了了解如何编写一般软件的想法,而不是如何在 Forth 的任何特定实现中进行编程,所以我不熟悉代码中使用的内置词,但我对这个模块系统很好奇。有人可以解释一下它是如何工作的吗?
我会改写描述。模块应如下所示:
INTERNAL
... code ...
EXTERNAL
... more code ...
MODULE
实现此模块系统的代码假定字典是一个传统的单 linked 列表。 INTERNAL
保存指向当前单词的指针,例如INTERNAL
之前的那个。 EXTERNAL
保存指向 EXTERNAL
之后的单词的指针。 MODULE
获取两个指针,并修补 EXTERNAL
之后单词的 link 字段以指向 INTERNAL
之前的单词。实际上,它使字典跳过 INTERNAL
和 EXTERNAL
.
这在现代 Forth 中可能行不通,因为单词 CURRENT
、PFA
和 LFA
没有标准化。而且,HERE
可能不是下一个词的 header 的正确地址。