summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--include/mruby.h1
-rw-r--r--mrblib/Makefile2
-rw-r--r--src/Makefile2
-rw-r--r--src/array.c14
-rw-r--r--src/dump.c24
-rw-r--r--src/object.c13
-rw-r--r--src/time.c2
-rw-r--r--src/vm.c47
-rw-r--r--test/Makefile4
-rw-r--r--tools/mirb/Makefile2
-rw-r--r--tools/mrbc/Makefile2
-rw-r--r--tools/mruby/Makefile2
13 files changed, 51 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index a960fc14a..2df86c949 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby
# compiler, linker (gcc), archiver, parser generator
diff --git a/include/mruby.h b/include/mruby.h
index 3063358f1..2f2f3753d 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -216,6 +216,7 @@ void mrb_p(mrb_state*, mrb_value);
mrb_int mrb_obj_id(mrb_value obj);
mrb_sym mrb_to_id(mrb_state *mrb, mrb_value name);
+int mrb_obj_eq(mrb_state*, mrb_value, mrb_value);
int mrb_obj_equal(mrb_state*, mrb_value, mrb_value);
int mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
diff --git a/mrblib/Makefile b/mrblib/Makefile
index c6a668dbd..6d7ac65f9 100644
--- a/mrblib/Makefile
+++ b/mrblib/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby library (Ruby part)
# project-specific macros
diff --git a/src/Makefile b/src/Makefile
index c746fa90a..de9a4e6e3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby library
# project-specific macros
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 */
diff --git a/src/vm.c b/src/vm.c
index 7745c0433..75a4cd442 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -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), &regs[GETARG_B(i)]);
mrb->arena_idx = ai;
NEXT;
}
diff --git a/test/Makefile b/test/Makefile
index 921442b28..18bc79b5a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,5 +1,5 @@
-# makefile discription.
-# basic build file for mruby library (Ruby part)
+# Makefile description.
+# basic build file for the mruby testing environment mrbtest
# project-specific macros
# extension of the executable-file is modifiable(.exe .out ...)
diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile
index 52941f242..8dbbc52b3 100644
--- a/tools/mirb/Makefile
+++ b/tools/mirb/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mirb executable
# project-specific macros
diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile
index eea0c02cb..9da1776bd 100644
--- a/tools/mrbc/Makefile
+++ b/tools/mrbc/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby-compiler
# project-specific macros
diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile
index 9955b4302..e94c1b2b4 100644
--- a/tools/mruby/Makefile
+++ b/tools/mruby/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby executable
# project-specific macros