值的Ocaml表示-原子 [英] Ocaml representation of values - Atoms
问题描述
我查看了一些OCaml值的内部表示.空数组的表示形式是atom(0)
,即具有tag=0
和size=0
的块.空的浮点数组也用atom(0)
表示.
I looked at the internal representation of some OCaml values. The representation of an empty array is an atom(0)
, i.e. a block with tag=0
and size=0
. Empty arrays of floats are represented by an atom(0)
too.
是否存在用tag > 0
的原子表示的OCaml值?如果不是:OCaml字节码集出于什么目的包含ATOM n
指令?
Is there any OCaml value represented by an atom with tag > 0
? If not: for what purpose the OCaml bytecode set contains the ATOM n
instruction?
推荐答案
标记> 0用于带有参数的构造函数,这会使它们不是原子.另一方面,不带参数的构造函数存储为int而不是块,因此也不存储原子.因此,我认为不使用atom(0).除了...
A tag > 0 is used for constructors with arguments, which would make them not atoms. Constructors without arguments on the other hand are stored as int instead of blocks so again not atoms. So I think atom(0) is not used. Except ...
拥有一个内联记录为空的构造函数该怎么办?
What about having a constructor with inline record that is empty?
# type t = A of int | B of { };;
Error: Syntax error
似乎不允许空记录.除了直接创建这样的块,我想不出另一种方法来创建带有标签的0大小的块.但这不会使用ATOM指令.
Seems empty records are not allowed. I can't think of another way to create a 0 size block with tag other than creating such a block directly. But that wouldn't be using the ATOM instruction.
这篇关于值的Ocaml表示-原子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!