From e473ce1ac4cd2d08f25a5f4eee7e64db99f7f2e4 Mon Sep 17 00:00:00 2001 From: Yuichiro MASUI Date: Sat, 2 Jun 2012 17:00:11 +0900 Subject: fixed const_get && const_missing issue --- src/variable.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 82ab7bef3..941e7689d 100644 --- a/src/variable.c +++ b/src/variable.c @@ -186,7 +186,7 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) if (k != kh_end(h)) { k = kh_put(iv, h, sym); kh_value(h, k) = v; - return; + return; } } c = c->super; @@ -233,26 +233,8 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) struct RClass *c = base; khash_t(iv) *h; khiter_t k; + mrb_sym cm = mrb_intern(mrb, "const_missing"); - if (c->iv) { - h = c->iv; - k = kh_get(iv, h, sym); - if (k != kh_end(h)) { - return kh_value(h, k); - } - } - for (;;) { - c = mrb_class_outer_module(mrb, c); - if (!c) break; - if (c->iv) { - h = c->iv; - k = kh_get(iv, h, sym); - if (k != kh_end(h)) { - return kh_value(h, k); - } - } - } - c = base->super; while (c) { if (c->iv) { h = c->iv; @@ -260,19 +242,14 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) if (k != kh_end(h)) { return kh_value(h, k); } + if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { + mrb_value argv = mrb_symbol_value(sym); + return mrb_funcall_argv(mrb, mrb_obj_value(c), "const_missing", 1, &argv); + } } c = c->super; } - if (!c) { - c = mrb->object_class; - } - - if (mrb_respond_to(mrb, mrb_obj_value(c), mrb_intern(mrb, "const_missing"))) { - mrb_value argv = mrb_symbol_value(sym); - return mrb_funcall_argv(mrb, mrb_obj_value(c), "const_missing", 1, &argv); - } - mrb_raise(mrb, E_NAME_ERROR, "uninitialized constant %s", mrb_sym2name(mrb, sym)); /* not reached */ -- cgit v1.2.3 From e65d4938f373132f2ab5c75533e0bd18e188f9bc Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 2 Jun 2012 17:25:18 +0900 Subject: 'mrb_sym' used as 'uint32_t'. it's broken portability; based on the work from @crimsonwoods; close #216 --- src/class.c | 4 ++-- src/kernel.c | 4 ++-- src/variable.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/variable.c') diff --git a/src/class.c b/src/class.c index b13ab2288..9424e8d84 100644 --- a/src/class.c +++ b/src/class.c @@ -17,8 +17,8 @@ #include "mruby/khash.h" -KHASH_MAP_INIT_INT(mt, struct RProc*); -KHASH_MAP_INIT_INT(iv, mrb_value); +KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) +KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) typedef struct fc_result { mrb_sym name; diff --git a/src/kernel.c b/src/kernel.c index 9092d239d..15a4158a4 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -39,8 +39,8 @@ typedef enum { #include "regint.h" #endif -KHASH_MAP_INIT_INT(mt, struct RProc*); -KHASH_MAP_INIT_INT(iv, mrb_value); +KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) +KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) #ifndef FALSE #define FALSE 0 diff --git a/src/variable.c b/src/variable.c index 82ab7bef3..a17484903 100644 --- a/src/variable.c +++ b/src/variable.c @@ -19,7 +19,7 @@ #include "st.h" #endif -KHASH_MAP_INIT_INT(iv, mrb_value); +KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) #ifndef FALSE #define FALSE 0 -- cgit v1.2.3 From 8bc506e25825620c356a61e0db8825b669409159 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 23:39:27 +0900 Subject: a bug in contant reference from modules --- src/variable.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 33cd6ba14..b8957fb6a 100644 --- a/src/variable.c +++ b/src/variable.c @@ -235,6 +235,7 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) khiter_t k; mrb_sym cm = mrb_intern(mrb, "const_missing"); + L_RETRY: while (c) { if (c->iv) { h = c->iv; @@ -250,6 +251,10 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) c = c->super; } + if (base->tt == MRB_TT_MODULE) { + c = base = mrb->object_class; + goto L_RETRY; + } mrb_raise(mrb, E_NAME_ERROR, "uninitialized constant %s", mrb_sym2name(mrb, sym)); /* not reached */ -- cgit v1.2.3 From f564ec7e822c55e8ef6973170818263675b2499f Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 00:56:00 +0900 Subject: Remove some redundant code. --- src/codegen.c | 12 ------------ src/error.c | 30 ------------------------------ src/error.h | 1 - src/etc.c | 8 -------- src/hash.c | 8 -------- src/kernel.c | 13 ------------- src/load.c | 8 -------- src/object.c | 8 -------- src/parse.y | 8 -------- src/range.c | 8 -------- src/string.c | 2 +- src/variable.c | 8 -------- 12 files changed, 1 insertion(+), 113 deletions(-) (limited to 'src/variable.c') diff --git a/src/codegen.c b/src/codegen.c index 1bdc2d21c..b64a18b96 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -298,20 +298,8 @@ push_(codegen_scope *s) s->sp++; nregs_update; } -#if 0 -static void -push_n_(codegen_scope *s, int n) -{ - if (s->sp + n > 511) { - codegen_error(s, "too complex expression"); - } - s->sp += n; - nregs_update; -} -#endif #define push() push_(s) -#define push_n(n) push_n_(s, n) #define pop() (s->sp--) #define pop_n(n) (s->sp-=(n)) #define cursp() (s->sp) diff --git a/src/error.c b/src/error.c index bb334322f..e6ccdf096 100644 --- a/src/error.c +++ b/src/error.c @@ -20,14 +20,6 @@ #define warn_printf printf -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, long len) { @@ -300,28 +292,6 @@ sysexit_status(mrb_state *mrb, mrb_value err) return mrb_fixnum(st); } -void -error_pos(void) -{ -#if 0 - const char *sourcefile = mrb_sourcefile(); - int sourceline = mrb_sourceline(); - - if (sourcefile) { - if (sourceline == 0) { - warn_printf("%s", sourcefile); - } - else if (mrb_frame_callee()) { - warn_printf("%s:%d:in `%s'", sourcefile, sourceline, - mrb_sym2name(mrb, mrb_frame_callee())); - } - else { - warn_printf("%s:%d", sourcefile, sourceline); - } - } -#endif -} - static void set_backtrace(mrb_state *mrb, mrb_value info, mrb_value bt) { diff --git a/src/error.h b/src/error.h index 8a86e7d3d..e4d6acb6c 100644 --- a/src/error.h +++ b/src/error.h @@ -14,7 +14,6 @@ struct RException { void mrb_sys_fail(mrb_state *mrb, const char *mesg); void mrb_bug_errno(const char*, int); int sysexit_status(mrb_state *mrb, mrb_value err); -void error_pos(void); mrb_value mrb_exc_new3(mrb_state *mrb, struct RClass* c, mrb_value str); mrb_value make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr); mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); diff --git a/src/etc.c b/src/etc.c index 5d70c8bc7..40a00c1f5 100644 --- a/src/etc.c +++ b/src/etc.c @@ -10,14 +10,6 @@ #include "mruby/numeric.h" #include "mruby/data.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - struct RData* mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const struct mrb_data_type *type) { diff --git a/src/hash.c b/src/hash.c index 4a85fcec3..fe5336dc1 100644 --- a/src/hash.c +++ b/src/hash.c @@ -33,14 +33,6 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b) KHASH_INIT(ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal); -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - static void mrb_hash_modify(mrb_state *mrb, mrb_value hash); static inline mrb_value diff --git a/src/kernel.c b/src/kernel.c index 4856af7ad..6dfe6be19 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -34,22 +34,9 @@ typedef enum { NOEX_RESPONDS = 0x80 } mrb_method_flag_t; -#ifdef INCLUDE_REGEXP -#include "re.h" -#include "regint.h" -#endif - KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - struct obj_ivar_tag { mrb_value obj; int (*func)(mrb_sym key, mrb_value val, void * arg); diff --git a/src/load.c b/src/load.c index 053ec2d7e..1f853df00 100644 --- a/src/load.c +++ b/src/load.c @@ -13,14 +13,6 @@ #endif #include "mruby/irep.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - typedef struct _RiteFILE { FILE* fp; diff --git a/src/object.c b/src/object.c index c9ea3f8eb..a30e7c58a 100644 --- a/src/object.c +++ b/src/object.c @@ -11,14 +11,6 @@ #include "mruby/class.h" #include "mruby/numeric.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - int mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2) { diff --git a/src/parse.y b/src/parse.y index 7ca0cda80..5e44dd85a 100644 --- a/src/parse.y +++ b/src/parse.y @@ -41,14 +41,6 @@ static void backref_error(parser_state *p, node *n); #define identchar(c) (isalnum(c) || (c) == '_' || !isascii(c)) -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - typedef unsigned int stack_type; #define BITSTACK_PUSH(stack, n) ((stack) = ((stack)<<1)|((n)&1)) diff --git a/src/range.c b/src/range.c index acec1514e..a158dd920 100644 --- a/src/range.c +++ b/src/range.c @@ -15,14 +15,6 @@ #include #include -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - #ifndef OTHER #define OTHER 2 #endif diff --git a/src/string.c b/src/string.c index 14041127a..a9e155c72 100644 --- a/src/string.c +++ b/src/string.c @@ -763,7 +763,7 @@ num_index: len = RSTRING_LEN(str); switch (mrb_range_beg_len(mrb, indx, &beg, &len, len, 0)) { - case 0/*FLASE*/: + case FALSE: break; case 2/*OTHER*/: return mrb_nil_value(); diff --git a/src/variable.c b/src/variable.c index b8957fb6a..47029da28 100644 --- a/src/variable.c +++ b/src/variable.c @@ -21,14 +21,6 @@ KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - static void mark_tbl(mrb_state *mrb, struct kh_iv *h) { -- cgit v1.2.3 From 76f7aecff326666543d9bac31fe13e0cab8e05f4 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 15:34:49 +0900 Subject: use ENABLE/DISABLE instead of INCLUDE for configuration macro names --- include/mrbconf.h | 50 ++++++++++++++++---------------- include/mruby/class.h | 9 +----- src/dump.c | 6 ++-- src/gc.c | 8 +++--- src/init.c | 6 ++-- src/load.c | 4 +-- src/math.c | 4 +-- src/parse.y | 6 ---- src/re.c | 8 +++--- src/regcomp.c | 8 +++--- src/regerror.c | 4 +-- src/regexec.c | 4 +-- src/regparse.c | 8 +++--- src/string.c | 80 +++++++++++++++++++++++++-------------------------- src/struct.c | 2 +- src/time.c | 3 +- src/variable.c | 2 +- 17 files changed, 98 insertions(+), 114 deletions(-) (limited to 'src/variable.c') diff --git a/include/mrbconf.h b/include/mrbconf.h index f4f3ccaef..4b778e6de 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -8,8 +8,21 @@ #define MRUBYCONF_H #include + +/* configuration options: */ +/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ #undef MRB_USE_FLOAT +/* -DDISABLE_XXXX to change to drop the feature */ +#define DISABLE_REGEXP /* regular expression classes */ +#undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */ +#undef DISABLE_MATH /* Math functions */ +#undef DISABLE_TIME /* Time class */ + +#undef HAVE_UNISTD_H /* WINDOWS */ +#define HAVE_UNISTD_H /* LINUX */ +/* end of configuration */ + #ifdef MRB_USE_FLOAT typedef float mrb_float; #else @@ -20,34 +33,19 @@ typedef double mrb_float; typedef int mrb_int; typedef intptr_t mrb_sym; -//#define PARSER_DUMP /* print out parser state */ -#undef PARSER_DUMP /* do not print out parser state */ - -//#define INCLUDE_ENCODING /* use UTF-8 encoding classes */ -#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */ - -//#define INCLUDE_REGEXP /* use regular expression classes */ -#undef INCLUDE_REGEXP /* not use regular expression classes */ - -#ifdef INCLUDE_REGEXP -# define INCLUDE_ENCODING /* Regexp depends Encoding */ +/* define ENABLE_XXXX from DISABLE_XXX */ +#ifndef DISABLE_REGEXP +#define ENABLE_REGEXP #endif - -#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ -//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ - -#define INCLUDE_MATH /* use (non ISO) Math module */ -//#undef INCLUDE_MATH /* not use (non ISO) Math module */ - -#define INCLUDE_TIME /* use Time module */ -//#undef INCLUDE_TIME /* not use Time module */ - -#ifdef MRUBY_DEBUG_BUILD -# define PARSER_DUMP +#ifndef DISABLE_KERNEL_SPRINTF +#define ENABLE_KERNEL_SPRINTF +#endif +#ifndef DISABLE_MATH +#define ENABLE_MATH +#endif +#ifndef DISABLE_TIME +#define ENABLE_TIME #endif - -#undef HAVE_UNISTD_H /* WINDOWS */ -#define HAVE_UNISTD_H /* LINUX */ #ifndef FALSE # define FALSE 0 diff --git a/include/mruby/class.h b/include/mruby/class.h index 35dd0ec1d..2cc90310e 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -40,14 +40,7 @@ mrb_class(mrb_state *mrb, mrb_value v) case MRB_TT_FLOAT: return mrb->float_class; -#ifdef INCLUDE_REGEXP -// case MRB_TT_REGEX: -// return mrb->regex_class; -// case MRB_TT_MATCH: -// return mrb->match_class; -// case MRB_TT_DATA: -// return mrb->encode_class; -#else +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: case MRB_TT_MATCH: mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given", diff --git a/src/dump.c b/src/dump.c index 7b2199a02..daf2868f1 100644 --- a/src/dump.c +++ b/src/dump.c @@ -8,7 +8,7 @@ #include "mruby/dump.h" #include "mruby/string.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif #include "mruby/irep.h" @@ -237,7 +237,7 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type) nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); size += nlen; break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_reg_to_s(mrb, irep->pool[pool_no]); nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); @@ -365,7 +365,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) str_dump(RSTRING_PTR(str), char_buf, RSTRING_LEN(str), type); break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_reg_to_s(mrb, irep->pool[pool_no]); nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); diff --git a/src/gc.c b/src/gc.c index 1b4b3eed4..c07c9b13b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -71,7 +71,7 @@ */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif @@ -92,7 +92,7 @@ typedef struct { struct RRange range; struct RStruct structdata; struct RProc procdata; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP struct RMatch match; struct RRegexp regexp; #endif @@ -412,7 +412,7 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj) } break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_MATCH: { struct RMatch *m = (struct RMatch*)obj; @@ -611,7 +611,7 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj) children+=2; break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_MATCH: children+=2; break; diff --git a/src/init.c b/src/init.c index 351874b32..a515ee880 100644 --- a/src/init.c +++ b/src/init.c @@ -51,15 +51,15 @@ mrb_init_core(mrb_state *mrb) mrb_init_range(mrb); mrb_init_struct(mrb); mrb_init_gc(mrb); -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_init_regexp(mrb); #endif mrb_init_exception(mrb); mrb_init_print(mrb); -#ifdef INCLUDE_TIME +#ifdef ENABLE_TIME mrb_init_time(mrb); #endif -#ifdef INCLUDE_MATH +#ifdef ENABLE_MATH mrb_init_math(mrb); #endif diff --git a/src/load.c b/src/load.c index 1f853df00..d3766da9d 100644 --- a/src/load.c +++ b/src/load.c @@ -8,7 +8,7 @@ #include "mruby/dump.h" #include "mruby/string.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif #include "mruby/irep.h" @@ -418,7 +418,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 irep->pool[i] = mrb_str_new(mrb, buf, pdl); break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_str_new(mrb, buf, pdl); irep->pool[i] = mrb_reg_quote(mrb, str); diff --git a/src/math.c b/src/math.c index f3a2dc12c..cf9a20489 100644 --- a/src/math.c +++ b/src/math.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef INCLUDE_MATH +#ifdef ENABLE_MATH #include #define domain_error(msg) \ @@ -681,4 +681,4 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "erf", math_erf, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, ARGS_REQ(1)); } -#endif /* INCLUDE_MATH */ +#endif /* ENABLE_MATH */ diff --git a/src/parse.y b/src/parse.y index 5e44dd85a..b7eaaa4e4 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4776,9 +4776,6 @@ mrb_compile_file(mrb_state * mrb, FILE *f) if (!p) return -1; if (!p->tree) return -1; if (p->nerr) return -1; -#ifdef PARSER_DUMP - parser_dump(mrb, p->tree, 0); -#endif n = mrb_generate_code(mrb, p->tree); mrb_pool_close(p->pool); @@ -4795,9 +4792,6 @@ mrb_compile_nstring(mrb_state *mrb, char *s, size_t len) if (!p) return -1; if (!p->tree) return -1; if (p->nerr) return -1; -#ifdef PARSER_DUMP - parser_dump(mrb, p->tree, 0); -#endif n = mrb_generate_code(mrb, p->tree); mrb_pool_close(p->pool); diff --git a/src/re.c b/src/re.c index b4134c81c..17b4f3da7 100644 --- a/src/re.c +++ b/src/re.c @@ -13,7 +13,7 @@ #include "regint.h" #include "mruby/class.h" #include "error.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #define REGEX_CLASS (mrb_class_obj_get(mrb, "Regexp")) #define MATCH_CLASS (mrb_class_obj_get(mrb, "MatchData")) @@ -2318,7 +2318,7 @@ mrb_backref_set(mrb_state *mrb, mrb_value val) { vm_svar_set(mrb, 1, val); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING static inline long @@ -2421,7 +2421,7 @@ mrb_memsearch(mrb_state *mrb, const void *x0, int m, const void *y0, int n, mrb_ } #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_value mrb_reg_init_str(mrb_state *mrb, mrb_value re, mrb_value s, int options) { @@ -2469,7 +2469,7 @@ re_adjust_startpos(struct re_pattern_buffer *bufp, const char *string, int size, }*/ return startpos; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING static const unsigned char mbctab_ascii[] = { diff --git a/src/regcomp.c b/src/regcomp.c index 523124b26..b8c652999 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -30,7 +30,7 @@ #include "mruby.h" #include #include "regparse.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP OnigCaseFoldType OnigDefaultCaseFoldFlag = ONIGENC_CASE_FOLD_MIN; @@ -5628,7 +5628,7 @@ onig_end(void) THREAD_SYSTEM_END; return 0; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING extern int @@ -5653,7 +5653,7 @@ onig_is_in_code_range(const UChar* p, OnigCodePoint code) } #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP extern int onig_is_code_in_cc_len(int elen, OnigCodePoint code, CClassNode* cc) { @@ -6285,4 +6285,4 @@ print_tree(FILE* f, Node* node) print_indent_tree(f, node, 0); } #endif -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regerror.c b/src/regerror.c index 2ba879f78..df60b49cc 100644 --- a/src/regerror.c +++ b/src/regerror.c @@ -28,7 +28,7 @@ */ #include "mruby.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include #include "regint.h" #include /* for vsnprintf() */ @@ -372,4 +372,4 @@ onig_snprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc, pat, pat_end, fmt, args); va_end(args); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regexec.c b/src/regexec.c index 4d8950b73..d265cc803 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -28,7 +28,7 @@ */ #include "mruby.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include #include "regint.h" @@ -3754,4 +3754,4 @@ onig_copy_encoding(OnigEncoding to, OnigEncoding from) { *to = *from; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regparse.c b/src/regparse.c index 509740ac3..f7bb23306 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -32,7 +32,7 @@ #include #include "regparse.h" #include -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #define WARN_BUFSIZE 256 @@ -298,7 +298,7 @@ strcat_capa_from_static(UChar* dest, UChar* dest_end, onig_strcpy(r + (dest_end - dest), src, src_end); return r; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING #ifdef USE_ST_LIBRARY @@ -393,7 +393,7 @@ onig_st_insert_strend(hash_table_type* table, const UChar* str_key, #endif /* USE_ST_LIBRARY */ #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #ifdef USE_NAMED_GROUP #define INIT_NAME_BACKREFS_ALLOC_NUM 8 @@ -5597,4 +5597,4 @@ onig_scan_env_set_error_string(ScanEnv* env, int ecode ARG_UNUSED, env->error = arg; env->error_end = arg_end; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/string.c b/src/string.c index a9e155c72..566c056cf 100644 --- a/src/string.c +++ b/src/string.c @@ -17,10 +17,10 @@ #include "mruby/variable.h" #include #include "re.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "regex.h" #include "st.h" -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifndef FALSE #define FALSE 0 @@ -32,9 +32,9 @@ const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP static mrb_value str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2); static mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len); @@ -743,12 +743,12 @@ num_index: return str; case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP return mrb_str_subpat(mrb, str, indx, 0); //mrb_str_subpat(str, indx, INT2FIX(0)); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); return mrb_nil_value(); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP case MRB_TT_STRING: if (mrb_str_index(mrb, str, indx, 0) != -1) @@ -835,12 +835,12 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) argc = mrb_get_args(mrb, "o|o", &a1, &a2); if (argc == 2) { if (mrb_type(a1) == MRB_TT_REGEX) { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP return mrb_str_subpat(mrb, str, argv[0], mrb_fixnum(argv[1])); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); return mrb_nil_value(); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } return mrb_str_substr(mrb, str, mrb_fixnum(a1), mrb_fixnum(a2)); } @@ -1246,7 +1246,7 @@ mrb_str_buf_append(mrb_state *mrb, mrb_value str, mrb_value str2) return str; } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang) { @@ -1383,7 +1383,7 @@ mrb_str_gsub_bang(mrb_state *mrb, mrb_value self) str_modify(mrb, s); return str_gsub(mrb, s, 1); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str) @@ -1506,7 +1506,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) switch (mrb_type(sub)) { case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP if (pos > RSTRING_LEN(str)) return mrb_nil_value(); pos = mrb_str_offset(mrb, str, pos); @@ -1514,7 +1514,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) pos = mrb_str_sublen(mrb, str, pos); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP break; case MRB_TT_FIXNUM: { @@ -1668,7 +1668,7 @@ mrb_check_string_type(mrb_state *mrb, mrb_value str) return mrb_check_convert_type(mrb, str, MRB_TT_STRING, "String", "to_str"); } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) { @@ -1696,7 +1696,7 @@ get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) return mrb_reg_regcomp(mrb, pat); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.27 */ /* @@ -1711,7 +1711,7 @@ get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) * 'hello'.match(/(.)\1/)[0] #=> "ll" * 'hello'.match('xx') #=> nil */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_match_m(mrb_state *mrb, mrb_value self) { @@ -1731,7 +1731,7 @@ mrb_str_match_m(mrb_state *mrb, mrb_value self) } return result; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* ---------------------------------- */ /* 15.2.10.5.29 */ @@ -1883,11 +1883,11 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) pos += len; if (pos < 0) { if (mrb_type(sub) == MRB_TT_REGEX) { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_backref_set(mrb, mrb_nil_value()); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } return mrb_nil_value(); } @@ -1904,7 +1904,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) switch (mrb_type(sub)) { case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP pos = mrb_str_offset(mrb, str, pos); if (!RREGEXP(sub)->ptr || RREGEXP_SRC_LEN(sub)) { pos = mrb_reg_search(mrb, sub, str, pos, 1); @@ -1913,7 +1913,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) if (pos >= 0) return mrb_fixnum_value(pos); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP break; case MRB_TT_FIXNUM: { @@ -1947,7 +1947,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) return mrb_nil_value(); } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) { @@ -1986,7 +1986,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) } return mrb_nil_value(); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.32 */ /* @@ -2019,7 +2019,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) * <> <> * rceu lowlr */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_scan(mrb_state *mrb, mrb_value str) { @@ -2053,7 +2053,7 @@ mrb_str_scan(mrb_state *mrb, mrb_value str) mrb_backref_set(mrb, match); return str; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP static const char isspacetable[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, @@ -2146,28 +2146,28 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) //fs_set: if (mrb_type(spat) == MRB_TT_STRING) { split_type = string; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP if (RSTRING_LEN(spat) == 0) { /* Special case - split into chars */ spat = mrb_reg_regcomp(mrb, spat); split_type = regexp; } else { -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' '){ split_type = awk; } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } else { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP spat = get_pat(mrb, spat, 1); split_type = regexp; #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } } @@ -2230,7 +2230,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) beg = ptr - temp; } else { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP char *ptr = RSTRING_PTR(str); long len = RSTRING_LEN(str); long start = beg; @@ -2276,7 +2276,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) } #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } if (RSTRING_LEN(str) > 0 && (lim >= 0 || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) @@ -2314,14 +2314,14 @@ mrb_block_given_p() * returning str, or nil if no substitutions were * performed. */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_sub_bang(mrb_state *mrb, mrb_value str) { str_modify(mrb, str); return mrb_nil_value(); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.36 */ @@ -2362,7 +2362,7 @@ mrb_str_sub_bang(mrb_state *mrb, mrb_value str) * #=> "Is /bin/bash your preferred shell?" */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_sub(mrb_state *mrb, mrb_value self) { @@ -2371,7 +2371,7 @@ mrb_str_sub(mrb_state *mrb, mrb_value self) mrb_str_sub_bang(mrb, str); return str; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) @@ -3030,7 +3030,7 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "each_line", mrb_str_each_line, ARGS_REQ(1)); /* 15.2.10.5.15 */ mrb_define_method(mrb, s, "empty?", mrb_str_empty_p, ARGS_NONE()); /* 15.2.10.5.16 */ mrb_define_method(mrb, s, "eql?", mrb_str_eql, ARGS_REQ(1)); /* 15.2.10.5.17 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "gsub", mrb_str_gsub, ARGS_REQ(1)); /* 15.2.10.5.18 */ mrb_define_method(mrb, s, "gsub!", mrb_str_gsub_bang, ARGS_REQ(1)); /* 15.2.10.5.19 */ #endif @@ -3040,19 +3040,19 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "initialize", mrb_str_init, ARGS_REQ(1)); /* 15.2.10.5.23 */ mrb_define_method(mrb, s, "initialize_copy", mrb_str_replace, ARGS_REQ(1)); /* 15.2.10.5.24 */ mrb_define_method(mrb, s, "intern", mrb_str_intern, ARGS_NONE()); /* 15.2.10.5.25 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "match", mrb_str_match_m, ARGS_REQ(1)); /* 15.2.10.5.27 */ #endif mrb_define_method(mrb, s, "replace", mrb_str_replace, ARGS_REQ(1)); /* 15.2.10.5.28 */ mrb_define_method(mrb, s, "reverse", mrb_str_reverse, ARGS_NONE()); /* 15.2.10.5.29 */ mrb_define_method(mrb, s, "reverse!", mrb_str_reverse_bang, ARGS_NONE()); /* 15.2.10.5.30 */ mrb_define_method(mrb, s, "rindex", mrb_str_rindex_m, ARGS_ANY()); /* 15.2.10.5.31 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "scan", mrb_str_scan, ARGS_REQ(1)); /* 15.2.10.5.32 */ #endif mrb_define_method(mrb, s, "slice", mrb_str_aref_m, ARGS_ANY()); /* 15.2.10.5.34 */ mrb_define_method(mrb, s, "split", mrb_str_split_m, ARGS_ANY()); /* 15.2.10.5.35 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "sub", mrb_str_sub, ARGS_REQ(1)); /* 15.2.10.5.36 */ mrb_define_method(mrb, s, "sub!", mrb_str_sub_bang, ARGS_REQ(1)); /* 15.2.10.5.37 */ #endif diff --git a/src/struct.c b/src/struct.c index 2e2e0c10f..5d759776f 100644 --- a/src/struct.c +++ b/src/struct.c @@ -12,7 +12,7 @@ #include //#include "defines.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "encoding.h" #endif diff --git a/src/time.c b/src/time.c index 1acde8ed9..55060729b 100644 --- a/src/time.c +++ b/src/time.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef INCLUDE_TIME +#ifdef ENABLE_TIME #include #include #include @@ -744,4 +744,3 @@ mrb_init_time(mrb_state *mrb) */ } #endif - diff --git a/src/variable.c b/src/variable.c index 47029da28..b11143b02 100644 --- a/src/variable.c +++ b/src/variable.c @@ -14,7 +14,7 @@ #include "error.h" #include "mruby/array.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #include "st.h" #endif -- cgit v1.2.3 From cd68190480785430b8e350d9a5d2127ab04e1074 Mon Sep 17 00:00:00 2001 From: crimsonwoods Date: Tue, 19 Jun 2012 23:00:29 +0900 Subject: split declaration and definition for 'khash_xxx'. --- include/mruby/khash.h | 63 +++++++++++++++++++++++++++++++++------------------ src/class.c | 3 --- src/hash.c | 3 ++- src/kernel.c | 3 --- src/khash.c | 5 ++++ src/symbol.c | 3 ++- src/variable.c | 2 -- 7 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 src/khash.c (limited to 'src/variable.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 22df48ebb..6cb2b383d 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -32,16 +32,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; #define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i)) -/* struct kh_xxx +/* declare struct kh_xxx and kh_xxx_funcs name: ash name khkey_t: key data type khval_t: value data type kh_is_map: (not implemented / not used in RiteVM ) - __hash_func: hash function - __hash_equal: hash comparation function */ -#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ +#define KHASH_DECLARE(name, khkey_t, khval_t, kh_is_map) \ typedef struct kh_##name { \ khint_t n_buckets; \ khint_t size; \ @@ -55,7 +53,26 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; khint_t inc; \ mrb_state *mrb; \ } kh_##name##_t; \ - static void kh_alloc_##name(kh_##name##_t *h) \ + void kh_alloc_##name(kh_##name##_t *h); \ + kh_##name##_t *kh_init_##name(mrb_state *mrb); \ + void kh_destroy_##name(kh_##name##_t *h); \ + void kh_clear_##name(kh_##name##_t *h); \ + khint_t kh_get_##name(kh_##name##_t *h, khkey_t key); \ + khint_t kh_put_##name(kh_##name##_t *h, khkey_t key); \ + void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \ + void kh_del_##name(kh_##name##_t *h, khint_t x); \ + +/* define kh_xxx_funcs + + name: ash name + khkey_t: key data type + khval_t: value data type + kh_is_map: (not implemented / not used in RiteVM ) + __hash_func: hash function + __hash_equal: hash comparation function +*/ +#define KHASH_DEFINE(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + void kh_alloc_##name(kh_##name##_t *h) \ { \ khint_t sz = h->n_buckets; \ h->size = h->n_occupied = 0; \ @@ -69,14 +86,14 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; h->mask = sz-1; \ h->inc = sz/2-1; \ } \ - static inline kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ + kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \ h->n_buckets = INITIAL_HASH_SIZE; \ h->mrb = mrb; \ kh_alloc_##name(h); \ return h; \ } \ - static inline void kh_destroy_##name(kh_##name##_t *h) \ + void kh_destroy_##name(kh_##name##_t *h) \ { \ if( h ){ \ mrb_free(h->mrb, h->keys); \ @@ -85,7 +102,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; mrb_free(h->mrb, h); \ } \ } \ - static inline void kh_clear_##name(kh_##name##_t *h) \ + void kh_clear_##name(kh_##name##_t *h) \ { \ if( h && h->e_flags ){ \ memset(h->e_flags, 0xff, h->n_buckets/8*sizeof(uint8_t)); \ @@ -93,7 +110,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; h->size = h->n_occupied = 0; \ } \ } \ - static inline khint_t kh_get_##name(kh_##name##_t *h, khkey_t key) \ + khint_t kh_get_##name(kh_##name##_t *h, khkey_t key) \ { \ khint_t k = __hash_func(h->mrb,key) & (h->mask); \ while( !__ac_isempty(h->e_flags, h->d_flags, k) ){ \ @@ -104,8 +121,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ return h->n_buckets; \ } \ - static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key); \ - static void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ + void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ { \ if( new_n_bucketse_flags; \ khkey_t *old_keys = h->keys; \ khval_t *old_vals = h->vals; \ @@ -124,17 +140,17 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; kh_alloc_##name(h); \ /* relocate */ \ for( i=0 ; imrb, old_e_flags); \ mrb_free(h->mrb, old_keys); \ mrb_free(h->mrb, old_vals); \ } \ } \ - static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key) \ + khint_t kh_put_##name(kh_##name##_t *h, khkey_t key) \ { \ khint_t k; \ if( h->n_occupied >= h->upper_bound ){ \ @@ -159,12 +175,13 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ return k; \ } \ - static inline void kh_del_##name(kh_##name##_t *h, khint_t x) \ + void kh_del_##name(kh_##name##_t *h, khint_t x) \ { \ h->d_flags[x/8] |= __m[x%8]; \ h->size--; \ } + #define khash_t(name) kh_##name##_t #define kh_init(name,mrb) kh_init_##name(mrb) @@ -197,11 +214,13 @@ static inline khint_t __ac_X31_hash_string(const char *s) #define kh_str_hash_func(mrb,key) __ac_X31_hash_string(key) #define kh_str_hash_equal(mrb,a, b) (strcmp(a, b) == 0) -#define KHASH_MAP_INIT_INT(name, khval_t) \ - KHASH_INIT(name, uint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) typedef const char *kh_cstr_t; -#define KHASH_MAP_INIT_STR(name, khval_t) \ - KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) + +/* declare common hash types. */ +#include "mruby.h" + +KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1) +KHASH_DECLARE(iv, mrb_sym, mrb_value, 1) #if defined(__cplusplus) } /* extern "C" { */ diff --git a/src/class.c b/src/class.c index df02a832a..434ecb037 100644 --- a/src/class.c +++ b/src/class.c @@ -17,9 +17,6 @@ #include "mruby/khash.h" -KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) -KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) - typedef struct fc_result { mrb_sym name; struct RClass * klass; diff --git a/src/hash.c b/src/hash.c index fe5336dc1..08f906800 100644 --- a/src/hash.c +++ b/src/hash.c @@ -31,7 +31,8 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b) return mrb_eql(mrb, a, b); } -KHASH_INIT(ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal); +KHASH_DECLARE(ht, mrb_value, mrb_value, 1); +KHASH_DEFINE (ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal); static void mrb_hash_modify(mrb_state *mrb, mrb_value hash); diff --git a/src/kernel.c b/src/kernel.c index b5bde628a..75c588a81 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -34,9 +34,6 @@ typedef enum { NOEX_RESPONDS = 0x80 } mrb_method_flag_t; -KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) -KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) - struct obj_ivar_tag { mrb_value obj; int (*func)(mrb_sym key, mrb_value val, void * arg); diff --git a/src/khash.c b/src/khash.c new file mode 100644 index 000000000..7ea09cfe7 --- /dev/null +++ b/src/khash.c @@ -0,0 +1,5 @@ +#include "mruby/khash.h" + +KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) +KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) + diff --git a/src/symbol.c b/src/symbol.c index b80174e7b..d2ae09655 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -36,7 +36,8 @@ sym_hash_func(mrb_state *mrb, const symbol_name s) } #define sym_hash_equal(mrb,a, b) (a.len == b.len && memcmp(a.name, b.name, a.len) == 0) -KHASH_INIT(n2s, symbol_name, mrb_sym, 1, sym_hash_func, sym_hash_equal) +KHASH_DECLARE(n2s, symbol_name, mrb_sym, 1) +KHASH_DEFINE (n2s, symbol_name, mrb_sym, 1, sym_hash_func, sym_hash_equal) /* ------------------------------------------------------ */ mrb_sym mrb_intern2(mrb_state *mrb, const char *name, int len) diff --git a/src/variable.c b/src/variable.c index b11143b02..d89e9d6bb 100644 --- a/src/variable.c +++ b/src/variable.c @@ -19,8 +19,6 @@ #include "st.h" #endif -KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) - static void mark_tbl(mrb_state *mrb, struct kh_iv *h) { -- cgit v1.2.3 From 396397bce17a0f03eab8ed6512651e665aa89c8a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 21 Jun 2012 11:04:36 +0900 Subject: move KHASH_DECLARE to header files --- include/mruby/khash.h | 6 ------ include/mruby/proc.h | 3 +++ include/mruby/variable.h | 7 ++++++- src/class.c | 6 ++---- src/kernel.c | 37 +++++-------------------------------- src/variable.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 60 insertions(+), 46 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 6cb2b383d..e236f0bea 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -216,12 +216,6 @@ static inline khint_t __ac_X31_hash_string(const char *s) typedef const char *kh_cstr_t; -/* declare common hash types. */ -#include "mruby.h" - -KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1) -KHASH_DECLARE(iv, mrb_sym, mrb_value, 1) - #if defined(__cplusplus) } /* extern "C" { */ #endif diff --git a/include/mruby/proc.h b/include/mruby/proc.h index 52dc5a98e..8f178790e 100644 --- a/include/mruby/proc.h +++ b/include/mruby/proc.h @@ -50,6 +50,9 @@ struct RProc *mrb_proc_new(mrb_state*, mrb_irep*); struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t); struct RProc *mrb_closure_new(mrb_state*, mrb_irep*); +#include "mruby/khash.h" +KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1); + #if defined(__cplusplus) } /* extern "C" { */ #endif diff --git a/include/mruby/variable.h b/include/mruby/variable.h index fb686fd47..440c4cc8b 100644 --- a/include/mruby/variable.h +++ b/include/mruby/variable.h @@ -20,6 +20,7 @@ typedef struct global_variable { //int block_trace; //struct trace_var *trace; } global_variable; + struct global_entry { global_variable *var; mrb_sym id; @@ -41,7 +42,8 @@ mrb_value mrb_obj_iv_get(mrb_state*, struct RObject*, mrb_sym); void mrb_obj_iv_set(mrb_state*, struct RObject*, mrb_sym, mrb_value); const char * mrb_class2name(mrb_state *mrb, struct RClass* klass); mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym); -void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v); /* mrb_iv_set */ +void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v); +mrb_value mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym); void mrb_copy_generic_ivar(mrb_value clone, mrb_value obj); int mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id); mrb_value mrb_f_global_variables(mrb_state *mrb, mrb_value self); @@ -55,6 +57,9 @@ void mrb_gc_mark_iv(mrb_state*, struct RObject*); size_t mrb_gc_mark_iv_size(mrb_state*, struct RObject*); void mrb_gc_free_iv(mrb_state*, struct RObject*); +#include "mruby/khash.h" +KHASH_DECLARE(iv, mrb_sym, mrb_value, 1) + #if defined(__cplusplus) } /* extern "C" { */ #endif diff --git a/src/class.c b/src/class.c index 72fef70aa..56ab8c06f 100644 --- a/src/class.c +++ b/src/class.c @@ -15,7 +15,8 @@ #include "mruby/array.h" #include "error.h" -#include "mruby/khash.h" +KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal); +KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal); typedef struct fc_result { mrb_sym name; @@ -25,9 +26,6 @@ typedef struct fc_result { struct fc_result *prev; } fcresult_t; -int kiv_lookup(khash_t(iv) *table, mrb_sym key, mrb_value *value); -extern struct kh_iv *mrb_class_tbl; - void mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c) { diff --git a/src/kernel.c b/src/kernel.c index a9f4792d7..fd0440e05 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -10,14 +10,12 @@ #include #include #include "mruby/proc.h" - #include "mruby/range.h" #include "mruby/array.h" #include "mruby/hash.h" #include "mruby/class.h" #include "mruby/struct.h" #include "mruby/variable.h" -#include "mruby/khash.h" #include "error.h" typedef enum { @@ -1057,39 +1055,14 @@ mrb_value mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) { mrb_sym sym; - mrb_value name; - khash_t(iv) *h; - khiter_t k; mrb_value val; - mrb_value Qundef = mrb_undef_value(); - mrb_get_args(mrb, "o", &name); - sym = mrb_to_id(mrb, name); - //if (OBJ_FROZEN(obj)) mrb_error_frozen("object"); - //if (!mrb_is_instance_id(id)) { - // mrb_name_error(mrb, id, "`%s' is not allowed as an instance variable name", mrb_sym2name(mrb, id)); - //} - switch (mrb_type(self)) { - case MRB_TT_OBJECT: - case MRB_TT_CLASS: - case MRB_TT_MODULE: - if (!mrb_obj_ptr(self)->iv) break; - h = mrb_obj_ptr(self)->iv; - if (!h) break; - k = kh_get(iv, h, sym); - if (k != kh_end(h)) { - val = kh_value(h, k); - if (!mrb_obj_equal(mrb, val, Qundef)) { - kh_value(h, k) = Qundef; - return val; - } - } - break; - default: - break; + mrb_get_args(mrb, "n", &sym); + val = mrb_iv_remove(mrb, self, sym); + if (UNDEF_P(val)) { + mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); } - mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); - return mrb_nil_value(); /* not reached */ + return val; } static inline int diff --git a/src/variable.c b/src/variable.c index d89e9d6bb..051c971d6 100644 --- a/src/variable.c +++ b/src/variable.c @@ -94,10 +94,28 @@ mrb_obj_iv_get(mrb_state *mrb, struct RObject *obj, mrb_sym sym) return ivget(mrb, obj->iv, sym); } +static int +obj_iv_p(mrb_value obj) +{ + switch (mrb_type(obj)) { + case MRB_TT_OBJECT: + case MRB_TT_CLASS: + case MRB_TT_MODULE: + case MRB_TT_HASH: + case MRB_TT_DATA: + return TRUE; + default: + return FALSE; + } +} + mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym) { - return mrb_obj_iv_get(mrb, mrb_obj_ptr(obj), sym); + if (obj_iv_p(obj)) { + return mrb_obj_iv_get(mrb, mrb_obj_ptr(obj), sym); + } + return mrb_nil_value(); } static void @@ -127,7 +145,30 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v) /* mrb_ivar_set */ { - mrb_obj_iv_set(mrb, mrb_obj_ptr(obj), sym, v); + if (obj_iv_p(obj)) { + mrb_obj_iv_set(mrb, mrb_obj_ptr(obj), sym, v); + } +} + +mrb_value +mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym) +{ + mrb_value val; + + if (obj_iv_p(obj)) { + khash_t(iv) *h = mrb_obj_ptr(obj)->iv; + khiter_t k; + + if (h) { + k = kh_get(iv, h, sym); + if (k != kh_end(h)) { + val = kh_value(h, k); + kh_del(iv, h, k); + return val; + } + } + } + return mrb_undef_value(); } mrb_value @@ -366,7 +407,7 @@ mrb_st_lookup(struct kh_iv *table, mrb_sym id, khiter_t *value) } } -int +static int kiv_lookup(khash_t(iv)* table, mrb_sym key, mrb_value *value) { khash_t(iv) *h=table; -- cgit v1.2.3 From 1fa63930fd072847d24ffe9c20a57109c41387ec Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 23 Jun 2012 10:40:17 +0900 Subject: check object type before retrieving instance variabls; close #311 --- include/mruby/variable.h | 1 + src/kernel.c | 40 ---------------------------------------- src/variable.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 40 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby/variable.h b/include/mruby/variable.h index 440c4cc8b..a4ed9a0ee 100644 --- a/include/mruby/variable.h +++ b/include/mruby/variable.h @@ -49,6 +49,7 @@ int mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id); mrb_value mrb_f_global_variables(mrb_state *mrb, mrb_value self); mrb_value mrb_gv_get(mrb_state *mrb, mrb_sym sym); void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val); +mrb_value mrb_obj_instance_variables(mrb_state*, mrb_value); /* GC functions */ void mrb_gc_mark_gv(mrb_state*); diff --git a/src/kernel.c b/src/kernel.c index fd0440e05..8f2b15378 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -708,46 +708,6 @@ mrb_obj_ivar_set(mrb_state *mrb, mrb_value self) return val; } -/* 15.3.1.3.23 */ -/* - * call-seq: - * obj.instance_variables -> array - * - * Returns an array of instance variable names for the receiver. Note - * that simply defining an accessor does not create the corresponding - * instance variable. - * - * class Fred - * attr_accessor :a1 - * def initialize - * @iv = 3 - * end - * end - * Fred.new.instance_variables #=> [:@iv] - */ -mrb_value -mrb_obj_instance_variables(mrb_state *mrb, mrb_value self) -{ - mrb_value ary; - kh_iv_t *h = RCLASS_IV_TBL(self); - khint_t i; - const char* p; - - ary = mrb_ary_new(mrb); - if (h) { - for (i=0;istack[0], sym, v); } +/* 15.3.1.3.23 */ +/* + * call-seq: + * obj.instance_variables -> array + * + * Returns an array of instance variable names for the receiver. Note + * that simply defining an accessor does not create the corresponding + * instance variable. + * + * class Fred + * attr_accessor :a1 + * def initialize + * @iv = 3 + * end + * end + * Fred.new.instance_variables #=> [:@iv] + */ +mrb_value +mrb_obj_instance_variables(mrb_state *mrb, mrb_value self) +{ + mrb_value ary; + kh_iv_t *h; + khint_t i; + int len; + const char* p; + + ary = mrb_ary_new(mrb); + if (obj_iv_p(self)) { + h = ROBJECT_IVPTR(self); + if (h) { + for (i=0;i 1 && *p == '@') { + if (mrb_type(kh_value(h, i)) != MRB_TT_UNDEF) + mrb_ary_push(mrb, ary, mrb_str_new(mrb, p, len)); + } + } + } + } + } + return ary; +} + mrb_value mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) { -- cgit v1.2.3 From ae2cd24afbf69e6e4c98ac8e642cb078e9d3750b Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 13 Jul 2012 00:24:44 +0900 Subject: remove st.h inclusion --- src/parse.y | 1 - src/re.h | 1 + src/string.c | 1 - src/variable.c | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src/variable.c') diff --git a/src/parse.y b/src/parse.y index fe8752ec2..292e60cfa 100644 --- a/src/parse.y +++ b/src/parse.y @@ -22,7 +22,6 @@ #include "mruby/compile.h" #include "mruby/proc.h" #include "node.h" -#include "st.h" #include #include diff --git a/src/re.h b/src/re.h index 238b4e408..91bd1abc1 100644 --- a/src/re.h +++ b/src/re.h @@ -13,6 +13,7 @@ #include "node.h" #include "regex.h" #include "encoding.h" +#include "st.h" #define BEG(no) regs->beg[no] #define END(no) regs->end[no] diff --git a/src/string.c b/src/string.c index b2cdc1212..2b7bdb454 100644 --- a/src/string.c +++ b/src/string.c @@ -19,7 +19,6 @@ #include "re.h" #ifdef ENABLE_REGEXP #include "regex.h" -#include "st.h" #endif //ENABLE_REGEXP const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"; diff --git a/src/variable.c b/src/variable.c index e785d56b7..33c9c0249 100644 --- a/src/variable.c +++ b/src/variable.c @@ -16,7 +16,6 @@ #ifdef ENABLE_REGEXP #include "re.h" -#include "st.h" #endif static void -- cgit v1.2.3 From 48c73ac630c2bfb3326d608d3c00e544dcfbcfea Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 13 Jul 2012 10:13:47 +0900 Subject: less --- src/etc.c | 1 - src/gc.c | 1 - src/hash.c | 1 - src/kernel.c | 1 - src/pool.c | 1 - src/range.c | 2 -- src/string.c | 2 +- src/symbol.c | 1 - src/variable.c | 1 - 9 files changed, 1 insertion(+), 10 deletions(-) (limited to 'src/variable.c') diff --git a/src/etc.c b/src/etc.c index 73cf31087..7e9381d16 100644 --- a/src/etc.c +++ b/src/etc.c @@ -126,7 +126,6 @@ mrb_block_proc(void) return mrb_nil_value();//proc_new(mrb_cProc, FALSE); } -#include static mrb_int float_id(mrb_float f) { diff --git a/src/gc.c b/src/gc.c index 78d8ee6a9..ada0bf31f 100644 --- a/src/gc.c +++ b/src/gc.c @@ -13,7 +13,6 @@ #include "mruby/range.h" #include "mruby/khash.h" #include -#include #include "mruby/struct.h" #include "mruby/proc.h" #include "mruby/data.h" diff --git a/src/hash.c b/src/hash.c index 888a1917e..ed8b70270 100644 --- a/src/hash.c +++ b/src/hash.c @@ -12,7 +12,6 @@ #include "mruby/string.h" #include "mruby/variable.h" #include -#include static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) diff --git a/src/kernel.c b/src/kernel.c index d230305da..1040dbe05 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -7,7 +7,6 @@ #include "mruby.h" #include "mruby/string.h" #include -#include #include #include "mruby/proc.h" #include "mruby/range.h" diff --git a/src/pool.c b/src/pool.c index 612bbe647..0f1baa776 100644 --- a/src/pool.c +++ b/src/pool.c @@ -35,7 +35,6 @@ struct mrb_pool { #undef TEST_POOL #ifdef TEST_POOL -#include #define mrb_malloc(m,s) malloc(s) #define mrb_free(m,p) free(p) diff --git a/src/range.c b/src/range.c index 1514313f1..b4d743e5f 100644 --- a/src/range.c +++ b/src/range.c @@ -11,8 +11,6 @@ #include "error.h" #include "mruby/numeric.h" #include "mruby/string.h" - -#include #include #ifndef OTHER diff --git a/src/string.c b/src/string.c index 2b7bdb454..14da83c51 100644 --- a/src/string.c +++ b/src/string.c @@ -16,8 +16,8 @@ #include "mruby/class.h" #include "mruby/variable.h" #include -#include "re.h" #ifdef ENABLE_REGEXP +#include "re.h" #include "regex.h" #endif //ENABLE_REGEXP diff --git a/src/symbol.c b/src/symbol.c index d2ae09655..91076e293 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -14,7 +14,6 @@ #include #include "mruby/class.h" #include "mruby/variable.h" -#include /* ------------------------------------------------------ */ typedef struct symbol_name { diff --git a/src/variable.c b/src/variable.c index 33c9c0249..e2f3a7d08 100644 --- a/src/variable.c +++ b/src/variable.c @@ -4,7 +4,6 @@ ** See Copyright Notice in mruby.h */ -#include #include "mruby.h" #include "mruby/class.h" #include "mruby/khash.h" -- cgit v1.2.3 From 96366117ea4bd91bccf00110469765ebc1ebaa8c Mon Sep 17 00:00:00 2001 From: Junji Sawada Date: Sat, 14 Jul 2012 11:39:25 +0900 Subject: Remove unnecessary header inclusion --- include/mruby/khash.h | 1 - src/cdump.c | 1 - src/codegen.c | 3 --- src/error.c | 5 ----- src/gc.c | 3 +-- src/hash.c | 1 - src/kernel.c | 5 ----- src/numeric.c | 4 ---- src/proc.c | 1 - src/range.c | 3 --- src/sprintf.c | 1 - src/string.c | 3 +-- src/struct.c | 4 ---- src/symbol.c | 4 ---- src/variable.c | 2 -- 15 files changed, 2 insertions(+), 39 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 0803521b7..09b23f6af 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -12,7 +12,6 @@ extern "C" { #endif #include -#include #include typedef uint32_t khint_t; diff --git a/src/cdump.c b/src/cdump.c index 16c1dc8ae..a4a2ac5e1 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -10,7 +10,6 @@ #include "mruby/irep.h" #include "mruby/string.h" -#include "re.h" #define MRB_CDUMP_LINE_LEN 128 diff --git a/src/codegen.c b/src/codegen.c index 6db09f310..9166b7144 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -10,15 +10,12 @@ #include "mruby.h" #include "mruby/string.h" #include "mruby/irep.h" -#include "mruby/proc.h" #include "mruby/compile.h" #include "mruby/numeric.h" #include "opcode.h" #include "node.h" #include #include -#include -#include #include typedef mrb_ast_node node; diff --git a/src/error.c b/src/error.c index e46e37cbb..5bfbc4319 100644 --- a/src/error.c +++ b/src/error.c @@ -6,14 +6,9 @@ #include "mruby.h" #include -#include #include #include #include "error.h" -#include "opcode.h" -#include "mruby/irep.h" -#include "mruby/proc.h" -#include "mruby/numeric.h" #include "mruby/variable.h" #include "mruby/string.h" #include "mruby/class.h" diff --git a/src/gc.c b/src/gc.c index ada0bf31f..3c00bb015 100644 --- a/src/gc.c +++ b/src/gc.c @@ -11,12 +11,10 @@ #include "mruby/string.h" #include "mruby/hash.h" #include "mruby/range.h" -#include "mruby/khash.h" #include #include "mruby/struct.h" #include "mruby/proc.h" #include "mruby/data.h" -#include "mruby/numeric.h" #include "mruby/variable.h" /* @@ -101,6 +99,7 @@ typedef struct { } RVALUE; #ifdef GC_PROFILE +#include #include static double program_invoke_time = 0; diff --git a/src/hash.c b/src/hash.c index ed8b70270..dacef4713 100644 --- a/src/hash.c +++ b/src/hash.c @@ -11,7 +11,6 @@ #include "mruby/array.h" #include "mruby/string.h" #include "mruby/variable.h" -#include static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) diff --git a/src/kernel.c b/src/kernel.c index 240c0dcb3..f5a1f3d53 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -6,14 +6,9 @@ #include "mruby.h" #include "mruby/string.h" -#include -#include #include "mruby/proc.h" -#include "mruby/range.h" #include "mruby/array.h" -#include "mruby/hash.h" #include "mruby/class.h" -#include "mruby/struct.h" #include "mruby/variable.h" #include "error.h" diff --git a/src/numeric.c b/src/numeric.c index 6638cf62c..ec3f97ca6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -8,11 +8,7 @@ #include "mruby/numeric.h" #include "mruby/string.h" #include "mruby/array.h" -#include -#include "mruby/class.h" -#include "mruby/variable.h" -#include #include #include #include diff --git a/src/proc.c b/src/proc.c index 98f753ac6..3e9bf1f67 100644 --- a/src/proc.c +++ b/src/proc.c @@ -6,7 +6,6 @@ #include "mruby.h" #include "mruby/proc.h" -#include "mruby/array.h" #include "mruby/class.h" #include "opcode.h" diff --git a/src/range.c b/src/range.c index 703ad12aa..b05836914 100644 --- a/src/range.c +++ b/src/range.c @@ -7,9 +7,6 @@ #include "mruby.h" #include "mruby/class.h" #include "mruby/range.h" -#include "mruby/variable.h" -#include "error.h" -#include "mruby/numeric.h" #include "mruby/string.h" #include diff --git a/src/sprintf.c b/src/sprintf.c index b597ff343..519e40b4b 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -15,7 +15,6 @@ #include "mruby/hash.h" #include "mruby/numeric.h" #include -#include #include #ifdef HAVE_IEEEFP_H diff --git a/src/string.c b/src/string.c index 14da83c51..e41116ebc 100644 --- a/src/string.c +++ b/src/string.c @@ -10,11 +10,10 @@ #include #include "mruby/string.h" #include -#include "mruby/numeric.h" +#include #include "mruby/range.h" #include "mruby/array.h" #include "mruby/class.h" -#include "mruby/variable.h" #include #ifdef ENABLE_REGEXP #include "re.h" diff --git a/src/struct.c b/src/struct.c index 25cd02d3d..6d8ce057f 100644 --- a/src/struct.c +++ b/src/struct.c @@ -17,13 +17,9 @@ #include "encoding.h" #endif -#include "mruby/numeric.h" -#include "mruby/hash.h" #include "mruby/string.h" #include "mruby/class.h" #include "mruby/variable.h" -#include "mruby/range.h" -#include "error.h" //#include "defines.h" #define mrb_long2int(n) ((int)(n)) diff --git a/src/symbol.c b/src/symbol.c index baab0fb3c..40484d4b5 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -8,12 +8,8 @@ #include "mruby/khash.h" #include -#include -#include #include "mruby/string.h" #include -#include "mruby/class.h" -#include "mruby/variable.h" /* ------------------------------------------------------ */ typedef struct symbol_name { diff --git a/src/variable.c b/src/variable.c index e2f3a7d08..be686bf72 100644 --- a/src/variable.c +++ b/src/variable.c @@ -8,8 +8,6 @@ #include "mruby/class.h" #include "mruby/khash.h" #include "mruby/variable.h" -#include "mruby/string.h" -#include "mruby/range.h" #include "error.h" #include "mruby/array.h" -- cgit v1.2.3 From 234b8e853cc8b3bac2945832d589562e41da1456 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 15 Jul 2012 16:37:23 +0900 Subject: make class_from_sym static --- include/mruby.h | 1 - src/class.c | 27 +++++++++++++++++++-------- src/variable.c | 13 ------------- 3 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby.h b/include/mruby.h index 1124ba89c..137a1b94e 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -297,7 +297,6 @@ void mrb_undef_method(mrb_state*, struct RClass*, const char*); mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv); struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super); struct RClass * mrb_module_new(mrb_state *mrb); -struct RClass * mrb_class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym name); struct RClass * mrb_class_get(mrb_state *mrb, const char *name); struct RClass * mrb_class_obj_get(mrb_state *mrb, const char *name); diff --git a/src/class.c b/src/class.c index 783627a7d..3985800d0 100644 --- a/src/class.c +++ b/src/class.c @@ -216,6 +216,23 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id return c; } +static struct RClass * +class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id) +{ + mrb_value c = mrb_const_get(mrb, mrb_obj_value(klass), id); + + if (c.tt != MRB_TT_MODULE && c.tt != MRB_TT_CLASS) { + mrb_raise(mrb, E_TYPE_ERROR, "%s is not a class/module", mrb_sym2name(mrb, id)); + } + return mrb_class_ptr(c); +} + +struct RClass * +mrb_class_get(mrb_state *mrb, const char *name) +{ + return class_from_sym(mrb, mrb->object_class, mrb_intern(mrb, name)); +} + /*! * Defines a class under the namespace of \a outer. * \param outer a class which contains the new class. @@ -239,10 +256,7 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s mrb_sym id = mrb_intern(mrb, name); if (mrb_const_defined_at(mrb, outer, id)) { - c = mrb_class_from_sym(mrb, outer, id); - if (c->tt != MRB_TT_CLASS) { - mrb_raise(mrb, E_TYPE_ERROR, "%s is not a class", mrb_sym2name(mrb, id)); - } + c = class_from_sym(mrb, outer, id); if (mrb_class_real(c->super) != super) { mrb_name_error(mrb, id, "%s is already defined", mrb_sym2name(mrb, id)); } @@ -266,10 +280,7 @@ mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name) mrb_sym id = mrb_intern(mrb, name); if (mrb_const_defined_at(mrb, outer, id)) { - c = mrb_class_from_sym(mrb, outer, id); - if (c->tt != MRB_TT_MODULE) { - mrb_raise(mrb, E_TYPE_ERROR, "%s is not a module", mrb_sym2name(mrb, id)); - } + c = class_from_sym(mrb, outer, id); return c; } c = mrb_module_new(mrb); diff --git a/src/variable.c b/src/variable.c index be686bf72..501bed5a6 100644 --- a/src/variable.c +++ b/src/variable.c @@ -495,19 +495,6 @@ mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id) return mrb_const_defined_0(mrb, klass, id, TRUE, FALSE); } -struct RClass * -mrb_class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id) -{ - mrb_value c = const_get(mrb, klass, id); - return mrb_class_ptr(c); -} - -struct RClass * -mrb_class_get(mrb_state *mrb, const char *name) -{ - return mrb_class_from_sym(mrb, mrb->object_class, mrb_intern(mrb, name)); -} - mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id) { -- cgit v1.2.3 From 08213e32e817f83313b1586d76c0e8735ba210e7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 25 Jul 2012 08:53:49 +0900 Subject: const reference from instance_eval should not cause SEGV --- src/variable.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 501bed5a6..a1a7f2e82 100644 --- a/src/variable.c +++ b/src/variable.c @@ -10,6 +10,7 @@ #include "mruby/variable.h" #include "error.h" #include "mruby/array.h" +#include "mruby/proc.h" #ifdef ENABLE_REGEXP #include "re.h" @@ -342,7 +343,10 @@ mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym) mrb_value mrb_vm_const_get(mrb_state *mrb, mrb_sym sym) { - return const_get(mrb, mrb->ci->target_class, sym); + struct RClass *c = mrb->ci->proc->target_class; + + if (!c) c = mrb->ci->target_class; + return const_get(mrb, c, sym); } void @@ -355,7 +359,10 @@ mrb_const_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v) void mrb_vm_const_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { - mrb_obj_iv_set(mrb, (struct RObject*)mrb->ci->target_class, sym, v); + struct RClass *c = mrb->ci->proc->target_class; + + if (!c) c = mrb->ci->target_class; + mrb_obj_iv_set(mrb, (struct RObject*)c, sym, v); } void -- cgit v1.2.3 From b2fc62f3a917e9ab1d562b49312f8d7dd2e057c5 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Sun, 29 Jul 2012 15:25:14 +0900 Subject: Remove commented out code. --- src/error.c | 9 ------- src/etc.c | 5 ---- src/hash.c | 8 +++---- src/kernel.c | 76 ++++++++++++++++------------------------------------------ src/object.c | 1 - src/range.c | 1 - src/string.c | 9 ------- src/struct.c | 9 ------- src/variable.c | 5 ---- 9 files changed, 24 insertions(+), 99 deletions(-) (limited to 'src/variable.c') diff --git a/src/error.c b/src/error.c index 5bfbc4319..e71245509 100644 --- a/src/error.c +++ b/src/error.c @@ -29,7 +29,6 @@ mrb_exc_new3(mrb_state *mrb, struct RClass* c, mrb_value str) return mrb_funcall(mrb, mrb_obj_value(c), "new", 1, str); } -//mrb_value make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr); /* * call-seq: * Exception.new(msg = nil) -> exception @@ -307,14 +306,6 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) case 3: n = 1; exception_call: - //if (argv[0] == sysstack_error) return argv[0]; - - //CONST_ID(mrb, exception, "exception"); - //mesg = mrb_check_funcall(mrb, argv[0], exception, n, argv+1); - //if (mrb_nil_p(mesg)) { - // /* undef */ - // mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); - //} if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) { mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1); } diff --git a/src/etc.c b/src/etc.c index 7e9381d16..d14498d9c 100644 --- a/src/etc.c +++ b/src/etc.c @@ -52,11 +52,6 @@ mrb_check_datatype(mrb_state *mrb, mrb_value obj, const struct mrb_data_type *ty mrb_value mrb_lastline_get(mrb_state *mrb) { - //mrb_value *var = mrb_svar(0); - //if (var) { - // return *var; - //} - //return mrb_nil_value(); mrb_value *argv; int argc; diff --git a/src/hash.c b/src/hash.c index 04e8c60be..5d3835019 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1339,9 +1339,9 @@ mrb_init_hash(mrb_state *mrb) mrb_define_method(mrb, h, "default_proc", mrb_hash_default_proc,ARGS_NONE()); /* 15.2.13.4.7 */ mrb_define_method(mrb, h, "default_proc=", mrb_hash_set_default_proc,ARGS_REQ(1)); /* 15.2.13.4.7 */ mrb_define_method(mrb, h, "__delete", mrb_hash_delete, ARGS_REQ(1)); /* core of 15.2.13.4.8 */ -//mrb_define_method(mrb, h, "each", mrb_hash_each_pair, ARGS_NONE()); /* 15.2.13.4.9 */ /* move to mrblib\hash.rb */ -//mrb_define_method(mrb, h, "each_key", mrb_hash_each_key, ARGS_NONE()); /* 15.2.13.4.10 */ /* move to mrblib\hash.rb */ -//mrb_define_method(mrb, h, "each_value", mrb_hash_each_value, ARGS_NONE()); /* 15.2.13.4.11 */ /* move to mrblib\hash.rb */ +// "each" 15.2.13.4.9 move to mrblib/hash.rb +// "each_key" 15.2.13.4.10 move to mrblib/hash.rb +// "each_value" 15.2.13.4.11 move to mrblib/hash.rb mrb_define_method(mrb, h, "empty?", mrb_hash_empty_p, ARGS_NONE()); /* 15.2.13.4.12 */ mrb_define_method(mrb, h, "has_key?", mrb_hash_has_key, ARGS_REQ(1)); /* 15.2.13.4.13 */ mrb_define_method(mrb, h, "has_value?", mrb_hash_has_value, ARGS_REQ(1)); /* 15.2.13.4.14 */ @@ -1352,7 +1352,7 @@ mrb_init_hash(mrb_state *mrb) mrb_define_method(mrb, h, "keys", mrb_hash_keys, ARGS_NONE()); /* 15.2.13.4.19 */ mrb_define_method(mrb, h, "length", mrb_hash_size_m, ARGS_NONE()); /* 15.2.13.4.20 */ mrb_define_method(mrb, h, "member?", mrb_hash_has_key, ARGS_REQ(1)); /* 15.2.13.4.21 */ -//mrb_define_method(mrb, h, "merge", mrb_hash_merge, ARGS_REQ(1)); /* 15.2.13.4.22 */ /* move to mrblib\hash.rb */ +// "merge" 15.2.13.4.22 move to mrblib/hash.rb mrb_define_method(mrb, h, "replace", mrb_hash_replace, ARGS_REQ(1)); /* 15.2.13.4.23 */ mrb_define_method(mrb, h, "shift", mrb_hash_shift, ARGS_NONE()); /* 15.2.13.4.24 */ mrb_define_method(mrb, h, "size", mrb_hash_size_m, ARGS_NONE()); /* 15.2.13.4.25 */ diff --git a/src/kernel.c b/src/kernel.c index 468891b23..8aba1a808 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -72,9 +72,6 @@ inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) int mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj) { - //const mrb_method_entry_t *me = mrb_method_entry(CLASS_OF(obj), mrb_intern("to_s")); - //if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC && - //me->def->body.cfunc.func == mrb_any_to_s) struct RProc *me = mrb_method_search(mrb, mrb_class(mrb, obj), mrb_intern(mrb, "to_s")); if (me && MRB_PROC_CFUNC_P(me) && (me->body.func == mrb_any_to_s)) return 1; @@ -314,52 +311,38 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj) { struct RClass *klass = RBASIC(obj)->c; - //if (!FL_TEST(klass, FL_SINGLETON)) - //return klass; if (klass->tt != MRB_TT_SCLASS) return klass; else { - //struct clone_method_data data; - /* copy singleton(unnamed) class */ - //VALUE clone = class_alloc(RBASIC(klass)->flags, 0); + /* copy singleton(unnamed) class */ struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class); - //clone->super = objklass->super; - if ((mrb_type(obj) == MRB_TT_CLASS) || - (mrb_type(obj) == MRB_TT_SCLASS)) { /* BUILTIN_TYPE(obj) == T_CLASS */ - clone->c = clone; - } - else { - clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass)); - } + if ((mrb_type(obj) == MRB_TT_CLASS) || + (mrb_type(obj) == MRB_TT_SCLASS)) { /* BUILTIN_TYPE(obj) == T_CLASS */ + clone->c = clone; + } + else { + clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass)); + } - clone->super = klass->super; - if (klass->iv) { - clone->iv = klass->iv; - } - if (klass->mt) { - clone->mt = kh_copy(mt, mrb, klass->mt); - } - else { - clone->mt = kh_init(mt, mrb); - } - clone->tt = MRB_TT_SCLASS; - return clone; + clone->super = klass->super; + if (klass->iv) { + clone->iv = klass->iv; + } + if (klass->mt) { + clone->mt = kh_copy(mt, mrb, klass->mt); + } + else { + clone->mt = kh_init(mt, mrb); + } + clone->tt = MRB_TT_SCLASS; + return clone; } } static void init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) { - //if (OBJ_FROZEN(dest)) { - // rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest)); - //} - //RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR); - //RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT); - //if (FL_TEST(obj, FL_EXIVAR)) { - // mrb_copy_generic_ivar(dest, obj); - //} - //mrb_gc_copy_finalizer(dest, obj); switch (mrb_type(obj)) { case MRB_TT_OBJECT: case MRB_TT_CLASS: @@ -416,8 +399,6 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self) clone = (struct RObject*)mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self)); clone->c = mrb_singleton_class_clone(mrb, self); init_copy(mrb, mrb_obj_value(clone), self); - //1-9-2 no bug mrb_funcall(mrb, clone, "initialize_clone", 1, self); - //RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE; return mrb_obj_value(clone); } @@ -466,7 +447,6 @@ mrb_obj_extend(mrb_state *mrb, int argc, mrb_value *argv, mrb_value obj) mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (at least 1)"); } for (i = 0; i < argc; i++) { - //Check_Type(argv[i], T_MODULE); mrb_check_type(mrb, argv[i], MRB_TT_MODULE); } while (argc--) { @@ -511,19 +491,6 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self) return mrb_obj_extend(mrb, argc, argv, self); } -/* 15.3.1.2.4 */ -/* 15.3.1.3.14 */ -/* - * call-seq: - * global_variables -> array - * - * Returns an array of the names of global variables. - * - * global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr] - */ -//mrb_value -//mrb_f_global_variables(mrb_state *mrb, mrb_value self) - /* 15.3.1.3.15 */ /* * call-seq: @@ -824,7 +791,6 @@ mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value o recur = mrb_true_value(); } else { - //mrb_scan_args(argc, argv, "01", &recur); recur = argv[0]; } klass = mrb_class(mrb, obj); @@ -853,7 +819,6 @@ retry: else { mrb_value recur; - //mrb_scan_args(argc, argv, "1", &recur); recur = argv[0]; if (mrb_test(recur)) { argc = 0; @@ -1073,7 +1038,6 @@ obj_respond_to(mrb_state *mrb, mrb_value self) mrb_sym id; mrb_get_args(mrb, "*", &argv, &argc); - //mrb_scan_args(argc, argv, "11", &mid, &priv); mid = argv[0]; if (argc > 1) priv = argv[1]; else priv = mrb_nil_value(); diff --git a/src/object.c b/src/object.c index 43e064fb0..4f5fb1d28 100644 --- a/src/object.c +++ b/src/object.c @@ -516,7 +516,6 @@ mrb_to_integer(mrb_state *mrb, mrb_value val, const char *method) mrb_value v; if (FIXNUM_P(val)) return val; - //if (TYPE(val) == T_BIGNUM) return val; v = convert_type(mrb, val, "Integer", method, TRUE); if (!mrb_obj_is_kind_of(mrb, v, mrb->fixnum_class)) { const char *cname = mrb_obj_classname(mrb, val); diff --git a/src/range.c b/src/range.c index 14fa2a6a3..9113a810a 100644 --- a/src/range.c +++ b/src/range.c @@ -412,7 +412,6 @@ range_initialize_copy(mrb_state *mrb, mrb_value copy) mrb_get_args(mrb, "o", &src); if (mrb_obj_equal(mrb, copy, src)) return copy; - //mrb_check_frozen(copy); if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } diff --git a/src/string.c b/src/string.c index e41116ebc..0a5dee88e 100644 --- a/src/string.c +++ b/src/string.c @@ -1354,7 +1354,6 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang) static mrb_value mrb_str_gsub(mrb_state *mrb, mrb_value self) { - //return str_gsub(argc, argv, self, 0); return str_gsub(mrb, self, 0); } @@ -1469,10 +1468,8 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) int argc; mrb_value sub; - //mrb_value initpos; mrb_int pos; - //if (mrb_scan_args(argc, argv, "11", &sub, &initpos) == 2) { mrb_get_args(mrb, "*", &argv, &argc); if (argc == 2) { pos = mrb_fixnum(argv[1]); @@ -1959,7 +1956,6 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) if (mrb_reg_search(mrb, pat, str, *start, 0) >= 0) { match = mrb_backref_get(mrb); - //regs = RMATCH(match)->regs; pmatch = mrb_match_ptr(match); regs = &pmatch->rmatch->regs; if (regs->beg[0] == regs->end[0]) { @@ -2143,7 +2139,6 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) split_type = awk; } else { -//fs_set: if (mrb_type(spat) == MRB_TT_STRING) { split_type = string; #ifdef ENABLE_REGEXP @@ -2546,7 +2541,6 @@ mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck) if (s) { len = RSTRING_LEN(str); if (s[len]) { /* no sentinel somehow */ - //char *p = ALLOCA_N(char, len+1); char *p = mrb_malloc(mrb, len+1); //MEMCPY(p, s, char, len); @@ -2584,10 +2578,8 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self) { mrb_value *argv; int argc; - //mrb_value b; int base; - //mrb_scan_args(argc, *argv, "01", &b); mrb_get_args(mrb, "*", &argv, &argc); if (argc == 0) base = 10; @@ -2710,7 +2702,6 @@ mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck) static mrb_value mrb_str_to_f(mrb_state *mrb, mrb_value self) { - //return mrb_float_new(mrb_str_to_dbl(self, 0/*Qfalse*/)); return mrb_float_value(mrb_str_to_dbl(mrb, self, 0/*Qfalse*/)); } diff --git a/src/struct.c b/src/struct.c index 6d8ce057f..0a95f9e49 100644 --- a/src/struct.c +++ b/src/struct.c @@ -38,8 +38,6 @@ struct_ivar_get(mrb_state *mrb, mrb_value c, mrb_sym id) mrb_value ans; for (;;) { - //if (mrb_ivar_defined(c, id)) - // return mrb_iv_get(mrb, c, id); ans = mrb_iv_get(mrb, c, id); if (!mrb_nil_p(ans)) return ans; kclass = RCLASS_SUPER(c); @@ -260,19 +258,15 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k //OBJ_FREEZE(members); if (mrb_nil_p(name)) { c = mrb_class_new(mrb, klass); - //mrb_make_metaclass(nstr, RBASIC(klass)->c); - //mrb_class_inherited(klass, nstr); } else { /* old style: should we warn? */ name = mrb_str_to_str(mrb, name); id = mrb_to_id(mrb, name); if (!mrb_is_const_id(id)) { - //mrb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); mrb_name_error(mrb, id, "identifier %s needs to be constant", mrb_string_value_ptr(mrb, name)); } if (mrb_const_defined_at(mrb, klass, id)) { - //mrb_warn("redefining constant Struct::%s", StringValuePtr(name)); mrb_warn("redefining constant Struct::%s", mrb_string_value_ptr(mrb, name)); //?rb_mod_remove_const(klass, mrb_sym2name(mrb, id)); } @@ -376,7 +370,6 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "&*", &b, &argv, &argc); if (argc > 0) name = argv[0]; if (argc > 1) rest = argv[1]; - //mrb_scan_args(argc, argv, "1*", &name, &rest); if (mrb_type(rest) == MRB_TT_ARRAY) { if (!mrb_nil_p(name) && SYMBOL_P(name)) { /* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */ @@ -389,7 +382,6 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) argcnt = argc-1; if (!mrb_nil_p(name) && SYMBOL_P(name)) { /* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */ - //mrb_ary_unshift(mrb, rest, name); name = mrb_nil_value(); pargv = &argv[0]; argcnt++; @@ -557,7 +549,6 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) mrb_get_args(mrb, "o", &s); if (mrb_obj_equal(mrb, copy, s)) return copy; - //mrb_check_frozen(copy); if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } diff --git a/src/variable.c b/src/variable.c index a1a7f2e82..04e5ad9f7 100644 --- a/src/variable.c +++ b/src/variable.c @@ -460,10 +460,6 @@ kiv_lookup(khash_t(iv)* table, mrb_sym key, mrb_value *value) khash_t(iv) *h=table; khiter_t k; - // you must check(iv==0), before you call this function. - //if (!obj->iv) { - // return 0; - //} k = kh_get(iv, h, key); if (k != kh_end(h)) { *value = kh_value(h, k); @@ -505,7 +501,6 @@ mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id) mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id) { - //return ivar_get(obj, id, FALSE); return mrb_iv_get(mrb, obj, id); } -- cgit v1.2.3 From e75c76ecee3a0b5b1b0b19d4fdd8c31b3e8bbd9b Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 17:16:05 +0900 Subject: iv khash initial size to 8 --- include/mruby/khash.h | 34 ++++++++++++++++++---------------- src/variable.c | 4 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 87ba44674..b28cd0702 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -39,7 +39,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; name: ash name khkey_t: key data type khval_t: value data type - kh_is_map: (not implemented / not used in RiteVM ) + kh_is_map: (not implemented / not used in RiteVM) */ #define KHASH_DECLARE(name, khkey_t, khval_t, kh_is_map) \ typedef struct kh_##name { \ @@ -56,6 +56,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; mrb_state *mrb; \ } kh_##name##_t; \ void kh_alloc_##name(kh_##name##_t *h); \ + kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size); \ kh_##name##_t *kh_init_##name(mrb_state *mrb); \ void kh_destroy_##name(kh_##name##_t *h); \ void kh_clear_##name(kh_##name##_t *h); \ @@ -70,7 +71,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; name: ash name khkey_t: key data type khval_t: value data type - kh_is_map: (not implemented / not used in RiteVM ) + kh_is_map: (not implemented / not used in RiteVM) __hash_func: hash function __hash_equal: hash comparation function */ @@ -101,7 +102,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ void kh_destroy_##name(kh_##name##_t *h) \ { \ - if( h ){ \ + if (h) { \ mrb_free(h->mrb, h->keys); \ mrb_free(h->mrb, h->vals); \ mrb_free(h->mrb, h->e_flags); \ @@ -110,7 +111,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ void kh_clear_##name(kh_##name##_t *h) \ { \ - if( h && h->e_flags ){ \ + if (h && h->e_flags) { \ memset(h->e_flags, 0xff, h->n_buckets/8*sizeof(uint8_t)); \ memset(h->d_flags, 0x00, h->n_buckets/8*sizeof(uint8_t)); \ h->size = h->n_occupied = 0; \ @@ -119,9 +120,9 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; khint_t kh_get_##name(kh_##name##_t *h, khkey_t key) \ { \ khint_t k = __hash_func(h->mrb,key) & (h->mask); \ - while( !__ac_isempty(h->e_flags, h->d_flags, k) ){ \ - if( !__ac_isdel(h->e_flags, h->d_flags, k) ){ \ - if( __hash_equal(h->mrb,h->keys[k], key) ) return k; \ + while (!__ac_isempty(h->e_flags, h->d_flags, k)) { \ + if (!__ac_isdel(h->e_flags, h->d_flags, k)) { \ + if (__hash_equal(h->mrb,h->keys[k], key)) return k; \ } \ k = (k+h->inc) & (h->mask); \ } \ @@ -129,12 +130,12 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ { \ - if( new_n_bucketsn_buckets = new_n_buckets; \ kh_alloc_##name(h); \ /* relocate */ \ - for( i=0 ; in_occupied >= h->upper_bound ){ \ + if (h->n_occupied >= h->upper_bound) { \ kh_resize_##name(h, h->n_buckets*2); \ } \ k = __hash_func(h->mrb,key) & (h->mask); \ - while( !__ac_iseither(h->e_flags, h->d_flags, k) ){ \ - if( __hash_equal(h->mrb,h->keys[k], key) ) break; \ + while (!__ac_iseither(h->e_flags, h->d_flags, k)) { \ + if (__hash_equal(h->mrb,h->keys[k], key)) break; \ k = (k+h->inc) & (h->mask); \ } \ - if( __ac_isempty(h->e_flags, h->d_flags, k) ) { \ + if (__ac_isempty(h->e_flags, h->d_flags, k)) { \ /* put at empty */ \ h->keys[k] = key; \ h->e_flags[k/8] &= ~__m[k%8]; \ h->size++; \ h->n_occupied++; \ - } else if( __ac_isdel(h->e_flags, h->d_flags, k) ) { \ + } else if (__ac_isdel(h->e_flags, h->d_flags, k)) { \ /* put at del */ \ h->keys[k] = key; \ h->d_flags[k/8] &= ~__m[k%8]; \ @@ -206,6 +207,7 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; #define khash_t(name) kh_##name##_t +#define kh_init_size(name,mrb,size) kh_init_##name##_size(mrb,size) #define kh_init(name,mrb) kh_init_##name(mrb) #define kh_destroy(name, h) kh_destroy_##name(h) #define kh_clear(name, h) kh_clear_##name(h) diff --git a/src/variable.c b/src/variable.c index 04e5ad9f7..49665a9ae 100644 --- a/src/variable.c +++ b/src/variable.c @@ -130,7 +130,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) khash_t(iv) *h; if (!obj->iv) { - h = obj->iv = kh_init(iv, mrb); + h = obj->iv = kh_init_size(iv, mrb, 8); } else { h = obj->iv; @@ -266,7 +266,7 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) c = mrb->ci->target_class; h = c->iv; if (!h) { - c->iv = h = kh_init(iv, mrb); + c->iv = h = kh_init_size(iv, mrb, 8); } k = kh_put(iv, h, sym); kh_value(h, k) = v; -- cgit v1.2.3 From 857370c2b703a7158dfde5766e4b3b6eedcff10c Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 17:33:54 +0900 Subject: use const MRB_IV_INITIAL_SIZE --- src/variable.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 49665a9ae..b81b292d9 100644 --- a/src/variable.c +++ b/src/variable.c @@ -16,6 +16,10 @@ #include "re.h" #endif +#ifndef MRB_IV_INITIAL_SIZE +#define MRB_IV_INITIAL_SIZE 8 +#endif + static void mark_tbl(mrb_state *mrb, struct kh_iv *h) { @@ -130,7 +134,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) khash_t(iv) *h; if (!obj->iv) { - h = obj->iv = kh_init_size(iv, mrb, 8); + h = obj->iv = kh_init_size(iv, mrb, MRB_IV_INITIAL_SIZE); } else { h = obj->iv; @@ -266,7 +270,7 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) c = mrb->ci->target_class; h = c->iv; if (!h) { - c->iv = h = kh_init_size(iv, mrb, 8); + c->iv = h = kh_init_size(iv, mrb, MRB_IV_INITIAL_SIZE); } k = kh_put(iv, h, sym); kh_value(h, k) = v; -- cgit v1.2.3 From d271bf0aa6e44a315802cf4246f5b92552be010a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 13:15:02 +0900 Subject: make mrb_funcall_argv and mrb_funcall_with_block to take mrb_sym as a method name --- include/mruby.h | 4 ++-- src/class.c | 36 ++++++++++++++++++++++++------------ src/error.c | 17 ++++++++++------- src/kernel.c | 2 +- src/re.c | 2 +- src/variable.c | 4 ++-- src/vm.c | 10 ++++++---- 7 files changed, 46 insertions(+), 29 deletions(-) (limited to 'src/variable.c') diff --git a/include/mruby.h b/include/mruby.h index 6fcda4d35..451b4eb8b 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -330,8 +330,8 @@ struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, co int mrb_get_args(mrb_state *mrb, const char *format, ...); mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, int,...); -mrb_value mrb_funcall_argv(mrb_state*, mrb_value, const char*, int, mrb_value*); -mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, const char*, int, mrb_value*, mrb_value); +mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, int, mrb_value*); +mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, int, mrb_value*, mrb_value); mrb_sym mrb_intern(mrb_state*,const char*); mrb_sym mrb_intern2(mrb_state*,const char*,int); mrb_sym mrb_intern_str(mrb_state*,mrb_value); diff --git a/src/class.c b/src/class.c index 6efc9f5e7..50d0b6317 100644 --- a/src/class.c +++ b/src/class.c @@ -723,8 +723,8 @@ mrb_mod_include(mrb_state *mrb, mrb_value klass) mrb_check_type(mrb, argv[i], MRB_TT_MODULE); } while (argc--) { - mrb_funcall_argv(mrb, argv[argc], "append_features", 1, &klass); - mrb_funcall_argv(mrb, argv[argc], "included", 1, &klass); + mrb_funcall(mrb, argv[argc], "append_features", 1, klass); + mrb_funcall(mrb, argv[argc], "included", 1, klass); } return klass; @@ -877,29 +877,41 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) mrb_value mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) { - mrb_value args[MRB_FUNCALL_ARGC_MAX]; + mrb_sym mid = mrb_intern(mrb, name); va_list ap; int i; - if (argc != 0) { + if (argc == 0) { + return mrb_funcall_argv(mrb, self, mid, 0, 0); + } + else if (argc == 1) { + mrb_value v; + + va_start(ap, argc); + v = va_arg(ap, mrb_value); + va_end(ap); + return mrb_funcall_argv(mrb, self, mid, 1, &v); + } + else { + mrb_value argv[MRB_FUNCALL_ARGC_MAX]; + if (argc > MRB_FUNCALL_ARGC_MAX) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", MRB_FUNCALL_ARGC_MAX); - } + mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)", MRB_FUNCALL_ARGC_MAX); + } va_start(ap, argc); for (i = 0; i < argc; i++) { - args[i] = va_arg(ap, mrb_value); + argv[i] = va_arg(ap, mrb_value); } va_end(ap); + return mrb_funcall_argv(mrb, self, mid, argc, argv); } - return mrb_funcall_argv(mrb, self, name, argc, args); } - void mrb_obj_call_init(mrb_state *mrb, mrb_value obj, int argc, mrb_value *argv) { - mrb_funcall_argv(mrb, obj, "initialize", argc, argv); + mrb_funcall_argv(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv); } /* @@ -938,7 +950,7 @@ mrb_class_new_instance_m(mrb_state *mrb, mrb_value klass) c = (struct RClass*)mrb_obj_alloc(mrb, k->tt, k); c->super = k; obj = mrb_obj_value(c); - mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk); + mrb_funcall_with_block(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv, blk); return obj; } @@ -957,7 +969,7 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv) o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c); obj = mrb_obj_value(o); mrb_get_args(mrb, "*&", &argv, &argc, &blk); - mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk); + mrb_funcall_with_block(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv, blk); return obj; } diff --git a/src/error.c b/src/error.c index e71245509..6fe839cb2 100644 --- a/src/error.c +++ b/src/error.c @@ -144,7 +144,7 @@ exc_equal(mrb_state *mrb, mrb_value exc) if (mrb_obj_equal(mrb, exc, obj)) return mrb_true_value(); if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) { - if ( mrb_respond_to(mrb, obj, mrb_intern(mrb, "message")) ) { + if (mrb_respond_to(mrb, obj, mrb_intern(mrb, "message"))) { mesg = mrb_funcall(mrb, obj, "message", 0); } else @@ -306,12 +306,15 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) case 3: n = 1; exception_call: - if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) { - mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1); - } - else { - /* undef */ - mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); + { + mrb_sym exc = mrb_intern(mrb, "exception"); + if (mrb_respond_to(mrb, argv[0], exc)) { + mesg = mrb_funcall_argv(mrb, argv[0], exc, n, argv+1); + } + else { + /* undef */ + mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); + } } break; diff --git a/src/kernel.c b/src/kernel.c index 36dfbe769..740960f80 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -245,7 +245,7 @@ mrb_f_send(mrb_state *mrb, mrb_value self) int argc; mrb_get_args(mrb, "n*&", &name, &argv, &argc, &block); - return mrb_funcall_with_block(mrb,self, mrb_sym2name(mrb, name), argc, argv, block); + return mrb_funcall_with_block(mrb,self, name, argc, argv, block); } /* 15.3.1.2.2 */ diff --git a/src/re.c b/src/re.c index f3cfea484..0022f9a9c 100644 --- a/src/re.c +++ b/src/re.c @@ -76,7 +76,7 @@ mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value re->ptr = 0; re->src = 0; re->usecnt = 0; - return mrb_funcall_argv(mrb, mrb_obj_value(re), "initialize", argc, argv); + return mrb_funcall_argv(mrb, mrb_obj_value(re), mrb_intern(mrb, "initialize"), argc, argv); } mrb_value diff --git a/src/variable.c b/src/variable.c index b81b292d9..a62e7e126 100644 --- a/src/variable.c +++ b/src/variable.c @@ -320,8 +320,8 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) return kh_value(h, k); } if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { - mrb_value argv = mrb_symbol_value(sym); - return mrb_funcall_argv(mrb, mrb_obj_value(c), "const_missing", 1, &argv); + mrb_value name = mrb_symbol_value(sym); + return mrb_funcall(mrb, mrb_obj_value(c), "const_missing", 1, name); } } c = c->super; diff --git a/src/vm.c b/src/vm.c index 2a13f0ea4..130e56071 100644 --- a/src/vm.c +++ b/src/vm.c @@ -179,16 +179,18 @@ ecall(mrb_state *mrb, int i) } mrb_value -mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int argc, mrb_value *argv, mrb_value blk) +mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mrb_value *argv, mrb_value blk) { struct RProc *p; struct RClass *c; - mrb_sym mid = mrb_intern(mrb, name); mrb_sym undef = 0; mrb_callinfo *ci; int n = mrb->ci->nregs; mrb_value val; + if (argc < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argc for funcall (%d)", argc); + } c = mrb_class(mrb, self); p = mrb_method_search_vm(mrb, &c, mid); if (!p) { @@ -232,9 +234,9 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int arg } mrb_value -mrb_funcall_argv(mrb_state *mrb, mrb_value self, const char *name, int argc, mrb_value *argv) +mrb_funcall_argv(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mrb_value *argv) { - return mrb_funcall_with_block(mrb, self, name, argc, argv, mrb_nil_value()); + return mrb_funcall_with_block(mrb, self, mid, argc, argv, mrb_nil_value()); } mrb_value -- cgit v1.2.3 From b00529e672a6b64ec41b36c25395d66364f8cc20 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 2 Aug 2012 01:53:01 +0900 Subject: reduce invoking const_missing --- src/variable.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index a62e7e126..0b4288734 100644 --- a/src/variable.c +++ b/src/variable.c @@ -309,7 +309,8 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) struct RClass *c = base; khash_t(iv) *h; khiter_t k; - mrb_sym cm = mrb_intern(mrb, "const_missing"); + int retry = 0; + mrb_sym cm; L_RETRY: while (c) { @@ -319,18 +320,23 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) if (k != kh_end(h)) { return kh_value(h, k); } - if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { - mrb_value name = mrb_symbol_value(sym); - return mrb_funcall(mrb, mrb_obj_value(c), "const_missing", 1, name); - } } c = c->super; } - - if (base->tt == MRB_TT_MODULE) { - c = base = mrb->object_class; + if (!retry && base->tt == MRB_TT_MODULE) { + c = mrb->object_class; + retry = 1; goto L_RETRY; } + c = base; + cm = mrb_intern(mrb, "const_missing"); + while (c) { + if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { + mrb_value name = mrb_symbol_value(sym); + return mrb_funcall(mrb, mrb_obj_value(c), "const_missing", 1, name); + } + c = c->super; + } mrb_raise(mrb, E_NAME_ERROR, "uninitialized constant %s", mrb_sym2name(mrb, sym)); /* not reached */ -- cgit v1.2.3 From 52ba6f5a8c79d4463167e2a3b802aa5238a52b51 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 5 Aug 2012 17:12:03 +0900 Subject: class variable resolution should be same as const resolution --- src/variable.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 0b4288734..8b94f5bbb 100644 --- a/src/variable.c +++ b/src/variable.c @@ -233,8 +233,9 @@ mrb_obj_instance_variables(mrb_state *mrb, mrb_value self) mrb_value mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) { - struct RClass *c = mrb->ci->target_class; + struct RClass *c = mrb->ci->proc->target_class; + if (!c) c = mrb->ci->target_class; while (c) { if (c->iv) { khash_t(iv) *h = c->iv; @@ -251,10 +252,11 @@ mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) void mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { - struct RClass *c = mrb->ci->target_class; + struct RClass *c = mrb->ci->proc->target_class; khash_t(iv) *h; khiter_t k; + if (!c) c = mrb->ci->target_class; while (c) { if (c->iv) { h = c->iv; -- cgit v1.2.3