c++ - 有没有免费的 OCaml 到 C 的翻译器?

标签 c++ c ocaml

<分区>

所以我有很好的 OCaml 代码(50000 行)。我想将它移植到 C。那么有没有免费的 OCaml 到 C 转换器?

最佳答案

这可能不是您想要的,但您可以让 OCaml 编译器将其运行时代码转储到 C:

ocamlc -output-obj -o foo.c foo.ml

您得到的基本上是字节码的静态转储。结果将类似于:

#include <caml/mlvalues.h>
CAMLextern void caml_startup_code(
           code_t code, asize_t code_size,
           char *data, asize_t data_size,
           char *section_table, asize_t section_table_size,
           char **argv);
static int caml_code[] = {
0x00000054, 0x000003df, 0x00000029, 0x0000002a, 0x00000001, 0x00000000, 
/* ... */
}

static char caml_data[] = {
132, 149, 166, 190, 0, 0, 3, 153, 0, 0, 0, 118, 
/* ... */
};

static char caml_sections[] = {
132, 149, 166, 190, 0, 0, 21, 203, 0, 0, 0, 117, 
/* ... */
};

/* ... */

void caml_startup(char ** argv)
{
    caml_startup_code(caml_code, sizeof(caml_code),
                      caml_data, sizeof(caml_data),
                      caml_sections, sizeof(caml_sections),
                      argv);
}

你可以编译它

gcc -L/usr/lib/ocaml foo.c -lcamlrun -lm -lncurses

有关详细信息,请参阅 the OCaml manual .

关于c++ - 有没有免费的 OCaml 到 C 的翻译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18181684/

相关文章:

c++ - 是否可以在没有任何库的情况下编译 C++?

c++ - 用C++打印循环链表?

c++ - Netbeans "__cplusplus"定义错误

c - 字符串数组、strcpy 和字符串的问题

C 找出大数的质因数

c - 在这些条件下设置变量原子

ocaml - 超出程序结束的语法错误

ocaml - 无法使用 opam 安装 ctypes

c++ - 在 C++ 流中检索标志

ocaml - 加号运算符的OCaml类型