Skip to content

Instantly share code, notes, and snippets.

@scalone
Created May 12, 2014 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalone/49ed1646204b7aed839e to your computer and use it in GitHub Desktop.
Save scalone/49ed1646204b7aed839e to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
/* Include the mruby headers */
#include <mruby.h>
#include <mruby/compile.h>
#include "mruby/irep.h"
#include "mruby/dump.h"
#include "mruby/proc.h"
int main(int argc, const char * argv[])
{
size_t bin_size = 0;
uint8_t *bin = NULL;
mrbc_context *c;
mrb_value result;
mrb_state *mrb;
char file_name[] = "hello4.mrb";
char file_name_rb[] = "hello4.rb";
FILE* file;
FILE* file_rb;
int ret_dump = MRB_DUMP_OK;
int index = 0;
printf("\nParse code and create irep");
mrb = mrb_open();
file_rb = fopen(file_name_rb, "r");
c = mrbc_context_new(mrb);
c->no_exec = 1;
//DEBUG
//c->dump_result = 1;
mrb->c = c;
index = mrb->irep_len;
result = mrb_load_file_cxt(mrb, file_rb, c);
printf("\nresult %d", mrb_fixnum(result));
mrbc_context_free(mrb, c);
printf("\nDump irep");
file = fopen(file_name, "wb");
ret_dump = mrb_dump_irep_binary(mrb, index, 0, file);
printf("\nmrb_dump_irep %d", ret_dump);
fclose(file);
mrb_close(mrb);
printf("\nExecute irep\n");
mrb = mrb_open();
file = fopen(file_name, "r");
mrb_load_irep_file(mrb, file);
mrb_close(mrb);
fclose(file);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment