Commit 6d742ef9 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2482 from take-cheeze/exc_tt

Use MRB_TT_EXCEPTION in exception object.
parents 4b691212 3c966025
......@@ -11,6 +11,13 @@
extern "C" {
#endif
struct RException {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
};
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
void mrb_sys_fail(mrb_state *mrb, const char *mesg);
mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
......
......@@ -122,6 +122,7 @@ enum mrb_vtype {
#define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)
#define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)
#define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
#define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
#define mrb_test(o) mrb_bool(o)
mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
......
......@@ -15,6 +15,7 @@
#include "mruby/variable.h"
#include "mruby/debug.h"
#include "mruby/error.h"
#include "mruby/class.h"
#include "mrb_throw.h"
mrb_value
......@@ -442,6 +443,7 @@ mrb_init_exception(mrb_state *mrb)
struct RClass *exception, *runtime_error, *script_error;
mrb->eException_class = exception = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */
MRB_SET_INSTANCE_TT(exception, MRB_TT_EXCEPTION);
mrb_define_class_method(mrb, exception, "exception", mrb_instance_new, MRB_ARGS_ANY());
mrb_define_method(mrb, exception, "exception", exc_exception, MRB_ARGS_ANY());
mrb_define_method(mrb, exception, "initialize", exc_initialize, MRB_ARGS_ANY());
......
......@@ -16,6 +16,7 @@
#include "mruby/string.h"
#include "mruby/variable.h"
#include "mruby/gc.h"
#include "mruby/error.h"
/*
= Tri-color Incremental Garbage Collection
......@@ -107,6 +108,7 @@ typedef struct {
struct RRange range;
struct RData data;
struct RProc proc;
struct RException exc;
#ifdef MRB_WORD_BOXING
struct RFloat floatv;
struct RCptr cptr;
......@@ -513,6 +515,7 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_OBJECT:
case MRB_TT_DATA:
case MRB_TT_EXCEPTION:
mrb_gc_mark_iv(mrb, (struct RObject*)obj);
break;
......@@ -612,6 +615,7 @@ obj_free(mrb_state *mrb, struct RBasic *obj)
#endif
case MRB_TT_OBJECT:
case MRB_TT_EXCEPTION:
mrb_gc_free_iv(mrb, (struct RObject*)obj);
break;
......@@ -747,6 +751,7 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_OBJECT:
case MRB_TT_DATA:
case MRB_TT_EXCEPTION:
children += mrb_gc_mark_iv_size(mrb, (struct RObject*)obj);
break;
......
......@@ -275,6 +275,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
case MRB_TT_SCLASS:
case MRB_TT_HASH:
case MRB_TT_DATA:
case MRB_TT_EXCEPTION:
mrb_iv_copy(mrb, dest, obj);
break;
......
......@@ -459,6 +459,7 @@ obj_iv_p(mrb_value obj)
case MRB_TT_SCLASS:
case MRB_TT_HASH:
case MRB_TT_DATA:
case MRB_TT_EXCEPTION:
return TRUE;
default:
return FALSE;
......
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