summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--eval_intern.h2
-rw-r--r--gc.c4
-rw-r--r--internal.h13
-rw-r--r--vm.c8
-rw-r--r--vm_eval.c6
-rw-r--r--vm_insnhelper.c4
-rw-r--r--vm_insnhelper.h24
8 files changed, 56 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 00eceef6d0..15241f646f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+Wed Mar 11 21:45:36 2015 Koichi Sasada <ko1@atdot.net>
+
+ * vm_insnhelper.h: use T_IMEMO to create THROW_DATA.
+
+ Add THROW_DATA_NEW().
+
+ * internal.h: move defnition of `struct THROW_DATA'
+ from vm_insnhelper.h to internal.h.
+
+ Rename `THROW_DATA' to `vm_throw_data'.
+
+ * eval_intern.h (THROW_DATA_P): move to internal.h.
+ THROW_DATA is no longer T_NODE, so check T_IMEMO.
+
+ * gc.c (gc_mark_children): mark THROW_DATA.
+
+ * vm.c: catch up these changes.
+
+ * vm_eval.c: ditto.
+
+ * vm_insnhelper.c: ditto.
+
Wed Mar 11 21:21:56 2015 Koichi Sasada <ko1@atdot.net>
* vm_insnhelper.c: use T_IMEMO to create SVAR.
diff --git a/eval_intern.h b/eval_intern.h
index 605c2aa2ed..d41368e628 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -199,8 +199,6 @@ enum ruby_tag_type {
#define TAG_FATAL RUBY_TAG_FATAL
#define TAG_MASK RUBY_TAG_MASK
-#define THROW_DATA_P(err) RB_TYPE_P((err), T_NODE)
-
#define SCOPE_TEST(f) (CREF_VISI(rb_vm_cref()) & (f))
#define SCOPE_CHECK(f) (CREF_VISI(rb_vm_cref()) == (f))
#define SCOPE_SET(f) (CREF_VISI_SET(rb_vm_cref(), (f)))
diff --git a/gc.c b/gc.c
index a7b2c6a0f0..ae1accd8e3 100644
--- a/gc.c
+++ b/gc.c
@@ -383,6 +383,7 @@ typedef struct RVALUE {
union {
rb_cref_t cref;
struct vm_svar svar;
+ struct vm_throw_data throw_data;
} imemo;
struct {
struct RBasic basic;
@@ -4163,6 +4164,9 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
gc_mark(objspace, RANY(obj)->as.imemo.svar.backref);
gc_mark(objspace, RANY(obj)->as.imemo.svar.others);
return;
+ case imemo_throw_data:
+ gc_mark(objspace, RANY(obj)->as.imemo.throw_data.throw_obj);
+ return;
default:
rb_bug("T_IMEMO: unreachable");
}
diff --git a/internal.h b/internal.h
index 0a4bcba5fa..af1d267b84 100644
--- a/internal.h
+++ b/internal.h
@@ -533,6 +533,7 @@ enum imemo_type {
imemo_none,
imemo_cref,
imemo_svar,
+ imemo_throw_data,
imemo_mask = 0x07
};
@@ -645,6 +646,18 @@ struct vm_svar {
const VALUE others;
};
+/* THROW_DATA */
+
+struct vm_throw_data {
+ VALUE flags;
+ VALUE reserved;
+ const VALUE throw_obj;
+ const struct rb_control_frame_struct *catch_frame;
+ VALUE throw_state;
+};
+
+#define THROW_DATA_P(err) RB_TYPE_P((err), T_IMEMO)
+
/* MEMO */
struct MEMO {
diff --git a/vm.c b/vm.c
index 07e7dc0ae6..74fa78be9d 100644
--- a/vm.c
+++ b/vm.c
@@ -1176,7 +1176,7 @@ vm_iter_break(rb_thread_t *th, VALUE val)
rb_control_frame_t *target_cfp = rb_vm_search_cf_from_ep(th, cfp, ep);
th->state = TAG_BREAK;
- th->errinfo = (VALUE)NEW_THROW_DATA(val, target_cfp, TAG_BREAK);
+ th->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK);
TH_JUMP_TAG(th, TAG_BREAK);
}
@@ -1421,7 +1421,7 @@ vm_exec(rb_thread_t *th)
int state;
VALUE result;
VALUE initial = 0;
- struct THROW_DATA *err;
+ struct vm_throw_data *err;
TH_PUSH_TAG(th);
_tag.retval = Qnil;
@@ -1429,7 +1429,7 @@ vm_exec(rb_thread_t *th)
vm_loop_start:
result = vm_exec_core(th, initial);
if ((state = th->state) != 0) {
- err = (struct THROW_DATA *)result;
+ err = (struct vm_throw_data *)result;
th->state = 0;
goto exception_handler;
}
@@ -1444,7 +1444,7 @@ vm_exec(rb_thread_t *th)
VALUE type;
const rb_control_frame_t *escape_cfp;
- err = (struct THROW_DATA *)th->errinfo;
+ err = (struct vm_throw_data *)th->errinfo;
exception_handler:
cont_pc = cont_sp = catch_iseqval = 0;
diff --git a/vm_eval.c b/vm_eval.c
index 294c90e0a2..8ae70458a2 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1132,7 +1132,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
retval = (*it_proc) (data1);
}
else {
- const struct THROW_DATA *err = (struct THROW_DATA *)th->errinfo;
+ const struct vm_throw_data *err = (struct vm_throw_data *)th->errinfo;
if (state == TAG_BREAK) {
const rb_control_frame_t *escape_cfp = THROW_DATA_CATCH_FRAME(err);
@@ -1881,7 +1881,7 @@ rb_throw_obj(VALUE tag, VALUE value)
rb_exc_raise(rb_class_new_instance(numberof(desc), desc, rb_eUncaughtThrow));
}
- th->errinfo = (VALUE)NEW_THROW_DATA(tag, NULL, TAG_THROW);
+ th->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
JUMP_TAG(TAG_THROW);
}
@@ -1996,7 +1996,7 @@ rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr)
/* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil);
}
- else if (state == TAG_THROW && THROW_DATA_VAL((struct THROW_DATA *)th->errinfo) == tag) {
+ else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->errinfo) == tag) {
rb_vm_rewind_cfp(th, saved_cfp);
val = th->tag->retval;
th->errinfo = Qnil;
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 9a30986275..de7d76bd65 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -642,7 +642,7 @@ vm_throw_continue(rb_thread_t *th, VALUE err)
th->state = TAG_THROW;
}
else if (THROW_DATA_P(err)) {
- th->state = THROW_DATA_STATE((struct THROW_DATA *)err);
+ th->state = THROW_DATA_STATE((struct vm_throw_data *)err);
}
else {
th->state = TAG_RAISE;
@@ -781,7 +781,7 @@ vm_throw_start(rb_thread_t * const th, rb_control_frame_t * const reg_cfp, int s
}
th->state = state;
- return (VALUE)NEW_THROW_DATA(throwobj, escape_cfp, state);
+ return (VALUE)THROW_DATA_NEW(throwobj, escape_cfp, state);
}
static VALUE
diff --git a/vm_insnhelper.h b/vm_insnhelper.h
index 9a3a2b1564..ab72b2217f 100644
--- a/vm_insnhelper.h
+++ b/vm_insnhelper.h
@@ -229,46 +229,38 @@ enum vm_regan_acttype {
static VALUE make_no_method_exception(VALUE exc, const char *format,
VALUE obj, int argc, const VALUE *argv);
-struct THROW_DATA {
- VALUE flags;
- VALUE reserved;
- VALUE throw_obj;
- const rb_control_frame_t *catch_frame;
- VALUE throw_state;
-};
-
-static inline struct THROW_DATA *
-NEW_THROW_DATA(VALUE val, rb_control_frame_t *cf, VALUE st)
+static inline struct vm_throw_data *
+THROW_DATA_NEW(VALUE val, rb_control_frame_t *cf, VALUE st)
{
- return (struct THROW_DATA *)rb_node_newnode(NODE_LIT, val, (VALUE)cf, st);
+ return (struct vm_throw_data *)rb_imemo_new(imemo_throw_data, val, (VALUE)cf, st, 0);
}
static inline void
-THROW_DATA_CATCH_FRAME_SET(struct THROW_DATA *obj, const rb_control_frame_t *cfp)
+THROW_DATA_CATCH_FRAME_SET(struct vm_throw_data *obj, const rb_control_frame_t *cfp)
{
obj->catch_frame = cfp;
}
static inline void
-THROW_DATA_STATE_SET(struct THROW_DATA *obj, int st)
+THROW_DATA_STATE_SET(struct vm_throw_data *obj, int st)
{
obj->throw_state = (VALUE)st;
}
static inline VALUE
-THROW_DATA_VAL(const struct THROW_DATA *obj)
+THROW_DATA_VAL(const struct vm_throw_data *obj)
{
return obj->throw_obj;
}
static inline const rb_control_frame_t *
-THROW_DATA_CATCH_FRAME(const struct THROW_DATA *obj)
+THROW_DATA_CATCH_FRAME(const struct vm_throw_data *obj)
{
return obj->catch_frame;
}
static int
-THROW_DATA_STATE(const struct THROW_DATA *obj)
+THROW_DATA_STATE(const struct vm_throw_data *obj)
{
return (int)obj->throw_state;
}