diff options
| author | mimaki <[email protected]> | 2012-04-23 11:51:47 +0900 |
|---|---|---|
| committer | mimaki <[email protected]> | 2012-04-23 11:51:47 +0900 |
| commit | c80487561f291e8239541687341b4d64a840c108 (patch) | |
| tree | d4f7777cc91597cf880bed364df26066b9aaee8f | |
| parent | 835443614d21b13b27af3674d7f8cb9bf49c298b (diff) | |
| parent | 3f0b98762d4a49beb7cc3f9cc8a8dfcee4aa5f6f (diff) | |
| download | mruby-c80487561f291e8239541687341b4d64a840c108.tar.gz mruby-c80487561f291e8239541687341b4d64a840c108.zip | |
Merge branch 'master' of github.com:mruby/mruby
Conflicts:
src/variable.c
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | COPYING | 56 | ||||
| -rw-r--r-- | COPYING.ja | 52 | ||||
| -rw-r--r-- | LEGAL | 2 | ||||
| -rw-r--r-- | MITL.ja | 17 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README | 108 | ||||
| -rw-r--r-- | README.ja | 113 | ||||
| -rw-r--r-- | README.ja.md | 57 | ||||
| -rw-r--r-- | README.md | 97 | ||||
| -rw-r--r-- | TODO.ja | 14 | ||||
| -rw-r--r-- | include/mrbconf.h | 9 | ||||
| -rw-r--r-- | include/mruby.h | 63 | ||||
| -rw-r--r-- | mrblib/Makefile | 2 | ||||
| -rw-r--r-- | src/Makefile | 3 | ||||
| -rw-r--r-- | src/array.c | 12 | ||||
| -rw-r--r-- | src/cdump.c | 2 | ||||
| -rw-r--r-- | src/compile.h | 12 | ||||
| -rw-r--r-- | src/encoding.c | 25 | ||||
| -rw-r--r-- | src/gc.c | 4 | ||||
| -rw-r--r-- | src/kernel.c | 138 | ||||
| -rw-r--r-- | src/numeric.c | 173 | ||||
| -rw-r--r-- | src/parse.y | 64 | ||||
| -rw-r--r-- | src/proc.c | 18 | ||||
| -rw-r--r-- | src/re.c | 49 | ||||
| -rw-r--r-- | src/regint.h | 4 | ||||
| -rw-r--r-- | src/st.c | 867 | ||||
| -rw-r--r-- | src/st.h | 72 | ||||
| -rw-r--r-- | src/string.c | 183 | ||||
| -rw-r--r-- | src/transcode.c | 8 | ||||
| -rw-r--r-- | src/variable.c | 1 | ||||
| -rw-r--r-- | src/variable.h | 1 | ||||
| -rw-r--r-- | tools/mrbc/Makefile | 1 | ||||
| -rw-r--r-- | tools/mruby/Makefile | 1 | ||||
| -rw-r--r-- | tools/mruby/mruby.c | 6 |
35 files changed, 389 insertions, 1854 deletions
diff --git a/.gitignore b/.gitignore index 76fdc3066..94a9f5d79 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.dylib *.inc *.o +*.a *.orig *.rej *.sav @@ -14,5 +15,7 @@ .svn /.git cscope.out -mruby.exe -y.tab.c +/src/y.tab.c +/bin +/mrblib/mrblib.c +/mrblib/*.*tmp 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 <[email protected]>. -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. 本プログラムは無保証です.作者は本プログラムをサポート - する意志はありますが,プログラム自身のバグあるいは本プ - ログラムの実行などから発生するいかなる損害に対しても責 - 任を持ちません. @@ -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/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 - -以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル(以下「ソフトウ -ェア」)の複製を取得するすべての人に対し、ソフトウェアを無制限に扱うことを無償 -で許可します。これには、ソフトウェアの複製を使用、複写、変更、結合、掲載、頒布、 -サブライセンス、および/または販売する権利、およびソフトウェアを提供する相手に -同じことを許可する権利も無制限に含まれます。 - -上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分 -に記載するものとします。 - -ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、何らの保証も -なく提供されます。ここでいう保証とは、商品性、特定の目的への適合性、および権利 -非侵害についての保証も含みますが、それに限定されるものではありません。 -作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェ -アに起因または関連し、あるいはソフトウェアの使用またはその他の扱いによって生じ -る一切の請求、損害、その他の義務について何らの責任も負わないものとします。 @@ -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/README b/README deleted file mode 100644 index 12f8f5135..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 .... - -There are some other branches under development. Try the following -command and see the list of branches: - - $ git .... - - -* 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 COPYING. - - -* 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: - - -------------------------------------------------------- -created at: Fri Apr 20 11:57:36 JST 2012 -Local variables: -mode: indented-text -end: diff --git a/README.ja b/README.ja deleted file mode 100644 index 22895a403..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 .... - -他に開発中のブランチの一覧は次のコマンドで見られます. - - $ git .... - - -* ホームページ (まだ準備中です。ただいま鋭意製作中です。) - -mrubyのホームページのURLは - - http://www.mruby.org/ - -です. - - -* メーリングリスト - -mrubyのメーリングリストがあります。参加希望の方は....[T.B.D.] - - -mruby開発者向けメーリングリストもあります。こちらではrubyのバグ、 -将来の仕様拡張など実装上の問題について議論されています。 -参加希望の方は....[T.B.D.] - - -* コンパイル・インストール・移植 - -INSTALL.ja ファイルを参照してください。 - - -* 配布条件 - -COPYING.ja ファイルを参照してください。 - - -* コントリビュートについて - -mrubyへの貢献の検討をありがとうございます。 -mrubyは組込み機器などの様々な環境で利用させることを期待し、ライセンスを -比較的制限の緩いMITライセンスにすることにいたしました。 -しかしながら、ライセンスの実行条件としてマニュアル等の何らかの形で -著作権表記及びライセンス文を記述する必要があります。 -昨今の規模の大きくなったシステムではこれらの対応も相当の煩雑さを伴います。 -そこで、mrubyではできる限り表記を簡便にするために、便宜上、著作権者名を -"mruby developers"とすることにいたしました。 -今後、新たにmrubyへのコミットされるコードについては、著作権を保持したまま、 -"mruby developers"の一員としてMITライセンスでの配布をお願いしたいと -考えています。 -(コミットしたコードの著作権を譲渡や放棄をお願いするものではありません。 - 実質の著作者名はAUTHORSファイルに表記いたします。) - -尚、その他のライセンスでの配布やGPL由来のコードのコミットについては -別途ご相談ください。 - - -* 著者 - -AUTHORS ファイルを参照してください。 - - -コメント,バグレポートその他は [email protected] まで. -------------------------------------------------------- -created at: Fri Apr 20 11:57:36 JST 2012 -Local variables: -mode: indented-text -end: diff --git a/README.ja.md b/README.ja.md index 75cb10d84..ec3c6166d 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 clone https://github.com/mruby/mruby.git -他に開発中のブランチの一覧は次のコマンドで見られます. +他に開発中のブランチの一覧は次のコマンドで見られます。 - $ git .... + $ git branch -r ## ホームページ -(まだ準備中です。ただいま鋭意製作中です。) +まだ準備中です。ただいま鋭意製作中です。 mrubyのホームページのURLは http://www.mruby.org/ -です. +になる予定です。 ## メーリングリスト @@ -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 ファイルを参照してください。 - - -コメント,バグレポートその他は - - -まで. +<http://github.com/mruby/mruby>にpull requestを送ってください。 +pull requestに含まれるコードについてMITライセンスでの配布を承諾したものとみなします。 +もし、mruby developersとして名前を残したいということであれば、 +pull requestにAUTHORSファイルへの修正を含めてください。 @@ -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 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. ## 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.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 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,67 +42,74 @@ 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 +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) +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 to the mruby mailing list....[T.B.D.] ## How to compile and install -See the file INSTALL. +See the INSTALL file. -## Copying +## License -See the file COPYING. +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 - -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 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. -## The Author +## Note for License -See the file AUTHORS. - - -Feel free to send comments and bug reports to the author. Here is the -author's latest mail address: +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 +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 the copyright name +to make it simple conventionally. +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 another license. +## How to Contribute +Send pull request to <http://github.com/mruby/mruby>. 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. 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以外削除) -* 気づいたら書き加える diff --git a/include/mrbconf.h b/include/mrbconf.h index 24dc18919..f87e2ef43 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -28,15 +28,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 -#define SIZEOF___INT64 0 -#define SIZEOF_VOIDP 4 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 8 - #ifndef FALSE # define FALSE 0 #endif diff --git a/include/mruby.h b/include/mruby.h index b1ee8dcfc..f0d726d32 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -76,7 +76,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) @@ -135,7 +135,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; @@ -389,6 +389,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 @@ -561,60 +565,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 @@ -640,7 +590,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/mrblib/Makefile b/mrblib/Makefile index 0192ec941..ef60654fd 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -59,5 +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`" diff --git a/src/Makefile b/src/Makefile index ea3681dce..fb5483a72 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 @@ -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/src/array.c b/src/array.c index 035feead5..1b92be560 100644 --- a/src/array.c +++ b/src/array.c @@ -40,10 +40,8 @@ mrb_value mrb_ary_new_capa(mrb_state *mrb, size_t capa) { struct RArray *a; + size_t blen; - 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"); @@ -52,10 +50,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; diff --git a/src/cdump.c b/src/cdump.c index 400f446ef..d48139664 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -146,7 +146,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; } diff --git a/src/compile.h b/src/compile.h index 49c8e9cf8..6e6975cbf 100644 --- a/src/compile.h +++ b/src/compile.h @@ -31,6 +31,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; @@ -61,14 +67,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/encoding.c b/src/encoding.c index 2df294e20..ed30a222a 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -917,6 +917,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) { @@ -407,8 +407,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; diff --git a/src/kernel.c b/src/kernel.c index dbc17940e..40db88b12 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -37,85 +37,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) { @@ -123,11 +50,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; } @@ -162,19 +110,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); @@ -429,7 +367,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); @@ -455,11 +392,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; } } @@ -1000,7 +935,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) { @@ -1012,25 +946,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; } @@ -1039,7 +967,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) { @@ -1050,22 +977,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; } @@ -1332,14 +1254,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 */ diff --git a/src/numeric.c b/src/numeric.c index d30e683fd..2462e63df 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -83,34 +83,9 @@ #define mrb_rational_raw1(x) mrb_rational_raw(x, INT2FIX(1)) -#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 - -#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 @@ -975,80 +950,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) { @@ -1060,7 +961,6 @@ mrb_fix2int(mrb_value val) { return mrb_fixnum(val); } -#endif mrb_value mrb_num2fix(mrb_state *mrb, mrb_value val) @@ -1071,59 +971,10 @@ 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); } -#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 * @@ -1199,7 +1050,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; @@ -1224,7 +1075,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)&&((n)>=-SQRT_LONG_MAX)) @@ -1250,21 +1101,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; @@ -1276,7 +1118,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: @@ -1610,9 +1451,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/parse.y b/src/parse.y index ef49338ac..2c02a31cb 100644 --- a/src/parse.y +++ b/src/parse.y @@ -281,7 +281,7 @@ new_true(parser_state *p) return list1((node*)NODE_TRUE); } -// (:true) +// (:false) static node* new_false(parser_state *p) { @@ -2904,8 +2904,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++; } @@ -2921,8 +2934,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 @@ -2982,8 +3009,13 @@ nextc(parser_state *p) c = *p->s++; } if (c == '\n') { - p->lineno++; - p->column = 0; + if (p->column < 0) { + p->column++; // pushback caused an underflow + } + else { + p->lineno++; + p->column = 0; + } // must understand heredoc } else { @@ -4610,6 +4642,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; @@ -4648,6 +4682,22 @@ mrb_parse_nstring(mrb_state *mrb, char *s, size_t len) } 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) { return mrb_parse_nstring(mrb, s, strlen(s)); diff --git a/src/proc.c b/src/proc.c index 94a8d8465..d4d57c6aa 100644 --- a/src/proc.c +++ b/src/proc.c @@ -56,6 +56,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) { @@ -92,6 +108,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); @@ -1778,11 +1778,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 @@ -2964,48 +2960,6 @@ mrb_backref_set(mrb_state *mrb, mrb_value val) #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) { const unsigned char *x = xs, *xe = xs + m; @@ -3099,9 +3053,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/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) @@ -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 <stdio.h> #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif #include <string.h> +#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<<i) > size) return 1<<i; + } + return -1; +#else + int newsize; - for (i = 0, newsize = MINSIZE; i < numberof(primes); i++, newsize <<= 1) { + for (i = 0, newsize = MINSIZE; + i < sizeof(primes)/sizeof(primes[0]); + i++, newsize <<= 1) + { if (newsize > 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; @@ -590,118 +404,12 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value) } 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) { 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)(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 <Landon Curt Noll> /\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 <Landon Curt Noll> /\../\ - * - * 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<argc; i+=2) { + st_insert(tbl, (st_data_t)argv[i], (st_data_t)argv[i+1]); + } + st_foreach(tbl, f, (st_data_t)tbl); + st_delete(tbl, (st_data_t*)&argv[1], 0); + st_foreach(tbl, f, (st_data_t)tbl); } +#endif + @@ -9,23 +9,8 @@ extern "C" { #endif -#ifndef RUBY_LIB_PREFIX - -#ifdef RUBY_EXTCONF_H -#include RUBY_EXTCONF_H -#endif -#endif - -#if defined STDC_HEADERS -#include <stddef.h> -#elif defined HAVE_STDLIB_H #include <stdlib.h> -#endif - -#ifdef HAVE_STDINT_H -# include <stdint.h> -#endif -#include <inttypes.h> +#include <stdint.h> #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 ... @@ -64,27 +45,15 @@ 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* */ }; -#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; }; @@ -94,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 */ diff --git a/src/string.c b/src/string.c index b9c8796e6..e774b7032 100644 --- a/src/string.c +++ b/src/string.c @@ -217,38 +217,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 @@ -1173,63 +1147,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) { @@ -1289,13 +1206,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); @@ -1412,46 +1322,6 @@ mrb_enc_strlen_cr(mrb_state *mrb, const char *p, const char *e, mrb_encoding *en #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) { const unsigned char *x = xs, *xe = xs + m; @@ -1470,6 +1340,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) { @@ -1490,12 +1361,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 @@ -1513,33 +1379,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); @@ -5000,9 +4839,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'; diff --git a/src/variable.c b/src/variable.c index 5c3c493d8..9804ab2ef 100644 --- a/src/variable.c +++ b/src/variable.c @@ -4,6 +4,7 @@ ** See Copyright Notice in mruby.h */ +#include <stdio.h> #include "mruby.h" #include "mruby/class.h" #include "ritehash.h" diff --git a/src/variable.h b/src/variable.h index bd00b2f1f..9076fcf7c 100644 --- a/src/variable.h +++ b/src/variable.h @@ -36,7 +36,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); 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`" 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 |
