diff options
| -rw-r--r-- | include/mrbconf.h | 5 | ||||
| -rw-r--r-- | include/mruby.h | 3 | ||||
| -rw-r--r-- | include/mruby/array.h | 18 | ||||
| -rw-r--r-- | include/mruby/string.h | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-math/src/math.c | 40 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 6 | ||||
| -rw-r--r-- | mrblib/array.rb | 2 | ||||
| -rw-r--r-- | mrblib/compar.rb | 4 | ||||
| -rw-r--r-- | mrblib/enum.rb | 12 | ||||
| -rw-r--r-- | mrblib/hash.rb | 2 | ||||
| -rw-r--r-- | src/array.c | 90 | ||||
| -rw-r--r-- | src/class.c | 12 | ||||
| -rw-r--r-- | src/codegen.c | 24 | ||||
| -rw-r--r-- | src/error.c | 26 | ||||
| -rw-r--r-- | src/gc.c | 4 | ||||
| -rw-r--r-- | src/hash.c | 8 | ||||
| -rw-r--r-- | src/kernel.c | 8 | ||||
| -rw-r--r-- | src/load.c | 2 | ||||
| -rw-r--r-- | src/numeric.c | 8 | ||||
| -rw-r--r-- | src/parse.y | 9 | ||||
| -rw-r--r-- | src/range.c | 8 | ||||
| -rw-r--r-- | src/sprintf.c | 4 | ||||
| -rw-r--r-- | src/state.c | 8 | ||||
| -rw-r--r-- | src/string.c | 13 | ||||
| -rw-r--r-- | src/variable.c | 2 |
25 files changed, 152 insertions, 172 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h index c84480af7..613f0575e 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -23,7 +23,7 @@ //#define MRB_ENDIAN_BIG /* argv max size in mrb_funcall */ -//#define MRB_FUNCALL_ARGC_MAX 16 +//#define MRB_FUNCALL_ARGC_MAX 16 /* number of object per heap page */ //#define MRB_HEAP_PAGE_SIZE 1024 @@ -34,6 +34,9 @@ /* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */ //#define MRB_IVHASH_INIT_SIZE 8 +/* initial size for IREP array */ +//#define MRB_IREP_ARRAY_INIT_SIZE (256u) + /* default size of khash table bucket */ //#define KHASH_DEFAULT_SIZE 32 diff --git a/include/mruby.h b/include/mruby.h index 61df6e9ed..fe97dd055 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -129,9 +129,6 @@ typedef struct mrb_state { mrb_sym symidx; struct kh_n2s *name2sym; /* symbol table */ -#ifdef INCLUDE_REGEXP - struct RNode *local_svar;/* regexp */ -#endif #ifdef ENABLE_DEBUG void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs); diff --git a/include/mruby/array.h b/include/mruby/array.h index 9f9483545..5d78ccddd 100644 --- a/include/mruby/array.h +++ b/include/mruby/array.h @@ -14,14 +14,14 @@ extern "C" { typedef struct mrb_shared_array { int refcnt; mrb_value *ptr; - int len; + mrb_int len; } mrb_shared_array; struct RArray { MRB_OBJECT_HEADER; - int len; + mrb_int len; union { - int capa; + mrb_int capa; mrb_shared_array *shared; } aux; mrb_value *ptr; @@ -36,24 +36,24 @@ struct RArray { #define MRB_ARY_SHARED 256 void mrb_ary_decref(mrb_state*, mrb_shared_array*); -mrb_value mrb_ary_new_capa(mrb_state*, int); +mrb_value mrb_ary_new_capa(mrb_state*, mrb_int); mrb_value mrb_ary_new(mrb_state *mrb); -mrb_value mrb_ary_new_elts(mrb_state *mrb, int n, const mrb_value *elts); +mrb_value mrb_ary_new_elts(mrb_state *mrb, mrb_int n, const mrb_value *elts); void mrb_ary_concat(mrb_state*, mrb_value, mrb_value); mrb_value mrb_ary_splat(mrb_state*, mrb_value); void mrb_ary_push(mrb_state*, mrb_value, mrb_value); mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); -mrb_value mrb_ary_new_from_values(mrb_state *mrb, int size, mrb_value *vals); +mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, mrb_value *vals); mrb_value mrb_ary_aget(mrb_state *mrb, mrb_value self); mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n); void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); -int mrb_ary_len(mrb_state *mrb, mrb_value ary); +mrb_int mrb_ary_len(mrb_state *mrb, mrb_value ary); void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b); mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self); mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item); -mrb_value mrb_ary_new4(mrb_state *mrb, int n, const mrb_value *elts); +mrb_value mrb_ary_new4(mrb_state *mrb, mrb_int n, const mrb_value *elts); mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr); -mrb_value mrb_ary_entry(mrb_value ary, int offset); +mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset); mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self); mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self); diff --git a/include/mruby/string.h b/include/mruby/string.h index 353d8cefc..3f661a742 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -24,14 +24,14 @@ extern const char mrb_digitmap[]; typedef struct mrb_shared_string { int refcnt; char *ptr; - int len; + mrb_int len; } mrb_shared_string; struct RString { MRB_OBJECT_HEADER; - int len; + mrb_int len; union { - int capa; + mrb_int capa; mrb_shared_string *shared; } aux; char *ptr; diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c index 9955d9862..76058250f 100644 --- a/mrbgems/mruby-math/src/math.c +++ b/mrbgems/mruby-math/src/math.c @@ -26,13 +26,13 @@ double erfc(double x); -/* +/* ** Implementations of error functions ** credits to http://www.digitalmars.com/archives/cplusplus/3634.html */ /* Implementation of Error function */ -double +double erf(double x) { static const double two_sqrtpi = 1.128379167095512574; @@ -55,24 +55,24 @@ erf(double x) } /* Implementation of complementary Error function */ -double +double erfc(double x) { - static const double one_sqrtpi= 0.564189583547756287; - double a = 1; - double b = x; - double c = x; - double d = x*x+0.5; + static const double one_sqrtpi= 0.564189583547756287; + double a = 1; + double b = x; + double c = x; + double d = x*x+0.5; double q1; double q2 = b/d; double n = 1.0; double t; if (fabs(x) < 2.2) { - return 1.0 - erf(x); - } - if (x < 0.0) { /*signbit(x)*/ - return 2.0 - erfc(-x); - } + return 1.0 - erf(x); + } + if (x < 0.0) { /*signbit(x)*/ + return 2.0 - erfc(-x); + } do { t = a*n+b*x; a = b; @@ -306,7 +306,7 @@ math_asinh(mrb_state *mrb, mrb_value obj) mrb_float x; mrb_get_args(mrb, "f", &x); - + x = asinh(x); return mrb_float_value(x); @@ -477,10 +477,10 @@ static mrb_value math_sqrt(mrb_state *mrb, mrb_value obj) { mrb_float x; - + mrb_get_args(mrb, "f", &x); x = sqrt(x); - + return mrb_float_value(x); } @@ -544,7 +544,7 @@ math_frexp(mrb_state *mrb, mrb_value obj) { mrb_float x; int exp; - + mrb_get_args(mrb, "f", &x); x = frexp(x, &exp); @@ -633,13 +633,13 @@ mrb_mruby_math_gem_init(mrb_state* mrb) { struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - + #ifdef M_PI mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); #else mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); #endif - + #ifdef M_E mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); #else @@ -660,7 +660,7 @@ mrb_mruby_math_gem_init(mrb_state* mrb) mrb_define_module_function(mrb, mrb_math, "acos", math_acos, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "atan", math_atan, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "atan2", math_atan2, ARGS_REQ(2)); - + mrb_define_module_function(mrb, mrb_math, "sinh", math_sinh, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "cosh", math_cosh, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "tanh", math_tanh, ARGS_REQ(1)); diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index a49d8244b..33997b294 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -352,8 +352,8 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "*&", &argv, &argc, &b); if (argc == 0) { /* special case to avoid crash */ rest = mrb_ary_new(mrb); - } - else { + } + else { if (argc > 0) name = argv[0]; if (argc > 1) rest = argv[1]; if (mrb_array_p(rest)) { @@ -378,7 +378,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) id = mrb_to_id(mrb, RARRAY_PTR(rest)[i]); RARRAY_PTR(rest)[i] = mrb_symbol_value(id); } - } + } st = make_struct(mrb, name, rest, struct_class(mrb)); if (!mrb_nil_p(b)) { mrb_funcall(mrb, b, "call", 1, &st); diff --git a/mrblib/array.rb b/mrblib/array.rb index abbb38cb6..82df90950 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -52,7 +52,7 @@ class Array ## # Alias for collect! - # + # # ISO 15.2.12.5.20 alias map! collect! diff --git a/mrblib/compar.rb b/mrblib/compar.rb index 9f2ab887d..40fb2e7f0 100644 --- a/mrblib/compar.rb +++ b/mrblib/compar.rb @@ -25,7 +25,7 @@ module Comparable # Return true if +self+ is less # than or equal to +other+. # Otherwise return false. - # + # # ISO 15.3.3.2.2 def <= other cmp = self <=> other @@ -88,7 +88,7 @@ module Comparable end ## - # Return true if +self+ is greater + # Return true if +self+ is greater # than or equal to +min+ and # less than or equal to +max+. # Otherwise return false. diff --git a/mrblib/enum.rb b/mrblib/enum.rb index 2774bc856..0593e1f04 100644 --- a/mrblib/enum.rb +++ b/mrblib/enum.rb @@ -73,7 +73,7 @@ module Enumerable ## # Call the given block for each element # which is yield by +each+. Append all - # values of each block together and + # values of each block together and # return this value. # # ISO 15.3.2.2.3 @@ -89,7 +89,7 @@ module Enumerable # Call the given block for each element # which is yield by +each+. Return # +ifnone+ if no block value was true. - # Otherwise return the first block value + # Otherwise return the first block value # which had was true. # # ISO 15.3.2.2.4 @@ -158,8 +158,8 @@ module Enumerable # Call the given block for each element # which is yield by +each+ and which return # value was true when invoking === with - # +pattern+. Return an array with all - # elements or the respective block values. + # +pattern+. Return an array with all + # elements or the respective block values. # # ISO 15.3.2.2.9 def grep(pattern, &block) @@ -291,9 +291,9 @@ module Enumerable ## # Call the given block for each element - # which is yield by +each+. Return an + # which is yield by +each+. Return an # array which contains two arrays. The - # first array contains all elements + # first array contains all elements # whose block value was true. The second # array contains all elements whose # block value was false. diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 7b7b3f8ac..c304d4845 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -64,7 +64,7 @@ class Hash # it will be called for each element with # a duplicate key. The value of the block # will be the final value of this element. - # + # # ISO 15.2.13.4.22 def merge(other, &block) h = {} diff --git a/src/array.c b/src/array.c index c767283aa..b55a47f66 100644 --- a/src/array.c +++ b/src/array.c @@ -10,14 +10,18 @@ #include "mruby/string.h" #include "mruby/class.h" +/* SIZE_MAX is not supported by VC++. */ +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t)-1) +#endif + #define ARY_DEFAULT_LEN 4 #define ARY_SHRINK_RATIO 5 /* must be larger than 2 */ -#ifdef INT_MAX -# define ARY_MAX_SIZE (INT_MAX / sizeof(mrb_value)) -#endif +#define ARY_C_MAX_SIZE (SIZE_MAX / sizeof(mrb_value)) +#define ARY_MAX_SIZE ((ARY_C_MAX_SIZE < (size_t)MRB_INT_MAX) ? (mrb_int)ARY_C_MAX_SIZE : MRB_INT_MAX) static inline mrb_value -ary_elt(mrb_value ary, int offset) +ary_elt(mrb_value ary, mrb_int offset) { if (RARRAY_LEN(ary) == 0) return mrb_nil_value(); if (offset < 0 || RARRAY_LEN(ary) <= offset) { @@ -27,16 +31,14 @@ ary_elt(mrb_value ary, int offset) } static struct RArray* -ary_new_capa(mrb_state *mrb, int capa) +ary_new_capa(mrb_state *mrb, mrb_int capa) { struct RArray *a; - int blen; + mrb_int blen; -#ifdef INT_MAX if (capa > ARY_MAX_SIZE) { mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); } -#endif blen = capa * sizeof(mrb_value) ; if (blen < capa) { mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); @@ -51,7 +53,7 @@ ary_new_capa(mrb_state *mrb, int capa) } mrb_value -mrb_ary_new_capa(mrb_state *mrb, int capa) +mrb_ary_new_capa(mrb_state *mrb, mrb_int capa) { struct RArray *a = ary_new_capa(mrb, capa); return mrb_obj_value(a); @@ -89,7 +91,7 @@ array_copy(mrb_value *dst, const mrb_value *src, size_t size) mrb_value -mrb_ary_new_from_values(mrb_state *mrb, int size, mrb_value *vals) +mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, mrb_value *vals) { mrb_value ary; struct RArray *a; @@ -112,7 +114,7 @@ mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr) } static void -ary_fill_with_nil(mrb_value *ptr, int size) +ary_fill_with_nil(mrb_value *ptr, mrb_int size) { mrb_value nil = mrb_nil_value(); @@ -134,13 +136,13 @@ ary_modify(mrb_state *mrb, struct RArray *a) } else { mrb_value *ptr, *p; - int len; + mrb_int len; p = a->ptr; len = a->len * sizeof(mrb_value); ptr = (mrb_value *)mrb_malloc(mrb, len); if (p) { - array_copy(ptr, p, a->len); + array_copy(ptr, p, a->len); } a->ptr = ptr; a->aux.capa = a->len; @@ -170,15 +172,13 @@ ary_make_shared(mrb_state *mrb, struct RArray *a) } static void -ary_expand_capa(mrb_state *mrb, struct RArray *a, int len) +ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len) { - int capa = a->aux.capa; + mrb_int capa = a->aux.capa; -#ifdef INT_MAX if (len > ARY_MAX_SIZE) { mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big"); } -#endif while(capa < len) { if (capa == 0) { @@ -189,9 +189,7 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, int len) } } -#ifdef INT_MAX if (capa > ARY_MAX_SIZE) capa = ARY_MAX_SIZE; /* len <= capa <= ARY_MAX_SIZE */ -#endif if (capa > a->aux.capa) { a->aux.capa = capa; @@ -202,7 +200,7 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, int len) static void ary_shrink_capa(mrb_state *mrb, struct RArray *a) { - int capa = a->aux.capa; + mrb_int capa = a->aux.capa; if (capa < ARY_DEFAULT_LEN * 2) return; if (capa <= a->len * ARY_SHRINK_RATIO) return; @@ -228,13 +226,13 @@ mrb_ary_s_create(mrb_state *mrb, mrb_value self) int len; mrb_get_args(mrb, "*", &vals, &len); - return mrb_ary_new_from_values(mrb, (int)len, vals); + return mrb_ary_new_from_values(mrb, len, vals); } static void -ary_concat(mrb_state *mrb, struct RArray *a, mrb_value *ptr, int blen) +ary_concat(mrb_state *mrb, struct RArray *a, mrb_value *ptr, mrb_int blen) { - int len = a->len + blen; + mrb_int len = a->len + blen; ary_modify(mrb, a); if (a->aux.capa < len) ary_expand_capa(mrb, a, len); @@ -255,7 +253,7 @@ mrb_value mrb_ary_concat_m(mrb_state *mrb, mrb_value self) { mrb_value *ptr; - int blen; + mrb_int blen; mrb_get_args(mrb, "a", &ptr, &blen); ary_concat(mrb, mrb_ary_ptr(self), ptr, blen); @@ -269,7 +267,7 @@ mrb_ary_plus(mrb_state *mrb, mrb_value self) struct RArray *a2; mrb_value ary; mrb_value *ptr; - int blen; + mrb_int blen; mrb_get_args(mrb, "a", &ptr, &blen); ary = mrb_ary_new_capa(mrb, a1->len + blen); @@ -305,7 +303,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1) mrb_value ary2; struct RArray *a1, *a2; mrb_value r = mrb_nil_value(); - int i, len; + mrb_int i, len; mrb_get_args(mrb, "o", &ary2); if (!mrb_array_p(ary2)) return mrb_nil_value(); @@ -329,7 +327,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1) } static void -ary_replace(mrb_state *mrb, struct RArray *a, mrb_value *argv, int len) +ary_replace(mrb_state *mrb, struct RArray *a, mrb_value *argv, mrb_int len) { ary_modify(mrb, a); if (a->aux.capa < len) @@ -429,7 +427,7 @@ mrb_ary_reverse(mrb_state *mrb, mrb_value self) } mrb_value -mrb_ary_new4(mrb_state *mrb, int n, const mrb_value *elts) +mrb_ary_new4(mrb_state *mrb, mrb_int n, const mrb_value *elts) { mrb_value ary; @@ -443,7 +441,7 @@ mrb_ary_new4(mrb_state *mrb, int n, const mrb_value *elts) } mrb_value -mrb_ary_new_elts(mrb_state *mrb, int n, const mrb_value *elts) +mrb_ary_new_elts(mrb_state *mrb, mrb_int n, const mrb_value *elts) { return mrb_ary_new4(mrb, n, elts); } @@ -505,7 +503,7 @@ mrb_ary_shift(mrb_state *mrb, mrb_value self) } else { mrb_value *ptr = a->ptr; - int size = a->len; + mrb_int size = a->len; val = *ptr; while((int)(--size)) { @@ -612,9 +610,9 @@ mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_value rpl) { struct RArray *a = mrb_ary_ptr(ary); - int tail, size; + mrb_int tail, size; mrb_value *argv; - int i, argc; + mrb_int i, argc; ary_modify(mrb, a); /* range check */ @@ -660,7 +658,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val return ary; } -int +mrb_int mrb_ary_len(mrb_state *mrb, mrb_value ary) { return RARRAY_LEN(ary); @@ -677,7 +675,7 @@ mrb_ary_decref(mrb_state *mrb, mrb_shared_array *shared) } static mrb_value -ary_subseq(mrb_state *mrb, struct RArray *a, int beg, int len) +ary_subseq(mrb_state *mrb, struct RArray *a, mrb_int beg, mrb_int len) { struct RArray *b; @@ -714,7 +712,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self) len = mrb_fixnum(argv[0]); if (len < 0) return mrb_nil_value(); if (a->len == (int)index) return mrb_ary_new(mrb); - if ((int)len > a->len - index) len = a->len - index; + if (len > a->len - index) len = a->len - index; return ary_subseq(mrb, a, index, len); default: @@ -757,7 +755,7 @@ mrb_ary_delete_at(mrb_state *mrb, mrb_value self) mrb_int index; mrb_value val; mrb_value *ptr; - int len; + mrb_int len; mrb_get_args(mrb, "i", &index); if (index < 0) index += a->len; @@ -803,7 +801,7 @@ mrb_value mrb_ary_last(mrb_state *mrb, mrb_value self) { struct RArray *a = mrb_ary_ptr(self); - int size; + mrb_int size; mrb_value *vals; int len; @@ -830,7 +828,7 @@ mrb_value mrb_ary_index_m(mrb_state *mrb, mrb_value self) { mrb_value obj; - int i; + mrb_int i; mrb_get_args(mrb, "o", &obj); for (i = 0; i < RARRAY_LEN(self); i++) { @@ -845,7 +843,7 @@ mrb_value mrb_ary_rindex_m(mrb_state *mrb, mrb_value self) { mrb_value obj; - int i; + mrb_int i; mrb_get_args(mrb, "o", &obj); for (i = RARRAY_LEN(self) - 1; i >= 0; i--) { @@ -904,7 +902,7 @@ mrb_check_array_type(mrb_state *mrb, mrb_value ary) } mrb_value -mrb_ary_entry(mrb_value ary, int offset) +mrb_ary_entry(mrb_value ary, mrb_int offset) { if (offset < 0) { offset += RARRAY_LEN(ary); @@ -915,7 +913,7 @@ mrb_ary_entry(mrb_value ary, int offset) static mrb_value inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) { - int i; + mrb_int i; mrb_value s, arystr; char head[] = { '[' }; char sep[] = { ',', ' ' }; @@ -934,7 +932,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) mrb_str_buf_cat(mrb, arystr, head, sizeof(head)); for(i=0; i<RARRAY_LEN(ary); i++) { - int ai = mrb_gc_arena_save(mrb); + mrb_int ai = mrb_gc_arena_save(mrb); if (i > 0) { mrb_str_buf_cat(mrb, arystr, sep, sizeof(sep)); @@ -977,7 +975,7 @@ mrb_ary_inspect(mrb_state *mrb, mrb_value ary) static mrb_value join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list) { - int i; + mrb_int i; mrb_value result, val, tmp; /* check recursive */ @@ -1092,7 +1090,7 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1) } if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value(); else { - int i; + mrb_int i; for (i=0; i<RARRAY_LEN(ary1); i++) { if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) @@ -1121,11 +1119,11 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1) if (!mrb_array_p(ary2)) return mrb_false_value(); if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value(); else { - int i; + mrb_int i; for (i=0; i<RARRAY_LEN(ary1); i++) { if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) - return mrb_false_value(); + return mrb_false_value(); } return mrb_true_value(); } diff --git a/src/class.c b/src/class.c index c0e71dad7..8ea323945 100644 --- a/src/class.c +++ b/src/class.c @@ -29,7 +29,7 @@ mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c) if (kh_exist(h, k)){ struct RProc *m = kh_value(h, k); if (m) { - mrb_gc_mark(mrb, (struct RBasic*)m); + mrb_gc_mark(mrb, (struct RBasic*)m); } } } @@ -356,7 +356,7 @@ to_hash(mrb_state *mrb, mrb_value val) retrieve arguments from mrb_state. mrb_get_args(mrb, format, ...) - + returns number of arguments parsed. fortmat specifiers: @@ -367,7 +367,7 @@ to_hash(mrb_state *mrb, mrb_value val) H: Hash [mrb_value] s: String [char*,int] z: String [char*] - a: Array [mrb_value*,int] + a: Array [mrb_value*,mrb_int] f: Float [mrb_float] i: Integer [mrb_int] b: Binary [int] @@ -489,10 +489,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) mrb_value aa; struct RArray *a; mrb_value **pb; - int *pl; + mrb_int *pl; pb = va_arg(ap, mrb_value**); - pl = va_arg(ap, int*); + pl = va_arg(ap, mrb_int*); if (i < argc) { aa = to_ary(mrb, *sp++); a = mrb_ary_ptr(aa); @@ -774,7 +774,7 @@ mrb_mod_include_p(mrb_state *mrb, mrb_value mod) } return mrb_false_value(); } - + static mrb_value mrb_mod_ancestors(mrb_state *mrb, mrb_value self) { diff --git a/src/codegen.c b/src/codegen.c index 577ef5400..d2640904a 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -330,7 +330,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val) if (c1 == OP_SUB) c = -c; if (c > 127 || c < -127) break; - if (0 <= c) + if (0 <= c) s->iseq[s->pc-1] = MKOP_ABC(OP_ADDI, GETARG_A(i), GETARG_B(i), c); else s->iseq[s->pc-1] = MKOP_ABC(OP_SUBI, GETARG_A(i), GETARG_B(i), -c); @@ -1161,7 +1161,7 @@ codegen(codegen_scope *s, node *tree, int val) if (e) { if (val) pop(); pos2 = new_label(s); - genop(s, MKOP_sBx(OP_JMP, 0)); + genop(s, MKOP_sBx(OP_JMP, 0)); dispatch(s, pos1); codegen(s, e, val); dispatch(s, pos2); @@ -1956,7 +1956,7 @@ codegen(codegen_scope *s, node *tree, int val) pop(); sym = new_sym(s, mrb_intern(s->mrb, "compile")); genop(s, MKOP_ABC(OP_SEND, cursp(), sym, argc)); - mrb_gc_arena_restore(s->mrb, ai); + mrb_gc_arena_restore(s->mrb, ai); push(); } break; @@ -1984,16 +1984,16 @@ codegen(codegen_scope *s, node *tree, int val) } n = tree->cdr->cdr; if (n->car) { - p = (char*)n->car; - off = new_lit(s, mrb_str_new(s->mrb, p, strlen(p))); - codegen(s, tree->car, VAL); - genop(s, MKOP_ABx(OP_STRING, cursp(), off)); - pop(); - genop(s, MKOP_AB(OP_STRCAT, cursp(), cursp()+1)); + p = (char*)n->car; + off = new_lit(s, mrb_str_new(s->mrb, p, strlen(p))); + codegen(s, tree->car, VAL); + genop(s, MKOP_ABx(OP_STRING, cursp(), off)); + pop(); + genop(s, MKOP_AB(OP_STRCAT, cursp(), cursp()+1)); } if (n->cdr) { - char *p2 = (char*)n->cdr; - int off; + char *p2 = (char*)n->cdr; + int off; push(); off = new_lit(s, mrb_str_new(s->mrb, p2, strlen(p2))); @@ -2004,7 +2004,7 @@ codegen(codegen_scope *s, node *tree, int val) pop(); sym = new_sym(s, mrb_intern(s->mrb, "compile")); genop(s, MKOP_ABC(OP_SEND, cursp(), sym, argc)); - mrb_gc_arena_restore(s->mrb, ai); + mrb_gc_arena_restore(s->mrb, ai); push(); } else { diff --git a/src/error.c b/src/error.c index 70a84455f..7599bd0a9 100644 --- a/src/error.c +++ b/src/error.c @@ -125,7 +125,7 @@ exc_inspect(mrb_state *mrb, mrb_value exc) mesg = mrb_attr_get(mrb, exc, mrb_intern(mrb, "mesg")); file = mrb_attr_get(mrb, exc, mrb_intern(mrb, "file")); line = mrb_attr_get(mrb, exc, mrb_intern(mrb, "line")); - + if (!mrb_nil_p(file) && !mrb_nil_p(line)) { str = file; mrb_str_cat2(mrb, str, ":"); @@ -190,12 +190,12 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc) ci--; while (ci >= mrb->cibase) { if (ci->proc && !MRB_PROC_CFUNC_P(ci->proc)) { - mrb_irep *irep = ci->proc->body.irep; + mrb_irep *irep = ci->proc->body.irep; if (irep->filename && irep->lines && irep->iseq <= pc && pc < irep->iseq + irep->ilen) { - mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "file"), mrb_str_new_cstr(mrb, irep->filename)); - mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "line"), mrb_fixnum_value(irep->lines[pc - irep->iseq - 1])); - return; + mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "file"), mrb_str_new_cstr(mrb, irep->filename)); + mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "line"), mrb_fixnum_value(irep->lines[pc - irep->iseq - 1])); + return; } } pc = ci->pc; @@ -366,14 +366,14 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) n = 1; exception_call: { - 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"); - } + 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; @@ -301,7 +301,7 @@ mrb_free_heap(mrb_state *mrb) page = page->next; for (p = tmp->objects, e=p+MRB_HEAP_PAGE_SIZE; p<e; p++) { if (p->as.free.tt != MRB_TT_FREE) - obj_free(mrb, &p->as.basic); + obj_free(mrb, &p->as.basic); } mrb_free(mrb, tmp); } @@ -586,7 +586,7 @@ root_scan_phase(mrb_state *mrb) mrb_irep *irep = mrb->irep[i]; if (!irep) continue; for (j=0; j<irep->plen; j++) { - mrb_gc_mark_value(mrb, irep->pool[j]); + mrb_gc_mark_value(mrb, irep->pool[j]); } } } diff --git a/src/hash.c b/src/hash.c index 2439a235d..728fc0f2f 100644 --- a/src/hash.c +++ b/src/hash.c @@ -559,7 +559,7 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash) delVal = mrb_hash_delete_key(mrb, hash, delKey); mrb_gc_protect(mrb, delVal); - return mrb_assoc_new(mrb, delKey, delVal); + return mrb_assoc_new(mrb, delKey, delVal); } } } @@ -1119,9 +1119,9 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql) key = kh_key(h1,k1); k2 = kh_get(ht, h2, key); if (k2 != kh_end(h2)) { - if (mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2))) { - continue; /* next key */ - } + if (mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2))) { + continue; /* next key */ + } } return mrb_false_value(); } diff --git a/src/kernel.c b/src/kernel.c index e45953fd3..c37b627a1 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -191,7 +191,7 @@ mrb_f_send(mrb_state *mrb, mrb_value self) mrb_sym name; mrb_value block, *argv; int argc; - + mrb_get_args(mrb, "n*&", &name, &argv, &argc, &block); return mrb_funcall_with_block(mrb,self, name, argc, argv, block); } @@ -305,7 +305,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) case MRB_TT_SCLASS: case MRB_TT_HASH: case MRB_TT_DATA: - mrb_iv_copy(mrb, dest, obj); + mrb_iv_copy(mrb, dest, obj); break; default: @@ -483,7 +483,7 @@ mrb_value mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *a * call-seq: * obj.instance_eval {| | block } -> obj * - * Evaluates the given block,within the context of the receiver (_obj_). + * Evaluates the given block,within the context of the receiver (_obj_). * In order to set the context, the variable +self+ is set to _obj_ while * the code is executing, giving the code access to _obj_'s * instance variables. In the version of <code>instance_eval</code> @@ -913,7 +913,7 @@ mrb_f_raise(mrb_state *mrb, mrb_value self) { mrb_value a[2], exc; int argc; - + argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]); switch (argc) { diff --git a/src/load.c b/src/load.c index 850fa6e8d..84c21c186 100644 --- a/src/load.c +++ b/src/load.c @@ -536,7 +536,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) nirep = read_rite_header(mrb, src, &bin_header); if (nirep < 0) return nirep; - + src += sizeof(bin_header) + MRB_DUMP_SIZE_OF_SHORT; //header + crc //Read Binary Data Section diff --git a/src/numeric.c b/src/numeric.c index b5bff652d..5aa577828 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -306,7 +306,7 @@ static mrb_value num_eql(mrb_state *mrb, mrb_value x) { mrb_value y; - + mrb_get_args(mrb, "o", &y); if (mrb_type(x) != mrb_type(y)) return mrb_false_value(); if (mrb_equal(mrb, x, y)) { @@ -699,7 +699,7 @@ mrb_value mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y) { mrb_int a; - + a = mrb_fixnum(x); if (a == 0) return x; if (mrb_fixnum_p(y)) { @@ -1126,7 +1126,7 @@ mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y) { mrb_int a; - + a = mrb_fixnum(x); if (a == 0) return y; if (mrb_fixnum_p(y)) { @@ -1165,7 +1165,7 @@ mrb_value mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y) { mrb_int a; - + a = mrb_fixnum(x); if (mrb_fixnum_p(y)) { mrb_int b, c; diff --git a/src/parse.y b/src/parse.y index fa12263a1..d6ca798cd 100644 --- a/src/parse.y +++ b/src/parse.y @@ -766,15 +766,6 @@ call_bin_op(parser_state *p, node *recv, char *m, node *arg1) return new_call(p, recv, intern(m), list1(list1(arg1))); } -/* -// (:match (a . b)) -static node* -match_op(parser_state *p, node *a, node *b) -{ - return cons((node*)NODE_MATCH, cons((node*)a, (node*)b)); -} -*/ - static void args_with_block(parser_state *p, node *a, node *b) { diff --git a/src/range.c b/src/range.c index aac1d830a..59bf445aa 100644 --- a/src/range.c +++ b/src/range.c @@ -16,8 +16,8 @@ static void range_check(mrb_state *mrb, mrb_value a, mrb_value b) { mrb_value ans; - int ta; - int tb; + enum mrb_vtype ta; + enum mrb_vtype tb; ta = mrb_type(a); tb = mrb_type(b); @@ -181,7 +181,7 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b) /* output :a < b => -1, a = b => 0, a > b => +1 */ if (mrb_type(r) == MRB_TT_FIXNUM) { - int c = mrb_fixnum(r); + mrb_int c = mrb_fixnum(r); if (c == 0 || c == -1) return TRUE; } @@ -208,7 +208,7 @@ r_ge(mrb_state *mrb, mrb_value a, mrb_value b) /* output :a < b => -1, a = b => 0, a > b => +1 */ if (mrb_type(r) == MRB_TT_FIXNUM) { - int c = mrb_fixnum(r); + mrb_int c = mrb_fixnum(r); if (c == 0 || c == 1) return TRUE; } diff --git a/src/sprintf.c b/src/sprintf.c index 905182147..192d44735 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -623,7 +623,7 @@ retry: p++; goto retry; } - + case '*': CHECK_FOR_WIDTH(flags); flags |= FWIDTH; @@ -658,7 +658,7 @@ retry: case '\n': case '\0': p--; - + case '%': if (flags != FNONE) { mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid format character - %"); diff --git a/src/state.c b/src/state.c index 53773ac89..1936b8aab 100644 --- a/src/state.c +++ b/src/state.c @@ -72,7 +72,7 @@ mrb_alloca_free(mrb_state *mrb) } mrb_state* -mrb_open() +mrb_open(void) { mrb_state *mrb = mrb_open_allocf(allocf, NULL); @@ -110,6 +110,10 @@ mrb_close(mrb_state *mrb) mrb_free(mrb, mrb); } +#ifndef MRB_IREP_ARRAY_INIT_SIZE +# define MRB_IREP_ARRAY_INIT_SIZE (256u) +#endif + mrb_irep* mrb_add_irep(mrb_state *mrb) { @@ -117,7 +121,7 @@ mrb_add_irep(mrb_state *mrb) mrb_irep *irep; if (!mrb->irep) { - int max = 256; + size_t max = MRB_IREP_ARRAY_INIT_SIZE; if (mrb->irep_len > max) max = mrb->irep_len+1; mrb->irep = (mrb_irep **)mrb_calloc(mrb, max, sizeof(mrb_irep*)); diff --git a/src/string.c b/src/string.c index 28cf0ab9a..23da3baa6 100644 --- a/src/string.c +++ b/src/string.c @@ -2056,7 +2056,6 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) char *end; char sign = 1; int c; - long len; unsigned long val; #undef ISDIGIT @@ -2113,30 +2112,25 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) } switch (base) { case 2: - len = 1; if (str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) { str += 2; } break; case 3: - len = 2; break; case 8: if (str[0] == '0' && (str[1] == 'o'||str[1] == 'O')) { str += 2; } case 4: case 5: case 6: case 7: - len = 3; break; case 10: if (str[0] == '0' && (str[1] == 'd'||str[1] == 'D')) { str += 2; } case 9: case 11: case 12: case 13: case 14: case 15: - len = 4; break; case 16: - len = 4; if (str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) { str += 2; } @@ -2145,12 +2139,6 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) if (base < 2 || 36 < base) { mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal radix %d", base); } - if (base <= 32) { - len = 5; - } - else { - len = 6; - } break; } /* end of switch (base) { */ if (*str == '0') { /* squeeze preceeding 0s */ @@ -2171,7 +2159,6 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) if (badcheck) goto bad; return mrb_fixnum_value(0); } - len *= strlen(str); val = strtoul((char*)str, &end, base); diff --git a/src/variable.c b/src/variable.c index 5f657e3d7..d5331f844 100644 --- a/src/variable.c +++ b/src/variable.c @@ -753,7 +753,7 @@ mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) struct RClass *c = mrb->ci->proc->target_class; if (!c) c = mrb->ci->target_class; - + return mrb_mod_cv_get(mrb, c, sym); } |
