script_core 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +2 -2
  4. data/ext/enterprise_script_service/Rakefile +1 -1
  5. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +117 -74
  6. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +41 -37
  7. data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
  8. data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
  9. data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
  10. data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
  11. data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
  12. data/ext/enterprise_script_service/mruby/.travis.yml +2 -2
  13. data/ext/enterprise_script_service/mruby/.yamllint +8 -0
  14. data/ext/enterprise_script_service/mruby/AUTHORS +3 -0
  15. data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
  16. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
  17. data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
  18. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  19. data/ext/enterprise_script_service/mruby/Makefile +1 -1
  20. data/ext/enterprise_script_service/mruby/README.md +4 -14
  21. data/ext/enterprise_script_service/mruby/Rakefile +18 -108
  22. data/ext/enterprise_script_service/mruby/TODO.md +17 -0
  23. data/ext/enterprise_script_service/mruby/appveyor.yml +31 -25
  24. data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
  25. data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
  26. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +2 -19
  27. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +2 -2
  28. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +1 -18
  29. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +2 -19
  30. data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
  31. data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
  32. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_android_armeabi_v7a_neon_hard.rb → build_config/android_armeabi_v7a_neon_hard.rb} +0 -15
  33. data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
  34. data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
  35. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +2 -19
  36. data/ext/enterprise_script_service/mruby/{travis_config.rb → build_config/ci/gcc-clang.rb} +10 -10
  37. data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
  38. data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
  39. data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
  40. data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
  41. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_dreamcast_shelf.rb → build_config/dreamcast_shelf.rb} +5 -19
  42. data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
  43. data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
  44. data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
  45. data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
  46. data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
  47. data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
  48. data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
  49. data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
  50. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +138 -49
  51. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
  52. data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
  53. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +49 -22
  54. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
  55. data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
  56. data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
  57. data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
  58. data/ext/enterprise_script_service/mruby/doc/opcode.md +93 -107
  59. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
  60. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
  61. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
  62. data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
  63. data/ext/enterprise_script_service/mruby/include/mrbconf.h +81 -62
  64. data/ext/enterprise_script_service/mruby/include/mruby.h +137 -96
  65. data/ext/enterprise_script_service/mruby/include/mruby/array.h +23 -6
  66. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +73 -48
  67. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
  68. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +79 -48
  69. data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
  70. data/ext/enterprise_script_service/mruby/include/mruby/common.h +4 -1
  71. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +13 -7
  72. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  73. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +17 -35
  74. data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
  75. data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
  76. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
  77. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
  78. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +64 -14
  79. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +6 -14
  80. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +36 -63
  81. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
  82. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +27 -23
  83. data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
  84. data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
  85. data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
  86. data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
  87. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +80 -13
  88. data/ext/enterprise_script_service/mruby/include/mruby/string.h +10 -15
  89. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
  90. data/ext/enterprise_script_service/mruby/include/mruby/value.h +29 -19
  91. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
  92. data/ext/enterprise_script_service/mruby/include/mruby/version.h +26 -7
  93. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -44
  94. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +55 -37
  95. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
  96. data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
  97. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +75 -32
  98. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
  99. data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
  100. data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
  101. data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
  102. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -88
  103. data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
  104. data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
  105. data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -1
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +5 -4
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +28 -19
  109. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
  110. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
  111. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
  112. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
  113. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
  114. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -3
  115. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
  116. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -4
  117. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
  118. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
  119. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +41 -34
  120. data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
  121. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
  122. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +19 -9
  123. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
  124. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -1
  125. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +22 -6
  126. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
  127. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +2 -2
  128. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
  129. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
  130. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +2 -1
  131. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +430 -399
  132. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
  133. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
  134. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +559 -217
  135. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +4774 -4193
  136. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +18 -19
  137. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +1 -1
  138. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +8 -7
  139. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
  140. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
  141. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
  142. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
  143. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +17 -25
  144. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +18 -13
  145. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +30 -2
  146. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
  147. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +2 -2
  148. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
  149. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +2 -2
  150. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
  151. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +2 -2
  152. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +55 -52
  153. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +4 -2
  154. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +99 -87
  155. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +2 -0
  156. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +2 -3
  157. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +1 -1
  158. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +7 -6
  159. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
  160. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
  161. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +43 -58
  162. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +4 -4
  163. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
  164. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +77 -74
  165. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
  166. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
  167. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +5 -4
  168. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -12
  169. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
  170. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
  171. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
  172. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
  173. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +38 -88
  174. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
  175. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +62 -26
  176. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +32 -19
  177. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
  178. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
  179. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
  180. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
  181. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +20 -40
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +11 -17
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +4 -4
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +102 -71
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +4 -2
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +13 -9
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +18 -25
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +6 -5
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +16 -44
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +27 -27
  203. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
  204. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
  205. data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
  206. data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
  207. data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
  208. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
  209. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +0 -20
  210. data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
  211. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
  212. data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
  213. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
  214. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
  215. data/ext/enterprise_script_service/mruby/src/array.c +43 -80
  216. data/ext/enterprise_script_service/mruby/src/backtrace.c +16 -17
  217. data/ext/enterprise_script_service/mruby/src/class.c +774 -182
  218. data/ext/enterprise_script_service/mruby/src/codedump.c +223 -198
  219. data/ext/enterprise_script_service/mruby/src/debug.c +6 -6
  220. data/ext/enterprise_script_service/mruby/src/dump.c +466 -141
  221. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  222. data/ext/enterprise_script_service/mruby/src/error.c +36 -13
  223. data/ext/enterprise_script_service/mruby/src/etc.c +43 -34
  224. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +5 -6
  225. data/ext/enterprise_script_service/mruby/src/gc.c +73 -71
  226. data/ext/enterprise_script_service/mruby/src/hash.c +1050 -707
  227. data/ext/enterprise_script_service/mruby/src/kernel.c +75 -220
  228. data/ext/enterprise_script_service/mruby/src/load.c +196 -166
  229. data/ext/enterprise_script_service/mruby/src/numeric.c +352 -314
  230. data/ext/enterprise_script_service/mruby/src/object.c +97 -90
  231. data/ext/enterprise_script_service/mruby/src/print.c +4 -3
  232. data/ext/enterprise_script_service/mruby/src/proc.c +48 -56
  233. data/ext/enterprise_script_service/mruby/src/range.c +45 -21
  234. data/ext/enterprise_script_service/mruby/src/state.c +25 -32
  235. data/ext/enterprise_script_service/mruby/src/string.c +59 -101
  236. data/ext/enterprise_script_service/mruby/src/symbol.c +121 -56
  237. data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
  238. data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
  239. data/ext/enterprise_script_service/mruby/src/vm.c +617 -602
  240. data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
  241. data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
  242. data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
  243. data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
  244. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +83 -77
  245. data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
  246. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
  247. data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
  248. data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
  249. data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
  250. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +6 -5
  251. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +10 -14
  252. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +17 -21
  253. data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
  254. data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
  255. data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
  256. data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
  257. data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
  258. data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
  259. data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
  260. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +1 -1
  261. data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
  262. data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
  263. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
  264. data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
  265. data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
  266. data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
  267. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
  268. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
  269. data/ext/enterprise_script_service/mruby_config.rb +2 -5
  270. data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
  271. data/lib/script_core/version.rb +1 -1
  272. data/spec/script_core_spec.rb +13 -0
  273. metadata +61 -23
  274. data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +0 -24
  275. data/ext/enterprise_script_service/mruby/TODO +0 -8
  276. data/ext/enterprise_script_service/mruby/appveyor_config.rb +0 -46
  277. data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
  278. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
  279. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
  280. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
  281. data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
  282. data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
  283. data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
@@ -1,10 +1,10 @@
1
1
  /*
2
- ** numeric.c - Numeric, Integer, Float, Fixnum class
2
+ ** numeric.c - Numeric, Integer, Float class
3
3
  **
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
- #ifndef MRB_WITHOUT_FLOAT
7
+ #ifndef MRB_NO_FLOAT
8
8
  #include <float.h>
9
9
  #include <math.h>
10
10
  #endif
@@ -17,9 +17,10 @@
17
17
  #include <mruby/numeric.h>
18
18
  #include <mruby/string.h>
19
19
  #include <mruby/class.h>
20
+ #include <mruby/presym.h>
20
21
 
21
- #ifndef MRB_WITHOUT_FLOAT
22
- #ifdef MRB_USE_FLOAT
22
+ #ifndef MRB_NO_FLOAT
23
+ #ifdef MRB_USE_FLOAT32
23
24
  #define trunc(f) truncf(f)
24
25
  #define floor(f) floorf(f)
25
26
  #define ceil(f) ceilf(f)
@@ -30,30 +31,38 @@
30
31
  #endif
31
32
  #endif
32
33
 
33
- #ifndef MRB_WITHOUT_FLOAT
34
+ #ifndef MRB_NO_FLOAT
34
35
  MRB_API mrb_float
35
36
  mrb_to_flo(mrb_state *mrb, mrb_value val)
36
37
  {
37
38
  switch (mrb_type(val)) {
38
- case MRB_TT_FIXNUM:
39
- return (mrb_float)mrb_fixnum(val);
39
+ case MRB_TT_INTEGER:
40
+ return (mrb_float)mrb_integer(val);
40
41
  case MRB_TT_FLOAT:
41
42
  break;
42
- default:
43
+ case MRB_TT_STRING:
44
+ case MRB_TT_FALSE:
45
+ case MRB_TT_TRUE:
43
46
  mrb_raise(mrb, E_TYPE_ERROR, "non float value");
47
+ default:
48
+ val = mrb_type_convert(mrb, val, MRB_TT_FLOAT, MRB_SYM(to_f));
49
+ break;
44
50
  }
45
51
  return mrb_float(val);
46
52
  }
53
+ #endif
47
54
 
48
- MRB_API mrb_value
49
- mrb_int_value(mrb_state *mrb, mrb_float f)
55
+ static void
56
+ int_overflow(mrb_state *mrb, const char *reason)
50
57
  {
51
- if (FIXABLE_FLOAT(f)) {
52
- return mrb_fixnum_value((mrb_int)f);
53
- }
54
- return mrb_float_value(mrb, f);
58
+ mrb_raisef(mrb, E_RANGE_ERROR, "integer overflow in %s", reason);
59
+ }
60
+
61
+ static void
62
+ int_zerodiv(mrb_state *mrb)
63
+ {
64
+ mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0");
55
65
  }
56
- #endif
57
66
 
58
67
  /*
59
68
  * call-seq:
@@ -65,80 +74,91 @@ mrb_int_value(mrb_state *mrb, mrb_float f)
65
74
  * 2.0**3 #=> 8.0
66
75
  */
67
76
  static mrb_value
68
- integral_pow(mrb_state *mrb, mrb_value x)
77
+ int_pow(mrb_state *mrb, mrb_value x)
69
78
  {
79
+ mrb_int base = mrb_int(mrb, x);
80
+ mrb_int exp;
81
+ #ifndef MRB_NO_FLOAT
70
82
  mrb_value y = mrb_get_arg1(mrb);
71
- #ifndef MRB_WITHOUT_FLOAT
72
- mrb_float d;
73
- #endif
83
+ mrb_float z;
74
84
 
75
- if (mrb_fixnum_p(x) && mrb_fixnum_p(y)) {
76
- /* try ipow() */
77
- mrb_int base = mrb_fixnum(x);
78
- mrb_int exp = mrb_fixnum(y);
79
- mrb_int result = 1;
80
-
81
- if (exp < 0)
82
- #ifdef MRB_WITHOUT_FLOAT
83
- return mrb_fixnum_value(0);
85
+ if (!mrb_integer_p(y)) {
86
+ mrb_get_args(mrb, "f", &z);
87
+ z = pow((mrb_float)base, z);
88
+ return mrb_float_value(mrb, z);
89
+ }
90
+ else {
91
+ mrb_get_args(mrb, "i", &exp);
92
+ z = pow((double)base, (double)exp);
93
+ if (exp < 0 || z < (mrb_float)MRB_INT_MIN || (mrb_float)MRB_INT_MAX < z) {
94
+ return mrb_float_value(mrb, z);
95
+ }
96
+ }
97
+ return mrb_int_value(mrb, (mrb_int)z);
84
98
  #else
85
- goto float_pow;
86
- #endif
87
- for (;;) {
88
- if (exp & 1) {
89
- if (mrb_int_mul_overflow(result, base, &result)) {
90
- #ifndef MRB_WITHOUT_FLOAT
91
- goto float_pow;
92
- #endif
93
- }
94
- }
95
- exp >>= 1;
96
- if (exp == 0) break;
97
- if (mrb_int_mul_overflow(base, base, &base)) {
98
- #ifndef MRB_WITHOUT_FLOAT
99
- goto float_pow;
100
- #endif
99
+ mrb_int result = 1;
100
+
101
+ mrb_get_args(mrb, "i", &exp);
102
+ if (exp < 0) {
103
+ return mrb_fixnum_value(0);
104
+ }
105
+ for (;;) {
106
+ if (exp & 1) {
107
+ if (mrb_int_mul_overflow(result, base, &result)) {
108
+ int_overflow(mrb, "multiplication");
101
109
  }
102
110
  }
103
- return mrb_fixnum_value(result);
111
+ exp >>= 1;
112
+ if (exp == 0) break;
113
+ if (mrb_int_mul_overflow(base, base, &base)) {
114
+ int_overflow(mrb, "multiplication");
115
+ }
104
116
  }
105
- #ifdef MRB_WITHOUT_FLOAT
106
- mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
107
- #else
108
- float_pow:
109
- d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y));
110
- return mrb_float_value(mrb, d);
117
+ return mrb_int_value(mrb, result);
111
118
  #endif
112
119
  }
113
120
 
114
- static mrb_value
115
- integral_idiv(mrb_state *mrb, mrb_value x)
116
- {
117
- #ifdef MRB_WITHOUT_FLOAT
118
- mrb_value y = mrb_get_arg1(mrb);
119
121
 
120
- if (!mrb_fixnum_p(y)) {
121
- mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
122
+ mrb_int
123
+ mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y)
124
+ {
125
+ if (y == 0) {
126
+ int_zerodiv(mrb);
122
127
  }
123
- return mrb_fixnum_value(mrb_fixnum(x) / mrb_fixnum(y));
124
- #else
125
- mrb_float y;
128
+ else if(x == MRB_INT_MIN && y == -1) {
129
+ int_overflow(mrb, "division");
130
+ }
131
+ else {
132
+ mrb_int div = x / y;
126
133
 
127
- mrb_get_args(mrb, "f", &y);
128
- return mrb_int_value(mrb, mrb_to_flo(mrb, x) / y);
129
- #endif
134
+ if ((x ^ y) < 0 && x != div * y) {
135
+ div -= 1;
136
+ }
137
+ return div;
138
+ }
139
+ /* not reached */
140
+ return 0;
130
141
  }
131
142
 
132
143
  /* 15.2.8.3.4 */
133
144
  /* 15.2.9.3.4 */
134
145
  /*
135
146
  * call-seq:
136
- * num / other -> num
147
+ * int / other -> int
137
148
  *
138
149
  * Performs division: the class of the resulting object depends on
139
150
  * the class of <code>num</code> and on the magnitude of the
140
151
  * result.
141
152
  */
153
+ static mrb_value
154
+ int_div(mrb_state *mrb, mrb_value xv)
155
+ {
156
+ mrb_int y, div;
157
+
158
+ mrb_get_args(mrb, "i", &y);
159
+ div = mrb_num_div_int(mrb, mrb_integer(xv), y);
160
+ return mrb_int_value(mrb, div);
161
+ }
142
162
 
143
163
  /* 15.2.9.3.19(x) */
144
164
  /*
@@ -149,31 +169,35 @@ integral_idiv(mrb_state *mrb, mrb_value x)
149
169
  */
150
170
 
151
171
  static mrb_value
152
- integral_div(mrb_state *mrb, mrb_value x)
172
+ int_quo(mrb_state *mrb, mrb_value xv)
153
173
  {
154
- #ifdef MRB_WITHOUT_FLOAT
155
- mrb_value y = mrb_get_arg1(mrb);
174
+ #ifdef MRB_NO_FLOAT
175
+ mrb_int y;
156
176
 
157
- if (!mrb_fixnum_p(y)) {
158
- mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
177
+ mrb_get_args(mrb, "i", &y);
178
+ if (y == 0) {
179
+ int_zerodiv(mrb);
159
180
  }
160
- return mrb_fixnum_value(mrb_fixnum(x) / mrb_fixnum(y));
181
+ return mrb_fixnum_value(mrb_integer(xv) / y);
161
182
  #else
162
183
  mrb_float y;
163
184
 
164
185
  mrb_get_args(mrb, "f", &y);
165
- return mrb_float_value(mrb, mrb_to_flo(mrb, x) / y);
186
+ if (y == 0) {
187
+ int_zerodiv(mrb);
188
+ }
189
+ return mrb_float_value(mrb, mrb_integer(xv) / y);
166
190
  #endif
167
191
  }
168
192
 
169
193
  static mrb_value
170
- integral_coerce_step_counter(mrb_state *mrb, mrb_value self)
194
+ coerce_step_counter(mrb_state *mrb, mrb_value self)
171
195
  {
172
196
  mrb_value num, step;
173
197
 
174
198
  mrb_get_args(mrb, "oo", &num, &step);
175
199
 
176
- #ifndef MRB_WITHOUT_FLOAT
200
+ #ifndef MRB_NO_FLOAT
177
201
  if (mrb_float_p(self) || mrb_float_p(num) || mrb_float_p(step)) {
178
202
  return mrb_Float(mrb, self);
179
203
  }
@@ -182,7 +206,7 @@ integral_coerce_step_counter(mrb_state *mrb, mrb_value self)
182
206
  return self;
183
207
  }
184
208
 
185
- #ifndef MRB_WITHOUT_FLOAT
209
+ #ifndef MRB_NO_FLOAT
186
210
  /********************************************************************
187
211
  *
188
212
  * Document-class: Float
@@ -192,15 +216,64 @@ integral_coerce_step_counter(mrb_state *mrb, mrb_value self)
192
216
  * representation.
193
217
  */
194
218
 
219
+ static mrb_value
220
+ flo_pow(mrb_state *mrb, mrb_value x)
221
+ {
222
+ mrb_value y = mrb_get_arg1(mrb);
223
+ mrb_float d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y));
224
+ return mrb_float_value(mrb, d);
225
+ }
226
+
227
+ static mrb_value
228
+ flo_idiv(mrb_state *mrb, mrb_value xv)
229
+ {
230
+ mrb_int y, div;
231
+
232
+ mrb_get_args(mrb, "i", &y);
233
+ div = mrb_num_div_int(mrb, (mrb_int)mrb_float(xv), y);
234
+ return mrb_int_value(mrb, (mrb_int)div);
235
+ }
236
+
237
+ mrb_float
238
+ mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y)
239
+ {
240
+ mrb_float f;
241
+
242
+ if (y == 0) {
243
+ if (x > 0) f = INFINITY;
244
+ else if (x < 0) f = -INFINITY;
245
+ else /* if (x == 0) */ f = NAN;
246
+ }
247
+ else {
248
+ f = x / y;
249
+ }
250
+ return f;
251
+ }
252
+
253
+ static mrb_value
254
+ flo_div(mrb_state *mrb, mrb_value xv)
255
+ {
256
+ mrb_float x, y;
257
+
258
+ x = mrb_float(xv);
259
+ mrb_get_args(mrb, "f", &y);
260
+ x = mrb_num_div_flo(mrb, x, y);
261
+ return mrb_float_value(mrb, x);
262
+ }
263
+
195
264
  /* 15.2.9.3.16(x) */
196
265
  /*
197
266
  * call-seq:
198
267
  * flt.to_s -> string
268
+ * flt.inspect -> string
199
269
  *
200
270
  * Returns a string containing a representation of self. As well as a
201
271
  * fixed or exponential form of the number, the call may return
202
272
  * "<code>NaN</code>", "<code>Infinity</code>", and
203
273
  * "<code>-Infinity</code>".
274
+ *
275
+ * 3.0.to_s #=> 3.0
276
+ * 3.25.to_s #=> 3.25
204
277
  */
205
278
 
206
279
  static mrb_value
@@ -247,6 +320,9 @@ flo_to_s(mrb_state *mrb, mrb_value flt)
247
320
  str = mrb_float_to_str(mrb, flt, fmt);
248
321
  goto insert_dot_zero;
249
322
  }
323
+ else {
324
+ mrb_str_cat(mrb, str, ".0", 2);
325
+ }
250
326
 
251
327
  goto exit;
252
328
  }
@@ -367,15 +443,15 @@ flo_mod(mrb_state *mrb, mrb_value x)
367
443
  * (1.0).eql?(1.0) #=> true
368
444
  */
369
445
  static mrb_value
370
- fix_eql(mrb_state *mrb, mrb_value x)
446
+ int_eql(mrb_state *mrb, mrb_value x)
371
447
  {
372
448
  mrb_value y = mrb_get_arg1(mrb);
373
449
 
374
- if (!mrb_fixnum_p(y)) return mrb_false_value();
375
- return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y));
450
+ if (!mrb_integer_p(y)) return mrb_false_value();
451
+ return mrb_bool_value(mrb_integer(x) == mrb_integer(y));
376
452
  }
377
453
 
378
- #ifndef MRB_WITHOUT_FLOAT
454
+ #ifndef MRB_NO_FLOAT
379
455
  static mrb_value
380
456
  flo_eql(mrb_state *mrb, mrb_value x)
381
457
  {
@@ -404,8 +480,8 @@ flo_eq(mrb_state *mrb, mrb_value x)
404
480
  mrb_value y = mrb_get_arg1(mrb);
405
481
 
406
482
  switch (mrb_type(y)) {
407
- case MRB_TT_FIXNUM:
408
- return mrb_bool_value(mrb_float(x) == (mrb_float)mrb_fixnum(y));
483
+ case MRB_TT_INTEGER:
484
+ return mrb_bool_value(mrb_float(x) == (mrb_float)mrb_integer(y));
409
485
  case MRB_TT_FLOAT:
410
486
  return mrb_bool_value(mrb_float(x) == mrb_float(y));
411
487
  default:
@@ -417,10 +493,15 @@ static int64_t
417
493
  value_int64(mrb_state *mrb, mrb_value x)
418
494
  {
419
495
  switch (mrb_type(x)) {
420
- case MRB_TT_FIXNUM:
421
- return (int64_t)mrb_fixnum(x);
496
+ case MRB_TT_INTEGER:
497
+ return (int64_t)mrb_integer(x);
422
498
  case MRB_TT_FLOAT:
423
- return (int64_t)mrb_float(x);
499
+ {
500
+ double f = mrb_float(x);
501
+
502
+ if ((mrb_float)INT64_MAX >= f && f >= (mrb_float)INT64_MIN)
503
+ return (int64_t)f;
504
+ }
424
505
  default:
425
506
  mrb_raise(mrb, E_TYPE_ERROR, "cannot convert to Integer");
426
507
  break;
@@ -432,17 +513,16 @@ value_int64(mrb_state *mrb, mrb_value x)
432
513
  static mrb_value
433
514
  int64_value(mrb_state *mrb, int64_t v)
434
515
  {
435
- if (TYPED_FIXABLE(v,int64_t)) {
436
- return mrb_fixnum_value((mrb_int)v);
516
+ if (!TYPED_FIXABLE(v,int64_t)) {
517
+ int_overflow(mrb, "bit operation");
437
518
  }
438
- return mrb_float_value(mrb, (mrb_float)v);
519
+ return mrb_fixnum_value((mrb_int)v);
439
520
  }
440
521
 
441
522
  static mrb_value
442
523
  flo_rev(mrb_state *mrb, mrb_value x)
443
524
  {
444
- int64_t v1;
445
- v1 = (int64_t)mrb_float(x);
525
+ int64_t v1 = value_int64(mrb, x);
446
526
  return int64_value(mrb, ~v1);
447
527
  }
448
528
 
@@ -452,7 +532,7 @@ flo_and(mrb_state *mrb, mrb_value x)
452
532
  mrb_value y = mrb_get_arg1(mrb);
453
533
  int64_t v1, v2;
454
534
 
455
- v1 = (int64_t)mrb_float(x);
535
+ v1 = value_int64(mrb, x);
456
536
  v2 = value_int64(mrb, y);
457
537
  return int64_value(mrb, v1 & v2);
458
538
  }
@@ -463,7 +543,7 @@ flo_or(mrb_state *mrb, mrb_value x)
463
543
  mrb_value y = mrb_get_arg1(mrb);
464
544
  int64_t v1, v2;
465
545
 
466
- v1 = (int64_t)mrb_float(x);
546
+ v1 = value_int64(mrb, x);
467
547
  v2 = value_int64(mrb, y);
468
548
  return int64_value(mrb, v1 | v2);
469
549
  }
@@ -474,7 +554,7 @@ flo_xor(mrb_state *mrb, mrb_value x)
474
554
  mrb_value y = mrb_get_arg1(mrb);
475
555
  int64_t v1, v2;
476
556
 
477
- v1 = (int64_t)mrb_float(x);
557
+ v1 = value_int64(mrb, x);
478
558
  v2 = value_int64(mrb, y);
479
559
  return int64_value(mrb, v1 ^ v2);
480
560
  }
@@ -488,6 +568,10 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width)
488
568
  return x;
489
569
  }
490
570
  val = mrb_float(x);
571
+ if (width < -MRB_INT_BIT/2) {
572
+ if (val < 0) return mrb_fixnum_value(-1);
573
+ return mrb_fixnum_value(0);
574
+ }
491
575
  if (width < 0) {
492
576
  while (width++) {
493
577
  val /= 2;
@@ -514,7 +598,9 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width)
514
598
  val *= 2;
515
599
  }
516
600
  }
517
- return mrb_int_value(mrb, val);
601
+ if (FIXABLE_FLOAT(val))
602
+ return mrb_int_value(mrb, (mrb_int)val);
603
+ return mrb_float_value(mrb, val);
518
604
  }
519
605
 
520
606
  static mrb_value
@@ -523,6 +609,7 @@ flo_rshift(mrb_state *mrb, mrb_value x)
523
609
  mrb_int width;
524
610
 
525
611
  mrb_get_args(mrb, "i", &width);
612
+ if (width == MRB_INT_MIN) return flo_shift(mrb, x, -MRB_INT_BIT);
526
613
  return flo_shift(mrb, x, -width);
527
614
  }
528
615
 
@@ -620,7 +707,7 @@ flo_floor(mrb_state *mrb, mrb_value num)
620
707
  mrb_float f = floor(mrb_float(num));
621
708
 
622
709
  mrb_check_num_exact(mrb, f);
623
- return mrb_int_value(mrb, f);
710
+ return mrb_int_value(mrb, (mrb_int)f);
624
711
  }
625
712
 
626
713
  /* 15.2.9.3.8 */
@@ -643,7 +730,7 @@ flo_ceil(mrb_state *mrb, mrb_value num)
643
730
  mrb_float f = ceil(mrb_float(num));
644
731
 
645
732
  mrb_check_num_exact(mrb, f);
646
- return mrb_int_value(mrb, f);
733
+ return mrb_int_value(mrb, (mrb_int)f);
647
734
  }
648
735
 
649
736
  /* 15.2.9.3.12 */
@@ -725,7 +812,9 @@ flo_round(mrb_state *mrb, mrb_value num)
725
812
  if (!isfinite(number)) return num;
726
813
  return mrb_float_value(mrb, number);
727
814
  }
728
- return mrb_int_value(mrb, number);
815
+ if (!FIXABLE_FLOAT(number))
816
+ return mrb_float_value(mrb, number);
817
+ return mrb_int_value(mrb, (mrb_int)number);
729
818
  }
730
819
 
731
820
  /* 15.2.9.3.14 */
@@ -747,7 +836,7 @@ flo_truncate(mrb_state *mrb, mrb_value num)
747
836
  if (f < 0.0) f = ceil(f);
748
837
 
749
838
  mrb_check_num_exact(mrb, f);
750
- return mrb_int_value(mrb, f);
839
+ return mrb_int_value(mrb, (mrb_int)f);
751
840
  }
752
841
 
753
842
  static mrb_value
@@ -760,8 +849,7 @@ flo_nan_p(mrb_state *mrb, mrb_value num)
760
849
  /*
761
850
  * Document-class: Integer
762
851
  *
763
- * <code>Integer</code> is the basis for the two concrete classes that
764
- * hold whole numbers, <code>Bignum</code> and <code>Fixnum</code>.
852
+ * <code>Integer</code> is hold whole numbers.
765
853
  *
766
854
  */
767
855
 
@@ -785,20 +873,18 @@ fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
785
873
  {
786
874
  mrb_int a;
787
875
 
788
- a = mrb_fixnum(x);
789
- if (mrb_fixnum_p(y)) {
876
+ a = mrb_integer(x);
877
+ if (mrb_integer_p(y)) {
790
878
  mrb_int b, c;
791
879
 
792
880
  if (a == 0) return x;
793
- b = mrb_fixnum(y);
881
+ b = mrb_integer(y);
794
882
  if (mrb_int_mul_overflow(a, b, &c)) {
795
- #ifndef MRB_WITHOUT_FLOAT
796
- return mrb_float_value(mrb, (mrb_float)a * (mrb_float)b);
797
- #endif
883
+ int_overflow(mrb, "multiplication");
798
884
  }
799
885
  return mrb_fixnum_value(c);
800
886
  }
801
- #ifdef MRB_WITHOUT_FLOAT
887
+ #ifdef MRB_NO_FLOAT
802
888
  mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
803
889
  #else
804
890
  return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y));
@@ -808,10 +894,10 @@ fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
808
894
  MRB_API mrb_value
809
895
  mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
