summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile45
-rw-r--r--mrblib/CMakeLists.txt4
-rw-r--r--mrblib/Makefile17
-rw-r--r--mrblib/compar.rb52
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile13
-rw-r--r--src/array.c18
-rw-r--r--src/class.c2
-rw-r--r--src/codegen.c17
-rw-r--r--src/error.c2
-rw-r--r--src/gc.c9
-rw-r--r--src/hash.c4
-rw-r--r--src/load.c3
-rw-r--r--src/numeric.c26
-rw-r--r--src/parse.y22
-rw-r--r--src/regint.h5
-rw-r--r--src/sprintf.c13
-rw-r--r--src/string.c10
-rw-r--r--src/transcode.c15
-rw-r--r--src/variable.c6
-rw-r--r--src/vm.c5
-rw-r--r--test/Makefile31
-rw-r--r--test/t/argumenterror.rb15
-rw-r--r--test/t/array.rb42
-rw-r--r--test/t/bs_block.rb1
-rw-r--r--test/t/bs_literal.rb1
-rw-r--r--test/t/class.rb (renamed from test/t/bs_class.rb)51
-rw-r--r--test/t/enumerable.rb103
-rw-r--r--test/t/exception.rb (renamed from test/t/bs_exception.rb)61
-rw-r--r--test/t/false.rb26
-rw-r--r--test/t/float.rb1
-rw-r--r--test/t/hash.rb1
-rw-r--r--test/t/indexerror.rb6
-rw-r--r--test/t/integer.rb1
-rw-r--r--test/t/kernel.rb124
-rw-r--r--test/t/literals.rb67
-rw-r--r--test/t/localjumperror.rb9
-rw-r--r--test/t/module.rb10
-rw-r--r--test/t/nameerror.rb14
-rw-r--r--test/t/nil.rb26
-rw-r--r--test/t/nomethoderror.rb13
-rw-r--r--test/t/numeric.rb1
-rw-r--r--test/t/object.rb6
-rw-r--r--test/t/proc.rb44
-rw-r--r--test/t/range.rb1
-rw-r--r--test/t/rangeerror.rb6
-rw-r--r--test/t/regexperror.rb4
-rw-r--r--test/t/runtimeerror.rb14
-rw-r--r--test/t/standarderror.rb6
-rw-r--r--test/t/string.rb1
-rw-r--r--test/t/struct.rb6
-rw-r--r--test/t/symbol.rb1
-rw-r--r--test/t/time.rb1
-rw-r--r--test/t/true.rb26
-rw-r--r--test/t/typeerror.rb6
-rw-r--r--tools/mirb/Makefile8
-rw-r--r--tools/mirb/mirb.c3
-rw-r--r--tools/mrbc/CMakeLists.txt4
-rw-r--r--tools/mrbc/Makefile8
-rw-r--r--tools/mrbc/mrbc.c5
-rw-r--r--tools/mruby/Makefile7
61 files changed, 848 insertions, 202 deletions
diff --git a/Makefile b/Makefile
index fc22089a9..e7408d793 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,12 @@
# makefile discription.
# basic build file for mruby
-# compiler, linker (gcc)
-CC = gcc
-LL = gcc
+# compiler, linker (gcc), archiver, parser generator
+export CC = gcc
+export LL = gcc
+export AR = ar
+export YACC = bison
+
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
@@ -18,6 +21,16 @@ else
endif
##############################
+# internal variables
+
+export MSG_BEGIN = @for line in
+export MSG_END = ; do echo "$$line"; done
+
+export CP := cp
+export RM_F := rm -f
+export CAT := cat
+
+##############################
# generic build targets, rules
.PHONY : all
@@ -39,3 +52,29 @@ clean :
@$(MAKE) clean -C tools/mruby $(MAKE_FLAGS)
@$(MAKE) clean -C tools/mirb $(MAKE_FLAGS)
@$(MAKE) clean -C test $(MAKE_FLAGS)
+
+# display help for build configuration and interesting targets
+.PHONY : showconfig
+showconfig :
+ $(MSG_BEGIN) \
+ "" \
+ " CC = $(CC)" \
+ " LL = $(LL)" \
+ " MAKE = $(MAKE)" \
+ "" \
+ " CFLAGS = $(CFLAGS)" \
+ " ALL_CFLAGS = $(ALL_CFLAGS)" \
+ $(MSG_END)
+
+.PHONY : help
+help :
+ $(MSG_BEGIN) \
+ "" \
+ " Basic mruby Makefile" \
+ "" \
+ "targets:" \
+ " all (default): build all targets, install (locally) in-repo" \
+ " clean: clean all built and in-repo installed artifacts" \
+ " showconfig: show build config summary" \
+ " test: run all mruby tests" \
+ $(MSG_END)
diff --git a/mrblib/CMakeLists.txt b/mrblib/CMakeLists.txt
index b9fa22587..a0386f0fe 100644
--- a/mrblib/CMakeLists.txt
+++ b/mrblib/CMakeLists.txt
@@ -45,12 +45,10 @@ else()
endif()
-add_library(mrblib_object OBJECT mrblib.c)
-
# generate final static libmruby archive library
add_library(libmruby_static STATIC
+ mrblib.c
$<TARGET_OBJECTS:mruby_object>
- $<TARGET_OBJECTS:mrblib_object>
)
set_target_properties(libmruby_static PROPERTIES OUTPUT_NAME mruby)
diff --git a/mrblib/Makefile b/mrblib/Makefile
index d22c4509f..c7226ddcd 100644
--- a/mrblib/Makefile
+++ b/mrblib/Makefile
@@ -15,17 +15,15 @@ MRBS := $(MRB1)
LIBR0 := ../lib/libmruby_core.a
LIBR := ../lib/libmruby.a
-# C compiler (gcc)
-CC = gcc
-LL = gcc
-AR = ar
+# libraries, includes
+INCLUDES = -I../src -I../include
+
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g
else
CFLAGS = -O3
endif
-INCLUDES = -I../src -I../include
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
ifeq ($(OS),Windows_NT)
MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)"
@@ -40,6 +38,7 @@ else
MRBC = ../bin/mrbc
endif
+
##############################
# generic build targets, rules
@@ -48,7 +47,7 @@ all : $(LIBR)
# update libmruby.a
$(LIBR) : $(MLIB) $(LIBR0)
- cp $(LIBR0) $(LIBR)
+ $(CP) $(LIBR0) $(LIBR)
$(AR) r $(LIBR) $(MLIB)
# Compile mrblib source
@@ -57,17 +56,17 @@ $(MLIB) : $(CLIB)
# Compile C source from merged mruby source
$(CLIB) : $(RLIB) $(MRBC)
- $(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); cat init_$(TARGET).c $(DLIB) > $@
+ $(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); $(CAT) init_$(TARGET).c $(DLIB) > $@
$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y
$(MAKE) -C ../tools/mrbc $(MAKE_FLAGS)
# merge mruby sources
$(RLIB) : $(MRBS)
- cat $? > $@
+ $(CAT) $(MRBS) > $@
# clean up
.PHONY : clean
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR)
+ -$(RM_F) $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR)
diff --git a/mrblib/compar.rb b/mrblib/compar.rb
index 3badf57de..9f2ab887d 100644
--- a/mrblib/compar.rb
+++ b/mrblib/compar.rb
@@ -1,5 +1,15 @@
+##
+# Comparable
+#
+# ISO 15.3.3
module Comparable
- # 15.3.3.2.1
+
+ ##
+ # Return true if +self+ is less
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.1
def < other
cmp = self <=> other
if cmp.nil?
@@ -11,7 +21,12 @@ module Comparable
end
end
- # 15.3.3.2.2
+ ##
+ # 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
if cmp.nil?
@@ -23,7 +38,12 @@ module Comparable
end
end
- # 15.3.3.2.3
+ ##
+ # Return true if +self+ is equal
+ # to +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.3
def == other
cmp = self <=> other
if cmp == 0
@@ -33,7 +53,12 @@ module Comparable
end
end
- # 15.3.3.2.4
+ ##
+ # Return true if +self+ is greater
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.4
def > other
cmp = self <=> other
if cmp.nil?
@@ -45,9 +70,14 @@ module Comparable
end
end
- # 15.3.3.2.5
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +other+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.5
def >= other
- cmp = self <=> other
+ cmp = self <=> other
if cmp.nil?
false
elsif cmp >= 0
@@ -57,8 +87,14 @@ module Comparable
end
end
- # 15.3.3.2.6
- def between?(min,max)
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +min+ and
+ # less than or equal to +max+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.6
+ def between?(min, max)
if self < min or self > max
false
else
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 390129eb9..4a6aeee2c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,5 @@ file(GLOB MRUBY_SRC_C "*.c")
list(APPEND MRUBY_SRC_C "${CMAKE_CURRENT_BINARY_DIR}/parse.c")
add_library(mruby_object OBJECT ${MRUBY_SRC_C} ${BISON_mruby_OUTPUTS})
-add_library(mruby_static STATIC EXCLUDE_FROM_ALL $<TARGET_OBJECTS:mruby_object>)
# vim: ts=2 sts=2 sw=2 et
diff --git a/src/Makefile b/src/Makefile
index 385e447e3..61012ea68 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -19,12 +19,6 @@ OBJS := $(OBJ1) $(OBJ2) $(OBJ3)
# libraries, includes
INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include
-# compiler, linker (gcc)
-CC = gcc
-LL = gcc
-AR = ar
-YACC = bison
-
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
@@ -33,6 +27,7 @@ CFLAGS = -O3
endif
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
+
##############################
# generic build targets, rules
@@ -64,6 +59,6 @@ $(LDEF) : $(KWD)
.PHONY : clean #cleandep
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(TARGET) $(OBJS) $(OBJY) $(YC)
- -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d)
- -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
+ -$(RM_F) $(TARGET) $(OBJS) $(OBJY) $(YC)
+ -$(RM_F) $(OBJS:.o=.d) $(OBJY:.o=.d)
+ -$(RM_F) $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
diff --git a/src/array.c b/src/array.c
index 37f1474df..7b486430f 100644
--- a/src/array.c
+++ b/src/array.c
@@ -917,22 +917,10 @@ mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
static mrb_value
mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
{
- mrb_value *argv;
- int argc;
-
- mrb_get_args(mrb, "*", &argv, &argc);
- switch(argc) {
- case 0:
- return mrb_ary_join(mrb, ary, mrb_nil_value());
-
- case 1:
- return mrb_ary_join(mrb, ary, argv[0]);
-
- default:
- mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
- }
+ mrb_value sep = mrb_nil_value();
- return mrb_nil_value(); /* dummy */
+ mrb_get_args(mrb, "|o", &sep);
+ return mrb_ary_join(mrb, ary, sep);
}
static mrb_value
diff --git a/src/class.c b/src/class.c
index c6dfdd568..b1ed7c0dc 100644
--- a/src/class.c
+++ b/src/class.c
@@ -578,7 +578,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
break;
}
}
- if (!*format && argc > i) {
+ if (!c && argc > i) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
}
va_end(ap);
diff --git a/src/codegen.c b/src/codegen.c
index 087dd3165..11e9eb236 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -64,6 +64,7 @@ typedef struct scope {
int nlocals;
int nregs;
+ int ai;
int idx;
} codegen_scope;
@@ -1234,25 +1235,25 @@ codegen(codegen_scope *s, node *tree, int val)
int idx = new_msym(s, sym);
if (name[0] == '+' && strlen(name) == 1) {
- genop(s, MKOP_ABC(OP_ADD, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_ADD, cursp(), idx, 1));
}
else if (name[0] == '-' && strlen(name) == 1) {
- genop(s, MKOP_ABC(OP_SUB, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_SUB, cursp(), idx, 1));
}
else if (name[0] == '<' && strlen(name) == 1) {
- genop(s, MKOP_ABC(OP_LT, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_LT, cursp(), idx, 1));
}
else if (name[0] == '<' && strlen(name) == 2 && name[1] == '=') {
- genop(s, MKOP_ABC(OP_LE, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_LE, cursp(), idx, 1));
}
else if (name[0] == '>' && strlen(name) == 1) {
- genop(s, MKOP_ABC(OP_GT, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_GT, cursp(), idx, 1));
}
else if (name[0] == '>' && strlen(name) == 2 && name[1] == '=') {
- genop(s, MKOP_ABC(OP_GE, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_GE, cursp(), idx, 1));
}
else {
- genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 2));
+ genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 1));
}
}
gen_assignment(s, tree->car, cursp(), val);
@@ -1849,6 +1850,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
p->lv = lv;
p->sp += node_len(lv)+2;
p->nlocals = p->sp;
+ p->ai = mrb->arena_idx;
p->idx = mrb->irep_len++;
@@ -1882,6 +1884,7 @@ scope_finish(codegen_scope *s, int idx)
irep->nlocals = s->nlocals;
irep->nregs = s->nregs;
+ s->mrb->arena_idx = s->ai;
mrb_pool_close(s->mpool);
}
diff --git a/src/error.c b/src/error.c
index 5b32e3a00..feaa04af7 100644
--- a/src/error.c
+++ b/src/error.c
@@ -443,7 +443,7 @@ mrb_init_exception(mrb_state *mrb)
#ifdef INCLUDE_ENCODING
mrb_define_class(mrb, "EncodingError", mrb->eStandardError_class);
#endif
- mrb_define_class(mrb, "ZeroDivisionError", mrb->eStandardError_class); /* 15.2.30 */
+ // mrb_define_class(mrb, "ZeroDivisionError", mrb->eStandardError_class); /* 15.2.30 */
mrb_define_class(mrb, "FloatDomainError", eRangeError);
mrb_define_class(mrb, "KeyError", eIndexError);
diff --git a/src/gc.c b/src/gc.c
index 1d7a8627f..0ba6e3e76 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -261,12 +261,13 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
}
mrb->live++;
- mrb->arena[mrb->arena_idx++] = p;
- memset(p, 0, sizeof(RVALUE));
- if (mrb->arena_idx >= MRB_ARENA_SIZE) {
+ if (mrb->arena_idx > MRB_ARENA_SIZE) {
/* arena overflow error */
- mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error");
+ mrb->arena_idx = MRB_ARENA_SIZE - 2; /* force room in arena */
+ mrb_raise(mrb, mrb->eRuntimeError_class, "arena overflow error");
}
+ mrb->arena[mrb->arena_idx++] = p;
+ memset(p, 0, sizeof(RVALUE));
p->tt = ttype;
p->c = cls;
paint_partial_white(mrb, p);
diff --git a/src/hash.c b/src/hash.c
index 94be511c8..19d0507e3 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -1007,14 +1007,12 @@ mrb_hash_keys(mrb_state *mrb, mrb_value hash)
{
khash_t(ht) *h = RHASH_TBL(hash);
khiter_t k;
- mrb_value ary = mrb_ary_new(mrb);
+ mrb_value ary = mrb_ary_new_capa(mrb, kh_size(h));
if (!h) return ary;
for (k = kh_begin(h); k != kh_end(h); k++) {
if (kh_exist(h, k)) {
mrb_value v = kh_key(h,k);
- if ( !mrb_special_const_p(v) )
- v = mrb_obj_dup(mrb, v);
mrb_ary_push(mrb, ary, v);
}
}
diff --git a/src/load.c b/src/load.c
index af0e519bd..e73f09b3a 100644
--- a/src/load.c
+++ b/src/load.c
@@ -337,6 +337,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
mrb_int fix_num;
mrb_float f;
mrb_value str;
+ int ai = mrb_gc_arena_save(mrb);
recordStart = src;
buf = mrb_malloc(mrb, bufsize);
@@ -489,6 +490,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
*len = src - recordStart;
error_exit:
+ mrb_gc_arena_restore(mrb, ai);
if (buf)
mrb_free(mrb, buf);
@@ -537,7 +539,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
}
mrb->irep_len += nirep;
-
error_exit:
if (ret != MRB_DUMP_OK) {
for (n=0,i=sirep; n<nirep; n++,i++) {
diff --git a/src/numeric.c b/src/numeric.c
index 09d55a5de..f26dda424 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -37,12 +37,6 @@
#define fmod(x,y) fmodf(x,y)
#endif
-void
-mrb_num_zerodiv(mrb_state *mrb)
-{
- mrb_raise(mrb, E_ZERODIVISION_ERROR, "divided by 0");
-}
-
static mrb_float
mrb_to_flo(mrb_state *mrb, mrb_value val)
{
@@ -252,7 +246,6 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
{
mrb_float div, mod;
- if (y == 0.0) mrb_num_zerodiv(mrb);
mod = fmod(x, y);
if (isinf(x) && !isinf(y) && !isnan(y))
div = x;
@@ -744,7 +737,6 @@ fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
{
mrb_int div, mod;
- if (y == 0) mrb_num_zerodiv(mrb);
if (y < 0) {
if (x < 0)
div = -x / -y;
@@ -1043,24 +1035,6 @@ fix_to_f(mrb_state *mrb, mrb_value num)
}
/*
- * Document-class: ZeroDivisionError
- *
- * Raised when attempting to divide an integer by 0.
- *
- * 42 / 0
- *
- * <em>raises the exception:</em>
- *
- * ZeroDivisionError: divided by 0
- *
- * Note that only division by an exact 0 will raise that exception:
- *
- * 42 / 0.0 #=> Float::INFINITY
- * 42 / -0.0 #=> -Float::INFINITY
- * 0 / 0.0 #=> NaN
- */
-
-/*
* Document-class: FloatDomainError
*
* Raised when attempting to convert special float values
diff --git a/src/parse.y b/src/parse.y
index 316e7309c..55c82c12d 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -41,8 +41,13 @@ static void backref_error(parser_state *p, node *n);
#define identchar(c) (isalnum(c) || (c) == '_' || !isascii(c))
+#ifndef TRUE
#define TRUE 1
+#endif
+
+#ifndef FALSE
#define FALSE 0
+#endif
typedef unsigned int stack_type;
@@ -1003,7 +1008,7 @@ top_stmts : none
}
| error top_stmt
{
- $$ = $2;
+ $$ = new_begin(p, 0);
}
;
@@ -2925,10 +2930,10 @@ yyerror(parser_state *p, const char *s)
if (! p->capture_errors) {
if (p->filename) {
- fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column+1, s);
+ fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
}
else {
- fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column+1, s);
+ fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s);
}
}
else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) {
@@ -2937,7 +2942,7 @@ yyerror(parser_state *p, const char *s)
memcpy(c, s, n + 1);
p->error_buffer[p->nerr].message = c;
p->error_buffer[p->nerr].lineno = p->lineno;
- p->error_buffer[p->nerr].column = p->column+1;
+ p->error_buffer[p->nerr].column = p->column;
}
p->nerr++;
}
@@ -2959,10 +2964,10 @@ yywarn(parser_state *p, const char *s)
if (! p->capture_errors) {
if (p->filename) {
- fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column+1, s);
+ fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
}
else {
- fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column+1, s);
+ fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s);
}
}
else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) {
@@ -3035,8 +3040,8 @@ nextc(parser_state *p)
if (c == '\n') {
// must understand heredoc
}
- p->column++;
}
+ p->column++;
return c;
}
@@ -3564,8 +3569,8 @@ parser_yylex(parser_state *p)
if (p->column == 1) {
if (peeks(p, "begin\n")) {
skips(p, "\n=end\n");
+ goto retry;
}
- goto retry;
}
switch (p->lstate) {
case EXPR_FNAME: case EXPR_DOT:
@@ -4694,6 +4699,7 @@ mrb_parser_new(mrb_state *mrb)
p->capture_errors = 0;
p->lineno = 1;
+ p->column = 0;
#if defined(PARSER_TEST) || defined(PARSER_DEBUG)
yydebug = 1;
#endif
diff --git a/src/regint.h b/src/regint.h
index 23e3a8c05..aa4871594 100644
--- a/src/regint.h
+++ b/src/regint.h
@@ -222,8 +222,13 @@
#include "regenc.h"
+#ifndef MIN
#define MIN(a,b) (((a)>(b))?(b):(a))
+#endif
+
+#ifndef MAX
#define MAX(a,b) (((a)<(b))?(b):(a))
+#endif
#define IS_NULL(p) (((void*)(p)) == (void*)0)
#define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
diff --git a/src/sprintf.c b/src/sprintf.c
index 6a86a0d04..479efa6c4 100644
--- a/src/sprintf.c
+++ b/src/sprintf.c
@@ -54,7 +54,7 @@ remove_sign_bits(char *str, int base)
static char
sign_bits(int base, const char *p)
{
- char c = '.';
+ char c;
switch (base) {
case 16:
@@ -65,6 +65,8 @@ sign_bits(int base, const char *p)
c = '7'; break;
case 2:
c = '1'; break;
+ default:
+ c = '.'; break;
}
return c;
}
@@ -74,7 +76,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
{
char buf[64], *b = buf + sizeof buf;
unsigned long val = mrb_fixnum(x);
- char d = 0;
+ char d;
if (base != 2) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid radix %d", base);
@@ -97,6 +99,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
case 16: d = 'f'; break;
case 8: d = '7'; break;
case 2: d = '1'; break;
+ default: d = 0; break;
}
if (d && *b != d) {
@@ -793,6 +796,8 @@ format_s:
case 'B':
if (flags&(FPLUS|FSPACE)) sign = 1;
break;
+ default:
+ break;
}
if (flags & FSHARP) {
switch (*p) {
@@ -801,6 +806,7 @@ format_s:
case 'X': prefix = "0X"; break;
case 'b': prefix = "0b"; break;
case 'B': prefix = "0B"; break;
+ default: break;
}
}
@@ -884,13 +890,14 @@ bin_retry:
snprintf(fbuf, sizeof(fbuf), "%%l%c", c);
snprintf(++s, sizeof(nbuf) - 1, fbuf, v);
if (v < 0) {
- char d = 0;
+ char d;
s = remove_sign_bits(s, base);
switch (base) {
case 16: d = 'f'; break;
case 8: d = '7'; break;
case 2: d = '1'; break;
+ default: d = 0; break;
}
if (d && *s != d) {
diff --git a/src/string.c b/src/string.c
index 28513c15c..695b0d01c 100644
--- a/src/string.c
+++ b/src/string.c
@@ -4400,9 +4400,17 @@ mrb_str_conv_enc_opts(mrb_state *mrb, mrb_value str, mrb_encoding *from, mrb_enc
mrb_enc_associate(mrb, newstr, to);
return newstr;
- default:
+ case econv_invalid_byte_sequence:
+ case econv_undefined_conversion:
+ case econv_source_buffer_empty:
+ case econv_after_output:
+ case econv_incomplete_input:
/* some error, return original */
return str;
+
+ default:
+ mrb_bug("Internal Error: Invalid return value mrb_econv_convert.");
+ return str;
}
}
diff --git a/src/transcode.c b/src/transcode.c
index 32a45932e..d9f0ce896 100644
--- a/src/transcode.c
+++ b/src/transcode.c
@@ -543,6 +543,7 @@ transcode_restartable0(mrb_state *mrb,
case 32: goto resume_label32;
case 33: goto resume_label33;
case 34: goto resume_label34;
+ default: break;
}
while (1) {
@@ -1197,6 +1198,10 @@ trans_sweep(mrb_state *mrb, mrb_econv_t *ec,
case econv_finished:
ec->num_finished = i+1;
break;
+
+ default:
+ mrb_bug("Internal Error: invalid return value from mrb_transcoding_convert().");
+ break;
}
}
}
@@ -1507,8 +1512,12 @@ mrb_econv_convert(mrb_state *mrb, mrb_econv_t *ec,
/* todo: add more alternative behaviors */
switch (ec->flags & ECONV_INVALID_MASK) {
case ECONV_INVALID_REPLACE:
- if (output_replacement_character(mrb, ec) == 0)
+ if (output_replacement_character(mrb, ec) == 0)
goto resume;
+
+ default:
+ mrb_bug("Internal error: Unhandled ECONV_INVALID_xxx.");
+ break;
}
}
@@ -1526,6 +1535,10 @@ mrb_econv_convert(mrb_state *mrb, mrb_econv_t *ec,
if (output_hex_charref(mrb, ec) == 0)
goto resume;
break;
+
+ default:
+ mrb_bug("Internal error: Unhandled ECONV_UNDEF_xxx.");
+ break;
}
}
diff --git a/src/variable.c b/src/variable.c
index 1f1a400cd..82ab7bef3 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -186,12 +186,16 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v)
if (k != kh_end(h)) {
k = kh_put(iv, h, sym);
kh_value(h, k) = v;
+ return;
}
}
c = c->super;
}
c = mrb->ci->target_class;
- h = c->iv = kh_init(iv, mrb);
+ h = c->iv;
+ if (!h) {
+ c->iv = h = kh_init(iv, mrb);
+ }
k = kh_put(iv, h, sym);
kh_value(h, k) = v;
}
diff --git a/src/vm.c b/src/vm.c
index b2a7b33d1..be55a0124 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -980,7 +980,10 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
cipop(mrb);
ci = mrb->ci;
if (ci == mrb->cibase) {
- if (ci->ridx == 0) goto L_STOP;
+ if (ci->ridx == 0) {
+ mrb->stack = mrb->stbase;
+ goto L_STOP;
+ }
break;
}
}
diff --git a/test/Makefile b/test/Makefile
index d46fa7a3e..170c1dac8 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -16,17 +16,16 @@ ASSLIB := $(BASEDIR)/assert.rb
MRBS := $(BASEDIR)/t/*.rb
OBJS := driver.o $(MLIB)
-# C compiler (gcc)
-CC = gcc
-LL = gcc
-AR = ar
+# libraries, includes
+LIBS = -lm
+INCLUDES = -I$(BASEDIR)/../src -I$(BASEDIR)/../include
+
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g
else
CFLAGS = -O3
endif
-INCLUDES = -I../src -I../include
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
ifeq ($(OS),Windows_NT)
MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)"
@@ -43,20 +42,6 @@ MRBC = ../bin/mrbc
EXE := $(TARGET)
endif
-# libraries, includes
-LIBS = -lm
-
-# compiler, linker (gcc)
-CC = gcc
-LL = gcc
-YACC = bison
-DEBUG_MODE = 1
-ifeq ($(DEBUG_MODE),1)
-CFLAGS = -g -O3
-else
-CFLAGS = -O3
-endif
-ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
##############################
# generic build targets, rules
@@ -66,7 +51,7 @@ all : $(EXE)
./$(EXE)
# executable constructed using linker from object files
-$(EXE) : $(OBJS)
+$(EXE) : $(OBJS) $(LIBR)
$(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(LIBS)
-include $(OBJS:.o=.d)
@@ -77,14 +62,14 @@ $(OBJS) : %.o : %.c
# Compile C source from merged mruby source
$(CLIB) : $(RLIB) $(MRBC) $(INIT)
- $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); cat $(INIT) $(DLIB) > $@
+ $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); $(CAT) $(INIT) $(DLIB) > $@
# merge mruby sources
$(RLIB) : $(ASSLIB) $(MRBS)
- cat $(ASSLIB) $(MRBS) > $@
+ $(CAT) $(ASSLIB) $(MRBS) > $@
# clean up
.PHONY : clean
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(OBJS) $(EXE)
+ -$(RM_F) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(OBJS) $(EXE)
diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb
new file mode 100644
index 000000000..ca998f8de
--- /dev/null
+++ b/test/t/argumenterror.rb
@@ -0,0 +1,15 @@
+##
+# ArgumentError ISO Test
+
+assert('ArgumentError', '15.2.24') do
+ e2 = nil
+ a = []
+ begin
+ # this will cause an exception due to the wrong arguments
+ a[]
+ rescue => e1
+ e2 = e1
+ end
+
+ ArgumentError.class == Class and e2.class == ArgumentError
+end
diff --git a/test/t/array.rb b/test/t/array.rb
index 3b9dfedfb..dba1b035d 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -22,11 +22,47 @@ assert('Array#<<', '15.2.12.5.3') do
end
assert('Array#[]', '15.2.12.5.4') do
- [1,2,3].[](1) == 2
+ e2 = nil
+ e3 = nil
+ a = Array.new
+ begin
+ # this will cause an exception due to the wrong arguments
+ a.[]()
+ rescue => e1
+ e2 = e1
+ end
+ begin
+ # this will cause an exception due to the wrong arguments
+ a.[](1,2,3)
+ rescue => e1
+ e3 = e1
+ end
+
+ [1,2,3].[](1) == 2 and
+ e2.class == ArgumentError and
+ e3.class == ArgumentError
end
assert('Array#[]=', '15.2.12.5.5') do
- [1,2,3].[]=(1,4) == [1, 4, 3]
+ e2 = nil
+ e3 = nil
+ a = Array.new
+ begin
+ # this will cause an exception due to the wrong arguments
+ a.[]=()
+ rescue => e1
+ e2 = e1
+ end
+ begin
+ # this will cause an exception due to the wrong arguments
+ a.[]=(1,2,3,4)
+ rescue => e1
+ e3 = e1
+ end
+
+ [1,2,3].[]=(1,4) == [1, 4, 3] and
+ e2.class == ArgumentError and
+ e3.class == ArgumentError
end
assert('Array#clear', '15.2.12.5.6') do
@@ -193,5 +229,3 @@ assert('Array#unshift', '15.2.12.5.30') do
end
# Not ISO specified
-
-
diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb
index acbade449..b290cb914 100644
--- a/test/t/bs_block.rb
+++ b/test/t/bs_block.rb
@@ -388,4 +388,3 @@ assert('BS Block [ruby-core:14395]') do
t = Controller.new
t.test_for_bug
end
-
diff --git a/test/t/bs_literal.rb b/test/t/bs_literal.rb
index b1ae3a5d6..842d8704c 100644
--- a/test/t/bs_literal.rb
+++ b/test/t/bs_literal.rb
@@ -36,4 +36,3 @@ end
assert('BS Literal 9') do
Fixnum == 1234.class
end
-
diff --git a/test/t/bs_class.rb b/test/t/class.rb
index d8bb63c05..92f3df51d 100644
--- a/test/t/bs_class.rb
+++ b/test/t/class.rb
@@ -1,121 +1,126 @@
##
-# Bootstrap tests for Class
+# Class ISO Test
-assert('BS Class 1') do
+assert('Class', '15.2.3') do
+ Class.class == Class
+end
+
+# Not ISO specified
+
+assert('Class 1') do
class C; end
C.class == Class
end
-assert('BS Class 2') do
+assert('Class 2') do
class C; end
C.new.class == C
end
-assert('BS Class 3') do
+assert('Class 3') do
class C; end
C.new.class.class == Class
end
-assert('BS Class 4') do
+assert('Class 4') do
class A; end
class C < A; end
C.class == Class
end
-assert('BS Class 5') do
+assert('Class 5') do
class A; end
class C < A; end
C.new.class == C
end
-assert('BS Class 6') do
+assert('Class 6') do
class A; end
class C < A; end
C.new.class.class == Class
end
-assert('BS Class Module 1') do
+assert('Class Module 1') do
module M; end
M.class == Module
end
-assert('BS Class Module 2') do
+assert('Class Module 2') do
module M; end
class C; include M; end
C.new.class == C
end
# nested class
-assert('BS Class Nested 1') do
+assert('Class Nested 1') do
class A; end
class A::B; end
A::B == A::B
end
-assert('BS Class Nested 2') do
+assert('Class Nested 2') do
class A; end
class A::B; end
A::B.new.class == A::B
end
-assert('BS Class Nested 3') do
+assert('Class Nested 3') do
class A; end
class A::B; end
A::B.new.class.class == Class
end
-assert('BS Class Nested 4') do
+assert('Class Nested 4') do
class A; end
class A::B; end
class A::B::C; end
A::B::C == A::B::C
end
-assert('BS Class Nested 5') do
+assert('Class Nested 5') do
class A; end
class A::B; end
class A::B::C; end
A::B::C.class == Class
end
-assert('BS Class Nested 6') do
+assert('Class Nested 6') do
class A; end
class A::B; end
class A::B::C; end
A::B::C.new.class == A::B::C
end
-assert('BS Class Nested 7') do
+assert('Class Nested 7') do
class A; end
class A::B; end
class A::B2 < A::B; end
A::B2 == A::B2
end
-assert('BS Class Nested 8') do
+assert('Class Nested 8') do
class A; end
class A::B; end
class A::B2 < A::B; end
A::B2.class == Class
end
-assert('BS Class Colon 1') do
+assert('Class Colon 1') do
class A; end; A::C = 1; A::C == 1
end
-assert('BS Class Colon 2') do
+assert('Class Colon 2') do
class A; class ::C; end end; C == C
end
-assert('BS Class Colon 3') do
+assert('Class Colon 3') do
class A; class ::C; end end; C.class == Class
end
-assert('BS Class Dup 1') do
+assert('Class Dup 1') do
class C; end; C.dup.class == Class
end
-assert('BS Class Dup 2') do
+assert('Class Dup 2') do
module M; end; M.dup.class == Module
end
-
diff --git a/test/t/enumerable.rb b/test/t/enumerable.rb
new file mode 100644
index 000000000..de0bb5a34
--- /dev/null
+++ b/test/t/enumerable.rb
@@ -0,0 +1,103 @@
+##
+# Enumerable ISO Test
+
+assert('Enumerable', '15.3.2') do
+ Enumerable.class == Module
+end
+
+assert('Enumerable#all?', '15.3.2.2.1') do
+ [1,2,3].all? and not [1,false,3].all?
+end
+
+assert('Enumerable#any?', '15.3.2.2.2') do
+ [false,true,false].any? and not [false,false,false].any?
+end
+
+assert('Enumerable#collect', '15.3.2.2.3') do
+ [1,2,3].collect { |i| i + i } == [2,4,6]
+end
+
+assert('Enumerable#detect', '15.3.2.2.4') do
+ [1,2,3].detect() { true } and [1,2,3].detect("a") { false } == 'a'
+end
+
+assert('Array#each_with_index', '15.3.2.2.5') do
+ a = nil
+ b = nil
+
+ [1].each_with_index {|e,i| a = e; b = i}
+
+ a == 1 and b == 0
+end
+
+assert('Enumerable#entries', '15.3.2.2.6') do
+ [1].entries == [1]
+end
+
+assert('Enumerable#find', '15.3.2.2.7') do
+ [1,2,3].find() { true } and [1,2,3].find("a") { false } == 'a'
+end
+
+assert('Enumerable#find_all', '15.3.2.2.8') do
+ [1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0} == [2,4,6,8]
+end
+
+assert('Enumerable#grep', '15.3.2.2.9') do
+ [1,2,3,4,5,6,7,8,9].grep(4..6) == [4,5,6]
+end
+
+assert('Enumerable#include?', '15.3.2.2.10') do
+ [1,2,3,4,5,6,7,8,9].include?(5) and
+ not [1,2,3,4,5,6,7,8,9].include?(0)
+end
+
+assert('Enumerable#inject', '15.3.2.2.11') do
+ [1,2,3,4,5,6].inject() {|s, n| s + n} == 21 and
+ [1,2,3,4,5,6].inject(1) {|s, n| s + n} == 22
+end
+
+assert('Enumerable#map', '15.3.2.2.12') do
+ [1,2,3].map { |i| i + i } == [2,4,6]
+end
+
+assert('Enumerable#max', '15.3.2.2.13') do
+ a = ['aaa', 'bb', 'c']
+ a.max == 'c' and
+ a.max {|i1,i2| i1.length <=> i2.length} == 'aaa'
+end
+
+assert('Enumerable#min', '15.3.2.2.14') do
+ a = ['aaa', 'bb', 'c']
+ a.min == 'aaa' and
+ a.min {|i1,i2| i1.length <=> i2.length} == 'c'
+end
+
+assert('Enumerable#member?', '15.3.2.2.15') do
+ [1,2,3,4,5,6,7,8,9].member?(5) and
+ not [1,2,3,4,5,6,7,8,9].member?(0)
+end
+
+assert('Enumerable#partion', '15.3.2.2.16') do
+ [0,1,2,3,4,5,6,7,8,9].partition do |i|
+ i % 2 == 0
+ end == [[0,2,4,6,8], [1,3,5,7,9]]
+end
+
+assert('Enumerable#reject', '15.3.2.2.17') do
+ [0,1,2,3,4,5,6,7,8,9].reject do |i|
+ i % 2 == 0
+ end == [1,3,5,7,9]
+end
+
+assert('Enumerable#select', '15.3.2.2.18') do
+ [1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0} == [2,4,6,8]
+end
+
+assert('Enumerable#sort', '15.3.2.2.19') do
+ [7,3,1,2,6,4].sort == [1,2,3,4,6,7] and
+ [7,3,1,2,6,4].sort {|e1,e2| e2<=>e1} == [7,6,4,3,2,1]
+end
+
+assert('Enumerable#to_a', '15.3.2.2.20') do
+ [1].to_a == [1]
+end
diff --git a/test/t/bs_exception.rb b/test/t/exception.rb
index 6ab2cee2a..6b46314d0 100644
--- a/test/t/bs_exception.rb
+++ b/test/t/exception.rb
@@ -1,7 +1,45 @@
##
-# Bootstrap tests for Exceptions
+# Exception ISO Test
-assert('BS Exception 1') do
+assert('Exception', '15.2.22') do
+ Exception.class == Class
+end
+
+assert('Exception.exception', '15.2.22.4.1') do
+ e = Exception.exception('a')
+
+ e.class == Exception
+end
+
+assert('Exception#exception', '15.2.22.5.1') do
+ e1 = Exception.exception()
+ e2 = Exception.exception('b')
+
+ e1.class == Exception and e2.class == Exception
+end
+
+assert('Exception#message', '15.2.22.5.2') do
+ e = Exception.exception('a')
+
+ e.message == 'a'
+end
+
+assert('Exception#to_s', '15.2.22.5.3') do
+ e = Exception.exception('a')
+
+ e.to_s == 'a'
+end
+
+assert('Exception.exception', '15.2.22.4.1') do
+ e = Exception.exception()
+ e.initialize('a')
+
+ e.message == 'a'
+end
+
+# Not ISO specified
+
+assert('Exception 1') do
begin
1+1
ensure
@@ -9,7 +47,7 @@ assert('BS Exception 1') do
end == 2
end
-assert('BS Exception 2') do
+assert('Exception 2') do
begin
1+1
begin
@@ -22,7 +60,7 @@ assert('BS Exception 2') do
end == 4
end
-assert('BS Exception 3') do
+assert('Exception 3') do
begin
1+1
begin
@@ -40,7 +78,7 @@ assert('BS Exception 3') do
end == 4
end
-assert('BS Exception 4') do
+assert('Exception 4') do
a = nil
1.times{|e|
begin
@@ -51,7 +89,7 @@ assert('BS Exception 4') do
a == NilClass
end
-assert('BS Exception 5') do
+assert('Exception 5') do
$ans = []
def m
$!
@@ -69,7 +107,7 @@ assert('BS Exception 5') do
$ans == [nil]
end
-assert('BS Exception 6') do
+assert('Exception 6') do
$i = 0
def m
iter{
@@ -95,7 +133,7 @@ assert('BS Exception 6') do
$i == 7
end
-assert('BS Exception 7') do
+assert('Exception 7') do
$i = 0
def m
begin
@@ -115,7 +153,7 @@ assert('BS Exception 7') do
$i == 10
end
-assert('BS Exception 8') do
+assert('Exception 8') do
begin
1
rescue
@@ -125,7 +163,7 @@ assert('BS Exception 8') do
end == 3
end
-assert('BS Exception 9') do
+assert('Exception 9') do
begin
1+1
rescue
@@ -137,7 +175,7 @@ assert('BS Exception 9') do
end == 6
end
-assert('BS Exception 10') do
+assert('Exception 10') do
begin
1+1
begin
@@ -155,4 +193,3 @@ assert('BS Exception 10') do
7+7
end == 12
end
-
diff --git a/test/t/false.rb b/test/t/false.rb
new file mode 100644
index 000000000..c2db283c8
--- /dev/null
+++ b/test/t/false.rb
@@ -0,0 +1,26 @@
+##
+# FalseClass ISO Test
+
+assert('FalseClass', '15.2.6') do
+ FalseClass.class == Class
+end
+
+assert('FalseClass false', '15.2.6.1') do
+ not false
+end
+
+assert('FalseClass#&', '15.2.6.3.1') do
+ not FalseClass.new.&(true) and not FalseClass.new.&(false)
+end
+
+assert('FalseClass#^', '15.2.6.3.2') do
+ FalseClass.new.^(true) and not FalseClass.new.^(false)
+end
+
+assert('FalseClass#to_s', '15.2.6.3.3') do
+ FalseClass.new.to_s == 'false'
+end
+
+assert('FalseClass#|', '15.2.6.3.4') do
+ FalseClass.new.|(true) and not FalseClass.new.|(false)
+end
diff --git a/test/t/float.rb b/test/t/float.rb
index fd87bb04f..fc87a5b22 100644
--- a/test/t/float.rb
+++ b/test/t/float.rb
@@ -99,4 +99,3 @@ end
assert('Float#truncate', '15.2.9.3.15') do
3.123456789.truncate == 3
end
-
diff --git a/test/t/hash.rb b/test/t/hash.rb
index bb2ef1209..af662688a 100644
--- a/test/t/hash.rb
+++ b/test/t/hash.rb
@@ -224,4 +224,3 @@ assert('Hash#values', '15.2.13.4.28') do
a.values == ['abc_value']
end
-
diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb
new file mode 100644
index 000000000..d0cb81f32
--- /dev/null
+++ b/test/t/indexerror.rb
@@ -0,0 +1,6 @@
+##
+# IndexError ISO Test
+
+assert('IndexError', '15.2.33') do
+ IndexError.class == Class
+end
diff --git a/test/t/integer.rb b/test/t/integer.rb
index 5e73b41b5..8c112861a 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -168,4 +168,3 @@ assert('Integer#upto', '15.2.8.3.27') do
end
a == 6
end
-
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
new file mode 100644
index 000000000..cd1f2d99e
--- /dev/null
+++ b/test/t/kernel.rb
@@ -0,0 +1,124 @@
+##
+# Kernel ISO Test
+
+assert('Kernel', '15.3.1') do
+ Kernel.class == Module
+end
+
+assert('Kernel.block_given?', '15.3.1.2.2') do
+ Kernel.block_given? == false
+end
+
+assert('Kernel.global_variables', '15.3.1.2.4') do
+ Kernel.global_variables.class == Array
+end
+
+assert('Kernel.iterator?', '15.3.1.2.5') do
+ Kernel.iterator? == false
+end
+
+assert('Kernel.lambda', '15.3.1.2.6') do
+ l = Kernel.lambda do
+ true
+ end
+
+ l.call and l.class == Proc
+end
+
+assert('Kernel.local_variables', '15.3.1.2.7') do
+ Kernel.local_variables.class == Array
+end
+
+assert('Kernel.loop', '15.3.1.2.8') do
+ i = 0
+
+ Kernel.loop do
+ i += 1
+ break if i == 100
+ end
+
+ i == 100
+end
+
+assert('Kernel.p', '15.3.1.2.9') do
+ # TODO search for a way to test p to stdio
+ true
+end
+
+assert('Kernel.print', '15.3.1.2.10') do
+ # TODO search for a way to test print to stdio
+ true
+end
+
+assert('Kernel.puts', '15.3.1.2.11') do
+ # TODO search for a way to test puts to stdio
+ true
+end
+
+# TODO fails at the moment without arguments
+assert('Kernel.raise', '15.3.1.2.12') do
+ e_list = []
+
+ begin
+ raise RuntimeError.new
+ rescue => e
+ e_list << e
+ end
+
+ e_list[0].class == RuntimeError
+end
+
+assert('Kernel#hash', '15.3.1.2.15') do
+ hash == hash
+end
+
+assert('Kernel#local_variables', '15.3.1.2.28') do
+ local_variables.class == Array
+end
+
+assert('Kernel#loop', '15.3.1.2.29') do
+ i = 0
+
+ loop do
+ i += 1
+ break if i == 100
+ end
+
+ i == 100
+end
+
+assert('Kernel#methods', '15.3.1.2.31') do
+ methods.class == Array
+end
+
+assert('Kernel#nil?', '15.3.1.2.32') do
+ # TODO why is Kernel nil ????
+ nil? == true
+end
+
+assert('Kernel#private_methods', '15.3.1.2.36') do
+ private_methods.class == Array
+end
+
+assert('Kernel#protected_methods', '15.3.1.2.37') do
+ protected_methods.class == Array
+end
+
+assert('Kernel#public_methods', '15.3.1.2.38') do
+ public_methods.class == Array
+end
+
+assert('Kernel#respond_to?', '15.3.1.2.43') do
+ respond_to? :nil?
+end
+
+# TODO at the moment doesn't comply to ISO assert('Kernel#send', '15.3.1.2.44') do
+
+assert('Kernel#singleton_methods', '15.3.1.2.45') do
+ singleton_methods.class == Array
+end
+
+assert('Kernel#to_s', '15.3.1.2.46') do
+ # TODO looks strange..
+ to_s == ''
+end
diff --git a/test/t/literals.rb b/test/t/literals.rb
new file mode 100644
index 000000000..700c4c846
--- /dev/null
+++ b/test/t/literals.rb
@@ -0,0 +1,67 @@
+##
+# Literals ISO Test
+
+assert('Literals Numerical', '8.7.6.2') do
+ # signed and unsigned integer
+ 1 == 1 and -1 == -1 and +1 == +1 and
+ # signed and unsigned float
+ 1.0 == 1.0 and -1.0 == -1.0 and
+ # binary
+ 0b10000000 == 128 and 0B10000000 == 128
+ # octal
+ 0o10 == 8 and 0O10 == 8 and 0_10 == 8
+ # hex
+ 0xff == 255 and 0Xff == 255 and
+ # decimal
+ 0d999 == 999 and 0D999 == 999 and
+ # decimal seperator
+ 10_000_000 == 10000000 and 1_0 == 10 and
+ # integer with exponent
+ 1e1 == 10.0 and 1e-1 == 0.1 and 1e+1 == 10.0
+ # float with exponent
+ 1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0
+end
+
+assert('Literals Strings Single Quoted', '8.7.6.3.2') do
+ 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\'
+end
+
+assert('Literals Strings Double Quoted', '8.7.6.3.3') do
+ a = "abc"
+
+ "abc" == "abc" and "\"" == "\"" and "\\" == "\\" and
+ "#{a}" == "abc"
+end
+
+assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
+ a = %q{abc}
+ b = %q(abc)
+ c = %q[abc]
+ d = %q<abc>
+ e = %q/abc/
+ f = %q/ab\/c/
+
+ a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
+ e == 'abc' and f == 'ab/c'
+end
+
+assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do
+ a = %Q{abc}
+ b = %Q(abc)
+ c = %Q[abc]
+ d = %Q<abc>
+ e = %Q/abc/
+ f = %Q/ab\/c/
+ g = %Q{#{a}}
+
+ a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
+ e == 'abc' and f == 'ab/c' and g == 'abc'
+end
+
+# Not Implemented ATM assert('Literals Strings Here documents', '8.7.6.3.6') do
+
+# Not Implemented ATM assert('Literals Array', '8.7.6.4') do
+
+# Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do
+
+# Not Implemented ATM assert('Literals Symbol', '8.7.6.6') do
diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb
new file mode 100644
index 000000000..9d1df9594
--- /dev/null
+++ b/test/t/localjumperror.rb
@@ -0,0 +1,9 @@
+##
+# LocalJumpError ISO Test
+
+assert('LocalJumoError', '15.2.25') do
+ LocalJumpError.class == Class
+end
+
+# TODO 15.2.25.2.1 LocalJumpError#exit_value
+# TODO 15.2.25.2.2 LocalJumpError#reason
diff --git a/test/t/module.rb b/test/t/module.rb
new file mode 100644
index 000000000..854be75a5
--- /dev/null
+++ b/test/t/module.rb
@@ -0,0 +1,10 @@
+##
+# Module ISO Test
+
+assert('Module', '15.2.2') do
+ Module.class == Class
+end
+
+# TODO not implemented ATM assert('Module.constants', '15.2.2') do
+
+# TODO not implemented ATM assert('Module.nesting', '15.2.2') do
diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb
new file mode 100644
index 000000000..67451ecf8
--- /dev/null
+++ b/test/t/nameerror.rb
@@ -0,0 +1,14 @@
+##
+# NameError ISO Test
+
+assert('NameError', '15.2.31') do
+ NameError.class == Class
+end
+
+# TODO 15.2.31.2.1 NameError#name
+
+assert('NameError#initialize', '15.2.31.2.2') do
+ e = NameError.new.initialize('a')
+
+ e.class == NameError and e.message == 'a'
+end
diff --git a/test/t/nil.rb b/test/t/nil.rb
new file mode 100644
index 000000000..3188a9516
--- /dev/null
+++ b/test/t/nil.rb
@@ -0,0 +1,26 @@
+##
+# NilClass ISO Test
+
+assert('NilClass', '15.2.4') do
+ NilClass.class == Class
+end
+
+assert('NilClass#&', '15.2.4.3.1') do
+ not NilClass.new.& and not NilClass.new.&(nil)
+end
+
+assert('NilClass#^', '15.2.4.3.2') do
+ NilClass.new.^(true) and not NilClass.new.^(false)
+end
+
+assert('NilClass#|', '15.2.4.3.3') do
+ NilClass.new.|(true) and not NilClass.new.|(false)
+end
+
+assert('NilClass#nil?', '15.2.4.3.4') do
+ NilClass.new.nil?
+end
+
+assert('NilClass#to_s', '15.2.4.3.5') do
+ NilClass.new.to_s == ''
+end
diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb
new file mode 100644
index 000000000..9eb122158
--- /dev/null
+++ b/test/t/nomethoderror.rb
@@ -0,0 +1,13 @@
+##
+# NoMethodError ISO Test
+
+assert('NoMethodError', '15.2.32') do
+ e2 = nil
+ begin
+ doesNotExistAsAMethodNameForVerySure("")
+ rescue => e1
+ e2 = e1
+ end
+
+ NoMethodError.class == Class and e2.class == NoMethodError
+end
diff --git a/test/t/numeric.rb b/test/t/numeric.rb
index 40b5845c0..924889a0e 100644
--- a/test/t/numeric.rb
+++ b/test/t/numeric.rb
@@ -22,4 +22,3 @@ end
assert('Numeric#**') do
2.0**3 == 8.0
end
-
diff --git a/test/t/object.rb b/test/t/object.rb
new file mode 100644
index 000000000..96929031b
--- /dev/null
+++ b/test/t/object.rb
@@ -0,0 +1,6 @@
+##
+# Object ISO Test
+
+assert('Object', '15.2.1') do
+ Object.class == Class
+end
diff --git a/test/t/proc.rb b/test/t/proc.rb
new file mode 100644
index 000000000..6d98cb40c
--- /dev/null
+++ b/test/t/proc.rb
@@ -0,0 +1,44 @@
+##
+# Proc ISO Test
+
+assert('Proc', '15.2.17') do
+ Proc.class == Class
+end
+
+assert('Proc.new', '15.2.17.3.1') do
+ a = nil
+
+ begin
+ Proc.new
+ rescue => e
+ a = e
+ end
+
+ b = Proc.new {}
+
+ a.class == ArgumentError and b.class == Proc
+end
+
+assert('Proc#[]', '15.2.17.4.1') do
+ a = 0
+ b = Proc.new { a += 1 }
+ b.[]
+
+ a2 = 0
+ b2 = Proc.new { |i| a2 += i }
+ b2.[](5)
+
+ a == 1 and a2 == 5
+end
+
+assert('Proc#call', '15.2.17.4.3') do
+ a = 0
+ b = Proc.new { a += 1 }
+ b.call
+
+ a2 = 0
+ b2 = Proc.new { |i| a2 += i }
+ b2.call(5)
+
+ a == 1 and a2 == 5
+end
diff --git a/test/t/range.rb b/test/t/range.rb
index 42677e72e..05bac8779 100644
--- a/test/t/range.rb
+++ b/test/t/range.rb
@@ -62,4 +62,3 @@ assert('Range#member?', '15.2.14.4.11') do
a.member?(5) and not a.member?(20)
end
-
diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb
new file mode 100644
index 000000000..7edb5d2d9
--- /dev/null
+++ b/test/t/rangeerror.rb
@@ -0,0 +1,6 @@
+##
+# RangeError ISO Test
+
+assert('RangeError', '15.2.26') do
+ RangeError.class == Class
+end
diff --git a/test/t/regexperror.rb b/test/t/regexperror.rb
new file mode 100644
index 000000000..b8f8c2c1f
--- /dev/null
+++ b/test/t/regexperror.rb
@@ -0,0 +1,4 @@
+##
+# RegexpError ISO Test
+
+# TODO broken ATM assert('RegexpError', '15.2.27') do
diff --git a/test/t/runtimeerror.rb b/test/t/runtimeerror.rb
new file mode 100644
index 000000000..9157293cd
--- /dev/null
+++ b/test/t/runtimeerror.rb
@@ -0,0 +1,14 @@
+##
+# RuntimeError ISO Test
+
+assert('RuntimeError', '15.2.28') do
+ e2 = nil
+ begin
+ # this will cause an exception due to the wrong location
+ retry
+ rescue => e1
+ e2 = e1
+ end
+
+ RuntimeError.class == Class and e2.class == RuntimeError
+end
diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb
new file mode 100644
index 000000000..550c337c1
--- /dev/null
+++ b/test/t/standarderror.rb
@@ -0,0 +1,6 @@
+##
+# StandardError ISO Test
+
+assert('StandardError', '15.2.23') do
+ StandardError.class == Class
+end
diff --git a/test/t/string.rb b/test/t/string.rb
index 7fd48761c..76df18aaf 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -319,4 +319,3 @@ assert('String#upcase!', '15.2.10.5.43') do
a == 'ABC'
end
-
diff --git a/test/t/struct.rb b/test/t/struct.rb
new file mode 100644
index 000000000..c41319f8a
--- /dev/null
+++ b/test/t/struct.rb
@@ -0,0 +1,6 @@
+##
+# Struct ISO Test
+
+assert('Struct', '15.2.18') do
+ Struct.class == Class
+end
diff --git a/test/t/symbol.rb b/test/t/symbol.rb
index 325c8d990..e9c310971 100644
--- a/test/t/symbol.rb
+++ b/test/t/symbol.rb
@@ -20,4 +20,3 @@ end
assert('Symbol#to_sym', '15.2.11.3.4') do
:abc.to_sym == :abc
end
-
diff --git a/test/t/time.rb b/test/t/time.rb
index 9ad0e4aff..22fc2e7c3 100644
--- a/test/t/time.rb
+++ b/test/t/time.rb
@@ -71,4 +71,3 @@ end
assert('Time#new') do
Time.new.class == Time
end
-
diff --git a/test/t/true.rb b/test/t/true.rb
new file mode 100644
index 000000000..bb648a7cd
--- /dev/null
+++ b/test/t/true.rb
@@ -0,0 +1,26 @@
+##
+# TrueClass ISO Test
+
+assert('TrueClass', '15.2.5') do
+ TrueClass.class == Class
+end
+
+assert('TrueClass true', '15.2.5.1') do
+ true
+end
+
+assert('TrueClass#&', '15.2.5.3.1') do
+ TrueClass.new.&(true) and not TrueClass.new.&(false)
+end
+
+assert('TrueClass#^', '15.2.5.3.2') do
+ not TrueClass.new.^(true) and TrueClass.new.^(false)
+end
+
+assert('TrueClass#to_s', '15.2.5.3.3') do
+ TrueClass.new.to_s == 'true'
+end
+
+assert('TrueClass#|', '15.2.5.3.4') do
+ TrueClass.new.|(true) and TrueClass.new.|(false)
+end
diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb
new file mode 100644
index 000000000..c4434aa24
--- /dev/null
+++ b/test/t/typeerror.rb
@@ -0,0 +1,6 @@
+##
+# TypeError ISO Test
+
+assert('TypeError', '15.2.29') do
+ TypeError.class == Class
+end
diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile
index 4c6ab4e62..ba307227c 100644
--- a/tools/mirb/Makefile
+++ b/tools/mirb/Makefile
@@ -21,10 +21,6 @@ EXTS := $(EXT1)
LIBS = -lm
INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include
-# compiler, linker (gcc)
-CC = gcc
-LL = gcc
-YACC = bison
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
@@ -69,5 +65,5 @@ clean :
$(MAKE) clean -C ../../mrblib $(MAKE_FLAGS)
$(MAKE) clean -C ../mrbc $(MAKE_FLAGS)
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(EXE) $(OBJS)
- -rm -f $(OBJS:.o=.d)
+ -$(RM_F) $(EXE) $(OBJS)
+ -$(RM_F) $(OBJS:.o=.d)
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index 459923768..59e5046cb 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -162,7 +162,8 @@ main(void)
last_code_line[char_index] = '\0';
- if (strcmp(last_code_line, "quit") == 0) {
+ if ((strcmp(last_code_line, "quit") == 0) ||
+ (strcmp(last_code_line, "exit") == 0)) {
if (code_block_open) {
/* cancel the current block and reset */
code_block_open = FALSE;
diff --git a/tools/mrbc/CMakeLists.txt b/tools/mrbc/CMakeLists.txt
index 71a3a937d..043b7dc83 100644
--- a/tools/mrbc/CMakeLists.txt
+++ b/tools/mrbc/CMakeLists.txt
@@ -1,8 +1,8 @@
# build tools/mrbc executable
file(GLOB MRBC_SRC_C "*.c")
-add_executable(mrbc ${MRBC_SRC_C})
-target_link_libraries(mrbc mruby_static ${MRUBY_LIBS})
+add_executable(mrbc ${MRBC_SRC_C} $<TARGET_OBJECTS:mruby_object>)
+target_link_libraries(mrbc ${MRUBY_LIBS})
install(TARGETS mrbc RUNTIME DESTINATION bin)
diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile
index 9ecda4a59..99f5830e6 100644
--- a/tools/mrbc/Makefile
+++ b/tools/mrbc/Makefile
@@ -23,9 +23,6 @@ LIBS = -lm
INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include
# compiler, linker (gcc)
-CC = gcc
-LL = gcc
-YACC = bison
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
@@ -39,6 +36,7 @@ else
MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'
endif
+
##############################
# generic build targets, rules
@@ -63,5 +61,5 @@ $(LIBR) :
.PHONY : clean
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(EXE) $(OBJS)
- -rm -f $(OBJS:.o=.d)
+ -$(RM_F) $(EXE) $(OBJS)
+ -$(RM_F) $(OBJS:.o=.d)
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c
index e711b69cb..3553fe646 100644
--- a/tools/mrbc/mrbc.c
+++ b/tools/mrbc/mrbc.c
@@ -205,11 +205,6 @@ main(int argc, char **argv)
}
void
-mrb_init_ext(mrb_state *mrb)
-{
-}
-
-void
mrb_init_mrblib(mrb_state *mrb)
{
}
diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile
index 052aa93d6..0442bd422 100644
--- a/tools/mruby/Makefile
+++ b/tools/mruby/Makefile
@@ -26,9 +26,6 @@ LIBS = -lm
INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include
# compiler, linker (gcc)
-CC = gcc
-LL = gcc
-YACC = bison
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
@@ -73,5 +70,5 @@ clean :
$(MAKE) clean -C ../../mrblib $(MAKE_FLAGS)
$(MAKE) clean -C ../mrbc $(MAKE_FLAGS)
@echo "make: removing targets, objects and depend files of `pwd`"
- -rm -f $(EXE) $(OBJS)
- -rm -f $(OBJS:.o=.d)
+ -$(RM_F) $(EXE) $(OBJS)
+ -$(RM_F) $(OBJS:.o=.d)