有没有免费的OCaml到C翻译? [英] Is there any free OCaml to C translator?
本文介绍了有没有免费的OCaml到C翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我有很好的OCaml code(50000行)。我想把它移植到C.那么,有没有免费的OCaml到C翻译?
So I have nice OCaml code (50000 lines). I want to port it to C. So Is there any free OCaml to C translator?
推荐答案
这可能不是你想要的,但你可以得到OCaml的编译器抛售其运行时的code在C:
This probably isn't what you want, but you can get the OCaml compiler to dump its runtime code in C:
ocamlc -output-obj -o foo.c foo.ml
你得到的基本上是字节code的静态转储。其结果将类似于:
What you get is basically a static dump of the bytecode. The result will look something like:
#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
有关详细信息,请参阅 OCaml的手动一>
For more information, see the OCaml manual.
这篇关于有没有免费的OCaml到C翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文