rename mrb_load_irep etc. for naming consistency

parent c7a2af38
......@@ -16,9 +16,10 @@ extern "C" {
#include <stdint.h>
int mrb_dump_irep(mrb_state*,int,FILE*);
int mrb_load_irep(mrb_state*,FILE*);
int mrb_load_irep_offset(mrb_state*,FILE*,long);
int mrb_read_irep(mrb_state*,const char*);
int mrb_read_irep_file(mrb_state*,FILE*);
mrb_value mrb_load_irep(mrb_state*,const char*);
mrb_value mrb_load_irep_file(mrb_state*,FILE*);
int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
......
......@@ -11,6 +11,7 @@
#ifdef ENABLE_REGEXP
#include "re.h"
#endif
#include "mruby/proc.h"
#include "mruby/irep.h"
typedef struct _RiteFILE
......@@ -28,7 +29,7 @@ const char hex2bin[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, //30-3f
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, //40-4f
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //50-5f
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 //60-6f
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 //60-6f
//70-ff
};
......@@ -241,7 +242,7 @@ error_exit:
}
int
mrb_load_irep(mrb_state *mrb, FILE* fp)
mrb_read_irep_file(mrb_state *mrb, FILE* fp)
{
int ret, i;
uint32_t len, rlen = 0;
......@@ -659,3 +660,34 @@ hex_to_str(char *hex, char *str, uint16_t *str_len)
}
return str;
}
static void
irep_error(mrb_state *mrb, int n)
{
static const char msg[] = "irep load error";
mrb->exc = (struct RObject*)mrb_object(mrb_exc_new(mrb, E_SCRIPT_ERROR, msg, sizeof(msg) - 1));
}
mrb_value
mrb_load_irep_file(mrb_state *mrb, FILE* fp)
{
int n = mrb_read_irep_file(mrb, fp);
if (n < 0) {
irep_error(mrb, n);
return mrb_nil_value();
}
return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
}
mrb_value
mrb_load_irep(mrb_state *mrb, const char *bin)
{
int n = mrb_read_irep(mrb, bin);
if (n < 0) {
irep_error(mrb, n);
return mrb_nil_value();
}
return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
}
......@@ -9,9 +9,7 @@ extern const char mrbtest_irep[];
void
mrb_init_mrbtest(mrb_state *mrb)
{
int n = mrb_read_irep(mrb, mrbtest_irep);
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
mrb_load_irep(mrb, mrbtest_irep);
if (mrb->exc) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
exit(0);
......
......@@ -238,7 +238,7 @@ main(int argc, char **argv)
mrb_define_global_const(mrb, "ARGV", ARGV);
if (args.mrbfile) {
n = mrb_load_irep(mrb, args.rfp);
n = mrb_read_irep_file(mrb, args.rfp);
if (n < 0) {
fprintf(stderr, "failed to load mrb file: %s\n", args.cmdline);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment