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
@@ -16,7 +16,7 @@
16
16
  #include <mruby/data.h>
17
17
 
18
18
  struct backtrace_location {
19
- int lineno;
19
+ int32_t lineno;
20
20
  mrb_sym method_id;
21
21
  const char *filename;
22
22
  };
@@ -26,7 +26,7 @@ typedef void (*each_backtrace_func)(mrb_state*, const struct backtrace_location*
26
26
  static const mrb_data_type bt_type = { "Backtrace", mrb_free };
27
27
 
28
28
  static void
29
- each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, mrb_code *pc0, each_backtrace_func func, void *data)
29
+ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtrace_func func, void *data)
30
30
  {
31
31
  ptrdiff_t i;
32
32
 
@@ -37,7 +37,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, mrb_code *pc0, each_backtrace_fu
37
37
  struct backtrace_location loc;
38
38
  mrb_callinfo *ci;
39
39
  mrb_irep *irep;
40
- mrb_code *pc;
40
+ const mrb_code *pc;
41
41
 
42
42
  ci = &mrb->c->cibase[i];
43
43
 
@@ -128,7 +128,7 @@ print_packed_backtrace(mrb_state *mrb, mrb_value packed)
128
128
  if (entry->method_id != 0) {
129
129
  const char *method_name;
130
130
 
131
- method_name = mrb_sym2name(mrb, entry->method_id);
131
+ method_name = mrb_sym_name(mrb, entry->method_id);
132
132
  fprintf(stream, ":in %s", method_name);
133
133
  mrb_gc_arena_restore(mrb, ai);
134
134
  }
@@ -246,12 +246,10 @@ mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace)
246
246
  mrb_value btline;
247
247
 
248
248
  if (entry->filename == NULL) continue;
249
- btline = mrb_format(mrb, "%S:%S",
250
- mrb_str_new_cstr(mrb, entry->filename),
251
- mrb_fixnum_value(entry->lineno));
249
+ btline = mrb_format(mrb, "%s:%d", entry->filename, entry->lineno);
252
250
  if (entry->method_id != 0) {
253
251
  mrb_str_cat_lit(mrb, btline, ":in ");
254
- mrb_str_cat_cstr(mrb, btline, mrb_sym2name(mrb, entry->method_id));
252
+ mrb_str_cat_cstr(mrb, btline, mrb_sym_name(mrb, entry->method_id));
255
253
  }
256
254
  mrb_ary_push(mrb, backtrace, btline);
257
255
  mrb_gc_arena_restore(mrb, ai);
@@ -7,6 +7,7 @@
7
7
  #include <stdarg.h>
8
8
  #include <mruby.h>
9
9
  #include <mruby/array.h>
10
+ #include <mruby/hash.h>
10
11
  #include <mruby/class.h>
11
12
  #include <mruby/numeric.h>
12
13
  #include <mruby/proc.h>
@@ -15,6 +16,7 @@
15
16
  #include <mruby/error.h>
16
17
  #include <mruby/data.h>
17
18
  #include <mruby/istruct.h>
19
+ #include <mruby/opcode.h>
18
20
 
19
21
  KHASH_DEFINE(mt, mrb_sym, mrb_method_t, TRUE, kh_int_hash_func, kh_int_hash_equal)
20
22
 
@@ -66,15 +68,26 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
66
68
  name = mrb_class_path(mrb, outer);
67
69
  if (mrb_nil_p(name)) { /* unnamed outer class */
68
70
  if (outer != mrb->object_class && outer != c) {
69
- mrb_obj_iv_set(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"),
70
- mrb_obj_value(outer));
71
+ mrb_obj_iv_set_force(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"),
72
+ mrb_obj_value(outer));
71
73
  }
72
74
  return;
73
75
  }
74
- mrb_str_cat_cstr(mrb, name, "::");
75
- mrb_str_cat_cstr(mrb, name, mrb_sym2name(mrb, id));
76
+ else {
77
+ mrb_int len;
78
+ const char *n = mrb_sym_name_len(mrb, id, &len);
79
+
80
+ mrb_str_cat_lit(mrb, name, "::");
81
+ mrb_str_cat(mrb, name, n, len);
82
+ }
76
83
  }
77
- mrb_obj_iv_set(mrb, (struct RObject*)c, nsym, name);
84
+ mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name);
85
+ }
86
+
87
+ mrb_bool
88
+ mrb_const_name_p(mrb_state *mrb, const char *name, mrb_int len)
89
+ {
90
+ return len > 0 && ISUPPER(name[0]) && mrb_ident_p(name+1, len-1);
78
91
  }
79
92
 
80
93
  static void
@@ -120,6 +133,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
120
133
  mrb_field_write_barrier(mrb, (struct RBasic*)o, (struct RBasic*)sc);
121
134
  mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)o);
122
135
  mrb_obj_iv_set(mrb, (struct RObject*)sc, mrb_intern_lit(mrb, "__attached__"), mrb_obj_value(o));
136
+ sc->flags |= o->flags & MRB_FL_OBJ_IS_FROZEN;
123
137
  }
124
138
 
125
139
  static mrb_value
@@ -129,7 +143,7 @@ class_name_str(mrb_state *mrb, struct RClass* c)
129
143
  if (mrb_nil_p(path)) {
130
144
  path = c->tt == MRB_TT_MODULE ? mrb_str_new_lit(mrb, "#<Module:") :
131
145
  mrb_str_new_lit(mrb, "#<Class:");
132
- mrb_str_concat(mrb, path, mrb_ptr_to_str(mrb, c));
146
+ mrb_str_cat_str(mrb, path, mrb_ptr_to_str(mrb, c));
133
147
  mrb_str_cat_lit(mrb, path, ">");
134
148
  }
135
149
  return path;
@@ -170,7 +184,7 @@ static void
170
184
  check_if_class_or_module(mrb_state *mrb, mrb_value obj)
171
185
  {
172
186
  if (!class_ptr_p(obj)) {
173
- mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class/module", mrb_inspect(mrb, obj));
187
+ mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a class/module", obj);
174
188
  }
175
189
  }
176
190
 
@@ -200,15 +214,15 @@ mrb_define_module(mrb_state *mrb, const char *name)
200
214
  return define_module(mrb, mrb_intern_cstr(mrb, name), mrb->object_class);
201
215
  }
202
216
 
203
- MRB_API struct RClass*
217
+ struct RClass*
204
218
  mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id)
205
219
  {
206
220
  check_if_class_or_module(mrb, outer);
207
221
  if (mrb_const_defined_at(mrb, outer, id)) {
208
222
  mrb_value old = mrb_const_get(mrb, outer, id);
209
223
 
210
- if (mrb_type(old) != MRB_TT_MODULE) {
211
- mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a module", mrb_inspect(mrb, old));
224
+ if (!mrb_module_p(old)) {
225
+ mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a module", old);
212
226
  }
213
227
  return mrb_class_ptr(old);
214
228
  }
@@ -241,9 +255,8 @@ define_class(mrb_state *mrb, mrb_sym name, struct RClass *super, struct RClass *
241
255
  c = class_from_sym(mrb, outer, name);
242
256
  MRB_CLASS_ORIGIN(c);
243
257
  if (super && mrb_class_real(c->super) != super) {
244
- mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for Class %S (%S not %S)",
245
- mrb_sym2str(mrb, name),
246
- mrb_obj_value(c->super), mrb_obj_value(super));
258
+ mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for Class %n (%C not %C)",
259
+ name, c->super, super);
247
260
  }
248
261
  return c;
249
262
  }
@@ -258,7 +271,7 @@ MRB_API struct RClass*
258
271
  mrb_define_class_id(mrb_state *mrb, mrb_sym name, struct RClass *super)
259
272
  {
260
273
  if (!super) {
261
- mrb_warn(mrb, "no super class for '%S', Object assumed", mrb_sym2str(mrb, name));
274
+ mrb_warn(mrb, "no super class for '%n', Object assumed", name);
262
275
  }
263
276
  return define_class(mrb, name, super, mrb->object_class);
264
277
  }
@@ -298,16 +311,15 @@ mrb_class_inherited(mrb_state *mrb, struct RClass *super, struct RClass *klass)
298
311
  }
299
312
  }
300
313
 
301
- MRB_API struct RClass*
314
+ struct RClass*
302
315
  mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id)
303
316
  {
304
317
  struct RClass *s;
305
318
  struct RClass *c;
306
319
 
307
320
  if (!mrb_nil_p(super)) {
308
- if (mrb_type(super) != MRB_TT_CLASS) {
309
- mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)",
310
- mrb_inspect(mrb, super));
321
+ if (!mrb_class_p(super)) {
322
+ mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%!v given)", super);
311
323
  }
312
324
  s = mrb_class_ptr(super);
313
325
  }
@@ -318,14 +330,14 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
318
330
  if (mrb_const_defined_at(mrb, outer, id)) {
319
331
  mrb_value old = mrb_const_get(mrb, outer, id);
320
332
 
321
- if (mrb_type(old) != MRB_TT_CLASS) {
322
- mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class", mrb_inspect(mrb, old));
333
+ if (!mrb_class_p(old)) {
334
+ mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a class", old);
323
335
  }
324
336
  c = mrb_class_ptr(old);
325
337
  if (s) {
326
338
  /* check super class */
327
339
  if (mrb_class_real(c->super) != s) {
328
- mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %S", old);
340
+ mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %v", old);
329
341
  }
330
342
  }
331
343
  return c;
@@ -375,7 +387,7 @@ mrb_exc_get(mrb_state *mrb, const char *name)
375
387
  mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class),
376
388
  mrb_intern_cstr(mrb, name));
377
389
 
378
- if (mrb_type(c) != MRB_TT_CLASS) {
390
+ if (!mrb_class_p(c)) {
379
391
  mrb_raise(mrb, mrb->eException_class, "exception corrupted");
380
392
  }
381
393
  exc = e = mrb_class_ptr(c);
@@ -403,7 +415,7 @@ mrb_module_get(mrb_state *mrb, const char *name)
403
415
  /*!
404
416
  * Defines a class under the namespace of \a outer.
405
417
  * \param outer a class which contains the new class.
406
- * \param id name of the new class
418
+ * \param name name of the new class
407
419
  * \param super a class from which the new class will derive.
408
420
  * NULL means \c Object class.
409
421
  * \return the created class
@@ -424,8 +436,7 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s
424
436
 
425
437
  #if 0
426
438
  if (!super) {
427
- mrb_warn(mrb, "no super class for '%S::%S', Object assumed",
428
- mrb_obj_value(outer), mrb_sym2str(mrb, id));
439
+ mrb_warn(mrb, "no super class for '%C::%n', Object assumed", outer, id);
429
440
  }
430
441
  #endif
431
442
  c = define_class(mrb, id, super, outer);
@@ -441,12 +452,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
441
452
  MRB_CLASS_ORIGIN(c);
442
453
  h = c->mt;
443
454
 
444
- if (MRB_FROZEN_P(c)) {
445
- if (c->tt == MRB_TT_MODULE)
446
- mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen module");
447
- else
448
- mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen class");
449
- }
455
+ mrb_check_frozen(mrb, c);
450
456
  if (!h) h = c->mt = kh_init(mt, mrb);
451
457
  k = kh_put(mt, mrb, h, mid);
452
458
  kh_value(h, k) = m;
@@ -470,6 +476,9 @@ mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t f
470
476
  int ai = mrb_gc_arena_save(mrb);
471
477
 
472
478
  MRB_METHOD_FROM_FUNC(m, func);
479
+ if (aspec == MRB_ARGS_NONE()) {
480
+ MRB_METHOD_NOARG_SET(m);
481
+ }
473
482
  mrb_define_method_raw(mrb, c, mid, m);
474
483
  mrb_gc_arena_restore(mrb, ai);
475
484
  }
@@ -487,8 +496,7 @@ mrb_notimplement(mrb_state *mrb)
487
496
  mrb_callinfo *ci = mrb->c->ci;
488
497
 
489
498
  if (ci->mid) {
490
- mrb_value str = mrb_sym2str(mrb, ci->mid);
491
- mrb_raisef(mrb, E_NOTIMP_ERROR, "%S() function is unimplemented on this machine", str);
499
+ mrb_raisef(mrb, E_NOTIMP_ERROR, "%n() function is unimplemented on this machine", ci->mid);
492
500
  }
493
501
  }
494
502
 
@@ -501,30 +509,17 @@ mrb_notimplement_m(mrb_state *mrb, mrb_value self)
501
509
  return mrb_nil_value();
502
510
  }
503
511
 
504
- #define CHECK_TYPE(mrb, val, t, c) do { \
505
- if (mrb_type(val) != (t)) {\
506
- mrb_raisef(mrb, E_TYPE_ERROR, "expected %S", mrb_str_new_lit(mrb, c));\
507
- }\
508
- } while (0)
509
-
510
- static mrb_value
511
- to_str(mrb_state *mrb, mrb_value val)
512
- {
513
- CHECK_TYPE(mrb, val, MRB_TT_STRING, "String");
514
- return val;
515
- }
516
-
517
512
  static mrb_value
518
513
  to_ary(mrb_state *mrb, mrb_value val)
519
514
  {
520
- CHECK_TYPE(mrb, val, MRB_TT_ARRAY, "Array");
515
+ mrb_check_type(mrb, val, MRB_TT_ARRAY);
521
516
  return val;
522
517
  }
523
518
 
524
519
  static mrb_value
525
520
  to_hash(mrb_state *mrb, mrb_value val)
526
521
  {
527
- CHECK_TYPE(mrb, val, MRB_TT_HASH, "Hash");
522
+ mrb_check_type(mrb, val, MRB_TT_HASH);
528
523
  return val;
529
524
  }
530
525
 
@@ -559,6 +554,8 @@ mrb_get_argv(mrb_state *mrb)
559
554
  return array_argv;
560
555
  }
561
556
 
557
+ void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
558
+
562
559
  /*
563
560
  retrieve arguments from mrb_state.
564
561
 
@@ -571,23 +568,24 @@ mrb_get_argv(mrb_state *mrb)
571
568
  string mruby type C type note
572
569
  ----------------------------------------------------------------------------------------------
573
570
  o: Object [mrb_value]
574
- C: class/module [mrb_value]
571
+ C: Class/Module [mrb_value]
575
572
  S: String [mrb_value] when ! follows, the value may be nil
576
573
  A: Array [mrb_value] when ! follows, the value may be nil
577
574
  H: Hash [mrb_value] when ! follows, the value may be nil
578
575
  s: String [char*,mrb_int] Receive two arguments; s! gives (NULL,0) for nil
579
576
  z: String [char*] NUL terminated string; z! gives NULL for nil
580
577
  a: Array [mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil
581
- f: Float [mrb_float]
582
- i: Integer [mrb_int]
583
- b: Boolean [mrb_bool]
584
- n: Symbol [mrb_sym]
585
- d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified
586
- I: Inline struct [void*]
587
- &: Block [mrb_value] &! raises exception if no block given
578
+ f: Fixnum/Float [mrb_float]
579
+ i: Fixnum/Float [mrb_int]
580
+ b: boolean [mrb_bool]
581
+ n: String/Symbol [mrb_sym]
582
+ d: data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified; when ! follows, the value may be nil
583
+ I: inline struct [void*]
584
+ &: block [mrb_value] &! raises exception if no block given
588
585
  *: rest argument [mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack
589
586
  |: optional Following arguments are optional
590
587
  ?: optional given [mrb_bool] true if preceding argument (optional) is given
588
+ ':': keyword args [mrb_kwargs const] Get keyword arguments
591
589
  */
592
590
  MRB_API mrb_int
593
591
  mrb_get_args(mrb_state *mrb, const char *format, ...)
@@ -602,6 +600,9 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
602
600
  mrb_bool opt = FALSE;
603
601
  mrb_bool opt_skip = TRUE;
604
602
  mrb_bool given = TRUE;
603
+ mrb_value kdict;
604
+ mrb_bool reqkarg = FALSE;
605
+ mrb_int needargc = 0;
605
606
 
606
607
  va_start(ap, format);
607
608
 
@@ -615,23 +616,39 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
615
616
  break;
616
617
  case '*':
617
618
  opt_skip = FALSE;
619
+ if (!reqkarg) reqkarg = strchr(fmt, ':') ? TRUE : FALSE;
618
620
  goto check_exit;
619
621
  case '!':
620
622
  break;
621
623
  case '&': case '?':
622
624
  if (opt) opt_skip = FALSE;
623
625
  break;
626
+ case ':':
627
+ reqkarg = TRUE;
628
+ break;
624
629
  default:
630
+ if (!opt) needargc ++;
625
631
  break;
626
632
  }
