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(-) (limited to 'src') 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(-) (limited to 'src') 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 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(-) (limited to 'src') 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 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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 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(+) (limited to 'src') 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 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(+) (limited to 'src') 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(+) (limited to 'src') 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 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(-) (limited to 'src') 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(-) (limited to 'src') 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 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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 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(+) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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