script_core 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (381) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +8 -6
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -1
  6. data/bin/sandbox +1 -1
  7. data/ext/enterprise_script_service/Rakefile +1 -1
  8. data/ext/enterprise_script_service/flags.rb +5 -0
  9. data/ext/enterprise_script_service/libseccomp/CHANGELOG +15 -0
  10. data/ext/enterprise_script_service/libseccomp/CREDITS +3 -0
  11. data/ext/enterprise_script_service/libseccomp/Makefile.am +1 -1
  12. data/ext/enterprise_script_service/libseccomp/README.md +1 -1
  13. data/ext/enterprise_script_service/libseccomp/SECURITY.md +45 -0
  14. data/ext/enterprise_script_service/libseccomp/configure.ac +3 -3
  15. data/ext/enterprise_script_service/libseccomp/doc/admin/MAINTAINER_PROCESS.md +95 -0
  16. data/ext/enterprise_script_service/libseccomp/{RELEASE_PROCESS.md → doc/admin/RELEASE_PROCESS.md} +9 -1
  17. data/ext/enterprise_script_service/libseccomp/include/Makefile.am +1 -1
  18. data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +2292 -0
  19. data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +3 -1065
  20. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +35 -3
  21. data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +35 -3
  22. data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +43 -11
  23. data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +33 -1
  24. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +33 -1
  25. data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +34 -2
  26. data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +43 -11
  27. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +44 -12
  28. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +46 -14
  29. data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +142 -18
  30. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +47 -15
  31. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +143 -17
  32. data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +33 -1
  33. data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +94 -12
  34. data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +142 -19
  35. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +33 -1
  36. data/ext/enterprise_script_service/libseccomp/src/db.c +1 -0
  37. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +10 -3
  38. data/ext/enterprise_script_service/libseccomp/src/python/Makefile.am +4 -4
  39. data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +2 -0
  40. data/ext/enterprise_script_service/libseccomp/tests/.gitignore +1 -0
  41. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.c +98 -0
  42. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.py +61 -0
  43. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.tests +18 -0
  44. data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +6 -3
  45. data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -2
  46. data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -0
  47. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +2 -0
  48. data/ext/enterprise_script_service/mruby-mpdecimal/src/ext.c +1 -1
  49. data/ext/enterprise_script_service/mruby/.gitignore +2 -2
  50. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +10 -3
  51. data/ext/enterprise_script_service/mruby/Doxyfile +2408 -0
  52. data/ext/enterprise_script_service/mruby/README.md +21 -8
  53. data/ext/enterprise_script_service/mruby/Rakefile +4 -13
  54. data/ext/enterprise_script_service/mruby/appveyor_config.rb +1 -1
  55. data/ext/enterprise_script_service/mruby/build_config.rb +3 -3
  56. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +42 -42
  57. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +1 -1
  58. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +45 -6
  59. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +5 -0
  60. data/ext/enterprise_script_service/mruby/doc/limitations.md +88 -38
  61. data/ext/enterprise_script_service/mruby/doc/mruby_logo_red_icon.png +0 -0
  62. data/ext/enterprise_script_service/mruby/doc/opcode.md +94 -94
  63. data/ext/enterprise_script_service/mruby/include/mrbconf.h +74 -11
  64. data/ext/enterprise_script_service/mruby/include/mruby.h +242 -146
  65. data/ext/enterprise_script_service/mruby/include/mruby/array.h +7 -7
  66. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +2 -9
  67. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +11 -10
  68. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +104 -69
  69. data/ext/enterprise_script_service/mruby/include/mruby/class.h +7 -5
  70. data/ext/enterprise_script_service/mruby/include/mruby/common.h +9 -7
  71. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +6 -6
  72. data/ext/enterprise_script_service/mruby/include/mruby/data.h +5 -5
  73. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  74. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +3 -7
  75. data/ext/enterprise_script_service/mruby/include/mruby/error.h +34 -6
  76. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +2 -2
  77. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +4 -11
  78. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +16 -4
  79. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -4
  80. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +2 -2
  81. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +41 -7
  82. data/ext/enterprise_script_service/mruby/include/mruby/object.h +8 -9
  83. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +2 -2
  84. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +6 -6
  85. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +19 -13
  86. data/ext/enterprise_script_service/mruby/include/mruby/range.h +10 -4
  87. data/ext/enterprise_script_service/mruby/include/mruby/re.h +2 -2
  88. data/ext/enterprise_script_service/mruby/include/mruby/string.h +130 -107
  89. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +2 -2
  90. data/ext/enterprise_script_service/mruby/include/mruby/value.h +137 -49
  91. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +3 -5
  92. data/ext/enterprise_script_service/mruby/include/mruby/version.h +24 -10
  93. data/ext/enterprise_script_service/mruby/lib/mruby-core-ext.rb +2 -39
  94. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +32 -15
  95. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +63 -17
  96. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +24 -10
  97. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +11 -7
  98. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +81 -0
  99. data/ext/enterprise_script_service/mruby/minirake +27 -11
  100. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +3 -0
  101. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrbgem.rake +0 -1
  102. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +47 -9
  103. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +3 -3
  104. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +50 -29
  105. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +3 -3
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +2 -2
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c +3 -3
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +2 -2
  109. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +1 -1
  110. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -0
  111. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +28 -1
  112. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +1 -2
  113. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +75 -8
  114. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +134 -90
  115. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -8
  116. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +69 -46
  117. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +0 -3
  118. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +51 -59
  119. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +430 -241
  120. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrbgem.rake +10 -0
  121. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +122 -0
  122. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +249 -0
  123. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +153 -0
  124. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/mrblib/chain.rb +19 -17
  125. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/test/enum_chain.rb +41 -9
  126. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb +30 -4
  127. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/test/enum.rb +8 -3
  128. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrbgem.rake +0 -1
  129. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +46 -14
  130. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +51 -2
  131. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +10 -0
  132. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +47 -44
  133. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +2 -2
  134. data/ext/enterprise_script_service/mruby/mrbgems/mruby-exit/src/mruby-exit.c +9 -4
  135. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +16 -12
  136. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/test/fiber.rb +1 -1
  137. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +0 -2
  138. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +3 -0
  139. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +3 -7
  140. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +1 -3
  141. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +1 -1
  142. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +0 -5
  143. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +24 -38
  144. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/kernel.rb +16 -0
  145. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +19 -18
  146. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +5 -16
  147. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +54 -42
  148. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +24 -20
  149. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file_test.rb +4 -9
  150. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +41 -35
  151. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +9 -36
  152. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrbgem.rake +1 -1
  153. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +9 -27
  154. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb +2 -0
  155. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +5 -2
  156. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +39 -24
  157. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +48 -17
  158. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/method.rb +0 -12
  159. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +134 -101
  160. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +9 -1
  161. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb +1 -5
  162. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +17 -37
  163. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +0 -8
  164. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrbgem.rake +1 -1
  165. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrblib/object.rb +15 -1
  166. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +35 -6
  167. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/test/nil.rb +4 -0
  168. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +1 -5
  169. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +1 -1
  170. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +28 -23
  171. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/test/pack.rb +43 -49
  172. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +3 -9
  173. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +6 -9
  174. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.rb +21 -5
  175. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +157 -124
  176. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +72 -26
  177. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +38 -0
  178. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +26 -11
  179. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +111 -1
  180. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrbgem.rake +5 -0
  181. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +117 -0
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +209 -0
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +308 -0
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +1 -1
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +10 -9
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +2 -2
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +22 -24
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrbgem.rake +0 -1
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +8 -4
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +116 -117
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/numeric.rb +29 -0
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/range.rb +26 -0
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/string.rb +32 -50
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +5 -7
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +43 -57
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/test/struct.rb +16 -11
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +2 -2
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +152 -1
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +4 -3
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +200 -0
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/include/mruby/time.h +2 -1
  203. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +199 -68
  204. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/test/time.rb +81 -46
  205. data/ext/enterprise_script_service/mruby/mrblib/array.rb +14 -16
  206. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +13 -9
  207. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +5 -7
  208. data/ext/enterprise_script_service/mruby/mrblib/kernel.rb +1 -1
  209. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +4 -4
  210. data/ext/enterprise_script_service/mruby/mrblib/range.rb +1 -1
  211. data/ext/enterprise_script_service/mruby/mrblib/string.rb +55 -112
  212. data/ext/enterprise_script_service/mruby/mruby-source.gemspec +1 -1
  213. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby.dict +105 -0
  214. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_fuzzer.options +5 -0
  215. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_proto_fuzzer.options +4 -0
  216. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_fuzzer.c +18 -0
  217. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +44 -0
  218. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.cpp +455 -0
  219. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +55 -0
  220. data/ext/enterprise_script_service/mruby/oss-fuzz/ruby.proto +201 -0
  221. data/ext/enterprise_script_service/mruby/src/array.c +95 -46
  222. data/ext/enterprise_script_service/mruby/src/backtrace.c +6 -8
  223. data/ext/enterprise_script_service/mruby/src/class.c +370 -278
  224. data/ext/enterprise_script_service/mruby/src/codedump.c +34 -34
  225. data/ext/enterprise_script_service/mruby/src/debug.c +2 -2
  226. data/ext/enterprise_script_service/mruby/src/dump.c +8 -6
  227. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  228. data/ext/enterprise_script_service/mruby/src/error.c +157 -55
  229. data/ext/enterprise_script_service/mruby/src/etc.c +13 -46
  230. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +2 -2
  231. data/ext/enterprise_script_service/mruby/src/gc.c +30 -11
  232. data/ext/enterprise_script_service/mruby/src/hash.c +23 -14
  233. data/ext/enterprise_script_service/mruby/src/kernel.c +16 -54
  234. data/ext/enterprise_script_service/mruby/src/load.c +40 -76
  235. data/ext/enterprise_script_service/mruby/src/numeric.c +164 -94
  236. data/ext/enterprise_script_service/mruby/src/object.c +16 -39
  237. data/ext/enterprise_script_service/mruby/src/pool.c +0 -2
  238. data/ext/enterprise_script_service/mruby/src/proc.c +47 -48
  239. data/ext/enterprise_script_service/mruby/src/range.c +22 -35
  240. data/ext/enterprise_script_service/mruby/src/state.c +5 -94
  241. data/ext/enterprise_script_service/mruby/src/string.c +874 -710
  242. data/ext/enterprise_script_service/mruby/src/symbol.c +73 -48
  243. data/ext/enterprise_script_service/mruby/src/variable.c +58 -38
  244. data/ext/enterprise_script_service/mruby/src/vm.c +133 -304
  245. data/ext/enterprise_script_service/mruby/tasks/doc.rake +48 -0
  246. data/ext/enterprise_script_service/mruby/tasks/toolchains/clang.rake +3 -4
  247. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +20 -19
  248. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +0 -12
  249. data/ext/enterprise_script_service/mruby/test/assert.rb +186 -25
  250. data/ext/enterprise_script_service/mruby/test/t/array.rb +34 -6
  251. data/ext/enterprise_script_service/mruby/test/t/class.rb +26 -0
  252. data/ext/enterprise_script_service/mruby/test/t/enumerable.rb +2 -2
  253. data/ext/enterprise_script_service/mruby/test/t/float.rb +17 -17
  254. data/ext/enterprise_script_service/mruby/test/t/hash.rb +2 -0
  255. data/ext/enterprise_script_service/mruby/test/t/integer.rb +14 -6
  256. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +38 -19
  257. data/ext/enterprise_script_service/mruby/test/t/module.rb +87 -14
  258. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +65 -23
  259. data/ext/enterprise_script_service/mruby/test/t/range.rb +4 -4
  260. data/ext/enterprise_script_service/mruby/test/t/string.rb +211 -49
  261. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +19 -2
  262. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +92 -0
  263. data/ext/enterprise_script_service/mruby/travis_config.rb +2 -2
  264. data/ext/enterprise_script_service/mruby_config.rb +10 -0
  265. data/ext/enterprise_script_service/mruby_engine.cpp +2 -2
  266. data/ext/enterprise_script_service/mruby_engine.gembox +1 -0
  267. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +14 -0
  268. data/ext/enterprise_script_service/msgpack/Files.cmake +4 -0
  269. data/ext/enterprise_script_service/msgpack/README.md +1 -1
  270. data/ext/enterprise_script_service/msgpack/appveyor.yml +1 -1
  271. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple.hpp.erb +1 -1
  272. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb +1 -1
  273. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_zone.hpp.erb +3 -3
  274. data/ext/enterprise_script_service/msgpack/example/boost/asio_send_recv.cpp +1 -1
  275. data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/cpp11/timespec.hpp +16 -0
  276. data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/wstring.hpp +15 -0
  277. data/ext/enterprise_script_service/msgpack/include/msgpack/object.h +2 -0
  278. data/ext/enterprise_script_service/msgpack/include/msgpack/pack_template.h +17 -9
  279. data/ext/enterprise_script_service/msgpack/include/msgpack/sysdep.h +27 -16
  280. data/ext/enterprise_script_service/msgpack/include/msgpack/type.hpp +2 -0
  281. data/ext/enterprise_script_service/msgpack/include/msgpack/unpack_template.h +5 -0
  282. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +0 -1
  283. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/check_container_size.hpp +1 -1
  284. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/chrono.hpp +5 -5
  285. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/timespec.hpp +140 -0
  286. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple.hpp +32 -32
  287. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple_decl.hpp +32 -32
  288. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple.hpp +6 -6
  289. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple_decl.hpp +10 -10
  290. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/ext.hpp +1 -1
  291. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/fixint.hpp +5 -4
  292. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int.hpp +40 -13
  293. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int_decl.hpp +3 -2
  294. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +121 -0
  295. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp03_zone.hpp +3 -3
  296. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp11_zone.hpp +3 -3
  297. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object.hpp +6 -6
  298. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object_fwd.hpp +1 -1
  299. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/pack.hpp +40 -5
  300. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/unpack.hpp +11 -11
  301. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/vrefbuffer.hpp +7 -7
  302. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/zbuffer.hpp +5 -5
  303. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/adaptor/int_decl.hpp +1 -1
  304. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/create_object_visitor.hpp +1 -1
  305. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/parse.hpp +13 -13
  306. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/x3_parse.hpp +28 -26
  307. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/adaptor/int_decl.hpp +1 -1
  308. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/parse.hpp +13 -13
  309. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  310. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +6 -6
  311. data/ext/enterprise_script_service/msgpack/include/msgpack/zone.h +1 -1
  312. data/ext/enterprise_script_service/msgpack/src/objectc.c +83 -148
  313. data/ext/enterprise_script_service/msgpack/src/unpack.c +73 -47
  314. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +1 -1
  315. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +5 -0
  316. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +5 -0
  317. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +7 -0
  318. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +7 -0
  319. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +6 -0
  320. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +15 -9
  321. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +7 -0
  322. data/ext/enterprise_script_service/msgpack/test/carray.cpp +7 -0
  323. data/ext/enterprise_script_service/msgpack/test/cases.cpp +7 -1
  324. data/ext/enterprise_script_service/msgpack/test/convert.cpp +6 -0
  325. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +7 -1
  326. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +6 -1
  327. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +5 -0
  328. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +8 -2
  329. data/ext/enterprise_script_service/msgpack/test/json.cpp +6 -0
  330. data/ext/enterprise_script_service/msgpack/test/limit.cpp +7 -0
  331. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +128 -6
  332. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +7 -2
  333. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +20 -3
  334. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +159 -0
  335. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +5 -0
  336. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +8 -3
  337. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +6 -0
  338. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +5 -0
  339. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +23 -18
  340. data/ext/enterprise_script_service/msgpack/test/object.cpp +77 -45
  341. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +28 -10
  342. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +25 -18
  343. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +7 -0
  344. data/ext/enterprise_script_service/msgpack/test/raw.cpp +17 -12
  345. data/ext/enterprise_script_service/msgpack/test/reference.cpp +6 -0
  346. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +6 -0
  347. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +6 -0
  348. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +6 -0
  349. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +6 -2
  350. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +10 -3
  351. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +7 -0
  352. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +6 -0
  353. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +5 -0
  354. data/ext/enterprise_script_service/msgpack/test/version.cpp +6 -0
  355. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +7 -0
  356. data/ext/enterprise_script_service/msgpack/test/zone.cpp +6 -0
  357. data/lib/script_core/version.rb +1 -1
  358. data/lib/tasks/mruby/engine.gembox.example +1 -0
  359. data/lib/tasks/script_core.rake +21 -3
  360. data/spec/dummy/app/helpers/fields_helper.rb +2 -2
  361. data/spec/dummy/mruby/engine.gembox +1 -0
  362. data/spec/script_core_spec.rb +1 -1
  363. metadata +38 -22
  364. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.gitignore +0 -1
  365. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.travis.yml +0 -2
  366. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/run_test.rb +0 -26
  367. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrblib/kernel.rb +0 -15
  368. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/unbound_method.rb +0 -9
  369. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.gitignore +0 -5
  370. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.travis.yml +0 -2
  371. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/packtest.rb +0 -157
  372. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/run_test.rb +0 -26
  373. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.c +0 -224
  374. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.h +0 -80
  375. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.h +0 -12
  376. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.gitignore +0 -4
  377. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis.yml +0 -29
  378. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis_build_config.rb +0 -6
  379. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/Rakefile +0 -29
  380. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/.travis.yml +0 -4
  381. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/run_test.rb +0 -28
@@ -102,8 +102,9 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
102
102
  }
103
103
  else {
104
104
  size_t data_len = sizeof(mrb_code) * irep->ilen;
105
- irep->iseq = (mrb_code *)mrb_malloc(mrb, data_len);
106
- memcpy(irep->iseq, src, data_len);
105
+ void *buf = mrb_malloc(mrb, data_len);
106
+ irep->iseq = (mrb_code *)buf;
107
+ memcpy(buf, src, data_len);
107
108
  src += data_len;
108
109
  }
109
110
  }
@@ -233,66 +234,6 @@ read_section_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
233
234
  return read_irep_record(mrb, bin, &len, flags);
234
235
  }
235
236
 
236
- /* ignore lineno record */
237
- static int
238
- read_lineno_record_1(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep, size_t *len)
239
- {
240
- size_t i, fname_len, niseq;
241
-
242
- *len = 0;
243
- bin += sizeof(uint32_t); /* record size */
244
- *len += sizeof(uint32_t);
245
- fname_len = bin_to_uint16(bin);
246
- bin += sizeof(uint16_t);
247
- *len += sizeof(uint16_t);
248
- bin += fname_len;
249
- *len += fname_len;
250
-
251
- niseq = (size_t)bin_to_uint32(bin);
252
- bin += sizeof(uint32_t); /* niseq */
253
- *len += sizeof(uint32_t);
254
-
255
- if (SIZE_ERROR_MUL(niseq, sizeof(uint16_t))) {
256
- return MRB_DUMP_GENERAL_FAILURE;
257
- }
258
- for (i = 0; i < niseq; i++) {
259
- bin += sizeof(uint16_t); /* niseq */
260
- *len += sizeof(uint16_t);
261
- }
262
-
263
- return MRB_DUMP_OK;
264
- }
265
-
266
- static int
267
- read_lineno_record(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep, size_t *lenp)
268
- {
269
- int result = read_lineno_record_1(mrb, bin, irep, lenp);
270
- int i;
271
-
272
- if (result != MRB_DUMP_OK) return result;
273
- for (i = 0; i < irep->rlen; i++) {
274
- size_t len;
275
-
276
- result = read_lineno_record(mrb, bin, irep->reps[i], &len);
277
- if (result != MRB_DUMP_OK) break;
278
- bin += len;
279
- *lenp += len;
280
- }
281
- return result;
282
- }
283
-
284
- static int
285
- read_section_lineno(mrb_state *mrb, const uint8_t *bin, mrb_irep *irep)
286
- {
287
- size_t len;
288
-
289
- len = 0;
290
- bin += sizeof(struct rite_section_lineno_header);
291
-
292
- /* Read Binary Data Section */
293
- return read_lineno_record(mrb, bin, irep, &len);
294
- }
295
-
296
237
  static int
