简体   繁体   English

Ocaml值的表示 - 原子

[英]Ocaml representation of values - Atoms

I looked at the internal representation of some OCaml values. 我查看了一些OCaml值的内部表示。 The representation of an empty array is an atom(0) , ie a block with tag=0 and size=0 . 空数组的表示是atom(0) ,即tag=0size=0 Empty arrays of floats are represented by an atom(0) too. 空的浮点数也由atom(0)表示。

Is there any OCaml value represented by an atom with tag > 0 ? 是否有任何OCaml值由tag > 0的原子表示? If not: for what purpose the OCaml bytecode set contains the ATOM n instruction? 如果不是:为什么OCaml字节码集包含ATOM n指令?

A tag > 0 is used for constructors with arguments, which would make them not atoms. 标签> 0用于带参数的构造函数,这将使它们不是原子。 Constructors without arguments on the other hand are stored as int instead of blocks so again not atoms. 另一方面,没有参数的构造函数存储为int而不是块,因此也不是原子。 So I think atom(0) is not used. 所以我认为不使用atom(0)。 Except ... 除了 ...

What about having a constructor with inline record that is empty? 如果构造函数的内联记录为空?

# type t = A of int | B of { };;
Error: Syntax error

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. 除了直接创建这样的块之外,我想不出用标签创建0大小块的另一种方法。 But that wouldn't be using the ATOM instruction. 但那不会使用ATOM指令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM