0

I am beginning with mruby, and I need a little in generating readable .c code using mrbc. I was following this article :

Here it is mentioned :

$ mruby/bin/mrbc -Cinit_tester test_program.rb

will produce test_program.c with some content.

but on my machine when I run this command it says :

mrbc: output file should be specified to compile multiple files

Then I tried

$ mruby/bin/mrbc -Binit_tester test_program.rb

which works , generates c files but its contents are only bytecode:

#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, };

Which is basically byte code of the mruby code that we have put in c code.

If you look at the blog m under section Readable C Code (.c), this should have actually generated c code.

why is the mrbc not generating readable c code ?

  • The example on that page isn't backed up by the options in the documentation: http://mruby.org/docs/articles/executing-ruby-code-with-mruby.html – Derrell Durrett Jul 06 '16 at 22:02

1 Answers1

0

why is the mrbc not generating readable c code?

Well, mrbc is a compiler to generate the binary format of ruby code with RiteVM understands so there is no way of generating a readable C code.

Instead with -v option you can see AST and VM codes of your code (I prefer to pass -c option too since mrbc will generate *.mrb files without it) .