297
238
  read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t *record_len, const mrb_sym *filenames, size_t filenames_len)
298
239
  {
@@ -519,10 +460,14 @@ lv_exit:
519
460
  }
520
461
 
521
462
  static int
522
- read_binary_header(const uint8_t *bin, size_t *bin_size, uint16_t *crc, uint8_t *flags)
463
+ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_t *crc, uint8_t *flags)
523
464
  {
524
465
  const struct rite_binary_header *header = (const struct rite_binary_header *)bin;
525
466
 
467
+ if (bufsize < sizeof(struct rite_binary_header)) {
468
+ return MRB_DUMP_READ_FAULT;
469
+ }
470
+
526
471
  if (memcmp(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident)) == 0) {
527
472
  if (bigendian_p())
528
473
  *flags |= FLAG_BYTEORDER_NATIVE;
@@ -539,16 +484,24 @@ read_binary_header(const uint8_t *bin, size_t *bin_size, uint16_t *crc, uint8_t
539
484
  return MRB_DUMP_INVALID_FILE_HEADER;
540
485
  }
541
486
 
487
+ if (memcmp(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version)) != 0) {
488
+ return MRB_DUMP_INVALID_FILE_HEADER;
489
+ }
490
+
542
491
  if (crc) {
543
492
  *crc = bin_to_uint16(header->binary_crc);
544
493
  }
