From 210fcdc14b7531e2888e9ebb67d2c77b9f5302c0 Mon Sep 17 00:00:00 2001 From: snaba Date: Fri, 20 Apr 2012 18:04:11 +0900 Subject: fixed the compile error when it comments out the definition of INCLUDE_ENCODING and INCLUDE_REGEXP in mrbconf.h. --- src/variable.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/variable.c b/src/variable.c index 0bc1f0de1..870c96a6a 100644 --- a/src/variable.c +++ b/src/variable.c @@ -1,3 +1,4 @@ +#include #include "mruby.h" #include "mruby/class.h" #include "ritehash.h" -- cgit v1.2.3 From 356788607b13d5d27de1301cdc8b2b18597d955b Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 18:54:54 +0900 Subject: should not free mrb stack; a bug found&fixed by @miura1729 --- src/gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index f4186f6e3..ad5bcc7a8 100644 --- a/src/gc.c +++ b/src/gc.c @@ -401,8 +401,8 @@ obj_free(mrb_state *mrb, struct RBasic *obj) struct REnv *e = (struct REnv *)obj; if (e->cioff < 0) { - mrb_free(mrb, mrb->stack); - mrb->stack = 0; + mrb_free(mrb, e->stack); + e->stack = 0; } } break; -- cgit v1.2.3 From 754ab1b0c99cb7bc07fa45fa8bb4f4448dd50351 Mon Sep 17 00:00:00 2001 From: Matt Aimonetti Date: Fri, 20 Apr 2012 12:16:22 +0200 Subject: updated the English README to fix some minor grammatical and spelling mistakes --- README.md | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 14d323a3a..b9443603f 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # !!Notice!! - This is a preliminary release for internal team reviewing. - The URL and address discribed below are not available yet. - The official release will be announced later. Thanks. - Any suggestion of the modification are welcome, - but the response might be delayed. Sorry for that in advance. + This is a preliminary release for internal team review. + The URLs and addresses discribed below are not available yet. + The official release will be announced later. + Any suggestion for modification is welcome. + Delays in replies are to be expected. Sorry in advance. ## What's mruby -mruby is the light-weight implementation of the Ruby language complied to -the ISO standard to execute various environments. It can run in 'interpreter -form' or 'compile and execute on vm form' according to its module construction. +mruby is the lightweight implementation of the Ruby language complying to +the [ISO standard](http://www.ipa.go.jp/about/press/20120402_2.html). +mruby can run Ruby code in 'interpreter mode' or 'compile and execute it on a virtual machine' depending on how the developer's preference. -This achievement is due to the Regional Innovation Creation R&D Programs of +This achievement was sponsored by the Regional Innovation Creation R&D Programs of the Ministry of Economy, Trade and Industry of Japan. @@ -22,7 +22,7 @@ the Ministry of Economy, Trade and Industry of Japan. |FIXME: | + Simple Syntax | + *Normal* Object-Oriented features(ex. class, method calls) - | + *Advanced* Object-Oriented features(ex. Mix-in, Singleton-method) + | + *Advanced* Object-Oriented features(ex. Mixin, Singleton-method) | + Operator Overloading | + Exception Handling | + Iterators and Closures @@ -42,7 +42,7 @@ The mruby distribution files can be found in the following site: The trunk of the mruby source tree can be checked out with the following command: - $ git .... + $ git clone https://github.com/mruby/mruby.git There are some other branches under development. Try the following command and see the list of branches: @@ -52,44 +52,43 @@ command and see the list of branches: ## mruby home-page -(sorry, it's not launched yet. we're working on this) +mruby's website is not launched yet but we are actively working on it. -The URL of the mruby home-page is: +The URL of the mruby home-page will be: http://www.mruby.org/ ## Mailing list -There is a mailing list to talk about mruby. -To subscribe this list....[T.B.D.] +To subscribe the mruby mailing list....[T.B.D.] ## How to compile and install -See the file INSTALL. +See the INSTALL file. ## Copying -See the file COPYING. +See the COPYING file. ## About Contribution -Thank you for considering of contribution for mruby. -mruby has chosen a MIT License as comparatively loose condition, -to expect to apply into various environment such as embedded system. -However, the license requires to display copyright notice and license -sentenses, for example manual or so. Especially for the recent bigger -system, it is comlecated or very troublesome. -So, mruby has decided to display "mruby developers" as copyright name +Thank you for considering contributing to mruby. +mruby has chosen a MIT License due to its permissive license allowing +developer to target various environments such as embedded systems. +However, the license requires to display the copyright notice and license +information in manuals for instance. Doing so for big projects can be +complicated or troublesome. +This is why, mruby has decided to display "mruby developers" as copyright name to make it simple conventionally. In the future, mruby might ask you to distribute your new codes (that you will commit,) under MIT License as a member of -"mruby developers" with keeping copyright of you. -(We did not intend you to transfer or waive your copyright, - Actual copyright holder name, you, will be listed in AUTHORS file.) +"mruby developers" but contributors will keep their copyright. +(We did not intend for contributors to transfer or waive their copyrights, + Actual copyright holder name (contributors) will be listed in the AUTHORS file.) Please ask us if you want to distribute your code under other license or if your code is derived from GPL code. -- cgit v1.2.3 From 79077801ee36941bac122ab679879dd646ae0b7e Mon Sep 17 00:00:00 2001 From: Hidetaka Takano Date: Fri, 20 Apr 2012 21:13:51 +0900 Subject: Update: adding ISO Standard link and etc. --- README.ja.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.ja.md b/README.ja.md index 75cb10d84..0776226aa 100644 --- a/README.ja.md +++ b/README.ja.md @@ -3,12 +3,12 @@ 記述されているURLやメールアドレスは現在使用できません。 正式リリースは後日アナウンス予定です。 - 修正のご指摘は随時受け付けていますが、対応が遅くなるかもしれません。 + 修正のご指摘は随時受け付けていますが、対応が遅れる可能性があります。 予めご了承ください。 ## mrubyとは -mrubyはISO規格に準拠したRuby言語を様々な環境で動作可能となるように +mrubyは[ISO規格](http://www.ipa.go.jp/about/press/20120402_2.html)に準拠したRuby言語を様々な環境で動作可能となるように 軽量化したものです。モジュール構成によりインタプリタ実行形式や コンパイル&VM実行形式でも動作させることができます。 @@ -37,30 +37,30 @@ mrubyはISO規格に準拠したRuby言語を様々な環境で動作可能と ### Zipで -以下の場所においてあります. +以下の場所においてあります。 https://github.com/mruby/mruby/zipball/master ### GitHubで -開発先端のソースコードは次のコマンドで取得できます. +開発先端のソースコードは次のコマンドで取得できます。 $ git .... -他に開発中のブランチの一覧は次のコマンドで見られます. +他に開発中のブランチの一覧は次のコマンドで見られます。 $ git .... ## ホームページ -(まだ準備中です。ただいま鋭意製作中です。) +まだ準備中です。ただいま鋭意製作中です。 mrubyのホームページのURLは http://www.mruby.org/ -です. +になる予定です。 ## メーリングリスト @@ -112,4 +112,4 @@ AUTHORS ファイルを参照してください。 devel@mruby.org -まで. +まで。 -- cgit v1.2.3 From f8de58abcff75a6d537c1165f75e691175a9157b Mon Sep 17 00:00:00 2001 From: Santiago Rodriguez Date: Fri, 20 Apr 2012 07:53:51 -0500 Subject: Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9443603f..8fcbf44c7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # !!Notice!! This is a preliminary release for internal team review. - The URLs and addresses discribed below are not available yet. + The URLs and addresses described below are not available yet. The official release will be announced later. Any suggestion for modification is welcome. Delays in replies are to be expected. Sorry in advance. -- cgit v1.2.3 From 3d034f52ddb878dc44c086d72da475c78f29ff9b Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 20 Apr 2012 15:10:46 +0200 Subject: assign will break under C++ even when included with extern C --- include/mruby.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..0097c397b 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -134,7 +134,7 @@ static inline mrb_value mrb_obj_value(void *p) { mrb_value v; - struct RBasic *b = p; + struct RBasic *b = (struct RBasic*) p; v.tt = b->tt; v.value.p = p; -- cgit v1.2.3 From 5622c977f441a91a7482d5956df96e60d71d90f9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:25:04 +0900 Subject: remove dependency to SIZEOF_VOIDP --- include/mrbconf.h | 1 - src/Makefile | 2 +- src/numeric.c | 95 +---------------------------- src/re.c | 49 --------------- src/st.h | 6 -- src/string.c | 177 +++--------------------------------------------------- 6 files changed, 11 insertions(+), 319 deletions(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index d4802a5e7..81c19a121 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -27,7 +27,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -#define SIZEOF_VOIDP 4 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 diff --git a/src/Makefile b/src/Makefile index ea3681dce..abb6f4c4b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -40,7 +40,7 @@ YACC = bison DEBUG_MODE = 1 ifeq ($(DEBUG_MODE),1) -CFLAGS = -g +CFLAGS = -g -O3 else CFLAGS = -O3 endif diff --git a/src/numeric.c b/src/numeric.c index f79369d90..ef4588f76 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -97,25 +97,9 @@ # define SIZEOF_LONG_LONG SIZEOF___INT64 #endif -#if defined HAVE_UINTPTR_T && 0 typedef uintptr_t VALUE; typedef uintptr_t ID; -# define SIGNED_VALUE intptr_t -# define SIZEOF_VALUE SIZEOF_UINTPTR_T -#elif SIZEOF_LONG == SIZEOF_VOIDP -//typedef unsigned long VALUE; -//typedef unsigned long ID; -# define SIGNED_VALUE long long -# define SIZEOF_VALUE SIZEOF_LONG -#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP -typedef unsigned LONG_LONG VALUE; -typedef unsigned LONG_LONG ID; -# define SIGNED_VALUE LONG_LONG -# define LONG_LONG_VALUE 1 -# define SIZEOF_VALUE SIZEOF_LONG_LONG -#else -# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<---- -#endif +#define SIGNED_VALUE intptr_t #ifdef HAVE_INFINITY #elif BYTE_ORDER == LITTLE_ENDIAN @@ -980,80 +964,6 @@ mrb_num2ulong(mrb_state *mrb, mrb_value val) } } -#if SIZEOF_INT < SIZEOF_VALUE -void -mrb_out_of_int(mrb_state *mrb, SIGNED_VALUE num) -{ - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " too %s to convert to `int'", - num, num < 0 ? "small" : "big"); -} - -static void -check_int(SIGNED_VALUE num) -{ - if ((SIGNED_VALUE)(int)num != num) { - mrb_out_of_int(num); - } -} - -static void -check_uint(mrb_state *mrb, mrb_value num, mrb_value sign) -{ - static const mrb_value mask = ~(mrb_value)UINT_MAX; - - if (RTEST(sign)) { - /* minus */ - if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num); - } - else { - /* plus */ - if ((num & mask) != 0) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIuVALUE " too big to convert to `unsigned int'", num); - } -} - -long -mrb_num2int(mrb_value val) -{ - long num = mrb_num2long(mrb, val); - - check_int(num); - return num; -} - -long -mrb_fix2int(mrb_state *mrb, mrb_value val) -{ - long num = FIXNUM_P(val)?mrb_fixnum(val):mrb_num2long(mrb, val); - - check_int(num); - return num; -} - -unsigned long -mrb_num2uint(mrb_value val) -{ - unsigned long num = mrb_num2ulong(val); - - check_uint(num, mrb_funcall(mrb, val, "<", 1, mrb_fixnum_value(0))); - return num; -} - -unsigned long -mrb_fix2uint(mrb_state *mrb, mrb_value val) -{ - unsigned long num; - - if (!FIXNUM_P(val)) { - return mrb_num2uint(mrb, val); - } - num = FIX2ULONG(val); - - check_uint(num, mrb_funcall(mrb, val, "<", 1, mrb_fixnum_value(0))); - return num; -} -#else long mrb_num2int(mrb_state *mrb, mrb_value val) { @@ -1065,7 +975,6 @@ mrb_fix2int(mrb_value val) { return mrb_fixnum(val); } -#endif mrb_value mrb_num2fix(mrb_state *mrb, mrb_value val) @@ -1204,7 +1113,7 @@ mrb_value rb_fix2str(mrb_state *mrb, mrb_value x, int base) { extern const char ruby_digitmap[]; - char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf; + char buf[sizeof(mrb_int)*CHAR_BIT + 2], *b = buf + sizeof buf; long val = mrb_fixnum(x); int neg = 0; diff --git a/src/re.c b/src/re.c index 645af6ba6..0cdf58e7a 100644 --- a/src/re.c +++ b/src/re.c @@ -1773,11 +1773,7 @@ static int pair_byte_cmp(const void *pair1, const void *pair2) { long diff = ((pair_t*)pair1)->byte_pos - ((pair_t*)pair2)->byte_pos; -#if SIZEOF_LONG > SIZEOF_INT return diff ? diff > 0 ? 1 : -1 : 0; -#else - return (int)diff; -#endif } static void @@ -2958,48 +2954,6 @@ mrb_backref_set(mrb_state *mrb, mrb_value val) #endif //INCLUDE_REGEXP #ifdef INCLUDE_ENCODING -static inline long -mrb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n) -{ - const unsigned char *x = xs, *xe = xs + m; - const unsigned char *y = ys, *ye = ys + n; -#define SIZEOF_VOIDP 4 -#define SIZEOF_LONG 4 - -#ifndef VALUE_MAX -# if SIZEOF_VALUE == 8 -# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL -# elif SIZEOF_VALUE == 4 -# define VALUE_MAX 0xFFFFFFFFUL -# elif SIZEOF_LONG == SIZEOF_VOIDP -# define SIZEOF_VALUE 4 -# define VALUE_MAX 0xFFFFFFFFUL -# endif -#endif - int hx, hy, mask = VALUE_MAX >> ((SIZEOF_VALUE - m) * CHAR_BIT); - - if (m > SIZEOF_VALUE) - mrb_bug("!!too long pattern string!!"); - - /* Prepare hash value */ - for (hx = *x++, hy = *y++; x < xe; ++x, ++y) { - hx <<= CHAR_BIT; - hy <<= CHAR_BIT; - hx |= *x; - hy |= *y; - } - /* Searching */ - while (hx != hy) { - if (y == ye) - return -1; - hy <<= CHAR_BIT; - hy |= *y; - hy &= mask; - y++; - } - return y - ys - m; -} - static inline long mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long n) { @@ -3094,9 +3048,6 @@ mrb_memsearch(mrb_state *mrb, const void *x0, int m, const void *y0, int n, mrb_ } return -1; } - else if (m <= SIZEOF_VALUE) { - return mrb_memsearch_ss(x0, m, y0, n); - } else if (enc == mrb_utf8_encoding(mrb)) { return mrb_memsearch_qs_utf8(x0, m, y0, n); } diff --git a/src/st.h b/src/st.h index 7324e8da7..d7ec7eb38 100644 --- a/src/st.h +++ b/src/st.h @@ -64,12 +64,6 @@ struct st_table_entry { st_table_entry *fore, *back; }; -#ifndef SIZEOF_VOIDP -#define SIZEOF_VOIDP 4 -#endif - -#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP - struct st_hash_type { int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */ st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */ diff --git a/src/string.c b/src/string.c index da52172f7..9556f93e8 100644 --- a/src/string.c +++ b/src/string.c @@ -211,38 +211,12 @@ single_byte_optimizable(mrb_state *mrb, mrb_value str) static inline const char * search_nonascii(const char *p, const char *e) { -#if SIZEOF_VALUE == 8 -# define NONASCII_MASK 0x8080808080808080ULL -#elif SIZEOF_VALUE == 4 -# define NONASCII_MASK 0x80808080UL -#endif -#ifdef NONASCII_MASK - if ((int)sizeof(intptr_t) * 2 < e - p) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(intptr_t) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - while (p < (const char *)s) { - if (!ISASCII(*p)) - return p; - p++; - } - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (s < t) { - if (*s & (intptr_t)NONASCII_MASK) { - t = s; - break; - } - s++; - } - p = (const char *)t; - } -#endif - while (p < e) { - if (!ISASCII(*p)) - return p; - p++; - } - return NULL; + while (p < e) { + if (!ISASCII(*p)) + return p; + p++; + } + return NULL; } #endif //INCLUDE_ENCODING @@ -1167,63 +1141,6 @@ mrb_str_match(mrb_state *mrb, mrb_value self/* x */) } } /* ---------------------------------- */ -#ifdef INCLUDE_ENCODING -#ifdef NONASCII_MASK -#define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80) -static inline int -count_utf8_lead_bytes_with_word(const intptr_t *s) -{ - int d = *s; - d |= ~(d>>1); - d >>= 6; - d &= NONASCII_MASK >> 7; - d += (d>>8); - d += (d>>16); -#if SIZEOF_VALUE == 8 - d += (d>>32); -#endif - return (d&0xF); -} -#endif - -#ifdef NONASCII_MASK -static char * -str_utf8_nth(const char *p, const char *e, long nth) -{ - if ((int)SIZEOF_VALUE < e - p && (int)SIZEOF_VALUE * 2 < nth) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(int) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (p < (const char *)s) { - if (is_utf8_lead_byte(*p)) nth--; - p++; - } - do { - nth -= count_utf8_lead_bytes_with_word(s); - s++; - } while (s < t && (int)sizeof(intptr_t) <= nth); - p = (char *)s; - } - while (p < e) { - if (is_utf8_lead_byte(*p)) { - if (nth == 0) break; - nth--; - } - p++; - } - return (char *)p; -} - -static long -str_utf8_offset(const char *p, const char *e, long nth) -{ - const char *pp = str_utf8_nth(p, e, nth); - return pp - p; -} -#endif -#endif //INCLUDE_ENCODING - mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len) { @@ -1283,13 +1200,6 @@ mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len) if (len == 0) { p = 0; } -#ifdef NONASCII_MASK - else if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID && - enc == mrb_utf8_encoding(mrb)) { - p = str_utf8_nth(s, e, beg); - len = str_utf8_offset(p, e, len); - } -#endif else if (mrb_enc_mbmaxlen(enc) == mrb_enc_mbminlen(enc)) { int char_sz = mrb_enc_mbmaxlen(enc); @@ -1405,46 +1315,6 @@ mrb_enc_strlen_cr(mrb_state *mrb, const char *p, const char *e, mrb_encoding *en /* --- 1-8-7parse.c --< */ #ifndef INCLUDE_ENCODING -static inline long -mrb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n) -{ - const unsigned char *x = xs, *xe = xs + m; - const unsigned char *y = ys, *ye = ys + n; -//2011/06/30 #define SIZEOF_VALUE 4 -#ifndef VALUE_MAX -# if SIZEOF_VALUE == 8 -# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL -# elif SIZEOF_VALUE == 4 -# define VALUE_MAX 0xFFFFFFFFUL -# elif SIZEOF_LONG == SIZEOF_VOIDP -# define SIZEOF_VALUE 4 -# define VALUE_MAX 0xFFFFFFFFUL -# endif -#endif - int hx, hy, mask = VALUE_MAX >> ((SIZEOF_VALUE - m) * CHAR_BIT); - - if (m > SIZEOF_VALUE) - mrb_bug("!!too long pattern string!!"); - - /* Prepare hash value */ - for (hx = *x++, hy = *y++; x < xe; ++x, ++y) { - hx <<= CHAR_BIT; - hy <<= CHAR_BIT; - hx |= *x; - hy |= *y; - } - /* Searching */ - while (hx != hy) { - if (y == ye) - return -1; - hy <<= CHAR_BIT; - hy |= *y; - hy &= mask; - y++; - } - return y - ys - m; -} - static inline long mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long n) { @@ -1464,6 +1334,7 @@ mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long } return -1; } + int mrb_memsearch(const void *x0, int m, const void *y0, int n) { @@ -1484,12 +1355,7 @@ mrb_memsearch(const void *x0, int m, const void *y0, int n) } return -1; } - else if (m <= SIZEOF_VALUE) { - return mrb_memsearch_ss(x0, m, y0, n); - } - else { - return mrb_memsearch_qs(x0, m, y0, n); - } + return mrb_memsearch_qs(x0, m, y0, n); } #endif //INCLUDE_ENCODING @@ -1507,33 +1373,6 @@ str_strlen(mrb_state *mrb, mrb_value str, mrb_encoding *enc) p = RSTRING_PTR(str); e = RSTRING_END(str); cr = ENC_CODERANGE(str); -#ifdef NONASCII_MASK - if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID && - enc == mrb_utf8_encoding(mrb)) { - - int len = 0; - if ((int)sizeof(intptr_t) * 2 < e - p) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(int) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (p < (const char *)s) { - if (is_utf8_lead_byte(*p)) len++; - p++; - } - while (s < t) { - len += count_utf8_lead_bytes_with_word(s); - s++; - } - p = (const char *)s; - } - while (p < e) { - if (is_utf8_lead_byte(*p)) len++; - p++; - } - return (long)len; - } -#endif n = mrb_enc_strlen_cr(mrb, p, e, enc, &cr); if (cr) { ENC_CODERANGE_SET(str, cr); -- cgit v1.2.3 From 41bf311cd1997ad2d20d451fe627b241aed571d3 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:31:58 +0900 Subject: remove dependency to SIZEOF_INT --- include/mrbconf.h | 1 - include/mruby.h | 54 ------------------------------------------------------ src/numeric.c | 2 +- src/string.c | 6 +++--- src/transcode.c | 8 ++++---- 5 files changed, 8 insertions(+), 63 deletions(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index 81c19a121..bc54de420 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_INT 4 #define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..f1cf1ca01 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -560,60 +560,6 @@ void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); #define ruby_setjmp(env) RUBY_SETJMP(env) #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val) -#if defined PRIdPTR && !defined PRI_VALUE_PREFIX -#define PRIdVALUE PRIdPTR -#define PRIiVALUE PRIiPTR -#define PRIoVALUE PRIoPTR -#define PRIuVALUE PRIuPTR -#define PRIxVALUE PRIxPTR -#define PRIXVALUE PRIXPTR -#else -#define PRIdVALUE PRI_VALUE_PREFIX"d" -#define PRIiVALUE PRI_VALUE_PREFIX"i" -#define PRIoVALUE PRI_VALUE_PREFIX"o" -#define PRIuVALUE PRI_VALUE_PREFIX"u" -#define PRIxVALUE PRI_VALUE_PREFIX"x" -#define PRIXVALUE PRI_VALUE_PREFIX"X" -#endif -#ifndef PRI_VALUE_PREFIX -# define PRI_VALUE_PREFIX "" -#endif - -#if defined PRIdPTR -# define PRI_PTRDIFF_PREFIX "t" -#elif SIZEOF_PTRDIFF_T == SIZEOF_INT -# define PRI_PTRDIFF_PREFIX -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG -# define PRI_PTRDIFF_PREFIX "l" -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG -# define PRI_PTRDIFF_PREFIX "ll" -#else -# define PRI_PTRDIFF_PREFIX -#endif -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" -#define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i" -#define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o" -#define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u" -#define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x" -#define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X" - -#if defined PRIdPTR -# define PRI_SIZE_PREFIX "z" -#elif SIZEOF_SIZE_T == SIZEOF_INT -# define PRI_SIZE_PREFIX -#elif SIZEOF_SIZE_T == SIZEOF_LONG -# define PRI_SIZE_PREFIX "l" -#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define PRI_SIZE_PREFIX "ll" -#endif -#define PRIdSIZE PRI_SIZE_PREFIX"d" -#define PRIiSIZE PRI_SIZE_PREFIX"i" -#define PRIoSIZE PRI_SIZE_PREFIX"o" -#define PRIuSIZE PRI_SIZE_PREFIX"u" -#define PRIxSIZE PRI_SIZE_PREFIX"x" -#define PRIXSIZE PRI_SIZE_PREFIX"X" -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" - #define KHASH 0 #define STHASH 1 #define BASICHASH 2 diff --git a/src/numeric.c b/src/numeric.c index ef4588f76..b03e57ce6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -985,7 +985,7 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) v = mrb_num2long(mrb, val); if (!FIXABLE(v)) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " out of range of fixnum", v); + mrb_raise(mrb, E_RANGE_ERROR, "integer %ld out of range of fixnum", v); return mrb_fixnum_value(v); } diff --git a/src/string.c b/src/string.c index 9556f93e8..6b8861ace 100644 --- a/src/string.c +++ b/src/string.c @@ -4833,9 +4833,9 @@ mrb_str_buf_cat_escaped_char(mrb_state *mrb, mrb_value result, unsigned int c, i char buf[CHAR_ESC_LEN + 1]; int l; -#if SIZEOF_INT > 4 - c &= 0xffffffff; -#endif + if (sizeof(c) > 4) { + c &= 0xffffffff; + } if (unicode_p) { if (c < 0x7F && ISPRINT(c)) { snprintf(buf, CHAR_ESC_LEN, "%c", c); diff --git a/src/transcode.c b/src/transcode.c index 05d2b05b1..66a4d4e42 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -1770,9 +1770,9 @@ mrb_econv_putbackable(mrb_econv_t *ec) { if (ec->num_trans == 0) return 0; -#if SIZEOF_SIZE_T > SIZEOF_INT - if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; -#endif + if (sizeof(size_t) > sizeof(int)) { + if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; + } return (int)ec->elems[0].tc->readagain_len; } @@ -2625,7 +2625,7 @@ str_transcode0(mrb_state *mrb, int argc, mrb_value *argv, mrb_value *self, int e transcode_loop(mrb, &fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, sname, dname, ecflags, ecopts); if (fromp != sp+slen) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); + mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %td bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; -- cgit v1.2.3 From 1f78ba77a2efb23f637e79a9b1120b5e316f870a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:37:21 +0900 Subject: remove SIZEOF_SHORT --- include/mrbconf.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index bc54de420..6dccaccec 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -- cgit v1.2.3 From 0f0ad36c5f4b00781b96e2cae595672aa84e57c7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:02 +0900 Subject: remove dependency to SIZEOF___INT64 --- include/mrbconf.h | 1 - src/numeric.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index 6dccaccec..5d377e3e3 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,7 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF___INT64 0 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 diff --git a/src/numeric.c b/src/numeric.c index b03e57ce6..113c9b062 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -90,11 +90,6 @@ #if SIZEOF_LONG_LONG > 0 # define LONG_LONG long long -#elif SIZEOF___INT64 > 0 -# define HAVE_LONG_LONG 1 -# define LONG_LONG __int64 -# undef SIZEOF_LONG_LONG -# define SIZEOF_LONG_LONG SIZEOF___INT64 #endif typedef uintptr_t VALUE; -- cgit v1.2.3 From 2c28d29cecaa1d007f89d3c233d0556345a8ff99 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:22 +0900 Subject: remove SIZEOF_FLOAT/DOUBLE --- include/mrbconf.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index 5d377e3e3..96214a30b 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,8 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 8 #ifndef FALSE # define FALSE 0 -- cgit v1.2.3 From 3c1b3478343a7618dac7ac16953e77f45511f505 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:46:07 +0900 Subject: remove dependency to SIZEOF_LONG/LONG_LONG --- include/mrbconf.h | 3 --- src/numeric.c | 71 ++++--------------------------------------------------- src/regint.h | 4 ++-- 3 files changed, 6 insertions(+), 72 deletions(-) diff --git a/include/mrbconf.h b/include/mrbconf.h index 96214a30b..923558fd9 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,9 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_LONG 4 -#define SIZEOF_LONG_LONG 8 - #ifndef FALSE # define FALSE 0 #endif diff --git a/src/numeric.c b/src/numeric.c index 113c9b062..135691644 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -88,10 +88,6 @@ #define mrb_rational_raw1(x) mrb_rational_raw(x, INT2FIX(1)) -#if SIZEOF_LONG_LONG > 0 -# define LONG_LONG long long -#endif - typedef uintptr_t VALUE; typedef uintptr_t ID; #define SIGNED_VALUE intptr_t @@ -984,55 +980,6 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) return mrb_fixnum_value(v); } -#if HAVE_LONG_LONG - -LONG_LONG -mrb_num2ll(mrb_state *mrb, mrb_value val) -{ - if (mrb_nil_p(val)) { - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from nil"); - } - - if (FIXNUM_P(val)) return (LONG_LONG)mrb_fixnum(val); - - switch (mrb_type(val)) { - case MRB_TT_FLOAT: - if (mrb_float(val) <= (double)LLONG_MAX - && mrb_float(val) >= (double)LLONG_MIN) { - return (LONG_LONG)(mrb_float(val)); - } - else { - char buf[24]; - char *s; - - snprintf(buf, sizeof(buf), "%-.10g", mrb_float(val)); - if ((s = strchr(buf, ' ')) != 0) *s = '\0'; - mrb_raise(mrb, E_RANGE_ERROR, "float %s out of range of long long", buf); - } - - case MRB_TT_STRING: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from string"); - return mrb_nil_value(); /* not reached */ - - case MRB_TT_TRUE: - case MRB_TT_FALSE: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from boolean"); - return mrb_nil_value(); /* not reached */ - - default: - val = mrb_to_int(mrb, val); - return NUM2LL(val); - } -} - -unsigned LONG_LONG -mrb_num2ull(mrb_state *mrb, mrb_value val) -{ - return (unsigned LONG_LONG)mrb_num2ll(mrb, val); -} - -#endif /* HAVE_LONG_LONG */ - /* * Document-class: Integer * @@ -1133,7 +1080,7 @@ rb_fix2str(mrb_state *mrb, mrb_value x, int base) return mrb_usascii_str_new2(mrb, b); } -#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2)) +#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((sizeof(intptr_t)*CHAR_BIT-1)/2)) /*tests if N*N would overflow*/ #define FIT_SQRT_LONG(n) (((n)=-SQRT_LONG_MAX)) @@ -1159,21 +1106,12 @@ fix_mul(mrb_state *mrb, mrb_value x) volatile #endif long a, b; -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - LONG_LONG d; -#else long c; mrb_value r; -#endif a = mrb_fixnum(x); b = mrb_fixnum(y); -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - d = (LONG_LONG)a * b; - if (FIXABLE(d)) return mrb_fixnum_value(d); - return mrb_nil_value();// rb_ll2inum(d); -#else if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b)) return mrb_fixnum_value(a*b); c = a * b; @@ -1185,7 +1123,6 @@ fix_mul(mrb_state *mrb, mrb_value x) r = mrb_fixnum_value(a*b); } return r; -#endif } switch (mrb_type(y)) { case MRB_TT_FLOAT: @@ -1519,9 +1456,9 @@ mrb_fix_lshift(mrb_state *mrb, mrb_value x) static mrb_value fix_lshift(mrb_state *mrb, long val, unsigned long width) { - if (width > (SIZEOF_LONG*CHAR_BIT-1) - || ((unsigned long)abs(val))>>(SIZEOF_LONG*CHAR_BIT-1-width) > 0) { - mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (SIZEOF_LONG*CHAR_BIT-1)", width); + if (width > (sizeof(intptr_t)*CHAR_BIT-1) + || ((unsigned long)abs(val))>>(sizeof(intptr_t)*CHAR_BIT-1-width) > 0) { + mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (sizeof(intptr_t)*CHAR_BIT-1)", width); } val = val << width; return mrb_fixnum_value(val); diff --git a/src/regint.h b/src/regint.h index e86a95f27..bf19eee1a 100644 --- a/src/regint.h +++ b/src/regint.h @@ -246,11 +246,11 @@ } while(0) /* sizeof(OnigCodePoint) */ -#define WORD_ALIGNMENT_SIZE SIZEOF_LONG +#define WORD_ALIGNMENT_SIZE sizeof(uintptr_t) #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\ (pad_size) = WORD_ALIGNMENT_SIZE \ - - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\ + - ((uintptr_t)(addr) % WORD_ALIGNMENT_SIZE);\ if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\ } while (0) -- cgit v1.2.3 From 2dd08ef2ec27c69edf7c2eed188ec69f42048a02 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 23:19:13 +0900 Subject: remove prototype for mrb_define_variable() --- src/variable.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/variable.h b/src/variable.h index 494099c2c..4f2f6a598 100644 --- a/src/variable.h +++ b/src/variable.h @@ -30,7 +30,6 @@ int mrb_const_defined(mrb_state*, mrb_value, mrb_sym); mrb_value mrb_obj_iv_get(mrb_state*, struct RObject*, mrb_sym); void mrb_obj_iv_set(mrb_state*, struct RObject*, mrb_sym, mrb_value); const char * mrb_class2name(mrb_state *mrb, struct RClass* klass); -void mrb_define_variable(mrb_state *mrb, const char *name, mrb_value *var); mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym); void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v); /* mrb_iv_set */ void mrb_copy_generic_ivar(mrb_value clone, mrb_value obj); -- cgit v1.2.3 From c8c90d364438febfb7419db996afeecc6ebdb51b Mon Sep 17 00:00:00 2001 From: Patrick Hogan Date: Fri, 20 Apr 2012 09:22:30 -0500 Subject: Fixed typos in usage message. --- tools/mruby/mruby.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c index 4e84b3c7d..769746530 100644 --- a/tools/mruby/mruby.c +++ b/tools/mruby/mruby.c @@ -22,10 +22,10 @@ usage(const char *name) { static const char *const usage_msg[] = { "switches:", - "-b load and execute RiteBinary(mrb) file", + "-b load and execute RiteBinary (mrb) file", "-c check syntax only", - "-v print version number, then trun on verbose mode", - "--verbose run at verbose mode", + "-v print version number, then run in verbose mode", + "--verbose run in verbose mode", "--version print the version", "--copyright print the copyright", NULL -- cgit v1.2.3 From 4cb86f87a1d02ed2c9a659391f3817a930743a8f Mon Sep 17 00:00:00 2001 From: Patrick Hogan Date: Fri, 20 Apr 2012 09:32:35 -0500 Subject: #undef DEBUG for compatibility with environments that define DEBUG (like Xcode) Signed-off-by: Patrick Hogan --- include/mruby.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/mruby.h b/include/mruby.h index eb121c971..4fccfaa79 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -388,6 +388,10 @@ void mrb_write_barrier(mrb_state *, struct RBasic*); #define MRUBY_VERSION "Rite" +#ifdef DEBUG +#undef DEBUG +#endif + #if 0 #define DEBUG(x) x #else -- cgit v1.2.3 From 9e32b5152edc6d5935e4cdb0c44b7b138169027b Mon Sep 17 00:00:00 2001 From: Ranmocy Date: Fri, 20 Apr 2012 22:39:46 +0800 Subject: fixed statement alignment --- include/mruby.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..397885ac5 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -75,7 +75,7 @@ typedef struct mrb_value { #define mrb_test(o) ((o).tt != MRB_TT_FALSE) #define mrb_fixnum(o) (o).value.i #define mrb_float(o) (o).value.f -#define mrb_symbol(o) (o).value.sym +#define mrb_symbol(o) (o).value.sym #define mrb_object(o) (o).value.p #define FIXNUM_P(o) ((o).tt == MRB_TT_FIXNUM) #define UNDEF_P(o) ((o).tt == MRB_TT_UNDEF) -- cgit v1.2.3 From f7f31188be83e937308ddd3abe7dec42ea48ba78 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 21 Apr 2012 00:15:39 +0900 Subject: fix git commands --- README | 4 ++-- README.ja | 4 ++-- README.ja.md | 4 ++-- README.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README b/README index 12f8f5135..bfcd138cc 100644 --- a/README +++ b/README @@ -40,12 +40,12 @@ The mruby distribution files can be found in the following site: The trunk of the mruby source tree can be checked out with the following command: - $ git .... + $ git clone https://github.com/mruby/mruby.git There are some other branches under development. Try the following command and see the list of branches: - $ git .... + $ git branch -r * mruby home-page (sorry, it's not launched yet. we're working on this) diff --git a/README.ja b/README.ja index 22895a403..18ef16d13 100644 --- a/README.ja +++ b/README.ja @@ -44,11 +44,11 @@ mrubyはISO規格に準拠したRuby言語を様々な環境で動作可能と 開発先端のソースコードは次のコマンドで取得できます. - $ git .... + $ git clone https://github.com/mruby/mruby.git 他に開発中のブランチの一覧は次のコマンドで見られます. - $ git .... + $ git branch -r * ホームページ (まだ準備中です。ただいま鋭意製作中です。) diff --git a/README.ja.md b/README.ja.md index 0776226aa..aabad4c15 100644 --- a/README.ja.md +++ b/README.ja.md @@ -45,11 +45,11 @@ mrubyは[ISO規格](http://www.ipa.go.jp/about/press/20120402_2.html)に準拠 開発先端のソースコードは次のコマンドで取得できます。 - $ git .... + $ git clone https://github.com/mruby/mruby.git 他に開発中のブランチの一覧は次のコマンドで見られます。 - $ git .... + $ git branch -r ## ホームページ diff --git a/README.md b/README.md index 8fcbf44c7..f9a64ebb3 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ following command: There are some other branches under development. Try the following command and see the list of branches: - $ git .... + $ git branch -r ## mruby home-page -- cgit v1.2.3 From e4afcf6c4313f5779c912775e1929f7557efb8c9 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 20 Apr 2012 10:18:08 -0500 Subject: Made text edits to README.md to improve clarity. --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8fcbf44c7..568cd41c9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ mruby is the lightweight implementation of the Ruby language complying to the [ISO standard](http://www.ipa.go.jp/about/press/20120402_2.html). -mruby can run Ruby code in 'interpreter mode' or 'compile and execute it on a virtual machine' depending on how the developer's preference. +mruby can run Ruby code in 'interpreter mode' or 'compile and execute it on a virtual machine' depending on the developer's preference. This achievement was sponsored by the Regional Innovation Creation R&D Programs of the Ministry of Economy, Trade and Industry of Japan. @@ -44,7 +44,7 @@ following command: $ git clone https://github.com/mruby/mruby.git -There are some other branches under development. Try the following +There are some other branches under development. Try the following command and see the list of branches: $ git .... @@ -61,7 +61,7 @@ The URL of the mruby home-page will be: ## Mailing list -To subscribe the mruby mailing list....[T.B.D.] +To subscribe to the mruby mailing list....[T.B.D.] ## How to compile and install @@ -78,19 +78,19 @@ See the COPYING file. Thank you for considering contributing to mruby. mruby has chosen a MIT License due to its permissive license allowing -developer to target various environments such as embedded systems. -However, the license requires to display the copyright notice and license +developers to target various environments such as embedded systems. +However, the license requires the display of the copyright notice and license information in manuals for instance. Doing so for big projects can be complicated or troublesome. -This is why, mruby has decided to display "mruby developers" as copyright name +This is why mruby has decided to display "mruby developers" as the copyright name to make it simple conventionally. -In the future, mruby might ask you to distribute your new codes -(that you will commit,) under MIT License as a member of +In the future, mruby might ask you to distribute your new code +(that you will commit,) under the MIT License as a member of "mruby developers" but contributors will keep their copyright. (We did not intend for contributors to transfer or waive their copyrights, Actual copyright holder name (contributors) will be listed in the AUTHORS file.) -Please ask us if you want to distribute your code under other license +Please ask us if you want to distribute your code under another license or if your code is derived from GPL code. @@ -99,7 +99,7 @@ or if your code is derived from GPL code. See the file AUTHORS. -Feel free to send comments and bug reports to the author. Here is the +Feel free to send comments and bug reports to the author. Here is the author's latest mail address: devel@mruby.org -- cgit v1.2.3 From 758096334f467dc3ac6753cb8769c9368388ed1b Mon Sep 17 00:00:00 2001 From: Patrick Hogan Date: Fri, 20 Apr 2012 09:52:10 -0500 Subject: Remove unnecessary check for size_t < 0 size_t can never be negative since it is an unsigned integer according to standard. Removed to silence warning. Signed-off-by: Patrick Hogan --- src/array.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/array.c b/src/array.c index 69f5fd8b3..e3a0a3a9a 100644 --- a/src/array.c +++ b/src/array.c @@ -35,9 +35,6 @@ mrb_ary_new_capa(mrb_state *mrb, size_t capa) { struct RArray *a; - if (capa < 0) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "negative ary size (or size too big)"); - } #ifdef LONG_MAX if (capa > ARY_MAX_SIZE) { mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); -- cgit v1.2.3 From c138d7ef0a2365fd7da6a6374f9fa607633f07d5 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 00:51:20 +0900 Subject: use %zd for size_t argument --- src/cdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdump.c b/src/cdump.c index 74365b090..424b4f69b 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -140,7 +140,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f) } } memset(buf, 0, buf_len); - SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break; + SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %zd);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break; /* TODO MRB_TT_REGEX */ default: break; } -- cgit v1.2.3 From 9b3a4fd8a47c0983e3a8c3e74b649fe9d15b8cbc Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:01:07 +0900 Subject: avoid integer overflow --- src/array.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/array.c b/src/array.c index e3a0a3a9a..75b2cd0c1 100644 --- a/src/array.c +++ b/src/array.c @@ -34,6 +34,7 @@ mrb_value mrb_ary_new_capa(mrb_state *mrb, size_t capa) { struct RArray *a; + size_t blen; #ifdef LONG_MAX if (capa > ARY_MAX_SIZE) { @@ -43,10 +44,14 @@ mrb_ary_new_capa(mrb_state *mrb, size_t capa) if (capa < ARY_DEFAULT_LEN) { capa = ARY_DEFAULT_LEN; } + blen = capa * sizeof(mrb_value) ; + if (blen < capa) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big"); + } a = mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class); - a->buf = mrb_malloc(mrb, sizeof(mrb_value) * capa); - memset(a->buf, 0, sizeof(mrb_value) * capa); + a->buf = mrb_malloc(mrb, blen); + memset(a->buf, 0, blen); a->capa = capa; a->len = 0; -- cgit v1.2.3 From 2cc0623ae7fe5a5c48d9ed6854e99f2f55e46e3b Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:03:44 +0900 Subject: update ISO link URL from Japanese page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d40b85d6e..210c1502c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## What's mruby mruby is the lightweight implementation of the Ruby language complying to -the [ISO standard](http://www.ipa.go.jp/about/press/20120402_2.html). +the [ISO standard](http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579). mruby can run Ruby code in 'interpreter mode' or 'compile and execute it on a virtual machine' depending on the developer's preference. This achievement was sponsored by the Regional Innovation Creation R&D Programs of -- cgit v1.2.3 From 984e188bbe17f0f4007fc9ab9b1c75a3cf0b09de Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:21:41 +0900 Subject: update licensing issue and how to contribute --- COPYING | 56 -------------------------------------------------------- COPYING.ja | 52 ---------------------------------------------------- LEGAL | 2 +- README | 2 +- README.ja | 2 +- README.md | 42 +++++++++++++++++++++++++----------------- 6 files changed, 28 insertions(+), 128 deletions(-) delete mode 100644 COPYING delete mode 100644 COPYING.ja diff --git a/COPYING b/COPYING deleted file mode 100644 index 0d14af350..000000000 --- a/COPYING +++ /dev/null @@ -1,56 +0,0 @@ -mruby is copyrighted free software by mruby developers . -You can redistribute it and/or modify it under either the terms of the -MIT license (see the file MITL), or the conditions below: - - 1. You may make and give away verbatim copies of the source form of the - software without restriction, provided that you duplicate all of the - original copyright notices and associated disclaimers. - - 2. You may modify your copy of the software in any way, provided that - you do at least ONE of the following: - - a) place your modifications in the Public Domain or otherwise - make them Freely Available, such as by posting said - modifications to Usenet or an equivalent medium, or by allowing - the author to include your modifications in the software. - - b) use the modified software only within your corporation or - organization. - - c) give non-standard binaries non-standard names, with - instructions on where to get the original software distribution. - - d) make other distribution arrangements with the author. - - 3. You may distribute the software in object code or binary form, - provided that you do at least ONE of the following: - - a) distribute the binaries and library files of the software, - together with instructions (in the manual page or equivalent) - on where to get the original distribution. - - b) accompany the distribution with the machine-readable source of - the software. - - c) give non-standard binaries non-standard names, with - instructions on where to get the original software distribution. - - d) make other distribution arrangements with the author. - - 4. You may modify and include the part of the software into any other - software (possibly commercial). But some files in the distribution - are not written by the author, so that they are not under these terms. - - For the list of those files and their copying conditions, see the - file LEGAL. - - 5. The scripts and library files supplied as input to or produced as - output from the software do not automatically fall under the - copyright of the software, but belong to whomever generated them, - and may be sold commercially, and may be aggregated with this - software. - - 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. diff --git a/COPYING.ja b/COPYING.ja deleted file mode 100644 index 4210acb96..000000000 --- a/COPYING.ja +++ /dev/null @@ -1,52 +0,0 @@ -本プログラムはフリーソフトウェアです.MITライセンス -または以下に示す条件で本プログラムを再配布できます -MITライセンスについてはMTILファイル(参考訳:MITL.ja)を -参照して下さい. - - 1. 複製は制限なく自由です. - - 2. 以下の条件のいずれかを満たす時に本プログラムのソースを - 自由に変更できます. - - (a) ネットニューズにポストしたり,作者に変更を送付する - などの方法で,変更を公開する. - - (b) 変更した本プログラムを自分の所属する組織内部だけで - 使う. - - (c) 変更点を明示したうえ,ソフトウェアの名前を変更する. - そのソフトウェアを配布する時には変更前の本プログラ - ムも同時に配布する.または変更前の本プログラムのソー - スの入手法を明示する. - - (d) その他の変更条件を作者と合意する. - - 3. 以下の条件のいずれかを満たす時に本プログラムをコンパイ - ルしたオブジェクトコードや実行形式でも配布できます. - - (a) バイナリを受け取った人がソースを入手できるように, - ソースの入手法を明示する. - - (b) 機械可読なソースコードを添付する. - - (c) 変更を行ったバイナリは名前を変更したうえ,オリジナ - ルのソースコードの入手法を明示する. - - (d) その他の配布条件を作者と合意する. - - 4. 他のプログラムへの引用はいかなる目的であれ自由です.た - だし,本プログラムに含まれる他の作者によるコードは,そ - れぞれの作者の意向による制限が加えられる場合があります. - - それらファイルの一覧とそれぞれの配布条件などに付いては - LEGALファイルを参照してください. - - 5. 本プログラムへの入力となるスクリプトおよび,本プログラ - ムからの出力の権利は本プログラムの作者ではなく,それぞ - れの入出力を生成した人に属します.また,本プログラムに - 組み込まれるための拡張ライブラリについても同様です. - - 6. 本プログラムは無保証です.作者は本プログラムをサポート - する意志はありますが,プログラム自身のバグあるいは本プ - ログラムの実行などから発生するいかなる損害に対しても責 - 任を持ちません. diff --git a/LEGAL b/LEGAL index 7b072b0b8..036b35a95 100644 --- a/LEGAL +++ b/LEGAL @@ -2,7 +2,7 @@ LEGAL NOTICE INFORMATION ------------------------ All the files in this distribution are covered under the MIT license -(see the file COPYING) except some files mentioned below: +(see the file MITL) except some files mentioned below: (Currently no items are listed.) diff --git a/README b/README index bfcd138cc..d974e1716 100644 --- a/README +++ b/README @@ -68,7 +68,7 @@ See the file INSTALL. * Copying -See the file COPYING. +See the file MITL. * About Contribution diff --git a/README.ja b/README.ja index 18ef16d13..6332bde85 100644 --- a/README.ja +++ b/README.ja @@ -77,7 +77,7 @@ INSTALL.ja ファイルを参照してください。 * 配布条件 -COPYING.ja ファイルを参照してください。 +MITL.ja ファイルを参照してください。 * コントリビュートについて diff --git a/README.md b/README.md index 210c1502c..040be1ff3 100644 --- a/README.md +++ b/README.md @@ -69,14 +69,30 @@ To subscribe to the mruby mailing list....[T.B.D.] See the INSTALL file. -## Copying +## License -See the COPYING file. +Copyright (c) 2012 mruby developers +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: -## About Contribution +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +## Note for License -Thank you for considering contributing to mruby. mruby has chosen a MIT License due to its permissive license allowing developers to target various environments such as embedded systems. However, the license requires the display of the copyright notice and license @@ -90,18 +106,10 @@ In the future, mruby might ask you to distribute your new code (We did not intend for contributors to transfer or waive their copyrights, Actual copyright holder name (contributors) will be listed in the AUTHORS file.) -Please ask us if you want to distribute your code under another license -or if your code is derived from GPL code. - - -## The Author - -See the file AUTHORS. - - -Feel free to send comments and bug reports to the author. Here is the -author's latest mail address: - - devel@mruby.org +Please ask us if you want to distribute your code under another license. +## How to Contribute +Send pull request to . We consider you have granted +non-exclusive right to your contributed code under MIT license. If you want to be named +as one of mruby developers, include update to the AUTHORS file in your pull request. -- cgit v1.2.3 From 71961c0b10253e09b0e651eee292b9ef6920a1ce Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:30:26 +0900 Subject: update README.ja.md --- README.ja.md | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/README.ja.md b/README.ja.md index aabad4c15..ec3c6166d 100644 --- a/README.ja.md +++ b/README.ja.md @@ -80,12 +80,28 @@ INSTALL.ja ファイルを参照してください。 ## 配布条件 -COPYING.ja ファイルを参照してください。 +Copyright (c) 2012 mruby developers +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: -## コントリビュートについて +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +## ライセンスについて -mrubyへの貢献の検討をありがとうございます。 mrubyは組込み機器などの様々な環境で利用させることを期待し、ライセンスを 比較的制限の緩いMITライセンスにすることにいたしました。 しかしながら、ライセンスの実行条件としてマニュアル等の何らかの形で @@ -97,19 +113,14 @@ mrubyは組込み機器などの様々な環境で利用させることを期待 "mruby developers"の一員としてMITライセンスでの配布をお願いしたいと 考えています。 (コミットしたコードの著作権を譲渡や放棄をお願いするものではありません。 - 実質の著作者名はAUTHORSファイルに表記いたします。) + 希望があれば、著作者名はAUTHORSファイルに表記いたします。) 尚、その他のライセンスでの配布やGPL由来のコードのコミットについては 別途ご相談ください。 +## コントリビュートについて -## 著者 - -AUTHORS ファイルを参照してください。 - - -コメント,バグレポートその他は - - devel@mruby.org - -まで。 +にpull requestを送ってください。 +pull requestに含まれるコードについてMITライセンスでの配布を承諾したものとみなします。 +もし、mruby developersとして名前を残したいということであれば、 +pull requestにAUTHORSファイルへの修正を含めてください。 -- cgit v1.2.3 From 43ca69ed81bf1da4af305dfd56d1809d5516cc6e Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:32:02 +0900 Subject: remove Japanese files --- MITL.ja | 17 ---------- README.ja | 113 -------------------------------------------------------------- TODO.ja | 14 -------- 3 files changed, 144 deletions(-) delete mode 100644 MITL.ja delete mode 100644 README.ja delete mode 100644 TODO.ja diff --git a/MITL.ja b/MITL.ja deleted file mode 100644 index 749e96220..000000000 --- a/MITL.ja +++ /dev/null @@ -1,17 +0,0 @@ -Copyright (c) 2012 mruby developers - -以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル(以下「ソフトウ -ェア」)の複製を取得するすべての人に対し、ソフトウェアを無制限に扱うことを無償 -で許可します。これには、ソフトウェアの複製を使用、複写、変更、結合、掲載、頒布、 -サブライセンス、および/または販売する権利、およびソフトウェアを提供する相手に -同じことを許可する権利も無制限に含まれます。 - -上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分 -に記載するものとします。 - -ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、何らの保証も -なく提供されます。ここでいう保証とは、商品性、特定の目的への適合性、および権利 -非侵害についての保証も含みますが、それに限定されるものではありません。 -作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェ -アに起因または関連し、あるいはソフトウェアの使用またはその他の扱いによって生じ -る一切の請求、損害、その他の義務について何らの責任も負わないものとします。 diff --git a/README.ja b/README.ja deleted file mode 100644 index 6332bde85..000000000 --- a/README.ja +++ /dev/null @@ -1,113 +0,0 @@ -※注意 これはチーム内レビューの為の事前公開です。 - 記述されているURLやメールアドレスは現在使用できません。 - 正式リリースは後日アナウンス予定です。 - - 修正のご指摘は随時受け付けていますが、対応が遅くなるかもしれません。 - 予めご了承ください。 - -* mrubyとは - -mrubyはISO規格に準拠したRuby言語を様々な環境で動作可能となるように -軽量化したものです。モジュール構成によりインタプリタ実行形式や -コンパイル&VM実行形式でも動作させることができます。 - -2010年度の経済産業省の地域イノベーション創出事業により開発されました。 - - -* mrubyの特長 - -|MRI(Matz Ruby Implementation)版との互換性 -| -|以下要修正 -| + シンプルな文法 -| + 普通のオブジェクト指向機能(クラス,メソッドコールなど) -| + 特殊なオブジェクト指向機能(Mixin, 特異メソッドなど) -| + 演算子オーバーロード -| + 例外処理機能 -| + イテレータとクロージャ -| + ガーベージコレクタ -| + ダイナミックローディング (アーキテクチャによる) -| + 移植性が高い.多くのUnix-like/POSIX互換プラットフォーム上で -| 動くだけでなく,Windows, Mac OS X,BeOSなどの上でも動く -| cf. http://redmine.ruby-lang.org/wiki/ruby-19/SupportedPlatformsJa - - -* 入手法 - -** Zipで - -以下の場所においてあります. - - https://github.com/mruby/mruby/zipball/master - -** GitHubで - -開発先端のソースコードは次のコマンドで取得できます. - - $ git clone https://github.com/mruby/mruby.git - -他に開発中のブランチの一覧は次のコマンドで見られます. - - $ git branch -r - - -* ホームページ (まだ準備中です。ただいま鋭意製作中です。) - -mrubyのホームページのURLは - - http://www.mruby.org/ - -です. - - -* メーリングリスト - -mrubyのメーリングリストがあります。参加希望の方は....[T.B.D.] - - -mruby開発者向けメーリングリストもあります。こちらではrubyのバグ、 -将来の仕様拡張など実装上の問題について議論されています。 -参加希望の方は....[T.B.D.] - - -* コンパイル・インストール・移植 - -INSTALL.ja ファイルを参照してください。 - - -* 配布条件 - -MITL.ja ファイルを参照してください。 - - -* コントリビュートについて - -mrubyへの貢献の検討をありがとうございます。 -mrubyは組込み機器などの様々な環境で利用させることを期待し、ライセンスを -比較的制限の緩いMITライセンスにすることにいたしました。 -しかしながら、ライセンスの実行条件としてマニュアル等の何らかの形で -著作権表記及びライセンス文を記述する必要があります。 -昨今の規模の大きくなったシステムではこれらの対応も相当の煩雑さを伴います。 -そこで、mrubyではできる限り表記を簡便にするために、便宜上、著作権者名を -"mruby developers"とすることにいたしました。 -今後、新たにmrubyへのコミットされるコードについては、著作権を保持したまま、 -"mruby developers"の一員としてMITライセンスでの配布をお願いしたいと -考えています。 -(コミットしたコードの著作権を譲渡や放棄をお願いするものではありません。 - 実質の著作者名はAUTHORSファイルに表記いたします。) - -尚、その他のライセンスでの配布やGPL由来のコードのコミットについては -別途ご相談ください。 - - -* 著者 - -AUTHORS ファイルを参照してください。 - - -コメント,バグレポートその他は devel@mruby.org まで. -------------------------------------------------------- -created at: Fri Apr 20 11:57:36 JST 2012 -Local variables: -mode: indented-text -end: diff --git a/TODO.ja b/TODO.ja deleted file mode 100644 index ac3c0b7fd..000000000 --- a/TODO.ja +++ /dev/null @@ -1,14 +0,0 @@ -やること(まだできてないこと) - -* ヒアドキュメント -* 特殊変数 ($1,$2..) -* super in aliased methods -* BEGIN/END (対応しないんだっけ?) -* const_missing -* respond_to_missing - -改善すること(できているが直すこと) - -* Hash (サイズを減らす。khashを使うか、順序を保存するか) -* stringEx (encoding削除、CODERANGE削除、UTF-8 or ASCII以外削除) -* 気づいたら書き加える -- cgit v1.2.3 From 9718925f1308e99ef4fc44b20e502836e2a94be9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 01:32:19 +0900 Subject: remove plain README file --- README | 108 ----------------------------------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index d974e1716..000000000 --- a/README +++ /dev/null @@ -1,108 +0,0 @@ -!!Notice!! - This is a preliminary release for internal team reviewing. - The URL and address discribed below are not available yet. - The official release will be announced later. Thanks. - Any suggestion of the modification are welcome, - but the response might be delayed. Sorry for that in advance. - -* What's mruby - -mruby is the light-weight implementation of the Ruby language complied to -the ISO standard to execute various environments. It can run in 'interpreter -form' or 'compile and execute on vm form' according to its module construction. - -This achievement is due to the Regional Innovation Creation R&D Programs of -the Ministry of Economy, Trade and Industry of Japan. - - -* Features of mruby - - |FIXME: - | + Simple Syntax - | + *Normal* Object-Oriented features(ex. class, method calls) - | + *Advanced* Object-Oriented features(ex. Mix-in, Singleton-method) - | + Operator Overloading - | + Exception Handling - | + Iterators and Closures - | + Garbage Collection - | + Dynamic Loading of Object files(on some architecture) - | + Highly Portable (works on many Unix-like/POSIX compatible platforms - | as well as Windows, Mac OS X, BeOS etc.) - | cf. http://redmine.ruby-lang.org/wiki/ruby-19/SupportedPlatforms - - -* How to get mruby - -The mruby distribution files can be found in the following site: - - https://github.com/mruby/mruby/zipball/master - -The trunk of the mruby source tree can be checked out with the -following command: - - $ git clone https://github.com/mruby/mruby.git - -There are some other branches under development. Try the following -command and see the list of branches: - - $ git branch -r - - -* mruby home-page (sorry, it's not launched yet. we're working on this) - -The URL of the mruby home-page is: - - http://www.mruby.org/ - - -* Mailing list - -There is a mailing list to talk about mruby. -To subscribe this list....[T.B.D.] - - -* How to compile and install - -See the file INSTALL. - - -* Copying - -See the file MITL. - - -* About Contribution - -Thank you for considering of contribution for mruby. -mruby has chosen a MIT License as comparatively loose condition, -to expect to apply into various environment such as embedded system. -However, the license requires to display copyright notice and license -sentenses, for example manual or so. Especially for the recent bigger -system, it is comlecated or very troublesome. -So, mruby has decided to display "mruby developers" as copyright name -to make it simple conventionally. -In the future, mruby might ask you to distribute your new codes -(that you will commit,) under MIT License as a member of -"mruby developers" with keeping copyright of you. -(We did not intend you to transfer or waive your copyright, - Actual copyright holder name, you, will be listed in AUTHORS file.) - -Please ask us if you want to distribute your code under other license -or if your code is derived from GPL code. - - -* The Author - -See the file AUTHORS. - - -Feel free to send comments and bug reports to the author. Here is the -author's latest mail address: - - devel@mruby.org - -------------------------------------------------------- -created at: Fri Apr 20 11:57:36 JST 2012 -Local variables: -mode: indented-text -end: -- cgit v1.2.3 From 748d762e851e1954b72b7bbd70408353518e0a9d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 12:42:43 +0900 Subject: object instance variable do not use st.c --- include/mruby.h | 1 - src/kernel.c | 138 +++++++++++--------------------------------------------- 2 files changed, 27 insertions(+), 112 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index e2a497eb6..d0f8af90f 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -589,7 +589,6 @@ int mrb_cmpint(mrb_state *mrb, mrb_value val, mrb_value a, mrb_value b); # define ANYARGS # endif #endif -void st_foreach_safe(mrb_state *mrb, void *table, int (*func)(ANYARGS), void * a); void mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const char *name2); const char *mrb_class_name(mrb_state *mrb, struct RClass* klass); void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val); diff --git a/src/kernel.c b/src/kernel.c index 7a4a13501..80b64c26a 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -31,85 +31,12 @@ KHASH_MAP_INIT_INT(iv, mrb_value); #define TRUE 1 #endif -static mrb_value tst_setconst(mrb_state *mrb, mrb_value obj); -int kiv_lookup(khash_t(iv) *table, mrb_sym key, mrb_value *value); - struct obj_ivar_tag { mrb_value obj; int (*func)(mrb_sym key, mrb_value val, void * arg); void * arg; }; -static int -obj_ivar_i(mrb_sym key, int index, struct obj_ivar_tag *arg) -{ - enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; - struct obj_ivar_tag *data = (struct obj_ivar_tag *)arg; - if ((long)index < ROBJECT_NUMIV(data->obj)) { - mrb_value val = ROBJECT_IVPTR(data->obj)->vals[(long)index]; - if (val.tt != MRB_TT_FREE) { - return (data->func)((mrb_sym)key, val, data->arg); - } - } - return ST_CONTINUE; -} - -void -mrb_ivar_foreach(mrb_state *mrb, mrb_value obj, int (*func)(ANYARGS), void* arg) -{ - struct obj_ivar_tag data; - switch (mrb_type(obj)) { - case MRB_TT_OBJECT: - //obj_ivar_each(mrb, obj, func, arg); - if (RCLASS_IV_TBL(obj)) { - data.obj = obj; - data.func = (int (*)(mrb_sym key, mrb_value val, void * arg))func; - data.arg = arg; - st_foreach_safe(mrb, RCLASS_IV_TBL(obj), obj_ivar_i, (void *)&data); - } - break; - case MRB_TT_CLASS: - case MRB_TT_MODULE: - if (RCLASS_IV_TBL(obj)) { - st_foreach_safe(mrb, RCLASS_IV_TBL(obj), func, arg); - } - break; - default: - if (!ROBJECT_IVPTR(obj)/*generic_iv_tbl*/) break; - if (/*FL_TEST(obj, FL_EXIVAR) ||*/ mrb_special_const_p(obj)) { - mrb_value *tbl=0; - if (kiv_lookup(ROBJECT_IVPTR(obj)/*generic_iv_tbl*/, SYM2ID(obj), tbl)) { - st_foreach_safe(mrb, (void *)tbl, func, arg); - } - } - break; - } -} - -static int -inspect_i(mrb_state *mrb, mrb_sym id, mrb_value value, mrb_value str) -{ - enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; - mrb_value str2; - const char *ivname; - /* need not to show internal data */ - if (RSTRING_PTR(str)[0] == '-') { /* first element */ - RSTRING_PTR(str)[0] = '#'; - mrb_str_cat2(mrb, str, " "); - } - else { - mrb_str_cat2(mrb, str, ", "); - } - ivname = mrb_sym2name(mrb, id); - mrb_str_cat2(mrb, str, ivname); - mrb_str_cat2(mrb, str, "="); - str2 = mrb_inspect(mrb, value); - mrb_str_append(mrb, str, str2); - //OBJ_INFECT(str, str2); - - return ST_CONTINUE; -} - static mrb_value inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) { @@ -117,11 +44,32 @@ inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) mrb_str_cat2(mrb, str, " ..."); } else { - mrb_ivar_foreach(mrb, obj, inspect_i, &str); + khiter_t k; + kh_iv_t *h = RCLASS_IV_TBL(obj); + + if (h) { + for (k = kh_begin(h); k != kh_end(h); k++) { + if (kh_exist(h, k)){ + mrb_sym id = kh_key(h, k); + mrb_value value = kh_value(h, k); + + /* need not to show internal data */ + if (RSTRING_PTR(str)[0] == '-') { /* first element */ + RSTRING_PTR(str)[0] = '#'; + mrb_str_cat2(mrb, str, " "); + } + else { + mrb_str_cat2(mrb, str, ", "); + } + mrb_str_cat2(mrb, str, mrb_sym2name(mrb, id)); + mrb_str_cat2(mrb, str, "="); + mrb_str_append(mrb, str, mrb_inspect(mrb, value)); + } + } + } } mrb_str_cat2(mrb, str, ">"); RSTRING_PTR(str)[0] = '#'; - //OBJ_INFECT(str, obj); return str; } @@ -156,19 +104,9 @@ mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value obj) { if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) { - int has_ivar = 0; - mrb_value *ptr = (mrb_value *)ROBJECT_IVPTR(obj); long len = ROBJECT_NUMIV(obj); - long i; - - for (i = 0; i < len; i++) { - if (ptr[i].tt != MRB_TT_FREE) { - has_ivar = 1; - break; - } - } - if (has_ivar) { + if (len > 0) { mrb_value str; const char *c = mrb_obj_classname(mrb, obj); @@ -423,7 +361,6 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj) clone->super = klass->super; if (klass->iv) { - //clone->iv = st_copy(klass->iv); clone->iv = klass->iv; } clone->mt = kh_init(mt, mrb); @@ -449,11 +386,9 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) case MRB_TT_CLASS: case MRB_TT_MODULE: if (ROBJECT(dest)->iv) { - //st_free_table(ROBJECT(dest)->iv); ROBJECT(dest)->iv = 0; } if (ROBJECT(obj)->iv) { - //ROBJECT(dest)->iv = st_copy((st_table *)ROBJECT(obj)->iv); ROBJECT(dest)->iv = ROBJECT(obj)->iv; } } @@ -994,7 +929,6 @@ class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RCl { mrb_value ary; int recur; - //st_table *list; struct RClass* oldklass; if (argc == 0) { @@ -1006,25 +940,19 @@ class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RCl recur = mrb_test(r); } - //list = st_init_numtable(); ary = mrb_ary_new(mrb); - //for (; mod; mod = RCLASS_SUPER(mod)) { oldklass = 0; while (klass && (klass != oldklass)) { - //st_foreach(RCLASS_M_TBL(mod), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); if ((klass->tt == MRB_TT_ICLASS) || (klass->tt == MRB_TT_SCLASS)) { } - else - { + else { if (!recur) break; } oldklass = klass; klass = klass->super; } - //st_foreach(list, func, ary); - //st_free_table(list); return ary; } @@ -1033,7 +961,6 @@ mrb_value mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value obj) { mrb_value recur, ary; - //st_table *list; struct RClass* klass; if (argc == 0) { @@ -1044,22 +971,17 @@ mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value o recur = argv[0]; } klass = mrb_class(mrb, obj); - //list = st_init_numtable(); ary = mrb_ary_new(mrb); if (klass && (klass->tt == MRB_TT_SCLASS)) { - //st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); klass = klass->super; } if (RTEST(recur)) { while (klass && ((klass->tt == MRB_TT_SCLASS) || (klass->tt == MRB_TT_ICLASS))) { - //st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); klass = klass->super; } } - //st_foreach(list, ins_methods_i, ary); - //st_free_table(list); return ary; } @@ -1326,14 +1248,8 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) } } break; - //default: - // if (mrb_special_const_p(obj)) { - // v = val; - // if (generic_ivar_remove(obj, (st_data_t)id, &v)) { - // return (VALUE)v; - // } - // } - // break; + default: + break; } mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); return mrb_nil_value(); /* not reached */ -- cgit v1.2.3 From 9676edda669a3028c24fd9f1e7364c3b73dc7212 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 18:59:02 +0900 Subject: replace st.[ch] to remove SIZEOF_ST_INDEX_T --- src/encoding.c | 25 ++ src/st.c | 867 ++++++--------------------------------------------------- src/st.h | 66 ++--- 3 files changed, 131 insertions(+), 827 deletions(-) diff --git a/src/encoding.c b/src/encoding.c index db9a36425..9c50686c6 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -922,6 +922,31 @@ enc_name(mrb_state *mrb, mrb_value self) return mrb_usascii_str_new2(mrb, mrb_enc_name((mrb_encoding*)DATA_PTR(self))); } +struct fn_arg { + mrb_state *mrb; + int (*func)(ANYARGS); + void *a; +}; + +static int +fn_i(st_data_t key, st_data_t val, st_data_t arg) { + struct fn_arg *a = (struct fn_arg*)arg; + + return (*a->func)(a->mrb, key, val, a->a); +} + +static int +st_foreachNew(mrb_state *mrb, st_table *tbl, int (*func)(ANYARGS), void *a) +{ + struct fn_arg arg = { + mrb, + func, + a, + }; + + return st_foreach(tbl, fn_i, (st_data_t)&arg); +} + static int enc_names_i(mrb_state *mrb, st_data_t name, st_data_t idx, st_data_t args) { diff --git a/src/st.c b/src/st.c index c4bbc702c..725408414 100644 --- a/src/st.c +++ b/src/st.c @@ -1,19 +1,13 @@ /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ /* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */ -#define NOT_RUBY -#ifdef NOT_RUBY -#include "regint.h" -#include "st.h" -#else -#include "ruby/ruby.h" -#endif #include #ifdef HAVE_STDLIB_H #include #endif #include +#include "st.h" #define ST_DEFAULT_MAX_DENSITY 5 #define ST_DEFAULT_INIT_TABLE_SIZE 11 @@ -27,15 +21,16 @@ * allocated initially * */ - -static const struct st_hash_type type_numhash = { - st_numcmp, - st_numhash, +static int numcmp(long, long); +static st_index_t numhash(long); +static struct st_hash_type type_numhash = { + numcmp, + numhash, }; /* extern int strcmp(const char *, const char *); */ -static st_index_t strhash(st_data_t); -static const struct st_hash_type type_strhash = { +static st_index_t strhash(const char *); +static struct st_hash_type type_strhash = { strcmp, strhash, }; @@ -51,18 +46,14 @@ static void rehash(st_table *); #ifdef RUBY #define malloc xmalloc #define calloc xcalloc -#define free(x) xfree(x) #endif -#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) - -#define alloc(type) (type*)malloc((size_t)sizeof(type)) +#define alloc(type) (type*)malloc((unsigned)sizeof(type)) #define Calloc(n,s) (char*)calloc((n),(s)) #define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0) -/* remove cast to unsigned int in the future */ -#define do_hash(key,table) (unsigned int)(st_index_t)(*(table)->type->hash)((key)) +#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key)) #define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins) /* @@ -74,7 +65,7 @@ static void rehash(st_table *); /* Table of prime numbers 2^n+a, 2<=n<=30. */ -static const unsigned int primes[] = { +static long primes[] = { 8 + 3, 16 + 3, 32 + 5, @@ -106,27 +97,32 @@ static const unsigned int primes[] = { 0 }; -static st_index_t -new_size(st_index_t size) +static int +new_size(int size) { int i; - st_index_t newsize; +#if 0 + for (i=3; i<31; i++) { + if ((1< size) return 1< size) return primes[i]; } /* Ran out of polynomials */ -#ifndef NOT_RUBY - rb_raise(rb_eRuntimeError, "st_table too big"); -#endif return -1; /* should raise exception */ +#endif } -#define MAX_PACKED_NUMHASH (ST_DEFAULT_INIT_TABLE_SIZE/2) - st_table* -st_init_table_with_size(const struct st_hash_type *type, st_index_t size) +st_init_table_with_size(const struct st_hash_type *type, int size) { st_table *tbl; @@ -135,7 +131,6 @@ st_init_table_with_size(const struct st_hash_type *type, st_index_t size) tbl = alloc(st_table); tbl->type = type; tbl->num_entries = 0; - tbl->entries_packed = type == &type_numhash && size/2 <= MAX_PACKED_NUMHASH; tbl->num_bins = size; tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*)); tbl->head = 0; @@ -157,7 +152,7 @@ st_init_numtable(void) } st_table* -st_init_numtable_with_size(st_index_t size) +st_init_numtable_with_size(int size) { return st_init_table_with_size(&type_numhash, size); } @@ -169,7 +164,7 @@ st_init_strtable(void) } st_table* -st_init_strtable_with_size(st_index_t size) +st_init_strtable_with_size(int size) { return st_init_table_with_size(&type_strhash, size); } @@ -192,11 +187,6 @@ st_clear(st_table *table) register st_table_entry *ptr, *next; st_index_t i; - if (table->entries_packed) { - table->num_entries = 0; - return; - } - for(i = 0; i < table->num_bins; i++) { ptr = table->bins[i]; table->bins[i] = 0; @@ -219,29 +209,13 @@ st_free_table(st_table *table) free(table); } -size_t -st_memsize(const st_table *table) -{ - if (table->entries_packed) { - return table->num_bins * sizeof (void *) + sizeof(st_table); - } - else { - return table->num_entries * sizeof(struct st_table_entry) + table->num_bins * sizeof (void *) + sizeof(st_table); - } -} - #define PTR_NOT_EQUAL(table, ptr, hash_val, key) \ ((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key))) -#define COLLISION -#define FOUND_ENTRY - #define FIND_ENTRY(table, ptr, hash_val, bin_pos) do {\ bin_pos = hash_val%(table)->num_bins;\ ptr = (table)->bins[bin_pos];\ - FOUND_ENTRY;\ if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\ - COLLISION;\ while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\ ptr = ptr->next;\ }\ @@ -249,25 +223,12 @@ st_memsize(const st_table *table) }\ } while (0) -#define collision_check 0 - int -st_lookup(st_table *table, register st_data_t key, st_data_t *value) +st_lookup(st_table *table, st_data_t key, st_data_t *value) { - st_index_t hash_val, bin_pos; + unsigned int hash_val, bin_pos; register st_table_entry *ptr; - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == key) { - if (value !=0) *value = (st_data_t)table->bins[i*2+1]; - return 1; - } - } - return 0; - } - hash_val = do_hash(key, table); FIND_ENTRY(table, ptr, hash_val, bin_pos); @@ -280,46 +241,10 @@ st_lookup(st_table *table, register st_data_t key, st_data_t *value) } } -int -st_get_key(st_table *table, register st_data_t key, st_data_t *result) -{ - st_index_t hash_val, bin_pos; - register st_table_entry *ptr; - - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == key) { - if (result !=0) *result = (st_data_t)table->bins[i*2]; - return 1; - } - } - return 0; - } - - hash_val = do_hash(key, table); - FIND_ENTRY(table, ptr, hash_val, bin_pos); - - if (ptr == 0) { - return 0; - } - else { - if (result != 0) *result = ptr->key; - return 1; - } -} - -#undef collision_check -#define collision_check 1 - -#define MORE_PACKABLE_P(table) \ - ((st_index_t)((table)->num_entries+1) * 2 <= (table)->num_bins && \ - (table)->num_entries+1 <= MAX_PACKED_NUMHASH) - #define ADD_DIRECT(table, key, value, hash_val, bin_pos)\ do {\ st_table_entry *entry;\ - if (table->num_entries > ST_DEFAULT_MAX_DENSITY * table->num_bins) {\ + if (table->num_entries/(table->num_bins) > ST_DEFAULT_MAX_DENSITY) {\ rehash(table);\ bin_pos = hash_val % table->num_bins;\ }\ @@ -343,49 +268,12 @@ do {\ table->num_entries++;\ } while (0) -static void -unpack_entries(register st_table *table) -{ - st_index_t i; - struct st_table_entry *packed_bins[MAX_PACKED_NUMHASH*2]; - st_table tmp_table = *table; - - memcpy(packed_bins, table->bins, sizeof(struct st_table_entry *) * table->num_entries*2); - table->bins = packed_bins; - tmp_table.entries_packed = 0; - tmp_table.num_entries = 0; - memset(tmp_table.bins, 0, sizeof(struct st_table_entry *) * tmp_table.num_bins); - for (i = 0; i < table->num_entries; i++) { - st_insert(&tmp_table, (st_data_t)packed_bins[i*2], (st_data_t)packed_bins[i*2+1]); - } - *table = tmp_table; -} - int -st_insert(register st_table *table, register st_data_t key, st_data_t value) +st_insert(st_table *table, st_data_t key, st_data_t value) { - st_index_t hash_val, bin_pos; + unsigned int hash_val, bin_pos; register st_table_entry *ptr; - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == key) { - table->bins[i*2+1] = (struct st_table_entry*)value; - return 1; - } - } - if (MORE_PACKABLE_P(table)) { - i = table->num_entries++; - table->bins[i*2] = (struct st_table_entry*)key; - table->bins[i*2+1] = (struct st_table_entry*)value; - return 0; - } - else { - unpack_entries(table); - } - } - hash_val = do_hash(key, table); FIND_ENTRY(table, ptr, hash_val, bin_pos); @@ -399,63 +287,10 @@ st_insert(register st_table *table, register st_data_t key, st_data_t value) } } -int -st_insert2(register st_table *table, register st_data_t key, st_data_t value, - st_data_t (*func)(st_data_t)) -{ - st_index_t hash_val, bin_pos; - register st_table_entry *ptr; - - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == key) { - table->bins[i*2+1] = (struct st_table_entry*)value; - return 1; - } - } - if (MORE_PACKABLE_P(table)) { - i = table->num_entries++; - table->bins[i*2] = (struct st_table_entry*)key; - table->bins[i*2+1] = (struct st_table_entry*)value; - return 0; - } - else { - unpack_entries(table); - } - } - - hash_val = do_hash(key, table); - FIND_ENTRY(table, ptr, hash_val, bin_pos); - - if (ptr == 0) { - key = (*func)(key); - ADD_DIRECT(table, key, value, hash_val, bin_pos); - return 0; - } - else { - ptr->record = value; - return 1; - } -} - void st_add_direct(st_table *table, st_data_t key, st_data_t value) { - st_index_t hash_val, bin_pos; - - if (table->entries_packed) { - int i; - if (MORE_PACKABLE_P(table)) { - i = table->num_entries++; - table->bins[i*2] = (struct st_table_entry*)key; - table->bins[i*2+1] = (struct st_table_entry*)value; - return; - } - else { - unpack_entries(table); - } - } + unsigned int hash_val, bin_pos; hash_val = do_hash(key, table); bin_pos = hash_val % table->num_bins; @@ -470,7 +305,7 @@ rehash(register st_table *table) new_num_bins = new_size(table->num_bins+1); new_bins = (st_table_entry**) - xrealloc(table->bins, new_num_bins * sizeof(st_table_entry*)); + realloc(table->bins, new_num_bins * sizeof(st_table_entry*)); for (i = 0; i < new_num_bins; ++i) new_bins[i] = 0; table->num_bins = new_num_bins; table->bins = new_bins; @@ -506,11 +341,6 @@ st_copy(st_table *old_table) return 0; } - if (old_table->entries_packed) { - memcpy(new_table->bins, old_table->bins, sizeof(struct st_table_entry *) * old_table->num_bins); - return new_table; - } - if ((ptr = old_table->head) != 0) { prev = 0; tail = &new_table->head; @@ -557,23 +387,7 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value) st_table_entry **prev; register st_table_entry *ptr; - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == *key) { - if (value != 0) *value = (st_data_t)table->bins[i*2+1]; - table->num_entries--; - memmove(&table->bins[i*2], &table->bins[(i+1)*2], - sizeof(struct st_table_entry*) * 2*(table->num_entries-i)); - return 1; - } - } - if (value != 0) *value = 0; - return 0; - } - hash_val = do_hash_bin(*key, table); - for (prev = &table->bins[hash_val]; (ptr = *prev) != 0; prev = &ptr->next) { if (EQUAL(table, *key, ptr->key)) { *prev = ptr->next; @@ -589,78 +403,6 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value) return 0; } -int -st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *value, st_data_t never) -{ - st_index_t hash_val; - register st_table_entry *ptr; - - if (table->entries_packed) { - st_index_t i; - for (i = 0; i < table->num_entries; i++) { - if ((st_data_t)table->bins[i*2] == *key) { - if (value != 0) *value = (st_data_t)table->bins[i*2+1]; - table->bins[i*2] = (void *)never; - return 1; - } - } - if (value != 0) *value = 0; - return 0; - } - - hash_val = do_hash_bin(*key, table); - ptr = table->bins[hash_val]; - - for (; ptr != 0; ptr = ptr->next) { - if ((ptr->key != never) && EQUAL(table, ptr->key, *key)) { - REMOVE_ENTRY(table, ptr); - *key = ptr->key; - if (value != 0) *value = ptr->record; - ptr->key = ptr->record = never; - return 1; - } - } - - if (value != 0) *value = 0; - return 0; -} - -void -st_cleanup_safe(st_table *table, st_data_t never) -{ - st_table_entry *ptr, **last, *tmp; - st_index_t i; - - if (table->entries_packed) { - st_index_t i = 0, j = 0; - while ((st_data_t)table->bins[i*2] != never) { - if (i++ == table->num_entries) return; - } - for (j = i; ++i < table->num_entries;) { - if ((st_data_t)table->bins[i*2] == never) continue; - table->bins[j*2] = table->bins[i*2]; - table->bins[j*2+1] = table->bins[i*2+1]; - j++; - } - table->num_entries = j; - return; - } - - for (i = 0; i < table->num_bins; i++) { - ptr = *(last = &table->bins[i]); - while (ptr != 0) { - if (ptr->key == never) { - tmp = ptr; - *last = ptr = ptr->next; - free(tmp); - } - else { - ptr = *(last = &ptr->next); - } - } - } -} - int st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) { @@ -668,40 +410,6 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) enum st_retval retval; st_index_t i; - if (table->entries_packed) { - for (i = 0; i < table->num_entries; i++) { - st_index_t j; - st_data_t key, val; - key = (st_data_t)table->bins[i*2]; - val = (st_data_t)table->bins[i*2+1]; - retval = (*func)(key, val, arg); - switch (retval) { - case ST_CHECK: /* check if hash is modified during iteration */ - for (j = 0; j < table->num_entries; j++) { - if ((st_data_t)table->bins[j*2] == key) - break; - } - if (j == table->num_entries) { - /* call func with error notice */ - retval = (*func)(0, 0, arg, 1); - return 1; - } - /* fall through */ - case ST_CONTINUE: - break; - case ST_STOP: - return 0; - case ST_DELETE: - table->num_entries--; - memmove(&table->bins[i*2], &table->bins[(i+1)*2], - sizeof(struct st_table_entry*) * 2*(table->num_entries-i)); - i--; - break; - } - } - return 0; - } - if ((ptr = table->head) != 0) { do { i = ptr->hash % table->num_bins; @@ -716,6 +424,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) } } /* fall through */ + default: case ST_CONTINUE: ptr = ptr->fore; break; @@ -740,466 +449,46 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) return 0; } -typedef int st_foreach_func(mrb_sym, void*, void *); - -struct foreach_safe_arg { - st_table *tbl; - st_foreach_func *func; - void *arg; -}; - -static int -foreach_safe_i(mrb_state *mrb, mrb_sym key, void* value, struct foreach_safe_arg *arg) -{ - int status; - - if (key == 0xffffffff/*key == Qundef*/) return ST_CONTINUE; - status = (*arg->func)(key, value, arg->arg); - if (status == ST_CONTINUE) { - return ST_CHECK; - } - return status; -} - -void -st_foreach_safe(mrb_state *mrb, void *table, int (*func)(ANYARGS), void* a) -{ - struct foreach_safe_arg arg; - - arg.tbl = table; - arg.func = (st_foreach_func *)func; - arg.arg = a; - if (st_foreach(table, foreach_safe_i, (st_data_t)&arg)) { - mrb_raise(mrb, mrb->eRuntimeError_class, "hash modified during iteration"); - } -} - -int -st_foreachNew(mrb_state *mrb, st_table *table, int (*func)(ANYARGS), void* arg) -{ - st_table_entry *ptr, **last, *tmp; - enum st_retval retval; - st_index_t i; - - if (table->entries_packed) { - for (i = 0; i < table->num_entries; i++) { - st_index_t j; - st_data_t key, val; - key = (st_data_t)table->bins[i*2]; - val = (st_data_t)table->bins[i*2+1]; - retval = (*func)(mrb, key, val, arg); - switch (retval) { - case ST_CHECK: /* check if hash is modified during iteration */ - for (j = 0; j < table->num_entries; j++) { - if ((st_data_t)table->bins[j*2] == key) - break; - } - if (j == table->num_entries) { - /* call func with error notice */ - retval = (*func)(0, 0, arg, 1); - return 1; - } - /* fall through */ - case ST_CONTINUE: - break; - case ST_STOP: - return 0; - case ST_DELETE: - table->num_entries--; - memmove(&table->bins[i*2], &table->bins[(i+1)*2], - sizeof(struct st_table_entry*) * 2*(table->num_entries-i)); - i--; - break; - } - } - return 0; - } - - if ((ptr = table->head) != 0) { - do { - i = ptr->hash % table->num_bins; - retval = (*func)(mrb, ptr->key, ptr->record, arg); - switch (retval) { - case ST_CHECK: /* check if hash is modified during iteration */ - for (tmp = table->bins[i]; tmp != ptr; tmp = tmp->next) { - if (!tmp) { - /* call func with error notice */ - retval = (*func)(0, 0, arg, 1); - return 1; - } - } - /* fall through */ - case ST_CONTINUE: - ptr = ptr->fore; - break; - case ST_STOP: - return 0; - case ST_DELETE: - last = &table->bins[ptr->hash % table->num_bins]; - for (; (tmp = *last) != 0; last = &tmp->next) { - if (ptr == tmp) { - tmp = ptr->fore; - *last = ptr->next; - REMOVE_ENTRY(table, ptr); - free(ptr); - if (ptr == tmp) return 0; - ptr = tmp; - break; - } - } - } - } while (ptr && table->head); - } - return 0; -} - -/* - * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code - * - * @(#) $Hash32: Revision: 1.1 $ - * @(#) $Hash32: Id: hash_32a.c,v 1.1 2003/10/03 20:38:53 chongo Exp $ - * @(#) $Hash32: Source: /usr/local/src/cmd/fnv/RCS/hash_32a.c,v $ - * - *** - * - * Fowler/Noll/Vo hash - * - * The basis of this hash algorithm was taken from an idea sent - * as reviewer comments to the IEEE POSIX P1003.2 committee by: - * - * Phong Vo (http://www.research.att.com/info/kpv/) - * Glenn Fowler (http://www.research.att.com/~gsf/) - * - * In a subsequent ballot round: - * - * Landon Curt Noll (http://www.isthe.com/chongo/) - * - * improved on their algorithm. Some people tried this hash - * and found that it worked rather well. In an EMail message - * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash. - * - * FNV hashes are designed to be fast while maintaining a low - * collision rate. The FNV speed allows one to quickly hash lots - * of data while maintaining a reasonable collision rate. See: - * - * http://www.isthe.com/chongo/tech/comp/fnv/index.html - * - * for more details as well as other forms of the FNV hash. - *** - * - * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the - * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str(). - * - *** - * - * Please do not copyright this code. This code is in the public domain. - * - * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO - * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF - * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * By: - * chongo /\oo/\ - * http://www.isthe.com/chongo/ - * - * Share and Enjoy! :-) - */ - -/* - * 32 bit FNV-1 and FNV-1a non-zero initial basis - * - * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets: - * - * chongo /\../\ - * - * NOTE: The \'s above are not back-slashing escape characters. - * They are literal ASCII backslash 0x5c characters. - * - * NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition. - */ -#define FNV1_32A_INIT 0x811c9dc5 - -/* - * 32 bit magic FNV-1a prime - */ -#define FNV_32_PRIME 0x01000193 - -#ifdef ST_USE_FNV1 static st_index_t -strhash(st_data_t arg) +strhash(const char *string) { - register const char *string = (const char *)arg; - register st_index_t hval = FNV1_32A_INIT; + register int c; - /* - * FNV-1a hash each octet in the buffer - */ - while (*string) { - /* xor the bottom with the current octet */ - hval ^= (unsigned int)*string++; +#ifdef HASH_ELFHASH + register unsigned int h = 0, g; - /* multiply by the 32 bit FNV magic prime mod 2^32 */ - hval *= FNV_32_PRIME; + while ((c = *string++) != '\0') { + h = ( h << 4 ) + c; + if ( g = h & 0xF0000000 ) + h ^= g >> 24; + h &= ~g; } - return hval; -} -#else - -#ifndef UNALIGNED_WORD_ACCESS -# if defined __i386__ || defined _M_IX86 -# define UNALIGNED_WORD_ACCESS 1 -# endif -#endif -#ifndef UNALIGNED_WORD_ACCESS -# define UNALIGNED_WORD_ACCESS 0 -#endif - -/* MurmurHash described in http://murmurhash.googlepages.com/ */ -#ifndef MURMUR -#define MURMUR 2 -#endif - -#if MURMUR == 1 -#define MurmurMagic 0xc6a4a793 -#elif MURMUR == 2 -#if SIZEOF_ST_INDEX_T > 4 -#define MurmurMagic 0xc6a4a7935bd1e995 -#else -#define MurmurMagic 0x5bd1e995 -#endif -#endif - -static inline st_index_t -murmur(st_index_t h, st_index_t k, int r) -{ - const st_index_t m = MurmurMagic; -#if MURMUR == 1 - h += k; - h *= m; - h ^= h >> r; -#elif MURMUR == 2 - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; -#endif return h; -} - -static inline st_index_t -murmur_finish(st_index_t h) -{ -#if MURMUR == 1 - h = murmur(h, 0, 10); - h = murmur(h, 0, 17); -#elif MURMUR == 2 - h ^= h >> 13; - h *= MurmurMagic; - h ^= h >> 15; -#endif - return h; -} - -#define murmur_step(h, k) murmur(h, k, 16) - -#if MURMUR == 1 -#define murmur1(h) murmur_step(h, 16) -#else -#define murmur1(h) murmur_step(h, 24) -#endif - -st_index_t -st_hash(const void *ptr, size_t len, st_index_t h) -{ - const char *data = ptr; - st_index_t t = 0; - - h += 0xdeadbeef; - -#define data_at(n) (st_index_t)((unsigned char)data[n]) -#define UNALIGNED_ADD_4 UNALIGNED_ADD(2); UNALIGNED_ADD(1); UNALIGNED_ADD(0) -#if SIZEOF_ST_INDEX_T > 4 -#define UNALIGNED_ADD_8 UNALIGNED_ADD(6); UNALIGNED_ADD(5); UNALIGNED_ADD(4); UNALIGNED_ADD(3); UNALIGNED_ADD_4 -#if SIZEOF_ST_INDEX_T > 8 -#define UNALIGNED_ADD_16 UNALIGNED_ADD(14); UNALIGNED_ADD(13); UNALIGNED_ADD(12); UNALIGNED_ADD(11); \ - UNALIGNED_ADD(10); UNALIGNED_ADD(9); UNALIGNED_ADD(8); UNALIGNED_ADD(7); UNALIGNED_ADD_8 -#define UNALIGNED_ADD_ALL UNALIGNED_ADD_16 -#endif -#define UNALIGNED_ADD_ALL UNALIGNED_ADD_8 -#else -#define UNALIGNED_ADD_ALL UNALIGNED_ADD_4 -#endif - if (len >= sizeof(st_index_t)) { -#if !UNALIGNED_WORD_ACCESS - int align = (int)((st_data_t)data % sizeof(st_index_t)); - if (align) { - st_index_t d = 0; - int sl, sr, pack; - - switch (align) { -#ifdef WORDS_BIGENDIAN -# define UNALIGNED_ADD(n) case SIZEOF_ST_INDEX_T - (n) - 1: \ - t |= data_at(n) << CHAR_BIT*(SIZEOF_ST_INDEX_T - (n) - 2) -#else -# define UNALIGNED_ADD(n) case SIZEOF_ST_INDEX_T - (n) - 1: \ - t |= data_at(n) << CHAR_BIT*(n) -#endif - UNALIGNED_ADD_ALL; -#undef UNALIGNED_ADD - } - -#ifdef WORDS_BIGENDIAN - t >>= (CHAR_BIT * align) - CHAR_BIT; -#else - t <<= (CHAR_BIT * align); -#endif +#elif defined(HASH_PERL) + register int val = 0; - data += sizeof(st_index_t)-align; - len -= sizeof(st_index_t)-align; - - sl = CHAR_BIT * (SIZEOF_ST_INDEX_T-align); - sr = CHAR_BIT * align; - - while (len >= sizeof(st_index_t)) { - d = *(st_index_t *)data; -#ifdef WORDS_BIGENDIAN - t = (t << sr) | (d >> sl); -#else - t = (t >> sr) | (d << sl); -#endif - h = murmur_step(h, t); - t = d; - data += sizeof(st_index_t); - len -= sizeof(st_index_t); - } - - pack = len < (size_t)align ? (int)len : align; - d = 0; - switch (pack) { -#ifdef WORDS_BIGENDIAN -# define UNALIGNED_ADD(n) case (n) + 1: \ - d |= data_at(n) << CHAR_BIT*(SIZEOF_ST_INDEX_T - (n) - 1) -#else -# define UNALIGNED_ADD(n) case (n) + 1: \ - d |= data_at(n) << CHAR_BIT*(n) -#endif - UNALIGNED_ADD_ALL; -#undef UNALIGNED_ADD - } -#ifdef WORDS_BIGENDIAN - t = (t << sr) | (d >> sl); -#else - t = (t >> sr) | (d << sl); -#endif - -#if MURMUR == 2 - if (len < (size_t)align) goto skip_tail; -#endif - h = murmur_step(h, t); - data += pack; - len -= pack; - } - else -#endif - { - do { - h = murmur_step(h, *(st_index_t *)data); - data += sizeof(st_index_t); - len -= sizeof(st_index_t); - } while (len >= sizeof(st_index_t)); - } + while ((c = *string++) != '\0') { + val += c; + val += (val << 10); + val ^= (val >> 6); } + val += (val << 3); + val ^= (val >> 11); - t = 0; - switch (len) { -#ifdef WORDS_BIGENDIAN -# define UNALIGNED_ADD(n) case (n) + 1: \ - t |= data_at(n) << CHAR_BIT*(SIZEOF_ST_INDEX_T - (n) - 1) + return val + (val << 15); #else -# define UNALIGNED_ADD(n) case (n) + 1: \ - t |= data_at(n) << CHAR_BIT*(n) -#endif - UNALIGNED_ADD_ALL; -#undef UNALIGNED_ADD -#if MURMUR == 1 - h = murmur_step(h, t); -#elif MURMUR == 2 -# if !UNALIGNED_WORD_ACCESS - skip_tail: -# endif - h ^= t; - h *= MurmurMagic; -#endif - } - - return murmur_finish(h); -} + register int val = 0; -st_index_t -st_hash_uint32(st_index_t h, uint32_t i) -{ - return murmur_step(h + i, 16); -} + while ((c = *string++) != '\0') { + val = val*997 + c; + } -st_index_t -st_hash_uint(st_index_t h, st_index_t i) -{ - st_index_t v = 0; - h += i; -#ifdef WORDS_BIGENDIAN -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 12*8 - v = murmur1(v + (h >> 12*8)); -#endif -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 8*8 - v = murmur1(v + (h >> 8*8)); -#endif -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8 - v = murmur1(v + (h >> 4*8)); -#endif -#endif - v = murmur1(v + h); -#ifndef WORDS_BIGENDIAN -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8 - v = murmur1(v + (h >> 4*8)); -#endif -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 8*8 - v = murmur1(v + (h >> 8*8)); -#endif -#if SIZEOF_ST_INDEX_T*CHAR_BIT > 12*8 - v = murmur1(v + (h >> 12*8)); + return val + (val>>5); #endif -#endif - return v; -} - -st_index_t -st_hash_end(st_index_t h) -{ - h = murmur_step(h, 10); - h = murmur_step(h, 17); - return h; } -#undef st_hash_start -st_index_t -st_hash_start(st_index_t h) -{ - return h; -} - -static st_index_t -strhash(st_data_t arg) -{ - register const char *string = (const char *)arg; - return st_hash(string, strlen(string), FNV1_32A_INIT); -} -#endif +#define FNV1_32A_INIT 0x811c9dc5 +#define FNV_32_PRIME 0x01000193 int st_strcasecmp(const char *s1, const char *s2) @@ -1270,14 +559,38 @@ strcasehash(st_data_t arg) return hval; } -int -st_numcmp(st_data_t x, st_data_t y) +static int +numcmp(long x, long y) { return x != y; } -st_index_t -st_numhash(st_data_t n) +static st_index_t +numhash(long n) +{ + return n; +} + +#if 0 +static int +f(st_data_t key, st_data_t val, st_data_t a) +{ + printf("tbl=%p key=%s val=%s\n", (st_table*)a, (char*)key, (char*)val); + // return ST_CONTINUE; +} + +void +main(int argc, char **argv) { - return (st_index_t)n; + st_table *tbl = st_init_strtable(); + int i; + + for (i = 1; i -#elif defined HAVE_STDLIB_H #include -#endif - -#ifdef HAVE_STDINT_H -# include -#endif -#include +#include #ifndef CHAR_BIT # ifdef HAVE_LIMITS_H @@ -35,10 +20,6 @@ extern "C" { # endif #endif -#ifndef _ -# define _(args) args -#endif - #ifndef ANYARGS # ifdef __cplusplus # define ANYARGS ... @@ -69,16 +50,10 @@ struct st_hash_type { st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */ }; -#define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT) - struct st_table { const struct st_hash_type *type; - st_index_t num_bins; - unsigned int entries_packed : 1; -#ifdef __GNUC__ - __extension__ -#endif - st_index_t num_entries : ST_INDEX_BITS - 1; + int num_bins; + int num_entries; struct st_table_entry **bins; struct st_table_entry *head, *tail; }; @@ -88,46 +63,37 @@ struct st_table { enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; st_table *st_init_table(const struct st_hash_type *); -st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t); +st_table *st_init_table_with_size(const struct st_hash_type *, int); st_table *st_init_numtable(void); -st_table *st_init_numtable_with_size(st_index_t); +st_table *st_init_numtable_with_size(int); st_table *st_init_strtable(void); -st_table *st_init_strtable_with_size(st_index_t); +st_table *st_init_strtable_with_size(int); st_table *st_init_strcasetable(void); st_table *st_init_strcasetable_with_size(st_index_t); -int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */ +int st_delete(st_table *, st_data_t *, st_data_t *); int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); int st_insert(st_table *, st_data_t, st_data_t); -int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t)); int st_lookup(st_table *, st_data_t, st_data_t *); -int st_get_key(st_table *, st_data_t, st_data_t *); int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); -int st_foreachNew(mrb_state *mrb, st_table *, int (*)(ANYARGS), void*); -int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t); void st_add_direct(st_table *, st_data_t, st_data_t); void st_free_table(st_table *); void st_cleanup_safe(st_table *, st_data_t); -void st_clear(st_table *); st_table *st_copy(st_table *); -int st_numcmp(st_data_t, st_data_t); -st_index_t st_numhash(st_data_t); -int st_strcasecmp(const char *s1, const char *s2); -int st_strncasecmp(const char *s1, const char *s2, size_t n); -size_t st_memsize(const st_table *); -st_index_t st_hash(const void *ptr, size_t len, st_index_t h); -st_index_t st_hash_uint32(st_index_t h, uint32_t i); -st_index_t st_hash_uint(st_index_t h, st_index_t i); -st_index_t st_hash_end(st_index_t h); -st_index_t st_hash_start(st_index_t h); -#define st_hash_start(h) ((st_index_t)(h)) - int st_strcasecmp(const char *s1, const char *s2); int st_strncasecmp(const char *s1, const char *s2, size_t n); #define STRCASECMP(s1, s2) (st_strcasecmp(s1, s2)) #define STRNCASECMP(s1, s2, n) (st_strncasecmp(s1, s2, n)) +#define ST_NUMCMP ((int (*)()) 0) +#define ST_NUMHASH ((int (*)()) -2) + +#define st_numcmp ST_NUMCMP +#define st_numhash ST_NUMHASH + +int st_strhash(); + #if defined(__cplusplus) } /* extern "C" { */ #endif -#endif /* RUBY_ST_H */ +#endif /* ST_INCLUDED */ -- cgit v1.2.3 From 669cfc7f66cecf24156b0052fac291c98c4b10f5 Mon Sep 17 00:00:00 2001 From: lucas dicioccio Date: Sat, 21 Apr 2012 12:02:12 +0200 Subject: typo in the node's comment --- src/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.y b/src/parse.y index b22dd10f6..2bc78f577 100644 --- a/src/parse.y +++ b/src/parse.y @@ -275,7 +275,7 @@ new_true(parser_state *p) return list1((node*)NODE_TRUE); } -// (:true) +// (:false) static node* new_false(parser_state *p) { -- cgit v1.2.3 From fc125524b2ece07fc70e782cc1a232d794dd4f6d Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 21 Apr 2012 23:30:34 +0200 Subject: only increment position, if no error has occured --- src/parse.y | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parse.y b/src/parse.y index 2bc78f577..9ffe6d33d 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2976,12 +2976,16 @@ nextc(parser_state *p) c = *p->s++; } if (c == '\n') { - p->lineno++; - p->column = 0; + if (p->nerr < 1) { + p->lineno++; + p->column = 0; + } // must understand heredoc } else { - p->column++; + if (p->nerr < 1) { + p->column++; + } } return c; } -- cgit v1.2.3 From 9760b7f126cfd5bb8ab8764331ad876b8e23297c Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 22 Apr 2012 07:40:31 +0200 Subject: simple fix for underflow --- src/parse.y | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/parse.y b/src/parse.y index 9ffe6d33d..62433a6bf 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2976,16 +2976,17 @@ nextc(parser_state *p) c = *p->s++; } if (c == '\n') { - if (p->nerr < 1) { + if (p->column < 0) { + p->column++; // pushback caused an underflow + } + else { p->lineno++; p->column = 0; } // must understand heredoc } else { - if (p->nerr < 1) { - p->column++; - } + p->column++; } return c; } -- cgit v1.2.3 From 844d7d49b3803f35ee102179e35de283df8e96c2 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 22 Apr 2012 08:53:55 +0200 Subject: allow errors & warning to be captured --- src/compile.h | 12 ++++++++++++ src/parse.y | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/compile.h b/src/compile.h index f0e6b1874..212628deb 100644 --- a/src/compile.h +++ b/src/compile.h @@ -25,6 +25,12 @@ enum mrb_lex_state_enum { EXPR_MAX_STATE }; +struct mrb_parser_message { + int lineno; + int column; + char* message; +}; + struct mrb_parser_state { mrb_state *mrb; struct mrb_pool *pool; @@ -55,14 +61,20 @@ struct mrb_parser_state { void *ylval; int nerr; + int nwarn; mrb_ast_node *tree, *begin_tree; + int capture_errors; + struct mrb_parser_message error_buffer[10]; + struct mrb_parser_message warn_buffer[10]; + jmp_buf jmp; }; struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*); struct mrb_parser_state* mrb_parse_string(mrb_state*,char*); struct mrb_parser_state* mrb_parse_nstring(mrb_state*,char*,size_t); +struct mrb_parser_state* mrb_parse_nstring_ext(mrb_state*,char*,size_t); int mrb_generate_code(mrb_state*, mrb_ast_node*); int mrb_compile_file(mrb_state*,FILE*); diff --git a/src/parse.y b/src/parse.y index 62433a6bf..6e2696bd9 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2898,8 +2898,21 @@ none : /* none */ static void yyerror(parser_state *p, const char *s) { - fputs(s, stderr); - fputs("\n", stderr); + char* c; + size_t n; + + if (! p->capture_errors) { + fputs(s, stderr); + fputs("\n", stderr); + } + else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) { + n = strlen(s); + c = parser_palloc(p, n + 1); + 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; + } p->nerr++; } @@ -2915,8 +2928,22 @@ yyerror_i(parser_state *p, const char *fmt, int i) static void yywarn(parser_state *p, const char *s) { - fputs(s, stderr); - fputs("\n", stderr); + char* c; + size_t n; + + if (! p->capture_errors) { + fputs(s, stderr); + fputs("\n", stderr); + } + else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) { + n = strlen(s); + c = parser_palloc(p, n + 1); + memcpy(c, s, n + 1); + p->error_buffer[p->nwarn].message = c; + p->error_buffer[p->nwarn].lineno = p->lineno; + p->error_buffer[p->nwarn].column = p->column; + } + p->nwarn++; } static void @@ -4609,6 +4636,8 @@ parser_new(mrb_state *mrb) p->cmd_start = TRUE; p->in_def = p->in_single = FALSE; + p->capture_errors = NULL; + p->lineno = 1; #if defined(PARSER_TEST) || defined(PARSER_DEBUG) yydebug = 1; @@ -4646,6 +4675,22 @@ mrb_parse_nstring(mrb_state *mrb, char *s, size_t len) return p; } +parser_state* +mrb_parse_nstring_ext(mrb_state *mrb, char *s, size_t len) +{ + parser_state *p; + + p = parser_new(mrb); + if (!p) return 0; + p->s = s; + p->send = s + len; + p->f = NULL; + p->capture_errors = 1; + + start_parser(p); + return p; +} + parser_state* mrb_parse_string(mrb_state *mrb, char *s) { -- cgit v1.2.3 From 5859a204fe9e43560993d5c090846ab82ab1f6f7 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sun, 22 Apr 2012 18:36:28 +0900 Subject: Fix SEGV when calling Proc object created by Proc.new --- src/proc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/proc.c b/src/proc.c index aae9b1932..502650ff5 100644 --- a/src/proc.c +++ b/src/proc.c @@ -50,6 +50,22 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func) return p; } +static mrb_value +mrb_proc_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value blk = mrb->stack[mrb->ci->argc+1]; + + if (!mrb_nil_p(blk)) { + *mrb_proc_ptr(self) = *mrb_proc_ptr(blk); + } + else { + /* Calling Proc.new without a block is not implemented yet */ + mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block"); + } + + return self; +} + int mrb_proc_cfunc_p(struct RProc *p) { @@ -86,6 +102,8 @@ mrb_init_proc(mrb_state *mrb) mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); + mrb_define_method(mrb, mrb->proc_class, "initialize", mrb_proc_initialize, ARGS_NONE()); + m = mrb_proc_new(mrb, call_irep); mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "call"), m); mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]"), m); -- cgit v1.2.3 From f9d4a5a02b206a2020738ce09049d2a220ebe1d4 Mon Sep 17 00:00:00 2001 From: Yuichiro MASUI Date: Mon, 23 Apr 2012 03:06:01 +0900 Subject: Fixed to forget to remove some files on 'make clean' --- Makefile | 2 ++ mrblib/Makefile | 1 + src/Makefile | 1 + tools/mrbc/Makefile | 1 + tools/mruby/Makefile | 1 + 5 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 76f4ef594..55988683b 100644 --- a/Makefile +++ b/Makefile @@ -113,8 +113,10 @@ $(OBJM) : $(MSRC) .PHONY : clean clean : $(MAKE) clean -C src $(MAKE_FLAGS) + $(MAKE) clean -C tools/mrbc $(MAKE_FLAGS) $(MAKE) clean -C tools/mruby $(MAKE_FLAGS) -rm -f $(EXE) $(OBJM) -rm -f $(OBJM:.o=.d) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) -rm -f $(IOSLIB) $(IOSSIMLIB) $(IOSDEVLIB) @echo "make: removing targets, objects and depend files of `pwd`" diff --git a/mrblib/Makefile b/mrblib/Makefile index 0192ec941..8fc808cc4 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -59,5 +59,6 @@ $(RLIB) : $(MRBS) .PHONY : clean clean : -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) @echo "make: removing targets, objects and depend files of `pwd`" diff --git a/src/Makefile b/src/Makefile index abb6f4c4b..fb5483a72 100644 --- a/src/Makefile +++ b/src/Makefile @@ -86,5 +86,6 @@ clean : $(MAKE) clean -C ../mrblib $(MAKE_FLAGS) -rm -f $(LIB) $(OBJS) $(OBJY) $(YC) -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) @echo "make: removing targets, objects and depend files of `pwd`" diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile index ba7764b78..7271a2fed 100644 --- a/tools/mrbc/Makefile +++ b/tools/mrbc/Makefile @@ -69,5 +69,6 @@ $(YC) : $(YSRC) clean : -rm -f $(EXE) $(OBJS) $(OBJY) $(YC) -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) @echo "make: removing targets, objects and depend files of `pwd`" diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile index dfb8b7f7c..62d7cdd3f 100644 --- a/tools/mruby/Makefile +++ b/tools/mruby/Makefile @@ -86,4 +86,5 @@ clean : $(MAKE) clean -C ../../mrblib $(MAKE_FLAGS) -rm -f $(EXE) $(OBJS) $(OBJY) $(YC) $(EXTS) -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) $(EXTS:.o=.d) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) @echo "make: removing targets, objects and depend files of `pwd`" -- cgit v1.2.3 From afefad8cd540c5ac4401664732ae5c002f99b59c Mon Sep 17 00:00:00 2001 From: Wuffers Lightwolf Date: Sun, 22 Apr 2012 15:33:12 -0500 Subject: Ignore files made from build --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 76fdc3066..8e8704797 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.dylib *.inc *.o +*.a *.orig *.rej *.sav @@ -16,3 +17,6 @@ cscope.out mruby.exe y.tab.c +bin +mrblib/mrblib.c +mrblib/*.*tmp -- cgit v1.2.3 From a639479c2731e7167887dcbb71208449f1a80923 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 23 Apr 2012 08:43:16 +0900 Subject: update .gitignore based on pull-request #36 --- .gitignore | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8e8704797..94a9f5d79 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,7 @@ .svn /.git cscope.out -mruby.exe -y.tab.c -bin -mrblib/mrblib.c -mrblib/*.*tmp +/src/y.tab.c +/bin +/mrblib/mrblib.c +/mrblib/*.*tmp -- cgit v1.2.3 From 359fe9dfdc80d846ad419e64cbaa4bb8ec29cd7c Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 23 Apr 2012 10:20:36 +0900 Subject: force to remove mrblib/mrblib.d --- mrblib/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/mrblib/Makefile b/mrblib/Makefile index 8fc808cc4..ef60654fd 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -59,6 +59,7 @@ $(RLIB) : $(MRBS) .PHONY : clean clean : -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) + -rm -f $(patsubst %.c,%.d,$(CLIB)) -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) @echo "make: removing targets, objects and depend files of `pwd`" -- cgit v1.2.3