Permalink
Browse files

rename mrb_load_irep for mrbtest to be consistent to name change

  • Loading branch information...
2 parents 471c00a + b8e5a57 commit be99d87ca49da86f1795bd1779f9ce82cf821a6e @bovi bovi committed Dec 5, 2012
Showing with 42 additions and 13 deletions.
  1. +3 −2 include/mruby/dump.h
  2. +34 −2 src/load.c
  3. +2 −1 src/parse.y
  4. +2 −7 test/init_mrbtest.c
  5. +1 −1 tools/mruby/mruby.c
View
@@ -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);
View
@@ -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 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
}
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));
+}
View
@@ -3307,7 +3307,8 @@ read_escape(parser_state *p)
int buf[3];
int i;
- for (i=0; i<3; i++) {
+ buf[0] = c;
+ for (i=1; i<3; i++) {
buf[i] = nextc(p);
if (buf[i] == -1) goto eof;
if (buf[i] < '0' || '7' < buf[i]) {
View
@@ -10,14 +10,9 @@ extern const char mrbgemtest_irep[];
void
mrb_init_mrbtest(mrb_state *mrb)
{
- int n = mrb_read_irep(mrb, mrbtest_irep);
+ mrb_load_irep(mrb, mrbtest_irep);
#ifdef ENABLE_GEMS
- int m = mrb_read_irep(mrb, mrbgemtest_irep);
-#endif
-
- mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
-#ifdef ENABLE_GEMS
- mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[m]), mrb_top_self(mrb));
+ mrb_load_irep(mrb, mrbgemtest_irep);
#endif
if (mrb->exc) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
View
@@ -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);
}

0 comments on commit be99d87

Please sign in to comment.