810
896
  {
811
- if (mrb_fixnum_p(x)) {
897
+ if (mrb_integer_p(x)) {
812
898
  return fixnum_mul(mrb, x, y);
813
899
  }
814
- #ifndef MRB_WITHOUT_FLOAT
900
+ #ifndef MRB_NO_FLOAT
815
901
  if (mrb_float_p(x)) {
816
902
  return mrb_float_value(mrb, mrb_float(x) * mrb_to_flo(mrb, y));
817
903
  }
@@ -831,7 +917,7 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
831
917
  */
832
918
 
833
919
  static mrb_value
834
- fix_mul(mrb_state *mrb, mrb_value x)
920
+ int_mul(mrb_state *mrb, mrb_value x)
835
921
  {
836
922
  mrb_value y = mrb_get_arg1(mrb);
837
923
 
@@ -841,29 +927,23 @@ fix_mul(mrb_state *mrb, mrb_value x)
841
927
  static void
842
928
  fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
843
929
  {
844
- mrb_int div, mod;
845
-
846
- /* TODO: add mrb_assert(y != 0) to make sure */
847
-
848
- if (y < 0) {
849
- if (x < 0)
850
- div = -x / -y;
851
- else
852
- div = - (x / -y);
930
+ if (y == 0) {
931
+ int_zerodiv(mrb);
853
932
  }
854
- else {
855
- if (x < 0)
856
- div = - (-x / y);
857
- else
858
- div = x / y;
933
+ else if(x == MRB_INT_MIN && y == -1) {
934
+ int_overflow(mrb, "division");
859
935
  }
860
- mod = x - div*y;
861
- if ((mod < 0 && y > 0) || (mod > 0 && y < 0)) {
862
- mod += y;
863
- div -= 1;
936
+ else {
937
+ mrb_int div = x / y;
938
+ mrb_int mod = x - div * y;
939
+
940
+ if ((x ^ y) < 0 && x != div * y) {
941
+ mod += y;
942
+ div -= 1;
943
+ }
944
+ if (divp) *divp = div;
945
+ if (modp) *modp = mod;
864
946
  }
865
- if (divp) *divp = div;
866
- if (modp) *modp = mod;
867
947
  }
868
948
 
869
949
  /* 15.2.8.3.5 */
@@ -877,29 +957,19 @@ fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
877
957
  */
878
958
 
879
959
  static mrb_value
880
- fix_mod(mrb_state *mrb, mrb_value x)
960
+ int_mod(mrb_state *mrb, mrb_value x)
881
961
  {
882
962
  mrb_value y = mrb_get_arg1(mrb);
883
963
  mrb_int a, b;
884
964
 
885
- a = mrb_fixnum(x);
886
- if (mrb_fixnum_p(y) && a != MRB_INT_MIN && (b=mrb_fixnum(y)) != MRB_INT_MIN) {
965
+ a = mrb_integer(x);
966
+ if (mrb_integer_p(y) && a != MRB_INT_MIN && (b=mrb_integer(y)) != MRB_INT_MIN) {
887
967
  mrb_int mod;
888
968
 
889
- if (b == 0) {
890
- #ifdef MRB_WITHOUT_FLOAT
891
- /* ZeroDivisionError */
892
- return mrb_fixnum_value(0);
893
- #else
894
- if (a > 0) return mrb_float_value(mrb, INFINITY);
895
- if (a < 0) return mrb_float_value(mrb, INFINITY);
896
- return mrb_float_value(mrb, NAN);
897
- #endif
898
- }
899
969
  fixdivmod(mrb, a, b, NULL, &mod);
900
970
  return mrb_fixnum_value(mod);
901
971
  }
902
- #ifdef MRB_WITHOUT_FLOAT
972
+ #ifdef MRB_NO_FLOAT
903
973
  mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
904
974
  #else
905
975
  else {
@@ -918,42 +988,32 @@ fix_mod(mrb_state *mrb, mrb_value x)
918
988
  * See <code>Numeric#divmod</code>.
919
989
  */
920
990
  static mrb_value
921
- fix_divmod(mrb_state *mrb, mrb_value x)
991
+ int_divmod(mrb_state *mrb, mrb_value x)
922
992
  {
923
993
  mrb_value y = mrb_get_arg1(mrb);
924
994
 
925
- if (mrb_fixnum_p(y)) {
995
+ if (mrb_integer_p(y)) {
926
996
  mrb_int div, mod;
927
997
 
928
- if (mrb_fixnum(y) == 0) {
929
- #ifdef MRB_WITHOUT_FLOAT
930
- return mrb_assoc_new(mrb, mrb_fixnum_value(0), mrb_fixnum_value(0));
931
- #else
932
- return mrb_assoc_new(mrb, ((mrb_fixnum(x) == 0) ?
933
- mrb_float_value(mrb, NAN):
934
- mrb_float_value(mrb, INFINITY)),
935
- mrb_float_value(mrb, NAN));
936
- #endif
937
- }
938
- fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod);
939
- return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod));
998
+ fixdivmod(mrb, mrb_integer(x), mrb_integer(y), &div, &mod);
999
+ return mrb_assoc_new(mrb, mrb_int_value(mrb, div), mrb_int_value(mrb, mod));
940
1000
  }
941
- #ifdef MRB_WITHOUT_FLOAT
1001
+ #ifdef MRB_NO_FLOAT
942
1002
  mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
943
1003
  #else
944
1004
  else {
945
1005
  mrb_float div, mod;
946
1006
  mrb_value a, b;
947
1007
 
948
- flodivmod(mrb, (mrb_float)mrb_fixnum(x), mrb_to_flo(mrb, y), &div, &mod);
949
- a = mrb_int_value(mrb, div);
1008
+ flodivmod(mrb, (mrb_float)mrb_integer(x), mrb_to_flo(mrb, y), &div, &mod);
1009
+ a = mrb_int_value(mrb, (mrb_int)div);
950
1010
  b = mrb_float_value(mrb, mod);
951
1011
  return mrb_assoc_new(mrb, a, b);
952
1012
  }
953
1013
  #endif
954
1014
  }
955
1015
 
956
- #ifndef MRB_WITHOUT_FLOAT
1016
+ #ifndef MRB_NO_FLOAT
957
1017
  static mrb_value
958
1018
  flo_divmod(mrb_state *mrb, mrb_value x)
959
1019
  {
@@ -962,7 +1022,7 @@ flo_divmod(mrb_state *mrb, mrb_value x)
962
1022
  mrb_value a, b;
963
1023
 
964
1024
  flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
965
- a = mrb_int_value(mrb, div);
1025
+ a = mrb_int_value(mrb, (mrb_int)div);
966
1026
  b = mrb_float_value(mrb, mod);
967
1027
  return mrb_assoc_new(mrb, a, b);
968
1028
  }
@@ -981,16 +1041,16 @@ flo_divmod(mrb_state *mrb, mrb_value x)
981
1041
  */
982
1042
 
983
1043
  static mrb_value
984
- fix_equal(mrb_state *mrb, mrb_value x)
1044
+ int_equal(mrb_state *mrb, mrb_value x)
985
1045
  {
986
1046
  mrb_value y = mrb_get_arg1(mrb);
987
1047
 
988
1048
  switch (mrb_type(y)) {
989
- case MRB_TT_FIXNUM:
990
- return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y));
991
- #ifndef MRB_WITHOUT_FLOAT
1049
+ case MRB_TT_INTEGER:
1050
+ return mrb_bool_value(mrb_integer(x) == mrb_integer(y));
1051
+ #ifndef MRB_NO_FLOAT
992
1052
  case MRB_TT_FLOAT:
993
- return mrb_bool_value((mrb_float)mrb_fixnum(x) == mrb_float(y));
1053
+ return mrb_bool_value((mrb_float)mrb_integer(x) == mrb_float(y));
994
1054
  #endif
995
1055
  default:
996
1056
  return mrb_false_value();
@@ -1009,24 +1069,24 @@ fix_equal(mrb_state *mrb, mrb_value x)
1009
1069
  */
1010
1070
 
1011
1071
  static mrb_value
1012
- fix_rev(mrb_state *mrb, mrb_value num)
1072
+ int_rev(mrb_state *mrb, mrb_value num)
1013
1073
  {
1014
- mrb_int val = mrb_fixnum(num);
1074
+ mrb_int val = mrb_integer(num);
1015
1075
 
1016
- return mrb_fixnum_value(~val);
1076
+ return mrb_int_value(mrb, ~val);
1017
1077
  }
1018
1078
 
1019
- #ifdef MRB_WITHOUT_FLOAT
1079
+ #ifdef MRB_NO_FLOAT
1020
1080
  #define bit_op(x,y,op1,op2) do {\
1021
- return mrb_fixnum_value(mrb_fixnum(x) op2 mrb_fixnum(y));\
1081
+ return mrb_int_value(mrb, (mrb_integer(x) op2 mrb_integer(y)));\
1022
1082
  } while(0)
1023
1083
  #else
1024
1084
  static mrb_value flo_and(mrb_state *mrb, mrb_value x);
1025
1085
  static mrb_value flo_or(mrb_state *mrb, mrb_value x);
1026
1086
  static mrb_value flo_xor(mrb_state *mrb, mrb_value x);
1027
1087
  #define bit_op(x,y,op1,op2) do {\
1028
- if (mrb_fixnum_p(y)) return mrb_fixnum_value(mrb_fixnum(x) op2 mrb_fixnum(y));\
1029
- return flo_ ## op1(mrb, mrb_float_value(mrb, (mrb_float)mrb_fixnum(x)));\
1088
+ if (mrb_integer_p(y)) return mrb_int_value(mrb, (mrb_integer(x) op2 mrb_integer(y))); \
1089
+ return flo_ ## op1(mrb, mrb_float_value(mrb, (mrb_float)mrb_integer(x)));\
1030
1090
  } while(0)
1031
1091
  #endif
1032
1092
 
@@ -1039,7 +1099,7 @@ static mrb_value flo_xor(mrb_state *mrb, mrb_value x);
1039
1099
  */
1040
1100
 
1041
1101
  static mrb_value
1042
- fix_and(mrb_state *mrb, mrb_value x)
1102
+ int_and(mrb_state *mrb, mrb_value x)
1043
1103
  {
1044
1104
  mrb_value y = mrb_get_arg1(mrb);
1045
1105
 
@@ -1055,7 +1115,7 @@ fix_and(mrb_state *mrb, mrb_value x)
1055
1115
  */
1056
1116
 
1057
1117
  static mrb_value
1058
- fix_or(mrb_state *mrb, mrb_value x)
1118
+ int_or(mrb_state *mrb, mrb_value x)
1059
1119
  {
1060
1120
  mrb_value y = mrb_get_arg1(mrb);
1061
1121
 
@@ -1071,7 +1131,7 @@ fix_or(mrb_state *mrb, mrb_value x)
1071
1131
  */
1072
1132
 
1073
1133
  static mrb_value
1074
- fix_xor(mrb_state *mrb, mrb_value x)
1134
+ int_xor(mrb_state *mrb, mrb_value x)
1075
1135
  {
1076
1136
  mrb_value y = mrb_get_arg1(mrb);
1077
1137
 
@@ -1083,61 +1143,34 @@ fix_xor(mrb_state *mrb, mrb_value x)
1083
1143
  static mrb_value
1084
1144
  lshift(mrb_state *mrb, mrb_int val, mrb_int width)
1085
1145
  {
1086
- if (width < 0) { /* mrb_int overflow */
1087
- #ifdef MRB_WITHOUT_FLOAT
1088
- return mrb_fixnum_value(0);
1089
- #else
1090
- return mrb_float_value(mrb, INFINITY);
1091
- #endif
1092
- }
1146
+ mrb_assert(width >= 0);
1093
1147
  if (val > 0) {
1094
1148
  if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
1095
1149
  (val > (MRB_INT_MAX >> width))) {
1096
- #ifdef MRB_WITHOUT_FLOAT
1097
- return mrb_fixnum_value(-1);
1098
- #else
1099
- goto bit_overflow;
1100
- #endif
1150
+ int_overflow(mrb, "bit shift");
1101
1151
  }
1102
- return mrb_fixnum_value(val << width);
1152
+ return mrb_int_value(mrb, val << width);
1103
1153
  }
1104
1154
  else {
1105
1155
  if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
1106
1156
  (val <= (MRB_INT_MIN >> width))) {
1107
- #ifdef MRB_WITHOUT_FLOAT
1108
- return mrb_fixnum_value(0);
1109
- #else
1110
- goto bit_overflow;
1111
- #endif
1157
+ int_overflow(mrb, "bit shift");
1112
1158
  }
1113
- return mrb_fixnum_value(val * ((mrb_int)1 << width));
1159
+ return mrb_int_value(mrb, (val * ((mrb_int)1 << width)));
1114
1160
  }
1115
-
1116
- #ifndef MRB_WITHOUT_FLOAT
1117
- bit_overflow:
1118
- {
1119
- mrb_float f = (mrb_float)val;
1120
- while (width--) {
1121
- f *= 2;
1122
- }
1123
- return mrb_float_value(mrb, f);
1124
- }
1125
- #endif
1126
1161
  }
1127
1162
 
1128
1163
  static mrb_value
1129
- rshift(mrb_int val, mrb_int width)
1164
+ rshift(mrb_state *mrb, mrb_int val, mrb_int width)
1130
1165
  {
1131
- if (width < 0) { /* mrb_int overflow */
1132
- return mrb_fixnum_value(0);
1133
- }
1166
+ mrb_assert(width >= 0);
1134
1167
  if (width >= NUMERIC_SHIFT_WIDTH_MAX) {
1135
1168
  if (val < 0) {
1136
1169
  return mrb_fixnum_value(-1);
1137
1170
  }
1138
1171
  return mrb_fixnum_value(0);
1139
1172
  }
1140
- return mrb_fixnum_value(val >> width);
1173
+ return mrb_int_value(mrb, val >> width);
1141
1174
  }
1142
1175
 
1143
1176
  /* 15.2.8.3.12 */
@@ -1149,7 +1182,7 @@ rshift(mrb_int val, mrb_int width)
1149
1182
  */
1150
1183
 
1151
1184
  static mrb_value
1152
- fix_lshift(mrb_state *mrb, mrb_value x)
1185
+ int_lshift(mrb_state *mrb, mrb_value x)
1153
1186
  {
1154
1187
  mrb_int width, val;
1155
1188
 
@@ -1157,10 +1190,11 @@ fix_lshift(mrb_state *mrb, mrb_value x)
1157
1190
  if (width == 0) {
1158
1191
  return x;
1159
1192
  }
1160
- val = mrb_fixnum(x);
1193
+ val = mrb_integer(x);
1161
1194
  if (val == 0) return x;
1162
1195
  if (width < 0) {
1163
- return rshift(val, -width);
1196
+ if (width == MRB_INT_MIN) return rshift(mrb, val, MRB_INT_BIT);
1197
+ return rshift(mrb, val, -width);
1164
1198
  }
1165
1199
  return lshift(mrb, val, width);
1166
1200
  }
@@ -1174,7 +1208,7 @@ fix_lshift(mrb_state *mrb, mrb_value x)
1174
1208
  */
1175
1209
 
1176
1210
  static mrb_value
1177
- fix_rshift(mrb_state *mrb, mrb_value x)
1211
+ int_rshift(mrb_state *mrb, mrb_value x)
1178
1212
  {
1179
1213
  mrb_int width, val;
1180
1214
 
@@ -1182,12 +1216,13 @@ fix_rshift(mrb_state *mrb, mrb_value x)
1182
1216
  if (width == 0) {
1183
1217
  return x;
1184
1218
  }
1185
- val = mrb_fixnum(x);
1219
+ val = mrb_integer(x);
1186
1220
  if (val == 0) return x;
1187
1221
  if (width < 0) {
1222
+ if (width == MRB_INT_MIN) int_overflow(mrb, "bit shift");
1188
1223
  return lshift(mrb, val, -width);
1189
1224
  }
1190
- return rshift(val, width);
1225
+ return rshift(mrb, val, width);
1191
1226
  }
1192
1227
 
1193
1228
  /* 15.2.8.3.23 */
@@ -1199,11 +1234,11 @@ fix_rshift(mrb_state *mrb, mrb_value x)
1199
1234
  *
1200
1235
  */
1201
1236
 
1202
- #ifndef MRB_WITHOUT_FLOAT
1237
+ #ifndef MRB_NO_FLOAT
1203
1238
  static mrb_value
1204
- fix_to_f(mrb_state *mrb, mrb_value num)
1239
+ int_to_f(mrb_state *mrb, mrb_value num)
1205
1240
  {
1206
- return mrb_float_value(mrb, (mrb_float)mrb_fixnum(num));
1241
+ return mrb_float_value(mrb, (mrb_float)mrb_integer(num));
1207
1242
  }
1208
1243
 
1209
1244
  /*
@@ -1240,7 +1275,7 @@ mrb_flo_to_fixnum(mrb_state *mrb, mrb_value x)
1240
1275
  mrb_raisef(mrb, E_RANGE_ERROR, "number (%v) too big for integer", x);
1241
1276
  }
1242
1277
  }
1243
- return mrb_fixnum_value(z);
1278
+ return mrb_int_value(mrb, z);
1244
1279
  }
1245
1280
  #endif
1246
1281
 
@@ -1249,20 +1284,18 @@ fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1249
1284
  {
1250
1285
  mrb_int a;
1251
1286
 
1252
- a = mrb_fixnum(x);
1253
- if (mrb_fixnum_p(y)) {
1287
+ a = mrb_integer(x);
1288
+ if (mrb_integer_p(y)) {
1254
1289
  mrb_int b, c;
1255
1290
 
1256
1291
  if (a == 0) return y;
1257
- b = mrb_fixnum(y);
1292
+ b = mrb_integer(y);
1258
1293
  if (mrb_int_add_overflow(a, b, &c)) {
1259
- #ifndef MRB_WITHOUT_FLOAT
1260
- return mrb_float_value(mrb, (mrb_float)a + (mrb_float)b);
1261
- #endif
1294
+ int_overflow(mrb, "addition");
1262
1295
  }
1263
- return mrb_fixnum_value(c);
1296
+ return mrb_int_value(mrb, c);
1264
1297
  }
1265
- #ifdef MRB_WITHOUT_FLOAT
1298
+ #ifdef MRB_NO_FLOAT
1266
1299
  mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
1267
1300
  #else
1268
1301
  return mrb_float_value(mrb, (mrb_float)a + mrb_to_flo(mrb, y));
@@ -1272,10 +1305,10 @@ fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1272
1305
  MRB_API mrb_value
1273
1306
  mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1274
1307
  {
1275
- if (mrb_fixnum_p(x)) {
1308
+ if (mrb_integer_p(x)) {
1276
1309
  return fixnum_plus(mrb, x, y);
1277
1310
  }
1278
- #ifndef MRB_WITHOUT_FLOAT
1311
+ #ifndef MRB_NO_FLOAT
1279
1312
  if (mrb_float_p(x)) {
1280
1313
  return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
1281
1314
  }
@@ -1294,7 +1327,7 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
1294
1327
  * result.
1295
1328
  */
1296
1329
  static mrb_value
1297
- fix_plus(mrb_state *mrb, mrb_value self)
1330
+ int_plus(mrb_state *mrb, mrb_value self)
1298
1331
  {
1299
1332
  mrb_value other = mrb_get_arg1(mrb);
1300
1333
 
@@ -1306,19 +1339,17 @@ fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1306
1339
  {
1307
1340
  mrb_int a;
1308
1341
 
1309
- a = mrb_fixnum(x);
1310
- if (mrb_fixnum_p(y)) {
1342
+ a = mrb_integer(x);
1343
+ if (mrb_integer_p(y)) {
1311
1344
  mrb_int b, c;
1312
1345
 
1313
- b = mrb_fixnum(y);
1346
+ b = mrb_integer(y);
1314
1347
  if (mrb_int_sub_overflow(a, b, &c)) {
1315
- #ifndef MRB_WITHOUT_FLOAT
1316
- return mrb_float_value(mrb, (mrb_float)a - (mrb_float)b);
1317
- #endif
1348
+ int_overflow(mrb, "subtraction");
1318
1349
  }
1319
- return mrb_fixnum_value(c);
1350
+ return mrb_int_value(mrb, c);
1320
1351
  }
1321
- #ifdef MRB_WITHOUT_FLOAT
1352
+ #ifdef MRB_NO_FLOAT
1322
1353
  mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
1323
1354
  #else
1324
1355
  return mrb_float_value(mrb, (mrb_float)a - mrb_to_flo(mrb, y));
@@ -1328,10 +1359,10 @@ fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1328
1359
  MRB_API mrb_value
1329
1360
  mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1330
1361
  {
1331
- if (mrb_fixnum_p(x)) {
1362
+ if (mrb_integer_p(x)) {
1332
1363
  return fixnum_minus(mrb, x, y);
1333
1364
  }
1334
- #ifndef MRB_WITHOUT_FLOAT
1365
+ #ifndef MRB_NO_FLOAT
1335
1366
  if (mrb_float_p(x)) {
1336
1367
  return mrb_float_value(mrb, mrb_float(x) - mrb_to_flo(mrb, y));
1337
1368
  }
@@ -1351,7 +1382,7 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
1351
1382
  * result.
1352
1383
  */
1353
1384
  static mrb_value
1354
- fix_minus(mrb_state *mrb, mrb_value self)
1385
+ int_minus(mrb_state *mrb, mrb_value self)
1355
1386
  {
1356
1387
  mrb_value other = mrb_get_arg1(mrb);
1357
1388
 
@@ -1364,7 +1395,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base)
1364
1395
  {
1365
1396
  char buf[MRB_INT_BIT+1];
1366
1397
  char *b = buf + sizeof buf;
1367
- mrb_int val = mrb_fixnum(x);
1398
+ mrb_int val = mrb_integer(x);
1368
1399
  mrb_value str;
1369
1400
 
1370
1401
  if (base < 2 || 36 < base) {
@@ -1408,7 +1439,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base)
1408
1439
  *
1409
1440
  */
1410
1441
  static mrb_value
1411
- fix_to_s(mrb_state *mrb, mrb_value self)
1442
+ int_to_s(mrb_state *mrb, mrb_value self)
1412
1443
  {
1413
1444
  mrb_int base = 10;
1414
1445
 
@@ -1420,26 +1451,26 @@ fix_to_s(mrb_state *mrb, mrb_value self)
1420
1451
  static mrb_int
1421
1452
  cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
1422
1453
  {
1423
- #ifdef MRB_WITHOUT_FLOAT
1454
+ #ifdef MRB_NO_FLOAT
1424
1455
  mrb_int x, y;
1425
1456
  #else
1426
1457
  mrb_float x, y;
1427
1458
  #endif
1428
1459
 
1429
- #ifdef MRB_WITHOUT_FLOAT
1430
- x = mrb_fixnum(v1);
1460
+ #ifdef MRB_NO_FLOAT
1461
+ x = mrb_integer(v1);
1431
1462
  #else
1432
1463
  x = mrb_to_flo(mrb, v1);
1433
1464
  #endif
1434
1465
  switch (mrb_type(v2)) {
1435
- case MRB_TT_FIXNUM:
1436
- #ifdef MRB_WITHOUT_FLOAT
1437
- y = mrb_fixnum(v2);
1466
+ case MRB_TT_INTEGER:
1467
+ #ifdef MRB_NO_FLOAT
1468
+ y = mrb_integer(v2);
1438
1469
  #else
1439
- y = (mrb_float)mrb_fixnum(v2);
1470
+ y = (mrb_float)mrb_integer(v2);
1440
1471
  #endif
1441
1472
  break;
1442
- #ifndef MRB_WITHOUT_FLOAT
1473
+ #ifndef MRB_NO_FLOAT
1443
1474
  case MRB_TT_FLOAT:
1444
1475
  y = mrb_float(v2);
1445
1476
  break;
@@ -1469,7 +1500,7 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
1469
1500
  * not comparable, it returns nil instead of raising an exception.
1470
1501
  */
1471
1502
  static mrb_value
1472
- integral_cmp(mrb_state *mrb, mrb_value self)
1503
+ num_cmp(mrb_state *mrb, mrb_value self)
1473
1504
  {
1474
1505
  mrb_value other = mrb_get_arg1(mrb);
1475
1506
  mrb_int n;
@@ -1486,7 +1517,7 @@ cmperr(mrb_state *mrb, mrb_value v1, mrb_value v2)
1486
1517
  }
1487
1518
 
1488
1519
  static mrb_value
1489
- integral_lt(mrb_state *mrb, mrb_value self)
1520
+ num_lt(mrb_state *mrb, mrb_value self)
1490
1521
  {
1491
1522
  mrb_value other = mrb_get_arg1(mrb);
1492
1523
  mrb_int n;
@@ -1498,7 +1529,7 @@ integral_lt(mrb_state *mrb, mrb_value self)
1498
1529
  }
1499
1530
 
1500
1531
  static mrb_value
1501
- integral_le(mrb_state *mrb, mrb_value self)
1532
+ num_le(mrb_state *mrb, mrb_value self)
1502
1533
  {
1503
1534
  mrb_value other = mrb_get_arg1(mrb);
1504
1535
  mrb_int n;
@@ -1510,7 +1541,7 @@ integral_le(mrb_state *mrb, mrb_value self)
1510
1541
  }
1511
1542
 
1512
1543
  static mrb_value
1513
- integral_gt(mrb_state *mrb, mrb_value self)
1544
+ num_gt(mrb_state *mrb, mrb_value self)
1514
1545
  {
1515
1546
  mrb_value other = mrb_get_arg1(mrb);
1516
1547
  mrb_int n;
@@ -1522,7 +1553,7 @@ integral_gt(mrb_state *mrb, mrb_value self)
1522
1553
  }
1523
1554
 
1524
1555
  static mrb_value
1525
- integral_ge(mrb_state *mrb, mrb_value self)
1556
+ num_ge(mrb_state *mrb, mrb_value self)
1526
1557
  {
1527
1558
  mrb_value other = mrb_get_arg1(mrb);
1528
1559
  mrb_int n;
@@ -1539,7 +1570,7 @@ mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
1539
1570
  mrb_value v;
1540
1571
 
1541
1572
  switch (mrb_type(obj1)) {
1542
- case MRB_TT_FIXNUM:
1573
+ case MRB_TT_INTEGER:
1543
1574
  case MRB_TT_FLOAT:
1544
1575
  return cmpnum(mrb, obj1, obj2);
1545
1576
  case MRB_TT_STRING:
@@ -1547,10 +1578,10 @@ mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
1547
1578
  return -2;
1548
1579
  return mrb_str_cmp(mrb, obj1, obj2);
1549
1580
  default:
1550
- v = mrb_funcall(mrb, obj1, "<=>", 1, obj2);
1551
- if (mrb_nil_p(v) || !mrb_fixnum_p(v))
1581
+ v = mrb_funcall_id(mrb, obj1, MRB_SYM(cmp), 1, obj2);
1582
+ if (mrb_nil_p(v) || !mrb_integer_p(v))
1552
1583
  return -2;
1553
- return mrb_fixnum(v);
1584
+ return mrb_integer(v);
1554
1585
  }
1555
1586
  }
1556
1587
 
@@ -1574,7 +1605,7 @@ num_infinite_p(mrb_state *mrb, mrb_value self)
1574
1605
  * Returns a new float which is the sum of <code>float</code>
1575
1606
  * and <code>other</code>.
1576
1607
  */
1577
- #ifndef MRB_WITHOUT_FLOAT
1608
+ #ifndef MRB_NO_FLOAT
1578
1609
  static mrb_value
1579
1610
  flo_plus(mrb_state *mrb, mrb_value x)
1580
1611
  {
@@ -1588,72 +1619,81 @@ flo_plus(mrb_state *mrb, mrb_value x)
1588
1619
  void
1589
1620
  mrb_init_numeric(mrb_state *mrb)
1590
1621
  {
1591
- struct RClass *numeric, *integer, *fixnum, *integral;
1592
- #ifndef MRB_WITHOUT_FLOAT
1622
+ struct RClass *numeric, *integer;
1623
+ #ifndef MRB_NO_FLOAT
1593
1624
  struct RClass *fl;
1594
1625
  #endif
1595
1626
 
1596
- integral = mrb_define_module(mrb, "Integral");
1597
- mrb_define_method(mrb, integral,"**", integral_pow, MRB_ARGS_REQ(1));
1598
- mrb_define_method(mrb, integral,"/", integral_div, MRB_ARGS_REQ(1)); /* 15.2.{8,9}.3.6 */
1599
- mrb_define_method(mrb, integral,"quo", integral_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
1600
- mrb_define_method(mrb, integral,"div", integral_idiv, MRB_ARGS_REQ(1));
1601
- mrb_define_method(mrb, integral,"<=>", integral_cmp, MRB_ARGS_REQ(1)); /* 15.2.{8,9}.3.1 */
1602
- mrb_define_method(mrb, integral,"<", integral_lt, MRB_ARGS_REQ(1));
1603
- mrb_define_method(mrb, integral,"<=", integral_le, MRB_ARGS_REQ(1));
1604
- mrb_define_method(mrb, integral,">", integral_gt, MRB_ARGS_REQ(1));
1605
- mrb_define_method(mrb, integral,">=", integral_ge, MRB_ARGS_REQ(1));
1606
- mrb_define_method(mrb, integral,"__coerce_step_counter", integral_coerce_step_counter, MRB_ARGS_REQ(2));
1607
-
1608
1627
  /* Numeric Class */
1609
1628
  numeric = mrb_define_class(mrb, "Numeric", mrb->object_class); /* 15.2.7 */
1610
1629
  mrb_define_method(mrb, numeric, "finite?", num_finite_p, MRB_ARGS_NONE());
1611
1630
  mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE());
1612
1631
 
1613
1632
  /* Integer Class */
1614
- integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
1615
- MRB_SET_INSTANCE_TT(integer, MRB_TT_FIXNUM);
1633
+ mrb->integer_class = integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
1634
+ MRB_SET_INSTANCE_TT(integer, MRB_TT_INTEGER);
1616
1635
  mrb_undef_class_method(mrb, integer, "new");
1636
+ mrb_define_method(mrb, integer, "**", int_pow, MRB_ARGS_REQ(1));
1637
+ mrb_define_method(mrb, integer, "/", int_div, MRB_ARGS_REQ(1)); /* 15.2.8.3.6 */
1638
+ mrb_define_method(mrb, integer, "quo", int_quo, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
1639
+ mrb_define_method(mrb, integer, "div", int_div, MRB_ARGS_REQ(1));
1640
+ mrb_define_method(mrb, integer, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */
1641
+ mrb_define_method(mrb, integer, "<", num_lt, MRB_ARGS_REQ(1));
1642
+ mrb_define_method(mrb, integer, "<=", num_le, MRB_ARGS_REQ(1));
1643
+ mrb_define_method(mrb, integer, ">", num_gt, MRB_ARGS_REQ(1));
1644
+ mrb_define_method(mrb, integer, ">=", num_ge, MRB_ARGS_REQ(1));
1645
+
1617
1646
  mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */
1618
1647
  mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE());
1619
- #ifndef MRB_WITHOUT_FLOAT
1620
- mrb_define_method(mrb, integer, "ceil", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.8 (x) */
1621
- mrb_define_method(mrb, integer, "floor", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.10 (x) */
1622
- mrb_define_method(mrb, integer, "round", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.12 (x) */
1623
- mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.15 (x) */
1648
+ #ifndef MRB_NO_FLOAT
1649
+ mrb_define_method(mrb, integer, "ceil", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.14 */
1650
+ mrb_define_method(mrb, integer, "floor", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.17 */
1651
+ mrb_define_method(mrb, integer, "round", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.20 */
1652
+ mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.26 */
1624
1653
  #endif
1625
1654
 
1626
- /* Fixnum Class */
1627
- mrb->fixnum_class = fixnum = mrb_define_class(mrb, "Fixnum", integer);
1628
- mrb_define_method(mrb, fixnum, "+", fix_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */
1629
- mrb_define_method(mrb, fixnum, "-", fix_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */
1630
- mrb_define_method(mrb, fixnum, "*", fix_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */
1631
- mrb_define_method(mrb, fixnum, "%", fix_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */
1632
- mrb_define_method(mrb, fixnum, "==", fix_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */
1633
- mrb_define_method(mrb, fixnum, "~", fix_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */
1634
- mrb_define_method(mrb, fixnum, "&", fix_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */
1635
- mrb_define_method(mrb, fixnum, "|", fix_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */
1636
- mrb_define_method(mrb, fixnum, "^", fix_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */
1637
- mrb_define_method(mrb, fixnum, "<<", fix_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */
1638
- mrb_define_method(mrb, fixnum, ">>", fix_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */
1639
- mrb_define_method(mrb, fixnum, "eql?", fix_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */
1640
- #ifndef MRB_WITHOUT_FLOAT
1641
- mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
1655
+ mrb_define_method(mrb, integer, "+", int_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */
1656
+ mrb_define_method(mrb, integer, "-", int_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */
1657
+ mrb_define_method(mrb, integer, "*", int_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */
1658
+ mrb_define_method(mrb, integer, "%", int_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */
1659
+ mrb_define_method(mrb, integer, "==", int_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */
1660
+ mrb_define_method(mrb, integer, "~", int_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */
1661
+ mrb_define_method(mrb, integer, "&", int_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */
1662
+ mrb_define_method(mrb, integer, "|", int_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */
1663
+ mrb_define_method(mrb, integer, "^", int_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */
1664
+ mrb_define_method(mrb, integer, "<<", int_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */
1665
+ mrb_define_method(mrb, integer, ">>", int_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */
1666
+ mrb_define_method(mrb, integer, "eql?", int_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */
1667
+ #ifndef MRB_NO_FLOAT
1668
+ mrb_define_method(mrb, integer, "to_f", int_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
1642
1669
  #endif
1643
- mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
1644
- mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1));
1645
- mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
1670
+ mrb_define_method(mrb, integer, "to_s", int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
1671
+ mrb_define_method(mrb, integer, "inspect", int_to_s, MRB_ARGS_OPT(1));
1672
+ mrb_define_method(mrb, integer, "divmod", int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
1673
+ mrb_define_method(mrb, integer, "__coerce_step_counter", coerce_step_counter, MRB_ARGS_REQ(2));
1674
+
1675
+ /* Fixnum Class for compatibility */
1676
+ mrb_define_const(mrb, mrb->object_class, "Fixnum", mrb_obj_value(integer));
1646
1677
 
1647
- #ifndef MRB_WITHOUT_FLOAT
1678
+ #ifndef MRB_NO_FLOAT
1648
1679
  /* Float Class */
1649
1680
  mrb->float_class = fl = mrb_define_class(mrb, "Float", numeric); /* 15.2.9 */
1650
1681
  MRB_SET_INSTANCE_TT(fl, MRB_TT_FLOAT);
1651
1682
  mrb_undef_class_method(mrb, fl, "new");
1652
- mrb_define_method(mrb, fl, "+", flo_plus, MRB_ARGS_REQ(1)); /* 15.2.9.3.1 */
1653
- mrb_define_method(mrb, fl, "-", flo_minus, MRB_ARGS_REQ(1)); /* 15.2.9.3.2 */
1654
- mrb_define_method(mrb, fl, "*", flo_mul, MRB_ARGS_REQ(1)); /* 15.2.9.3.3 */
1655
- mrb_define_method(mrb, fl, "%", flo_mod, MRB_ARGS_REQ(1)); /* 15.2.9.3.5 */
1656
- mrb_define_method(mrb, fl, "==", flo_eq, MRB_ARGS_REQ(1)); /* 15.2.9.3.7 */
1683
+ mrb_define_method(mrb, fl, "**", flo_pow, MRB_ARGS_REQ(1));
1684
+ mrb_define_method(mrb, fl, "/", flo_div, MRB_ARGS_REQ(1)); /* 15.2.9.3.6 */
1685
+ mrb_define_method(mrb, fl, "quo", flo_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
1686
+ mrb_define_method(mrb, fl, "div", flo_idiv, MRB_ARGS_REQ(1));
1687
+ mrb_define_method(mrb, fl, "+", flo_plus, MRB_ARGS_REQ(1)); /* 15.2.9.3.3 */
1688
+ mrb_define_method(mrb, fl, "-", flo_minus, MRB_ARGS_REQ(1)); /* 15.2.9.3.4 */
1689
+ mrb_define_method(mrb, fl, "*", flo_mul, MRB_ARGS_REQ(1)); /* 15.2.9.3.5 */
1690
+ mrb_define_method(mrb, fl, "%", flo_mod, MRB_ARGS_REQ(1)); /* 15.2.9.3.7 */
1691
+ mrb_define_method(mrb, fl, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.9.3.1 */
1692
+ mrb_define_method(mrb, fl, "<", num_lt, MRB_ARGS_REQ(1));
1693
+ mrb_define_method(mrb, fl, "<=", num_le, MRB_ARGS_REQ(1));
1694
+ mrb_define_method(mrb, fl, ">", num_gt, MRB_ARGS_REQ(1));
1695
+ mrb_define_method(mrb, fl, ">=", num_ge, MRB_ARGS_REQ(1));
1696
+ mrb_define_method(mrb, fl, "==", flo_eq, MRB_ARGS_REQ(1)); /* 15.2.9.3.2 */
1657
1697
  mrb_define_method(mrb, fl, "~", flo_rev, MRB_ARGS_NONE());
1658
1698
  mrb_define_method(mrb, fl, "&", flo_and, MRB_ARGS_REQ(1));
1659
1699
  mrb_define_method(mrb, fl, "|", flo_or, MRB_ARGS_REQ(1));
@@ -1677,12 +1717,10 @@ mrb_init_numeric(mrb_state *mrb)
1677
1717
  mrb_define_method(mrb, fl, "nan?", flo_nan_p, MRB_ARGS_NONE());
1678
1718
 
1679
1719
  #ifdef INFINITY
1680
- mrb_define_const(mrb, fl, "INFINITY", mrb_float_value(mrb, INFINITY));
1720
+ mrb_define_const_id(mrb, fl, MRB_SYM(INFINITY), mrb_float_value(mrb, INFINITY));
1681
1721
  #endif
1682
1722
  #ifdef NAN
1683
- mrb_define_const(mrb, fl, "NAN", mrb_float_value(mrb, NAN));
1723
+ mrb_define_const_id(mrb, fl, MRB_SYM(NAN), mrb_float_value(mrb, NAN));
1684
1724
  #endif
1685
-
1686
- mrb_include_module(mrb, fl, integral);
1687
1725
  #endif
1688
1726
  }