From 30b6507817a349cd1bdc5139533010b58faf9d14 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 3 Jun 2012 18:58:19 -0400 Subject: Refactor hardcoded PARSER_DUMP macro --- include/mrbconf.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index e90b685bb..5a54ebeef 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -21,6 +21,9 @@ typedef int mrb_int; typedef intptr_t mrb_sym; #define readint(p,base) strtol((p),NULL,(base)) +#undef PARSER_DUMP /* do not print out parser state */ +//#define PARSER_DUMP /* print out parser state */ + #undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */ //#define INCLUDE_ENCODING /* use UTF-8 encoding classes */ @@ -31,6 +34,10 @@ typedef intptr_t mrb_sym; # define INCLUDE_ENCODING /* Regexp depends Encoding */ #endif +#ifdef MRUBY_DEBUG_BUILD +# define PARSER_DUMP +#endif + #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -- cgit v1.2.3 From e1e4ceb3e42dab35038a52d89064ca6378a08c7d Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 12 Jun 2012 17:46:38 +0900 Subject: Make sprintf/format optional. --- include/mrbconf.h | 3 +++ src/kernel.c | 2 ++ src/sprintf.c | 5 +++++ 3 files changed, 10 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5a54ebeef..f2b23258e 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -34,6 +34,9 @@ typedef intptr_t mrb_sym; # define INCLUDE_ENCODING /* Regexp depends Encoding */ #endif +//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ +#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ + #ifdef MRUBY_DEBUG_BUILD # define PARSER_DUMP #endif diff --git a/src/kernel.c b/src/kernel.c index 15a4158a4..bc8e0059b 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1425,8 +1425,10 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ +#ifdef INCLUDE_KERNEL_SPRINTF mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ +#endif mrb_include_module(mrb, mrb->object_class, mrb->kernel_module); } diff --git a/src/sprintf.c b/src/sprintf.c index 296a7c73e..c7e7badc4 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -5,6 +5,9 @@ */ #include "mruby.h" + +#ifdef INCLUDE_KERNEL_SPRINTF + #include #include #include "encoding.h" @@ -1078,3 +1081,5 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf++ = c; *buf = '\0'; } + +#endif //INCLUDE_KERNEL_SPRINTF -- cgit v1.2.3 From 6919ca61edb2da9ea81217fdc355eef1208a6398 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 13 Jun 2012 23:16:53 +0900 Subject: stop using strtol (via readint) except in load.c; use custom readint_float --- include/mrbconf.h | 1 - src/codegen.c | 19 +++++++++++-------- src/load.c | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index f2b23258e..5848eee1a 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -19,7 +19,6 @@ typedef double mrb_float; typedef int mrb_int; typedef intptr_t mrb_sym; -#define readint(p,base) strtol((p),NULL,(base)) #undef PARSER_DUMP /* do not print out parser state */ //#define PARSER_DUMP /* print out parser state */ diff --git a/src/codegen.c b/src/codegen.c index 5f8d17314..63531eac1 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1575,16 +1575,18 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { char *p = (char*)tree->car; int base = (intptr_t)tree->cdr->car; - long i = readint(p, base); + mrb_float f; + mrb_int i; mrb_code co; - if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) { - mrb_float f = readint_float(s, p, base); + f = readint_float(s, p, base); + if (!FIXABLE(f)) { int off = new_lit(s, mrb_float_value(f)); genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); } else { + i = (mrb_int)f; if (i < MAXARG_sBx && i > -MAXARG_sBx) { co = MKOP_AsBx(OP_LOADI, cursp(), i); } @@ -1629,17 +1631,18 @@ codegen(codegen_scope *s, node *tree, int val) { char *p = (char*)tree->car; int base = (intptr_t)tree->cdr->car; - long i = readint(p, base); + mrb_float f; + mrb_int i; mrb_code co; - if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) { - mrb_float f = readint_float(s, p, base); + f = readint_float(s, p, base); + if (!FIXABLE(f)) { int off = new_lit(s, mrb_float_value(-f)); - + genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); } else { - i = -i; + i = (mrb_int)-f; if (i < MAXARG_sBx && i > -MAXARG_sBx) { co = MKOP_AsBx(OP_LOADI, cursp(), i); } diff --git a/src/load.c b/src/load.c index 1b607909c..053ec2d7e 100644 --- a/src/load.c +++ b/src/load.c @@ -413,7 +413,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 switch (tt) { //pool data case MRB_TT_FIXNUM: - fix_num = readint(buf, 10); + fix_num = strtol(buf, NULL, 10); irep->pool[i] = mrb_fixnum_value(fix_num); break; -- cgit v1.2.3 From 764a791f439bb843838239909d98b26ac90a9e02 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 14 Jun 2012 00:59:35 +0900 Subject: make Math module optional --- include/mrbconf.h | 13 ++++++++----- src/init.c | 2 ++ src/math.c | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5848eee1a..3744c1827 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -20,21 +20,24 @@ typedef double mrb_float; typedef int mrb_int; typedef intptr_t mrb_sym; -#undef PARSER_DUMP /* do not print out parser state */ //#define PARSER_DUMP /* print out parser state */ +#undef PARSER_DUMP /* do not print out parser state */ -#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */ //#define INCLUDE_ENCODING /* use UTF-8 encoding classes */ +#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */ -#undef INCLUDE_REGEXP /* not use regular expression classes */ //#define INCLUDE_REGEXP /* use regular expression classes */ +#undef INCLUDE_REGEXP /* not use regular expression classes */ #ifdef INCLUDE_REGEXP # define INCLUDE_ENCODING /* Regexp depends Encoding */ #endif -//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ -#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method. */ +#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ +//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ + +#define INCLUDE_MATH /* use (non ISO) Math module */ +//#undef INCLUDE_MATH /* not use (non ISO) Math module */ #ifdef MRUBY_DEBUG_BUILD # define PARSER_DUMP diff --git a/src/init.c b/src/init.c index 17ce24313..1f7d4d364 100644 --- a/src/init.c +++ b/src/init.c @@ -57,7 +57,9 @@ mrb_init_core(mrb_state *mrb) mrb_init_exception(mrb); mrb_init_print(mrb); mrb_init_time(mrb); +#ifdef INCLUDE_MATH mrb_init_math(mrb); +#endif mrb_init_mrblib(mrb); diff --git a/src/math.c b/src/math.c index 1de9c0d8f..3898146b6 100644 --- a/src/math.c +++ b/src/math.c @@ -5,6 +5,8 @@ */ #include "mruby.h" + +#ifdef INCLUDE_MATH #include #define domain_error(msg) \ @@ -679,3 +681,4 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "erf", math_erf, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, ARGS_REQ(1)); } +#endif /* INCLUDE_MATH */ -- cgit v1.2.3 From 8c838de4a83956fec100e2da8dc4f49c4ace6298 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 14:07:24 +0900 Subject: Time class made optinal --- include/mrbconf.h | 3 +++ src/init.c | 2 ++ src/time.c | 3 +++ 3 files changed, 8 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 3744c1827..f4f3ccaef 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -39,6 +39,9 @@ typedef intptr_t mrb_sym; #define INCLUDE_MATH /* use (non ISO) Math module */ //#undef INCLUDE_MATH /* not use (non ISO) Math module */ +#define INCLUDE_TIME /* use Time module */ +//#undef INCLUDE_TIME /* not use Time module */ + #ifdef MRUBY_DEBUG_BUILD # define PARSER_DUMP #endif diff --git a/src/init.c b/src/init.c index 1f7d4d364..13b074fd1 100644 --- a/src/init.c +++ b/src/init.c @@ -56,7 +56,9 @@ mrb_init_core(mrb_state *mrb) #endif mrb_init_exception(mrb); mrb_init_print(mrb); +#ifdef INCLUDE_TIME mrb_init_time(mrb); +#endif #ifdef INCLUDE_MATH mrb_init_math(mrb); #endif diff --git a/src/time.c b/src/time.c index 862ff57a9..1acde8ed9 100644 --- a/src/time.c +++ b/src/time.c @@ -6,6 +6,7 @@ #include "mruby.h" +#ifdef INCLUDE_TIME #include #include #include @@ -742,3 +743,5 @@ mrb_init_time(mrb_state *mrb) utc_offset(15.2.19.7.29) */ } +#endif + -- cgit v1.2.3 From 76f7aecff326666543d9bac31fe13e0cab8e05f4 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 15:34:49 +0900 Subject: use ENABLE/DISABLE instead of INCLUDE for configuration macro names --- include/mrbconf.h | 50 ++++++++++++++++---------------- include/mruby/class.h | 9 +----- src/dump.c | 6 ++-- src/gc.c | 8 +++--- src/init.c | 6 ++-- src/load.c | 4 +-- src/math.c | 4 +-- src/parse.y | 6 ---- src/re.c | 8 +++--- src/regcomp.c | 8 +++--- src/regerror.c | 4 +-- src/regexec.c | 4 +-- src/regparse.c | 8 +++--- src/string.c | 80 +++++++++++++++++++++++++-------------------------- src/struct.c | 2 +- src/time.c | 3 +- src/variable.c | 2 +- 17 files changed, 98 insertions(+), 114 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index f4f3ccaef..4b778e6de 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -8,8 +8,21 @@ #define MRUBYCONF_H #include + +/* configuration options: */ +/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ #undef MRB_USE_FLOAT +/* -DDISABLE_XXXX to change to drop the feature */ +#define DISABLE_REGEXP /* regular expression classes */ +#undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */ +#undef DISABLE_MATH /* Math functions */ +#undef DISABLE_TIME /* Time class */ + +#undef HAVE_UNISTD_H /* WINDOWS */ +#define HAVE_UNISTD_H /* LINUX */ +/* end of configuration */ + #ifdef MRB_USE_FLOAT typedef float mrb_float; #else @@ -20,34 +33,19 @@ typedef double mrb_float; typedef int mrb_int; typedef intptr_t mrb_sym; -//#define PARSER_DUMP /* print out parser state */ -#undef PARSER_DUMP /* do not print out parser state */ - -//#define INCLUDE_ENCODING /* use UTF-8 encoding classes */ -#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */ - -//#define INCLUDE_REGEXP /* use regular expression classes */ -#undef INCLUDE_REGEXP /* not use regular expression classes */ - -#ifdef INCLUDE_REGEXP -# define INCLUDE_ENCODING /* Regexp depends Encoding */ +/* define ENABLE_XXXX from DISABLE_XXX */ +#ifndef DISABLE_REGEXP +#define ENABLE_REGEXP #endif - -#define INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ -//#undef INCLUDE_KERNEL_SPRINTF /* not use Kernel.sprintf method */ - -#define INCLUDE_MATH /* use (non ISO) Math module */ -//#undef INCLUDE_MATH /* not use (non ISO) Math module */ - -#define INCLUDE_TIME /* use Time module */ -//#undef INCLUDE_TIME /* not use Time module */ - -#ifdef MRUBY_DEBUG_BUILD -# define PARSER_DUMP +#ifndef DISABLE_KERNEL_SPRINTF +#define ENABLE_KERNEL_SPRINTF +#endif +#ifndef DISABLE_MATH +#define ENABLE_MATH +#endif +#ifndef DISABLE_TIME +#define ENABLE_TIME #endif - -#undef HAVE_UNISTD_H /* WINDOWS */ -#define HAVE_UNISTD_H /* LINUX */ #ifndef FALSE # define FALSE 0 diff --git a/include/mruby/class.h b/include/mruby/class.h index 35dd0ec1d..2cc90310e 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -40,14 +40,7 @@ mrb_class(mrb_state *mrb, mrb_value v) case MRB_TT_FLOAT: return mrb->float_class; -#ifdef INCLUDE_REGEXP -// case MRB_TT_REGEX: -// return mrb->regex_class; -// case MRB_TT_MATCH: -// return mrb->match_class; -// case MRB_TT_DATA: -// return mrb->encode_class; -#else +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: case MRB_TT_MATCH: mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given", diff --git a/src/dump.c b/src/dump.c index 7b2199a02..daf2868f1 100644 --- a/src/dump.c +++ b/src/dump.c @@ -8,7 +8,7 @@ #include "mruby/dump.h" #include "mruby/string.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif #include "mruby/irep.h" @@ -237,7 +237,7 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type) nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); size += nlen; break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_reg_to_s(mrb, irep->pool[pool_no]); nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); @@ -365,7 +365,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) str_dump(RSTRING_PTR(str), char_buf, RSTRING_LEN(str), type); break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_reg_to_s(mrb, irep->pool[pool_no]); nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); diff --git a/src/gc.c b/src/gc.c index 1b4b3eed4..c07c9b13b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -71,7 +71,7 @@ */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif @@ -92,7 +92,7 @@ typedef struct { struct RRange range; struct RStruct structdata; struct RProc procdata; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP struct RMatch match; struct RRegexp regexp; #endif @@ -412,7 +412,7 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj) } break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_MATCH: { struct RMatch *m = (struct RMatch*)obj; @@ -611,7 +611,7 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj) children+=2; break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_MATCH: children+=2; break; diff --git a/src/init.c b/src/init.c index 351874b32..a515ee880 100644 --- a/src/init.c +++ b/src/init.c @@ -51,15 +51,15 @@ mrb_init_core(mrb_state *mrb) mrb_init_range(mrb); mrb_init_struct(mrb); mrb_init_gc(mrb); -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_init_regexp(mrb); #endif mrb_init_exception(mrb); mrb_init_print(mrb); -#ifdef INCLUDE_TIME +#ifdef ENABLE_TIME mrb_init_time(mrb); #endif -#ifdef INCLUDE_MATH +#ifdef ENABLE_MATH mrb_init_math(mrb); #endif diff --git a/src/load.c b/src/load.c index 1f853df00..d3766da9d 100644 --- a/src/load.c +++ b/src/load.c @@ -8,7 +8,7 @@ #include "mruby/dump.h" #include "mruby/string.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #endif #include "mruby/irep.h" @@ -418,7 +418,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 irep->pool[i] = mrb_str_new(mrb, buf, pdl); break; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP case MRB_TT_REGEX: str = mrb_str_new(mrb, buf, pdl); irep->pool[i] = mrb_reg_quote(mrb, str); diff --git a/src/math.c b/src/math.c index f3a2dc12c..cf9a20489 100644 --- a/src/math.c +++ b/src/math.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef INCLUDE_MATH +#ifdef ENABLE_MATH #include #define domain_error(msg) \ @@ -681,4 +681,4 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "erf", math_erf, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, ARGS_REQ(1)); } -#endif /* INCLUDE_MATH */ +#endif /* ENABLE_MATH */ diff --git a/src/parse.y b/src/parse.y index 5e44dd85a..b7eaaa4e4 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4776,9 +4776,6 @@ mrb_compile_file(mrb_state * mrb, FILE *f) if (!p) return -1; if (!p->tree) return -1; if (p->nerr) return -1; -#ifdef PARSER_DUMP - parser_dump(mrb, p->tree, 0); -#endif n = mrb_generate_code(mrb, p->tree); mrb_pool_close(p->pool); @@ -4795,9 +4792,6 @@ mrb_compile_nstring(mrb_state *mrb, char *s, size_t len) if (!p) return -1; if (!p->tree) return -1; if (p->nerr) return -1; -#ifdef PARSER_DUMP - parser_dump(mrb, p->tree, 0); -#endif n = mrb_generate_code(mrb, p->tree); mrb_pool_close(p->pool); diff --git a/src/re.c b/src/re.c index b4134c81c..17b4f3da7 100644 --- a/src/re.c +++ b/src/re.c @@ -13,7 +13,7 @@ #include "regint.h" #include "mruby/class.h" #include "error.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #define REGEX_CLASS (mrb_class_obj_get(mrb, "Regexp")) #define MATCH_CLASS (mrb_class_obj_get(mrb, "MatchData")) @@ -2318,7 +2318,7 @@ mrb_backref_set(mrb_state *mrb, mrb_value val) { vm_svar_set(mrb, 1, val); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING static inline long @@ -2421,7 +2421,7 @@ mrb_memsearch(mrb_state *mrb, const void *x0, int m, const void *y0, int n, mrb_ } #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_value mrb_reg_init_str(mrb_state *mrb, mrb_value re, mrb_value s, int options) { @@ -2469,7 +2469,7 @@ re_adjust_startpos(struct re_pattern_buffer *bufp, const char *string, int size, }*/ return startpos; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING static const unsigned char mbctab_ascii[] = { diff --git a/src/regcomp.c b/src/regcomp.c index 523124b26..b8c652999 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -30,7 +30,7 @@ #include "mruby.h" #include #include "regparse.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP OnigCaseFoldType OnigDefaultCaseFoldFlag = ONIGENC_CASE_FOLD_MIN; @@ -5628,7 +5628,7 @@ onig_end(void) THREAD_SYSTEM_END; return 0; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING extern int @@ -5653,7 +5653,7 @@ onig_is_in_code_range(const UChar* p, OnigCodePoint code) } #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP extern int onig_is_code_in_cc_len(int elen, OnigCodePoint code, CClassNode* cc) { @@ -6285,4 +6285,4 @@ print_tree(FILE* f, Node* node) print_indent_tree(f, node, 0); } #endif -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regerror.c b/src/regerror.c index 2ba879f78..df60b49cc 100644 --- a/src/regerror.c +++ b/src/regerror.c @@ -28,7 +28,7 @@ */ #include "mruby.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include #include "regint.h" #include /* for vsnprintf() */ @@ -372,4 +372,4 @@ onig_snprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc, pat, pat_end, fmt, args); va_end(args); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regexec.c b/src/regexec.c index 4d8950b73..d265cc803 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -28,7 +28,7 @@ */ #include "mruby.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include #include "regint.h" @@ -3754,4 +3754,4 @@ onig_copy_encoding(OnigEncoding to, OnigEncoding from) { *to = *from; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/regparse.c b/src/regparse.c index 509740ac3..f7bb23306 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -32,7 +32,7 @@ #include #include "regparse.h" #include -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #define WARN_BUFSIZE 256 @@ -298,7 +298,7 @@ strcat_capa_from_static(UChar* dest, UChar* dest_end, onig_strcpy(r + (dest_end - dest), src, src_end); return r; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifdef INCLUDE_ENCODING #ifdef USE_ST_LIBRARY @@ -393,7 +393,7 @@ onig_st_insert_strend(hash_table_type* table, const UChar* str_key, #endif /* USE_ST_LIBRARY */ #endif //INCLUDE_ENCODING -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #ifdef USE_NAMED_GROUP #define INIT_NAME_BACKREFS_ALLOC_NUM 8 @@ -5597,4 +5597,4 @@ onig_scan_env_set_error_string(ScanEnv* env, int ecode ARG_UNUSED, env->error = arg; env->error_end = arg_end; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP diff --git a/src/string.c b/src/string.c index a9e155c72..566c056cf 100644 --- a/src/string.c +++ b/src/string.c @@ -17,10 +17,10 @@ #include "mruby/variable.h" #include #include "re.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "regex.h" #include "st.h" -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP #ifndef FALSE #define FALSE 0 @@ -32,9 +32,9 @@ const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP static mrb_value str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2); static mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len); @@ -743,12 +743,12 @@ num_index: return str; case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP return mrb_str_subpat(mrb, str, indx, 0); //mrb_str_subpat(str, indx, INT2FIX(0)); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); return mrb_nil_value(); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP case MRB_TT_STRING: if (mrb_str_index(mrb, str, indx, 0) != -1) @@ -835,12 +835,12 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) argc = mrb_get_args(mrb, "o|o", &a1, &a2); if (argc == 2) { if (mrb_type(a1) == MRB_TT_REGEX) { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP return mrb_str_subpat(mrb, str, argv[0], mrb_fixnum(argv[1])); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); return mrb_nil_value(); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } return mrb_str_substr(mrb, str, mrb_fixnum(a1), mrb_fixnum(a2)); } @@ -1246,7 +1246,7 @@ mrb_str_buf_append(mrb_state *mrb, mrb_value str, mrb_value str2) return str; } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang) { @@ -1383,7 +1383,7 @@ mrb_str_gsub_bang(mrb_state *mrb, mrb_value self) str_modify(mrb, s); return str_gsub(mrb, s, 1); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str) @@ -1506,7 +1506,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) switch (mrb_type(sub)) { case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP if (pos > RSTRING_LEN(str)) return mrb_nil_value(); pos = mrb_str_offset(mrb, str, pos); @@ -1514,7 +1514,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) pos = mrb_str_sublen(mrb, str, pos); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP break; case MRB_TT_FIXNUM: { @@ -1668,7 +1668,7 @@ mrb_check_string_type(mrb_state *mrb, mrb_value str) return mrb_check_convert_type(mrb, str, MRB_TT_STRING, "String", "to_str"); } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) { @@ -1696,7 +1696,7 @@ get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) return mrb_reg_regcomp(mrb, pat); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.27 */ /* @@ -1711,7 +1711,7 @@ get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote) * 'hello'.match(/(.)\1/)[0] #=> "ll" * 'hello'.match('xx') #=> nil */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_match_m(mrb_state *mrb, mrb_value self) { @@ -1731,7 +1731,7 @@ mrb_str_match_m(mrb_state *mrb, mrb_value self) } return result; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* ---------------------------------- */ /* 15.2.10.5.29 */ @@ -1883,11 +1883,11 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) pos += len; if (pos < 0) { if (mrb_type(sub) == MRB_TT_REGEX) { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_backref_set(mrb, mrb_nil_value()); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } return mrb_nil_value(); } @@ -1904,7 +1904,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) switch (mrb_type(sub)) { case MRB_TT_REGEX: -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP pos = mrb_str_offset(mrb, str, pos); if (!RREGEXP(sub)->ptr || RREGEXP_SRC_LEN(sub)) { pos = mrb_reg_search(mrb, sub, str, pos, 1); @@ -1913,7 +1913,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) if (pos >= 0) return mrb_fixnum_value(pos); #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP break; case MRB_TT_FIXNUM: { @@ -1947,7 +1947,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) return mrb_nil_value(); } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) { @@ -1986,7 +1986,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) } return mrb_nil_value(); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.32 */ /* @@ -2019,7 +2019,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) * <> <> * rceu lowlr */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_scan(mrb_state *mrb, mrb_value str) { @@ -2053,7 +2053,7 @@ mrb_str_scan(mrb_state *mrb, mrb_value str) mrb_backref_set(mrb, match); return str; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP static const char isspacetable[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, @@ -2146,28 +2146,28 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) //fs_set: if (mrb_type(spat) == MRB_TT_STRING) { split_type = string; -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP if (RSTRING_LEN(spat) == 0) { /* Special case - split into chars */ spat = mrb_reg_regcomp(mrb, spat); split_type = regexp; } else { -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' '){ split_type = awk; } -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } else { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP spat = get_pat(mrb, spat, 1); split_type = regexp; #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } } @@ -2230,7 +2230,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) beg = ptr - temp; } else { -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP char *ptr = RSTRING_PTR(str); long len = RSTRING_LEN(str); long start = beg; @@ -2276,7 +2276,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) } #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP } if (RSTRING_LEN(str) > 0 && (lim >= 0 || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) @@ -2314,14 +2314,14 @@ mrb_block_given_p() * returning str, or nil if no substitutions were * performed. */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_sub_bang(mrb_state *mrb, mrb_value str) { str_modify(mrb, str); return mrb_nil_value(); } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP /* 15.2.10.5.36 */ @@ -2362,7 +2362,7 @@ mrb_str_sub_bang(mrb_state *mrb, mrb_value str) * #=> "Is /bin/bash your preferred shell?" */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP static mrb_value mrb_str_sub(mrb_state *mrb, mrb_value self) { @@ -2371,7 +2371,7 @@ mrb_str_sub(mrb_state *mrb, mrb_value self) mrb_str_sub_bang(mrb, str); return str; } -#endif //INCLUDE_REGEXP +#endif //ENABLE_REGEXP mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) @@ -3030,7 +3030,7 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "each_line", mrb_str_each_line, ARGS_REQ(1)); /* 15.2.10.5.15 */ mrb_define_method(mrb, s, "empty?", mrb_str_empty_p, ARGS_NONE()); /* 15.2.10.5.16 */ mrb_define_method(mrb, s, "eql?", mrb_str_eql, ARGS_REQ(1)); /* 15.2.10.5.17 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "gsub", mrb_str_gsub, ARGS_REQ(1)); /* 15.2.10.5.18 */ mrb_define_method(mrb, s, "gsub!", mrb_str_gsub_bang, ARGS_REQ(1)); /* 15.2.10.5.19 */ #endif @@ -3040,19 +3040,19 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "initialize", mrb_str_init, ARGS_REQ(1)); /* 15.2.10.5.23 */ mrb_define_method(mrb, s, "initialize_copy", mrb_str_replace, ARGS_REQ(1)); /* 15.2.10.5.24 */ mrb_define_method(mrb, s, "intern", mrb_str_intern, ARGS_NONE()); /* 15.2.10.5.25 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "match", mrb_str_match_m, ARGS_REQ(1)); /* 15.2.10.5.27 */ #endif mrb_define_method(mrb, s, "replace", mrb_str_replace, ARGS_REQ(1)); /* 15.2.10.5.28 */ mrb_define_method(mrb, s, "reverse", mrb_str_reverse, ARGS_NONE()); /* 15.2.10.5.29 */ mrb_define_method(mrb, s, "reverse!", mrb_str_reverse_bang, ARGS_NONE()); /* 15.2.10.5.30 */ mrb_define_method(mrb, s, "rindex", mrb_str_rindex_m, ARGS_ANY()); /* 15.2.10.5.31 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "scan", mrb_str_scan, ARGS_REQ(1)); /* 15.2.10.5.32 */ #endif mrb_define_method(mrb, s, "slice", mrb_str_aref_m, ARGS_ANY()); /* 15.2.10.5.34 */ mrb_define_method(mrb, s, "split", mrb_str_split_m, ARGS_ANY()); /* 15.2.10.5.35 */ -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP mrb_define_method(mrb, s, "sub", mrb_str_sub, ARGS_REQ(1)); /* 15.2.10.5.36 */ mrb_define_method(mrb, s, "sub!", mrb_str_sub_bang, ARGS_REQ(1)); /* 15.2.10.5.37 */ #endif diff --git a/src/struct.c b/src/struct.c index 2e2e0c10f..5d759776f 100644 --- a/src/struct.c +++ b/src/struct.c @@ -12,7 +12,7 @@ #include //#include "defines.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "encoding.h" #endif diff --git a/src/time.c b/src/time.c index 1acde8ed9..55060729b 100644 --- a/src/time.c +++ b/src/time.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef INCLUDE_TIME +#ifdef ENABLE_TIME #include #include #include @@ -744,4 +744,3 @@ mrb_init_time(mrb_state *mrb) */ } #endif - diff --git a/src/variable.c b/src/variable.c index 47029da28..b11143b02 100644 --- a/src/variable.c +++ b/src/variable.c @@ -14,7 +14,7 @@ #include "error.h" #include "mruby/array.h" -#ifdef INCLUDE_REGEXP +#ifdef ENABLE_REGEXP #include "re.h" #include "st.h" #endif -- cgit v1.2.3 From ede3049f33f8c6cdb703784619fb4143bfe3b441 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 17 Jun 2012 23:36:34 +0900 Subject: allow disabling Struct class --- include/mrbconf.h | 4 ++++ src/init.c | 2 ++ src/struct.c | 2 ++ 3 files changed, 8 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 4b778e6de..21b8fea18 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -18,6 +18,7 @@ #undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */ #undef DISABLE_MATH /* Math functions */ #undef DISABLE_TIME /* Time class */ +#undef DISABLE_STRUCT /* Struct class */ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ @@ -46,6 +47,9 @@ typedef intptr_t mrb_sym; #ifndef DISABLE_TIME #define ENABLE_TIME #endif +#ifndef DISABLE_STRUCT +#define ENABLE_STRUCT +#endif #ifndef FALSE # define FALSE 0 diff --git a/src/init.c b/src/init.c index a515ee880..e2ab62339 100644 --- a/src/init.c +++ b/src/init.c @@ -49,7 +49,9 @@ mrb_init_core(mrb_state *mrb) mrb_init_hash(mrb); mrb_init_numeric(mrb); mrb_init_range(mrb); +#ifdef ENABLE_STRUCT mrb_init_struct(mrb); +#endif mrb_init_gc(mrb); #ifdef ENABLE_REGEXP mrb_init_regexp(mrb); diff --git a/src/struct.c b/src/struct.c index 8e9804cbc..c0af85d0e 100644 --- a/src/struct.c +++ b/src/struct.c @@ -5,6 +5,7 @@ */ #include "mruby.h" +#ifdef ENABLE_STRUCT #include #include "error.h" #include "mruby/struct.h" @@ -793,3 +794,4 @@ mrb_init_struct(mrb_state *mrb) mrb_define_method(mrb, st, "eql?", mrb_struct_eql, ARGS_REQ(1)); /* 15.2.18.4.12(x) */ } +#endif /* ENABLE_STRUCT */ -- cgit v1.2.3 From 6410cdf3bffcbbb3d97f0153720922242c4f800f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 27 Jun 2012 01:13:21 +0900 Subject: do not undef config macros --- include/mrbconf.h | 12 ++++++------ src/kernel.c | 2 +- src/sprintf.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 21b8fea18..f496c53d9 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -15,10 +15,10 @@ /* -DDISABLE_XXXX to change to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ -#undef DISABLE_KERNEL_SPRINTF /* Kernel.sprintf method */ -#undef DISABLE_MATH /* Math functions */ -#undef DISABLE_TIME /* Time class */ -#undef DISABLE_STRUCT /* Struct class */ +//#define DISABLE_SPRINTF /* Kernel.sprintf method */ +//#define DISABLE_MATH /* Math functions */ +//#define DISABLE_TIME /* Time class */ +//#define DISABLE_STRUCT /* Struct class */ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ @@ -38,8 +38,8 @@ typedef intptr_t mrb_sym; #ifndef DISABLE_REGEXP #define ENABLE_REGEXP #endif -#ifndef DISABLE_KERNEL_SPRINTF -#define ENABLE_KERNEL_SPRINTF +#ifndef DISABLE_SPRINTF +#define ENABLE_SPRINTF #endif #ifndef DISABLE_MATH #define ENABLE_MATH diff --git a/src/kernel.c b/src/kernel.c index 5e17d4b5a..605b84124 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1168,7 +1168,7 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ -#ifdef ENABLE_KERNEL_SPRINTF +#ifdef ENABLE_SPRINTF mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ #endif diff --git a/src/sprintf.c b/src/sprintf.c index 86c3b66bc..68addef89 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -6,7 +6,7 @@ #include "mruby.h" -#ifdef ENABLE_KERNEL_SPRINTF +#ifdef ENABLE_SPRINTF #include #include @@ -1084,4 +1084,4 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf = '\0'; } -#endif /* ENABLE_KERNEL_SPRINTF */ +#endif /* ENABLE_SPRINTF */ -- cgit v1.2.3 From e9d56f4ccfcd71fa34be36f9457fd60e897036bd Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 28 Jun 2012 14:37:32 +0900 Subject: do not undef config macro MRB_USE_FLOAT --- include/mrbconf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index f496c53d9..4ed481e0b 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -11,7 +11,7 @@ /* configuration options: */ /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ -#undef MRB_USE_FLOAT +//#define MRB_USE_FLOAT /* -DDISABLE_XXXX to change to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ -- cgit v1.2.3 From 737eaea038af56794b8fdb5a66bb4138dbd446f6 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 13 Jul 2012 15:00:45 +0900 Subject: allow DISABLE/ENABLE_SATDIO --- include/mrbconf.h | 4 ++++ src/codegen.c | 8 ++++++++ src/object.c | 10 ++-------- src/parse.y | 7 ++++++- src/vm.c | 4 ++++ 5 files changed, 24 insertions(+), 9 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 4ed481e0b..5d307e66f 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -19,6 +19,7 @@ //#define DISABLE_MATH /* Math functions */ //#define DISABLE_TIME /* Time class */ //#define DISABLE_STRUCT /* Struct class */ +//#define DISABLE_STDIO /* use of stdio */ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ @@ -50,6 +51,9 @@ typedef intptr_t mrb_sym; #ifndef DISABLE_STRUCT #define ENABLE_STRUCT #endif +#ifndef DISABLE_STDIO +#define ENABLE_STDIO +#endif #ifndef FALSE # define FALSE 0 diff --git a/src/codegen.c b/src/codegen.c index 3ef52a0d4..6db09f310 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -94,7 +94,9 @@ codegen_error(codegen_scope *s, const char *message) s = s->prev; } mrb_pool_close(s->mpool); +#ifdef ENABLE_STDIO fprintf(stderr, "codegen error: %s\n", message); +#endif longjmp(s->jmp, 1); } @@ -270,7 +272,9 @@ dispatch(codegen_scope *s, int pc) case OP_ONERR: break; default: +#ifdef ENABLE_STDIO fprintf(stderr, "bug: dispatch on non JMP op\n"); +#endif scope_error(s); } s->iseq[pc] = MKOP_AsBx(c, GETARG_A(i), diff); @@ -739,7 +743,9 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val) break; default: +#ifdef ENABLE_STDIO printf("unknown lhs %d\n", type); +#endif break; } if (val) push(); @@ -2047,6 +2053,7 @@ loop_pop(codegen_scope *s, int val) static void codedump(mrb_state *mrb, int n) { +#ifdef ENABLE_STDIO mrb_irep *irep = mrb->irep[n]; int i; mrb_code c; @@ -2342,6 +2349,7 @@ codedump(mrb_state *mrb, int n) } } printf("\n"); +#endif } void diff --git a/src/object.c b/src/object.c index eb63c1293..29684b118 100644 --- a/src/object.c +++ b/src/object.c @@ -403,11 +403,6 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) struct RString *s; int xt; - /*if (x == Qundef) { - //mrb_bug("undef leaked to the Ruby space"); - printf ("undef leaked to the Ruby space\n"); - }*/ - xt = mrb_type(x); if ((xt != t) || (xt == MRB_TT_DATA)) { while (type->type < MRB_TT_MAXDEFINE) { @@ -431,12 +426,11 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) etype = mrb_obj_classname(mrb, x); } mrb_raise(mrb, E_TYPE_ERROR, "wrong argument type %s (expected %s)", - etype, type->name); + etype, type->name); } type++; } - /*mrb_bug("unknown type 0x%x", t);*/ - printf ("unknown type 0x%x (0x%x given)", t, mrb_type(x)); + mrb_raise(mrb, E_TYPE_ERROR, "unknown type 0x%x (0x%x given)", t, mrb_type(x)); } } diff --git a/src/parse.y b/src/parse.y index 13643f68e..8d626b5d8 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2964,12 +2964,14 @@ yyerror(parser_state *p, const char *s) int n; if (! p->capture_errors) { +#ifdef ENABLE_STDIO if (p->filename) { 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, s); } +#endif } else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) { n = strlen(s); @@ -2998,12 +3000,14 @@ yywarn(parser_state *p, const char *s) int n; if (! p->capture_errors) { +#ifdef ENABLE_STDIO if (p->filename) { 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, s); } +#endif } else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) { n = strlen(s); @@ -4943,6 +4947,7 @@ dump_recur(mrb_state *mrb, node *tree, int offset) void parser_dump(mrb_state *mrb, node *tree, int offset) { +#ifdef ENABLE_STDIO int n; if (!tree) return; @@ -5631,7 +5636,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset) printf("node type: %d (0x%x)\n", (int)n, (int)n); break; } - return; +#endif } #ifdef PARSER_TEST diff --git a/src/vm.c b/src/vm.c index 9ee6b9883..ef323f785 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1577,7 +1577,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_DEBUG) { /* A debug print R(A),R(B),R(C) */ +#ifdef ENABLE_STDIO printf("OP_DEBUG %d %d %d\n", GETARG_A(i), GETARG_B(i), GETARG_C(i)); +#else + abort(); +#endif NEXT; } -- cgit v1.2.3 From f146fd039706c426c738fc1186a86fa1fca89a4a Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 18 Jul 2012 15:47:57 +0900 Subject: MRB_FUNCALL_ARGC_MAX support. (refs comments in #324). --- include/mrbconf.h | 4 ++++ src/class.c | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5d307e66f..757192d89 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -23,6 +23,10 @@ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ + +#define MRB_FUNCALL_ARGC_MAX 16U /* Allocate arrays using auto variable. */ +//#undef MRB_FUNCALL_ARGC_MAX /* Allocate arrays using mrb_malloc if undefned. */ + /* end of configuration */ #ifdef MRB_USE_FLOAT diff --git a/src/class.c b/src/class.c index bf63198dd..762fa1591 100644 --- a/src/class.c +++ b/src/class.c @@ -7,7 +7,6 @@ #include "mruby.h" #include #include -#include #include "mruby/class.h" #include "mruby/proc.h" #include "mruby/string.h" @@ -866,27 +865,38 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) mrb_value mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) { - mrb_value *args; +#if defined(MRB_FUNCALL_ARGC_MAX) + mrb_value args[MRB_FUNCALL_ARGC_MAX]; +#else + mrb_value *args = NULL; +#endif mrb_value result; va_list ap; int i; if (argc != 0) { +#if !defined(MRB_FUNCALL_ARGC_MAX) args = mrb_malloc(mrb, sizeof(mrb_value) * argc); - assert(args != 0); +#else + if (argc > MRB_FUNCALL_ARGC_MAX) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", MRB_FUNCALL_ARGC_MAX); + } +#endif va_start(ap, argc); for (i = 0; i < argc; i++) { args[i] = va_arg(ap, mrb_value); } va_end(ap); - } else { - args = NULL; } + result = mrb_funcall_argv(mrb, self, name, argc, args); + +#if !defined(MRB_FUNCALL_ARGC_MAX) if (args != NULL) { mrb_free(mrb, args); } +#endif return result; } -- cgit v1.2.3 From 4b9ef5dabee09115edc15ecad05b335ecfaf598d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 19 Jul 2012 17:45:13 +0900 Subject: use no malloc in mrb_funcall; close #386 --- include/mrbconf.h | 5 ++--- src/class.c | 24 +++++------------------- 2 files changed, 7 insertions(+), 22 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 757192d89..cf8217b23 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -21,12 +21,11 @@ //#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STDIO /* use of stdio */ +//#define MRB_FUNCALL_ARGC_MAX 16 /* argv size in mrb_funcall */ + #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define MRB_FUNCALL_ARGC_MAX 16U /* Allocate arrays using auto variable. */ -//#undef MRB_FUNCALL_ARGC_MAX /* Allocate arrays using mrb_malloc if undefned. */ - /* end of configuration */ #ifdef MRB_USE_FLOAT diff --git a/src/class.c b/src/class.c index 762fa1591..38eb5ea1f 100644 --- a/src/class.c +++ b/src/class.c @@ -862,26 +862,21 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) return m; } +#ifndef MRB_FUNCALL_ARGC_MAX +#define MRB_FUNCALL_ARGC_MAX 16 +#endif + mrb_value mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) { -#if defined(MRB_FUNCALL_ARGC_MAX) mrb_value args[MRB_FUNCALL_ARGC_MAX]; -#else - mrb_value *args = NULL; -#endif - mrb_value result; va_list ap; int i; if (argc != 0) { -#if !defined(MRB_FUNCALL_ARGC_MAX) - args = mrb_malloc(mrb, sizeof(mrb_value) * argc); -#else if (argc > MRB_FUNCALL_ARGC_MAX) { mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", MRB_FUNCALL_ARGC_MAX); } -#endif va_start(ap, argc); for (i = 0; i < argc; i++) { @@ -889,16 +884,7 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) } va_end(ap); } - - result = mrb_funcall_argv(mrb, self, name, argc, args); - -#if !defined(MRB_FUNCALL_ARGC_MAX) - if (args != NULL) { - mrb_free(mrb, args); - } -#endif - - return result; + return mrb_funcall_argv(mrb, self, name, argc, args); } -- cgit v1.2.3 From ee899778c4f6cb0d201e50996e73639eabf98704 Mon Sep 17 00:00:00 2001 From: Max Anselm Date: Sun, 29 Jul 2012 19:44:49 -0400 Subject: Define __STDC_LIMIT_MACROS for INT32_MAX in C++ --- include/mrbconf.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index cf8217b23..b0a33aa43 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -7,6 +7,9 @@ #ifndef MRUBYCONF_H #define MRUBYCONF_H +#if defined(__cplusplus) +#define __STDC_LIMIT_MACROS +#endif #include /* configuration options: */ -- cgit v1.2.3 From eb34ad365b4fc70f174398b6898e14f3001aca69 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 09:45:37 +0900 Subject: fixed the comment English --- include/mrbconf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index b0a33aa43..45a5afabb 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -16,7 +16,7 @@ /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ //#define MRB_USE_FLOAT -/* -DDISABLE_XXXX to change to drop the feature */ +/* -DDISABLE_XXXX to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ //#define DISABLE_MATH /* Math functions */ -- cgit v1.2.3 From 446005620babeb0bf5ef8b8d2b6552c3c85aefd1 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 10:51:24 +0900 Subject: remove __STDC_LIMIT_MACROS for INT32_MAX --- include/mrbconf.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 45a5afabb..0113136d6 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -7,9 +7,6 @@ #ifndef MRUBYCONF_H #define MRUBYCONF_H -#if defined(__cplusplus) -#define __STDC_LIMIT_MACROS -#endif #include /* configuration options: */ -- cgit v1.2.3 From d91f475e5514248ad660172d35ccdf21872d63e7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 17:16:13 +0900 Subject: better mrbconf decsription --- include/mrbconf.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 0113136d6..c4cf23017 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -13,6 +13,12 @@ /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ //#define MRB_USE_FLOAT +/* initial size of khash table bucket; should be power of 2 (n >= 8) */ +//#define MRB_INITIAL_HASH_SIZE 32 + +/* argv max size in mrb_funcall */ +//#define MRB_FUNCALL_ARGC_MAX 16 + /* -DDISABLE_XXXX to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ @@ -21,8 +27,6 @@ //#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STDIO /* use of stdio */ -//#define MRB_FUNCALL_ARGC_MAX 16 /* argv size in mrb_funcall */ - #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -- cgit v1.2.3 From 0c55f7ecc3fa61fc3a1fd19c2632389377779305 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 17:18:32 +0900 Subject: add description of MRB_HEAP_PAGE_SIZE --- include/mrbconf.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index c4cf23017..f5f8de969 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -19,6 +19,9 @@ /* argv max size in mrb_funcall */ //#define MRB_FUNCALL_ARGC_MAX 16 +/* number of object per heap page */ +//#define MRB_HEAP_PAGE_SIZE 1024 + /* -DDISABLE_XXXX to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ -- cgit v1.2.3 From 515862cc015097144a003aa0f253af3a58dbab37 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 23:55:35 +0900 Subject: khash refactoring; no more MRB_KHASH_INITIAL_SIZE --- include/mrbconf.h | 6 +++--- include/mruby/khash.h | 32 +++++++++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index f5f8de969..955e6538b 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -13,15 +13,15 @@ /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ //#define MRB_USE_FLOAT -/* initial size of khash table bucket; should be power of 2 (n >= 8) */ -//#define MRB_INITIAL_HASH_SIZE 32 - /* argv max size in mrb_funcall */ //#define MRB_FUNCALL_ARGC_MAX 16 /* number of object per heap page */ //#define MRB_HEAP_PAGE_SIZE 1024 +/* default size of khash table bucket */ +//#define KHASH_DEFAULT_SIZE 32 + /* -DDISABLE_XXXX to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ diff --git a/include/mruby/khash.h b/include/mruby/khash.h index b28cd0702..16a35c3d5 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -17,9 +17,10 @@ extern "C" { typedef uint32_t khint_t; typedef khint_t khiter_t; -#ifndef MRB_INITIAL_HASH_SIZE -# define MRB_INITIAL_HASH_SIZE 32 +#ifndef KHASH_DEFAULT_SIZE +# define KHASH_DEFAULT_SIZE 32 #endif +#define KHASH_MIN_SIZE 8 #define UPPER_BOUND(x) ((x)>>2|(x>>1)) @@ -32,7 +33,15 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; #define __ac_isempty(e_flag, d_flag, i) (e_flag[(i)/8]&__m[(i)%8]) #define __ac_isdel(e_flag, d_flag, i) (d_flag[(i)/8]&__m[(i)%8]) #define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i)) - +#define khash_power2(v) do { \ + v--;\ + v |= v >> 1;\ + v |= v >> 2;\ + v |= v >> 4;\ + v |= v >> 8;\ + v |= v >> 16;\ + v++;\ +} while (0); /* declare struct kh_xxx and kh_xxx_funcs @@ -92,13 +101,16 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size) { \ kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \ + if (size < KHASH_MIN_SIZE) \ + size = KHASH_MIN_SIZE; \ + khash_power2(size); \ h->n_buckets = size; \ h->mrb = mrb; \ kh_alloc_##name(h); \ return h; \ } \ kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ - return kh_init_##name##_size(mrb, MRB_INITIAL_HASH_SIZE); \ + return kh_init_##name##_size(mrb, KHASH_DEFAULT_SIZE); \ } \ void kh_destroy_##name(kh_##name##_t *h) \ { \ @@ -130,15 +142,9 @@ static const uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; } \ void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ { \ - if (new_n_bucketse_flags; \ khkey_t *old_keys = h->keys; \ -- cgit v1.2.3 From d749ccfd3eb3f6020146ab287b0cea74f35e169f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 30 Jul 2012 23:56:34 +0900 Subject: add description of MRB_IV_INITIAL_SIZE --- include/mrbconf.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 955e6538b..3d1e1757d 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -19,6 +19,9 @@ /* number of object per heap page */ //#define MRB_HEAP_PAGE_SIZE 1024 +/* initial size for IV khash */ +//#define MRB_IV_INITIAL_SIZE 8 + /* default size of khash table bucket */ //#define KHASH_DEFAULT_SIZE 32 -- cgit v1.2.3 From 0cee3bb5317a220da7c123059a2c08daec288d30 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 31 Jul 2012 16:47:53 +0900 Subject: POOL_ALIGNMENT POOL_PAGE_SIZE : Configurable parameters. --- include/mrbconf.h | 6 ++++++ src/pool.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 3d1e1757d..20f49ec29 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -25,6 +25,12 @@ /* default size of khash table bucket */ //#define KHASH_DEFAULT_SIZE 32 +/* allocated memory address alignment */ +//#define POOL_ALIGNMENT 4 + +/* page size of memory pool */ +//#define POOL_PAGE_SIZE 16000 + /* -DDISABLE_XXXX to drop the feature */ #define DISABLE_REGEXP /* regular expression classes */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ diff --git a/src/pool.c b/src/pool.c index 36c6fa8eb..daa6d0f69 100644 --- a/src/pool.c +++ b/src/pool.c @@ -9,7 +9,7 @@ #include /* configuration section */ -/* allcated memory address should be multiple of POOL_ALLOC_ALIGN */ +/* allocated memory address should be multiple of POOL_ALIGNMENT */ /* or undef it if alignment does not matter */ #ifndef POOL_ALIGNMENT #define POOL_ALIGNMENT 4 -- cgit v1.2.3