gpt4 book ai didi

c - mruby:生成可读的 C 代码

转载 作者:行者123 更新时间:2023-11-30 17:01:26 25 4
gpt4 key购买 nike

我从 mruby 开始,我需要一些使用 mrbc 生成可读的 .c 代码。我正在关注this article :

这里提到:

$ mruby/bin/mrbc -Cinit_tester test_program.rb

将生成包含一些内容的test_program.c。

但在我的机器上,当我运行此命令时,它显示:

mrbc: output file should be specified to compile multiple files

然后我尝试了

$ mruby/bin/mrbc -Binit_tester test_program.rb

它可以工作,生成c文件,但其内容只是字节码:

#include <stdint.h>
const uint8_t init_tester[] = {0x45,0x54,0x49,0x52,0x30,0x30,0x30,0x33,0x73,0x0d,0x00,0x00,0x00,0x65,0x4d,0x41,0x54,0x5a,0x30,0x30,0x30,0x30,0x49,0x52,0x45,0x50,0x00,0x00,0x00,0x47,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x3f,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04,0x06,0x00,0x80,0x00,0x3d,0x00,0x00,0x01,0xa0,0x00,0x80,0x00,0x4a,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x0b,0x68,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,0x6c,0x64,0x00,0x00,0x00,0x01,0x00,0x04,0x70,0x75,0x74,0x73,0x00,0x45,0x4e,0x44,0x00,0x00,0x00,0x00,0x08, };

这基本上是我们放入 c 代码中的 mruby 代码的字节码。

如果您查看可读 C 代码 (.c) 部分下的博客 m,这实际上应该生成了 C 代码。

为什么 mrbc 不生成可读的 C 代码?

最佳答案

why is the mrbc not generating readable c code?

嗯,mrbc 是一个编译器,用于生成 RiteVM 可以理解的二进制格式的 ruby​​ 代码,因此无法生成可读的 C 代码。

使用 -v 选项,您可以看到代码的 AST 和 VM 代码(我也更喜欢传递 -c 选项,因为如果没有它,mrbc 将生成 *.mrb 文件)。

关于c - mruby:生成可读的 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37066161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com