diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/array.c | 14 | ||||
| -rw-r--r-- | src/dump.c | 24 | ||||
| -rw-r--r-- | src/object.c | 13 | ||||
| -rw-r--r-- | src/time.c | 2 | ||||
| -rw-r--r-- | src/vm.c | 47 |
5 files changed, 42 insertions, 58 deletions
diff --git a/src/array.c b/src/array.c index 15b6df0f2..fa43bdd35 100644 --- a/src/array.c +++ b/src/array.c @@ -37,16 +37,13 @@ ary_new_capa(mrb_state *mrb, int capa) mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); } #endif - if (capa < ARY_DEFAULT_LEN) { - capa = ARY_DEFAULT_LEN; - } blen = capa * sizeof(mrb_value) ; if (blen < capa) { mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); } a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class); - a->ptr = (mrb_value *)mrb_calloc(mrb, blen, 1); + a->ptr = (mrb_value *)mrb_malloc(mrb, blen); a->aux.capa = capa; a->len = 0; @@ -859,9 +856,11 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self) { struct RArray *a = mrb_ary_ptr(self); - a->len = 0; ary_modify(mrb, a); - ary_shrink_capa(mrb, a); + a->len = 0; + a->aux.capa = 0; + mrb_free(mrb, a->ptr); + a->ptr = 0; return self; } @@ -1054,7 +1053,8 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1) mrb_value ary2; mrb_get_args(mrb, "o", &ary2); - if (mrb_obj_equal(mrb, ary1,ary2)) return mrb_true_value(); + if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value(); + if (SPECIAL_CONST_P(ary2)) return mrb_false_value(); if (mrb_type(ary2) != MRB_TT_ARRAY) { if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) { return mrb_false_value(); diff --git a/src/dump.c b/src/dump.c index 190f16027..516374cd9 100644 --- a/src/dump.c +++ b/src/dump.c @@ -332,7 +332,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) char *buf_top = buf; char *char_buf; uint16_t buf_size =0; - int len; + uint16_t len =0; buf_size = MRB_DUMP_DEFAULT_STR_LEN; if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == 0) @@ -341,25 +341,23 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) buf += uint32_dump((uint32_t)irep->plen, buf, type); /* number of pool */ for (pool_no = 0; pool_no < irep->plen; pool_no++) { - uint16_t nlen =0; - buf += uint8_dump(mrb_type(irep->pool[pool_no]), buf, type); /* data type */ memset(char_buf, 0, buf_size); switch (mrb_type(irep->pool[pool_no])) { case MRB_TT_FIXNUM: - sprintf(char_buf, "%d", mrb_fixnum(irep->pool[pool_no])); + len = sprintf(char_buf, "%d", mrb_fixnum(irep->pool[pool_no])); break; case MRB_TT_FLOAT: - sprintf(char_buf, "%.16e", mrb_float(irep->pool[pool_no])); + len = sprintf(char_buf, "%.16e", mrb_float(irep->pool[pool_no])); break; case MRB_TT_STRING: str = mrb_string_value( mrb, &irep->pool[pool_no]); - nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); - if ( nlen > buf_size - 1) { - buf_size = nlen + 1; + len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); + if ( len > buf_size - 1) { + buf_size = len + 1; if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) goto error_exit; memset(char_buf, 0, buf_size); @@ -370,9 +368,9 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) #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); - if ( nlen > buf_size - 1) { - buf_size = nlen + 1; + len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); + if ( len > buf_size - 1) { + buf_size = len + 1; if ((char_buf = mrb_realloc(mrb, char_buf, buf_size)) == 0) goto error_exit; memset(char_buf, 0, buf_size); @@ -386,9 +384,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) continue; } - len = strlen(char_buf); - - buf += uint16_dump((uint16_t)len, buf, type); /* data length */ + buf += uint16_dump(len, buf, type); /* data length */ memcpy(buf, char_buf, len); buf += len; diff --git a/src/object.c b/src/object.c index 4c494101a..5130f3d54 100644 --- a/src/object.c +++ b/src/object.c @@ -47,17 +47,8 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2) if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; result = mrb_funcall(mrb, obj1, "==", 1, obj2); - if (mrb_nil_p(result)) { - return FALSE; - } - else { - if (mrb_type(result) == MRB_TT_TRUE) { - return TRUE; - } - else { - return FALSE; - } - } + if (mrb_test(result)) return TRUE; + return FALSE; } /* diff --git a/src/time.c b/src/time.c index 3dd56c6a9..085c4f30f 100644 --- a/src/time.c +++ b/src/time.c @@ -28,13 +28,11 @@ #ifdef _WIN32 /* Win32 platform do not provide gmtime_r/localtime_r; emulate them using gmtime_s/localtime_s */ -#if _MVC_VER #define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL) #define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tm) : NULL) #else #define NO_GMTIME_R #endif -#endif /* timegm(3) */ /* mktime() creates tm structure for localtime; timegm() is for UTF time */ @@ -23,6 +23,18 @@ #include <stddef.h> #include <stdarg.h> +#define SET_TRUE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_TRUE, value.i, 1) +#define SET_FALSE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 1) +#define SET_NIL_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 0) +#define SET_INT_VALUE(r,n) MRB_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n)) +#define SET_SYM_VALUE(r,v) MRB_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v)) +#define SET_OBJ_VALUE(r,v) MRB_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v)) +#ifdef MRB_NAN_BOXING +#define SET_FLT_VALUE(r,v) r.f = (v) +#else +#define SET_FLT_VALUE(r,v) MRB_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v)) +#endif + #define STACK_INIT_SIZE 128 #define CALLINFO_INIT_SIZE 32 @@ -84,7 +96,7 @@ stack_extend(mrb_state *mrb, int room, int keep) int i; for (i=keep; i<room; i++) { - mrb->stack[i] = mrb_nil_value(); + SET_NIL_VALUE(mrb->stack[i]); } #endif } @@ -402,18 +414,6 @@ argnum_error(mrb_state *mrb, int num) mrb->exc = (struct RObject*)mrb_object(exc); } -#define SET_TRUE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_TRUE, value.i, 1) -#define SET_FALSE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 1) -#define SET_NIL_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 0) -#define SET_INT_VALUE(r,n) MRB_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n)) -#define SET_SYM_VALUE(r,v) MRB_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v)) -#define SET_OBJ_VALUE(r,v) MRB_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v)) -#ifdef MRB_NAN_BOXING -#define SET_FLT_VALUE(r,v) r.f = (v) -#else -#define SET_FLT_VALUE(r,v) MRB_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v)) -#endif - #ifdef __GNUC__ #define DIRECT_THREADED #endif @@ -763,7 +763,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } else { memmove(regs+a+2, regs+a+1, sizeof(mrb_value)*(n+1)); - regs[a+1] = sym; + regs[a+1] = sym; n++; } } @@ -896,7 +896,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } else { memmove(regs+a+2, regs+a+1, sizeof(mrb_value)*(n+1)); - regs[a+1] = mrb_symbol_value(ci->mid); + SET_SYM_VALUE(regs[a+1], ci->mid); n++; } } @@ -1495,7 +1495,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_EQ) { /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/ - OP_CMP(==); + int a = GETARG_A(i); + if (mrb_obj_eq(mrb, regs[a], regs[a+1])) { + SET_TRUE_VALUE(regs[a]); + } + else { + OP_CMP(==); + } NEXT; } @@ -1525,14 +1531,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_ARRAY) { /* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */ - int b = GETARG_B(i); - int lim = b+GETARG_C(i); - mrb_value ary = mrb_ary_new_capa(mrb, GETARG_C(i)); - - while (b < lim) { - mrb_ary_push(mrb, ary, regs[b++]); - } - regs[GETARG_A(i)] = ary; + regs[GETARG_A(i)] = mrb_ary_new_from_values(mrb, GETARG_C(i), ®s[GETARG_B(i)]); mrb->arena_idx = ai; NEXT; } |