545
494
  *bin_size = (size_t)bin_to_uint32(header->binary_size);
546
495
 
496
+ if (bufsize < *bin_size) {
497
+ return MRB_DUMP_READ_FAULT;
498
+ }
499
+
547
500
  return MRB_DUMP_OK;
548
501
  }
549
502
 
550
503
  static mrb_irep*
551
- read_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
504
+ read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
552
505
  {
553
506
  int result;
554
507
  mrb_irep *irep = NULL;
@@ -561,7 +514,7 @@ read_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
561
514
  return NULL;
562
515
  }
563
516
 
564
- result = read_binary_header(bin, &bin_size, &crc, &flags);
517
+ result = read_binary_header(bin, bufsize, &bin_size, &crc, &flags);
565
518
  if (result != MRB_DUMP_OK) {
566
519
  return NULL;
567
520
  }
@@ -578,13 +531,6 @@ read_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
578
531
  irep = read_section_irep(mrb, bin, flags);
579
532
  if (!irep) return NULL;
580
533
  }
581
- else if (memcmp(section_header->section_ident, RITE_SECTION_LINENO_IDENT, sizeof(section_header->section_ident)) == 0) {
582
- if (!irep) return NULL; /* corrupted data */
583
- result = read_section_lineno(mrb, bin, irep);
584
- if (result < MRB_DUMP_OK) {
585
- return NULL;
586
- }
587
- }
588
534
  else if (memcmp(section_header->section_ident, RITE_SECTION_DEBUG_IDENT, sizeof(section_header->section_ident)) == 0) {
589
535
  if (!irep) return NULL; /* corrupted data */
590
536
  result = read_section_debug(mrb, bin, irep, flags);
@@ -608,13 +554,19 @@ read_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
608
554
  mrb_irep*
609
555
  mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
610
556
  {
611
- #ifdef MRB_USE_ETEXT_EDATA
557
+ #if defined(MRB_USE_LINK_TIME_RO_DATA_P) || defined(MRB_USE_CUSTOM_RO_DATA_P)
612
558
  uint8_t flags = mrb_ro_data_p((char*)bin) ? FLAG_SRC_STATIC : FLAG_SRC_MALLOC;
613
559
  #else
614
560
  uint8_t flags = FLAG_SRC_STATIC;
615
561
  #endif
616
562
 
617
- return read_irep(mrb, bin, flags);
563
+ return read_irep(mrb, bin, (size_t)-1, flags);
564
+ }
565
+
566
+ MRB_API mrb_irep*
567
+ mrb_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
568
+ {
569
+ return read_irep(mrb, (const uint8_t *)buf, bufsize, FLAG_SRC_MALLOC);
618
570
  }
619
571
 
620
572
  void mrb_exc_set(mrb_state *mrb, mrb_value exc);
@@ -650,12 +602,24 @@ mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
650
602
  return load_irep(mrb, mrb_read_irep(mrb, bin), c);
651
603
  }
652
604
 
605
+ MRB_API mrb_value
606
+ mrb_load_irep_buf_cxt(mrb_state *mrb, const void *buf, size_t bufsize, mrbc_context *c)
607
+ {
608
+ return load_irep(mrb, mrb_read_irep_buf(mrb, buf, bufsize), c);
609
+ }
610
+
653
611
  MRB_API mrb_value
654
612
  mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
655
613
  {
656
614
  return mrb_load_irep_cxt(mrb, bin, NULL);
657
615
  }
658
616
 
617
+ MRB_API mrb_value
618
+ mrb_load_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
619
+ {
620
+ return mrb_load_irep_buf_cxt(mrb, buf, bufsize, NULL);
621
+ }
622
+
659
623
  #ifndef MRB_DISABLE_STDIO
660
624
 
661
625
  mrb_irep*
@@ -676,7 +640,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
676
640
  if (fread(buf, header_size, 1, fp) == 0) {
677
641
  goto irep_exit;
678
642
  }
679
- result = read_binary_header(buf, &buf_size, NULL, &flags);
643
+ result = read_binary_header(buf, (size_t)-1, &buf_size, NULL, &flags);
680
644
  if (result != MRB_DUMP_OK || buf_size <= header_size) {
681
645
  goto irep_exit;
682
646
  }
@@ -685,7 +649,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
685
649
  if (fread(buf+header_size, buf_size-header_size, 1, fp) == 0) {
686
650
  goto irep_exit;
687
651
  }
688
- irep = read_irep(mrb, buf, FLAG_SRC_MALLOC);
652
+ irep = read_irep(mrb, buf, (size_t)-1, FLAG_SRC_MALLOC);
689
653
 
690
654
  irep_exit:
691
655
  mrb_free(mrb, buf);
@@ -44,6 +44,15 @@ mrb_to_flo(mrb_state *mrb, mrb_value val)
44
44
  }
45
45
  return mrb_float(val);
46
46
  }
47
+
48
+ MRB_API mrb_value
49
+ mrb_int_value(mrb_state *mrb, mrb_float f)
50
+ {
51
+ if (FIXABLE_FLOAT(f)) {
52
+ return mrb_fixnum_value((mrb_int)f);
53
+ }
54
+ return mrb_float_value(mrb, f);
55
+ }
47
56
  #endif
48
57
 
49
58
  /*
@@ -56,7 +65,7 @@ mrb_to_flo(mrb_state *mrb, mrb_value val)
56
65
  * 2.0**3 #=> 8.0
57
66
  */
58
67
  static mrb_value
59
- num_pow(mrb_state *mrb, mrb_value x)
68
+ integral_pow(mrb_state *mrb, mrb_value x)
60
69
  {
61
70
  mrb_value y;
62
71
  #ifndef MRB_WITHOUT_FLOAT
@@ -103,6 +112,25 @@ num_pow(mrb_state *mrb, mrb_value x)
103
112
  #endif
104
113
  }
105
114
 
115
+ static mrb_value
116
+ integral_idiv(mrb_state *mrb, mrb_value x)
117
+ {
118
+ #ifdef MRB_WITHOUT_FLOAT
119
+ mrb_value y;
120
+
121
+ mrb_get_args(mrb, "o", &y);
122
+ if (!mrb_fixnum_p(y)) {
123
+ mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
124
+ }
125
+ return mrb_fixnum_value(mrb_fixnum(x) / mrb_fixnum(y));
126
+ #else
127
+ mrb_float y;
128
+
129
+ mrb_get_args(mrb, "f", &y);
130
+ return mrb_int_value(mrb, mrb_to_flo(mrb, x) / y);
131
+ #endif
132
+ }
133
+
106
134
  /* 15.2.8.3.4 */
107
135
  /* 15.2.9.3.4 */
108
136
  /*
@@ -114,19 +142,6 @@ num_pow(mrb_state *mrb, mrb_value x)
114
142
  * result.
115
143
  */
116
144
 
117
- mrb_value
118
- mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y)
119
- {
120
- #ifdef MRB_WITHOUT_FLOAT
121
- if (!mrb_fixnum_p(y)) {
122
- mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
123
- }
124
- return mrb_fixnum_value(mrb_fixnum(x) / mrb_fixnum(y));
125
- #else
126
- return mrb_float_value(mrb, mrb_to_flo(mrb, x) / mrb_to_flo(mrb, y));
127
- #endif
128
- }
129
-
130
145
  /* 15.2.9.3.19(x) */
131
146
  /*
132
147
  * call-seq:
@@ -136,7 +151,7 @@ mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y)
136
151
  */
137
152
 
138
153
  static mrb_value
139
- num_div(mrb_state *mrb, mrb_value x)
154
+ integral_div(mrb_state *mrb, mrb_value x)
140
155
  {
141
156
  #ifdef MRB_WITHOUT_FLOAT
142
157
  mrb_value y;
@@ -155,19 +170,19 @@ num_div(mrb_state *mrb, mrb_value x)
155
170
  }
156
171
 
157
172
  static mrb_value
158
- num_coerce_step_counter(mrb_state *mrb, mrb_value self)
173
+ integral_coerce_step_counter(mrb_state *mrb, mrb_value self)
159
174
  {
160
- mrb_value counter = self, num, step;
175
+ mrb_value num, step;
161
176
 
162
177
  mrb_get_args(mrb, "oo", &num, &step);
163
178
 
164
179
  #ifndef MRB_WITHOUT_FLOAT
165
180
  if (mrb_float_p(self) || mrb_float_p(num) || mrb_float_p(step)) {
166
- counter = mrb_funcall(mrb, counter, "to_f", 0);
181
+ return mrb_Float(mrb, self);
167
182
  }
168
183
  #endif
169
184
 
170
- return counter;
185
+ return self;
171
186
  }
172
187
 
173
188
  #ifndef MRB_WITHOUT_FLOAT
@@ -207,12 +222,12 @@ flo_to_s(mrb_state *mrb, mrb_value flt)
207
222
  char fmt[] = "%." MRB_STRINGIZE(FLO_TO_STR_PREC) "g";
208
223
  mrb_value str = mrb_float_to_str(mrb, flt, fmt);
209
224
  mrb_int len;
210
- char *begp;
225
+ char *begp, *p, *endp;
211
226
 
212
227
  insert_dot_zero:
213
228
  begp = RSTRING_PTR(str);
214
229
  len = RSTRING_LEN(str);
215
- for (char *p = begp, *endp = p + len; p < endp; ++p) {
230
+ for (p = begp, endp = p + len; p < endp; ++p) {
216
231
  if (*p == '.') {
217
232
  return str;
218
233
  }
@@ -231,9 +246,6 @@ flo_to_s(mrb_state *mrb, mrb_value flt)
231
246
  str = mrb_float_to_str(mrb, flt, fmt);
232
247
  goto insert_dot_zero;
233
248
  }
234
- else {
235
- mrb_str_cat(mrb, str, ".0", 2);
236
- }
237
249
 
238
250
  return str;
239
251
  }
@@ -305,6 +317,8 @@ flodivmod(mrb_state *mrb, double x, double y, mrb_float *divp, mrb_float *modp)
305
317
  div = (x - mod) / y;
306
318
  if (modp && divp) div = round(div);
307
319
  }
320
+ if (div == 0) div = 0.0;
321
+ if (mod == 0) mod = 0.0;
308
322
  if (y*mod < 0) {
309
323
  mod += y;
310
324
  div -= 1.0;
@@ -421,7 +435,7 @@ value_int64(mrb_state *mrb, mrb_value x)
421
435
  static mrb_value
422
436
  int64_value(mrb_state *mrb, int64_t v)
423
437
  {
424
- if (FIXABLE(v)) {
438
+ if (TYPED_FIXABLE(v,int64_t)) {
425
439
  return mrb_fixnum_value((mrb_int)v);
426
440
  }
427
441
  return mrb_float_value(mrb, (mrb_float)v);
@@ -431,7 +445,6 @@ static mrb_value
431
445
  flo_rev(mrb_state *mrb, mrb_value x)
432
446
  {
433
447
  int64_t v1;
434
- mrb_get_args(mrb, "");
435
448
  v1 = (int64_t)mrb_float(x);
436
449
  return int64_value(mrb, ~v1);
437
450
  }
@@ -484,6 +497,10 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width)
484
497
  if (width < 0) {
485
498
  while (width++) {
486
499
  val /= 2;
500
+ if (val < 1.0) {
501
+ val = 0;
502
+ break;
503
+ }
487
504
  }
488
505
  #if defined(_ISOC99_SOURCE)
489
506
  val = trunc(val);
@@ -503,14 +520,11 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width)
503
520
  val *= 2;
504
521
  }
505
522
  }
506
- if (FIXABLE_FLOAT(val)) {
507
- return mrb_fixnum_value((mrb_int)val);
508
- }
509
- return mrb_float_value(mrb, val);
523
+ return mrb_int_value(mrb, val);
510
524
  }
511
525
 
512
526
  static mrb_value
513
- flo_lshift(mrb_state *mrb, mrb_value x)
527
+ flo_rshift(mrb_state *mrb, mrb_value x)
514
528
  {
515
529
  mrb_int width;
516
530
 
@@ -519,7 +533,7 @@ flo_lshift(mrb_state *mrb, mrb_value x)
519
533
  }
520
534
 
521
535
  static mrb_value
522
- flo_rshift(mrb_state *mrb, mrb_value x)
536
+ flo_lshift(mrb_state *mrb, mrb_value x)
523
537
  {
524
538
  mrb_int width;
525
539
 
@@ -612,10 +626,7 @@ flo_floor(mrb_state *mrb, mrb_value num)
612
626
  mrb_float f = floor(mrb_float(num));
613
627
 
614
628
  mrb_check_num_exact(mrb, f);
615
- if (!FIXABLE_FLOAT(f)) {
616
- return mrb_float_value(mrb, f);
617
- }
618
- return mrb_fixnum_value((mrb_int)f);
629
+ return mrb_int_value(mrb, f);
619
630
  }
620
631
 
621
632
  /* 15.2.9.3.8 */
@@ -638,10 +649,7 @@ flo_ceil(mrb_state *mrb, mrb_value num)
638
649
  mrb_float f = ceil(mrb_float(num));
639
650
 
640
651
  mrb_check_num_exact(mrb, f);
641
- if (!FIXABLE_FLOAT(f)) {
642
- return mrb_float_value(mrb, f);
643
- }
644
- return mrb_fixnum_value((mrb_int)f);
652
+ return mrb_int_value(mrb, f);
645
653
  }
646
654
 
647
655
  /* 15.2.9.3.12 */
@@ -692,6 +700,7 @@ flo_round(mrb_state *mrb, mrb_value num)
692
700
 
693
701
  f = 1.0;
694
702
  i = ndigits >= 0 ? ndigits : -ndigits;
703
+ if (ndigits > DBL_DIG+2) return num;
695
704
  while (--i >= 0)
696
705
  f = f*10.0;
697
706
 
@@ -722,7 +731,7 @@ flo_round(mrb_state *mrb, mrb_value num)
722
731
  if (!isfinite(number)) return num;
723
732
  return mrb_float_value(mrb, number);
724
733
  }
725
- return mrb_fixnum_value((mrb_int)number);
734
+ return mrb_int_value(mrb, number);
726
735
  }
727
736
 
728
737
  /* 15.2.9.3.14 */
@@ -744,10 +753,7 @@ flo_truncate(mrb_state *mrb, mrb_value num)
744
753
  if (f < 0.0) f = ceil(f);
745
754
 
746
755
  mrb_check_num_exact(mrb, f);
747
- if (!FIXABLE_FLOAT(f)) {
748
- return mrb_float_value(mrb, f);
749
- }
750
- return mrb_fixnum_value((mrb_int)f);
756
+ return mrb_int_value(mrb, f);
751
757
  }
752
758
 
753
759
  static mrb_value
@@ -780,8 +786,8 @@ int_to_i(mrb_state *mrb, mrb_value num)
780
786
  return num;
781
787
  }
782
788
 
783
- mrb_value
784
- mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
789
+ static mrb_value
790
+ fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
785
791
  {
786
792
  mrb_int a;
787
793
 
@@ -805,6 +811,21 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
805
811
  #endif
806
812
  }
807
813
 
814
+ MRB_API mrb_value
815
+ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
816
+ {
817
+ if (mrb_fixnum_p(x)) {
818
+ return fixnum_mul(mrb, x, y);
819
+ }
820
+ #ifndef MRB_WITHOUT_FLOAT
821
+ if (mrb_float_p(x)) {
822
+ return mrb_float_value(mrb, mrb_float(x) * mrb_to_flo(mrb, y));
823
+ }
824
+ #endif
825
+ mrb_raise(mrb, E_TYPE_ERROR, "no number multiply");
826
+ return mrb_nil_value(); /* not reached */
827
+ }
828
+
808
829
  /* 15.2.8.3.3 */
809
830
  /*
810
831
  * call-seq:
@@ -821,7 +842,7 @@ fix_mul(mrb_state *mrb, mrb_value x)
821
842
  mrb_value y;
822
843
 
823
844
  mrb_get_args(mrb, "o", &y);
824
- return mrb_fixnum_mul(mrb, x, y);
845
+ return fixnum_mul(mrb, x, y);
825
846
  }
826
847
 
827
848
  static void
@@ -866,22 +887,24 @@ static mrb_value
866
887
  fix_mod(mrb_state *mrb, mrb_value x)
867
888
  {
868
889
  mrb_value y;
869
- mrb_int a;
890
+ mrb_int a, b;
870
891
 
871
892
  mrb_get_args(mrb, "o", &y);
872
893
  a = mrb_fixnum(x);
873
- if (mrb_fixnum_p(y)) {
874
- mrb_int b, mod;
894
+ if (mrb_fixnum_p(y) && a != MRB_INT_MIN && (b=mrb_fixnum(y)) != MRB_INT_MIN) {
895
+ mrb_int mod;
875
896
 
876
- if ((b=mrb_fixnum(y)) == 0) {
897
+ if (b == 0) {
877
898
  #ifdef MRB_WITHOUT_FLOAT
878
899
  /* ZeroDivisionError */
879
900
  return mrb_fixnum_value(0);
880
901
  #else
902
+ if (a > 0) return mrb_float_value(mrb, INFINITY);
903
+ if (a < 0) return mrb_float_value(mrb, INFINITY);
881
904
  return mrb_float_value(mrb, NAN);
882
905
  #endif
883
906
  }
884
- fixdivmod(mrb, a, b, 0, &mod);
907
+ fixdivmod(mrb, a, b, NULL, &mod);
885
908
  return mrb_fixnum_value(mod);
886
909
  }
887
910
  #ifdef MRB_WITHOUT_FLOAT
@@ -890,7 +913,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
890
913
  else {
891
914
  mrb_float mod;
892
915
 
893
- flodivmod(mrb, (mrb_float)a, mrb_to_flo(mrb, y), 0, &mod);
916
+ flodivmod(mrb, (mrb_float)a, mrb_to_flo(mrb, y), NULL, &mod);
894
917
  return mrb_float_value(mrb, mod);
895
918
  }
896
919
  #endif
@@ -933,7 +956,7 @@ fix_divmod(mrb_state *mrb, mrb_value x)
933
956
  mrb_value a, b;
934
957
 
935
958
  flodivmod(mrb, (mrb_float)mrb_fixnum(x), mrb_to_flo(mrb, y), &div, &mod);
936
- a = mrb_float_value(mrb, div);
959
+ a = mrb_int_value(mrb, div);
937
960
  b = mrb_float_value(mrb, mod);
938
961
  return mrb_assoc_new(mrb, a, b);
939
962
  }
@@ -951,7 +974,7 @@ flo_divmod(mrb_state *mrb, mrb_value x)
951
974
  mrb_get_args(mrb, "o", &y);
952
975
 
953
976
  flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
954
- a = mrb_float_value(mrb, div);
977
+ a = mrb_int_value(mrb, div);
955
978
  b = mrb_float_value(mrb, mod);
956
979
  return mrb_assoc_new(mrb, a, b);
957
980
  }
@@ -1096,7 +1119,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
1096
1119
  }