627
633
  }
628
634
 
629
635
  check_exit:
636
+ if (reqkarg && argc > needargc && mrb_hash_p(kdict = ARGV[argc - 1])) {
637
+ mrb_hash_check_kdict(mrb, kdict);
638
+ argc --;
639
+ }
640
+ else {
641
+ kdict = mrb_nil_value();
642
+ }
643
+
630
644
  opt = FALSE;
631
645
  i = 0;
632
646
  while ((c = *format++)) {
647
+ mrb_value *argv = ARGV;
648
+ mrb_bool altmode;
649
+
633
650
  switch (c) {
634
- case '|': case '*': case '&': case '?':
651
+ case '|': case '*': case '&': case '?': case ':':
635
652
  break;
636
653
  default:
637
654
  if (argc <= i) {
@@ -645,6 +662,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
645
662
  break;
646
663
  }
647
664
 
665
+ if (*format == '!') {
666
+ format ++;
667
+ altmode = TRUE;
668
+ }
669
+ else {
670
+ altmode = FALSE;
671
+ }
672
+
648
673
  switch (c) {
649
674
  case 'o':
650
675
  {
@@ -652,7 +677,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
652
677
 
653
678
  p = va_arg(ap, mrb_value*);
654
679
  if (i < argc) {
655
- *p = ARGV[arg_i++];
680
+ *p = argv[arg_i++];
656
681
  i++;
657
682
  }
658
683
  }
@@ -665,9 +690,9 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
665
690
  if (i < argc) {
666
691
  mrb_value ss;
667
692
 
668
- ss = ARGV[arg_i++];
693
+ ss = argv[arg_i++];
669
694
  if (!class_ptr_p(ss)) {
670
- mrb_raisef(mrb, E_TYPE_ERROR, "%S is not class/module", ss);
695
+ mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss);
671
696
  }
672
697
  *p = ss;
673
698
  i++;
@@ -679,17 +704,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
679
704
  mrb_value *p;
680
705
 
681
706
  p = va_arg(ap, mrb_value*);
682
- if (*format == '!') {
683
- format++;
684
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
685
- *p = ARGV[arg_i++];
686
- i++;
687
- break;
688
- }
689
- }
690
707
  if (i < argc) {
691
- *p = to_str(mrb, ARGV[arg_i++]);
708
+ *p = argv[arg_i++];
692
709
  i++;
710
+ if (!(altmode && mrb_nil_p(*p))) {
711
+ mrb_to_str(mrb, *p);
712
+ }
693
713
  }
694
714
  }
695
715
  break;
@@ -698,17 +718,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
698
718
  mrb_value *p;
699
719
 
700
720
  p = va_arg(ap, mrb_value*);
701
- if (*format == '!') {
702
- format++;
703
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
704
- *p = ARGV[arg_i++];
705
- i++;
706
- break;
707
- }
708
- }
709
721
  if (i < argc) {
710
- *p = to_ary(mrb, ARGV[arg_i++]);
722
+ *p = argv[arg_i++];
711
723
  i++;
724
+ if (!(altmode && mrb_nil_p(*p))) {
725
+ *p = to_ary(mrb, *p);
726
+ }
712
727
  }
713
728
  }
714
729
  break;
@@ -717,17 +732,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
717
732
  mrb_value *p;
718
733
 
719
734
  p = va_arg(ap, mrb_value*);
720
- if (*format == '!') {
721
- format++;
722
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
723
- *p = ARGV[arg_i++];
724
- i++;
725
- break;
726
- }
727
- }
728
735
  if (i < argc) {
729
- *p = to_hash(mrb, ARGV[arg_i++]);
736
+ *p = argv[arg_i++];
730
737
  i++;
738
+ if (!(altmode && mrb_nil_p(*p))) {
739
+ *p = to_hash(mrb, *p);
740
+ }
731
741
  }
732
742
  }
733
743
  break;
@@ -739,20 +749,18 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
739
749
 
740
750
  ps = va_arg(ap, char**);
741
751
  pl = va_arg(ap, mrb_int*);
742
- if (*format == '!') {
743
- format++;
744
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
752
+ if (i < argc) {
753
+ ss = argv[arg_i++];
754
+ i++;
755
+ if (altmode && mrb_nil_p(ss)) {
745
756
  *ps = NULL;
746
757
  *pl = 0;
747
- i++; arg_i++;
748
- break;
749
758
  }
750
- }
751
- if (i < argc) {
752
- ss = to_str(mrb, ARGV[arg_i++]);
753
- *ps = RSTRING_PTR(ss);
754
- *pl = RSTRING_LEN(ss);
755
- i++;
759
+ else {
760
+ mrb_to_str(mrb, ss);
761
+ *ps = RSTRING_PTR(ss);
762
+ *pl = RSTRING_LEN(ss);
763
+ }
756
764
  }
757
765
  }
758
766
  break;
@@ -762,18 +770,16 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
762
770
  const char **ps;
763
771
 
764
772
  ps = va_arg(ap, const char**);
765
- if (*format == '!') {
766
- format++;
767
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
768
- *ps = NULL;
769
- i++; arg_i++;
770
- break;
771
- }
772
- }
773
773
  if (i < argc) {
774
- ss = to_str(mrb, ARGV[arg_i++]);
775
- *ps = mrb_string_value_cstr(mrb, &ss);
774
+ ss = argv[arg_i++];
776
775
  i++;
776
+ if (altmode && mrb_nil_p(ss)) {
777
+ *ps = NULL;
778
+ }
779
+ else {
780
+ mrb_to_str(mrb, ss);
781
+ *ps = RSTRING_CSTR(mrb, ss);
782
+ }
777
783
  }
778
784
  }
779
785
  break;
@@ -786,21 +792,19 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
786
792
 
787
793
  pb = va_arg(ap, mrb_value**);
788
794
  pl = va_arg(ap, mrb_int*);
789
- if (*format == '!') {
790
- format++;
791
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
795
+ if (i < argc) {
796
+ aa = argv[arg_i++];
797
+ i++;
798
+ if (altmode && mrb_nil_p(aa)) {
792
799
  *pb = 0;
793
800
  *pl = 0;
794
- i++; arg_i++;
795
- break;
796
801
  }
797
- }
798
- if (i < argc) {
799
- aa = to_ary(mrb, ARGV[arg_i++]);
800
- a = mrb_ary_ptr(aa);
801
- *pb = ARY_PTR(a);
802
- *pl = ARY_LEN(a);
803
- i++;
802
+ else {
803
+ aa = to_ary(mrb, aa);
804
+ a = mrb_ary_ptr(aa);
805
+ *pb = ARY_PTR(a);
806
+ *pl = ARY_LEN(a);
807
+ }
804
808
  }
805
809
  }
806
810
  break;
@@ -811,10 +815,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
811
815
 
812
816
  p = va_arg(ap, void**);
813
817
  if (i < argc) {
814
- ss = ARGV[arg_i];
815
- if (mrb_type(ss) != MRB_TT_ISTRUCT)
818
+ ss = argv[arg_i];
819
+ if (!mrb_istruct_p(ss))
816
820
  {
817
- mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss);
821
+ mrb_raisef(mrb, E_TYPE_ERROR, "%v is not inline struct", ss);
818
822
  }
819
823
  *p = mrb_istruct_ptr(ss);
820
824
  arg_i++;
@@ -829,7 +833,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
829
833
 
830
834
  p = va_arg(ap, mrb_float*);
831
835
  if (i < argc) {
832
- *p = mrb_to_flo(mrb, ARGV[arg_i]);
836
+ *p = mrb_to_flo(mrb, argv[arg_i]);
833
837
  arg_i++;
834
838
  i++;
835
839
  }
@@ -842,29 +846,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
842
846
 
843
847
  p = va_arg(ap, mrb_int*);
844
848
  if (i < argc) {
845
- switch (mrb_type(ARGV[arg_i])) {
846
- case MRB_TT_FIXNUM:
847
- *p = mrb_fixnum(ARGV[arg_i]);
848
- break;
849
- #ifndef MRB_WITHOUT_FLOAT
850
- case MRB_TT_FLOAT:
851
- {
852
- mrb_float f = mrb_float(ARGV[arg_i]);
853
-
854
- if (!FIXABLE_FLOAT(f)) {
855
- mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
856
- }
857
- *p = (mrb_int)f;
858
- }
859
- break;
860
- #endif
861
- case MRB_TT_STRING:
862
- mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion of String into Integer");
863
- break;
864
- default:
865
- *p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
866
- break;
867
- }
849
+ *p = mrb_fixnum(mrb_to_int(mrb, argv[arg_i]));
868
850
  arg_i++;
869
851
  i++;
870
852
  }
@@ -875,7 +857,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
875
857
  mrb_bool *boolp = va_arg(ap, mrb_bool*);
876
858
 
877
859
  if (i < argc) {
878
- mrb_value b = ARGV[arg_i++];
860
+ mrb_value b = argv[arg_i++];
879
861
  *boolp = mrb_test(b);
880
862
  i++;
881
863
  }
@@ -889,7 +871,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
889
871
  if (i < argc) {
890
872
  mrb_value ss;
891
873
 
892
- ss = ARGV[arg_i++];
874
+ ss = argv[arg_i++];
893
875
  *symp = to_sym(mrb, ss);
894
876
  i++;
895
877
  }
@@ -902,17 +884,15 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
902
884
 
903
885
  datap = va_arg(ap, void**);
904
886
  type = va_arg(ap, struct mrb_data_type const*);
905
- if (*format == '!') {
906
- format++;
907
- if (i < argc && mrb_nil_p(ARGV[arg_i])) {
887
+ if (i < argc) {
888
+ mrb_value dd = argv[arg_i++];
889
+ i++;
890
+ if (altmode && mrb_nil_p(dd)) {
908
891
  *datap = 0;
909
- i++; arg_i++;
910
- break;
911
892
  }
912
- }
913
- if (i < argc) {
914
- *datap = mrb_data_get_ptr(mrb, ARGV[arg_i++], type);
915
- ++i;
893
+ else {
894
+ *datap = mrb_data_get_ptr(mrb, dd, type);
895
+ }
916
896
  }
917
897
  }
918
898
  break;
@@ -928,11 +908,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
928
908
  else {
929
909
  bp = mrb->c->stack + mrb->c->ci->argc + 1;
930
910
  }
931
- if (*format == '!') {
932
- format ++;
933
- if (mrb_nil_p(*bp)) {
934
- mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
935
- }
911
+ if (altmode && mrb_nil_p(*bp)) {
912
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
936
913
  }
937
914
  *p = *bp;
938
915
  }
@@ -954,22 +931,18 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
954
931
  {
955
932
  mrb_value **var;
956
933
  mrb_int *pl;
957
- mrb_bool nocopy = array_argv ? TRUE : FALSE;
934
+ mrb_bool nocopy = altmode || array_argv ? TRUE : FALSE;
958
935
 
959
- if (*format == '!') {
960
- format++;
961
- nocopy = TRUE;
962
- }
963
936
  var = va_arg(ap, mrb_value**);
964
937
  pl = va_arg(ap, mrb_int*);
965
938
  if (argc > i) {
966
939
  *pl = argc-i;
967
940
  if (*pl > 0) {
968
941
  if (nocopy) {
969
- *var = ARGV+arg_i;
942
+ *var = argv+arg_i;
970
943
  }
971
944
  else {
972
- mrb_value args = mrb_ary_new_from_values(mrb, *pl, ARGV+arg_i);
945
+ mrb_value args = mrb_ary_new_from_values(mrb, *pl, argv+arg_i);
973
946
  RARRAY(args)->c = NULL;
974
947
  *var = RARRAY_PTR(args);
975
948
  }
@@ -983,8 +956,64 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
983
956
  }
984
957
  }
985
958
  break;
959
+
960
+ case ':':
961
+ {
962
+ mrb_value ksrc = mrb_hash_p(kdict) ? mrb_hash_dup(mrb, kdict) : mrb_hash_new(mrb);
963
+ const mrb_kwargs *kwargs = va_arg(ap, const mrb_kwargs*);
964
+ mrb_value *rest;
965
+
966
+ if (kwargs == NULL) {
967
+ rest = NULL;
968
+ }
969
+ else {
970
+ uint32_t kwnum = kwargs->num;
971
+ uint32_t required = kwargs->required;
972
+ const char *const *kname = kwargs->table;
973
+ mrb_value *values = kwargs->values;
974
+ uint32_t j;
975
+ const uint32_t keyword_max = 40;
976
+
977
+ if (kwnum > keyword_max || required > kwnum) {
978
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "keyword number is too large");
979
+ }
980
+
981
+ for (j = required; j > 0; j --, kname ++, values ++) {
982
+ mrb_value k = mrb_symbol_value(mrb_intern_cstr(mrb, *kname));
983
+ if (!mrb_hash_key_p(mrb, ksrc, k)) {
984
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "missing keyword: %s", *kname);
985
+ }
986
+ *values = mrb_hash_delete_key(mrb, ksrc, k);
987
+ mrb_gc_protect(mrb, *values);
988
+ }
989
+
990
+ for (j = kwnum - required; j > 0; j --, kname ++, values ++) {
991
+ mrb_value k = mrb_symbol_value(mrb_intern_cstr(mrb, *kname));
992
+ if (mrb_hash_key_p(mrb, ksrc, k)) {
993
+ *values = mrb_hash_delete_key(mrb, ksrc, k);
994
+ mrb_gc_protect(mrb, *values);
995
+ }
996
+ else {
997
+ *values = mrb_undef_value();
998
+ }
999
+ }
1000
+
1001
+ rest = kwargs->rest;
1002
+ }
1003
+
1004
+ if (rest) {
1005
+ *rest = ksrc;
1006
+ }
1007
+ else if (!mrb_hash_empty_p(mrb, ksrc)) {
1008
+ ksrc = mrb_hash_keys(mrb, ksrc);
1009
+ ksrc = RARRAY_PTR(ksrc)[0];
1010
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown keyword: %v", ksrc);
1011
+ }
1012
+ }
1013
+ break;
1014
+
986
1015
  default:
987
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %S", mrb_str_new(mrb, &c, 1));
1016
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %c", c);
988
1017
  break;
989
1018
  }
990
1019
  }
@@ -1090,8 +1119,8 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
1090
1119
  MRB_API void
1091
1120
  mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
1092
1121
  {
1093
- int changed = include_module_at(mrb, c, find_origin(c), m, 1);
1094
- if (changed < 0) {
1122
+ mrb_check_frozen(mrb, c);
1123
+ if (include_module_at(mrb, c, find_origin(c), m, 1) < 0) {
1095
1124
  mrb_raise(mrb, E_ARGUMENT_ERROR, "cyclic include detected");
1096
1125
  }
1097
1126
  }
@@ -1102,6 +1131,7 @@ mrb_prepend_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
1102
1131
  struct RClass *origin;
1103
1132
  int changed = 0;
1104
1133
 
1134
+ mrb_check_frozen(mrb, c);
1105
1135
  if (!(c->flags & MRB_FL_CLASS_IS_PREPENDED)) {
1106
1136
  origin = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, c);
1107
1137
  origin->flags |= MRB_FL_CLASS_IS_ORIGIN | MRB_FL_CLASS_IS_INHERITED;
@@ -1372,25 +1402,57 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid)
1372
1402
 
1373
1403
  m = mrb_method_search_vm(mrb, &c, mid);
1374
1404
  if (MRB_METHOD_UNDEF_P(m)) {
1375
- mrb_value inspect = mrb_funcall(mrb, mrb_obj_value(c), "inspect", 0);
1376
- if (mrb_string_p(inspect) && RSTRING_LEN(inspect) > 64) {
1377
- inspect = mrb_any_to_s(mrb, mrb_obj_value(c));
1378
- }
1379
- mrb_name_error(mrb, mid, "undefined method '%S' for class %S",
1380
- mrb_sym2str(mrb, mid), inspect);
1405
+ mrb_name_error(mrb, mid, "undefined method '%n' for class %C", mid, c);
1381
1406
  }
1382
1407
  return m;
1383
1408
  }
1384
1409
 
1410
+ #define ONSTACK_ALLOC_MAX 32
1411
+
1412
+ static mrb_sym
1413
+ prepare_name_common(mrb_state *mrb, mrb_sym sym, const char *prefix, const char *suffix)
1414
+ {
1415
+ char onstack[ONSTACK_ALLOC_MAX];
1416
+ mrb_int sym_len;
1417
+ const char *sym_str = mrb_sym_name_len(mrb, sym, &sym_len);
1418
+ size_t prefix_len = prefix ? strlen(prefix) : 0;
1419
+ size_t suffix_len = suffix ? strlen(suffix) : 0;
1420
+ size_t name_len = sym_len + prefix_len + suffix_len;
1421
+ char *buf = name_len > sizeof(onstack) ? (char *)mrb_alloca(mrb, name_len) : onstack;
1422
+ char *p = buf;
1423
+
1424
+ if (prefix_len > 0) {
1425
+ memcpy(p, prefix, prefix_len);
1426
+ p += prefix_len;
1427
+ }
1428
+
1429
+ memcpy(p, sym_str, sym_len);
1430
+ p += sym_len;
1431
+
1432
+ if (suffix_len > 0) {
1433
+ memcpy(p, suffix, suffix_len);
1434
+ p += suffix_len;
1435
+ }
1436
+
1437
+ return mrb_intern(mrb, buf, name_len);
1438
+ }
1439
+
1385
1440
  static mrb_value
1386
- attr_reader(mrb_state *mrb, mrb_value obj)
1441
+ prepare_ivar_name(mrb_state *mrb, mrb_sym sym)
1387
1442
  {
1388
- mrb_value name = mrb_proc_cfunc_env_get(mrb, 0);
1389
- return mrb_iv_get(mrb, obj, to_sym(mrb, name));
1443
+ sym = prepare_name_common(mrb, sym, "@", NULL);
1444
+ mrb_iv_name_sym_check(mrb, sym);
1445
+ return mrb_symbol_value(sym);
1446
+ }
1447
+
1448
+ static mrb_sym
1449
+ prepare_writer_name(mrb_state *mrb, mrb_sym sym)
1450
+ {
1451
+ return prepare_name_common(mrb, sym, NULL, "=");
1390
1452
  }
1391
1453
 
1392
1454
  static mrb_value
1393
- mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
1455
+ mod_attr_define(mrb_state *mrb, mrb_value mod, mrb_value (*accessor)(mrb_state *, mrb_value), mrb_sym (*access_name)(mrb_state *, mrb_sym))
1394
1456
  {
1395
1457
  struct RClass *c = mrb_class_ptr(mod);
1396
1458
  mrb_value *argv;
@@ -1400,20 +1462,18 @@ mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
1400
1462
  mrb_get_args(mrb, "*", &argv, &argc);
1401
1463
  ai = mrb_gc_arena_save(mrb);
1402
1464
  for (i=0; i<argc; i++) {
1403
- mrb_value name, str;
1404
- mrb_sym method, sym;
1465
+ mrb_value name;
1466
+ mrb_sym method;
1405
1467
  struct RProc *p;
1406
1468
  mrb_method_t m;
1407
1469
 
1408
1470
  method = to_sym(mrb, argv[i]);
1409
- name = mrb_sym2str(mrb, method);
1410
- str = mrb_str_new_capa(mrb, RSTRING_LEN(name)+1);
1411
- mrb_str_cat_lit(mrb, str, "@");
1412
- mrb_str_cat_str(mrb, str, name);
1413
- sym = mrb_intern_str(mrb, str);
1414
- mrb_iv_name_sym_check(mrb, sym);
1415
- name = mrb_symbol_value(sym);
1416
- p = mrb_proc_new_cfunc_with_env(mrb, attr_reader, 1, &name);
1471
+ name = prepare_ivar_name(mrb, method);
1472
+ if (access_name) {
1473
+ method = access_name(mrb, method);
1474
+ }
1475
+
1476
+ p = mrb_proc_new_cfunc_with_env(mrb, accessor, 1, &name);
1417
1477
  MRB_METHOD_FROM_PROC(m, p);
1418
1478
  mrb_define_method_raw(mrb, c, method, m);
1419
1479
  mrb_gc_arena_restore(mrb, ai);
@@ -1421,6 +1481,19 @@ mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
1421
1481
  return mrb_nil_value();
1422
1482
  }
1423
1483
 
1484
+ static mrb_value
1485
+ attr_reader(mrb_state *mrb, mrb_value obj)
1486
+ {
1487
+ mrb_value name = mrb_proc_cfunc_env_get(mrb, 0);
1488
+ return mrb_iv_get(mrb, obj, to_sym(mrb, name));
1489
+ }
1490
+
1491
+ static mrb_value
1492
+ mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
1493
+ {
1494
+ return mod_attr_define(mrb, mod, attr_reader, NULL);
1495
+ }
1496
+
1424
1497
  static mrb_value
1425
1498
  attr_writer(mrb_state *mrb, mrb_value obj)
1426
1499
  {
@@ -1435,42 +1508,7 @@ attr_writer(mrb_state *mrb, mrb_value obj)
1435
1508
  static mrb_value
1436
1509
  mrb_mod_attr_writer(mrb_state *mrb, mrb_value mod)
1437
1510
  {
1438
- struct RClass *c = mrb_class_ptr(mod);
1439
- mrb_value *argv;
1440
- mrb_int argc, i;
1441
- int ai;
1442
-
1443
- mrb_get_args(mrb, "*", &argv, &argc);
1444
- ai = mrb_gc_arena_save(mrb);
1445
- for (i=0; i<argc; i++) {
1446
- mrb_value name, str, attr;
1447
- mrb_sym method, sym;
1448
- struct RProc *p;
1449
- mrb_method_t m;
1450
-
1451
- method = to_sym(mrb, argv[i]);
1452
-
1453
- /* prepare iv name (@name) */
1454
- name = mrb_sym2str(mrb, method);
1455
- str = mrb_str_new_capa(mrb, RSTRING_LEN(name)+1);
1456
- mrb_str_cat_lit(mrb, str, "@");
1457
- mrb_str_cat_str(mrb, str, name);
1458
- sym = mrb_intern_str(mrb, str);
1459
- mrb_iv_name_sym_check(mrb, sym);
1460
- attr = mrb_symbol_value(sym);
1461
-
1462
- /* prepare method name (name=) */
1463
- str = mrb_str_new_capa(mrb, RSTRING_LEN(str));
1464
- mrb_str_cat_str(mrb, str, name);
1465
- mrb_str_cat_lit(mrb, str, "=");
1466
- method = mrb_intern_str(mrb, str);
1467
-
1468
- p = mrb_proc_new_cfunc_with_env(mrb, attr_writer, 1, &attr);
1469
- MRB_METHOD_FROM_PROC(m, p);
1470
- mrb_define_method_raw(mrb, c, method, m);
1471
- mrb_gc_arena_restore(mrb, ai);
1472
- }
1473
- return mrb_nil_value();
1511
+ return mod_attr_define(mrb, mod, attr_writer, prepare_writer_name);
1474
1512
  }
1475
1513
 
1476
1514
  static mrb_value
@@ -1485,7 +1523,7 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv)
1485
1523
 
1486
1524
  if (ttype == 0) ttype = MRB_TT_OBJECT;
1487
1525
  if (ttype <= MRB_TT_CPTR) {
1488
- mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %S", cv);
1526
+ mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %v", cv);
1489
1527
  }
1490
1528
  o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);
1491
1529
  return mrb_obj_value(o);
@@ -1503,29 +1541,20 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv)
1503
1541
  *
1504
1542
  */
1505
1543
 
1506
- MRB_API mrb_value
1544
+ mrb_value
1507
1545
  mrb_instance_new(mrb_state *mrb, mrb_value cv)
1508
1546
  {
1509
1547
  mrb_value obj, blk;
1510
1548
  mrb_value *argv;
1511
1549
  mrb_int argc;
1512
1550
  mrb_sym init;
1513
- mrb_method_t m;
1514
1551
 
1515
- mrb_get_args(mrb, "*&", &argv, &argc, &blk);
1552
+ mrb_get_args(mrb, "*!&", &argv, &argc, &blk);
1516
1553
  obj = mrb_instance_alloc(mrb, cv);
1517
1554
  init = mrb_intern_lit(mrb, "initialize");
1518
- m = mrb_method_search(mrb, mrb_class(mrb, obj), init);
1519
- if (MRB_METHOD_CFUNC_P(m)) {
1520
- mrb_func_t f = MRB_METHOD_CFUNC(m);
1521
- if (f != mrb_bob_init) {
1522
- f(mrb, obj);
1523
- }
1524
- }
1525
- else {
1555
+ if (!mrb_func_basic_p(mrb, obj, init, mrb_bob_init)) {
1526
1556
  mrb_funcall_with_block(mrb, obj, init, argc, argv, blk);
1527
1557
  }
1528
-
1529
1558
  return obj;
1530
1559
  }
1531
1560
 
@@ -1569,7 +1598,10 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv)
1569
1598
  }
1570
1599
  new_class = mrb_obj_value(mrb_class_new(mrb, mrb_class_ptr(super)));
1571
1600
  mid = mrb_intern_lit(mrb, "initialize");
1572
- if (!mrb_func_basic_p(mrb, new_class, mid, mrb_bob_init)) {
1601
+ if (mrb_func_basic_p(mrb, new_class, mid, mrb_class_initialize)) {
1602
+ mrb_class_initialize(mrb, new_class);
1603
+ }
1604
+ else {
1573
1605
  mrb_funcall_with_block(mrb, new_class, mid, n, &super, blk);
1574
1606
  }
1575
1607
  mrb_class_inherited(mrb, mrb_class_ptr(super), mrb_class_ptr(new_class));
@@ -1682,7 +1714,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
1682
1714
  }
1683
1715
  else if (mrb_symbol_p(path)) {
1684
1716
  /* toplevel class/module */
1685
- return mrb_sym2str(mrb, mrb_symbol(path));
1717
+ return mrb_sym_str(mrb, mrb_symbol(path));
1686
1718
  }
1687
1719
  return mrb_str_dup(mrb, path);
1688
1720
  }
@@ -1721,7 +1753,7 @@ static void
1721
1753
  mrb_check_inheritable(mrb_state *mrb, struct RClass *super)
1722
1754
  {
1723
1755
  if (super->tt != MRB_TT_CLASS) {
1724
- mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)", mrb_obj_value(super));
1756
+ mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%C given)", super);
1725
1757
  }
1726
1758
  if (super->tt == MRB_TT_SCLASS) {
1727
1759
  mrb_raise(mrb, E_TYPE_ERROR, "can't make subclass of singleton class");
@@ -1790,11 +1822,31 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b)
1790
1822
  {
1791
1823
  mrb_method_t m = mrb_method_search(mrb, c, b);
1792
1824
 
1825
+ if (!MRB_METHOD_CFUNC_P(m)) {
1826
+ struct RProc *p = MRB_METHOD_PROC(m);
1827
+
1828
+ if (MRB_PROC_ENV_P(p)) {
1829
+ MRB_PROC_ENV(p)->mid = b;
1830
+ }
1831
+ else {
1832
+ struct RClass *tc = MRB_PROC_TARGET_CLASS(p);
1833
+ struct REnv *e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL);
1834
+
1835
+ e->mid = b;
1836
+ if (tc) {
1837
+ e->c = tc;
1838
+ mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)tc);
1839
+ }
1840
+ p->e.env = e;
1841
+ p->flags |= MRB_PROC_ENVSET;
1842
+ }
1843
+ }
1793
1844
  mrb_define_method_raw(mrb, c, a, m);
1794
1845
  }
1795
1846
 
1796
1847
  /*!
1797
1848
  * Defines an alias of a method.
1849
+ * \param mrb the mruby state
1798
1850
  * \param klass the class which the original method belongs to
1799
1851
  * \param name1 a new name for the method
1800
1852
  * \param name2 the original name of the method
@@ -1818,7 +1870,7 @@ mrb_value
1818
1870
  mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
1819
1871
  {
1820
1872
 
1821
- if (mrb_type(klass) == MRB_TT_SCLASS) {
1873
+ if (mrb_sclass_p(klass)) {
1822
1874
  mrb_value v = mrb_iv_get(mrb, klass, mrb_intern_lit(mrb, "__attached__"));
1823
1875
  mrb_value str = mrb_str_new_lit(mrb, "#<Class:");
1824
1876
 
@@ -1843,27 +1895,31 @@ mrb_mod_alias(mrb_state *mrb, mrb_value mod)
1843
1895
 
1844
1896
  mrb_get_args(mrb, "nn", &new_name, &old_name);
1845
1897
  mrb_alias_method(mrb, c, new_name, old_name);
1846
- return mrb_nil_value();
1898
+ return mod;
1899
+ }
1900
+
1901
+ static void
1902
+ undef_method(mrb_state *mrb, struct RClass *c, mrb_sym a)
1903
+ {
1904
+ mrb_method_t m;
1905
+
1906
+ MRB_METHOD_FROM_PROC(m, NULL);
1907
+ mrb_define_method_raw(mrb, c, a, m);
1847
1908
  }
1848
1909
 
1849
1910
  void
1850
1911
  mrb_undef_method_id(mrb_state *mrb, struct RClass *c, mrb_sym a)
1851
1912
  {
1852
1913
  if (!mrb_obj_respond_to(mrb, c, a)) {
1853
- mrb_name_error(mrb, a, "undefined method '%S' for class '%S'", mrb_sym2str(mrb, a), mrb_obj_value(c));
1854
- }
1855
- else {
1856
- mrb_method_t m;
1857
-
1858
- MRB_METHOD_FROM_PROC(m, NULL);
1859
- mrb_define_method_raw(mrb, c, a, m);
1914
+ mrb_name_error(mrb, a, "undefined method '%n' for class '%C'", a, c);
1860
1915
  }
1916
+ undef_method(mrb, c, a);
1861
1917
  }
1862
1918
 
1863
1919
  MRB_API void
1864
1920
  mrb_undef_method(mrb_state *mrb, struct RClass *c, const char *name)
1865
1921
  {
1866
- mrb_undef_method_id(mrb, c, mrb_intern_cstr(mrb, name));
1922
+ undef_method(mrb, c, mrb_intern_cstr(mrb, name));
1867
1923
  }
1868
1924
 
1869
1925
  MRB_API void
@@ -1887,19 +1943,13 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod)
1887
1943
  return mrb_nil_value();
1888
1944
  }
1889
1945
 
1890
- static mrb_bool
1891
- const_name_p(mrb_state *mrb, const char *name, mrb_int len)
1892
- {
1893
- return len > 0 && ISUPPER(name[0]) && mrb_ident_p(name+1, len-1);
1894
- }
1895
-
1896
1946
  static void
1897
1947
  check_const_name_sym(mrb_state *mrb, mrb_sym id)
1898
1948
  {
1899
1949
  mrb_int len;
1900
- const char *name = mrb_sym2name_len(mrb, id, &len);
1901
- if (!const_name_p(mrb, name, len)) {
1902
- mrb_name_error(mrb, id, "wrong constant name %S", mrb_sym2str(mrb, id));
1950
+ const char *name = mrb_sym_name_len(mrb, id, &len);
1951
+ if (!mrb_const_name_p(mrb, name, len)) {
1952
+ mrb_name_error(mrb, id, "wrong constant name %n", id);
1903
1953
  }
1904
1954
  }
1905
1955
 
@@ -1956,7 +2006,7 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
1956
2006
  else {
1957
2007
  off = end + 2;
1958
2008
  if (off == len) { /* trailing "::" */
1959
- mrb_name_error(mrb, id, "wrong constant name '%S'", path);
2009
+ mrb_name_error(mrb, id, "wrong constant name '%v'", path);
1960
2010
  }
1961
2011
  }
1962
2012
  }
@@ -1986,7 +2036,7 @@ mrb_mod_remove_const(mrb_state *mrb, mrb_value mod)
1986
2036
  check_const_name_sym(mrb, id);
1987
2037
  val = mrb_iv_remove(mrb, mod, id);
1988
2038
  if (mrb_undef_p(val)) {
1989
- mrb_name_error(mrb, id, "constant %S not defined", mrb_sym2str(mrb, id));
2039
+ mrb_name_error(mrb, id, "constant %n not defined", id);
1990
2040
  }
1991
2041
  return val;
1992
2042
  }
@@ -1999,13 +2049,10 @@ mrb_mod_const_missing(mrb_state *mrb, mrb_value mod)
1999
2049
  mrb_get_args(mrb, "n", &sym);
2000
2050
 
2001
2051
  if (mrb_class_real(mrb_class_ptr(mod)) != mrb->object_class) {
2002
- mrb_name_error(mrb, sym, "uninitialized constant %S::%S",
2003
- mod,
2004
- mrb_sym2str(mrb, sym));
2052
+ mrb_name_error(mrb, sym, "uninitialized constant %v::%n", mod, sym);
2005
2053
  }
2006
2054
  else {
2007
- mrb_name_error(mrb, sym, "uninitialized constant %S",
2008
- mrb_sym2str(mrb, sym));
2055
+ mrb_name_error(mrb, sym, "uninitialized constant %n", sym);
2009
2056
  }
2010
2057
  /* not reached */
2011
2058
  return mrb_nil_value();
@@ -2066,7 +2113,7 @@ mod_define_method(mrb_state *mrb, mrb_value self)
2066
2113
  /* ignored */
2067
2114
  break;
2068
2115
  default:
2069
- mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %S (expected Proc)", mrb_obj_value(mrb_obj_class(mrb, proc)));
2116
+ mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %T (expected Proc)", proc);
2070
2117
  break;
2071
2118
  }
2072
2119
  if (mrb_nil_p(blk)) {
@@ -2098,6 +2145,14 @@ mrb_mod_eqq(mrb_state *mrb, mrb_value mod)
2098
2145
  return mrb_bool_value(eqq);
2099
2146
  }
2100
2147
 
2148
+ static mrb_value
2149
+ mrb_mod_dup(mrb_state *mrb, mrb_value self)
2150
+ {
2151
+ mrb_value mod = mrb_obj_clone(mrb, self);
2152
+ MRB_UNSET_FROZEN_FLAG(mrb_obj_ptr(mod));
2153
+ return mod;
2154
+ }
2155
+
2101
2156
  static mrb_value
2102
2157
  mrb_mod_module_function(mrb_state *mrb, mrb_value mod)
2103
2158
  {
@@ -2146,6 +2201,40 @@ inspect_main(mrb_state *mrb, mrb_value mod)
2146
2201
  return mrb_str_new_lit(mrb, "main");
2147
2202
  }
2148
2203
 
2204
+ static const mrb_code new_iseq[] = {
2205
+ OP_ENTER, 0x0, 0x10, 0x1, /* OP_ENTER 0:0:1:0:0:0:1 */
2206
+ OP_LOADSELF, 0x3, /* OP_LOADSELF R3 */
2207
+ OP_SEND, 0x3, 0x0, 0x0, /* OP_SEND R3 :allocate 0 */
2208
+ OP_MOVE, 0x0, 0x3, /* OP_MOVE R0 R3 */
2209
+ OP_MOVE, 0x4, 0x1, /* OP_MOVE R4 R1 */
2210
+ OP_MOVE, 0x5, 0x2, /* OP_MOVE R5 R2 */
2211
+ OP_SENDVB, 0x3, 0x1, /* OP_SENDVB R4 :initialize */
2212
+ OP_RETURN, 0x0 /* OP_RETURN R0 */
2213
+ };
2214
+
2215
+ static void
2216
+ init_class_new(mrb_state *mrb, struct RClass *cls)
2217
+ {
2218
+ struct RProc *p;
2219
+ mrb_method_t m;
2220
+ mrb_irep *new_irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep));
2221
+ static const mrb_irep mrb_irep_zero = { 0 };
2222
+
2223
+ *new_irep = mrb_irep_zero;
2224
+ new_irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*2);
2225
+ new_irep->syms[0] = mrb_intern_lit(mrb, "allocate");
2226
+ new_irep->syms[1] = mrb_intern_lit(mrb, "initialize");
2227
+ new_irep->slen = 2;
2228
+ new_irep->flags = MRB_ISEQ_NO_FREE;
2229
+ new_irep->iseq = new_iseq;
2230
+ new_irep->ilen = sizeof(new_iseq);
2231
+ new_irep->nregs = 6;
2232
+ new_irep->nlocals = 3;
2233
+ p = mrb_proc_new(mrb, new_irep);
2234
+ MRB_METHOD_FROM_PROC(m, p);
2235
+ mrb_define_method_raw(mrb, cls, mrb_intern_lit(mrb, "new"), m);
2236
+ }
2237
+
2149
2238
  void
2150
2239
  mrb_init_class(mrb_state *mrb)
2151
2240
  {
@@ -2168,7 +2257,6 @@ mrb_init_class(mrb_state *mrb)
2168
2257
 
2169
2258
  /* name basic classes */
2170
2259
  mrb_define_const(mrb, bob, "BasicObject", mrb_obj_value(bob));
2171
- mrb_define_const(mrb, obj, "BasicObject", mrb_obj_value(bob));
2172
2260
  mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj));
2173
2261
  mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod));
2174
2262
  mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls));
@@ -2188,15 +2276,18 @@ mrb_init_class(mrb_state *mrb)
2188
2276
  mrb_define_method(mrb, bob, "==", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.1 */
2189
2277
  mrb_define_method(mrb, bob, "!=", mrb_obj_not_equal_m, MRB_ARGS_REQ(1));
2190
2278
  mrb_define_method(mrb, bob, "__id__", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.4 */
2191
- mrb_define_method(mrb, bob, "__send__", mrb_f_send, MRB_ARGS_ANY()); /* 15.3.1.3.5 */
2192
- mrb_define_method(mrb, bob, "instance_eval", mrb_obj_instance_eval, MRB_ARGS_ANY()); /* 15.3.1.3.18 */
2279
+ mrb_define_method(mrb, bob, "__send__", mrb_f_send, MRB_ARGS_REQ(1)|MRB_ARGS_REST()|MRB_ARGS_BLOCK()); /* 15.3.1.3.5 */
2280
+ mrb_define_method(mrb, bob, "equal?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.11 */
2281
+ mrb_define_method(mrb, bob, "instance_eval", mrb_obj_instance_eval, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.3.1.3.18 */
2193
2282
 
2194
- mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, MRB_ARGS_OPT(1));
2283
+ mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK());
2284
+ mrb_define_method(mrb, cls, "allocate", mrb_instance_alloc, MRB_ARGS_NONE());
2195
2285
  mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, MRB_ARGS_NONE()); /* 15.2.3.3.4 */
2196
- mrb_define_method(mrb, cls, "new", mrb_instance_new, MRB_ARGS_ANY()); /* 15.2.3.3.3 */
2197
2286
  mrb_define_method(mrb, cls, "initialize", mrb_class_initialize, MRB_ARGS_OPT(1)); /* 15.2.3.3.1 */
2198
2287
  mrb_define_method(mrb, cls, "inherited", mrb_bob_init, MRB_ARGS_REQ(1));
2199
2288
 
2289
+ init_class_new(mrb, cls);
2290
+
2200
2291
  MRB_SET_INSTANCE_TT(mod, MRB_TT_MODULE);
2201
2292
  mrb_define_method(mrb, mod, "extend_object", mrb_mod_extend_object, MRB_ARGS_REQ(1)); /* 15.2.2.4.25 */
2202
2293
  mrb_define_method(mrb, mod, "extended", mrb_bob_init, MRB_ARGS_REQ(1)); /* 15.2.2.4.26 */
@@ -2226,7 +2317,8 @@ mrb_init_class(mrb_state *mrb)
2226
2317
  mrb_define_method(mrb, mod, "const_missing", mrb_mod_const_missing, MRB_ARGS_REQ(1));
2227
2318
  mrb_define_method(mrb, mod, "method_defined?", mrb_mod_method_defined, MRB_ARGS_REQ(1)); /* 15.2.2.4.34 */
2228
2319
  mrb_define_method(mrb, mod, "define_method", mod_define_method, MRB_ARGS_ARG(1,1));
2229
- mrb_define_method(mrb, mod, "===", mrb_mod_eqq, MRB_ARGS_REQ(1));
2320
+ mrb_define_method(mrb, mod, "===", mrb_mod_eqq, MRB_ARGS_REQ(1)); /* 15.2.2.4.7 */
2321
+ mrb_define_method(mrb, mod, "dup", mrb_mod_dup, MRB_ARGS_NONE());
2230
2322
 
2231
2323
  mrb_undef_method(mrb, cls, "append_features");
2232
2324
  mrb_undef_method(mrb, cls, "extend_object");