summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--MITL24
-rw-r--r--Makefile2
-rw-r--r--README.md26
-rw-r--r--doc/compile/README.md56
-rw-r--r--doc/language/Core.md956
-rw-r--r--doc/language/README.md2
-rw-r--r--doc/language/mrbdoc/lib/mrbdoc_docu.rb10
-rw-r--r--doc/mrbgems/README.md16
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake2
-rw-r--r--examples/mrbgems/c_extension_example/mrbgem.rake2
-rw-r--r--examples/mrbgems/ruby_extension_example/mrbgem.rake2
-rw-r--r--examples/targets/build_config_ArduinoDue.rb (renamed from examples/targets/ArduinoDue.rb)26
-rw-r--r--examples/targets/build_config_IntelGalileo.rb (renamed from examples/targets/IntelGalileo.rb)52
-rw-r--r--examples/targets/build_config_chipKITMax32.rb (renamed from examples/targets/chipKitMax32.rb)33
-rw-r--r--include/mruby.h3
-rw-r--r--include/mruby/dump.h1
-rw-r--r--include/mruby/error.h3
-rw-r--r--include/mruby/numeric.h35
-rw-r--r--include/mruby/range.h1
-rw-r--r--include/mruby/value.h22
-rw-r--r--mrbgems/default.gembox3
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb5
-rw-r--r--mrbgems/mruby-array-ext/src/array.c13
-rw-r--r--mrbgems/mruby-array-ext/test/array.rb22
-rw-r--r--mrbgems/mruby-bin-mirb/mrbgem.rake10
-rw-r--r--mrbgems/mruby-bin-mirb/tools/mirb/mirb.c43
-rw-r--r--mrbgems/mruby-bin-mruby-config/mruby-config2
-rw-r--r--mrbgems/mruby-bin-mruby/tools/mruby/mruby.c2
-rw-r--r--mrbgems/mruby-enum-ext/mrblib/enum.rb6
-rw-r--r--mrbgems/mruby-enum-ext/test/enum.rb2
-rw-r--r--mrbgems/mruby-enum-lazy/mrbgem.rake3
-rw-r--r--mrbgems/mruby-enum-lazy/mrblib/lazy.rb2
-rw-r--r--mrbgems/mruby-enumerator/mrbgem.rake2
-rw-r--r--mrbgems/mruby-enumerator/mrblib/enumerator.rb10
-rw-r--r--mrbgems/mruby-enumerator/test/enumerator.rb2
-rw-r--r--mrbgems/mruby-fiber/src/fiber.c10
-rw-r--r--mrbgems/mruby-hash-ext/mrblib/hash.rb159
-rw-r--r--mrbgems/mruby-hash-ext/test/hash.rb78
-rw-r--r--mrbgems/mruby-kernel-ext/mrbgem.rake5
-rw-r--r--mrbgems/mruby-kernel-ext/src/kernel.c36
-rw-r--r--mrbgems/mruby-kernel-ext/test/kernel.rb18
-rw-r--r--mrbgems/mruby-math/src/math.c39
-rw-r--r--mrbgems/mruby-objectspace/src/mruby_objectspace.c22
-rw-r--r--mrbgems/mruby-random/src/mt19937ar.c42
-rw-r--r--mrbgems/mruby-random/src/random.c66
-rw-r--r--mrbgems/mruby-random/test/random.rb16
-rw-r--r--mrbgems/mruby-sprintf/src/sprintf.c2
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb8
-rw-r--r--mrbgems/mruby-string-utf8/test/string.rb4
-rw-r--r--mrbgems/mruby-struct/src/struct.c89
-rw-r--r--mrbgems/mruby-struct/test/struct.rb12
-rw-r--r--mrbgems/mruby-symbol-ext/mrblib/symbol.rb2
-rw-r--r--mrbgems/mruby-time/mrblib/time.rb9
-rw-r--r--mrbgems/mruby-time/src/time.c24
-rw-r--r--mrbgems/mruby-time/test/time.rb302
-rw-r--r--mrbgems/mruby-toplevel-ext/test/toplevel.rb2
-rw-r--r--mrblib/enum.rb2
-rw-r--r--mrblib/error.rb4
-rw-r--r--mrblib/hash.rb58
-rw-r--r--mrblib/mrblib.rake2
-rw-r--r--src/array.c15
-rw-r--r--src/codegen.c2
-rw-r--r--src/dump.c8
-rw-r--r--src/error.c35
-rw-r--r--src/gc.c6
-rw-r--r--src/hash.c2
-rw-r--r--src/kernel.c88
-rw-r--r--src/load.c4
-rw-r--r--src/mruby_core.rake2
-rw-r--r--src/numeric.c47
-rw-r--r--src/parse.y49
-rw-r--r--src/print.c2
-rw-r--r--src/proc.c2
-rw-r--r--src/range.c80
-rw-r--r--src/string.c117
-rw-r--r--src/variable.c2
-rw-r--r--src/vm.c111
-rw-r--r--tasks/mrbgems_test.rake4
-rw-r--r--tasks/mruby_build.rake4
-rw-r--r--tasks/mruby_build_commands.rake12
-rw-r--r--tasks/ruby_ext.rake2
-rw-r--r--tasks/toolchains/gcc.rake25
-rw-r--r--tasks/toolchains/visualcpp.rake3
-rw-r--r--test/assert.rb2
-rw-r--r--test/driver.c21
-rw-r--r--test/t/array.rb5
-rw-r--r--test/t/bs_block.rb7
-rw-r--r--test/t/exception.rb66
-rw-r--r--test/t/hash.rb8
-rw-r--r--test/t/integer.rb26
-rw-r--r--test/t/kernel.rb14
-rw-r--r--test/t/methods.rb2
-rw-r--r--test/t/module.rb12
-rw-r--r--test/t/proc.rb57
-rw-r--r--test/t/range.rb16
-rw-r--r--test/t/string.rb14
-rw-r--r--test/t/syntax.rb6
97 files changed, 2043 insertions, 1247 deletions
diff --git a/MITL b/MITL
index 6ddb85c47..59400498f 100644
--- a/MITL
+++ b/MITL
@@ -1,20 +1,20 @@
Copyright (c) 2014 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
+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
+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
+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.
diff --git a/Makefile b/Makefile
index 9a7263872..4912f17e1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
# mruby is using Rake (http://rake.rubyforge.org) as a build tool.
-# We provide a minimalistic version called minirake inside of our
+# We provide a minimalistic version called minirake inside of our
# codebase.
RAKE = ruby ./minirake
diff --git a/README.md b/README.md
index ffadfeb4f..dd6d9af22 100644
--- a/README.md
+++ b/README.md
@@ -68,22 +68,22 @@ documentation with examples under *examples/mrbgems*.
Copyright (c) 2014 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
+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
+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
+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
@@ -91,7 +91,7 @@ DEALINGS IN THE SOFTWARE.
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
+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.
diff --git a/doc/compile/README.md b/doc/compile/README.md
index 19bcf1ac6..8928a0086 100644
--- a/doc/compile/README.md
+++ b/doc/compile/README.md
@@ -33,7 +33,7 @@ customized path using the *$MRUBY_CONFIG* environment variable.
To compile just call ```./minirake``` inside of the mruby source root. To
generate and execute the test tools call ```./minirake test```. To clean
-all build files call ```./minirake clean```. To see full command line on
+all build files call ```./minirake clean```. To see full command line on
build, call ```./minirake -v```.
## Build Configuration
@@ -110,6 +110,34 @@ Configuration of the C compiler binary, flags and include paths.
cc.compile_options = ...
end
+C Compiler has header searcher to detect installed library.
+
+If you need a include path of header file use ```search_header_path```:
+
+ # Searches ```iconv.h```.
+ # If found it will return include path of the header file.
+ # Otherwise it will return nil .
+ fail 'iconv.h not found' unless conf.cc.search_header_path 'iconv.h'
+
+If you need a full file name of header file use ```search_header```:
+
+ # Searches ```iconv.h```.
+ # If found it will return full path of the header file.
+ # Otherwise it will return nil .
+ iconv_h = conf.cc.search_header 'iconv.h'
+ print "iconv.h found: #{iconv_h}\n"
+
+Header searcher uses compiler's ```include_paths``` by default.
+When you are using GCC toolchain (including clang toolchain since its base is gcc toolchain)
+it will use compiler specific include paths too. (For example ```/usr/local/include```, ```/usr/include```)
+
+If you need a special header search paths define a singleton method ```header_search_paths``` to C compiler:
+
+ def conf.cc.header_search_paths
+ ['/opt/local/include'] + include_paths
+ end
+
+
### Linker
Configuration of the Linker binary, flags and library paths.
@@ -284,21 +312,21 @@ root directory. The structure of this directory will look like this:
+- mirb
|
+- mrbc
- |
+ |
+- mruby
The compilation workflow will look like this:
-* compile all files under *src* (object files will be stored
+* compile all files under *src* (object files will be stored
in *build/host/src*)
* generate parser grammar out of *src/parse.y* (generated
result will be stored in *build/host/src/y.tab.c*)
* compile *build/host/src/y.tab.c* to *build/host/src/y.tab.o*
* create *build/host/lib/libmruby_core.a* out of all object files (C only)
* create ```build/host/bin/mrbc``` by compiling *tools/mrbc/mrbc.c* and
-linking with *build/host/lib/libmruby_core.a*
+linking with *build/host/lib/libmruby_core.a*
* create *build/host/mrblib/mrblib.c* by compiling all \*.rb files
under *mrblib* with ```build/host/bin/mrbc```
-* compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
+* compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/host/lib/libmruby.a* out of all object files (C and Ruby)
* create ```build/host/bin/mruby``` by compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
linking with *build/host/lib/libmruby.a*
@@ -336,8 +364,8 @@ like this:
| +- mirb
| |
| +- mrbc
- | |
- | +- mruby
+ | |
+ | +- mruby
+- i386
|
+- bin <- Cross-compiled Binaries
@@ -355,7 +383,7 @@ like this:
+- mirb
|
+- mrbc
- |
+ |
+- mruby
An extra directory is created for the target platform. In case you
@@ -365,7 +393,7 @@ build direcotry.
The cross compilation workflow starts in the same way as the normal
compilation by compiling all *native* libraries and binaries.
Afterwards the cross compilation process proceeds like this:
-* cross-compile all files under *src* (object files will be stored
+* cross-compile all files under *src* (object files will be stored
in *build/i386/src*)
* generate parser grammar out of *src/parse.y* (generated
result will be stored in *build/i386/src/y.tab.c*)
@@ -380,7 +408,7 @@ linking with *build/i386/lib/libmruby.a*
linking with *build/i386/lib/libmruby.a*
* create *build/i386/lib/libmruby_core.a* out of all object files (C only)
* create ```build/i386/bin/mrbc``` by cross-compiling *tools/mrbc/mrbc.c* and
-linking with *build/i386/lib/libmruby_core.a*
+linking with *build/i386/lib/libmruby_core.a*
```
_______________________________________________________________
@@ -406,15 +434,15 @@ linking with *build/i386/lib/libmruby_core.a*
### Minimal Library
-To build a minimal mruby library you need to use the Cross Compiling
-feature due to the reason that there are functions (i.e. stdio) which
+To build a minimal mruby library you need to use the Cross Compiling
+feature due to the reason that there are functions (i.e. stdio) which
can't be disabled for the main build.
MRuby::CrossBuild.new('Minimal') do |conf|
toolchain :gcc
conf.cc.defines = %w(DISABLE_STDIO)
- conf.bins = []
+ conf.bins = []
end
This configuration defines a cross compile build called 'Minimal' which
@@ -426,5 +454,5 @@ all usages of stdio and doesn't compile any binaries (i.e. mrbc).
mruby's build process includes a test environment. In case you start the testing
of mruby, a native binary called ```mrbtest``` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
-of a cross-compilation an additional cross-compiled *mrbtest* binary is
+of a cross-compilation an additional cross-compiled *mrbtest* binary is
generated. You can copy this binary and run on your target system.
diff --git a/doc/language/Core.md b/doc/language/Core.md
index 37f9eb474..033939865 100644
--- a/doc/language/Core.md
+++ b/doc/language/Core.md
@@ -10,173 +10,173 @@ ISO Code | Mixins | Source File
#### []
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.4.1 | src/array.c | mrb_ary_s_create
+15.2.12.4.1 | src/array.c | mrb_ary_s_create
### Methods
#### *
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.2 | src/array.c | mrb_ary_times
+15.2.12.5.2 | src/array.c | mrb_ary_times
#### +
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.1 | src/array.c | mrb_ary_plus
+15.2.12.5.1 | src/array.c | mrb_ary_plus
#### <<
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.3 | src/array.c | mrb_ary_push_m
+15.2.12.5.3 | src/array.c | mrb_ary_push_m
#### []
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.4 | src/array.c | mrb_ary_aget
+15.2.12.5.4 | src/array.c | mrb_ary_aget
#### []=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.5 | src/array.c | mrb_ary_aset
+15.2.12.5.5 | src/array.c | mrb_ary_aset
#### __ary_cmp
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/array.c | mrb_ary_cmp
+n/a | src/array.c | mrb_ary_cmp
#### __ary_eq
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/array.c | mrb_ary_eq
+n/a | src/array.c | mrb_ary_eq
#### clear
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.6 | src/array.c | mrb_ary_clear
+15.2.12.5.6 | src/array.c | mrb_ary_clear
#### concat
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.8 | src/array.c | mrb_ary_concat_m
+15.2.12.5.8 | src/array.c | mrb_ary_concat_m
#### delete_at
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.9 | src/array.c | mrb_ary_delete_at
+15.2.12.5.9 | src/array.c | mrb_ary_delete_at
#### empty?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.12 | src/array.c | mrb_ary_empty_p
+15.2.12.5.12 | src/array.c | mrb_ary_empty_p
#### first
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.13 | src/array.c | mrb_ary_first
+15.2.12.5.13 | src/array.c | mrb_ary_first
#### index
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.14 | src/array.c | mrb_ary_index_m
+15.2.12.5.14 | src/array.c | mrb_ary_index_m
#### initialize_copy
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.16 | src/array.c | mrb_ary_replace_m
+15.2.12.5.16 | src/array.c | mrb_ary_replace_m
#### join
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.17 | src/array.c | mrb_ary_join_m
+15.2.12.5.17 | src/array.c | mrb_ary_join_m
#### last
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.18 | src/array.c | mrb_ary_last
+15.2.12.5.18 | src/array.c | mrb_ary_last
#### length
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.19 | src/array.c | mrb_ary_size
+15.2.12.5.19 | src/array.c | mrb_ary_size
#### pop
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.21 | src/array.c | mrb_ary_pop
+15.2.12.5.21 | src/array.c | mrb_ary_pop
#### push
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.22 | src/array.c | mrb_ary_push_m
+15.2.12.5.22 | src/array.c | mrb_ary_push_m
#### replace
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.23 | src/array.c | mrb_ary_replace_m
+15.2.12.5.23 | src/array.c | mrb_ary_replace_m
#### reverse
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.24 | src/array.c | mrb_ary_reverse
+15.2.12.5.24 | src/array.c | mrb_ary_reverse
#### reverse!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.25 | src/array.c | mrb_ary_reverse_bang
+15.2.12.5.25 | src/array.c | mrb_ary_reverse_bang
#### rindex
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.26 | src/array.c | mrb_ary_rindex_m
+15.2.12.5.26 | src/array.c | mrb_ary_rindex_m
#### shift
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.27 | src/array.c | mrb_ary_shift
+15.2.12.5.27 | src/array.c | mrb_ary_shift
#### size
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.28 | src/array.c | mrb_ary_size
+15.2.12.5.28 | src/array.c | mrb_ary_size
#### slice
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.29 | src/array.c | mrb_ary_aget
+15.2.12.5.29 | src/array.c | mrb_ary_aget
#### unshift
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.12.5.30 | src/array.c | mrb_ary_unshift_m
+15.2.12.5.30 | src/array.c | mrb_ary_unshift_m
## Exception
@@ -188,53 +188,53 @@ ISO Code | Mixins | Source File
#### exception
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/class.c | mrb_instance_new
+n/a | src/class.c | mrb_instance_new
### Methods
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_equal
+n/a | src/error.c | exc_equal
#### backtrace
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/backtrace.c | mrb_exc_backtrace
+n/a | src/backtrace.c | mrb_exc_backtrace
#### exception
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_exception
+n/a | src/error.c | exc_exception
#### initialize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_initialize
+n/a | src/error.c | exc_initialize
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_inspect
+n/a | src/error.c | exc_inspect
#### message
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_message
+n/a | src/error.c | exc_message
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/error.c | exc_to_s
+n/a | src/error.c | exc_to_s
## FalseClass
@@ -246,33 +246,33 @@ n/a | n/a | src/object.c
#### &
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.6.3.1 | src/object.c | false_and
+15.2.6.3.1 | src/object.c | false_and
#### ^
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.6.3.2 | src/object.c | false_xor
+15.2.6.3.2 | src/object.c | false_xor
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/object.c | false_to_s
+n/a | src/object.c | false_to_s
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.6.3.3 | src/object.c | false_to_s
+15.2.6.3.3 | src/object.c | false_to_s
#### |
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.6.3.4 | src/object.c | false_or
+15.2.6.3.4 | src/object.c | false_or
## Fixnum
@@ -284,105 +284,105 @@ n/a | n/a | src/numeric.c
#### %
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.5 | src/numeric.c | fix_mod
+15.2.8.3.5 | src/numeric.c | fix_mod
#### &
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.9 | src/numeric.c | fix_and
+15.2.8.3.9 | src/numeric.c | fix_and
#### *
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.3 | src/numeric.c | fix_mul
+15.2.8.3.3 | src/numeric.c | fix_mul
#### +
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.1 | src/numeric.c | fix_plus
+15.2.8.3.1 | src/numeric.c | fix_plus
#### -
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.2 | src/numeric.c | fix_minus
+15.2.8.3.2 | src/numeric.c | fix_minus
#### <<
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.12 | src/numeric.c | fix_lshift
+15.2.8.3.12 | src/numeric.c | fix_lshift
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.7 | src/numeric.c | fix_equal
+15.2.8.3.7 | src/numeric.c | fix_equal
#### >>
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.13 | src/numeric.c | fix_rshift
+15.2.8.3.13 | src/numeric.c | fix_rshift
#### ^
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.11 | src/numeric.c | fix_xor
+15.2.8.3.11 | src/numeric.c | fix_xor
#### divmod
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.30 | src/numeric.c | fix_divmod
+15.2.8.3.30 | src/numeric.c | fix_divmod
#### eql?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.16 | src/numeric.c | fix_eql
+15.2.8.3.16 | src/numeric.c | fix_eql
#### hash
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.18 | src/numeric.c | flo_hash
+15.2.8.3.18 | src/numeric.c | flo_hash
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | fix_to_s
+n/a | src/numeric.c | fix_to_s
#### to_f
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.23 | src/numeric.c | fix_to_f
+15.2.8.3.23 | src/numeric.c | fix_to_f
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.25 | src/numeric.c | fix_to_s
+15.2.8.3.25 | src/numeric.c | fix_to_s
#### |
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.10 | src/numeric.c | fix_or
+15.2.8.3.10 | src/numeric.c | fix_or
#### ~
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.8 | src/numeric.c | fix_rev
+15.2.8.3.8 | src/numeric.c | fix_rev
## Float
@@ -394,117 +394,117 @@ ISO Code | Mixins | Source File
#### %
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.5 | src/numeric.c | flo_mod
+15.2.9.3.5 | src/numeric.c | flo_mod
#### *
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.3 | src/numeric.c | flo_mul
+15.2.9.3.3 | src/numeric.c | flo_mul
#### +
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.1 | src/numeric.c | flo_plus
+15.2.9.3.1 | src/numeric.c | flo_plus
#### -
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.2 | src/numeric.c | flo_minus
+15.2.9.3.2 | src/numeric.c | flo_minus
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.7 | src/numeric.c | flo_eq
+15.2.9.3.7 | src/numeric.c | flo_eq
#### ceil
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.8 | src/numeric.c | flo_ceil
+15.2.9.3.8 | src/numeric.c | flo_ceil
#### divmod
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | flo_divmod
+n/a | src/numeric.c | flo_divmod
#### eql?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.16 | src/numeric.c | flo_eql
+15.2.8.3.16 | src/numeric.c | flo_eql
#### finite?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.9 | src/numeric.c | flo_finite_p
+15.2.9.3.9 | src/numeric.c | flo_finite_p
#### floor
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.10 | src/numeric.c | flo_floor
+15.2.9.3.10 | src/numeric.c | flo_floor
#### infinite?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.11 | src/numeric.c | flo_infinite_p
+15.2.9.3.11 | src/numeric.c | flo_infinite_p
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | flo_to_s
+n/a | src/numeric.c | flo_to_s
#### nan?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | flo_nan_p
+n/a | src/numeric.c | flo_nan_p
#### round
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.12 | src/numeric.c | flo_round
+15.2.9.3.12 | src/numeric.c | flo_round
#### to_f
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.13 | src/numeric.c | flo_to_f
+15.2.9.3.13 | src/numeric.c | flo_to_f
#### to_i
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.14 | src/numeric.c | flo_truncate
+15.2.9.3.14 | src/numeric.c | flo_truncate
#### to_int
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | flo_truncate
+n/a | src/numeric.c | flo_truncate
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.16 | src/numeric.c | flo_to_s
+15.2.9.3.16 | src/numeric.c | flo_to_s
#### truncate
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.15 | src/numeric.c | flo_truncate
+15.2.9.3.15 | src/numeric.c | flo_truncate
## Hash
@@ -516,147 +516,147 @@ ISO Code | Mixins | Source File
#### []
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.2 | src/hash.c | mrb_hash_aget
+15.2.13.4.2 | src/hash.c | mrb_hash_aget
#### []=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.3 | src/hash.c | mrb_hash_aset
+15.2.13.4.3 | src/hash.c | mrb_hash_aset
#### __delete
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.8 | src/hash.c | mrb_hash_delete
+15.2.13.4.8 | src/hash.c | mrb_hash_delete
#### clear
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.4 | src/hash.c | mrb_hash_clear
+15.2.13.4.4 | src/hash.c | mrb_hash_clear
#### default
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.5 | src/hash.c | mrb_hash_default
+15.2.13.4.5 | src/hash.c | mrb_hash_default
#### default=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.6 | src/hash.c | mrb_hash_set_default
+15.2.13.4.6 | src/hash.c | mrb_hash_set_default
#### default_proc
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.7 | src/hash.c | mrb_hash_default_proc
+15.2.13.4.7 | src/hash.c | mrb_hash_default_proc
#### default_proc=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.7 | src/hash.c | mrb_hash_set_default_proc
+15.2.13.4.7 | src/hash.c | mrb_hash_set_default_proc
#### dup
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/hash.c | mrb_hash_dup
+n/a | src/hash.c | mrb_hash_dup
#### empty?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.12 | src/hash.c | mrb_hash_empty_p
+15.2.13.4.12 | src/hash.c | mrb_hash_empty_p
#### has_key?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.13 | src/hash.c | mrb_hash_has_key
+15.2.13.4.13 | src/hash.c | mrb_hash_has_key
#### has_value?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.14 | src/hash.c | mrb_hash_has_value
+15.2.13.4.14 | src/hash.c | mrb_hash_has_value
#### include?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.15 | src/hash.c | mrb_hash_has_key
+15.2.13.4.15 | src/hash.c | mrb_hash_has_key
#### initialize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.16 | src/hash.c | mrb_hash_init
+15.2.13.4.16 | src/hash.c | mrb_hash_init
#### key?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.18 | src/hash.c | mrb_hash_has_key
+15.2.13.4.18 | src/hash.c | mrb_hash_has_key
#### keys
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.19 | src/hash.c | mrb_hash_keys
+15.2.13.4.19 | src/hash.c | mrb_hash_keys
#### length
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.20 | src/hash.c | mrb_hash_size_m
+15.2.13.4.20 | src/hash.c | mrb_hash_size_m
#### member?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.21 | src/hash.c | mrb_hash_has_key
+15.2.13.4.21 | src/hash.c | mrb_hash_has_key
#### shift
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.24 | src/hash.c | mrb_hash_shift
+15.2.13.4.24 | src/hash.c | mrb_hash_shift
#### size
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.25 | src/hash.c | mrb_hash_size_m
+15.2.13.4.25 | src/hash.c | mrb_hash_size_m
#### store
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.26 | src/hash.c | mrb_hash_aset
+15.2.13.4.26 | src/hash.c | mrb_hash_aset
#### to_hash
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.29 | src/hash.c | mrb_hash_to_hash
+15.2.13.4.29 | src/hash.c | mrb_hash_to_hash
#### value?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.27 | src/hash.c | mrb_hash_has_value
+15.2.13.4.27 | src/hash.c | mrb_hash_has_value
#### values
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.13.4.28 | src/hash.c | mrb_hash_values
+15.2.13.4.28 | src/hash.c | mrb_hash_values
## Integer
@@ -668,15 +668,15 @@ ISO Code | Mixins | Source File
#### to_i
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.24 | src/numeric.c | int_to_i
+15.2.8.3.24 | src/numeric.c | int_to_i
#### to_int
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | int_to_i
+n/a | src/numeric.c | int_to_i
## NilClass
@@ -688,39 +688,39 @@ n/a | n/a | src/object.c
#### &
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.4.3.1 | src/object.c | false_and
+15.2.4.3.1 | src/object.c | false_and
#### ^
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.4.3.2 | src/object.c | false_xor
+15.2.4.3.2 | src/object.c | false_xor
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/object.c | nil_inspect
+n/a | src/object.c | nil_inspect
#### nil?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.4.3.4 | src/object.c | mrb_true
+15.2.4.3.4 | src/object.c | mrb_true
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.4.3.5 | src/object.c | nil_to_s
+15.2.4.3.5 | src/object.c | nil_to_s
#### |
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.4.3.3 | src/object.c | false_or
+15.2.4.3.3 | src/object.c | false_or
## Numeric
@@ -732,27 +732,27 @@ ISO Code | Mixins | Source File
#### **
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/numeric.c | num_pow
+n/a | src/numeric.c | num_pow
#### /
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.8.3.4 | src/numeric.c | num_div
+15.2.8.3.4 | src/numeric.c | num_div
#### <=>
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.9.3.6 | src/numeric.c | num_cmp
+15.2.9.3.6 | src/numeric.c | num_cmp
#### quo
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.7.4.5 | src/numeric.c | num_div
+15.2.7.4.5 | src/numeric.c | num_div
## Proc
@@ -764,21 +764,21 @@ ISO Code | Mixins | Source File
#### arity
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/proc.c | mrb_proc_arity
+n/a | src/proc.c | mrb_proc_arity
#### initialize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/proc.c | mrb_proc_initialize
+n/a | src/proc.c | mrb_proc_initialize
#### initialize_copy
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/proc.c | mrb_proc_init_copy
+n/a | src/proc.c | mrb_proc_init_copy
## Range
@@ -790,93 +790,87 @@ ISO Code | Mixins | Source File
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.1 | src/range.c | mrb_range_eq
+15.2.14.4.1 | src/range.c | mrb_range_eq
#### ===
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.2 | src/range.c | mrb_range_include
+15.2.14.4.2 | src/range.c | mrb_range_include
#### begin
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.3 | src/range.c | mrb_range_beg
-
-#### each
-
-ISO Code | Source File | C Function
---- | --- | ---
-15.2.14.4.4 | src/range.c | mrb_range_each
+15.2.14.4.3 | src/range.c | mrb_range_beg
#### end
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.5 | src/range.c | mrb_range_end
+15.2.14.4.5 | src/range.c | mrb_range_end
#### eql?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.14 | src/range.c | range_eql
+15.2.14.4.14 | src/range.c | range_eql
#### exclude_end?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.6 | src/range.c | mrb_range_excl
+15.2.14.4.6 | src/range.c | mrb_range_excl
#### first
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.7 | src/range.c | mrb_range_beg
+15.2.14.4.7 | src/range.c | mrb_range_beg
#### include?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.8 | src/range.c | mrb_range_include
+15.2.14.4.8 | src/range.c | mrb_range_include
#### initialize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.9 | src/range.c | mrb_range_initialize
+15.2.14.4.9 | src/range.c | mrb_range_initialize
#### initialize_copy
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.15 | src/range.c | range_initialize_copy
+15.2.14.4.15 | src/range.c | range_initialize_copy
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.13 | src/range.c | range_inspect
+15.2.14.4.13 | src/range.c | range_inspect
#### last
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.10 | src/range.c | mrb_range_end
+15.2.14.4.10 | src/range.c | mrb_range_end
#### member?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.11 | src/range.c | mrb_range_include
+15.2.14.4.11 | src/range.c | mrb_range_include
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.14.4.12 | src/range.c | range_to_s
+15.2.14.4.12 | src/range.c | range_to_s
## RuntimeError
@@ -906,237 +900,237 @@ ISO Code | Mixins | Source File
#### *
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.5 | src/string.c | mrb_str_times
+15.2.10.5.5 | src/string.c | mrb_str_times
#### +
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.4 | src/string.c | mrb_str_plus_m
+15.2.10.5.4 | src/string.c | mrb_str_plus_m
#### <=>
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.1 | src/string.c | mrb_str_cmp_m
+15.2.10.5.1 | src/string.c | mrb_str_cmp_m
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.2 | src/string.c | mrb_str_equal_m
+15.2.10.5.2 | src/string.c | mrb_str_equal_m
#### []
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.6 | src/string.c | mrb_str_aref_m
+15.2.10.5.6 | src/string.c | mrb_str_aref_m
#### bytes
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/string.c | mrb_str_bytes
+n/a | src/string.c | mrb_str_bytes
#### bytesize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/string.c | mrb_str_bytesize
+n/a | src/string.c | mrb_str_bytesize
#### capitalize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.7 | src/string.c | mrb_str_capitalize
+15.2.10.5.7 | src/string.c | mrb_str_capitalize
#### capitalize!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.8 | src/string.c | mrb_str_capitalize_bang
+15.2.10.5.8 | src/string.c | mrb_str_capitalize_bang
#### chomp
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.9 | src/string.c | mrb_str_chomp
+15.2.10.5.9 | src/string.c | mrb_str_chomp
#### chomp!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.10 | src/string.c | mrb_str_chomp_bang
+15.2.10.5.10 | src/string.c | mrb_str_chomp_bang
#### chop
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.11 | src/string.c | mrb_str_chop
+15.2.10.5.11 | src/string.c | mrb_str_chop
#### chop!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.12 | src/string.c | mrb_str_chop_bang
+15.2.10.5.12 | src/string.c | mrb_str_chop_bang
#### downcase
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.13 | src/string.c | mrb_str_downcase
+15.2.10.5.13 | src/string.c | mrb_str_downcase
#### downcase!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.14 | src/string.c | mrb_str_downcase_bang
+15.2.10.5.14 | src/string.c | mrb_str_downcase_bang
#### empty?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.16 | src/string.c | mrb_str_empty_p
+15.2.10.5.16 | src/string.c | mrb_str_empty_p
#### eql?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.17 | src/string.c | mrb_str_eql
+15.2.10.5.17 | src/string.c | mrb_str_eql
#### hash
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.20 | src/string.c | mrb_str_hash_m
+15.2.10.5.20 | src/string.c | mrb_str_hash_m
#### include?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.21 | src/string.c | mrb_str_include
+15.2.10.5.21 | src/string.c | mrb_str_include
#### index
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.22 | src/string.c | mrb_str_index_m
+15.2.10.5.22 | src/string.c | mrb_str_index_m
#### initialize
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.23 | src/string.c | mrb_str_init
+15.2.10.5.23 | src/string.c | mrb_str_init
#### initialize_copy
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.24 | src/string.c | mrb_str_replace
+15.2.10.5.24 | src/string.c | mrb_str_replace
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.46 | src/string.c | mrb_str_inspect
+15.2.10.5.46 | src/string.c | mrb_str_inspect
#### intern
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.25 | src/string.c | mrb_str_intern
+15.2.10.5.25 | src/string.c | mrb_str_intern
#### length
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.26 | src/string.c | mrb_str_size
+15.2.10.5.26 | src/string.c | mrb_str_size
#### replace
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.28 | src/string.c | mrb_str_replace
+15.2.10.5.28 | src/string.c | mrb_str_replace
#### reverse
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.29 | src/string.c | mrb_str_reverse
+15.2.10.5.29 | src/string.c | mrb_str_reverse
#### reverse!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.30 | src/string.c | mrb_str_reverse_bang
+15.2.10.5.30 | src/string.c | mrb_str_reverse_bang
#### rindex
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.31 | src/string.c | mrb_str_rindex_m
+15.2.10.5.31 | src/string.c | mrb_str_rindex_m
#### size
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.33 | src/string.c | mrb_str_size
+15.2.10.5.33 | src/string.c | mrb_str_size
#### slice
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.34 | src/string.c | mrb_str_aref_m
+15.2.10.5.34 | src/string.c | mrb_str_aref_m
#### split
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.35 | src/string.c | mrb_str_split_m
+15.2.10.5.35 | src/string.c | mrb_str_split_m
#### to_f
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.38 | src/string.c | mrb_str_to_f
+15.2.10.5.38 | src/string.c | mrb_str_to_f
#### to_i
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.39 | src/string.c | mrb_str_to_i
+15.2.10.5.39 | src/string.c | mrb_str_to_i
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.40 | src/string.c | mrb_str_to_s
+15.2.10.5.40 | src/string.c | mrb_str_to_s
#### to_str
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/string.c | mrb_str_to_s
+n/a | src/string.c | mrb_str_to_s
#### to_sym
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.41 | src/string.c | mrb_str_intern
+15.2.10.5.41 | src/string.c | mrb_str_intern
#### upcase
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.42 | src/string.c | mrb_str_upcase
+15.2.10.5.42 | src/string.c | mrb_str_upcase
#### upcase!
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.10.5.43 | src/string.c | mrb_str_upcase_bang
+15.2.10.5.43 | src/string.c | mrb_str_upcase_bang
## Symbol
@@ -1148,39 +1142,39 @@ ISO Code | Mixins | Source File
#### <=>
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/symbol.c | sym_cmp
+n/a | src/symbol.c | sym_cmp
#### ===
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.11.3.1 | src/symbol.c | sym_equal
+15.2.11.3.1 | src/symbol.c | sym_equal
#### id2name
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.11.3.2 | src/symbol.c | mrb_sym_to_s
+15.2.11.3.2 | src/symbol.c | mrb_sym_to_s
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.11.3.5 | src/symbol.c | sym_inspect
+15.2.11.3.5 | src/symbol.c | sym_inspect
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.11.3.3 | src/symbol.c | mrb_sym_to_s
+15.2.11.3.3 | src/symbol.c | mrb_sym_to_s
#### to_sym
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.11.3.4 | src/symbol.c | sym_to_sym
+15.2.11.3.4 | src/symbol.c | sym_to_sym
## SyntaxError
@@ -1198,393 +1192,387 @@ n/a | n/a | src/object.c
#### &
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.5.3.1 | src/object.c | true_and
+15.2.5.3.1 | src/object.c | true_and
#### ^
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.5.3.2 | src/object.c | true_xor
+15.2.5.3.2 | src/object.c | true_xor
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/object.c | true_to_s
+n/a | src/object.c | true_to_s
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.5.3.3 | src/object.c | true_to_s
+15.2.5.3.3 | src/object.c | true_to_s
#### |
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.2.5.3.4 | src/object.c | true_or
+15.2.5.3.4 | src/object.c | true_or
# Core Modules
## Comparable
ISO Code | Source File
---- | ---
+--- | ---
15.3.3 | src/compar.c
## Enumerable
ISO Code | Source File
---- | ---
+--- | ---
15.3.2 | src/enum.c
## GC
ISO Code | Source File
---- | ---
+--- | ---
n/a | src/gc.c
### Class Methods
#### disable
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_disable
+n/a | src/gc.c | gc_disable
#### enable
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_enable
+n/a | src/gc.c | gc_enable
#### generational_mode
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_generational_mode_get
+n/a | src/gc.c | gc_generational_mode_get
#### generational_mode=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_generational_mode_set
+n/a | src/gc.c | gc_generational_mode_set
#### interval_ratio
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_interval_ratio_get
+n/a | src/gc.c | gc_interval_ratio_get
#### interval_ratio=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_interval_ratio_set
+n/a | src/gc.c | gc_interval_ratio_set
#### start
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_start
+n/a | src/gc.c | gc_start
#### step_ratio
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_step_ratio_get
+n/a | src/gc.c | gc_step_ratio_get
#### step_ratio=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_step_ratio_set
+n/a | src/gc.c | gc_step_ratio_set
#### test
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/gc.c | gc_test
+n/a | src/gc.c | gc_test
## Kernel
ISO Code | Source File
---- | ---
+--- | ---
15.3.1 | src/kernel.c
### Class Methods
#### block_given?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.2.2 | src/kernel.c | mrb_f_block_given_p_m
+15.3.1.2.2 | src/kernel.c | mrb_f_block_given_p_m
#### global_variables
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.2.4 | src/kernel.c | mrb_f_global_variables
+15.3.1.2.4 | src/kernel.c | mrb_f_global_variables
#### iterator?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.2.5 | src/kernel.c | mrb_f_block_given_p_m
+15.3.1.2.5 | src/kernel.c | mrb_f_block_given_p_m
#### raise
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.2.12 | src/kernel.c | mrb_f_raise
+15.3.1.2.12 | src/kernel.c | mrb_f_raise
### Methods
#### !=
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/kernel.c | mrb_obj_not_equal_m
+n/a | src/kernel.c | mrb_obj_not_equal_m
#### ==
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.1 | src/kernel.c | mrb_obj_equal_m
+15.3.1.3.1 | src/kernel.c | mrb_obj_equal_m
#### ===
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.2 | src/kernel.c | mrb_equal_m
+15.3.1.3.2 | src/kernel.c | mrb_equal_m
#### __case_eqq
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/kernel.c | mrb_obj_ceqq
+n/a | src/kernel.c | mrb_obj_ceqq
#### __id__
-ISO Code | Source File | C Function
---- | --- | ---
-15.3.1.3.3 | src/kernel.c | mrb_obj_id_m
-
-#### __method__
-
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/kernel.c | mrb_f_method
+15.3.1.3.3 | src/kernel.c | mrb_obj_id_m
#### __send__
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.4 | src/kernel.c | mrb_f_send
+15.3.1.3.4 | src/kernel.c | mrb_f_send
#### block_given?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.6 | src/kernel.c | mrb_f_block_given_p_m
+15.3.1.3.6 | src/kernel.c | mrb_f_block_given_p_m
#### class
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.7 | src/kernel.c | mrb_obj_class_m
+15.3.1.3.7 | src/kernel.c | mrb_obj_class_m
#### clone
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.8 | src/kernel.c | mrb_obj_clone
+15.3.1.3.8 | src/kernel.c | mrb_obj_clone
#### define_singleton_method
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/kernel.c | mod_define_singleton_method
+n/a | src/kernel.c | mod_define_singleton_method
#### dup
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.9 | src/kernel.c | mrb_obj_dup
+15.3.1.3.9 | src/kernel.c | mrb_obj_dup
#### eql?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.10 | src/kernel.c | mrb_obj_equal_m
+15.3.1.3.10 | src/kernel.c | mrb_obj_equal_m
#### equal?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.11 | src/kernel.c | mrb_obj_equal_m
+15.3.1.3.11 | src/kernel.c | mrb_obj_equal_m
#### extend
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.13 | src/kernel.c | mrb_obj_extend_m
+15.3.1.3.13 | src/kernel.c | mrb_obj_extend_m
#### global_variables
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.14 | src/kernel.c | mrb_f_global_variables
+15.3.1.3.14 | src/kernel.c | mrb_f_global_variables
#### hash
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.15 | src/kernel.c | mrb_obj_hash
+15.3.1.3.15 | src/kernel.c | mrb_obj_hash
#### initialize_copy
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.16 | src/kernel.c | mrb_obj_init_copy
+15.3.1.3.16 | src/kernel.c | mrb_obj_init_copy
#### inspect
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.17 | src/kernel.c | mrb_obj_inspect
+15.3.1.3.17 | src/kernel.c | mrb_obj_inspect
#### instance_eval
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.18 | src/kernel.c | mrb_obj_instance_eval
+15.3.1.3.18 | src/kernel.c | mrb_obj_instance_eval
#### instance_of?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.19 | src/kernel.c | obj_is_instance_of
+15.3.1.3.19 | src/kernel.c | obj_is_instance_of
#### instance_variable_defined?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.20 | src/kernel.c | mrb_obj_ivar_defined
+15.3.1.3.20 | src/kernel.c | mrb_obj_ivar_defined
#### instance_variable_get
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.21 | src/kernel.c | mrb_obj_ivar_get
+15.3.1.3.21 | src/kernel.c | mrb_obj_ivar_get
#### instance_variable_set
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.22 | src/kernel.c | mrb_obj_ivar_set
+15.3.1.3.22 | src/kernel.c | mrb_obj_ivar_set
#### instance_variables
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.23 | src/kernel.c | mrb_obj_instance_variables
+15.3.1.3.23 | src/kernel.c | mrb_obj_instance_variables
#### is_a?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.24 | src/kernel.c | mrb_obj_is_kind_of_m
+15.3.1.3.24 | src/kernel.c | mrb_obj_is_kind_of_m
#### iterator?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.25 | src/kernel.c | mrb_f_block_given_p_m
+15.3.1.3.25 | src/kernel.c | mrb_f_block_given_p_m
#### kind_of?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.26 | src/kernel.c | mrb_obj_is_kind_of_m
+15.3.1.3.26 | src/kernel.c | mrb_obj_is_kind_of_m
#### methods
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.31 | src/kernel.c | mrb_obj_methods_m
+15.3.1.3.31 | src/kernel.c | mrb_obj_methods_m
#### nil?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.32 | src/kernel.c | mrb_false
+15.3.1.3.32 | src/kernel.c | mrb_false
#### object_id
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.33 | src/kernel.c | mrb_obj_id_m
+15.3.1.3.33 | src/kernel.c | mrb_obj_id_m
#### private_methods
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.36 | src/kernel.c | mrb_obj_private_methods
+15.3.1.3.36 | src/kernel.c | mrb_obj_private_methods
#### protected_methods
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.37 | src/kernel.c | mrb_obj_protected_methods
+15.3.1.3.37 | src/kernel.c | mrb_obj_protected_methods
#### public_methods
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.38 | src/kernel.c | mrb_obj_public_methods
+15.3.1.3.38 | src/kernel.c | mrb_obj_public_methods
#### raise
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.40 | src/kernel.c | mrb_f_raise
+15.3.1.3.40 | src/kernel.c | mrb_f_raise
#### remove_instance_variable
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.41 | src/kernel.c | mrb_obj_remove_instance_variable
+15.3.1.3.41 | src/kernel.c | mrb_obj_remove_instance_variable
#### respond_to?
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.43 | src/kernel.c | obj_respond_to
+15.3.1.3.43 | src/kernel.c | obj_respond_to
#### send
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.44 | src/kernel.c | mrb_f_send
+15.3.1.3.44 | src/kernel.c | mrb_f_send
#### singleton_class
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-n/a | src/kernel.c | mrb_singleton_class
+n/a | src/kernel.c | mrb_singleton_class
#### singleton_methods
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.45 | src/kernel.c | mrb_obj_singleton_methods_m
+15.3.1.3.45 | src/kernel.c | mrb_obj_singleton_methods_m
#### to_s
-ISO Code | Source File | C Function
+ISO Code | Source File | C Function
--- | --- | ---
-15.3.1.3.46 | src/kernel.c | mrb_any_to_s
+15.3.1.3.46 | src/kernel.c | mrb_any_to_s
diff --git a/doc/language/README.md b/doc/language/README.md
index 67946fe64..24dd598ac 100644
--- a/doc/language/README.md
+++ b/doc/language/README.md
@@ -6,4 +6,4 @@ which are provided together with mruby.
## Built-In Class and Modules
-see *doc/lang/Core.md*
+see *doc/language/Core.md*
diff --git a/doc/language/mrbdoc/lib/mrbdoc_docu.rb b/doc/language/mrbdoc/lib/mrbdoc_docu.rb
index 4dc20a5a3..f6f327804 100644
--- a/doc/language/mrbdoc/lib/mrbdoc_docu.rb
+++ b/doc/language/mrbdoc/lib/mrbdoc_docu.rb
@@ -69,7 +69,7 @@ CLASS
## #{name}
ISO Code | Source File
---- | ---
+--- | ---
#{iso} | #{file}
CLASS
@@ -96,8 +96,8 @@ CLASS
def print_method(io, met_name, met_hsh, cfg)
if cfg[:print_line_no]
- line_no_head = '| Line'
- line_no = "| #{find_c_func(met_hsh[:c_func])[:line_no]}"
+ line_no_head = ' | Line'
+ line_no = " | #{find_c_func(met_hsh[:c_func])[:line_no]}"
else
line_no, line_no_head = '', ''
end
@@ -109,9 +109,9 @@ CLASS
io.puts <<METHOD
#### #{met_name}
-ISO Code | Source File | C Function #{line_no_head}
+ISO Code | Source File | C Function#{line_no_head}
--- | --- | ---
-#{iso} | #{file} | #{met_hsh[:c_func]} #{line_no}
+#{iso} | #{file} | #{met_hsh[:c_func]}#{line_no}
METHOD
end
diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md
index 863f7bd30..7ac225730 100644
--- a/doc/mrbgems/README.md
+++ b/doc/mrbgems/README.md
@@ -25,19 +25,19 @@ A remote GIT repository location for a GEM is also supported:
conf.gem :bitbucket => 'mruby/mrbgems-example', :branch => 'master'
-To pull all gems from remote GIT repository on build, call ```./minirake -p```,
+To pull all gems from remote GIT repository on build, call ```./minirake -p```,
or ```./minirake --pull-gems```.
NOTE: `:bitbucket` option supports only git. Hg is unsupported in this version.
## GemBox
-There are instances when you wish to add a collection of mrbgems into mruby at
+There are instances when you wish to add a collection of mrbgems into mruby at
once, or be able to substitute mrbgems based on configuration, without having to
-add each gem to the *build_config.rb* file. A packaged collection of mrbgems
-is called a GemBox. A GemBox is a file that contains a list of mrbgems to load
+add each gem to the *build_config.rb* file. A packaged collection of mrbgems
+is called a GemBox. A GemBox is a file that contains a list of mrbgems to load
into mruby, in the same format as if you were adding them to *build_config.rb*
-via `config.gem`, but wrapped in an `MRuby::GemBox` object. GemBoxes are
+via `config.gem`, but wrapped in an `MRuby::GemBox` object. GemBoxes are
loaded into mruby via `config.gembox 'boxname'`.
Below we have created a GemBox containing *mruby-time* and *mrbgems-example*:
@@ -51,8 +51,8 @@ As mentioned, the GemBox uses the same conventions as `MRuby::Build`. The GemBo
must be saved with a *.gembox* extension inside the *mrbgems* directory to to be
picked up by mruby.
-To use this example GemBox, we save it as `custom.gembox` inside the *mrbgems*
-directory in mruby, and add the following to our *build_config.rb* file inside
+To use this example GemBox, we save it as `custom.gembox` inside the *mrbgems*
+directory in mruby, and add the following to our *build_config.rb* file inside
the build block:
conf.gembox 'custom'
@@ -60,7 +60,7 @@ the build block:
This will cause the *custom* GemBox to be read in during the build process,
adding *mruby-time* and *mrbgems-example* to the build.
-If you want, you can put GemBox outside of mruby directory. In that case you must
+If you want, you can put GemBox outside of mruby directory. In that case you must
specify absolute path like below.
conf.gembox "#{ENV["HOME"]}/mygemboxes/custom"
diff --git a/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
index a1f964b36..6b4595b35 100644
--- a/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
@@ -1,7 +1,7 @@
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
-
+
# Add compile flags
# spec.cc.flags << ''
diff --git a/examples/mrbgems/c_extension_example/mrbgem.rake b/examples/mrbgems/c_extension_example/mrbgem.rake
index 3524e22f4..6e4c5b165 100644
--- a/examples/mrbgems/c_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_extension_example/mrbgem.rake
@@ -1,7 +1,7 @@
MRuby::Gem::Specification.new('c_extension_example') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
-
+
# Add compile flags
# spec.cc.flags << '-g'
diff --git a/examples/mrbgems/ruby_extension_example/mrbgem.rake b/examples/mrbgems/ruby_extension_example/mrbgem.rake
index 5624c33e9..57cf1a69e 100644
--- a/examples/mrbgems/ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/ruby_extension_example/mrbgem.rake
@@ -1,7 +1,7 @@
MRuby::Gem::Specification.new('ruby_extension_example') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
-
+
# Add compile flags
# spec.cc.flags << ''
diff --git a/examples/targets/ArduinoDue.rb b/examples/targets/build_config_ArduinoDue.rb
index 59101c2cc..eadcfdd43 100644
--- a/examples/targets/ArduinoDue.rb
+++ b/examples/targets/build_config_ArduinoDue.rb
@@ -1,8 +1,24 @@
+MRuby::Build.new do |conf|
+
+ # Gets set by the VS command prompts.
+ if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
+ toolchain :visualcpp
+ else
+ toolchain :gcc
+ end
+
+ enable_debug
+
+ # include the default GEMs
+ conf.gembox 'default'
+
+end
+
# Cross Compiling configuration for Arduino Due
# http://arduino.cc/en/Main/ArduinoBoardDue
#
# Requires Arduino IDE >= 1.5
-MRuby::CrossBuild.new("Arduino Due") do |conf|
+MRuby::CrossBuild.new("ArduinoDue") do |conf|
toolchain :gcc
# Mac OS X
@@ -18,8 +34,8 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
cc.include_paths << ["#{SAM_PATH}/system/libsam", "#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
"#{SAM_PATH}/system/CMSIS/Device/ATMEL/",
"#{SAM_PATH}/cores/arduino", "#{SAM_PATH}/libraries","#{TARGET_PATH}"]
- cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
- -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM
+ cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
+ -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM
-D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due")
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
@@ -57,12 +73,12 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
conf.disable_cxx_exception
#gems from core
- conf.gem :core => "mruby-print"
+ conf.gem :core => "mruby-print"
conf.gem :core => "mruby-math"
conf.gem :core => "mruby-enum-ext"
#light-weight regular expression
- conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
+ conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
#Arduino API
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master"
diff --git a/examples/targets/IntelGalileo.rb b/examples/targets/build_config_IntelGalileo.rb
index 0ee073344..42f800d9f 100644
--- a/examples/targets/IntelGalileo.rb
+++ b/examples/targets/build_config_IntelGalileo.rb
@@ -1,31 +1,47 @@
+MRuby::Build.new do |conf|
+
+ # Gets set by the VS command prompts.
+ if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
+ toolchain :visualcpp
+ else
+ toolchain :gcc
+ end
+
+ enable_debug
+
+ # include the default GEMs
+ conf.gembox 'default'
+
+end
+
+
# Cross Compiling configuration for Intel Galileo on Arduino environment
# http://arduino.cc/en/ArduinoCertified/IntelGalileo
#
# Requires Arduino IDE for Intel Galileo
-
MRuby::CrossBuild.new("Galileo") do |conf|
toolchain :gcc
-
+
# Mac OS X
# Assume you renamed Arduino.app to Arduino_Galileo.app
GALILEO_ARDUINO_PATH = '/Applications/Arduino_Galileo.app/Contents/Resources/Java'
# GNU Linux
#ARDUINO_GALILEO_PATH = '/opt/arduino'
-
+
GALILEO_BIN_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i386-pokysdk-darwin/usr/bin/i586-poky-linux-uclibc"
GALILEO_SYSROOT = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc"
GALILEO_X86_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/arduino/x86"
-
-
+
+
conf.cc do |cc|
cc.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-gcc"
cc.include_paths << ["#{GALILEO_X86_PATH}/cores/arduino", "#{GALILEO_X86_PATH}/variants/galileo_fab_d"]
- cc.flags = %w(-m32 -march=i586 -c -g -Os -w
+ cc.flags = %w(-m32 -march=i586 -c -g -Os -w
-ffunction-sections -fdata-sections -MMD -DARDUINO=153)
cc.flags << "--sysroot=#{GALILEO_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
end
-
+
conf.cxx do |cxx|
cxx.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++"
cxx.include_paths = conf.cc.include_paths.dup
@@ -35,12 +51,12 @@ MRuby::CrossBuild.new("Galileo") do |conf|
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
-
+
conf.archiver do |archiver|
archiver.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
end
-
+
conf.linker do |linker|
linker.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++"
linker.flags = %w(-m32 -march=i586)
@@ -48,13 +64,13 @@ MRuby::CrossBuild.new("Galileo") do |conf|
linker.flags << %w(-Os -Wl,--gc-sections)
linker.libraries = %w(m pthread)
end
-
+
#no executables
conf.bins = []
-
+
#do not build executable test
conf.build_mrbtest_lib_only
-
+
#official mrbgems
conf.gem :core => "mruby-sprintf"
conf.gem :core => "mruby-print"
@@ -74,17 +90,17 @@ MRuby::CrossBuild.new("Galileo") do |conf|
conf.gem :core => "mruby-objectspace"
conf.gem :core => "mruby-fiber"
conf.gem :core => "mruby-toplevel-ext"
-
+
#lightweigh regular expression
- conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
-
+ conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
+
#Arduino API
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master" do |g|
# g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Wire"
# g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Servo"
-
+
#enable unsupported Servo class
# g.cxx.defines << "MRUBY_ARDUINO_GALILEO_ENABLE_SERVO"
#end
-
-end \ No newline at end of file
+
+end
diff --git a/examples/targets/chipKitMax32.rb b/examples/targets/build_config_chipKITMax32.rb
index 5c3a30a2b..e3a122f43 100644
--- a/examples/targets/chipKitMax32.rb
+++ b/examples/targets/build_config_chipKITMax32.rb
@@ -1,3 +1,19 @@
+MRuby::Build.new do |conf|
+
+ # Gets set by the VS command prompts.
+ if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
+ toolchain :visualcpp
+ else
+ toolchain :gcc
+ end
+
+ enable_debug
+
+ # include the default GEMs
+ conf.gembox 'default'
+
+end
+
# Cross Compiling configuration for Digilent chipKIT Max32
# http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
#
@@ -5,7 +21,7 @@
#
# This configuration is based on @kyab's version
# http://d.hatena.ne.jp/kyab/20130201
-MRuby::CrossBuild.new("chipKitMax32") do |conf|
+MRuby::CrossBuild.new("chipKITMax32") do |conf|
toolchain :gcc
# Mac OS X
@@ -13,15 +29,15 @@ MRuby::CrossBuild.new("chipKitMax32") do |conf|
# GNU Linux
MPIDE_PATH = '/opt/mpide-0023-linux-20120903'
- PIC32_PATH = "#{MPIDE_PATH}/hardware/pic32"
+ PIC32_PATH = "#{MPIDE_PATH}/hardware/pic32"
conf.cc do |cc|
cc.command = "#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-gcc"
cc.include_paths << ["#{PIC32_PATH}/cores/pic32",
"#{PIC32_PATH}/variants/Max32",
"#{PIC32_PATH}/libraries"]
- cc.flags = %w(-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align
- -fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_
+ cc.flags = %w(-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align
+ -fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_
-DMPIDEVER=0x01000202 -DMPIDE=23)
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
@@ -51,16 +67,19 @@ MRuby::CrossBuild.new("chipKitMax32") do |conf|
#no executables
conf.bins = []
- #do not build test executable
+ #do not build test executable
conf.build_mrbtest_lib_only
+ #disable C++ exception
+ conf.disable_cxx_exception
+
#gems from core
- conf.gem :core => "mruby-print"
+ conf.gem :core => "mruby-print"
conf.gem :core => "mruby-math"
conf.gem :core => "mruby-enum-ext"
#light-weight regular expression
- conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
+ conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
#Arduino API
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master"
diff --git a/include/mruby.h b/include/mruby.h
index 9cf578836..3b1425cce 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -312,7 +312,7 @@ void mrb_gc_mark(mrb_state*,struct RBasic*);
} while (0)
void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*);
#define mrb_field_write_barrier_value(mrb, obj, val) do{\
- if (MRB_TT_HAS_BASIC_P(val.tt)) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \
+ if (MRB_TT_HAS_BASIC_P(mrb_type(val))) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \
} while (0)
void mrb_write_barrier(mrb_state *, struct RBasic*);
@@ -381,6 +381,7 @@ mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const
void mrb_gc_protect(mrb_state *mrb, mrb_value obj);
mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
+#define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val))
void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
typedef enum call_type {
diff --git a/include/mruby/dump.h b/include/mruby/dump.h
index b0e96db77..d8713343e 100644
--- a/include/mruby/dump.h
+++ b/include/mruby/dump.h
@@ -14,6 +14,7 @@ extern "C" {
#include "mruby.h"
#include "mruby/irep.h"
+int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, size_t *bin_size);
#ifdef ENABLE_STDIO
int mrb_dump_irep_binary(mrb_state*, mrb_irep*, int, FILE*);
int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, int, FILE *f, const char *initname);
diff --git a/include/mruby/error.h b/include/mruby/error.h
index 689cf4b8f..9dd4260c2 100644
--- a/include/mruby/error.h
+++ b/include/mruby/error.h
@@ -21,6 +21,9 @@ void mrb_print_backtrace(mrb_state *mrb);
mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
mrb_value mrb_get_backtrace(mrb_state *mrb);
+/* declaration for fail method */
+mrb_value mrb_f_raise(mrb_state*, mrb_value);
+
#if defined(__cplusplus)
} /* extern "C" { */
#endif
diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h
index 17291c2f2..fe4f3b264 100644
--- a/include/mruby/numeric.h
+++ b/include/mruby/numeric.h
@@ -25,6 +25,41 @@ mrb_value mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
+#define MRB_UINT_MAKE2(n) uint ## n ## _t
+#define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n)
+#define mrb_uint MRB_UINT_MAKE(MRB_INT_BIT)
+
+#ifdef MRB_WORD_BOXING
+# define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT))
+#else
+# define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1))
+#endif
+
+static inline mrb_bool
+mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
+{
+ mrb_uint x = (mrb_uint)augend;
+ mrb_uint y = (mrb_uint)addend;
+ mrb_uint z = (mrb_uint)(x + y);
+ *sum = (mrb_int)z;
+ return !!(((x ^ z) & (y ^ z)) & MRB_INT_OVERFLOW_MASK);
+}
+
+static inline mrb_bool
+mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
+{
+ mrb_uint x = (mrb_uint)minuend;
+ mrb_uint y = (mrb_uint)subtrahend;
+ mrb_uint z = (mrb_uint)(x - y);
+ *difference = (mrb_int)z;
+ return !!(((x ^ z) & (~y ^ z)) & MRB_INT_OVERFLOW_MASK);
+}
+
+#undef MRB_INT_OVERFLOW_MASK
+#undef mrb_uint
+#undef MRB_UINT_MAKE
+#undef MRB_UINT_MAKE2
+
#if defined(__cplusplus)
} /* extern "C" { */
#endif
diff --git a/include/mruby/range.h b/include/mruby/range.h
index 828ec2691..61beb2319 100644
--- a/include/mruby/range.h
+++ b/include/mruby/range.h
@@ -27,6 +27,7 @@ struct RRange {
mrb_value mrb_range_new(mrb_state*, mrb_value, mrb_value, mrb_bool);
mrb_bool mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len);
+mrb_value mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int));
#if defined(__cplusplus)
} /* extern "C" { */
diff --git a/include/mruby/value.h b/include/mruby/value.h
index 9ba714cae..f6d08f58e 100644
--- a/include/mruby/value.h
+++ b/include/mruby/value.h
@@ -27,8 +27,13 @@
# else
typedef int64_t mrb_int;
# define MRB_INT_BIT 64
-# define MRB_INT_MIN INT64_MIN
-# define MRB_INT_MAX INT64_MAX
+# ifdef MRB_WORD_BOXING
+# define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
+# define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
+# else
+# define MRB_INT_MIN INT64_MIN
+# define MRB_INT_MAX INT64_MAX
+# endif
# define PRIdMRB_INT PRId64
# define PRIiMRB_INT PRIi64
# define PRIoMRB_INT PRIo64
@@ -36,6 +41,9 @@
# define PRIXMRB_INT PRIX64
# endif
#elif defined(MRB_INT16)
+# ifdef MRB_WORD_BOXING
+# error "MRB_INT16 is too small for MRB_WORD_BOXING."
+# endif
typedef int16_t mrb_int;
# define MRB_INT_BIT 16
# define MRB_INT_MIN INT16_MIN
@@ -43,8 +51,13 @@
#else
typedef int32_t mrb_int;
# define MRB_INT_BIT 32
-# define MRB_INT_MIN INT32_MIN
-# define MRB_INT_MAX INT32_MAX
+# ifdef MRB_WORD_BOXING
+# define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
+# define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
+# else
+# define MRB_INT_MIN INT32_MIN
+# define MRB_INT_MAX INT32_MAX
+# endif
# define PRIdMRB_INT PRId32
# define PRIiMRB_INT PRIi32
# define PRIoMRB_INT PRIo32
@@ -60,6 +73,7 @@ typedef short mrb_sym;
# define snprintf _snprintf
# if _MSC_VER < 1800
# include <float.h>
+# define isfinite(n) _finite(n)
# define isnan _isnan
# define isinf(n) (!_finite(n) && !_isnan(n))
# define signbit(n) (_copysign(1.0, (n)) < 0.0)
diff --git a/mrbgems/default.gembox b/mrbgems/default.gembox
index 1bba7be26..8729593de 100644
--- a/mrbgems/default.gembox
+++ b/mrbgems/default.gembox
@@ -64,4 +64,7 @@ MRuby::GemBox.new do |conf|
# Generate mruby command
conf.gem :core => "mruby-bin-mruby"
+
+ # Use extensional Kernel module
+ conf.gem :core => "mruby-kernel-ext"
end
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb
index 3a4b1460b..fd80fa0bb 100644
--- a/mrbgems/mruby-array-ext/mrblib/array.rb
+++ b/mrbgems/mruby-array-ext/mrblib/array.rb
@@ -58,7 +58,7 @@ class Array
ary = self.dup
if block
ary.uniq!(&block)
- else
+ else
ary.uniq!
end
ary
@@ -370,7 +370,7 @@ class Array
self[i] = block.call(i)
i += 1
end
- else
+ else
while i < len
self[i] = arg0
i += 1
@@ -617,7 +617,6 @@ class Array
return to_enum :delete_if unless block_given?
idx = 0
- len = self.size
while idx < self.size do
if block.call(self[idx])
self.delete_at(idx)
diff --git a/mrbgems/mruby-array-ext/src/array.c b/mrbgems/mruby-array-ext/src/array.c
index ad6cead2c..ae9d8296e 100644
--- a/mrbgems/mruby-array-ext/src/array.c
+++ b/mrbgems/mruby-array-ext/src/array.c
@@ -1,6 +1,7 @@
#include "mruby.h"
#include "mruby/value.h"
#include "mruby/array.h"
+#include "mruby/range.h"
/*
* call-seq:
@@ -122,6 +123,17 @@ mrb_ary_at(mrb_state *mrb, mrb_value ary)
return mrb_ary_entry(ary, pos);
}
+static mrb_value
+mrb_ary_values_at(mrb_state *mrb, mrb_value self)
+{
+ mrb_int argc;
+ mrb_value *argv;
+
+ mrb_get_args(mrb, "*", &argv, &argc);
+
+ return mrb_get_values_at(mrb, self, RARRAY_LEN(self), argc, argv, mrb_ary_ref);
+}
+
void
mrb_mruby_array_ext_gem_init(mrb_state* mrb)
{
@@ -132,6 +144,7 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, a, "assoc", mrb_ary_assoc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "at", mrb_ary_at, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1));
+ mrb_define_method(mrb, a, "values_at", mrb_ary_values_at, MRB_ARGS_ANY());
}
void
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb
index f94189356..1fa7cfc04 100644
--- a/mrbgems/mruby-array-ext/test/array.rb
+++ b/mrbgems/mruby-array-ext/test/array.rb
@@ -19,7 +19,7 @@ end
assert("Array#at") do
a = [ "a", "b", "c", "d", "e" ]
assert_equal "a", a.at(0)
- assert_equal "e", a.at(-1)
+ assert_equal "e", a.at(-1)
end
assert("Array#rassoc") do
@@ -50,7 +50,7 @@ assert("Array#uniq") do
assert_equal [1, 2, 3, 1], a
b = [["student","sam"], ["student","george"], ["teacher","matz"]]
- assert_equal [["student", "sam"], ["teacher", "matz"]], b.uniq { |s| s.first }
+ assert_equal [["student", "sam"], ["teacher", "matz"]], b.uniq { |s| s.first }
end
assert("Array#-") do
@@ -60,7 +60,7 @@ assert("Array#-") do
assert_raise(TypeError) { a - c }
assert_equal [2, 3], (a - b)
- assert_equal [1, 2, 3, 1], a
+ assert_equal [1, 2, 3, 1], a
end
assert("Array#|") do
@@ -70,7 +70,7 @@ assert("Array#|") do
assert_raise(TypeError) { a | c }
assert_equal [1, 2, 3, 4], (a | b)
- assert_equal [1, 2, 3, 1], a
+ assert_equal [1, 2, 3, 1], a
end
assert("Array#&") do
@@ -79,8 +79,8 @@ assert("Array#&") do
c = 1
assert_raise(TypeError) { a & c }
- assert_equal [1], (a & b)
- assert_equal [1, 2, 3, 1], a
+ assert_equal [1], (a & b)
+ assert_equal [1, 2, 3, 1], a
end
assert("Array#flatten") do
@@ -280,3 +280,13 @@ assert("Array#select!") do
assert_equal [4, 5], a.select! { |val| val > 3 }
assert_equal [4, 5], a
end
+
+assert('Array#values_at') do
+ a = %w{red green purple white none}
+
+ assert_equal %w{red purple none}, a.values_at(0, 2, 4)
+ assert_equal ['green', 'white', nil, nil], a.values_at(1, 3, 5, 7)
+ assert_equal ['none', 'white', 'white', nil], a.values_at(-1, -2, -2, -7)
+ assert_equal ['none', nil, nil, 'red', 'green', 'purple'], a.values_at(4..6, 0...3)
+ assert_raise(TypeError) { a.values_at 'tt' }
+end
diff --git a/mrbgems/mruby-bin-mirb/mrbgem.rake b/mrbgems/mruby-bin-mirb/mrbgem.rake
index ffef67a39..c4374b47e 100644
--- a/mrbgems/mruby-bin-mirb/mrbgem.rake
+++ b/mrbgems/mruby-bin-mirb/mrbgem.rake
@@ -3,7 +3,15 @@ MRuby::Gem::Specification.new('mruby-bin-mirb') do |spec|
spec.author = 'mruby developers'
spec.summary = 'mirb command'
- spec.linker.libraries << 'readline' if spec.cc.defines.include? "ENABLE_READLINE"
+ if spec.build.cc.search_header_path 'readline/readline.h'
+ spec.cc.defines << "ENABLE_READLINE"
+ if spec.build.cc.search_header_path 'termcap.h'
+ spec.linker.libraries << 'termcap'
+ end
+ spec.linker.libraries << 'readline'
+ elsif spec.build.cc.search_header_path 'linenoise.h'
+ spec.cc.defines << "ENABLE_LINENOISE"
+ end
spec.bins = %w(mirb)
end
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
index 320bc30fb..b1b8767bc 100644
--- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
@@ -8,11 +8,7 @@
#include <stdlib.h>
#include <string.h>
-#include "mruby.h"
-#include "mruby/array.h"
-#include "mruby/proc.h"
-#include "mruby/compile.h"
-#include "mruby/string.h"
+#include <stdio.h>
#ifdef ENABLE_READLINE
#include <readline/readline.h>
@@ -22,7 +18,7 @@
#define MIRB_WRITE_HISTORY(path) write_history(path)
#define MIRB_READ_HISTORY(path) read_history(path)
#define MIRB_USING_HISTORY() using_history()
-#elif ENABLE_LINENOISE
+#elif defined(ENABLE_LINENOISE)
#define ENABLE_READLINE
#include <linenoise.h>
#define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line)
@@ -31,13 +27,19 @@
#define MIRB_READ_HISTORY(path) linenoiseHistoryLoad(history_path)
#define MIRB_USING_HISTORY()
#endif
-
+
#ifdef ENABLE_READLINE
#include <limits.h>
static const char *history_file_name = ".mirb_history";
char history_path[PATH_MAX];
#endif
+#include "mruby.h"
+#include "mruby/array.h"
+#include "mruby/proc.h"
+#include "mruby/compile.h"
+#include "mruby/string.h"
+
static void
p(mrb_state *mrb, mrb_value obj, int prompt)
{
@@ -98,9 +100,9 @@ is_code_block_open(struct mrb_parser_state *parser)
/* all states which need more code */
case EXPR_BEG:
- /* an expression was just started, */
- /* we can't end it like this */
- code_block_open = TRUE;
+ /* beginning of a statement, */
+ /* that means previous line ended */
+ code_block_open = FALSE;
break;
case EXPR_DOT:
/* a message dot was the last token, */
@@ -244,7 +246,7 @@ print_cmdline(int code_block_open)
printf("> ");
}
}
-#endif
+#endif
void mrb_codedump_all(mrb_state*, struct RProc*);
@@ -317,6 +319,10 @@ main(int argc, char **argv)
char_index = 0;
while ((last_char = getchar()) != '\n') {
if (last_char == EOF) break;
+ if (char_index > sizeof(last_code_line)-2) {
+ fputs("input string too long\n", stderr);
+ continue;
+ }
last_code_line[char_index++] = last_char;
}
if (last_char == EOF) {
@@ -324,6 +330,7 @@ main(int argc, char **argv)
break;
}
+ last_code_line[char_index++] = '\n';
last_code_line[char_index] = '\0';
#else
char* line = MIRB_READLINE(code_block_open ? "* " : "> ");
@@ -331,14 +338,22 @@ main(int argc, char **argv)
printf("\n");
break;
}
- strncpy(last_code_line, line, sizeof(last_code_line)-1);
+ if (strlen(line) > sizeof(last_code_line)-2) {
+ fputs("input string too long\n", stderr);
+ continue;
+ }
+ strcpy(last_code_line, line);
+ strcat(last_code_line, "\n");
MIRB_ADD_HISTORY(line);
free(line);
#endif
if (code_block_open) {
- strcat(ruby_code, "\n");
- strcat(ruby_code, last_code_line);
+ if (strlen(ruby_code)+strlen(last_code_line) > sizeof(ruby_code)-1) {
+ fputs("concatenated input string too long\n", stderr);
+ continue;
+ }
+ strcat(ruby_code, last_code_line);
}
else {
if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) {
diff --git a/mrbgems/mruby-bin-mruby-config/mruby-config b/mrbgems/mruby-bin-mruby-config/mruby-config
index 20b1701a7..f346eb719 100644
--- a/mrbgems/mruby-bin-mruby-config/mruby-config
+++ b/mrbgems/mruby-bin-mruby-config/mruby-config
@@ -9,7 +9,7 @@ while [ $# -gt 0 ]; do
echo " switches:"
echo " --cflags print flags passed to compiler"
echo " --ldflags print flags passed to linker"
- echo " --libs print linked libraries"
+ echo " --libs print linked libraries"
exit 0;;
esac
shift
diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
index f60fd1974..73617b162 100644
--- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -211,7 +211,7 @@ main(int argc, char **argv)
cmdline = args.cmdline ? args.cmdline : "-";
mrbc_filename(mrb, c, cmdline);
mrb_gv_set(mrb, zero_sym, mrb_str_new_cstr(mrb, cmdline));
- }
+ }
else {
mrbc_filename(mrb, c, "-e");
mrb_gv_set(mrb, zero_sym, mrb_str_new_lit(mrb, "-e"));
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb
index 22c793108..5abb75d54 100644
--- a/mrbgems/mruby-enum-ext/mrblib/enum.rb
+++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -92,7 +92,7 @@ module Enumerable
end
ary
end
-
+
##
# call-seq:
# enum.each_cons(n) {...} -> nil
@@ -192,7 +192,7 @@ module Enumerable
return to_enum :sort_by unless block_given?
ary = []
- orig = []
+ orig = []
self.each_with_index{|e, i|
orig.push(e)
ary.push([block.call(e), i])
@@ -253,7 +253,7 @@ module Enumerable
self.each { count += 1 }
else
self.each do |*val|
- count += 1 if val.__svalue == v
+ count += 1 if val.__svalue == v
end
end
end
diff --git a/mrbgems/mruby-enum-ext/test/enum.rb b/mrbgems/mruby-enum-ext/test/enum.rb
index 9348cb4a5..bce9cb15d 100644
--- a/mrbgems/mruby-enum-ext/test/enum.rb
+++ b/mrbgems/mruby-enum-ext/test/enum.rb
@@ -108,7 +108,7 @@ assert("Enumerable#one?") do
assert_false %w(ant bear cat).one? { |word| word.length > 4 }
assert_false %w(ant bear cat).one? { |word| word.length < 4 }
assert_false [nil, true, 99].one?
- assert_true [nil, true, false].one?
+ assert_true [nil, true, false].one?
end
assert("Enumerable#each_with_object") do
diff --git a/mrbgems/mruby-enum-lazy/mrbgem.rake b/mrbgems/mruby-enum-lazy/mrbgem.rake
index 45dda4054..219141e98 100644
--- a/mrbgems/mruby-enum-lazy/mrbgem.rake
+++ b/mrbgems/mruby-enum-lazy/mrbgem.rake
@@ -2,5 +2,6 @@ MRuby::Gem::Specification.new('mruby-enum-lazy') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Enumerable::Lazy class'
- spec.add_dependency('mruby-enumerator')
+ spec.add_dependency('mruby-enumerator', :core => 'mruby-enumerator')
+ spec.add_dependency('mruby-enum-ext', :core => 'mruby-enum-ext')
end
diff --git a/mrbgems/mruby-enum-lazy/mrblib/lazy.rb b/mrbgems/mruby-enum-lazy/mrblib/lazy.rb
index 088ce760d..2ffeb1808 100644
--- a/mrbgems/mruby-enum-lazy/mrblib/lazy.rb
+++ b/mrbgems/mruby-enum-lazy/mrblib/lazy.rb
@@ -97,7 +97,7 @@ module Enumerable
end
}
end
-
+
def take(n)
if n == 0
return Lazy.new(self){raise StopIteration}
diff --git a/mrbgems/mruby-enumerator/mrbgem.rake b/mrbgems/mruby-enumerator/mrbgem.rake
index 2d5fd35ac..abcc54e7a 100644
--- a/mrbgems/mruby-enumerator/mrbgem.rake
+++ b/mrbgems/mruby-enumerator/mrbgem.rake
@@ -1,6 +1,6 @@
MRuby::Gem::Specification.new('mruby-enumerator') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
- spec.add_dependency('mruby-fiber')
+ spec.add_dependency('mruby-fiber', :core => 'mruby-fiber')
spec.summary = 'Enumerator class'
end
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
index 0257d8bf0..58996adc8 100644
--- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb
+++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
@@ -217,14 +217,12 @@ class Enumerator
def inspect
return "#<#{self.class}: uninitialized>" unless @obj
- args = ""
if @args && @args.size > 0
- args = "("
- @args.each {|arg| args << "#{arg}, " }
- args = args[0, args.size-2]
- args << ")"
+ args = @args.join(", ")
+ "#<#{self.class}: #{@obj}:#{@meth}(#{args})>"
+ else
+ "#<#{self.class}: #{@obj}:#{@meth}>"
end
- "#<#{self.class}: #{@obj}:#{@meth}#{args}>"
end
##
diff --git a/mrbgems/mruby-enumerator/test/enumerator.rb b/mrbgems/mruby-enumerator/test/enumerator.rb
index b22ed7754..0e3ddcba9 100644
--- a/mrbgems/mruby-enumerator/test/enumerator.rb
+++ b/mrbgems/mruby-enumerator/test/enumerator.rb
@@ -78,7 +78,7 @@ assert 'Enumerator#with_object arguments' do
y << x
end
end
-
+
a = []
to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string|
diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c
index 927cccac7..9bd15f4b6 100644
--- a/mrbgems/mruby-fiber/src/fiber.c
+++ b/mrbgems/mruby-fiber/src/fiber.c
@@ -13,7 +13,7 @@
* Fiber.new{...} -> obj
*
* Creates a fiber, whose execution is suspend until it is explicitly
- * resumed using <code>Fiber#resume</code> method.
+ * resumed using <code>Fiber#resume</code> method.
* The code running inside the fiber can give up control by calling
* <code>Fiber.yield</code> in which case it yields control back to caller
* (the caller of the <code>Fiber#resume</code>).
@@ -71,7 +71,7 @@ fiber_init(mrb_state *mrb, mrb_value self)
mrb_value blk;
mrb_get_args(mrb, "&", &blk);
-
+
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Fiber object without a block");
}
@@ -166,7 +166,7 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
*b++ = *a++;
}
c->cibase->argc = len;
- if (c->prev->fib)
+ if (c->prev->fib)
mrb_field_write_barrier(mrb, (struct RBasic*)c->fib, (struct RBasic*)c->prev->fib);
mrb_write_barrier(mrb, (struct RBasic*)c->fib);
c->status = MRB_FIBER_RUNNING;
@@ -176,7 +176,7 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
return c->ci->proc->env->stack[0];
}
MARK_CONTEXT_MODIFY(c);
- if (c->prev->fib)
+ if (c->prev->fib)
mrb_field_write_barrier(mrb, (struct RBasic*)c->fib, (struct RBasic*)c->prev->fib);
mrb_write_barrier(mrb, (struct RBasic*)c->fib);
c->status = MRB_FIBER_RUNNING;
@@ -332,7 +332,7 @@ fiber_current(mrb_state *mrb, mrb_value self)
}
return mrb_obj_value(mrb->c->fib);
}
-
+
void
mrb_mruby_fiber_gem_init(mrb_state* mrb)
{
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb
index bf3836514..504848a74 100644
--- a/mrbgems/mruby-hash-ext/mrblib/hash.rb
+++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb
@@ -1,6 +1,31 @@
class Hash
+
+ # ISO does not define Hash#each_pair, so each_pair is defined in gem.
+ alias each_pair each
+
+ ##
+ # call-seq:
+ # hsh.merge!(other_hash) -> hsh
+ # hsh.merge!(other_hash){|key, oldval, newval| block} -> hsh
+ #
+ # Adds the contents of _other_hash_ to _hsh_. If no block is specified,
+ # entries with duplicate keys are overwritten with the values from
+ # _other_hash_, otherwise the value of each duplicate key is determined by
+ # calling the block with the key, its value in _hsh_ and its value in
+ # _other_hash_.
+ #
+ # h1 = { "a" => 100, "b" => 200 }
+ # h2 = { "b" => 254, "c" => 300 }
+ # h1.merge!(h2) #=> {"a"=>100, "b"=>254, "c"=>300}
+ #
+ # h1 = { "a" => 100, "b" => 200 }
+ # h2 = { "b" => 254, "c" => 300 }
+ # h1.merge!(h2) { |key, v1, v2| v1 }
+ # #=> {"a"=>100, "b"=>200, "c"=>300}
+ #
+
def merge!(other, &block)
- raise "can't convert argument into Hash" unless other.respond_to?(:to_hash)
+ raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
if block
other.each_key{|k|
self[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]
@@ -11,9 +36,36 @@ class Hash
self
end
- alias each_pair each
alias update merge!
+ ##
+ # call-seq:
+ # hsh.fetch(key [, default] ) -> obj
+ # hsh.fetch(key) {| key | block } -> obj
+ #
+ # Returns a value from the hash for the given key. If the key can't be
+ # found, there are several options: With no other arguments, it will
+ # raise an <code>KeyError</code> exception; if <i>default</i> is
+ # given, then that will be returned; if the optional code block is
+ # specified, then that will be run and its result returned.
+ #
+ # h = { "a" => 100, "b" => 200 }
+ # h.fetch("a") #=> 100
+ # h.fetch("z", "go fish") #=> "go fish"
+ # h.fetch("z") { |el| "go fish, #{el}"} #=> "go fish, z"
+ #
+ # The following example shows that an exception is raised if the key
+ # is not found and a default value is not supplied.
+ #
+ # h = { "a" => 100, "b" => 200 }
+ # h.fetch("z")
+ #
+ # <em>produces:</em>
+ #
+ # prog.rb:2:in `fetch': key not found (KeyError)
+ # from prog.rb:2
+ #
+
def fetch(key, none=NONE, &block)
unless self.key?(key)
if block
@@ -27,4 +79,107 @@ class Hash
self[key]
end
end
+
+ ##
+ # call-seq:
+ # hsh.delete_if {| key, value | block } -> hsh
+ # hsh.delete_if -> an_enumerator
+ #
+ # Deletes every key-value pair from <i>hsh</i> for which <i>block</i>
+ # evaluates to <code>true</code>.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.delete_if {|key, value| key >= "b" } #=> {"a"=>100}
+ #
+
+ def delete_if(&block)
+ return to_enum :delete_if unless block_given?
+
+ self.each do |k, v|
+ self.delete(k) if block.call(k, v)
+ end
+ self
+ end
+
+ ##
+ # call-seq:
+ # hash.flatten -> an_array
+ # hash.flatten(level) -> an_array
+ #
+ # Returns a new array that is a one-dimensional flattening of this
+ # hash. That is, for every key or value that is an array, extract
+ # its elements into the new array. Unlike Array#flatten, this
+ # method does not flatten recursively by default. The optional
+ # <i>level</i> argument determines the level of recursion to flatten.
+ #
+ # a = {1=> "one", 2 => [2,"two"], 3 => "three"}
+ # a.flatten # => [1, "one", 2, [2, "two"], 3, "three"]
+ # a.flatten(2) # => [1, "one", 2, 2, "two", 3, "three"]
+ #
+
+ def flatten(level=1)
+ self.to_a.flatten(level)
+ end
+
+ ##
+ # call-seq:
+ # hsh.invert -> new_hash
+ #
+ # Returns a new hash created by using <i>hsh</i>'s values as keys, and
+ # the keys as values.
+ #
+ # h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
+ # h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}
+ #
+
+ def invert
+ h = Hash.new
+ self.each {|k, v| h[v] = k }
+ h
+ end
+
+ ##
+ # call-seq:
+ # hsh.keep_if {| key, value | block } -> hsh
+ # hsh.keep_if -> an_enumerator
+ #
+ # Deletes every key-value pair from <i>hsh</i> for which <i>block</i>
+ # evaluates to false.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+
+ def keep_if(&block)
+ return to_enum :keep_if unless block_given?
+
+ keys = []
+ self.each do |k, v|
+ unless block.call([k, v])
+ self.delete(k)
+ end
+ end
+ self
+ end
+
+ ##
+ # call-seq:
+ # hsh.key(value) -> key
+ #
+ # Returns the key of an occurrence of a given value. If the value is
+ # not found, returns <code>nil</code>.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 }
+ # h.key(200) #=> "b"
+ # h.key(300) #=> "c"
+ # h.key(999) #=> nil
+ #
+
+ def key(val)
+ self.each do |k, v|
+ return k if v == val
+ end
+ nil
+ end
end
diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb
index 661da3af3..62cfc8856 100644
--- a/mrbgems/mruby-hash-ext/test/hash.rb
+++ b/mrbgems/mruby-hash-ext/test/hash.rb
@@ -6,7 +6,7 @@ assert('Hash#merge!') do
b = { 'cba_key' => 'XXX', 'xyz_key' => 'xyz_value' }
result_1 = a.merge! b
-
+
a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
result_2 = a.merge!(b) do |key, original, new|
original
@@ -16,6 +16,10 @@ assert('Hash#merge!') do
'xyz_key' => 'xyz_value' }, result_1)
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }, result_2)
+
+ assert_raise(TypeError) do
+ { 'abc_key' => 'abc_value' }.merge! "a"
+ end
end
assert('Hash#values_at') do
@@ -39,3 +43,75 @@ assert('Hash#fetch') do
assert_kind_of(StandardError, e);
end
end
+
+assert("Hash#delete_if") do
+ base = { 1 => 'one', 2 => false, true => 'true', 'cat' => 99 }
+ h1 = { 1 => 'one', 2 => false, true => 'true' }
+ h2 = { 2 => false, 'cat' => 99 }
+ h3 = { 2 => false }
+
+ h = base.dup
+ assert_equal(h, h.delete_if { false })
+ assert_equal({}, h.delete_if { true })
+
+ h = base.dup
+ assert_equal(h1, h.delete_if {|k,v| k.instance_of?(String) })
+ assert_equal(h1, h)
+
+ h = base.dup
+ assert_equal(h2, h.delete_if {|k,v| v.instance_of?(String) })
+ assert_equal(h2, h)
+
+ h = base.dup
+ assert_equal(h3, h.delete_if {|k,v| v })
+ assert_equal(h3, h)
+
+ h = base.dup
+ n = 0
+ h.delete_if {|*a|
+ n += 1
+ assert_equal(2, a.size)
+ assert_equal(base[a[0]], a[1])
+ h.shift
+ true
+ }
+ assert_equal(base.size, n)
+end
+
+assert("Hash#flatten") do
+ a = {1=> "one", 2 => [2,"two"], 3 => [3, ["three"]]}
+ assert_equal [1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten
+ assert_equal [[1, "one"], [2, [2, "two"]], [3, [3, ["three"]]]], a.flatten(0)
+ assert_equal [1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(1)
+ assert_equal [1, "one", 2, 2, "two", 3, 3, ["three"]], a.flatten(2)
+ assert_equal [1, "one", 2, 2, "two", 3, 3, "three"], a.flatten(3)
+end
+
+assert("Hash#invert") do
+ h = { 1 => 'one', 2 => 'two', 3 => 'three',
+ true => 'true', nil => 'nil' }.invert
+ assert_equal 1, h['one']
+ assert_equal true, h['true']
+ assert_equal nil, h['nil']
+
+ h = { 'a' => 1, 'b' => 2, 'c' => 1 }.invert
+ assert_equal(2, h.length)
+ assert_include(%w[a c], h[1])
+ assert_equal('b', h[2])
+end
+
+assert("Hash#keep_if") do
+ h = { 1 => 2, 3 => 4, 5 => 6 }
+ assert_equal({3=>4,5=>6}, h.keep_if {|k, v| k + v >= 7 })
+ h = { 1 => 2, 3 => 4, 5 => 6 }
+ assert_equal({ 1 => 2, 3=> 4, 5 =>6} , h.keep_if { true })
+end
+
+assert("Hash#key") do
+ h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300, nil => 'nil', 'nil' => nil }
+ assert_equal "b", h.key(200)
+ assert_equal "c", h.key(300)
+ assert_nil h.key(999)
+ assert_nil h.key('nil')
+ assert_equal 'nil', h.key(nil)
+end
diff --git a/mrbgems/mruby-kernel-ext/mrbgem.rake b/mrbgems/mruby-kernel-ext/mrbgem.rake
new file mode 100644
index 000000000..ab610c02b
--- /dev/null
+++ b/mrbgems/mruby-kernel-ext/mrbgem.rake
@@ -0,0 +1,5 @@
+MRuby::Gem::Specification.new('mruby-kernel-ext') do |spec|
+ spec.license = 'MIT'
+ spec.author = 'mruby developers'
+ spec.summary = 'extensional Kernel module'
+end
diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c
new file mode 100644
index 000000000..1ce63ac94
--- /dev/null
+++ b/mrbgems/mruby-kernel-ext/src/kernel.c
@@ -0,0 +1,36 @@
+#include "mruby.h"
+#include "mruby/error.h"
+
+/*
+ * call-seq:
+ * __method__ -> symbol
+ *
+ * Returns the name at the definition of the current method as a
+ * Symbol.
+ * If called outside of a method, it returns <code>nil</code>.
+ *
+ */
+static mrb_value
+mrb_f_method(mrb_state *mrb, mrb_value self)
+{
+ mrb_callinfo *ci = mrb->c->ci;
+ ci--;
+ if (ci->mid)
+ return mrb_symbol_value(ci->mid);
+ else
+ return mrb_nil_value();
+}
+
+void
+mrb_mruby_kernel_ext_gem_init(mrb_state *mrb)
+{
+ struct RClass *krn = mrb->kernel_module;
+
+ mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_NONE());
+ mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE());
+}
+
+void
+mrb_mruby_kernel_ext_gem_final(mrb_state *mrb)
+{
+}
diff --git a/mrbgems/mruby-kernel-ext/test/kernel.rb b/mrbgems/mruby-kernel-ext/test/kernel.rb
new file mode 100644
index 000000000..0e47e3b57
--- /dev/null
+++ b/mrbgems/mruby-kernel-ext/test/kernel.rb
@@ -0,0 +1,18 @@
+assert('Kernel.fail, Kernel#fail') do
+ assert_raise(RuntimeError) { fail }
+ assert_raise(RuntimeError) { Kernel.fail }
+end
+
+assert('Kernel#__method__') do
+ assert_equal(:m, Class.new {def m; __method__; end}.new.m)
+ assert_equal(:m, Class.new {define_method(:m) {__method__}}.new.m)
+ c = Class.new do
+ [:m1, :m2].each do |m|
+ define_method(m) do
+ __method__
+ end
+ end
+ end
+ assert_equal(:m1, c.new.m1)
+ assert_equal(:m2, c.new.m2)
+end
diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c
index a699a12f0..871cba301 100644
--- a/mrbgems/mruby-math/src/math.c
+++ b/mrbgems/mruby-math/src/math.c
@@ -9,8 +9,14 @@
#include <math.h>
-#define domain_error(msg) \
- mrb_raise(mrb, E_RANGE_ERROR, "Numerical argument is out of domain - " #msg)
+static void
+domain_error(mrb_state *mrb, const char *func)
+{
+ struct RClass *math = mrb_module_get(mrb, "Math");
+ struct RClass *domainerror = mrb_class_get_under(mrb, math, "DomainError");
+ mrb_value str = mrb_str_new_cstr(mrb, func);
+ mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %S", str);
+}
/* math functions not provided by Microsoft Visual C++ 2012 or older */
#if defined _MSC_VER && _MSC_VER < 1800
@@ -172,6 +178,9 @@ math_asin(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "asin");
+ }
x = asin(x);
return mrb_float_value(mrb, x);
@@ -189,6 +198,9 @@ math_acos(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "acos");
+ }
x = acos(x);
return mrb_float_value(mrb, x);
@@ -334,6 +346,9 @@ math_acosh(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 1.0) {
+ domain_error(mrb, "acosh");
+ }
x = acosh(x);
return mrb_float_value(mrb, x);
@@ -351,6 +366,9 @@ math_atanh(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "atanh");
+ }
x = atanh(x);
return mrb_float_value(mrb, x);
@@ -404,8 +422,14 @@ math_log(mrb_state *mrb, mrb_value obj)
int argc;
argc = mrb_get_args(mrb, "f|f", &x, &base);
+ if (x < 0.0) {
+ domain_error(mrb, "log");
+ }
x = log(x);
if (argc == 2) {
+ if (base < 0.0) {
+ domain_error(mrb, "log");
+ }
x /= log(base);
}
return mrb_float_value(mrb, x);
@@ -429,6 +453,9 @@ math_log2(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "log2");
+ }
x = log2(x);
return mrb_float_value(mrb, x);
@@ -451,6 +478,9 @@ math_log10(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "log10");
+ }
x = log10(x);
return mrb_float_value(mrb, x);
@@ -469,6 +499,9 @@ math_sqrt(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "sqrt");
+ }
x = sqrt(x);
return mrb_float_value(mrb, x);
@@ -624,6 +657,8 @@ mrb_mruby_math_gem_init(mrb_state* mrb)
struct RClass *mrb_math;
mrb_math = mrb_define_module(mrb, "Math");
+ mrb_define_class_under(mrb, mrb_math, "DomainError", mrb->eStandardError_class);
+
#ifdef M_PI
mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, M_PI));
#else
diff --git a/mrbgems/mruby-objectspace/src/mruby_objectspace.c b/mrbgems/mruby-objectspace/src/mruby_objectspace.c
index 7d3b0b74e..ba22fc990 100644
--- a/mrbgems/mruby-objectspace/src/mruby_objectspace.c
+++ b/mrbgems/mruby-objectspace/src/mruby_objectspace.c
@@ -1,7 +1,7 @@
-#include <mruby.h>
-#include <mruby/gc.h>
-#include <mruby/hash.h>
-#include <mruby/class.h>
+#include "mruby.h"
+#include "mruby/gc.h"
+#include "mruby/hash.h"
+#include "mruby/class.h"
struct os_count_struct {
mrb_int total;
@@ -128,6 +128,20 @@ os_each_object_cb(mrb_state *mrb, struct RBasic *obj, void *ud)
++d->count;
}
+/*
+ * call-seq:
+ * ObjectSpace.each_object([module]) {|obj| ... } -> fixnum
+ *
+ * Calls the block once for each object in this Ruby process.
+ * Returns the number of objects found.
+ * If the optional argument +module+ is given,
+ * calls the block for only those classes or modules
+ * that match (or are a subclass of) +module+.
+ *
+ * If no block is given, ArgumentError is raised.
+ *
+ */
+
static mrb_value
os_each_object(mrb_state *mrb, mrb_value self)
{
diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c
index a27aee311..0e1279b34 100644
--- a/mrbgems/mruby-random/src/mt19937ar.c
+++ b/mrbgems/mruby-random/src/mt19937ar.c
@@ -7,8 +7,8 @@
#include "mruby.h"
#include "mt19937ar.h"
-/* Period parameters */
-/* #define N 624 */
+/* Period parameters */
+/* #define N 624 */
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
@@ -23,8 +23,8 @@ void mrb_random_init_genrand(mt_state *t, unsigned long s)
{
t->mt[0]= s & 0xffffffffUL;
for (t->mti=1; t->mti<N; t->mti++) {
- t->mt[t->mti] =
- (1812433253UL * (t->mt[t->mti-1] ^ (t->mt[t->mti-1] >> 30)) + t->mti);
+ t->mt[t->mti] =
+ (1812433253UL * (t->mt[t->mti-1] ^ (t->mt[t->mti-1] >> 30)) + t->mti);
t->mt[t->mti] &= 0xffffffffUL;
}
}
@@ -54,7 +54,7 @@ unsigned long mrb_random_genrand_int32(mt_state *t)
t->mti = 0;
}
-
+
y = t->mt[t->mti++];
/* Tempering */
@@ -62,7 +62,7 @@ unsigned long mrb_random_genrand_int32(mt_state *t)
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
-
+
t->gen.int_ = y;
return y;
@@ -71,9 +71,9 @@ unsigned long mrb_random_genrand_int32(mt_state *t)
double mrb_random_genrand_real1(mt_state *t)
{
mrb_random_genrand_int32(t);
- t->gen.double_ = t->gen.int_*(1.0/4294967295.0);
+ t->gen.double_ = t->gen.int_*(1.0/4294967295.0);
return t->gen.double_;
- /* divided by 2^32-1 */
+ /* divided by 2^32-1 */
}
#if 0 /* dead_code */
@@ -82,8 +82,8 @@ void init_genrand(unsigned long s)
{
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
- mt[mti] =
- (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
+ mt[mti] =
+ (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
@@ -119,7 +119,7 @@ void init_by_array(unsigned long init_key[], int key_length)
if (i>=N) { mt[0] = mt[N-1]; i=1; }
}
- mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
+ mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
@@ -148,7 +148,7 @@ unsigned long genrand_int32(void)
mti = 0;
}
-
+
y = mt[mti++];
/* Tempering */
@@ -169,29 +169,29 @@ long genrand_int31(void)
/* generates a random number on [0,1]-real-interval */
double genrand_real1(void)
{
- return genrand_int32()*(1.0/4294967295.0);
- /* divided by 2^32-1 */
+ return genrand_int32()*(1.0/4294967295.0);
+ /* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
double genrand_real2(void)
{
- return genrand_int32()*(1.0/4294967296.0);
+ return genrand_int32()*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
double genrand_real3(void)
{
- return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
+ return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
-double genrand_res53(void)
-{
- unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
- return(a*67108864.0+b)*(1.0/9007199254740992.0);
-}
+double genrand_res53(void)
+{
+ unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
+ return(a*67108864.0+b)*(1.0/9007199254740992.0);
+}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
#endif /* dead_code */
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c
index 8f983ea0f..391336493 100644
--- a/mrbgems/mruby-random/src/random.c
+++ b/mrbgems/mruby-random/src/random.c
@@ -22,29 +22,29 @@ static const struct mrb_data_type mt_state_type = {
static mrb_value mrb_random_rand(mrb_state *mrb, mrb_value self);
static mrb_value mrb_random_srand(mrb_state *mrb, mrb_value self);
-static void
+static void
mt_srand(mt_state *t, unsigned long seed)
{
mrb_random_init_genrand(t, seed);
-}
+}
-static unsigned long
+static unsigned long
mt_rand(mt_state *t)
{
return mrb_random_genrand_int32(t);
-}
+}
-static double
+static double
mt_rand_real(mt_state *t)
{
return mrb_random_genrand_real1(t);
-}
+}
-static mrb_value
+static mrb_value
mrb_random_mt_srand(mrb_state *mrb, mt_state *t, mrb_value seed)
-{
+{
if (mrb_nil_p(seed)) {
- seed = mrb_fixnum_value(time(NULL) + mt_rand(t));
+ seed = mrb_fixnum_value((mrb_int)(time(NULL) + mt_rand(t)));
if (mrb_fixnum(seed) < 0) {
seed = mrb_fixnum_value( 0 - mrb_fixnum(seed));
}
@@ -55,9 +55,9 @@ mrb_random_mt_srand(mrb_state *mrb, mt_state *t, mrb_value seed)
return seed;
}
-static mrb_value
+static mrb_value
mrb_random_mt_rand(mrb_state *mrb, mt_state *t, mrb_value max)
-{
+{
mrb_value value;
if (mrb_fixnum(max) == 0) {
@@ -70,7 +70,7 @@ mrb_random_mt_rand(mrb_state *mrb, mt_state *t, mrb_value max)
return value;
}
-static mrb_value
+static mrb_value
get_opt(mrb_state* mrb)
{
mrb_value arg;
@@ -104,35 +104,35 @@ get_random_state(mrb_state *mrb)
return DATA_GET_PTR(mrb, random_val, &mt_state_type, mt_state);
}
-static mrb_value
+static mrb_value
mrb_random_g_rand(mrb_state *mrb, mrb_value self)
{
mrb_value random = get_random(mrb);
return mrb_random_rand(mrb, random);
}
-static mrb_value
+static mrb_value
mrb_random_g_srand(mrb_state *mrb, mrb_value self)
{
mrb_value random = get_random(mrb);
return mrb_random_srand(mrb, random);
}
-static mrb_value
+static mrb_value
mrb_random_init(mrb_state *mrb, mrb_value self)
{
mrb_value seed;
mt_state *t;
-
+
/* avoid memory leaks */
t = (mt_state*)DATA_PTR(self);
if (t) {
mrb_free(mrb, t);
- }
+ }
DATA_TYPE(self) = &mt_state_type;
DATA_PTR(self) = NULL;
-
+
t = (mt_state *)mrb_malloc(mrb, sizeof(mt_state));
t->mti = N + 1;
@@ -146,13 +146,13 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
t->has_seed = TRUE;
t->seed = mrb_fixnum(seed);
}
-
+
DATA_PTR(self) = t;
-
+
return self;
}
-static void
+static void
mrb_random_rand_seed(mrb_state *mrb, mt_state *t)
{
if (!t->has_seed) {
@@ -160,7 +160,7 @@ mrb_random_rand_seed(mrb_state *mrb, mt_state *t)
}
}
-static mrb_value
+static mrb_value
mrb_random_rand(mrb_state *mrb, mrb_value self)
{
mrb_value max;
@@ -171,7 +171,7 @@ mrb_random_rand(mrb_state *mrb, mrb_value self)
return mrb_random_mt_rand(mrb, t, max);
}
-static mrb_value
+static mrb_value
mrb_random_srand(mrb_state *mrb, mrb_value self)
{
mrb_value seed;
@@ -205,7 +205,7 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary)
{
mrb_int i;
mt_state *random = NULL;
-
+
if (RARRAY_LEN(ary) > 1) {
mrb_get_args(mrb, "|d", &random, &mt_state_type);
@@ -213,21 +213,21 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary)
random = get_random_state(mrb);
}
mrb_random_rand_seed(mrb, random);
-
+
mrb_ary_modify(mrb, mrb_ary_ptr(ary));
-
+
for (i = RARRAY_LEN(ary) - 1; i > 0; i--) {
mrb_int j;
mrb_value tmp;
-
+
j = mrb_fixnum(mrb_random_mt_rand(mrb, random, mrb_fixnum_value(RARRAY_LEN(ary))));
-
+
tmp = RARRAY_PTR(ary)[i];
RARRAY_PTR(ary)[i] = RARRAY_PTR(ary)[j];
RARRAY_PTR(ary)[j] = tmp;
- }
+ }
}
-
+
return ary;
}
@@ -243,7 +243,7 @@ mrb_ary_shuffle(mrb_state *mrb, mrb_value ary)
{
mrb_value new_ary = mrb_ary_new_from_values(mrb, RARRAY_LEN(ary), RARRAY_PTR(ary));
mrb_ary_shuffle_bang(mrb, new_ary);
-
+
return new_ary;
}
@@ -272,7 +272,7 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary)
mrb_get_args(mrb, "|i?d", &n, &given, &random, &mt_state_type);
if (random == NULL) {
- random = get_random_state(mrb);
+ random = get_random_state(mrb);
}
mrb_random_rand_seed(mrb, random);
mt_rand(random);
@@ -334,7 +334,7 @@ void mrb_mruby_random_gem_init(mrb_state *mrb)
mrb_define_method(mrb, random, "initialize", mrb_random_init, MRB_ARGS_OPT(1));
mrb_define_method(mrb, random, "rand", mrb_random_rand, MRB_ARGS_OPT(1));
mrb_define_method(mrb, random, "srand", mrb_random_srand, MRB_ARGS_OPT(1));
-
+
mrb_define_method(mrb, array, "shuffle", mrb_ary_shuffle, MRB_ARGS_OPT(1));
mrb_define_method(mrb, array, "shuffle!", mrb_ary_shuffle_bang, MRB_ARGS_OPT(1));
mrb_define_method(mrb, array, "sample", mrb_ary_sample, MRB_ARGS_OPT(2));
diff --git a/mrbgems/mruby-random/test/random.rb b/mrbgems/mruby-random/test/random.rb
index fa31b782b..1653ae4a6 100644
--- a/mrbgems/mruby-random/test/random.rb
+++ b/mrbgems/mruby-random/test/random.rb
@@ -31,32 +31,32 @@ assert("float") do
rand.class == Float
end
-assert("Array#shuffle") do
+assert("Array#shuffle") do
ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
shuffled = ary.shuffle
-
+
ary == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and shuffled != ary and 10.times { |x| ary.include? x }
end
assert('Array#shuffle!') do
ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ary.shuffle!
-
+
ary != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary.include? x }
end
-assert("Array#shuffle(random)") do
+assert("Array#shuffle(random)") do
assert_raise(TypeError) do
# this will cause an exception due to the wrong argument
[1, 2].shuffle "Not a Random instance"
end
-
+
# verify that the same seed causes the same results
ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
shuffle1 = ary1.shuffle Random.new 345
ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
shuffle2 = ary2.shuffle Random.new 345
-
+
ary1 != shuffle1 and 10.times { |x| shuffle1.include? x } and shuffle1 == shuffle2
end
@@ -65,12 +65,12 @@ assert('Array#shuffle!(random)') do
# this will cause an exception due to the wrong argument
[1, 2].shuffle! "Not a Random instance"
end
-
+
# verify that the same seed causes the same results
ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ary1.shuffle! Random.new 345
ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ary2.shuffle! Random.new 345
-
+
ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2
end
diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c
index a82a674cf..31f22975d 100644
--- a/mrbgems/mruby-sprintf/src/sprintf.c
+++ b/mrbgems/mruby-sprintf/src/sprintf.c
@@ -999,7 +999,7 @@ retry:
char fbuf[32];
fval = mrb_float(mrb_Float(mrb, val));
- if (isnan(fval) || isinf(fval)) {
+ if (!isfinite(fval)) {
const char *expr;
const int elen = 3;
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index 4c5620575..01712a607 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -31,7 +31,7 @@ assert('String#strip') do
end
assert('String#lstrip') do
- s = " abc "
+ s = " abc "
s.lstrip
"".lstrip == "" and " \t\r\n\f\v".lstrip == "" and
"\0a\0".lstrip == "\0a\0" and
@@ -43,7 +43,7 @@ assert('String#lstrip') do
end
assert('String#rstrip') do
- s = " abc "
+ s = " abc "
s.rstrip
"".rstrip == "" and " \t\r\n\f\v".rstrip == "" and
"\0a\0".rstrip == "\0a" and
@@ -122,7 +122,7 @@ end
assert('String#partition') do
assert_equal ["a", "x", "axa"], "axaxa".partition("x")
assert_equal ["aaaaa", "", ""], "aaaaa".partition("x")
- assert_equal ["", "", "aaaaa"], "aaaaa".partition("")
+ assert_equal ["", "", "aaaaa"], "aaaaa".partition("")
assert_equal ["", "a", "aaaa"], "aaaaa".partition("a")
assert_equal ["aaaa", "b", ""], "aaaab".partition("b")
assert_equal ["", "b", "aaaa"], "baaaa".partition("b")
@@ -132,7 +132,7 @@ end
assert('String#rpartition') do
assert_equal ["axa", "x", "a"], "axaxa".rpartition("x")
assert_equal ["", "", "aaaaa"], "aaaaa".rpartition("x")
- assert_equal ["aaaaa", "", ""], "aaaaa".rpartition("")
+ assert_equal ["aaaaa", "", ""], "aaaaa".rpartition("")
assert_equal ["aaaa", "a", ""], "aaaaa".rpartition("a")
assert_equal ["aaaa", "b", ""], "aaaab".rpartition("b")
assert_equal ["", "b", "aaaa"], "baaaa".rpartition("b")
diff --git a/mrbgems/mruby-string-utf8/test/string.rb b/mrbgems/mruby-string-utf8/test/string.rb
index ce99fba47..1bfa8512c 100644
--- a/mrbgems/mruby-string-utf8/test/string.rb
+++ b/mrbgems/mruby-string-utf8/test/string.rb
@@ -14,7 +14,7 @@ end
assert('String#reverse', '15.2.10.5.29') do
a = 'こんにちは世界!'
a.reverse
-
+
assert_equal 'こんにちは世界!', a
assert_equal '!界世はちにんこ', 'こんにちは世界!'.reverse
end
@@ -22,7 +22,7 @@ end
assert('String#reverse!', '15.2.10.5.30') do
a = 'こんにちは世界!'
a.reverse!
-
+
assert_equal '!界世はちにんこ', a
assert_equal '!界世はちにんこ', 'こんにちは世界!'.reverse!
end
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 121226717..a15655dbb 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -11,6 +11,8 @@
#include "mruby/string.h"
#include "mruby/class.h"
#include "mruby/variable.h"
+#include "mruby/hash.h"
+#include "mruby/range.h"
#define RSTRUCT_LEN(st) RARRAY_LEN(st)
#define RSTRUCT_PTR(st) RARRAY_PTR(st)
@@ -530,7 +532,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
}
static mrb_value
-mrb_struct_aref_id(mrb_state *mrb, mrb_value s, mrb_sym id)
+struct_aref_sym(mrb_state *mrb, mrb_value s, mrb_sym id)
{
mrb_value *ptr, members, *ptr_members;
mrb_int i, len;
@@ -548,6 +550,21 @@ mrb_struct_aref_id(mrb_state *mrb, mrb_value s, mrb_sym id)
return mrb_nil_value(); /* not reached */
}
+static mrb_value
+struct_aref_int(mrb_state *mrb, mrb_value s, mrb_int i)
+{
+ if (i < 0) i = RSTRUCT_LEN(s) + i;
+ if (i < 0)
+ mrb_raisef(mrb, E_INDEX_ERROR,
+ "offset %S too small for struct(size:%S)",
+ mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s)));
+ if (RSTRUCT_LEN(s) <= i)
+ mrb_raisef(mrb, E_INDEX_ERROR,
+ "offset %S too large for struct(size:%S)",
+ mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s)));
+ return RSTRUCT_PTR(s)[i];
+}
+
/* 15.2.18.4.2 */
/*
* call-seq:
@@ -568,10 +585,11 @@ mrb_struct_aref_id(mrb_state *mrb, mrb_value s, mrb_sym id)
* joe[0] #=> "Joe Smith"
*/
mrb_value
-mrb_struct_aref_n(mrb_state *mrb, mrb_value s, mrb_value idx)
+mrb_struct_aref(mrb_state *mrb, mrb_value s)
{
- mrb_int i;
+ mrb_value idx;
+ mrb_get_args(mrb, "o", &idx);
if (mrb_string_p(idx)) {
mrb_value sym = mrb_check_intern_str(mrb, idx);
@@ -581,33 +599,13 @@ mrb_struct_aref_n(mrb_state *mrb, mrb_value s, mrb_value idx)
idx = sym;
}
if (mrb_symbol_p(idx)) {
- return mrb_struct_aref_id(mrb, s, mrb_symbol(idx));
+ return struct_aref_sym(mrb, s, mrb_symbol(idx));
}
-
- i = mrb_fixnum(idx);
- if (i < 0) i = RSTRUCT_LEN(s) + i;
- if (i < 0)
- mrb_raisef(mrb, E_INDEX_ERROR,
- "offset %S too small for struct(size:%S)",
- mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s)));
- if (RSTRUCT_LEN(s) <= i)
- mrb_raisef(mrb, E_INDEX_ERROR,
- "offset %S too large for struct(size:%S)",
- mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s)));
- return RSTRUCT_PTR(s)[i];
-}
-
-mrb_value
-mrb_struct_aref(mrb_state *mrb, mrb_value s)
-{
- mrb_value idx;
-
- mrb_get_args(mrb, "o", &idx);
- return mrb_struct_aref_n(mrb, s, idx);
+ return struct_aref_int(mrb, s, mrb_int(mrb, idx));
}
static mrb_value
-mrb_struct_aset_id(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val)
+mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val)
{
mrb_value members, *ptr, *ptr_members;
mrb_int i, len;
@@ -662,8 +660,8 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
mrb_get_args(mrb, "oo", &idx, &val);
- if (mrb_string_p(idx) || mrb_symbol_p(idx)) {
- return mrb_struct_aset_id(mrb, s, mrb_obj_to_sym(mrb, idx), val);
+ if (mrb_symbol_p(idx)) {
+ return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val);
}
i = mrb_fixnum(idx);
@@ -806,6 +804,39 @@ mrb_struct_to_a(mrb_state *mrb, mrb_value self)
}
/*
+ * call-seq:
+ * struct.to_h -> hash
+ *
+ * Create a hash from member names and struct values.
+ */
+static mrb_value
+mrb_struct_to_h(mrb_state *mrb, mrb_value self)
+{
+ mrb_value members, ret;
+ mrb_int i;
+
+ members = mrb_struct_s_members(mrb, mrb_obj_value(mrb_class(mrb, self)));
+ ret = mrb_hash_new_capa(mrb, RARRAY_LEN(members));
+
+ for (i = 0; i < RARRAY_LEN(members); ++i) {
+ mrb_hash_set(mrb, ret, RARRAY_PTR(members)[i], RSTRUCT_PTR(self)[i]);
+ }
+
+ return ret;
+}
+
+static mrb_value
+mrb_struct_values_at(mrb_state *mrb, mrb_value self)
+{
+ mrb_int argc;
+ mrb_value *argv;
+
+ mrb_get_args(mrb, "*", &argv, &argc);
+
+ return mrb_get_values_at(mrb, self, RSTRUCT_LEN(self), argc, argv, struct_aref_int);
+}
+
+/*
* A <code>Struct</code> is a convenient way to bundle a number of
* attributes together, using accessor methods, without having to write
* an explicit class.
@@ -842,6 +873,8 @@ mrb_mruby_struct_gem_init(mrb_state* mrb)
mrb_define_method(mrb, st, "length", mrb_struct_len, MRB_ARGS_NONE());
mrb_define_method(mrb, st, "to_a", mrb_struct_to_a, MRB_ARGS_NONE());
mrb_define_method(mrb, st, "values", mrb_struct_to_a, MRB_ARGS_NONE());
+ mrb_define_method(mrb, st, "to_h", mrb_struct_to_h, MRB_ARGS_NONE());
+ mrb_define_method(mrb, st, "values_at", mrb_struct_values_at, MRB_ARGS_NONE());
}
void
diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb
index 01e3076a5..b3b9ce33f 100644
--- a/mrbgems/mruby-struct/test/struct.rb
+++ b/mrbgems/mruby-struct/test/struct.rb
@@ -118,3 +118,15 @@ assert('Struct#to_a, Struct#values') do
assert_equal ['a', 'b'], s.to_a
assert_equal ['a', 'b'], s.values
end
+
+assert('Struct#to_h') do
+ s = Struct.new(:white, :red, :green).new('ruuko', 'yuzuki', 'hitoe')
+ assert_equal(:white => 'ruuko', :red => 'yuzuki', :green => 'hitoe') { s.to_h }
+end
+
+assert('Struct#values_at') do
+ a = Struct.new(:blue, :purple).new('aki', 'io')
+ assert_equal ['aki'], a.values_at(0)
+ assert_equal ['io', 'aki'], a.values_at(1, 0)
+ assert_raise(IndexError) { a.values_at 2 }
+end
diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
index f4bf23cb1..4cf18f647 100644
--- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
@@ -3,7 +3,7 @@ class Symbol
def to_proc
->(obj,*args,&block) do
- obj.send(self, *args, &block)
+ obj.__send__(self, *args, &block)
end
end
diff --git a/mrbgems/mruby-time/mrblib/time.rb b/mrbgems/mruby-time/mrblib/time.rb
new file mode 100644
index 000000000..df0d8ca82
--- /dev/null
+++ b/mrbgems/mruby-time/mrblib/time.rb
@@ -0,0 +1,9 @@
+class Time
+ def sunday?; wday == 0 end
+ def monday?; wday == 1 end
+ def tuesday?; wday == 2 end
+ def wednesday?; wday == 3 end
+ def thursday?; wday == 4 end
+ def friday?; wday == 5 end
+ def saturday?; wday == 6 end
+end
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 1ffab9ae6..3f8ffabef 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -10,6 +10,10 @@
#include "mruby/class.h"
#include "mruby/data.h"
+#if defined(__MINGW64__) || defined(__MINGW32__)
+# include <sys/time.h>
+#endif
+
/** Time class configuration */
/* gettimeofday(2) */
@@ -54,7 +58,7 @@
typedef long suseconds_t;
-# ifndef __MINGW64__
+# if (!defined __MINGW64__) && (!defined __MINGW32__)
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
@@ -197,14 +201,14 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time));
tm->sec = (time_t)sec;
- tm->usec = (sec - tm->sec) * 1.0e6 + usec;
+ tm->usec = (time_t)((sec - tm->sec) * 1.0e6 + usec);
while (tm->usec < 0) {
tm->sec--;
- tm->usec += 1.0e6;
+ tm->usec += 1000000;
}
- while (tm->usec > 1.0e6) {
+ while (tm->usec > 1000000) {
tm->sec++;
- tm->usec -= 1.0e6;
+ tm->usec -= 1000000;
}
tm->timezone = timezone;
mrb_time_update_datetime(tm);
@@ -297,7 +301,7 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time.");
}
- return time_alloc(mrb, nowsecs, ausec, timezone);
+ return time_alloc(mrb, (double)nowsecs, ausec, timezone);
}
/* 15.2.19.6.2 */
@@ -377,7 +381,7 @@ mrb_time_plus(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "f", &f);
tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
- return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec+f, tm->usec, tm->timezone);
+ return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec+f, (double)tm->usec, tm->timezone);
}
static mrb_value
@@ -398,7 +402,7 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
}
else {
mrb_get_args(mrb, "f", &f);
- return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec-f, tm->usec, tm->timezone);
+ return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec-f, (double)tm->usec, tm->timezone);
}
}
@@ -662,7 +666,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self)
struct mrb_time *tm;
tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
- return mrb_fixnum_value(tm->sec);
+ return mrb_fixnum_value((mrb_int)tm->sec);
}
/* 15.2.19.7.26 */
@@ -673,7 +677,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self)
struct mrb_time *tm;
tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
- return mrb_fixnum_value(tm->usec);
+ return mrb_fixnum_value((mrb_int)tm->usec);
}
/* 15.2.19.7.27 */
diff --git a/mrbgems/mruby-time/test/time.rb b/mrbgems/mruby-time/test/time.rb
index f92459d5e..450d87b43 100644
--- a/mrbgems/mruby-time/test/time.rb
+++ b/mrbgems/mruby-time/test/time.rb
@@ -1,201 +1,209 @@
##
# Time ISO Test
-if Object.const_defined?(:Time)
- assert('Time.new', '15.2.3.3.3') do
- Time.new.class == Time
- end
+assert('Time.new', '15.2.3.3.3') do
+ Time.new.class == Time
+end
- assert('Time', '15.2.19') do
- Time.class == Class
- end
+assert('Time', '15.2.19') do
+ Time.class == Class
+end
- assert('Time superclass', '15.2.19.2') do
- Time.superclass == Object
- end
+assert('Time superclass', '15.2.19.2') do
+ Time.superclass == Object
+end
- assert('Time.at', '15.2.19.6.1') do
- Time.at(1300000000.0)
- end
+assert('Time.at', '15.2.19.6.1') do
+ Time.at(1300000000.0)
+end
- assert('Time.gm', '15.2.19.6.2') do
- Time.gm(2012, 12, 23)
- end
+assert('Time.gm', '15.2.19.6.2') do
+ Time.gm(2012, 12, 23)
+end
- assert('Time.local', '15.2.19.6.3') do
- Time.local(2012, 12, 23)
- end
+assert('Time.local', '15.2.19.6.3') do
+ Time.local(2012, 12, 23)
+end
- assert('Time.mktime', '15.2.19.6.4') do
- Time.mktime(2012, 12, 23)
- end
+assert('Time.mktime', '15.2.19.6.4') do
+ Time.mktime(2012, 12, 23)
+end
- assert('Time.now', '15.2.19.6.5') do
- Time.now.class == Time
- end
+assert('Time.now', '15.2.19.6.5') do
+ Time.now.class == Time
+end
- assert('Time.utc', '15.2.19.6.6') do
- Time.utc(2012, 12, 23)
- end
+assert('Time.utc', '15.2.19.6.6') do
+ Time.utc(2012, 12, 23)
+end
- assert('Time#+', '15.2.19.7.1') do
- t1 = Time.at(1300000000.0)
- t2 = t1.+(60)
+assert('Time#+', '15.2.19.7.1') do
+ t1 = Time.at(1300000000.0)
+ t2 = t1.+(60)
- t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011"
- end
+ t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011"
+end
- assert('Time#-', '15.2.19.7.2') do
- t1 = Time.at(1300000000.0)
- t2 = t1.-(60)
+assert('Time#-', '15.2.19.7.2') do
+ t1 = Time.at(1300000000.0)
+ t2 = t1.-(60)
- t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011"
- end
+ t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011"
+end
- assert('Time#<=>', '15.2.19.7.3') do
- t1 = Time.at(1300000000.0)
- t2 = Time.at(1400000000.0)
- t3 = Time.at(1500000000.0)
+assert('Time#<=>', '15.2.19.7.3') do
+ t1 = Time.at(1300000000.0)
+ t2 = Time.at(1400000000.0)
+ t3 = Time.at(1500000000.0)
- t2.<=>(t1) == 1 and
- t2.<=>(t2) == 0 and
- t2.<=>(t3) == -1 and
- t2.<=>(nil) == nil
- end
+ t2.<=>(t1) == 1 and
+ t2.<=>(t2) == 0 and
+ t2.<=>(t3) == -1 and
+ t2.<=>(nil) == nil
+end
- assert('Time#asctime', '15.2.19.7.4') do
- Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#asctime', '15.2.19.7.4') do
+ Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
+end
- assert('Time#ctime', '15.2.19.7.5') do
- Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#ctime', '15.2.19.7.5') do
+ Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011"
+end
- assert('Time#day', '15.2.19.7.6') do
- Time.gm(2012, 12, 23).day == 23
- end
+assert('Time#day', '15.2.19.7.6') do
+ Time.gm(2012, 12, 23).day == 23
+end
- assert('Time#dst?', '15.2.19.7.7') do
- not Time.gm(2012, 12, 23).utc.dst?
- end
+assert('Time#dst?', '15.2.19.7.7') do
+ not Time.gm(2012, 12, 23).utc.dst?
+end
- assert('Time#getgm', '15.2.19.7.8') do
- Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#getgm', '15.2.19.7.8') do
+ Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011"
+end
- assert('Time#getlocal', '15.2.19.7.9') do
- t1 = Time.at(1300000000.0)
- t2 = Time.at(1300000000.0)
- t3 = t1.getlocal
+assert('Time#getlocal', '15.2.19.7.9') do
+ t1 = Time.at(1300000000.0)
+ t2 = Time.at(1300000000.0)
+ t3 = t1.getlocal
- t1 == t3 and t3 == t2.getlocal
- end
+ t1 == t3 and t3 == t2.getlocal
+end
- assert('Time#getutc', '15.2.19.7.10') do
- Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#getutc', '15.2.19.7.10') do
+ Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
+end
- assert('Time#gmt?', '15.2.19.7.11') do
- Time.at(1300000000.0).utc.gmt?
- end
+assert('Time#gmt?', '15.2.19.7.11') do
+ Time.at(1300000000.0).utc.gmt?
+end
- # ATM not implemented
- # assert('Time#gmt_offset', '15.2.19.7.12') do
+# ATM not implemented
+# assert('Time#gmt_offset', '15.2.19.7.12') do
- assert('Time#gmtime', '15.2.19.7.13') do
- Time.at(1300000000.0).gmtime
- end
+assert('Time#gmtime', '15.2.19.7.13') do
+ Time.at(1300000000.0).gmtime
+end
- # ATM not implemented
- # assert('Time#gmtoff', '15.2.19.7.14') do
+# ATM not implemented
+# assert('Time#gmtoff', '15.2.19.7.14') do
- assert('Time#hour', '15.2.19.7.15') do
- Time.gm(2012, 12, 23, 7, 6).hour == 7
- end
+assert('Time#hour', '15.2.19.7.15') do
+ Time.gm(2012, 12, 23, 7, 6).hour == 7
+end
- # ATM doesn't really work
- # assert('Time#initialize', '15.2.19.7.16') do
+# ATM doesn't really work
+# assert('Time#initialize', '15.2.19.7.16') do
- assert('Time#initialize_copy', '15.2.19.7.17') do
- time_tmp_2 = Time.at(7.0e6)
- time_tmp_2.clone == time_tmp_2
- end
+assert('Time#initialize_copy', '15.2.19.7.17') do
+ time_tmp_2 = Time.at(7.0e6)
+ time_tmp_2.clone == time_tmp_2
+end
- assert('Time#localtime', '15.2.19.7.18') do
- t1 = Time.at(1300000000.0)
- t2 = Time.at(1300000000.0)
+assert('Time#localtime', '15.2.19.7.18') do
+ t1 = Time.at(1300000000.0)
+ t2 = Time.at(1300000000.0)
- t1.localtime
- t1 == t2.getlocal
- end
+ t1.localtime
+ t1 == t2.getlocal
+end
- assert('Time#mday', '15.2.19.7.19') do
- Time.gm(2012, 12, 23).mday == 23
- end
+assert('Time#mday', '15.2.19.7.19') do
+ Time.gm(2012, 12, 23).mday == 23
+end
- assert('Time#min', '15.2.19.7.20') do
- Time.gm(2012, 12, 23, 7, 6).min == 6
- end
+assert('Time#min', '15.2.19.7.20') do
+ Time.gm(2012, 12, 23, 7, 6).min == 6
+end
- assert('Time#mon', '15.2.19.7.21') do
- Time.gm(2012, 12, 23).mon == 12
- end
+assert('Time#mon', '15.2.19.7.21') do
+ Time.gm(2012, 12, 23).mon == 12
+end
- assert('Time#month', '15.2.19.7.22') do
- Time.gm(2012, 12, 23).month == 12
- end
+assert('Time#month', '15.2.19.7.22') do
+ Time.gm(2012, 12, 23).month == 12
+end
- assert('Times#sec', '15.2.19.7.23') do
- Time.gm(2012, 12, 23, 7, 6, 40).sec == 40
- end
+assert('Times#sec', '15.2.19.7.23') do
+ Time.gm(2012, 12, 23, 7, 6, 40).sec == 40
+end
- assert('Time#to_f', '15.2.19.7.24') do
- Time.at(1300000000.0).to_f == 1300000000.0
- end
+assert('Time#to_f', '15.2.19.7.24') do
+ Time.at(1300000000.0).to_f == 1300000000.0
+end
- assert('Time#to_i', '15.2.19.7.25') do
- Time.at(1300000000.0).to_i == 1300000000
- end
+assert('Time#to_i', '15.2.19.7.25') do
+ Time.at(1300000000.0).to_i == 1300000000
+end
- assert('Time#usec', '15.2.19.7.26') do
- Time.at(1300000000.0).usec == 0
- end
+assert('Time#usec', '15.2.19.7.26') do
+ Time.at(1300000000.0).usec == 0
+end
- assert('Time#utc', '15.2.19.7.27') do
- Time.at(1300000000.0).utc
- end
+assert('Time#utc', '15.2.19.7.27') do
+ Time.at(1300000000.0).utc
+end
- assert('Time#utc?', '15.2.19.7.28') do
- Time.at(1300000000.0).utc.utc?
- end
+assert('Time#utc?', '15.2.19.7.28') do
+ Time.at(1300000000.0).utc.utc?
+end
- # ATM not implemented
- # assert('Time#utc_offset', '15.2.19.7.29') do
+# ATM not implemented
+# assert('Time#utc_offset', '15.2.19.7.29') do
- assert('Time#wday', '15.2.19.7.30') do
- Time.gm(2012, 12, 23).wday == 0
- end
+assert('Time#wday', '15.2.19.7.30') do
+ Time.gm(2012, 12, 23).wday == 0
+end
- assert('Time#yday', '15.2.19.7.31') do
- Time.gm(2012, 12, 23).yday == 358
- end
+assert('Time#yday', '15.2.19.7.31') do
+ Time.gm(2012, 12, 23).yday == 358
+end
- assert('Time#year', '15.2.19.7.32') do
- Time.gm(2012, 12, 23).year == 2012
- end
+assert('Time#year', '15.2.19.7.32') do
+ Time.gm(2012, 12, 23).year == 2012
+end
- assert('Time#zone', '15.2.19.7.33') do
- Time.at(1300000000.0).utc.zone == 'UTC'
- end
+assert('Time#zone', '15.2.19.7.33') do
+ Time.at(1300000000.0).utc.zone == 'UTC'
+end
- # Not ISO specified
+# Not ISO specified
- assert('Time#to_s') do
- Time.at(1300000000.0).utc.to_s == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#to_s') do
+ Time.at(1300000000.0).utc.to_s == "Sun Mar 13 07:06:40 UTC 2011"
+end
- assert('Time#inspect') do
- Time.at(1300000000.0).utc.inspect == "Sun Mar 13 07:06:40 UTC 2011"
- end
+assert('Time#inspect') do
+ Time.at(1300000000.0).utc.inspect == "Sun Mar 13 07:06:40 UTC 2011"
end
+assert('day of week methods') do
+ t = Time.gm(2012, 12, 24)
+ assert_false t.sunday?
+ assert_true t.monday?
+ assert_false t.tuesday?
+ assert_false t.wednesday?
+ assert_false t.thursday?
+ assert_false t.friday?
+ assert_false t.saturday?
+end
diff --git a/mrbgems/mruby-toplevel-ext/test/toplevel.rb b/mrbgems/mruby-toplevel-ext/test/toplevel.rb
index 9630fe3dd..aebdd8b4b 100644
--- a/mrbgems/mruby-toplevel-ext/test/toplevel.rb
+++ b/mrbgems/mruby-toplevel-ext/test/toplevel.rb
@@ -15,7 +15,7 @@ assert('Toplevel#include') do
end
self.include ToplevelTestModule2, ToplevelTestModule1
-
+
assert_true self.class.included_modules.include?( ToplevelTestModule1 )
assert_true self.class.included_modules.include?( ToplevelTestModule2 )
assert_equal :foo, method_foo
diff --git a/mrblib/enum.rb b/mrblib/enum.rb
index 4f9682ac7..41fd97fe7 100644
--- a/mrblib/enum.rb
+++ b/mrblib/enum.rb
@@ -202,7 +202,7 @@ module Enumerable
raise ArgumentError, "too many arguments" if args.size > 2
if Symbol === args[-1]
sym = args[-1]
- block = ->(x,y){x.send(sym,y)}
+ block = ->(x,y){x.__send__(sym,y)}
args.pop
end
if args.empty?
diff --git a/mrblib/error.rb b/mrblib/error.rb
index 9e5a3daeb..6e8181e9d 100644
--- a/mrblib/error.rb
+++ b/mrblib/error.rb
@@ -40,10 +40,6 @@ end
class NameError < StandardError
attr_accessor :name
- def new(message="NameError", name=nil)
- initialize(message, name)
- end
-
def initialize(message=nil, name=nil)
@name = name
super(message)
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 87e517b97..9bb146b27 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -161,7 +161,7 @@ class Hash
}
if hash.default_proc
self.default_proc = hash.default_proc
- else
+ else
self.default = hash.default
end
self
@@ -179,7 +179,7 @@ class Hash
# ISO 15.2.13.4.22
def merge(other, &block)
h = {}
- raise "can't convert argument into Hash" unless other.respond_to?(:to_hash)
+ raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
other = other.to_hash
self.each_key{|k| h[k] = self[k]}
if block
@@ -205,7 +205,16 @@ class Hash
# ISO 15.2.13.4.31 (x)
alias to_s inspect
- # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.reject! {| key, value | block } -> hsh or nil
+ # hsh.reject! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#delete_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
+ #
def reject!(&b)
return to_enum :reject! unless block_given?
@@ -222,7 +231,21 @@ class Hash
self
end
- # 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.reject {|key, value| block} -> a_hash
+ # hsh.reject -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns false.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300}
+ # h.reject {|k,v| v > 100} #=> {"a" => 100}
+ #
+ # 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
+ #
def reject(&b)
return to_enum :reject unless block_given?
@@ -235,7 +258,16 @@ class Hash
h
end
- # 1.9 Hash#select! returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.select! {| key, value | block } -> hsh or nil
+ # hsh.select! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#keep_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.9 Hash#select! returns Hash; ISO says nothing.
+ #
def select!(&b)
return to_enum :select! unless block_given?
@@ -252,7 +284,21 @@ class Hash
self
end
- # 1.9 Hash#select returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.select {|key, value| block} -> a_hash
+ # hsh.select -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns true.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
+ # h.select {|k,v| v < 200} #=> {"a" => 100}
+ #
+ # 1.9 Hash#select returns Hash; ISO says nothing
+ #
def select(&b)
return to_enum :select unless block_given?
diff --git a/mrblib/mrblib.rake b/mrblib/mrblib.rake
index db70842bf..0c549f5b8 100644
--- a/mrblib/mrblib.rake
+++ b/mrblib/mrblib.rake
@@ -2,7 +2,7 @@ MRuby.each_target do
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
-
+
self.libmruby << objfile("#{current_build_dir}/mrblib")
file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c"
diff --git a/src/array.c b/src/array.c
index febc3a7a8..d008e52cf 100644
--- a/src/array.c
+++ b/src/array.c
@@ -401,7 +401,7 @@ mrb_ary_push(mrb_state *mrb, mrb_value ary, mrb_value elem)
if (a->len == a->aux.capa)
ary_expand_capa(mrb, a, a->len + 1);
a->ptr[a->len++] = elem;
- mrb_write_barrier(mrb, (struct RBasic*)a);
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)a, elem);
}
static mrb_value
@@ -484,7 +484,7 @@ mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item)
a->ptr[0] = item;
}
a->len++;
- mrb_write_barrier(mrb, (struct RBasic*)a);
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)a, item);
return self;
}
@@ -511,7 +511,9 @@ mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
}
array_copy(a->ptr, vals, len);
a->len += len;
- mrb_write_barrier(mrb, (struct RBasic*)a);
+ while (len--) {
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)a, vals[len]);
+ }
return self;
}
@@ -549,7 +551,7 @@ mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val)
}
a->ptr[n] = val;
- mrb_write_barrier(mrb, (struct RBasic*)a);
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)a, val);
}
mrb_value
@@ -561,6 +563,10 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
mrb_int i, argc;
ary_modify(mrb, a);
+
+ /* len check */
+ if (len < 0) mrb_raisef(mrb, E_INDEX_ERROR, "negative length (%S)", mrb_fixnum_value(len));
+
/* range check */
if (head < 0) {
head += a->len;
@@ -597,6 +603,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
for (i = 0; i < argc; i++) {
*(a->ptr + head + i) = *(argv + i);
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)a, argv[i]);
}
a->len = size;
diff --git a/src/codegen.c b/src/codegen.c
index 5e22e199f..226cd9bf8 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -2755,7 +2755,7 @@ codedump(mrb_state *mrb, mrb_irep *irep)
print_lv(mrb, irep, c, RA);
break;
case OP_GETGLOBAL:
- printf("OP_GETGLOBAL\tR%d\t:%s\n", GETARG_A(c),
+ printf("OP_GETGLOBAL\tR%d\t:%s", GETARG_A(c),
mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
print_lv(mrb, irep, c, RA);
break;
diff --git a/src/dump.c b/src/dump.c
index 854ddfe33..7ad3d6985 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -860,8 +860,8 @@ is_debug_info_defined(mrb_irep *irep)
return TRUE;
}
-static int
-dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, size_t *bin_size)
+int
+mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, size_t *bin_size)
{
int result = MRB_DUMP_GENERAL_FAILURE;
size_t section_irep_size;
@@ -964,7 +964,7 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, int debug_info, FILE* fp)
return MRB_DUMP_INVALID_ARGUMENT;
}
- result = dump_irep(mrb, irep, debug_info, &bin, &bin_size);
+ result = mrb_dump_irep(mrb, irep, debug_info, &bin, &bin_size);
if (result == MRB_DUMP_OK) {
fwrite(bin, bin_size, 1, fp);
}
@@ -1000,7 +1000,7 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, int debug_info, FILE *fp, co
return MRB_DUMP_INVALID_ARGUMENT;
}
- result = dump_irep(mrb, irep, debug_info, &bin, &bin_size);
+ result = mrb_dump_irep(mrb, irep, debug_info, &bin, &bin_size);
if (result == MRB_DUMP_OK) {
fprintf(fp, "#include <stdint.h>\n"); /* for uint8_t under at least Darwin */
fprintf(fp, "const uint8_t %s[] = {", initname);
diff --git a/src/error.c b/src/error.c
index 8f13dcf77..b4fac2097 100644
--- a/src/error.c
+++ b/src/error.c
@@ -115,7 +115,10 @@ exc_message(mrb_state *mrb, mrb_value exc)
* call-seq:
* exception.inspect -> string
*
- * Return this exception's class name an message
+ * Returns this exception's file name, line number,
+ * message and class name.
+ * If file name or line number is not set,
+ * returns message and class name.
*/
static mrb_value
@@ -442,20 +445,20 @@ mrb_sys_fail(mrb_state *mrb, const char *mesg)
void
mrb_init_exception(mrb_state *mrb)
{
- struct RClass *e;
-
- mrb->eException_class = e = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */
- mrb_define_class_method(mrb, e, "exception", mrb_instance_new, MRB_ARGS_ANY());
- mrb_define_method(mrb, e, "exception", exc_exception, MRB_ARGS_ANY());
- mrb_define_method(mrb, e, "initialize", exc_initialize, MRB_ARGS_ANY());
- mrb_define_method(mrb, e, "==", exc_equal, MRB_ARGS_REQ(1));
- mrb_define_method(mrb, e, "to_s", exc_to_s, MRB_ARGS_NONE());
- mrb_define_method(mrb, e, "message", exc_message, MRB_ARGS_NONE());
- mrb_define_method(mrb, e, "inspect", exc_inspect, MRB_ARGS_NONE());
- mrb_define_method(mrb, e, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE());
-
- mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */
+ struct RClass *exception, *script_error;
+
+ mrb->eException_class = exception = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */
+ mrb_define_class_method(mrb, exception, "exception", mrb_instance_new, MRB_ARGS_ANY());
+ mrb_define_method(mrb, exception, "exception", exc_exception, MRB_ARGS_ANY());
+ mrb_define_method(mrb, exception, "initialize", exc_initialize, MRB_ARGS_ANY());
+ mrb_define_method(mrb, exception, "==", exc_equal, MRB_ARGS_REQ(1));
+ mrb_define_method(mrb, exception, "to_s", exc_to_s, MRB_ARGS_NONE());
+ mrb_define_method(mrb, exception, "message", exc_message, MRB_ARGS_NONE());
+ mrb_define_method(mrb, exception, "inspect", exc_inspect, MRB_ARGS_NONE());
+ mrb_define_method(mrb, exception, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE());
+
+ mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */
mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */
- e = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */
- mrb_define_class(mrb, "SyntaxError", e); /* 15.2.38 */
+ script_error = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */
+ mrb_define_class(mrb, "SyntaxError", script_error); /* 15.2.38 */
}
diff --git a/src/gc.c b/src/gc.c
index 2660ffcc7..4478b71f3 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -121,9 +121,9 @@ static double gc_total_time = 0;
static double
gettimeofday_time(void)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec + tv.tv_usec * 1e-6;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec + tv.tv_usec * 1e-6;
}
#define GC_INVOKE_TIME_REPORT(with) do {\
diff --git a/src/hash.c b/src/hash.c
index c39560d5c..8e6be2214 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -221,7 +221,7 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val)
kh_value(h, k).n = kh_size(h)-1;
}
- mrb_write_barrier(mrb, (struct RBasic*)RHASH(hash));
+ mrb_field_write_barrier_value(mrb, (struct RBasic*)RHASH(hash), val);
return;
}
diff --git a/src/kernel.c b/src/kernel.c
index 4db8ad7ee..7bcbd6518 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -93,24 +93,18 @@ static mrb_value
mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
{
mrb_value arg;
- mrb_bool eql_p;
mrb_get_args(mrb, "o", &arg);
- eql_p = mrb_obj_equal(mrb, self, arg);
-
- return mrb_bool_value(eql_p);
+ return mrb_bool_value(mrb_obj_equal(mrb, self, arg));
}
static mrb_value
mrb_obj_not_equal_m(mrb_state *mrb, mrb_value self)
{
mrb_value arg;
- mrb_bool eql_p;
mrb_get_args(mrb, "o", &arg);
- eql_p = mrb_equal(mrb, self, arg);
-
- return mrb_bool_value(!eql_p);
+ return mrb_bool_value(!mrb_equal(mrb, self, arg));
}
/* 15.3.1.3.2 */
@@ -126,12 +120,9 @@ static mrb_value
mrb_equal_m(mrb_state *mrb, mrb_value self)
{
mrb_value arg;
- mrb_bool equal_p;
mrb_get_args(mrb, "o", &arg);
- equal_p = mrb_equal(mrb, self, arg);
-
- return mrb_bool_value(equal_p);
+ return mrb_bool_value(mrb_equal(mrb, self, arg));
}
/* 15.3.1.3.3 */
@@ -210,26 +201,6 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
return mrb_bool_value(given_p);
}
-/*
- * call-seq:
- * __method__ -> symbol
- *
- * Returns the name at the definition of the current method as a
- * Symbol.
- * If called outside of a method, it returns <code>nil</code>.
- *
- */
-static mrb_value
-mrb_f_method(mrb_state *mrb, mrb_value self)
-{
- mrb_callinfo *ci = mrb->c->ci;
- ci--;
- if (ci->mid)
- return mrb_symbol_value(ci->mid);
- else
- return mrb_nil_value();
-}
-
/* 15.3.1.3.7 */
/*
* call-seq:
@@ -296,21 +267,21 @@ static void
init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
{
switch (mrb_type(obj)) {
- case MRB_TT_CLASS:
- case MRB_TT_MODULE:
- copy_class(mrb, dest, obj);
- /* fall through */
- case MRB_TT_OBJECT:
- case MRB_TT_SCLASS:
- case MRB_TT_HASH:
- case MRB_TT_DATA:
- mrb_iv_copy(mrb, dest, obj);
- break;
-
- default:
- break;
- }
- mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
+ case MRB_TT_CLASS:
+ case MRB_TT_MODULE:
+ copy_class(mrb, dest, obj);
+ /* fall through */
+ case MRB_TT_OBJECT:
+ case MRB_TT_SCLASS:
+ case MRB_TT_HASH:
+ case MRB_TT_DATA:
+ mrb_iv_copy(mrb, dest, obj);
+ break;
+
+ default:
+ break;
+ }
+ mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
}
/* 15.3.1.3.8 */
@@ -346,7 +317,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
mrb_value clone;
if (mrb_special_const_p(self)) {
- mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %S", self);
+ mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %S", self);
}
p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
p->c = mrb_singleton_class_clone(mrb, self);
@@ -378,17 +349,17 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
mrb_value
mrb_obj_dup(mrb_state *mrb, mrb_value obj)
{
- struct RBasic *p;
- mrb_value dup;
+ struct RBasic *p;
+ mrb_value dup;
- if (mrb_special_const_p(obj)) {
- mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %S", obj);
- }
- p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
- dup = mrb_obj_value(p);
- init_copy(mrb, dup, obj);
+ if (mrb_special_const_p(obj)) {
+ mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %S", obj);
+ }
+ p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
+ dup = mrb_obj_value(p);
+ init_copy(mrb, dup, obj);
- return dup;
+ return dup;
}
static mrb_value
@@ -924,7 +895,7 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
* raise "Failed to create socket"
* raise ArgumentError, "No parameters", caller
*/
-static mrb_value
+mrb_value
mrb_f_raise(mrb_state *mrb, mrb_value self)
{
mrb_value a[2], exc;
@@ -1153,7 +1124,6 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "===", mrb_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.2 */
mrb_define_method(mrb, krn, "__id__", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.3 */
mrb_define_method(mrb, krn, "__send__", mrb_f_send, MRB_ARGS_ANY()); /* 15.3.1.3.4 */
- mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE());
mrb_define_method(mrb, krn, "block_given?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.6 */
mrb_define_method(mrb, krn, "class", mrb_obj_class_m, MRB_ARGS_NONE()); /* 15.3.1.3.7 */
mrb_define_method(mrb, krn, "clone", mrb_obj_clone, MRB_ARGS_NONE()); /* 15.3.1.3.8 */
diff --git a/src/load.c b/src/load.c
index 912a28218..dc5a5bf06 100644
--- a/src/load.c
+++ b/src/load.c
@@ -191,12 +191,10 @@ read_section_irep(mrb_state *mrb, const uint8_t *bin, mrb_bool alloc)
static int
read_lineno_record_1(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep, size_t *len)
{
- int ret;
size_t i, fname_len, niseq;
char *fname;
uint16_t *lines;
- ret = MRB_DUMP_OK;
*len = 0;
bin += sizeof(uint32_t); /* record size */
*len += sizeof(uint32_t);
@@ -228,7 +226,7 @@ read_lineno_record_1(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep, size_t
irep->filename = fname;
irep->lines = lines;
- return ret;
+ return MRB_DUMP_OK;
}
static int
diff --git a/src/mruby_core.rake b/src/mruby_core.rake
index 87759aa61..04be0736c 100644
--- a/src/mruby_core.rake
+++ b/src/mruby_core.rake
@@ -2,7 +2,7 @@ MRuby.each_target do
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
-
+
lex_def = "#{current_dir}/lex.def"
objs = Dir.glob("#{current_dir}/*.c").map { |f|
next nil if cxx_abi_enabled? and f =~ /(codegen|error|vm).c$/
diff --git a/src/numeric.c b/src/numeric.c
index ef7b5fc82..b3daddf85 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -150,7 +150,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_float flo)
else {
exp = 0;
}
-
+
/* preserve significands */
if (exp < 0) {
int i, beg = -1, end = 0;
@@ -309,7 +309,7 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
}
else {
mod = fmod(x, y);
- if (isinf(x) && !isinf(y) && !isnan(y))
+ if (isinf(x) && isfinite(y))
div = x;
else
div = (x - mod) / y;
@@ -495,7 +495,7 @@ flo_finite_p(mrb_state *mrb, mrb_value num)
{
mrb_float value = mrb_float(num);
- return mrb_bool_value(!(isinf(value) || isnan(value)));
+ return mrb_bool_value(isfinite(value));
}
/* 15.2.9.3.10 */
@@ -626,7 +626,7 @@ flo_round(mrb_state *mrb, mrb_value num)
}
if (ndigits > 0) {
- if (isinf(number) || isnan(number)) return num;
+ if (!isfinite(number)) return num;
return mrb_float_value(mrb, number);
}
return mrb_fixnum_value((mrb_int)number);
@@ -687,7 +687,11 @@ int_to_i(mrb_state *mrb, mrb_value num)
return num;
}
+#ifdef MRB_FIXNUM_SHIFT
+#define SQRT_INT_MAX ((mrb_int)1<<((MRB_INT_BIT-1-MRB_FIXNUM_SHIFT)/2))
+#else
#define SQRT_INT_MAX ((mrb_int)1<<((MRB_INT_BIT-1)/2))
+#endif
/*tests if N*N would overflow*/
#define FIT_SQRT_INT(n) (((n)<SQRT_INT_MAX)&&((n)>=-SQRT_INT_MAX))
@@ -698,14 +702,15 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
a = mrb_fixnum(x);
if (mrb_fixnum_p(y)) {
- mrb_int b, c;
+ mrb_float c;
+ mrb_int b;
if (a == 0) return x;
b = mrb_fixnum(y);
if (FIT_SQRT_INT(a) && FIT_SQRT_INT(b))
return mrb_fixnum_value(a*b);
c = a * b;
- if (a != 0 && c/a != b) {
+ if ((a != 0 && c/a != b) || !FIXABLE(c)) {
return mrb_float_value(mrb, (mrb_float)a*(mrb_float)b);
}
return mrb_fixnum_value(c);
@@ -774,17 +779,17 @@ static mrb_value
fix_mod(mrb_state *mrb, mrb_value x)
{
mrb_value y;
- mrb_int a, b;
+ mrb_int a;
mrb_get_args(mrb, "o", &y);
a = mrb_fixnum(x);
- if (mrb_fixnum_p(y) && (b=mrb_fixnum(y)) != 0) {
- mrb_int mod;
+ if (mrb_fixnum_p(y)) {
+ mrb_int b, mod;
- if (mrb_fixnum(y) == 0) {
+ if ((b=mrb_fixnum(y)) == 0) {
return mrb_float_value(mrb, NAN);
}
- fixdivmod(mrb, a, mrb_fixnum(y), 0, &mod);
+ fixdivmod(mrb, a, b, 0, &mod);
return mrb_fixnum_value(mod);
}
else {
@@ -980,17 +985,11 @@ rshift(mrb_int val, mrb_int width)
mrb_assert(width >= 0);
if (width >= NUMERIC_SHIFT_WIDTH_MAX) {
if (val < 0) {
- val = -1;
- }
- else {
- val = 0;
+ return mrb_fixnum_value(-1);
}
+ return mrb_fixnum_value(0);
}
- else {
- val = val >> width;
- }
-
- return mrb_fixnum_value(val);
+ return mrb_fixnum_value(val >> width);
}
static inline void
@@ -1115,9 +1114,7 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
if (a == 0) return y;
b = mrb_fixnum(y);
- c = a + b;
- if (((a < 0) ^ (b < 0)) == 0 && (a < 0) != (c < 0)) {
- /* integer overflow */
+ if (mrb_int_add_overflow(a, b, &c)) {
return mrb_float_value(mrb, (mrb_float)a + (mrb_float)b);
}
return mrb_fixnum_value(c);
@@ -1153,9 +1150,7 @@ mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
mrb_int b, c;
b = mrb_fixnum(y);
- c = a - b;
- if (((a < 0) ^ (b < 0)) != 0 && (a < 0) != (c < 0)) {
- /* integer overflow */
+ if (mrb_int_sub_overflow(a, b, &c)) {
return mrb_float_value(mrb, (mrb_float)a - (mrb_float)b);
}
return mrb_fixnum_value(c);
diff --git a/src/parse.y b/src/parse.y
index aab1aaa40..205405065 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -3417,15 +3417,15 @@ skip(parser_state *p, char term)
}
}
-static mrb_bool
-peek_n(parser_state *p, int c, int n)
+static int
+peekc_n(parser_state *p, int n)
{
node *list = 0;
int c0;
do {
c0 = nextc(p);
- if (c0 < 0) return FALSE;
+ if (c0 < 0) return c0;
list = push(list, (node*)(intptr_t)c0);
} while(n--);
if (p->pb) {
@@ -3434,8 +3434,13 @@ peek_n(parser_state *p, int c, int n)
else {
p->pb = list;
}
- if (c0 == c) return TRUE;
- return FALSE;
+ return c0;
+}
+
+static mrb_bool
+peek_n(parser_state *p, int c, int n)
+{
+ return peekc_n(p, n) == c && c >= 0;
}
#define peek(p,c) peek_n((p), (c), 0)
@@ -3454,7 +3459,7 @@ peeks(parser_state *p, const char *s)
}
else
#endif
- if (p->s && p->s + len >= p->send) {
+ if (p->s && p->s + len <= p->send) {
if (memcmp(p->s, s, len) == 0) return TRUE;
}
return FALSE;
@@ -3470,6 +3475,10 @@ skips(parser_state *p, const char *s)
for (;;) {
c = nextc(p);
if (c < 0) return c;
+ if (c == '\n') {
+ p->lineno++;
+ p->column = 0;
+ }
if (c == *s) break;
}
s++;
@@ -3477,7 +3486,10 @@ skips(parser_state *p, const char *s)
int len = strlen(s);
while (len--) {
- nextc(p);
+ if (nextc(p) == '\n') {
+ p->lineno++;
+ p->column = 0;
+ }
}
return TRUE;
}
@@ -4189,14 +4201,23 @@ parser_yylex(parser_state *p)
case '=':
if (p->column == 1) {
- if (peeks(p, "begin ") || peeks(p, "begin\n")) {
- if (skips(p, "\n=end ")) {
- goto retry;
- }
- if (skips(p, "\n=end\n")) {
+ static const char begin[] = "begin";
+ static const char end[] = "\n=end";
+ if (peeks(p, begin)) {
+ c = peekc_n(p, sizeof(begin)-1);
+ if (c < 0 || isspace(c)) {
+ do {
+ if (!skips(p, end)) {
+ yyerror(p, "embedded document meets end of file");
+ return 0;
+ }
+ c = nextc(p);
+ } while (!(c < 0 || isspace(c)));
+ if (c != '\n') skip(p, '\n');
+ p->lineno++;
+ p->column = 0;
goto retry;
}
- goto retry;
}
}
if (p->lstate == EXPR_FNAME || p->lstate == EXPR_DOT) {
@@ -5445,7 +5466,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
new_table = (mrb_sym*)parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length);
if (p->filename_table) {
- memcpy(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
+ memmove(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
}
p->filename_table = new_table;
p->filename_table[p->filename_table_length - 1] = sym;
diff --git a/src/print.c b/src/print.c
index 6472a4675..f4ed85601 100644
--- a/src/print.c
+++ b/src/print.c
@@ -38,7 +38,7 @@ mrb_print_error(mrb_state *mrb)
{
#ifdef ENABLE_STDIO
mrb_value s;
-
+
mrb_print_backtrace(mrb);
s = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
if (mrb_string_p(s)) {
diff --git a/src/proc.c b/src/proc.c
index b29bd5977..fa4c28fc8 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -43,7 +43,7 @@ closure_setup(mrb_state *mrb, struct RProc *p, int nlocals)
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->c->ci->proc->env);
MRB_ENV_STACK_LEN(e)= (unsigned int)nlocals;
e->mid = mrb->c->ci->mid;
- e->cioff = mrb->c->ci - mrb->c->cibase;
+ e->cioff = mrb->c->ci - mrb->c->cibase;
e->stack = mrb->c->stack;
mrb->c->ci->env = e;
}
diff --git a/src/range.c b/src/range.c
index b59b234ef..3e5af1894 100644
--- a/src/range.c
+++ b/src/range.c
@@ -8,6 +8,7 @@
#include "mruby/class.h"
#include "mruby/range.h"
#include "mruby/string.h"
+#include "mruby/array.h"
#define RANGE_CLASS (mrb_class_get(mrb, "Range"))
@@ -233,53 +234,30 @@ mrb_range_include(mrb_state *mrb, mrb_value range)
return mrb_bool_value(include_p);
}
-/*
- * call-seq:
- * rng.each {| i | block } => rng
- *
- * Iterates over the elements <i>rng</i>, passing each in turn to the
- * block. You can only iterate if the start object of the range
- * supports the +succ+ method (which means that you can't iterate over
- * ranges of +Float+ objects).
- *
- * (10..15).each do |n|
- * print n, ' '
- * end
- *
- * <em>produces:</em>
- *
- * 10 11 12 13 14 15
- */
-
-mrb_value
-mrb_range_each(mrb_state *mrb, mrb_value range)
-{
- return range;
-}
-
mrb_bool
-mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len)
+range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc)
{
mrb_int beg, end, b, e;
struct RRange *r = mrb_range_ptr(range);
- if (mrb_type(range) != MRB_TT_RANGE) {
- mrb_raise(mrb, E_TYPE_ERROR, "expected Range.");
- }
+ if (mrb_type(range) != MRB_TT_RANGE) return FALSE;
- beg = b = mrb_fixnum(r->edges->beg);
- end = e = mrb_fixnum(r->edges->end);
+ beg = b = mrb_int(mrb, r->edges->beg);
+ end = e = mrb_int(mrb, r->edges->end);
if (beg < 0) {
beg += len;
if (beg < 0) return FALSE;
}
- if (beg > len) return FALSE;
- if (end > len) end = len;
+ if (trunc) {
+ if (beg > len) return FALSE;
+ if (end > len) end = len;
+ }
if (end < 0) end += len;
- if (!r->excl && end < len) end++; /* include end point */
+ if (!r->excl && (!trunc || end < len))
+ end++; /* include end point */
len = end - beg;
if (len < 0) len = 0;
@@ -288,6 +266,12 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
return TRUE;
}
+mrb_bool
+mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len)
+{
+ return range_beg_len(mrb, range, begp, lenp, len, TRUE);
+}
+
/* 15.2.14.4.12(x) */
/*
* call-seq:
@@ -395,6 +379,35 @@ range_initialize_copy(mrb_state *mrb, mrb_value copy)
return copy;
}
+mrb_value
+mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int))
+{
+ mrb_int i, j, beg, len;
+ mrb_value result;
+ result = mrb_ary_new(mrb);
+
+ for (i = 0; i < argc; ++i) {
+ if (mrb_fixnum_p(argv[i])) {
+ mrb_ary_push(mrb, result, func(mrb, obj, mrb_fixnum(argv[i])));
+ }
+ else if (range_beg_len(mrb, argv[i], &beg, &len, olen, FALSE)) {
+ mrb_int const end = olen < beg + len ? olen : beg + len;
+ for (j = beg; j < end; ++j) {
+ mrb_ary_push(mrb, result, func(mrb, obj, j));
+ }
+
+ for (; j < beg + len; ++j) {
+ mrb_ary_push(mrb, result, mrb_nil_value());
+ }
+ }
+ else {
+ mrb_raisef(mrb, E_TYPE_ERROR, "invalid values selector: %S", argv[i]);
+ }
+ }
+
+ return result;
+}
+
void
mrb_init_range(mrb_state *mrb)
{
@@ -407,7 +420,6 @@ mrb_init_range(mrb_state *mrb)
mrb_define_method(mrb, r, "end", mrb_range_end, MRB_ARGS_NONE()); /* 15.2.14.4.5 */
mrb_define_method(mrb, r, "==", mrb_range_eq, MRB_ARGS_REQ(1)); /* 15.2.14.4.1 */
mrb_define_method(mrb, r, "===", mrb_range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.2 */
- mrb_define_method(mrb, r, "each", mrb_range_each, MRB_ARGS_NONE()); /* 15.2.14.4.4 */
mrb_define_method(mrb, r, "exclude_end?", mrb_range_excl, MRB_ARGS_NONE()); /* 15.2.14.4.6 */
mrb_define_method(mrb, r, "first", mrb_range_beg, MRB_ARGS_NONE()); /* 15.2.14.4.7 */
mrb_define_method(mrb, r, "include?", mrb_range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.8 */
diff --git a/src/string.c b/src/string.c
index aa4f6bed5..d5a849cec 100644
--- a/src/string.c
+++ b/src/string.c
@@ -914,7 +914,7 @@ static mrb_value
mrb_str_capitalize_bang(mrb_state *mrb, mrb_value str)
{
char *p, *pend;
- int modify = 0;
+ mrb_bool modify = FALSE;
struct RString *s = mrb_str_ptr(str);
mrb_str_modify(mrb, s);
@@ -922,12 +922,12 @@ mrb_str_capitalize_bang(mrb_state *mrb, mrb_value str)
p = STR_PTR(s); pend = STR_PTR(s) + STR_LEN(s);
if (ISLOWER(*p)) {
*p = TOUPPER(*p);
- modify = 1;
+ modify = TRUE;
}
while (++p < pend) {
if (ISUPPER(*p)) {
*p = TOLOWER(*p);
- modify = 1;
+ modify = TRUE;
}
}
if (modify) return str;
@@ -1128,7 +1128,7 @@ static mrb_value
mrb_str_downcase_bang(mrb_state *mrb, mrb_value str)
{
char *p, *pend;
- int modify = 0;
+ mrb_bool modify = FALSE;
struct RString *s = mrb_str_ptr(str);
mrb_str_modify(mrb, s);
@@ -1137,7 +1137,7 @@ mrb_str_downcase_bang(mrb_state *mrb, mrb_value str)
while (p < pend) {
if (ISUPPER(*p)) {
*p = TOLOWER(*p);
- modify = 1;
+ modify = TRUE;
}
p++;
}
@@ -1230,8 +1230,6 @@ mrb_str_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
mrb_value
mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
{
- mrb_value str2;
-
if (len < 0) return mrb_nil_value();
if (!RSTRING_LEN(str)) {
len = 0;
@@ -1246,9 +1244,7 @@ mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
if (len <= 0) {
len = 0;
}
- str2 = mrb_str_subseq(mrb, str, beg, len);
-
- return str2;
+ return mrb_str_subseq(mrb, str, beg, len);
}
mrb_int
@@ -1264,8 +1260,7 @@ mrb_str_hash(mrb_state *mrb, mrb_value str)
key = key*65599 + *p;
p++;
}
- key = key + (key>>5);
- return key;
+ return key + (key>>5);
}
/* 15.2.10.5.20 */
@@ -1851,7 +1846,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
char *ptr = RSTRING_PTR(str);
char *eptr = RSTRING_END(str);
char *bptr = ptr;
- int skip = 1;
+ mrb_bool skip = TRUE;
unsigned int c;
end = beg;
@@ -1864,14 +1859,14 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
}
else {
end = ptr - bptr;
- skip = 0;
+ skip = FALSE;
if (lim_p && lim <= i) break;
}
}
else if (ascii_isspace(c)) {
mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg));
mrb_gc_arena_restore(mrb, ai);
- skip = 1;
+ skip = TRUE;
beg = ptr - bptr;
if (lim_p) ++i;
}
@@ -2285,7 +2280,7 @@ mrb_str_upcase_bang(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
char *p, *pend;
- int modify = 0;
+ mrb_bool modify = FALSE;
mrb_str_modify(mrb, s);
p = RSTRING_PTR(str);
@@ -2293,7 +2288,7 @@ mrb_str_upcase_bang(mrb_state *mrb, mrb_value str)
while (p < pend) {
if (ISLOWER(*p)) {
*p = TOUPPER(*p);
- modify = 1;
+ modify = TRUE;
}
p++;
}
@@ -2484,54 +2479,54 @@ mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2)
mrb_value
mrb_str_inspect(mrb_state *mrb, mrb_value str)
{
- const char *p, *pend;
- char buf[CHAR_ESC_LEN + 1];
- mrb_value result = mrb_str_new_lit(mrb, "\"");
+ const char *p, *pend;
+ char buf[CHAR_ESC_LEN + 1];
+ mrb_value result = mrb_str_new_lit(mrb, "\"");
- p = RSTRING_PTR(str); pend = RSTRING_END(str);
- for (;p < pend; p++) {
- unsigned char c, cc;
+ p = RSTRING_PTR(str); pend = RSTRING_END(str);
+ for (;p < pend; p++) {
+ unsigned char c, cc;
- c = *p;
- if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) {
- buf[0] = '\\'; buf[1] = c;
- mrb_str_cat(mrb, result, buf, 2);
- continue;
- }
- if (ISPRINT(c)) {
- buf[0] = c;
- mrb_str_cat(mrb, result, buf, 1);
- continue;
- }
- switch (c) {
- case '\n': cc = 'n'; break;
- case '\r': cc = 'r'; break;
- case '\t': cc = 't'; break;
- case '\f': cc = 'f'; break;
- case '\013': cc = 'v'; break;
- case '\010': cc = 'b'; break;
- case '\007': cc = 'a'; break;
- case 033: cc = 'e'; break;
- default: cc = 0; break;
- }
- if (cc) {
- buf[0] = '\\';
- buf[1] = (char)cc;
- mrb_str_cat(mrb, result, buf, 2);
- continue;
- }
- else {
- buf[0] = '\\';
- buf[3] = '0' + c % 8; c /= 8;
- buf[2] = '0' + c % 8; c /= 8;
- buf[1] = '0' + c % 8;
- mrb_str_cat(mrb, result, buf, 4);
- continue;
- }
+ c = *p;
+ if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) {
+ buf[0] = '\\'; buf[1] = c;
+ mrb_str_cat(mrb, result, buf, 2);
+ continue;
+ }
+ if (ISPRINT(c)) {
+ buf[0] = c;
+ mrb_str_cat(mrb, result, buf, 1);
+ continue;
}
- mrb_str_cat_lit(mrb, result, "\"");
+ switch (c) {
+ case '\n': cc = 'n'; break;
+ case '\r': cc = 'r'; break;
+ case '\t': cc = 't'; break;
+ case '\f': cc = 'f'; break;
+ case '\013': cc = 'v'; break;
+ case '\010': cc = 'b'; break;
+ case '\007': cc = 'a'; break;
+ case 033: cc = 'e'; break;
+ default: cc = 0; break;
+ }
+ if (cc) {
+ buf[0] = '\\';
+ buf[1] = (char)cc;
+ mrb_str_cat(mrb, result, buf, 2);
+ continue;
+ }
+ else {
+ buf[0] = '\\';
+ buf[3] = '0' + c % 8; c /= 8;
+ buf[2] = '0' + c % 8; c /= 8;
+ buf[1] = '0' + c % 8;
+ mrb_str_cat(mrb, result, buf, 4);
+ continue;
+ }
+ }
+ mrb_str_cat_lit(mrb, result, "\"");
- return result;
+ return result;
}
/*
diff --git a/src/variable.c b/src/variable.c
index 231697d47..f34735e75 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -118,7 +118,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
}
/*
- * Get a value for a symbol from the instance the variable table.
+ * Get a value for a symbol from the instance variable table.
*
* Parameters
* mrb
diff --git a/src/vm.c b/src/vm.c
index 5e5904a3f..9757cf705 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -12,6 +12,7 @@
#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/irep.h"
+#include "mruby/numeric.h"
#include "mruby/proc.h"
#include "mruby/range.h"
#include "mruby/string.h"
@@ -131,10 +132,19 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase)
}
}
+static inline void
+init_new_stack_space(mrb_state *mrb, int room, int keep)
+{
+ if (room > keep) {
+ /* do not leave uninitialized malloc region */
+ stack_clear(&(mrb->c->stack[keep]), room - keep);
+ }
+}
+
/** def rec ; $deep =+ 1 ; if $deep > 1000 ; return 0 ; end ; rec ; end */
static void
-stack_extend_alloc(mrb_state *mrb, int room)
+stack_extend_alloc(mrb_state *mrb, int room, int keep)
{
mrb_value *oldbase = mrb->c->stbase;
int size = mrb->c->stend - mrb->c->stbase;
@@ -159,9 +169,11 @@ stack_extend_alloc(mrb_state *mrb, int room)
mrb->c->stack = mrb->c->stbase + off;
mrb->c->stend = mrb->c->stbase + size;
envadjust(mrb, oldbase, mrb->c->stbase);
+
/* Raise an exception if the new stack size will be too large,
to prevent infinite recursion. However, do this only after resizing the stack, so mrb_raise has stack space to work with. */
if (size > MRB_STACK_MAX) {
+ init_new_stack_space(mrb, room, keep);
mrb_raise(mrb, E_RUNTIME_ERROR, "stack level too deep. (limit=" TO_STR(MRB_STACK_MAX) ")");
}
}
@@ -170,12 +182,9 @@ static inline void
stack_extend(mrb_state *mrb, int room, int keep)
{
if (mrb->c->stack + room >= mrb->c->stend) {
- stack_extend_alloc(mrb, room);
- }
- if (room > keep) {
- /* do not leave uninitialized malloc region */
- stack_clear(&(mrb->c->stack[keep]), room - keep);
+ stack_extend_alloc(mrb, room, keep);
}
+ init_new_stack_space(mrb, room, keep);
}
static inline struct REnv*
@@ -1277,6 +1286,9 @@ RETRY_TRY_BLOCK:
int len = m1 + o + r + m2;
mrb_value *blk = &argv[argc < 0 ? 1 : argc];
+ if (!mrb_nil_p(*blk) && mrb_type(*blk) != MRB_TT_PROC) {
+ *blk = mrb_convert_type(mrb, *blk, MRB_TT_PROC, "Proc", "to_proc");
+ }
if (argc < 0) {
struct RArray *ary = mrb_ary_ptr(regs[1]);
argv = ary->ptr;
@@ -1292,20 +1304,25 @@ RETRY_TRY_BLOCK:
}
}
else if (len > 1 && argc == 1 && mrb_array_p(argv[0])) {
+ mrb_gc_protect(mrb, argv[0]);
argc = mrb_ary_ptr(argv[0])->len;
argv = mrb_ary_ptr(argv[0])->ptr;
}
mrb->c->ci->argc = len;
if (argc < len) {
+ int mlen = m2;
+ if (argc < m1+m2) {
+ if (m1 < argc)
+ mlen = argc - m1;
+ else
+ mlen = 0;
+ }
regs[len+1] = *blk; /* move block */
+ SET_NIL_VALUE(regs[argc+1]);
if (argv0 != argv) {
- value_move(&regs[1], argv, argc-m2); /* m1 + o */
+ value_move(&regs[1], argv, argc-mlen); /* m1 + o */
}
- if (m2) {
- int mlen = m2;
- if (argc-m2 <= m1) {
- mlen = argc - m1;
- }
+ if (mlen) {
value_move(&regs[len-m2+1], &argv[argc-mlen], mlen);
}
if (r) {
@@ -1316,16 +1333,18 @@ RETRY_TRY_BLOCK:
pc += argc - m1 - m2 + 1;
}
else {
+ int rnum = 0;
if (argv0 != argv) {
regs[len+1] = *blk; /* move block */
value_move(&regs[1], argv, m1+o);
}
if (r) {
- regs[m1+o+1] = mrb_ary_new_from_values(mrb, argc-m1-o-m2, argv+m1+o);
+ rnum = argc-m1-o-m2;
+ regs[m1+o+1] = mrb_ary_new_from_values(mrb, rnum, argv+m1+o);
}
if (m2) {
if (argc-m2 > m1) {
- value_move(&regs[m1+o+r+1], &argv[argc-m2], m2);
+ value_move(&regs[m1+o+r+1], &argv[m1+o+rnum], m2);
}
}
if (argv0 == argv) {
@@ -1400,6 +1419,7 @@ RETRY_TRY_BLOCK:
}
}
L_RESCUE:
+ if (ci->ridx == 0) goto L_STOP;
proc = ci->proc;
irep = proc->body.irep;
pool = irep->pool;
@@ -1601,12 +1621,7 @@ RETRY_TRY_BLOCK:
x = mrb_fixnum(regs_a[0]);
y = mrb_fixnum(regs_a[1]);
- z = x + y;
-#ifdef MRB_WORD_BOXING
- z = (z << MRB_FIXNUM_SHIFT) / (1 << MRB_FIXNUM_SHIFT);
-#endif
- if ((x < 0) != (z < 0) && ((x < 0) ^ (y < 0)) == 0) {
- /* integer overflow */
+ if (mrb_int_add_overflow(x, y, &z)) {
SET_FLT_VALUE(mrb, regs_a[0], (mrb_float)x + (mrb_float)y);
break;
}
@@ -1664,12 +1679,7 @@ RETRY_TRY_BLOCK:
x = mrb_fixnum(regs[a]);
y = mrb_fixnum(regs[a+1]);
- z = x - y;
-#ifdef MRB_WORD_BOXING
- z = (z << MRB_FIXNUM_SHIFT) / (1 << MRB_FIXNUM_SHIFT);
-#endif
- if (((x < 0) ^ (y < 0)) != 0 && (x < 0) != (z < 0)) {
- /* integer overflow */
+ if (mrb_int_sub_overflow(x, y, &z)) {
SET_FLT_VALUE(mrb, regs[a], (mrb_float)x - (mrb_float)y);
break;
}
@@ -1719,19 +1729,24 @@ RETRY_TRY_BLOCK:
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
{
- mrb_int x, y, z;
+ mrb_value z;
- x = mrb_fixnum(regs[a]);
- y = mrb_fixnum(regs[a+1]);
- z = x * y;
-#ifdef MRB_WORD_BOXING
- z = (z << MRB_FIXNUM_SHIFT) / (1 << MRB_FIXNUM_SHIFT);
-#endif
- if (x != 0 && z/x != y) {
- SET_FLT_VALUE(mrb, regs[a], (mrb_float)x * (mrb_float)y);
- }
- else {
- SET_INT_VALUE(regs[a], z);
+ z = mrb_fixnum_mul(mrb, regs[a], regs[a+1]);
+
+ switch (mrb_type(z)) {
+ case MRB_TT_FIXNUM:
+ {
+ SET_INT_VALUE(regs[a], mrb_fixnum(z));
+ }
+ break;
+ case MRB_TT_FLOAT:
+ {
+ SET_FLT_VALUE(mrb, regs[a], mrb_float(z));
+ }
+ break;
+ default:
+ /* cannot happen */
+ break;
}
}
break;
@@ -1833,10 +1848,9 @@ RETRY_TRY_BLOCK:
{
mrb_int x = regs[a].attr_i;
mrb_int y = GETARG_C(i);
- mrb_int z = x + y;
+ mrb_int z;
- if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) {
- /* integer overflow */
+ if (mrb_int_add_overflow(x, y, &z)) {
SET_FLT_VALUE(mrb, regs[a], (mrb_float)x + (mrb_float)y);
break;
}
@@ -1872,10 +1886,9 @@ RETRY_TRY_BLOCK:
{
mrb_int x = regs_a[0].attr_i;
mrb_int y = GETARG_C(i);
- mrb_int z = x - y;
+ mrb_int z;
- if ((x < 0) != (z < 0) && ((x < 0) ^ (y < 0)) != 0) {
- /* integer overflow */
+ if (mrb_int_sub_overflow(x, y, &z)) {
SET_FLT_VALUE(mrb, regs_a[0], (mrb_float)x - (mrb_float)y);
}
else {
@@ -2242,10 +2255,10 @@ RETRY_TRY_BLOCK:
/* stop VM */
L_STOP:
{
- int n = mrb->c->ci->eidx;
-
- while (n--) {
- ecall(mrb, n);
+ int eidx_stop = mrb->c->ci == mrb->c->cibase ? 0 : mrb->c->ci[-1].eidx;
+ int eidx = mrb->c->ci->eidx;
+ while (eidx > eidx_stop) {
+ ecall(mrb, --eidx);
}
}
ERR_PC_CLR(mrb);
@@ -2298,8 +2311,6 @@ mrb_toplevel_run(mrb_state *mrb, struct RProc *proc)
}
ci = cipush(mrb);
ci->acc = CI_ACC_SKIP;
- ci->eidx = 0;
- ci->ridx = 0;
ci->target_class = mrb->object_class;
v = mrb_context_run(mrb, proc, mrb_top_self(mrb), 0);
cipop(mrb);
diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake
index bf775ffdd..d06b7a24c 100644
--- a/tasks/mrbgems_test.rake
+++ b/tasks/mrbgems_test.rake
@@ -114,10 +114,10 @@ MRuby.each_target do
if no_mrb_open_test_rbfiles.empty?
no_mrb_open_test_rbfiles << "#{MRUBY_ROOT}/test/no_mrb_open_test_dummy.rb"
end
-
+
no_mrb_open_test_lib = no_mrb_open_test.ext(exts.object)
file no_mrb_open_test_lib => "#{no_mrb_open_test}.c"
- file "#{no_mrb_open_test}.c" => no_mrb_open_test_rbfiles do |t|
+ file "#{no_mrb_open_test}.c" => no_mrb_open_test_rbfiles + [MRUBY_CONFIG] do |t|
open(t.name, 'w') do |f|
f.puts %Q[/*]
f.puts %Q[ * This file contains a test code for following gems:]
diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake
index 1df67c37e..966c602a4 100644
--- a/tasks/mruby_build.rake
+++ b/tasks/mruby_build.rake
@@ -143,9 +143,9 @@ module MRuby
def define_rules
compilers.each do |compiler|
if respond_to?(:enable_gems?) && enable_gems?
- compiler.defines -= %w(DISABLE_GEMS)
+ compiler.defines -= %w(DISABLE_GEMS)
else
- compiler.defines += %w(DISABLE_GEMS)
+ compiler.defines += %w(DISABLE_GEMS)
end
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..'))
end
diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake
index 4beb7e743..4fbfaa785 100644
--- a/tasks/mruby_build_commands.rake
+++ b/tasks/mruby_build_commands.rake
@@ -54,6 +54,18 @@ module MRuby
@compile_options = '%{flags} -o %{outfile} -c %{infile}'
end
+ alias header_search_paths include_paths
+ def search_header_path(name)
+ header_search_paths.find do |v|
+ File.exist? build.filename("#{v}/#{name}").sub(/^"(.*)"$/, '\1')
+ end
+ end
+
+ def search_header(name)
+ path = search_header_path name
+ path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1')
+ end
+
def all_flags(_defineds=[], _include_paths=[], _flags=[])
define_flags = [defines, _defineds].flatten.map{ |d| option_define % d }
include_path_flags = [include_paths, _include_paths].flatten.map do |f|
diff --git a/tasks/ruby_ext.rake b/tasks/ruby_ext.rake
index 0a0883e02..38dfff0a3 100644
--- a/tasks/ruby_ext.rake
+++ b/tasks/ruby_ext.rake
@@ -16,7 +16,7 @@ class String
def relative_path
relative_path_from(Dir.pwd)
end
-
+
# Compatible with 1.9 on 1.8
def %(params)
if params.is_a?(Hash)
diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake
index a25f840c5..821100748 100644
--- a/tasks/toolchains/gcc.rake
+++ b/tasks/toolchains/gcc.rake
@@ -28,4 +28,29 @@ MRuby::Toolchain.new(:gcc) do |conf|
linker.option_library_path = '-L%s'
linker.link_options = '%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}'
end
+
+ [[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang|
+ cc.instance_variable_set :@header_search_language, lang
+ def cc.header_search_paths
+ if @header_search_command != command
+ result = `echo | #{build.filename command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1`
+ result = `echo | #{command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1` if $?.exitstatus != 0
+ return include_paths if $?.exitstatus != 0
+
+ @frameworks = []
+ @header_search_paths = result.lines.map { |v|
+ framework = v.match(/^ (.*)(?: \(framework directory\))$/)
+ if framework
+ @frameworks << framework[1]
+ next nil
+ end
+
+ v.match(/^ (.*)$/)
+ }.compact.map { |v| v[1] }.select { |v| File.directory? v }
+ @header_search_paths += include_paths
+ @header_search_command = command
+ end
+ @header_search_paths
+ end
+ end
end
diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake
index 1498ec3c9..a5726dce7 100644
--- a/tasks/toolchains/visualcpp.rake
+++ b/tasks/toolchains/visualcpp.rake
@@ -1,7 +1,8 @@
MRuby::Toolchain.new(:visualcpp) do |conf|
[conf.cc].each do |cc|
cc.command = ENV['CC'] || 'cl.exe'
- cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
+ # C4013: implicit function declaration
+ cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
cc.include_paths = ["#{MRUBY_ROOT}/include"]
cc.defines = %w(DISABLE_GEMS MRB_STACK_EXTEND_DOUBLING)
cc.option_include_path = '/I%s'
diff --git a/test/assert.rb b/test/assert.rb
index 8fecc5b0a..a4ee00299 100644
--- a/test/assert.rb
+++ b/test/assert.rb
@@ -106,7 +106,7 @@ def assert_equal(arg1, arg2 = nil, arg3 = nil)
else
exp, act, msg = arg1, arg2, arg3
end
-
+
msg = "Expected to be equal" unless msg
diff = assertion_diff(exp, act)
assert_true(exp == act, msg, diff)
diff --git a/test/driver.c b/test/driver.c
index bcac73d25..f605d7517 100644
--- a/test/driver.c
+++ b/test/driver.c
@@ -10,12 +10,12 @@
#include <stdlib.h>
#include <string.h>
-#include <mruby.h>
-#include <mruby/proc.h>
-#include <mruby/data.h>
-#include <mruby/compile.h>
-#include <mruby/string.h>
-#include <mruby/variable.h>
+#include "mruby.h"
+#include "mruby/proc.h"
+#include "mruby/data.h"
+#include "mruby/compile.h"
+#include "mruby/string.h"
+#include "mruby/variable.h"
void
mrb_init_mrbtest(mrb_state *);
@@ -63,7 +63,7 @@ t_printstr(mrb_state *mrb, mrb_value obj)
{
char *s;
int len;
-
+
if (mrb_string_p(obj)) {
s = RSTRING_PTR(obj);
len = RSTRING_LEN(obj);
@@ -87,6 +87,7 @@ main(int argc, char **argv)
{
mrb_state *mrb;
struct RClass *krn;
+ struct RClass *mrbtest;
int ret;
print_hint();
@@ -106,6 +107,12 @@ main(int argc, char **argv)
krn = mrb->kernel_module;
mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1));
+ mrbtest = mrb_define_module(mrb, "Mrbtest");
+
+ mrb_define_const(mrb, mrbtest, "FIXNUM_MAX", mrb_fixnum_value(MRB_INT_MAX));
+ mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
+ mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));
+
mrb_init_mrbtest(mrb);
ret = eval_test(mrb);
mrb_close(mrb);
diff --git a/test/t/array.rb b/test/t/array.rb
index 48f2fe0c4..56daf0b01 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -66,6 +66,11 @@ assert('Array#[]=', '15.2.12.5.5') do
# this will cause an exception due to the wrong arguments
a.[]=(1,2,3,4)
end
+ assert_raise(IndexError) do
+ # this will cause an exception due to the wrong arguments
+ a = [1,2,3,4,5]
+ a[1, -1] = 10
+ end
assert_equal(4, [1,2,3].[]=(1,4))
assert_equal(3, [1,2,3].[]=(1,2,3))
diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb
index 0a58741e3..04a4a15ba 100644
--- a/test/t/bs_block.rb
+++ b/test/t/bs_block.rb
@@ -512,3 +512,10 @@ assert('BS Block 37') do
end
end
+assert('BS Block 38') do
+ def iter
+ yield 1,2,3,4,5,6
+ end
+
+ assert_equal [1,2,3,4,5], iter{|a,b,c=:c,d,e| [a,b,c,d,e]}
+end
diff --git a/test/t/exception.rb b/test/t/exception.rb
index 8099e911f..186ac2892 100644
--- a/test/t/exception.rb
+++ b/test/t/exception.rb
@@ -42,6 +42,16 @@ assert('Exception.exception', '15.2.22.4.1') do
assert_equal 'a', e.message
end
+assert('NameError', '15.2.31') do
+ assert_raise(NameError) do
+ raise NameError.new
+ end
+
+ e = NameError.new "msg", "name"
+ assert_equal "msg", e.message
+ assert_equal "name", e.name
+end
+
assert('ScriptError', '15.2.37') do
assert_raise(ScriptError) do
raise ScriptError.new
@@ -57,15 +67,16 @@ end
# Not ISO specified
assert('Exception 1') do
- begin
+r=begin
1+1
ensure
2+2
- end == 2
+ end
+ assert_equal 2, r
end
assert('Exception 2') do
- begin
+r=begin
1+1
begin
2+2
@@ -74,11 +85,12 @@ assert('Exception 2') do
end
ensure
4+4
- end == 4
+ end
+ assert_equal 4, r
end
assert('Exception 3') do
- begin
+r=begin
1+1
begin
2+2
@@ -92,7 +104,8 @@ assert('Exception 3') do
ensure
6+6
end
- end == 4
+ end
+ assert_equal 4, r
end
assert('Exception 4') do
@@ -171,17 +184,18 @@ assert('Exception 7') do
end
assert('Exception 8') do
- begin
+r=begin
1
rescue
2
else
3
- end == 3
+ end
+ assert_equal 3, r
end
assert('Exception 9') do
- begin
+r=begin
1+1
rescue
2+2
@@ -189,11 +203,12 @@ assert('Exception 9') do
3+3
ensure
4+4
- end == 6
+ end
+ assert_equal 6, r
end
assert('Exception 10') do
- begin
+r=begin
1+1
begin
2+2
@@ -208,7 +223,8 @@ assert('Exception 10') do
6+6
ensure
7+7
- end == 12
+ end
+ assert_equal 12, r
end
assert('Exception 11') do
@@ -273,12 +289,12 @@ assert('Exception 16') do
raise "foo"
false
rescue => e
- e.message == "foo"
+ assert_equal "foo", e.message
end
end
assert('Exception 17') do
- begin
+r=begin
raise "a" # StandardError
rescue ArgumentError
1
@@ -288,11 +304,12 @@ assert('Exception 17') do
3
ensure
4
- end == 2
+ end
+ assert_equal 2, r
end
assert('Exception 18') do
- begin
+r=begin
0
rescue ArgumentError
1
@@ -302,7 +319,8 @@ assert('Exception 18') do
3
ensure
4
- end == 3
+ end
+ assert_equal 3, r
end
assert('Exception 19') do
@@ -333,17 +351,17 @@ assert('Exception 19') do
end
assert('Exception#inspect without message') do
- Exception.new.inspect
+ assert_equal "Exception: Exception", Exception.new.inspect
end
assert('Exception#backtrace') do
- begin
- raise "get backtrace"
- rescue => e
- e.backtrace
+ assert_nothing_raised do
+ begin
+ raise "get backtrace"
+ rescue => e
+ e.backtrace
+ end
end
-
- true
end
assert('Raise in ensure') do
diff --git a/test/t/hash.rb b/test/t/hash.rb
index 8a10f4026..0d8d137c4 100644
--- a/test/t/hash.rb
+++ b/test/t/hash.rb
@@ -40,7 +40,7 @@ assert('Hash#dup') do
a = { 'a' => 1 }
b = a.dup
a['a'] = 2
- assert_equal(b, {'a' => 1})
+ assert_equal({'a' => 1}, b)
end
assert('Hash#default', '15.2.13.4.5') do
@@ -223,6 +223,10 @@ assert('Hash#merge', '15.2.13.4.22') do
'xyz_key' => 'xyz_value' }, result_1)
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }, result_2)
+
+ assert_raise(TypeError) do
+ { 'abc_key' => 'abc_value' }.merge "a"
+ end
end
assert('Hash#replace', '15.2.13.4.23') do
@@ -235,7 +239,7 @@ assert('Hash#replace', '15.2.13.4.23') do
b = {}
b.replace(a)
assert_equal(42, b[1])
-
+
a = Hash.new{|h,x| x}
b.replace(a)
assert_equal(127, b[127])
diff --git a/test/t/integer.rb b/test/t/integer.rb
index 66dd61c0b..b15d4645d 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -18,6 +18,14 @@ assert('Integer#+', '15.2.8.3.1') do
assert_raise(TypeError){ 0+nil }
assert_raise(TypeError){ 1+nil }
+
+ c = Mrbtest::FIXNUM_MAX + 1
+ d = Mrbtest::FIXNUM_MAX.__send__(:+, 1)
+ e = Mrbtest::FIXNUM_MAX + 1.0
+ assert_equal Float, c.class
+ assert_equal Float, d.class
+ assert_float e, c
+ assert_float e, d
end
assert('Integer#-', '15.2.8.3.2') do
@@ -26,6 +34,14 @@ assert('Integer#-', '15.2.8.3.2') do
assert_equal 1, a
assert_equal 1.0, b
+
+ c = Mrbtest::FIXNUM_MIN - 1
+ d = Mrbtest::FIXNUM_MIN.__send__(:-, 1)
+ e = Mrbtest::FIXNUM_MIN - 1.0
+ assert_equal Float, c.class
+ assert_equal Float, d.class
+ assert_float e, c
+ assert_float e, d
end
assert('Integer#*', '15.2.8.3.3') do
@@ -37,6 +53,14 @@ assert('Integer#*', '15.2.8.3.3') do
assert_raise(TypeError){ 0*nil }
assert_raise(TypeError){ 1*nil }
+
+ c = Mrbtest::FIXNUM_MAX * 2
+ d = Mrbtest::FIXNUM_MAX.__send__(:*, 2)
+ e = Mrbtest::FIXNUM_MAX * 2.0
+ assert_equal Float, c.class
+ assert_equal Float, d.class
+ assert_float e, c
+ assert_float e, d
end
assert('Integer#/', '15.2.8.3.4') do
@@ -57,7 +81,7 @@ assert('Integer#%', '15.2.8.3.5') do
assert_equal 2, c
end
-assert('Integer#<=>', '15.2.8.3.6') do
+assert('Integer#<=>', '15.2.9.3.6') do
a = 1<=>0
b = 1<=>1
c = 1<=>2
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index c6b65ddf7..17f776683 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -528,20 +528,6 @@ assert('Kernel#global_variables') do
end
end
-assert('Kernel#__method__') do
- assert_equal(:m, Class.new {def m; __method__; end}.new.m)
- assert_equal(:m, Class.new {define_method(:m) {__method__}}.new.m)
- c = Class.new do
- [:m1, :m2].each do |m|
- define_method(m) do
- __method__
- end
- end
- end
- assert_equal(:m1, c.new.m1)
- assert_equal(:m2, c.new.m2)
-end
-
assert('Kernel#define_singleton_method') do
o = Object.new
ret = o.define_singleton_method(:test_method) do
diff --git a/test/t/methods.rb b/test/t/methods.rb
index bbd8ee09d..f9c25dc33 100644
--- a/test/t/methods.rb
+++ b/test/t/methods.rb
@@ -65,7 +65,7 @@ assert('The undef statement', '13.3.7 a) 4)') do
assert_true(existing_method_e, 'Method should be defined')
assert_true(existing_method_f, 'Method should be defined')
- # undefine in all possible ways and check that method
+ # undefine in all possible ways and check that method
# is undefined
undef existing_method_a
diff --git a/test/t/module.rb b/test/t/module.rb
index 48a09f720..585774a4b 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -485,19 +485,19 @@ end
assert('Issue 1467') do
module M1
def initialize()
- super()
+ super()
end
end
- class C1
- include M1
- def initialize()
- super()
+ class C1
+ include M1
+ def initialize()
+ super()
end
end
class C2
- include M1
+ include M1
end
C1.new
diff --git a/test/t/proc.rb b/test/t/proc.rb
index 151e1df86..e871e637e 100644
--- a/test/t/proc.rb
+++ b/test/t/proc.rb
@@ -55,6 +55,46 @@ assert('Proc#call', '15.2.17.4.3') do
assert_equal 5, a2
end
+assert('Proc#call proc args pos block') do
+ pr = Proc.new {|a,b,&c|
+ [a, b, c.class, c&&c.call(:x)]
+ }
+ assert_equal [nil, nil, Proc, :proc], (pr.call(){ :proc })
+ assert_equal [1, nil, Proc, :proc], (pr.call(1){ :proc })
+ assert_equal [1, 2, Proc, :proc], (pr.call(1, 2){ :proc })
+ assert_equal [1, 2, Proc, :proc], (pr.call(1, 2, 3){ :proc })
+ assert_equal [1, 2, Proc, :proc], (pr.call(1, 2, 3, 4){ :proc })
+
+ assert_equal [nil, nil, Proc, :x], (pr.call(){|x| x})
+ assert_equal [1, nil, Proc, :x], (pr.call(1){|x| x})
+ assert_equal [1, 2, Proc, :x], (pr.call(1, 2){|x| x})
+ assert_equal [1, 2, Proc, :x], (pr.call(1, 2, 3){|x| x})
+ assert_equal [1, 2, Proc, :x], (pr.call(1, 2, 3, 4){|x| x})
+end
+
+assert('Proc#call proc args pos rest post') do
+ pr = Proc.new {|a,b,*c,d,e|
+ [a,b,c,d,e]
+ }
+ assert_equal [nil, nil, [], nil, nil], pr.call()
+ assert_equal [1, nil, [], nil, nil], pr.call(1)
+ assert_equal [1, 2, [], nil, nil], pr.call(1,2)
+ assert_equal [1, 2, [], 3, nil], pr.call(1,2,3)
+ assert_equal [1, 2, [], 3, 4], pr.call(1,2,3,4)
+ assert_equal [1, 2, [3], 4, 5], pr.call(1,2,3,4,5)
+ assert_equal [1, 2, [3, 4], 5, 6], pr.call(1,2,3,4,5,6)
+ assert_equal [1, 2, [3, 4, 5], 6,7], pr.call(1,2,3,4,5,6,7)
+
+ assert_equal [nil, nil, [], nil, nil], pr.call([])
+ assert_equal [1, nil, [], nil, nil], pr.call([1])
+ assert_equal [1, 2, [], nil, nil], pr.call([1,2])
+ assert_equal [1, 2, [], 3, nil], pr.call([1,2,3])
+ assert_equal [1, 2, [], 3, 4], pr.call([1,2,3,4])
+ assert_equal [1, 2, [3], 4, 5], pr.call([1,2,3,4,5])
+ assert_equal [1, 2, [3, 4], 5, 6], pr.call([1,2,3,4,5,6])
+ assert_equal [1, 2, [3, 4, 5], 6,7], pr.call([1,2,3,4,5,6,7])
+end
+
assert('Proc#return_does_not_break_self') do
class TestClass
attr_accessor :block
@@ -91,3 +131,20 @@ assert('Proc#return_does_not_break_self') do
assert_equal nil, c.return_nil
assert_equal c, c.block.call
end
+
+assert('&obj call to_proc if defined') do
+ pr = Proc.new{}
+ def mock(&b)
+ b
+ end
+ assert_equal pr.object_id, mock(&pr).object_id
+ assert_equal pr, mock(&pr)
+
+ obj = Object.new
+ def obj.to_proc
+ Proc.new{ :from_to_proc }
+ end
+ assert_equal :from_to_proc, mock(&obj).call
+
+ assert_raise(TypeError){ mock(&(Object.new)) }
+end
diff --git a/test/t/range.rb b/test/t/range.rb
index d7294cc1b..b35da40ab 100644
--- a/test/t/range.rb
+++ b/test/t/range.rb
@@ -46,7 +46,7 @@ assert('Range#first', '15.2.14.4.7') do
assert_equal 1, (1..10).first
end
-assert('Range#include', '15.2.14.4.8') do
+assert('Range#include?', '15.2.14.4.8') do
a = (1..10)
assert_true a.include?(5)
@@ -74,6 +74,20 @@ assert('Range#member?', '15.2.14.4.11') do
assert_false a.member?(20)
end
+assert('Range#to_s', '15.2.14.4.12') do
+ assert_equal "0..1", (0..1).to_s
+ assert_equal "0...1", (0...1).to_s
+ assert_equal "a..b", ("a".."b").to_s
+ assert_equal "a...b", ("a"..."b").to_s
+end
+
+assert('Range#inspect', '15.2.14.4.13') do
+ assert_equal "0..1", (0..1).inspect
+ assert_equal "0...1", (0...1).inspect
+ assert_equal "\"a\"..\"b\"", ("a".."b").inspect
+ assert_equal "\"a\"...\"b\"", ("a"..."b").inspect
+end
+
assert('Range#eql?', '15.2.14.4.14') do
assert_true (1..10).eql? (1..10)
assert_false (1..10).eql? (1..100)
diff --git a/test/t/string.rb b/test/t/string.rb
index 04f90fb45..5ecb51530 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -475,6 +475,15 @@ assert('String#upcase!', '15.2.10.5.43') do
assert_equal 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', b
end
+assert('String#inspect', '15.2.10.5.46') do
+ # should not raise an exception - regress #1210
+ assert_nothing_raised do
+ ("\1" * 100).inspect
+ end
+
+ assert_equal "\"\\000\"", "\0".inspect
+end
+
# Not ISO specified
assert('String interpolation (mrb_str_concat for shared strings)') do
@@ -506,8 +515,3 @@ assert('String#each_byte') do
assert_equal bytes1, bytes2
end
-
-assert('String#inspect') do
- ("\1" * 100).inspect # should not raise an exception - regress #1210
- assert_equal "\"\\000\"", "\0".inspect
-end
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index 0bb3fa389..e105cd3d4 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -307,5 +307,9 @@ this is a comment that has =end with spaces after it
=begin this is a comment
this is a comment that has extra after =begin and =end with spaces after it
=end
- true
+ line = __LINE__
+=begin this is a comment
+this is a comment that has extra after =begin and =end with tabs after it
+=end xxxxxxxxxxxxxxxxxxxxxxxxxx
+ assert_equal(line + 4, __LINE__)
end