1097
1120
  else {
1098
1121
  if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
1099
- (val < (MRB_INT_MIN >> width))) {
1122
+ (val <= (MRB_INT_MIN >> width))) {
1100
1123
  #ifdef MRB_WITHOUT_FLOAT
1101
1124
  return mrb_fixnum_value(0);
1102
1125
  #else
@@ -1230,15 +1253,15 @@ mrb_flo_to_fixnum(mrb_state *mrb, mrb_value x)
1230
1253
  z = (mrb_int)d;
1231
1254
  }
1232
1255
  else {
1233
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "number (%S) too big for integer", x);
1256
+ mrb_raisef(mrb, E_RANGE_ERROR, "number (%v) too big for integer", x);
1234
1257
  }
1235
1258
  }
1236
1259
  return mrb_fixnum_value(z);
1237
1260
  }
1238
1261
  #endif
1239
1262
 
1240
- mrb_value
1241
- mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1263
+ static mrb_value
1264
+ fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1242
1265
  {
1243
1266
  mrb_int a;
1244
1267
 
@@ -1262,6 +1285,21 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1262
1285
  #endif
1263
1286
  }
1264
1287
 
1288
+ MRB_API mrb_value
1289
+ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1290
+ {
1291
+ if (mrb_fixnum_p(x)) {
1292
+ return fixnum_plus(mrb, x, y);
1293
+ }
1294
+ #ifndef MRB_WITHOUT_FLOAT
1295
+ if (mrb_float_p(x)) {
1296
+ return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
1297
+ }
1298
+ #endif
1299
+ mrb_raise(mrb, E_TYPE_ERROR, "no number addition");
1300
+ return mrb_nil_value(); /* not reached */
1301
+ }
1302
+
1265
1303
  /* 15.2.8.3.1 */
1266
1304
  /*
1267
1305
  * call-seq:
@@ -1277,11 +1315,11 @@ fix_plus(mrb_state *mrb, mrb_value self)
1277
1315
  mrb_value other;
1278
1316
 
1279
1317
  mrb_get_args(mrb, "o", &other);
1280
- return mrb_fixnum_plus(mrb, self, other);
1318
+ return fixnum_plus(mrb, self, other);
1281
1319
  }
1282
1320
 
1283
- mrb_value
1284
- mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1321
+ static mrb_value
1322
+ fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1285
1323
  {
1286
1324
  mrb_int a;
1287
1325
 
@@ -1304,6 +1342,21 @@ mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1304
1342
  #endif
1305
1343
  }
1306
1344
 
1345
+ MRB_API mrb_value
1346
+ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1347
+ {
1348
+ if (mrb_fixnum_p(x)) {
1349
+ return fixnum_minus(mrb, x, y);
1350
+ }
1351
+ #ifndef MRB_WITHOUT_FLOAT
1352
+ if (mrb_float_p(x)) {
1353
+ return mrb_float_value(mrb, mrb_float(x) - mrb_to_flo(mrb, y));
1354
+ }
1355
+ #endif
1356
+ mrb_raise(mrb, E_TYPE_ERROR, "no number subtraction");
1357
+ return mrb_nil_value(); /* not reached */
1358
+ }
1359
+
1307
1360
  /* 15.2.8.3.2 */
1308
1361
  /* 15.2.8.3.16 */
1309
1362
  /*
@@ -1320,7 +1373,7 @@ fix_minus(mrb_state *mrb, mrb_value self)
1320
1373
  mrb_value other;
1321
1374
 
1322
1375
  mrb_get_args(mrb, "o", &other);
1323
- return mrb_fixnum_minus(mrb, self, other);
1376
+ return fixnum_minus(mrb, self, other);
1324
1377
  }
1325
1378
 
1326
1379
 
@@ -1332,7 +1385,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base)
1332
1385
  mrb_int val = mrb_fixnum(x);
1333
1386
 
1334
1387
  if (base < 2 || 36 < base) {
1335
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %S", mrb_fixnum_value(base));
1388
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %i", base);
1336
1389
  }
1337
1390
 
1338
1391
  if (val == 0) {
@@ -1430,7 +1483,7 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
1430
1483
  * basis for the tests in <code>Comparable</code>.
1431
1484
  */
1432
1485
  static mrb_value
1433
- num_cmp(mrb_state *mrb, mrb_value self)
1486
+ integral_cmp(mrb_state *mrb, mrb_value self)
1434
1487
  {
1435
1488
  mrb_value other;
1436
1489
  mrb_int n;
@@ -1441,16 +1494,14 @@ num_cmp(mrb_state *mrb, mrb_value self)
1441
1494
  return mrb_fixnum_value(n);
1442
1495
  }
1443
1496
 
1444
- static void
1497
+ static mrb_noreturn void
1445
1498
  cmperr(mrb_state *mrb, mrb_value v1, mrb_value v2)
1446
1499
  {
1447
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "comparison of %S with %S failed",
1448
- mrb_obj_value(mrb_class(mrb, v1)),
1449
- mrb_obj_value(mrb_class(mrb, v2)));
1500
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "comparison of %t with %t failed", v1, v2);
1450
1501
  }
1451
1502
 
1452
1503
  static mrb_value
1453
- num_lt(mrb_state *mrb, mrb_value self)
1504
+ integral_lt(mrb_state *mrb, mrb_value self)
1454
1505
  {
1455
1506
  mrb_value other;
1456
1507
  mrb_int n;
@@ -1463,7 +1514,7 @@ num_lt(mrb_state *mrb, mrb_value self)
1463
1514
  }
1464
1515
 
1465
1516
  static mrb_value
1466
- num_le(mrb_state *mrb, mrb_value self)
1517
+ integral_le(mrb_state *mrb, mrb_value self)
1467
1518
  {
1468
1519
  mrb_value other;
1469
1520
  mrb_int n;
@@ -1476,7 +1527,7 @@ num_le(mrb_state *mrb, mrb_value self)
1476
1527
  }
1477
1528
 
1478
1529
  static mrb_value
1479
- num_gt(mrb_state *mrb, mrb_value self)
1530
+ integral_gt(mrb_state *mrb, mrb_value self)
1480
1531
  {
1481
1532
  mrb_value other;
1482
1533
  mrb_int n;
@@ -1489,7 +1540,7 @@ num_gt(mrb_state *mrb, mrb_value self)
1489
1540
  }
1490
1541
 
1491
1542
  static mrb_value
1492
- num_ge(mrb_state *mrb, mrb_value self)
1543
+ integral_ge(mrb_state *mrb, mrb_value self)
1493
1544
  {
1494
1545
  mrb_value other;
1495
1546
  mrb_int n;
@@ -1501,17 +1552,36 @@ num_ge(mrb_state *mrb, mrb_value self)
1501
1552
  return mrb_false_value();
1502
1553
  }
1503
1554
 
1555
+ MRB_API mrb_int
1556
+ mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
1557
+ {
1558
+ mrb_value v;
1559
+
1560
+ switch (mrb_type(obj1)) {
1561
+ case MRB_TT_FIXNUM:
1562
+ case MRB_TT_FLOAT:
1563
+ return cmpnum(mrb, obj1, obj2);
1564
+ case MRB_TT_STRING:
1565
+ if (!mrb_string_p(obj2))
1566
+ return -2;
1567
+ return mrb_str_cmp(mrb, obj1, obj2);
1568
+ default:
1569
+ v = mrb_funcall(mrb, obj1, "<=>", 1, obj2);
1570
+ if (mrb_nil_p(v) || !mrb_fixnum_p(v))
1571
+ return -2;
1572
+ return mrb_fixnum(v);
1573
+ }
1574
+ }
1575
+
1504
1576
  static mrb_value
1505
1577
  num_finite_p(mrb_state *mrb, mrb_value self)
1506
1578
  {
1507
- mrb_get_args(mrb, "");
1508
1579
  return mrb_true_value();
1509
1580
  }
1510
1581
 
1511
1582
  static mrb_value
1512
1583
  num_infinite_p(mrb_state *mrb, mrb_value self)
1513
1584
  {
1514
- mrb_get_args(mrb, "");
1515
1585
  return mrb_false_value();
1516
1586
  }
1517
1587
 
@@ -1544,21 +1614,21 @@ mrb_init_numeric(mrb_state *mrb)
1544
1614
  #endif
1545
1615
 
1546
1616
  integral = mrb_define_module(mrb, "Integral");
1617
+ mrb_define_method(mrb, integral,"**", integral_pow, MRB_ARGS_REQ(1));
1618
+ mrb_define_method(mrb, integral,"/", integral_div, MRB_ARGS_REQ(1)); /* 15.2.{8,9}.3.6 */
1619
+ mrb_define_method(mrb, integral,"quo", integral_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
1620
+ mrb_define_method(mrb, integral,"div", integral_idiv, MRB_ARGS_REQ(1));
1621
+ mrb_define_method(mrb, integral,"<=>", integral_cmp, MRB_ARGS_REQ(1)); /* 15.2.{8,9}.3.1 */
1622
+ mrb_define_method(mrb, integral,"<", integral_lt, MRB_ARGS_REQ(1));
1623
+ mrb_define_method(mrb, integral,"<=", integral_le, MRB_ARGS_REQ(1));
1624
+ mrb_define_method(mrb, integral,">", integral_gt, MRB_ARGS_REQ(1));
1625
+ mrb_define_method(mrb, integral,">=", integral_ge, MRB_ARGS_REQ(1));
1626
+ mrb_define_method(mrb, integral,"__coerce_step_counter", integral_coerce_step_counter, MRB_ARGS_REQ(2));
1547
1627
 
1548
1628
  /* Numeric Class */
1549
1629
  numeric = mrb_define_class(mrb, "Numeric", mrb->object_class); /* 15.2.7 */
1550
-
1551
- mrb_define_method(mrb, numeric, "**", num_pow, MRB_ARGS_REQ(1));
1552
- mrb_define_method(mrb, numeric, "/", num_div, MRB_ARGS_REQ(1)); /* 15.2.8.3.4 */
1553
- mrb_define_method(mrb, numeric, "quo", num_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
1554
- mrb_define_method(mrb, numeric, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.9.3.6 */
1555
- mrb_define_method(mrb, numeric, "<", num_lt, MRB_ARGS_REQ(1));
1556
- mrb_define_method(mrb, numeric, "<=", num_le, MRB_ARGS_REQ(1));
1557
- mrb_define_method(mrb, numeric, ">", num_gt, MRB_ARGS_REQ(1));
1558
- mrb_define_method(mrb, numeric, ">=", num_ge, MRB_ARGS_REQ(1));
1559
1630
  mrb_define_method(mrb, numeric, "finite?", num_finite_p, MRB_ARGS_NONE());
1560
1631
  mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE());
1561
- mrb_define_method(mrb, numeric, "__coerce_step_counter", num_coerce_step_counter, MRB_ARGS_REQ(2));
1562
1632
 
1563
1633
  /* Integer Class */
1564
1634
  integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
@@ -1567,10 +1637,10 @@ mrb_init_numeric(mrb_state *mrb)
1567
1637
  mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */
1568
1638
  mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE());
1569
1639
  #ifndef MRB_WITHOUT_FLOAT
1570
- mrb_define_method(mrb, integer, "ceil", int_to_i, MRB_ARGS_REQ(1)); /* 15.2.8.3.8 (x) */
1571
- mrb_define_method(mrb, integer, "floor", int_to_i, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 (x) */
1572
- mrb_define_method(mrb, integer, "round", int_to_i, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 (x) */
1573
- mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_REQ(1)); /* 15.2.8.3.15 (x) */
1640
+ mrb_define_method(mrb, integer, "ceil", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.8 (x) */
1641
+ mrb_define_method(mrb, integer, "floor", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.10 (x) */
1642
+ mrb_define_method(mrb, integer, "round", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.12 (x) */
1643
+ mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.15 (x) */
1574
1644
  #endif
1575
1645
 
1576
1646
  /* Fixnum Class */
@@ -1590,8 +1660,8 @@ mrb_init_numeric(mrb_state *mrb)
1590
1660
  #ifndef MRB_WITHOUT_FLOAT
1591
1661
  mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
1592
1662
  #endif
1593
- mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_NONE()); /* 15.2.8.3.25 */
1594
- mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_NONE());
1663
+ mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
1664
+ mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1));
1595
1665
  mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
1596
1666
 
1597
1667
  #ifndef MRB_WITHOUT_FLOAT
@@ -1608,8 +1678,8 @@ mrb_init_numeric(mrb_state *mrb)
1608
1678
  mrb_define_method(mrb, fl, "&", flo_and, MRB_ARGS_REQ(1));
1609
1679
  mrb_define_method(mrb, fl, "|", flo_or, MRB_ARGS_REQ(1));
1610
1680
  mrb_define_method(mrb, fl, "^", flo_xor, MRB_ARGS_REQ(1));
1611
- mrb_define_method(mrb, fl, ">>", flo_lshift, MRB_ARGS_REQ(1));
1612
- mrb_define_method(mrb, fl, "<<", flo_rshift, MRB_ARGS_REQ(1));
1681
+ mrb_define_method(mrb, fl, ">>", flo_rshift, MRB_ARGS_REQ(1));
1682
+ mrb_define_method(mrb, fl, "<<", flo_lshift, MRB_ARGS_REQ(1));
1613
1683
  mrb_define_method(mrb, fl, "ceil", flo_ceil, MRB_ARGS_NONE()); /* 15.2.9.3.8 */
1614
1684
  mrb_define_method(mrb, fl, "finite?", flo_finite_p, MRB_ARGS_NONE()); /* 15.2.9.3.9 */
1615
1685
  mrb_define_method(mrb, fl, "floor", flo_floor, MRB_ARGS_NONE()); /* 15.2.9.3.10 */