许多external
声明中OCaml的标准库中的函数名称的开头有一个%,如int_of_float
定义:OCaml外部声明中的%意味着什么?
external int_of_float : float -> int = "%intoffloat"
什么是“%”是什么意思?
许多external
声明中OCaml的标准库中的函数名称的开头有一个%,如int_of_float
定义:OCaml外部声明中的%意味着什么?
external int_of_float : float -> int = "%intoffloat"
什么是“%”是什么意思?
有很多%foo
隐藏在编译器中的特殊原语。我认为在ocaml编译器源代码中的最佳列表可以在bytecomp/translcore.ml
中找到。让我们看看有多少可以在这里列出:
这些比较有专门的版本INT ,float,string,nativeint,int32和int64,并且如果类型在编译时已知,它将自动专门化。
%identity, %ignore, %field0, %field1, %setfield0, %makeblock, %makemutable, %raise, %incr, %decr, %seqand, %seqor, %boolnot
%negint, %succint, %predint, %addint, %subint, %mulint, %divint, %modint, %andint, %orint, %xorint, %lslint, %lsrint, %asrint
%eq, %noteq, %ltint, %leint, %gtint, %geint
%intoffloat, %floatofint, %negfloat, %absfloat, %addfloat, %subfloat, %mulfloat, %divfloat
%eqfloat, %noteqfloat, %ltfloat, %lefloat, %gtfloat, %gefloat
%string_length, %string_safe_get, %string_safe_set, %string_unsafe_get, %string_unsafe_set
%array_length, %array_safe_get, %array_safe_set, %array_unsafe_get, %array_unsafe_set
%obj_size, %obj_field, %obj_set_field, %obj_is_int
%lazy_force
%{nativeint,int32,int64}: _of_int, _to_int, _neg, _add, _sub, _mul, _div, _mod, _and, _or, _xor, _lsl, _lsr, _asr
%nativeint_{of,to}_int32, int64_{of,to}_int32, int64_{of,to}_nativeint
%caml_ba_ref_{1,2,3}, %caml_ba_set_{1,2,3}, %caml_ba_unsafe_ref_{1,2,3}, %caml_ba_unsafe_set_{1,2,3}
%send, %sendself, %sendcache
这就是我能找到的。
外部的%是特殊的外部,这将由编译器专门处理。例如,使用int_of_float,ocamlc会将其编译为某个C函数的调用,但使用ocamlopt时,它会将其编译为一些特殊的汇编程序操作码,将double转换为整数。
我想知道它是否可能是这样的。你知道这个功能和可用的魔法名称是否记录在任何地方吗? – 2009-12-16 21:26:42