From 44f2c59a612ec5d10e9bd74d7194524eb1c5c7e2 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 23 May 2012 12:17:42 -0400 Subject: Teach mirb another way to quit --- tools/mirb/mirb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3 From cd713836aa027e2be95d90eca4b9f78bbc5a5029 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 24 May 2012 01:20:33 +0900 Subject: simplify Array#join --- src/array.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) 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 -- cgit v1.2.3 From 14e28a8a4d6d13275564561ddca805e7ac3d7aa0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 24 May 2012 01:24:45 +0900 Subject: raise error on too many arguments --- src/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- cgit v1.2.3 From 6f00683e8729ad2a834de80ef312711d56a23d67 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 23 May 2012 11:09:07 -0400 Subject: Add `help` and `showconfig` targets to Makefile --- Makefile | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Makefile b/Makefile index fc22089a9..dbb2f173a 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,12 @@ else MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' endif +############################## +# internal variables + +export MSG_BEGIN = @for line in +export MSG_END = ; do echo "$$line"; done + ############################## # generic build targets, rules @@ -39,3 +45,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) -- cgit v1.2.3 From 105c11b7f6570292ad0fa15c8346c038f9d2f561 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 23 May 2012 12:01:08 -0400 Subject: Clean and DRY up the basic Makefiles --- Makefile | 13 ++++++++++--- mrblib/Makefile | 17 ++++++++--------- src/Makefile | 13 ++++--------- test/Makefile | 29 +++++++---------------------- tools/mirb/Makefile | 8 ++------ tools/mrbc/Makefile | 8 +++----- tools/mruby/Makefile | 7 ++----- 7 files changed, 36 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index dbb2f173a..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 @@ -23,6 +26,10 @@ endif 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 diff --git a/mrblib/Makefile b/mrblib/Makefile index d22c4509f..9a7e93596 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) $? > $@ # 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/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/test/Makefile b/test/Makefile index d46fa7a3e..b2df11486 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 @@ -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/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/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/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) -- cgit v1.2.3 From 2664eb5ca6aba1351dfb467cd5a3bb4c2d04c309 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 24 May 2012 05:33:29 +0800 Subject: Add ISO Test Cases for Kernel --- test/t/kernel.rb | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 test/t/kernel.rb diff --git a/test/t/kernel.rb b/test/t/kernel.rb new file mode 100644 index 000000000..eda07074b --- /dev/null +++ b/test/t/kernel.rb @@ -0,0 +1,125 @@ +## +# 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 + -- cgit v1.2.3 From c2a084dff98f234f8a9bc2215bfd406da87e15c9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 24 May 2012 09:24:11 +0900 Subject: wrong number of arguments for self-assignments --- src/codegen.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 087dd3165..5e2b7083f 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1234,25 +1234,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); -- cgit v1.2.3 From 34d9043c81e8db4d40f65334e025c36a1b7bc179 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 24 May 2012 09:35:42 +0900 Subject: parser->colum number was wrong --- src/parse.y | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/parse.y b/src/parse.y index 316e7309c..5924cd43c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2925,10 +2925,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 +2937,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 +2959,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])) { @@ -3400,7 +3400,7 @@ parse_qstring(parser_state *p, int term) switch (c) { case '\n': p->lineno++; - p->column = 0; + p->column = 1; continue; case '\\': @@ -3469,7 +3469,7 @@ parser_yylex(parser_state *p) /* fall through */ case '\n': p->lineno++; - p->column = 0; + p->column = 1; switch (p->lstate) { case EXPR_BEG: case EXPR_FNAME: @@ -4258,7 +4258,7 @@ parser_yylex(parser_state *p) c = nextc(p); if (c == '\n') { p->lineno++; - p->column = 0; + p->column = 1; space_seen = 1; goto retry; /* skip \\n */ } @@ -4694,6 +4694,7 @@ mrb_parser_new(mrb_state *mrb) p->capture_errors = 0; p->lineno = 1; + p->column = 1; #if defined(PARSER_TEST) || defined(PARSER_DEBUG) yydebug = 1; #endif @@ -4716,7 +4717,7 @@ mrb_parser_lineno(struct mrb_parser_state *p, int n) if (n <= 0) { return p->lineno; } - p->column = 0; + p->column = 1; p->lineno = n; return n; } -- cgit v1.2.3 From d9227aa41d8e626e7ff706f2d8cb94fea08658a9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 24 May 2012 21:10:23 +0900 Subject: remove ZeroDivisionError since mruby gives float for integer division --- src/error.c | 2 +- src/numeric.c | 26 -------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) 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/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; @@ -1042,24 +1034,6 @@ fix_to_f(mrb_state *mrb, mrb_value num) return mrb_float_value(val); } -/* - * Document-class: ZeroDivisionError - * - * Raised when attempting to divide an integer by 0. - * - * 42 / 0 - * - * raises the exception: - * - * 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 * -- cgit v1.2.3 From ea9bb1e38ffeec1ca3487031b5957d1f48c3f5ad Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 25 May 2012 13:48:54 +0900 Subject: adjust stack position before exiting mrb_run(); close #193 --- src/vm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; } } -- cgit v1.2.3 From 150b235fb650f15277e99080bc639bc4b60e08ba Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 25 May 2012 14:01:14 +0800 Subject: Add Tests for all Exception classes, for false, true, Proc, Module, nil and Object --- test/t/argumenterror.rb | 7 ++ test/t/bs_class.rb | 121 ----------------------------- test/t/bs_exception.rb | 158 -------------------------------------- test/t/class.rb | 126 ++++++++++++++++++++++++++++++ test/t/exception.rb | 195 +++++++++++++++++++++++++++++++++++++++++++++++ test/t/false.rb | 27 +++++++ test/t/indexerror.rb | 7 ++ test/t/localjumperror.rb | 10 +++ test/t/module.rb | 11 +++ test/t/nameerror.rb | 15 ++++ test/t/nil.rb | 27 +++++++ test/t/nomethoderror.rb | 14 ++++ test/t/object.rb | 7 ++ test/t/proc.rb | 45 +++++++++++ test/t/rangeerror.rb | 7 ++ test/t/regexperror.rb | 5 ++ test/t/runtimeerror.rb | 15 ++++ test/t/standarderror.rb | 7 ++ test/t/struct.rb | 7 ++ test/t/true.rb | 27 +++++++ test/t/typeerror.rb | 7 ++ 21 files changed, 566 insertions(+), 279 deletions(-) create mode 100644 test/t/argumenterror.rb delete mode 100644 test/t/bs_class.rb delete mode 100644 test/t/bs_exception.rb create mode 100644 test/t/class.rb create mode 100644 test/t/exception.rb create mode 100644 test/t/false.rb create mode 100644 test/t/indexerror.rb create mode 100644 test/t/localjumperror.rb create mode 100644 test/t/module.rb create mode 100644 test/t/nameerror.rb create mode 100644 test/t/nil.rb create mode 100644 test/t/nomethoderror.rb create mode 100644 test/t/object.rb create mode 100644 test/t/proc.rb create mode 100644 test/t/rangeerror.rb create mode 100644 test/t/regexperror.rb create mode 100644 test/t/runtimeerror.rb create mode 100644 test/t/standarderror.rb create mode 100644 test/t/struct.rb create mode 100644 test/t/true.rb create mode 100644 test/t/typeerror.rb diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb new file mode 100644 index 000000000..be1dec974 --- /dev/null +++ b/test/t/argumenterror.rb @@ -0,0 +1,7 @@ +## +# ArgumentError ISO Test + +assert('ArgumentError', '15.2.24') do + ArgumentError.class == Class +end + diff --git a/test/t/bs_class.rb b/test/t/bs_class.rb deleted file mode 100644 index d8bb63c05..000000000 --- a/test/t/bs_class.rb +++ /dev/null @@ -1,121 +0,0 @@ -## -# Bootstrap tests for Class - -assert('BS Class 1') do - class C; end - C.class == Class -end - -assert('BS Class 2') do - class C; end - C.new.class == C -end - -assert('BS Class 3') do - class C; end - C.new.class.class == Class -end - -assert('BS Class 4') do - class A; end - class C < A; end - C.class == Class -end - -assert('BS Class 5') do - class A; end - class C < A; end - C.new.class == C -end - -assert('BS Class 6') do - class A; end - class C < A; end - C.new.class.class == Class -end - -assert('BS Class Module 1') do - module M; end - M.class == Module -end - -assert('BS 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 - class A; end - class A::B; end - A::B == A::B -end - -assert('BS Class Nested 2') do - class A; end - class A::B; end - A::B.new.class == A::B -end - -assert('BS Class Nested 3') do - class A; end - class A::B; end - A::B.new.class.class == Class -end - -assert('BS 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 - class A; end - class A::B; end - class A::B::C; end - A::B::C.class == Class -end - -assert('BS 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 - class A; end - class A::B; end - class A::B2 < A::B; end - A::B2 == A::B2 -end - -assert('BS 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 - class A; end; A::C = 1; A::C == 1 -end - -assert('BS Class Colon 2') do - class A; class ::C; end end; C == C -end - -assert('BS Class Colon 3') do - class A; class ::C; end end; C.class == Class -end - -assert('BS Class Dup 1') do - class C; end; C.dup.class == Class -end - -assert('BS Class Dup 2') do - module M; end; M.dup.class == Module -end - diff --git a/test/t/bs_exception.rb b/test/t/bs_exception.rb deleted file mode 100644 index 6ab2cee2a..000000000 --- a/test/t/bs_exception.rb +++ /dev/null @@ -1,158 +0,0 @@ -## -# Bootstrap tests for Exceptions - -assert('BS Exception 1') do - begin - 1+1 - ensure - 2+2 - end == 2 -end - -assert('BS Exception 2') do - begin - 1+1 - begin - 2+2 - ensure - 3+3 - end - ensure - 4+4 - end == 4 -end - -assert('BS Exception 3') do - begin - 1+1 - begin - 2+2 - ensure - 3+3 - end - ensure - 4+4 - begin - 5+5 - ensure - 6+6 - end - end == 4 -end - -assert('BS Exception 4') do - a = nil - 1.times{|e| - begin - rescue => err - end - a = err.class - } - a == NilClass -end - -assert('BS Exception 5') do - $ans = [] - def m - $! - end - def m2 - 1.times{ - begin - return - ensure - $ans << m - end - } - end - m2 - $ans == [nil] -end - -assert('BS Exception 6') do - $i = 0 - def m - iter{ - begin - $i += 1 - begin - $i += 2 - break - ensure - - end - ensure - $i += 4 - end - $i = 0 - } - end - - def iter - yield - end - m - $i == 7 -end - -assert('BS Exception 7') do - $i = 0 - def m - begin - $i += 1 - begin - $i += 2 - return - ensure - $i += 3 - end - ensure - $i += 4 - end - p :end - end - m - $i == 10 -end - -assert('BS Exception 8') do - begin - 1 - rescue - 2 - else - 3 - end == 3 -end - -assert('BS Exception 9') do - begin - 1+1 - rescue - 2+2 - else - 3+3 - ensure - 4+4 - end == 6 -end - -assert('BS Exception 10') do - begin - 1+1 - begin - 2+2 - rescue - 3+3 - else - 4+4 - end - rescue - 5+5 - else - 6+6 - ensure - 7+7 - end == 12 -end - diff --git a/test/t/class.rb b/test/t/class.rb new file mode 100644 index 000000000..92f3df51d --- /dev/null +++ b/test/t/class.rb @@ -0,0 +1,126 @@ +## +# Class ISO Test + +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('Class 2') do + class C; end + C.new.class == C +end + +assert('Class 3') do + class C; end + C.new.class.class == Class +end + +assert('Class 4') do + class A; end + class C < A; end + C.class == Class +end + +assert('Class 5') do + class A; end + class C < A; end + C.new.class == C +end + +assert('Class 6') do + class A; end + class C < A; end + C.new.class.class == Class +end + +assert('Class Module 1') do + module M; end + M.class == Module +end + +assert('Class Module 2') do + module M; end + class C; include M; end + C.new.class == C +end + +# nested class +assert('Class Nested 1') do + class A; end + class A::B; end + A::B == A::B +end + +assert('Class Nested 2') do + class A; end + class A::B; end + A::B.new.class == A::B +end + +assert('Class Nested 3') do + class A; end + class A::B; end + A::B.new.class.class == Class +end + +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('Class Nested 5') do + class A; end + class A::B; end + class A::B::C; end + A::B::C.class == Class +end + +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('Class Nested 7') do + class A; end + class A::B; end + class A::B2 < A::B; end + A::B2 == A::B2 +end + +assert('Class Nested 8') do + class A; end + class A::B; end + class A::B2 < A::B; end + A::B2.class == Class +end + +assert('Class Colon 1') do + class A; end; A::C = 1; A::C == 1 +end + +assert('Class Colon 2') do + class A; class ::C; end end; C == C +end + +assert('Class Colon 3') do + class A; class ::C; end end; C.class == Class +end + +assert('Class Dup 1') do + class C; end; C.dup.class == Class +end + +assert('Class Dup 2') do + module M; end; M.dup.class == Module +end diff --git a/test/t/exception.rb b/test/t/exception.rb new file mode 100644 index 000000000..6b46314d0 --- /dev/null +++ b/test/t/exception.rb @@ -0,0 +1,195 @@ +## +# Exception ISO Test + +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 + 2+2 + end == 2 +end + +assert('Exception 2') do + begin + 1+1 + begin + 2+2 + ensure + 3+3 + end + ensure + 4+4 + end == 4 +end + +assert('Exception 3') do + begin + 1+1 + begin + 2+2 + ensure + 3+3 + end + ensure + 4+4 + begin + 5+5 + ensure + 6+6 + end + end == 4 +end + +assert('Exception 4') do + a = nil + 1.times{|e| + begin + rescue => err + end + a = err.class + } + a == NilClass +end + +assert('Exception 5') do + $ans = [] + def m + $! + end + def m2 + 1.times{ + begin + return + ensure + $ans << m + end + } + end + m2 + $ans == [nil] +end + +assert('Exception 6') do + $i = 0 + def m + iter{ + begin + $i += 1 + begin + $i += 2 + break + ensure + + end + ensure + $i += 4 + end + $i = 0 + } + end + + def iter + yield + end + m + $i == 7 +end + +assert('Exception 7') do + $i = 0 + def m + begin + $i += 1 + begin + $i += 2 + return + ensure + $i += 3 + end + ensure + $i += 4 + end + p :end + end + m + $i == 10 +end + +assert('Exception 8') do + begin + 1 + rescue + 2 + else + 3 + end == 3 +end + +assert('Exception 9') do + begin + 1+1 + rescue + 2+2 + else + 3+3 + ensure + 4+4 + end == 6 +end + +assert('Exception 10') do + begin + 1+1 + begin + 2+2 + rescue + 3+3 + else + 4+4 + end + rescue + 5+5 + else + 6+6 + ensure + 7+7 + end == 12 +end diff --git a/test/t/false.rb b/test/t/false.rb new file mode 100644 index 000000000..3fd885a7f --- /dev/null +++ b/test/t/false.rb @@ -0,0 +1,27 @@ +## +# 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/indexerror.rb b/test/t/indexerror.rb new file mode 100644 index 000000000..dcf9d283b --- /dev/null +++ b/test/t/indexerror.rb @@ -0,0 +1,7 @@ +## +# IndexError ISO Test + +assert('IndexError', '15.2.33') do + IndexError.class == Class +end + diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb new file mode 100644 index 000000000..132acd81e --- /dev/null +++ b/test/t/localjumperror.rb @@ -0,0 +1,10 @@ +## +# 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..f9efa553a --- /dev/null +++ b/test/t/module.rb @@ -0,0 +1,11 @@ +## +# 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..23158fce2 --- /dev/null +++ b/test/t/nameerror.rb @@ -0,0 +1,15 @@ +## +# 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..9a4855a62 --- /dev/null +++ b/test/t/nil.rb @@ -0,0 +1,27 @@ +## +# 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..4c4fb3fdf --- /dev/null +++ b/test/t/nomethoderror.rb @@ -0,0 +1,14 @@ +## +# 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/object.rb b/test/t/object.rb new file mode 100644 index 000000000..8d9938a48 --- /dev/null +++ b/test/t/object.rb @@ -0,0 +1,7 @@ +## +# 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..68d8ca8f6 --- /dev/null +++ b/test/t/proc.rb @@ -0,0 +1,45 @@ +## +# 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/rangeerror.rb b/test/t/rangeerror.rb new file mode 100644 index 000000000..da8e9bf88 --- /dev/null +++ b/test/t/rangeerror.rb @@ -0,0 +1,7 @@ +## +# 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..2ce2edd7f --- /dev/null +++ b/test/t/regexperror.rb @@ -0,0 +1,5 @@ +## +# 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..b410dd64f --- /dev/null +++ b/test/t/runtimeerror.rb @@ -0,0 +1,15 @@ +## +# 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..f6c63ac12 --- /dev/null +++ b/test/t/standarderror.rb @@ -0,0 +1,7 @@ +## +# StandardError ISO Test + +assert('StandardError', '15.2.23') do + StandardError.class == Class +end + diff --git a/test/t/struct.rb b/test/t/struct.rb new file mode 100644 index 000000000..04279d532 --- /dev/null +++ b/test/t/struct.rb @@ -0,0 +1,7 @@ +## +# Struct ISO Test + +assert('Struct', '15.2.18') do + Struct.class == Class +end + diff --git a/test/t/true.rb b/test/t/true.rb new file mode 100644 index 000000000..af4caeeec --- /dev/null +++ b/test/t/true.rb @@ -0,0 +1,27 @@ +## +# 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..12cf64e70 --- /dev/null +++ b/test/t/typeerror.rb @@ -0,0 +1,7 @@ +## +# TypeError ISO Test + +assert('TypeError', '15.2.29') do + TypeError.class == Class +end + -- cgit v1.2.3 From f6d539eabd305d40afe18639d2e19e0fb8dafc55 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 26 May 2012 11:18:16 +0900 Subject: clear arena_idx after exiting scope; close #195 --- src/codegen.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/codegen.c b/src/codegen.c index 5e2b7083f..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; @@ -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); } -- cgit v1.2.3 From 74fb270298225c392ec1b31a29f1ef10a36925c3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 27 May 2012 00:50:39 +0800 Subject: add Enumerable tests and identify data corruption with merge in Hash --- test/t/enumerable.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/t/enumerable.rb diff --git a/test/t/enumerable.rb b/test/t/enumerable.rb new file mode 100644 index 000000000..909531045 --- /dev/null +++ b/test/t/enumerable.rb @@ -0,0 +1,74 @@ +## +# 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 + -- cgit v1.2.3 From c1faad90ec8768b9364638da4bb56b47b87c6661 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 27 May 2012 04:34:47 +0800 Subject: Add documentation to Comparable --- mrblib/compar.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) 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 -- cgit v1.2.3 From 2f4ef95ae65490d180571b8563374c052cd2afd7 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 27 May 2012 23:05:43 +0900 Subject: Add 'ifndef/endif' to avoid conflict of 'TRUE' definition. --- src/parse.y | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parse.y b/src/parse.y index 5924cd43c..887ba0134 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; -- cgit v1.2.3 From c8201aa7ce4745e4321f594fdaa7d7de294d5fd1 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 27 May 2012 23:07:20 +0900 Subject: Add "ifndef/endif" to avoid conflict of "MIN" and "MAX" definition. --- src/regint.h | 5 +++++ 1 file changed, 5 insertions(+) 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) -- cgit v1.2.3 From 3be28e0b730aa4b241c761ea1eb0084076888796 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 27 May 2012 14:44:13 -0400 Subject: Remove unnecessary mrb_init_ext definition --- tools/mrbc/mrbc.c | 5 ----- 1 file changed, 5 deletions(-) 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 @@ -204,11 +204,6 @@ main(int argc, char **argv) return n; } -void -mrb_init_ext(mrb_state *mrb) -{ -} - void mrb_init_mrblib(mrb_state *mrb) { -- cgit v1.2.3 From c14e440897b2cf8c0769f00d9a14810b11ca9a99 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 08:50:10 +0900 Subject: column adjustment was wrong for pushed back characters --- src/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.y b/src/parse.y index 887ba0134..37a16c614 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3040,8 +3040,8 @@ nextc(parser_state *p) if (c == '\n') { // must understand heredoc } - p->column++; } + p->column++; return c; } -- cgit v1.2.3 From 6f4eda74015d30083d406d227f6675302484c9f1 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 27 May 2012 20:27:11 -0400 Subject: Simplify CMake mruby object library Also removes an unnecessary build target from the CMake generated build and project files. --- src/CMakeLists.txt | 1 - tools/mrbc/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) 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 $) # vim: ts=2 sts=2 sw=2 et 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_link_libraries(mrbc ${MRUBY_LIBS}) install(TARGETS mrbc RUNTIME DESTINATION bin) -- cgit v1.2.3 From c403458b977dea4fcab756cf1644ed69440b5e2c Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 27 May 2012 22:06:28 -0400 Subject: Remove unnecessary mrblib object build target --- mrblib/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 $ - $ ) set_target_properties(libmruby_static PROPERTIES OUTPUT_NAME mruby) -- cgit v1.2.3 From 661906c6824e992790c2558d9983eb606367f5cc Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 12:10:23 +0900 Subject: should compile all mrblib files --- mrblib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrblib/Makefile b/mrblib/Makefile index 9a7e93596..c7226ddcd 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -63,7 +63,7 @@ $(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y # merge mruby sources $(RLIB) : $(MRBS) - $(CAT) $? > $@ + $(CAT) $(MRBS) > $@ # clean up .PHONY : clean -- cgit v1.2.3 From 4bca3e5470820fb4498191619a2c6d324fe58def Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 12:21:28 +0900 Subject: should compile mrbtest if libmruby.a is modifie --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index b2df11486..170c1dac8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -51,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) -- cgit v1.2.3 From b275be253d8969128f2828a76cd9eaf2cb1c0eef Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 12:24:31 +0900 Subject: Hash#keys stop duping keys --- src/hash.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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); } } -- cgit v1.2.3 From cf8f429624e6c2e75cbd146e548dd1ca62930149 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 15:50:30 +0900 Subject: ignore error nodes (with node_begin initialization) --- src/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.y b/src/parse.y index 37a16c614..2d7003f62 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1008,7 +1008,7 @@ top_stmts : none } | error top_stmt { - $$ = $2; + $$ = new_begin(p, 0); } ; -- cgit v1.2.3 From dae33d3f660e598c95b7c9feb67f5716227607ce Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 28 May 2012 15:51:07 +0900 Subject: column position adjustment was wrong --- src/parse.y | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/parse.y b/src/parse.y index 2d7003f62..55c82c12d 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3405,7 +3405,7 @@ parse_qstring(parser_state *p, int term) switch (c) { case '\n': p->lineno++; - p->column = 1; + p->column = 0; continue; case '\\': @@ -3474,7 +3474,7 @@ parser_yylex(parser_state *p) /* fall through */ case '\n': p->lineno++; - p->column = 1; + p->column = 0; switch (p->lstate) { case EXPR_BEG: case EXPR_FNAME: @@ -3569,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: @@ -4263,7 +4263,7 @@ parser_yylex(parser_state *p) c = nextc(p); if (c == '\n') { p->lineno++; - p->column = 1; + p->column = 0; space_seen = 1; goto retry; /* skip \\n */ } @@ -4699,7 +4699,7 @@ mrb_parser_new(mrb_state *mrb) p->capture_errors = 0; p->lineno = 1; - p->column = 1; + p->column = 0; #if defined(PARSER_TEST) || defined(PARSER_DEBUG) yydebug = 1; #endif @@ -4722,7 +4722,7 @@ mrb_parser_lineno(struct mrb_parser_state *p, int n) if (n <= 0) { return p->lineno; } - p->column = 1; + p->column = 0; p->lineno = n; return n; } -- cgit v1.2.3 From 31e9705022d585d818a5c869f0f91e4d6b7c252e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 01:20:46 +0800 Subject: Add Test cases for Literals, Enumeration, Exceptions and clean line endings --- test/t/argumenterror.rb | 12 ++++++++++-- test/t/array.rb | 42 ++++++++++++++++++++++++++++++++++++++---- test/t/bs_block.rb | 1 - test/t/bs_literal.rb | 1 - test/t/enumerable.rb | 29 +++++++++++++++++++++++++++++ test/t/false.rb | 1 - test/t/float.rb | 1 - test/t/hash.rb | 1 - test/t/indexerror.rb | 1 - test/t/integer.rb | 1 - test/t/kernel.rb | 1 - test/t/localjumperror.rb | 1 - test/t/module.rb | 1 - test/t/nameerror.rb | 1 - test/t/nil.rb | 1 - test/t/nomethoderror.rb | 1 - test/t/numeric.rb | 1 - test/t/object.rb | 1 - test/t/proc.rb | 1 - test/t/range.rb | 1 - test/t/rangeerror.rb | 1 - test/t/regexperror.rb | 1 - test/t/runtimeerror.rb | 1 - test/t/standarderror.rb | 1 - test/t/string.rb | 1 - test/t/struct.rb | 1 - test/t/symbol.rb | 1 - test/t/time.rb | 1 - test/t/true.rb | 1 - test/t/typeerror.rb | 1 - 30 files changed, 77 insertions(+), 33 deletions(-) diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index be1dec974..ca998f8de 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -2,6 +2,14 @@ # ArgumentError ISO Test assert('ArgumentError', '15.2.24') do - ArgumentError.class == Class -end + 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/enumerable.rb b/test/t/enumerable.rb index 909531045..de0bb5a34 100644 --- a/test/t/enumerable.rb +++ b/test/t/enumerable.rb @@ -72,3 +72,32 @@ assert('Enumerable#min', '15.3.2.2.14') do 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/false.rb b/test/t/false.rb index 3fd885a7f..c2db283c8 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -24,4 +24,3 @@ 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 index dcf9d283b..d0cb81f32 100644 --- a/test/t/indexerror.rb +++ b/test/t/indexerror.rb @@ -4,4 +4,3 @@ 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 index eda07074b..cd1f2d99e 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -122,4 +122,3 @@ assert('Kernel#to_s', '15.3.1.2.46') do # TODO looks strange.. to_s == '' end - diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb index 132acd81e..9d1df9594 100644 --- a/test/t/localjumperror.rb +++ b/test/t/localjumperror.rb @@ -7,4 +7,3 @@ 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 index f9efa553a..854be75a5 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -8,4 +8,3 @@ 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 index 23158fce2..67451ecf8 100644 --- a/test/t/nameerror.rb +++ b/test/t/nameerror.rb @@ -12,4 +12,3 @@ assert('NameError#initialize', '15.2.31.2.2') do e.class == NameError and e.message == 'a' end - diff --git a/test/t/nil.rb b/test/t/nil.rb index 9a4855a62..3188a9516 100644 --- a/test/t/nil.rb +++ b/test/t/nil.rb @@ -24,4 +24,3 @@ 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 index 4c4fb3fdf..9eb122158 100644 --- a/test/t/nomethoderror.rb +++ b/test/t/nomethoderror.rb @@ -11,4 +11,3 @@ assert('NoMethodError', '15.2.32') do 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 index 8d9938a48..96929031b 100644 --- a/test/t/object.rb +++ b/test/t/object.rb @@ -4,4 +4,3 @@ assert('Object', '15.2.1') do Object.class == Class end - diff --git a/test/t/proc.rb b/test/t/proc.rb index 68d8ca8f6..6d98cb40c 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -42,4 +42,3 @@ assert('Proc#call', '15.2.17.4.3') do 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 index da8e9bf88..7edb5d2d9 100644 --- a/test/t/rangeerror.rb +++ b/test/t/rangeerror.rb @@ -4,4 +4,3 @@ assert('RangeError', '15.2.26') do RangeError.class == Class end - diff --git a/test/t/regexperror.rb b/test/t/regexperror.rb index 2ce2edd7f..b8f8c2c1f 100644 --- a/test/t/regexperror.rb +++ b/test/t/regexperror.rb @@ -2,4 +2,3 @@ # RegexpError ISO Test # TODO broken ATM assert('RegexpError', '15.2.27') do - diff --git a/test/t/runtimeerror.rb b/test/t/runtimeerror.rb index b410dd64f..9157293cd 100644 --- a/test/t/runtimeerror.rb +++ b/test/t/runtimeerror.rb @@ -12,4 +12,3 @@ assert('RuntimeError', '15.2.28') do RuntimeError.class == Class and e2.class == RuntimeError end - diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb index f6c63ac12..550c337c1 100644 --- a/test/t/standarderror.rb +++ b/test/t/standarderror.rb @@ -4,4 +4,3 @@ 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 index 04279d532..c41319f8a 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -4,4 +4,3 @@ 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 index af4caeeec..bb648a7cd 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -24,4 +24,3 @@ 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 index 12cf64e70..c4434aa24 100644 --- a/test/t/typeerror.rb +++ b/test/t/typeerror.rb @@ -4,4 +4,3 @@ assert('TypeError', '15.2.29') do TypeError.class == Class end - -- cgit v1.2.3 From b19575e5ac1e15c83797a0d8974bc4cc02b83fe6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 01:33:17 +0800 Subject: Forgot Literals file --- test/t/literals.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/t/literals.rb diff --git a/test/t/literals.rb b/test/t/literals.rb new file mode 100644 index 000000000..92f9bd755 --- /dev/null +++ b/test/t/literals.rb @@ -0,0 +1,49 @@ +## +# 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 +# creates segmentation fault for now +# '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 + +#creates segmentation fault for now +#assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do +# a = %q{abc} +# b = %q(abc) +# c = %q[abc] +# d = %q +# e = %/abc/ +# f = %/ab\/c/ + +# a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and +# e == 'abc' and f 'ab/c' +#end + -- cgit v1.2.3 From 61a47e344db34211c8d299660d6e0eabc4463d4b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 07:23:17 +0800 Subject: Raise SEGV by using String literal --- test/t/literals.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/t/literals.rb b/test/t/literals.rb index 92f9bd755..477e499a0 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -22,10 +22,9 @@ assert('Literals Numerical', '8.7.6.2') do 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 -# creates segmentation fault for now -# 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\' -#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" -- cgit v1.2.3 From 0dd5e0eba6806c8d16c1b38ba4e878455698d7e2 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 09:31:12 +0900 Subject: restore arena_idx after reading irep --- src/load.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/load.c b/src/load.c index af0e519bd..d3e492856 100644 --- a/src/load.c +++ b/src/load.c @@ -502,6 +502,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; + int ai = mrb->arena_idx; if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -539,6 +540,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) mrb->irep_len += nirep; error_exit: + mrb->arena_idx = ai; if (ret != MRB_DUMP_OK) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3 From 2d887c57ff809b20f1e094b584a58aa9eb071ac8 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 09:56:48 +0900 Subject: use API to restore arena_idx --- src/load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/load.c b/src/load.c index d3e492856..6894ac1ef 100644 --- a/src/load.c +++ b/src/load.c @@ -502,7 +502,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; - int ai = mrb->arena_idx; + int ai = mrb_gc_arena_save(mrb); if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -540,7 +540,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) mrb->irep_len += nirep; error_exit: - mrb->arena_idx = ai; + mrb_gc_arena_restore(mrb, ai); if (ret != MRB_DUMP_OK) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3 From c87ec7c33beb47c04bc00981fabfca371691ad97 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 10:29:01 +0900 Subject: compact arena before raising exception; also reserve a few slots to allocate exception objects --- src/gc.c | 20 ++++++++++++++++---- src/load.c | 1 - 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gc.c b/src/gc.c index 1d7a8627f..46bce642d 100644 --- a/src/gc.c +++ b/src/gc.c @@ -261,12 +261,24 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) } mrb->live++; + if (mrb->arena_idx > MRB_ARENA_SIZE - 4) { + struct RBasic **p, **q, **e; + + p = q = mrb->arena; + e = p + mrb->arena_idx; + while (p < e) { + if (is_white(*p)) + *q++ = *p; + p++; + } + if (p == q) { + /* arena overflow error */ + mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error"); + } + mrb->arena_idx = q - mrb->arena; + } mrb->arena[mrb->arena_idx++] = p; memset(p, 0, sizeof(RVALUE)); - if (mrb->arena_idx >= MRB_ARENA_SIZE) { - /* arena overflow error */ - mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error"); - } p->tt = ttype; p->c = cls; paint_partial_white(mrb, p); diff --git a/src/load.c b/src/load.c index 6894ac1ef..f2aff8cbe 100644 --- a/src/load.c +++ b/src/load.c @@ -538,7 +538,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin) } mrb->irep_len += nirep; - error_exit: mrb_gc_arena_restore(mrb, ai); if (ret != MRB_DUMP_OK) { -- cgit v1.2.3 From b92f302d59aa4fbbbf0dba3e6ea59cda4a27e367 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 13:52:59 +0800 Subject: SEGV by adding a new assert --- test/t/literals.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/t/literals.rb b/test/t/literals.rb index 477e499a0..1f755863a 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -33,16 +33,20 @@ assert('Literals Strings Double Quoted', '8.7.6.3.3') do "#{a}" == "abc" end -#creates segmentation fault for now -#assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do -# a = %q{abc} -# b = %q(abc) -# c = %q[abc] -# d = %q -# e = %/abc/ -# f = %/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 Non-Expanded', '8.7.6.3.4') do + a = %q{abc} + b = %q(abc) + c = %q[abc] + d = %q + 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 + # segv atm + true +end -- cgit v1.2.3 From 34dddc58e1cfc8091907406ce3df943cdf03bd4d Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 29 May 2012 16:15:43 +0900 Subject: Use default case in switch statement. --- src/sprintf.c | 13 ++++++++++--- src/string.c | 10 +++++++++- src/transcode.c | 15 ++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) 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; } } -- cgit v1.2.3 From b20388c004c11b338ee2b6e41d3b3dd641842162 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 22:05:06 +0900 Subject: make arena_idx restoration per irep, not per load --- src/load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/load.c b/src/load.c index f2aff8cbe..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); @@ -502,7 +504,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin) uint32_t len = 0; unsigned char *src; rite_binary_header bin_header; - int ai = mrb_gc_arena_save(mrb); if ((mrb == NULL) || (bin == NULL)) { return MRB_DUMP_INVALID_ARGUMENT; @@ -539,7 +540,6 @@ mrb_read_irep(mrb_state *mrb, const char *bin) mrb->irep_len += nirep; error_exit: - mrb_gc_arena_restore(mrb, ai); if (ret != MRB_DUMP_OK) { for (n=0,i=sirep; nirep[i]) { -- cgit v1.2.3 From 42b4060c9d75601b81b537323b969c69212a520e Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 22:14:32 +0900 Subject: force room in arena before raising arena overflow error --- src/gc.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/gc.c b/src/gc.c index 46bce642d..0ba6e3e76 100644 --- a/src/gc.c +++ b/src/gc.c @@ -261,21 +261,10 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) } mrb->live++; - if (mrb->arena_idx > MRB_ARENA_SIZE - 4) { - struct RBasic **p, **q, **e; - - p = q = mrb->arena; - e = p + mrb->arena_idx; - while (p < e) { - if (is_white(*p)) - *q++ = *p; - p++; - } - if (p == q) { - /* arena overflow error */ - mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error"); - } - mrb->arena_idx = q - mrb->arena; + if (mrb->arena_idx > MRB_ARENA_SIZE) { + /* 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)); -- cgit v1.2.3 From 84c5d35b9e95e1baaa1a28fcf23981068b075621 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 29 May 2012 23:00:45 +0900 Subject: class variable table intialization bug; close #206 --- src/variable.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3 From 82d600da24bb0866472126b4117c55dda773908d Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 29 May 2012 23:51:51 +0800 Subject: Add literal tests for currently working String literals and make notice about literals which yet need to be proper implementation --- test/t/literals.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/t/literals.rb b/test/t/literals.rb index 1f755863a..700c4c846 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -46,7 +46,22 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do end assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do - # segv atm - true + a = %Q{abc} + b = %Q(abc) + c = %Q[abc] + d = %Q + 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 -- cgit v1.2.3