Permalink
Browse files

Merge branch 'master' into iij

Conflicts:
	test/t/string.rb
  • Loading branch information...
2 parents 62a69d8 + 2dbd6fa commit 2d4620f11f53feb8474c012b6a14598370b00cf5 @tsahara tsahara committed Sep 11, 2012
View
2 Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby
# compiler, linker (gcc), archiver, parser generator
View
5 README.md
@@ -106,6 +106,11 @@ To subscribe to the mruby mailing list....[T.B.D.]
See the INSTALL file.
+## Running Tests
+
+To run the tests, execute the following from the project's root directory.
+
+ $ make test
## License
View
2 include/mrbconf.h
@@ -29,7 +29,7 @@
//#define MRB_USE_IV_SEGLIST
/* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */
-//#define MRB_IV_INITIAL_SIZE 8
+//#define MRB_IVHASH_INIT_SIZE 8
/* default size of khash table bucket */
//#define KHASH_DEFAULT_SIZE 32
View
1 include/mruby.h
@@ -223,6 +223,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);
View
76 include/mruby/value.h
@@ -17,24 +17,24 @@ enum mrb_vtype {
MRB_TT_SYMBOL, /* 4 */
MRB_TT_UNDEF, /* 5 */
MRB_TT_FLOAT, /* 6 */
- MRB_TT_OBJECT, /* 7 */
- MRB_TT_CLASS, /* 8 */
- MRB_TT_MODULE, /* 9 */
- MRB_TT_ICLASS, /* 10 */
- MRB_TT_SCLASS, /* 11 */
- MRB_TT_PROC, /* 12 */
- MRB_TT_ARRAY, /* 13 */
- MRB_TT_HASH, /* 14 */
- MRB_TT_STRING, /* 15 */
- MRB_TT_RANGE, /* 16 */
- MRB_TT_REGEX, /* 17 */
- MRB_TT_STRUCT, /* 18 */
- MRB_TT_EXCEPTION, /* 19 */
- MRB_TT_MATCH, /* 20 */
- MRB_TT_FILE, /* 21 */
- MRB_TT_ENV, /* 22 */
- MRB_TT_DATA, /* 23 */
- MRB_TT_MAIN, /* 24 */
+ MRB_TT_MAIN, /* 7 */
+ MRB_TT_OBJECT, /* 8 */
+ MRB_TT_CLASS, /* 9 */
+ MRB_TT_MODULE, /* 10 */
+ MRB_TT_ICLASS, /* 11 */
+ MRB_TT_SCLASS, /* 12 */
+ MRB_TT_PROC, /* 13 */
+ MRB_TT_ARRAY, /* 14 */
+ MRB_TT_HASH, /* 15 */
+ MRB_TT_STRING, /* 16 */
+ MRB_TT_RANGE, /* 17 */
+ MRB_TT_REGEX, /* 18 */
+ MRB_TT_STRUCT, /* 19 */
+ MRB_TT_EXCEPTION, /* 20 */
+ MRB_TT_MATCH, /* 21 */
+ MRB_TT_FILE, /* 22 */
+ MRB_TT_ENV, /* 23 */
+ MRB_TT_DATA, /* 24 */
MRB_TT_MAXDEFINE /* 25 */
};
@@ -78,25 +78,25 @@ enum mrb_vtype {
MRB_TT_SYMBOL, /* 5 */
MRB_TT_UNDEF, /* 6 */
MRB_TT_FLOAT, /* 7 */
- MRB_TT_OBJECT, /* 8 */
- MRB_TT_CLASS, /* 9 */
- MRB_TT_MODULE, /* 10 */
- MRB_TT_ICLASS, /* 11 */
- MRB_TT_SCLASS, /* 12 */
- MRB_TT_PROC, /* 13 */
- MRB_TT_ARRAY, /* 14 */
- MRB_TT_HASH, /* 15 */
- MRB_TT_STRING, /* 16 */
- MRB_TT_RANGE, /* 17 */
- MRB_TT_REGEX, /* 18 */
- MRB_TT_STRUCT, /* 19 */
- MRB_TT_EXCEPTION, /* 20 */
- MRB_TT_MATCH, /* 21 */
- MRB_TT_FILE, /* 22 */
- MRB_TT_ENV, /* 23 */
- MRB_TT_DATA, /* 24 */
- MRB_TT_MAIN, /* 25 */
- MRB_TT_MAXDEFINE /* 26 */
+ MRB_TT_MAIN, /* 8 */
+ MRB_TT_OBJECT, /* 9 */
+ MRB_TT_CLASS, /* 10 */
+ MRB_TT_MODULE, /* 11 */
+ MRB_TT_ICLASS, /* 12 */
+ MRB_TT_SCLASS, /* 13 */
+ MRB_TT_PROC, /* 14 */
+ MRB_TT_ARRAY, /* 15 */
+ MRB_TT_HASH, /* 16 */
+ MRB_TT_STRING, /* 17 */
+ MRB_TT_RANGE, /* 18 */
+ MRB_TT_REGEX, /* 19 */
+ MRB_TT_STRUCT, /* 20 */
+ MRB_TT_EXCEPTION, /* 21 */
+ MRB_TT_MATCH, /* 22 */
+ MRB_TT_FILE, /* 23 */
+ MRB_TT_ENV, /* 24 */
+ MRB_TT_DATA, /* 25 */
+ MRB_TT_MAXDEFINE /* 27 */
};
#ifdef MRB_ENDIAN_BIG
@@ -156,7 +156,7 @@ mrb_float_value(mrb_float f)
#include "mruby/object.h"
-#define IMMEDIATE_P(x) (mrb_type(x) <= MRB_TT_FLOAT)
+#define IMMEDIATE_P(x) (mrb_type(x) <= MRB_TT_MAIN)
#define SPECIAL_CONST_P(x) IMMEDIATE_P(x)
#define SYMBOL_P(o) (mrb_type(o) == MRB_TT_SYMBOL)
#define RTEST(o) mrb_test(o)
View
4 mrblib/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby library (Ruby part)
# project-specific macros
@@ -69,7 +69,7 @@ $(CLIB) : $(RLIB1) $(RLIB2) $(MRBC)
$(MRBC) -Bmrblib_ext_irep -o$(DLIB2) $(RLIB2)
$(CAT) init_$(TARGET).c $(DLIB1) $(DLIB2) > $@
-$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y
+$(MRBC) : $(LIBR0)
$(MAKE) -C ../tools/mrbc $(MAKE_FLAGS)
# merge mruby sources
View
8 mrblib/error.rb
@@ -51,14 +51,6 @@ class IndexError < StandardError
class KeyError < IndexError
end
-# ISO 15.2.37
-class ScriptError < Exception
-end
-
-# ISO 15.2.38
-class SyntaxError < ScriptError
-end
-
class NotImplementedError < ScriptError
end
View
2 src/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby library
# project-specific macros
View
14 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();
View
3 src/class.c
@@ -1090,7 +1090,7 @@ mrb_class_name(mrb_state *mrb, struct RClass* c)
const char*
mrb_obj_classname(mrb_state *mrb, mrb_value obj)
{
- return mrb_class_name(mrb, mrb_class(mrb, obj));
+ return mrb_class_name(mrb, mrb_obj_class(mrb, obj));
}
/*!
@@ -1417,6 +1417,7 @@ mrb_init_class(mrb_state *mrb)
mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, ARGS_NONE()); /* 15.2.2.4.30 */
mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE());
+ mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, ARGS_NONE());
mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY()); /* 15.2.2.4.8 */
mrb_define_method(mrb, mod, "ancestors", mrb_mod_ancestors, ARGS_NONE()); /* 15.2.2.4.9 */
mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY()); /* 15.2.2.4.41 */
View
24 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;
View
4 src/error.c
@@ -407,4 +407,8 @@ mrb_init_exception(mrb_state *mrb)
mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */
mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */
+
+ mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */
+ e = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */
+ mrb_define_class(mrb, "SyntaxError", e); /* 15.2.38 */
}
View
13 src/object.c
@@ -48,17 +48,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;
}
/*
View
2 src/state.c
@@ -99,6 +99,8 @@ mrb_close(mrb_state *mrb)
mrb_free(mrb, mrb->irep[i]);
}
mrb_free(mrb, mrb->irep);
+ mrb_free(mrb, mrb->rescue);
+ mrb_free(mrb, mrb->ensure);
mrb_free_symtbl(mrb);
mrb_free_heap(mrb);
mrb_alloca_free(mrb);
View
3 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 */
@@ -710,6 +708,7 @@ mrb_init_time(mrb_state *mrb)
mrb_define_method(mrb, tc, "+" , mrb_time_plus , ARGS_REQ(1)); /* 15.2.19.7.2 */
mrb_define_method(mrb, tc, "-" , mrb_time_minus , ARGS_REQ(1)); /* 15.2.19.7.3 */
mrb_define_method(mrb, tc, "to_s" , mrb_time_asctime, ARGS_NONE());
+ mrb_define_method(mrb, tc, "inspect", mrb_time_asctime, ARGS_NONE());
mrb_define_method(mrb, tc, "asctime", mrb_time_asctime, ARGS_NONE()); /* 15.2.19.7.4 */
mrb_define_method(mrb, tc, "ctime" , mrb_time_asctime, ARGS_NONE()); /* 15.2.19.7.5 */
mrb_define_method(mrb, tc, "day" , mrb_time_day , ARGS_NONE()); /* 15.2.19.7.6 */
View
8 src/variable.c
@@ -251,8 +251,8 @@ iv_free(mrb_state *mrb, iv_tbl *t)
#include "mruby/khash.h"
-#ifndef MRB_IV_INITIAL_SIZE
-#define MRB_IV_INITIAL_SIZE 8
+#ifndef MRB_IVHASH_INIT_SIZE
+#define MRB_IVHASH_INIT_SIZE 8
#endif
KHASH_DECLARE(iv, mrb_sym, mrb_value, 1)
@@ -265,7 +265,7 @@ typedef struct iv_tbl {
static iv_tbl*
iv_new(mrb_state *mrb)
{
- return (iv_tbl*)kh_init_size(iv, mrb, MRB_IV_INITIAL_SIZE);
+ return (iv_tbl*)kh_init_size(iv, mrb, MRB_IVHASH_INIT_SIZE);
}
static void
@@ -549,7 +549,7 @@ mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym)
iv_tbl *t = mrb_obj_ptr(obj)->iv;
mrb_value val;
- if (iv_del(mrb, t, sym, &val)) {
+ if (t && iv_del(mrb, t, sym, &val)) {
return val;
}
}
View
114 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
}
@@ -233,7 +245,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mr
struct RClass *c;
mrb_sym undef = 0;
mrb_callinfo *ci;
- int n = mrb->ci->nregs;
+ int n;
mrb_value val;
if (!mrb->jmp) {
@@ -250,6 +262,10 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mr
return val;
}
+ if (!mrb->stack) {
+ stack_init(mrb);
+ }
+ n = mrb->ci->nregs;
if (argc < 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argc for funcall (%d)", argc);
}
@@ -398,13 +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 __GNUC__
#define DIRECT_THREADED
#endif
@@ -459,7 +468,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
&&L_OP_GETUPVAR, &&L_OP_SETUPVAR,
&&L_OP_JMP, &&L_OP_JMPIF, &&L_OP_JMPNOT,
&&L_OP_ONERR, &&L_OP_RESCUE, &&L_OP_POPERR, &&L_OP_RAISE, &&L_OP_EPUSH, &&L_OP_EPOP,
- &&L_OP_SEND, &&L_OP_SEND, &&L_OP_FSEND,
+ &&L_OP_SEND, &&L_OP_SENDB, &&L_OP_FSEND,
&&L_OP_CALL, &&L_OP_SUPER, &&L_OP_ARGARY, &&L_OP_ENTER,
&&L_OP_KARG, &&L_OP_KDICT, &&L_OP_RETURN, &&L_OP_TAILCALL, &&L_OP_BLKPUSH,
&&L_OP_ADD, &&L_OP_ADDI, &&L_OP_SUB, &&L_OP_SUBI, &&L_OP_MUL, &&L_OP_DIV,
@@ -496,17 +505,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_MOVE) {
/* A B R(A) := R(B) */
-#if 1
regs[GETARG_A(i)] = regs[GETARG_B(i)];
-#elif 0
- int a = GETARG_A(i);
- int b = GETARG_B(i);
-
- regs[a].tt = regs[b].tt;
- regs[a].value = regs[b].value;
-#else
- memcpy(regs+GETARG_A(i), regs+GETARG_B(i), sizeof(mrb_value));
-#endif
NEXT;
}
@@ -530,19 +529,19 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_LOADSELF) {
/* A R(A) := self */
- regs[GETARG_A(i)] = mrb->stack[0];
+ regs[GETARG_A(i)] = regs[0];
NEXT;
}
CASE(OP_LOADT) {
/* A R(A) := true */
- regs[GETARG_A(i)] = mrb_true_value();
+ SET_TRUE_VALUE(regs[GETARG_A(i)]);
NEXT;
}
CASE(OP_LOADF) {
/* A R(A) := false */
- regs[GETARG_A(i)] = mrb_false_value();
+ SET_FALSE_VALUE(regs[GETARG_A(i)]);
NEXT;
}
@@ -624,6 +623,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_GETUPVAR) {
/* A B C R(A) := uvget(B,C) */
+
regs[GETARG_A(i)] = uvget(mrb, GETARG_C(i), GETARG_B(i));
NEXT;
}
@@ -671,7 +671,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_RESCUE) {
/* A R(A) := exc; clear(exc) */
- SET_OBJ_VALUE(regs[GETARG_A(i)],mrb->exc);
+ SET_OBJ_VALUE(regs[GETARG_A(i)], mrb->exc);
mrb->exc = 0;
NEXT;
}
@@ -727,6 +727,10 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
NEXT;
}
+ CASE(OP_SENDB) {
+ /* fall through */
+ };
+
L_SEND:
CASE(OP_SEND) {
/* A B C R(A) := call(R(A),Sym(B),R(A+1),... ,R(A+C-1)) */
@@ -759,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++;
}
}
@@ -892,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++;
}
}
@@ -1278,16 +1282,17 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
z = x + y;
if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) {
/* integer overflow */
- return mrb_float_value((mrb_float)x + (mrb_float)y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x + (mrb_float)y);
+ break;
}
- regs[a] = mrb_fixnum_value(z);
+ SET_INT_VALUE(regs[a], z);
}
break;
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_float y = mrb_float(regs[a+1]);
- regs[a] = mrb_float_value((mrb_float)x + y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x + y);
}
break;
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
@@ -1297,10 +1302,9 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
OP_MATH_BODY(+,attr_f,attr_f);
break;
case TYPES2(MRB_TT_STRING,MRB_TT_STRING):
- regs[a] = mrb_str_plus(mrb, regs[a], regs[a+1]);
+ regs[a] = mrb_str_plus(mrb, regs[a], regs[a+1]);
break;
default:
- i = MKOP_ABC(OP_SEND, a, GETARG_B(i), GETARG_C(i));
goto L_SEND;
}
mrb->arena_idx = ai;
@@ -1322,16 +1326,17 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
z = x - y;
if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) {
/* integer overflow */
- return mrb_float_value((mrb_float)x - (mrb_float)y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x - (mrb_float)y);
+ break;
}
- regs[a] = mrb_fixnum_value(z);
+ SET_INT_VALUE(regs[a], z);
}
break;
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_float y = mrb_float(regs[a+1]);
- regs[a] = mrb_float_value((mrb_float)x - y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x - y);
}
break;
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
@@ -1341,7 +1346,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
OP_MATH_BODY(-,attr_f,attr_f);
break;
default:
- i = MKOP_ABC(OP_SEND, a, GETARG_B(i), GETARG_C(i));
goto L_SEND;
}
NEXT;
@@ -1361,18 +1365,18 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
y = mrb_fixnum(regs[a+1]);
z = x * y;
if (x != 0 && z/x != y) {
- regs[a] = mrb_float_value((mrb_float)x * (mrb_float)y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x * (mrb_float)y);
}
else {
- regs[a] = mrb_fixnum_value(z);
+ SET_INT_VALUE(regs[a], z);
}
}
break;
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_float y = mrb_float(regs[a+1]);
- regs[a] = mrb_float_value((mrb_float)x * y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x * y);
}
break;
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
@@ -1382,7 +1386,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
OP_MATH_BODY(*,attr_f,attr_f);
break;
default:
- i = MKOP_ABC(OP_SEND, a, GETARG_B(i), GETARG_C(i));
goto L_SEND;
}
NEXT;
@@ -1398,14 +1401,14 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_int y = mrb_fixnum(regs[a+1]);
- regs[a] = mrb_float_value((mrb_float)x / (mrb_float)y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x / (mrb_float)y);
}
break;
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_float y = mrb_float(regs[a+1]);
- regs[a] = mrb_float_value((mrb_float)x / y);
+ SET_FLT_VALUE(regs[a], (mrb_float)x / y);
}
break;
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
@@ -1415,7 +1418,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
OP_MATH_BODY(/,attr_f,attr_f);
break;
default:
- i = MKOP_ABC(OP_SEND, a, GETARG_B(i), GETARG_C(i));
goto L_SEND;
}
NEXT;
@@ -1487,14 +1489,19 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
OP_CMP_BODY(op,attr_f,attr_f);\
break;\
default:\
- i = MKOP_ABC(OP_SEND, a, GETARG_B(i), GETARG_C(i));\
goto L_SEND;\
}\
} while (0)
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;
}
@@ -1524,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;
}
@@ -1565,7 +1565,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
}
else {
- regs[GETARG_A(i)] = mrb_ary_ref(mrb, v, c);
+ regs[GETARG_A(i)] = mrb_ary_ref(mrb, v, c);
}
NEXT;
}
@@ -1598,13 +1598,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
if (len > pre + post) {
regs[a++] = mrb_ary_new_elts(mrb, len - pre - post, ary->ptr+pre);
while (post--) {
- regs[a++] = ary->ptr[len-post-1];
+ regs[a++] = ary->ptr[len-post-1];
}
}
else {
- regs[a++] = mrb_ary_new_capa(mrb, 0);
+ regs[a++] = mrb_ary_new_capa(mrb, 0);
for (i=0; i+pre<len; i++) {
- regs[a+i] = ary->ptr[pre+i];
+ regs[a+i] = ary->ptr[pre+i];
}
while (i < post) {
SET_NIL_VALUE(regs[a+i]);
@@ -1695,7 +1695,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
base = regs[a];
if (mrb_nil_p(base)) {
- base = mrb_obj_value(mrb->ci->target_class);
+ base = mrb_obj_value(mrb->ci->target_class);
}
c = mrb_vm_define_module(mrb, base, id);
regs[a] = mrb_obj_value(c);
View
4 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 ...)
View
7 test/README.md
@@ -0,0 +1,7 @@
+Running Tests
+=============
+
+To run the tests, execute the following from the project's root directory.
+
+ $ make test
+
View
9 test/t/kernel.rb
@@ -213,8 +213,8 @@ def test_method; end
end
assert('Kernel#inspect', '15.3.1.3.17') do
- s = nil.inspect
- s.class == String and s == "nil"
+ s = inspect
+ s.class == String and s == "main"
end
assert('Kernel#instance_variables', '15.3.1.3.23') do
@@ -270,7 +270,7 @@ def test_method; end
end
assert('Kernel#nil?', '15.3.1.3.32') do
- nil.nil? == true
+ nil? == false
end
assert('Kernel#object_id', '15.3.1.3.33') do
@@ -337,6 +337,5 @@ def test_method; end
end
assert('Kernel#to_s', '15.3.1.3.46') do
- # TODO looks strange..
- nil.to_s == ''
+ to_s == '#<Object:0x0>'
end
View
16 test/t/module.rb
@@ -105,3 +105,19 @@ module Test4includedModules2
r = Test4includedModules2.included_modules
r.class == Array and r.include?(Test4includedModules)
end
+
+# Not ISO specified
+
+assert('Module#to_s') do
+ module Test4to_sModules
+ end
+
+ Test4to_sModules.to_s == 'Test4to_sModules'
+end
+
+assert('Module#inspect') do
+ module Test4to_sModules
+ end
+
+ Test4to_sModules.inspect == 'Test4to_sModules'
+end
View
4 test/t/string.rb
@@ -335,6 +335,10 @@
"#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:"
end
+assert('Check the usage of a NUL character') do
+ "qqq\0ppp"
+end
+
assert('String strip methods test') do
ls = " strip"
rs = "strip "
View
10 test/t/time.rb
@@ -187,5 +187,15 @@
assert('Time#zone', '15.2.19.7.33') do
Time.at(1300000000.0).utc.zone == 'UTC'
end
+
+ # Not ISO specified
+
+ assert('Time#to_s') do
+ Time.at(1300000000.0).utc.to_s == "Sun Mar 13 07:06:40 UTC 2011"
+ end
+
+ assert('Time#inspect') do
+ Time.at(1300000000.0).utc.inspect == "Sun Mar 13 07:06:40 UTC 2011"
+ end
end
View
2 tools/mirb/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mirb executable
# project-specific macros
View
13 tools/mirb/mirb.c
@@ -143,7 +143,9 @@ print_cmdline(int code_block_open)
int
main(void)
{
- char last_char, ruby_code[1024], last_code_line[1024];
+ char last_char;
+ char ruby_code[1024] = { 0 };
+ char last_code_line[1024] = { 0 };
int char_index;
mrbc_context *cxt;
struct mrb_parser_state *parser;
@@ -163,8 +165,6 @@ main(void)
cxt = mrbc_context_new(mrb);
cxt->capture_errors = 1;
- memset(ruby_code, 0, sizeof(*ruby_code));
- memset(last_code_line, 0, sizeof(*last_code_line));
while (TRUE) {
print_cmdline(code_block_open);
@@ -197,8 +197,7 @@ main(void)
strcat(ruby_code, last_code_line);
}
else {
- memset(ruby_code, 0, sizeof(*ruby_code));
- strcat(ruby_code, last_code_line);
+ strcpy(ruby_code, last_code_line);
}
}
@@ -238,8 +237,8 @@ main(void)
p(mrb, result);
}
}
- memset(ruby_code, 0, sizeof(*ruby_code));
- memset(ruby_code, 0, sizeof(*last_code_line));
+ ruby_code[0] = '\0';
+ last_code_line[0] = '\0';
mrb_parser_free(parser);
}
}
View
2 tools/mrbc/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby-compiler
# project-specific macros
View
3 tools/mrbc/mrbc.c
@@ -70,8 +70,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
char *infile = NULL;
char *outfile = NULL;
char **origargv = argv;
+ static const struct _args args_zero = { 0 };
- memset(args, 0, sizeof(*args));
+ *args = args_zero;
args->ext = RITEBIN_EXT;
for (argc--,argv++; argc > 0; argc--,argv++) {
View
2 tools/mruby/Makefile
@@ -1,4 +1,4 @@
-# makefile discription.
+# Makefile description.
# basic build file for mruby executable
# project-specific macros
View
3 tools/mruby/mruby.c
@@ -57,8 +57,9 @@ static int
parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
{
char **origargv = argv;
+ static const struct _args args_zero = { 0 };
- memset(args, 0, sizeof(*args));
+ *args = args_zero;
for (argc--,argv++; argc > 0; argc--,argv++) {
char *item;
View
9 tools/xpcat/xpcat.c
@@ -26,8 +26,10 @@ main(int argc, char *argv[])
i++;
if (i < argc)
output = argv[i];
- else
+ else {
+ usage(argv[0]);
return EXIT_FAILURE;
+ }
}
}
@@ -40,7 +42,10 @@ main(int argc, char *argv[])
setbuf(outfile, NULL);
for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-o") == 0) { i++; continue; }
+ if (strcmp(argv[i], "-o") == 0) {
+ i++;
+ continue;
+ }
infile = fopen(argv[i], "rb");
if (!infile) {

0 comments on commit 2d4620f

Please sign in to comment.