Created
March 19, 2018 15:08
-
-
Save yannick/cc075407a903c8ddb6e59ace8115609a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static mrb_value | |
b_eval(mrb_state *mrb, mrb_value self) | |
{ | |
char *s; | |
mrb_int len; | |
mrb_value binding = mrb_nil_value(); | |
char *file = NULL; | |
mrb_int line = 1; | |
struct RProc *proc; | |
int ai; | |
mrb_get_args(mrb, "s|ozi", &s, &len, &binding, &file, &line); | |
mrb_irep* irep = mrb_read_irep( mrb, (uint8_t*)s); | |
replace_stop_with_return(mrb, irep); | |
proc = mrb_proc_new(mrb, irep); | |
MRB_PROC_SET_TARGET_CLASS(proc, mrb->object_class); | |
ai = mrb_gc_arena_save(mrb); | |
mrb_yield_with_class(mrb, mrb_obj_value(proc), 0, NULL, mrb_top_self(mrb), mrb->object_class); | |
mrb_gc_arena_restore(mrb, ai); | |
return mrb_nil_value(); | |
} | |
static mrb_value | |
b_compile(mrb_state *mrb, mrb_value self) | |
{ | |
char *s; | |
mrb_int len; | |
mrb_value binding = mrb_nil_value(); | |
char *file = NULL; | |
mrb_int line = 1; | |
struct RProc *proc; | |
mrb_get_args(mrb, "s|ozi", &s, &len, &binding, &file, &line); | |
proc = create_proc_from_string(mrb, s, len, binding, file, line); | |
mrb_assert(!MRB_PROC_CFUNC_P(proc)); | |
mrb_irep *irep = proc->body.irep; | |
// convert irep to bytecode | |
uint8_t * bin_ptr; | |
size_t bin_size = 0; | |
uint8_t flags = 0; | |
//FIXME | |
int ok = mrb_dump_irep(mrb, irep, flags, &bin_ptr, &bin_size); | |
if( ok != 0) | |
{ | |
fprintf(stderr, "Error %d calling mrb_dump_irep \n", ok); | |
//FIXME: Raise | |
return mrb_nil_value(); | |
} | |
//bit binary data into mruby string | |
return mrb_str_new(mrb, bin_ptr, bin_size); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment