From f05be6a605b6ccbd0168702eefa0653b41388eea Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Fri, 5 Jun 2015 11:17:44 +0800 Subject: [PATCH 1/3] load bytecode from file if available --- load.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/load.c b/load.c index e5014c165faef0..4f753f2c521b92 100644 --- a/load.c +++ b/load.c @@ -9,6 +9,8 @@ #include "eval_intern.h" #include "probes.h" #include "node.h" +#include "iseq.h" +#include "vm_debug.h" VALUE ruby_dln_librefs; @@ -606,12 +608,25 @@ rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap) if (state == 0) { NODE *node; VALUE iseq; - - th->mild_compile_error++; - node = (NODE *)rb_load_file_str(fname); - loaded = TRUE; - iseq = rb_iseq_new_top(node, rb_str_new2(""), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse); - th->mild_compile_error--; + VALUE io; + VALUE fcname = rb_str_plus(fname, rb_str_new2("o")); + + if (RTEST(rb_funcall(rb_cFile, rb_intern("exist?"), 1, fcname))) { + dpv("loading bytecode from", fcname); + iseq = rb_iseq_load(rb_marshal_load(rb_funcall(rb_cIO, rb_intern("binread"), 1, fcname)), Qnil, Qnil); + loaded = TRUE; + } else { + th->mild_compile_error++; + node = (NODE *)rb_load_file_str(fname); + loaded = TRUE; + iseq = rb_iseq_new_top(node, rb_str_new2(""), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse); + th->mild_compile_error--; + + io = rb_file_open_str(fcname, "w"); + rb_marshal_dump(rb_funcall(iseq, rb_intern("to_a"), 0), io); + rb_io_close(io); + dpv("wrote bytecode to", fcname); + } rb_iseq_eval(iseq); } POP_TAG(); From 50847d6d07ae84cb54c8ba5201fa307ae0a052de Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Fri, 5 Jun 2015 11:58:21 +0800 Subject: [PATCH 2/3] fix iseq_load of cdhash labels --- compile.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/compile.c b/compile.c index 1c0309ac8502aa..901fcb15c8d090 100644 --- a/compile.c +++ b/compile.c @@ -1560,15 +1560,22 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) } case TS_CDHASH: { + int i; VALUE map = operands[j]; struct cdhash_set_label_struct data; - data.hash = map; - data.pos = pos; - data.len = len; - rb_hash_foreach(map, cdhash_set_label_i, (VALUE)&data); + data.hash = map; + data.pos = pos; + data.len = len; + if (RB_TYPE_P(map, T_ARRAY)) { + data.hash = rb_hash_new(); + for (i=0; i Date: Sat, 6 Jun 2015 16:40:04 +0800 Subject: [PATCH 3/3] backport local table fix --- iseq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iseq.c b/iseq.c index 700a161f6bc3e6..a5823f629daaba 100644 --- a/iseq.c +++ b/iseq.c @@ -1718,7 +1718,12 @@ iseq_data_to_ary(rb_iseq_t *iseq) for (i=0; ilocal_table_size; i++) { ID lid = iseq->local_table[i]; if (lid) { - if (rb_id2str(lid)) rb_ary_push(locals, ID2SYM(lid)); + if (rb_id2str(lid)) { + rb_ary_push(locals, ID2SYM(lid)); + } + else { /* hidden variable from id_internal() */ + rb_ary_push(locals, ULONG2NUM(iseq->local_table_size-i+1)); + } } else { rb_ary_push(locals, ID2SYM(rb_intern("#arg_rest")));