From 0249e7dd7f5407939d47f272cb0d1d36783c0bd2 Mon Sep 17 00:00:00 2001 From: cremno Date: Thu, 5 Jun 2014 01:16:23 +0200 Subject: mruby-struct: internal linkage for all functions --- mrbgems/mruby-struct/src/struct.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'mrbgems/mruby-struct/src') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 6894ffec9..f27e0ba71 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -40,13 +40,13 @@ struct_ivar_get(mrb_state *mrb, mrb_value c, mrb_sym id) } } -mrb_value +static mrb_value mrb_struct_iv_get(mrb_state *mrb, mrb_value c, const char *name) { return struct_ivar_get(mrb, c, mrb_intern_cstr(mrb, name)); } -mrb_value +static mrb_value mrb_struct_s_members(mrb_state *mrb, mrb_value klass) { mrb_value members = struct_ivar_get(mrb, klass, mrb_intern_lit(mrb, "__members__")); @@ -60,7 +60,7 @@ mrb_struct_s_members(mrb_state *mrb, mrb_value klass) return members; } -mrb_value +static mrb_value mrb_struct_members(mrb_state *mrb, mrb_value s) { mrb_value members = mrb_struct_s_members(mrb, mrb_obj_value(mrb_obj_class(mrb, s))); @@ -109,7 +109,7 @@ mrb_struct_members_m(mrb_state *mrb, mrb_value obj) return mrb_struct_s_members_m(mrb, mrb_obj_value(mrb_obj_class(mrb, obj))); } -mrb_value +static mrb_value mrb_struct_getmember(mrb_state *mrb, mrb_value obj, mrb_sym id) { mrb_value members, slot, *ptr, *ptr_members; @@ -162,7 +162,7 @@ static mrb_value (*const ref_func[])(mrb_state*, mrb_value) = { mrb_struct_ref9, }; -mrb_sym +static mrb_sym mrb_id_attrset(mrb_state *mrb, mrb_sym id) { const char *name; @@ -219,14 +219,14 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj) #define is_notop_id(id) (id) /* ((id)>tLAST_TOKEN) */ #define is_local_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_LOCAL) */ -int +static int mrb_is_local_id(mrb_sym id) { return is_local_id(id); } #define is_const_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_CONST) */ -int +static int mrb_is_const_id(mrb_sym id) { return is_const_id(id); @@ -284,7 +284,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k return nstr; } -mrb_value +static mrb_value mrb_struct_define(mrb_state *mrb, const char *name, ...) { va_list ar; @@ -436,7 +436,7 @@ mrb_struct_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value return mrb_struct_initialize_withArg(mrb, argc, argv, self); } -mrb_value +static mrb_value mrb_struct_initialize(mrb_state *mrb, mrb_value self, mrb_value values) { return mrb_struct_initialize_withArg(mrb, RARRAY_LEN(values), RARRAY_PTR(values), self); @@ -506,7 +506,7 @@ mrb_struct_inspect(mrb_state *mrb, mrb_value s) /* 15.2.18.4.9 */ /* :nodoc: */ -mrb_value +static mrb_value mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) { mrb_value s; @@ -584,7 +584,7 @@ struct_aref_int(mrb_state *mrb, mrb_value s, mrb_int i) * joe[:name] #=> "Joe Smith" * joe[0] #=> "Joe Smith" */ -mrb_value +static mrb_value mrb_struct_aref(mrb_state *mrb, mrb_value s) { mrb_value idx; @@ -651,7 +651,7 @@ mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val) * joe.zip #=> "90210" */ -mrb_value +static mrb_value mrb_struct_aset(mrb_state *mrb, mrb_value s) { mrb_int i; -- cgit v1.2.3 From 64b0e48dcbb65d77fe3da68ee2368394642445ba Mon Sep 17 00:00:00 2001 From: cremno Date: Thu, 5 Jun 2014 01:27:39 +0200 Subject: mruby-struct: use correct data types --- mrbgems/mruby-struct/src/struct.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'mrbgems/mruby-struct/src') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index f27e0ba71..8b2b71513 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -149,7 +149,7 @@ static mrb_value mrb_struct_ref9(mrb_state* mrb, mrb_value obj) {return RSTRUCT_ #define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) #define N_REF_FUNC numberof(ref_func) -static mrb_value (*const ref_func[])(mrb_state*, mrb_value) = { +static const mrb_func_t ref_func[] = { mrb_struct_ref0, mrb_struct_ref1, mrb_struct_ref2, @@ -185,8 +185,7 @@ static mrb_value mrb_struct_set(mrb_state *mrb, mrb_value obj, mrb_value val) { const char *name; - size_t i, len; - mrb_int slen; + mrb_int i, len, slen; mrb_sym mid; mrb_value members, slot, *ptr, *ptr_members; @@ -219,17 +218,17 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj) #define is_notop_id(id) (id) /* ((id)>tLAST_TOKEN) */ #define is_local_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_LOCAL) */ -static int +static mrb_bool mrb_is_local_id(mrb_sym id) { - return is_local_id(id); + return !!is_local_id(id); } #define is_const_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_CONST) */ -static int +static mrb_bool mrb_is_const_id(mrb_sym id) { - return is_const_id(id); + return !!is_const_id(id); } static mrb_value @@ -344,7 +343,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) { mrb_value name, rest; mrb_value *pargv; - int argcnt; + mrb_int argcnt; mrb_int i; mrb_value b, st; mrb_sym id; @@ -391,7 +390,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) return st; } -static int +static mrb_int num_members(mrb_state *mrb, struct RClass *klass) { mrb_value members; @@ -407,10 +406,10 @@ num_members(mrb_state *mrb, struct RClass *klass) /* */ static mrb_value -mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_value self) +mrb_struct_initialize_withArg(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value self) { struct RClass *klass = mrb_obj_class(mrb, self); - int i, n; + mrb_int i, n; n = num_members(mrb, klass); if (n < argc) { @@ -443,7 +442,7 @@ mrb_struct_initialize(mrb_state *mrb, mrb_value self, mrb_value values) } static mrb_value -inspect_struct(mrb_state *mrb, mrb_value s, int recur) +inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur) { const char *cn = mrb_class_name(mrb, mrb_obj_class(mrb, s)); mrb_value members, str = mrb_str_new_lit(mrb, "# Date: Thu, 5 Jun 2014 01:31:15 +0200 Subject: mruby-struct: remove unused functions --- mrbgems/mruby-struct/src/struct.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'mrbgems/mruby-struct/src') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 8b2b71513..3a0369ecb 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -5,7 +5,6 @@ */ #include -#include #include "mruby.h" #include "mruby/array.h" #include "mruby/string.h" @@ -40,12 +39,6 @@ struct_ivar_get(mrb_state *mrb, mrb_value c, mrb_sym id) } } -static mrb_value -mrb_struct_iv_get(mrb_state *mrb, mrb_value c, const char *name) -{ - return struct_ivar_get(mrb, c, mrb_intern_cstr(mrb, name)); -} - static mrb_value mrb_struct_s_members(mrb_state *mrb, mrb_value klass) { @@ -283,27 +276,6 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k return nstr; } -static mrb_value -mrb_struct_define(mrb_state *mrb, const char *name, ...) -{ - va_list ar; - mrb_value nm, ary; - char *mem; - - if (!name) nm = mrb_nil_value(); - else nm = mrb_str_new_cstr(mrb, name); - ary = mrb_ary_new(mrb); - - va_start(ar, name); - while ((mem = va_arg(ar, char*)) != 0) { - mrb_sym slot = mrb_intern_cstr(mrb, mem); - mrb_ary_push(mrb, ary, mrb_symbol_value(slot)); - } - va_end(ar); - - return make_struct(mrb, nm, ary, struct_class(mrb)); -} - /* 15.2.18.3.1 */ /* * call-seq: @@ -435,12 +407,6 @@ mrb_struct_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value return mrb_struct_initialize_withArg(mrb, argc, argv, self); } -static mrb_value -mrb_struct_initialize(mrb_state *mrb, mrb_value self, mrb_value values) -{ - return mrb_struct_initialize_withArg(mrb, RARRAY_LEN(values), RARRAY_PTR(values), self); -} - static mrb_value inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur) { -- cgit v1.2.3 From 025b8f764492d82a4b8e2c739f61dfd4a4174531 Mon Sep 17 00:00:00 2001 From: cremno Date: Thu, 5 Jun 2014 18:30:52 +0200 Subject: mruby-struct: implement `mrb_is_(local|const)_id` --- mrbgems/mruby-struct/src/struct.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'mrbgems/mruby-struct/src') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 3a0369ecb..9d749a152 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -4,6 +4,7 @@ ** See Copyright Notice in mruby.h */ +#include #include #include "mruby.h" #include "mruby/array.h" @@ -209,19 +210,18 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj) return mrb_struct_set(mrb, obj, val); } -#define is_notop_id(id) (id) /* ((id)>tLAST_TOKEN) */ -#define is_local_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_LOCAL) */ static mrb_bool -mrb_is_local_id(mrb_sym id) +mrb_is_local_id(mrb_state *mrb, mrb_sym id) { - return !!is_local_id(id); + const char *name = mrb_sym2name_len(mrb, id, NULL); + return !ISUPPER(name[0]); } -#define is_const_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_CONST) */ static mrb_bool -mrb_is_const_id(mrb_sym id) +mrb_is_const_id(mrb_state *mrb, mrb_sym id) { - return !!is_const_id(id); + const char *name = mrb_sym2name_len(mrb, id, NULL); + return ISUPPER(name[0]); } static mrb_value @@ -240,7 +240,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k /* old style: should we warn? */ name = mrb_str_to_str(mrb, name); id = mrb_obj_to_sym(mrb, name); - if (!mrb_is_const_id(id)) { + if (!mrb_is_const_id(mrb, id)) { mrb_name_error(mrb, id, "identifier %S needs to be constant", name); } if (mrb_const_defined_at(mrb, klass, id)) { @@ -262,7 +262,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k ai = mrb_gc_arena_save(mrb); for (i=0; i< len; i++) { mrb_sym id = mrb_symbol(ptr_members[i]); - if (mrb_is_local_id(id) || mrb_is_const_id(id)) { + if (mrb_is_local_id(mrb, id) || mrb_is_const_id(mrb, id)) { if (i < N_REF_FUNC) { mrb_define_method_id(mrb, c, id, ref_func[i], MRB_ARGS_NONE()); } @@ -438,7 +438,7 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur) } slot = ptr_members[i]; id = mrb_symbol(slot); - if (mrb_is_local_id(id) || mrb_is_const_id(id)) { + if (mrb_is_local_id(mrb, id) || mrb_is_const_id(mrb, id)) { const char *name; mrb_int len; -- cgit v1.2.3