script_core 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (529) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -57
  3. data/.ruby-version +1 -1
  4. data/Gemfile +2 -2
  5. data/README.md +7 -1
  6. data/ext/enterprise_script_service/Rakefile +1 -1
  7. data/ext/enterprise_script_service/libseccomp/.travis.yml +24 -12
  8. data/ext/enterprise_script_service/libseccomp/CHANGELOG +32 -0
  9. data/ext/enterprise_script_service/libseccomp/CONTRIBUTING.md +37 -26
  10. data/ext/enterprise_script_service/libseccomp/CREDITS +11 -0
  11. data/ext/enterprise_script_service/libseccomp/README.md +21 -1
  12. data/ext/enterprise_script_service/libseccomp/configure.ac +13 -8
  13. data/ext/enterprise_script_service/libseccomp/doc/Makefile.am +6 -0
  14. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_api_get.3 +12 -2
  15. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_arch_add.3 +38 -6
  16. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_attr_set.3 +53 -2
  17. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_export_bpf.3 +20 -2
  18. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_init.3 +9 -2
  19. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_load.3 +32 -2
  20. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_merge.3 +16 -2
  21. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_alloc.3 +113 -0
  22. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_fd.3 +1 -0
  23. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_free.3 +1 -0
  24. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_id_valid.3 +1 -0
  25. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_receive.3 +1 -0
  26. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_respond.3 +1 -0
  27. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_rule_add.3 +64 -3
  28. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_syscall_priority.3 +18 -3
  29. data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +19 -0
  30. data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +116 -0
  31. data/ext/enterprise_script_service/libseccomp/src/.gitignore +2 -0
  32. data/ext/enterprise_script_service/libseccomp/src/Makefile.am +31 -17
  33. data/ext/enterprise_script_service/libseccomp/src/api.c +254 -58
  34. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64.h +1 -9
  35. data/ext/enterprise_script_service/libseccomp/src/arch-arm.c +47 -2
  36. data/ext/enterprise_script_service/libseccomp/src/arch-arm.h +1 -9
  37. data/ext/enterprise_script_service/libseccomp/src/arch-gperf-generate +40 -0
  38. data/ext/enterprise_script_service/libseccomp/src/arch-mips.c +41 -4
  39. data/ext/enterprise_script_service/libseccomp/src/arch-mips.h +2 -10
  40. data/ext/enterprise_script_service/libseccomp/src/arch-mips64.c +41 -4
  41. data/ext/enterprise_script_service/libseccomp/src/arch-mips64.h +3 -11
  42. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.c +41 -4
  43. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.h +2 -10
  44. data/ext/enterprise_script_service/libseccomp/src/arch-parisc.h +1 -10
  45. data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.c +3 -3
  46. data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.h +29 -0
  47. data/ext/enterprise_script_service/libseccomp/src/arch-ppc.h +1 -9
  48. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.c +606 -8
  49. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.h +2 -10
  50. data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.c +31 -0
  51. data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.h +22 -0
  52. data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +171 -12
  53. data/ext/enterprise_script_service/libseccomp/src/arch-s390.h +1 -17
  54. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +166 -10
  55. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.h +1 -20
  56. data/ext/enterprise_script_service/libseccomp/src/arch-syscall-dump.c +8 -1
  57. data/ext/enterprise_script_service/libseccomp/src/arch-syscall-validate +359 -143
  58. data/ext/enterprise_script_service/libseccomp/src/arch-x32.c +36 -2
  59. data/ext/enterprise_script_service/libseccomp/src/arch-x32.h +2 -10
  60. data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +172 -10
  61. data/ext/enterprise_script_service/libseccomp/src/arch-x86.h +1 -14
  62. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64.h +1 -9
  63. data/ext/enterprise_script_service/libseccomp/src/arch.c +11 -3
  64. data/ext/enterprise_script_service/libseccomp/src/arch.h +7 -0
  65. data/ext/enterprise_script_service/libseccomp/src/db.c +268 -57
  66. data/ext/enterprise_script_service/libseccomp/src/db.h +16 -2
  67. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +503 -148
  68. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.h +2 -1
  69. data/ext/enterprise_script_service/libseccomp/src/gen_pfc.c +165 -37
  70. data/ext/enterprise_script_service/libseccomp/src/python/libseccomp.pxd +37 -1
  71. data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +295 -5
  72. data/ext/enterprise_script_service/libseccomp/src/syscalls.c +56 -0
  73. data/ext/enterprise_script_service/libseccomp/src/syscalls.csv +470 -0
  74. data/ext/enterprise_script_service/libseccomp/src/syscalls.h +62 -0
  75. data/ext/enterprise_script_service/libseccomp/src/syscalls.perf.template +82 -0
  76. data/ext/enterprise_script_service/libseccomp/src/system.c +196 -16
  77. data/ext/enterprise_script_service/libseccomp/src/system.h +68 -13
  78. data/ext/enterprise_script_service/libseccomp/tests/.gitignore +10 -2
  79. data/ext/enterprise_script_service/libseccomp/tests/06-sim-actions.tests +1 -1
  80. data/ext/enterprise_script_service/libseccomp/tests/11-basic-basic_errors.c +5 -5
  81. data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.c +35 -1
  82. data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.py +10 -1
  83. data/ext/enterprise_script_service/libseccomp/tests/15-basic-resolver.c +4 -3
  84. data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.c +12 -0
  85. data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.py +1 -0
  86. data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.c → 18-sim-basic_allowlist.c} +0 -0
  87. data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.py → 18-sim-basic_allowlist.py} +0 -0
  88. data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_allowlist.tests +32 -0
  89. data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.c +3 -0
  90. data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.py +1 -0
  91. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.c +3 -0
  92. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.py +1 -0
  93. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.tests +33 -17
  94. data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.c → 34-sim-basic_denylist.c} +0 -0
  95. data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.py → 34-sim-basic_denylist.py} +0 -0
  96. data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_denylist.tests +32 -0
  97. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.c +3 -0
  98. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.py +1 -0
  99. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.tests +25 -25
  100. data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.c +24 -3
  101. data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.py +16 -1
  102. data/ext/enterprise_script_service/libseccomp/tests/47-live-kill_process.c +3 -3
  103. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.c +112 -0
  104. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.py +60 -0
  105. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.tests +11 -0
  106. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.c +48 -0
  107. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.py +38 -0
  108. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.tests +11 -0
  109. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.c +156 -0
  110. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.py +95 -0
  111. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.tests +65 -0
  112. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.c +128 -0
  113. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.py +95 -0
  114. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.tests +11 -0
  115. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.c +134 -0
  116. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.sh +46 -0
  117. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.tests +11 -0
  118. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.c +90 -0
  119. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.py +65 -0
  120. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.tests +11 -0
  121. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.c +64 -0
  122. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.py +46 -0
  123. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.tests +11 -0
  124. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.c +116 -0
  125. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.py +61 -0
  126. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.tests +11 -0
  127. data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +34 -10
  128. data/ext/enterprise_script_service/libseccomp/tests/regression +10 -3
  129. data/ext/enterprise_script_service/libseccomp/tests/util.c +3 -3
  130. data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -3
  131. data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -1
  132. data/ext/enterprise_script_service/libseccomp/tools/scmp_arch_detect.c +3 -0
  133. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_disasm.c +4 -2
  134. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +4 -0
  135. data/ext/enterprise_script_service/libseccomp/tools/util.c +14 -12
  136. data/ext/enterprise_script_service/libseccomp/tools/util.h +7 -0
  137. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +149 -0
  138. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +55 -0
  139. data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
  140. data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
  141. data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
  142. data/ext/enterprise_script_service/mruby/.gitignore +3 -0
  143. data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
  144. data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
  145. data/ext/enterprise_script_service/mruby/.travis.yml +7 -10
  146. data/ext/enterprise_script_service/mruby/.yamllint +8 -0
  147. data/ext/enterprise_script_service/mruby/AUTHORS +4 -0
  148. data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
  149. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
  150. data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
  151. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  152. data/ext/enterprise_script_service/mruby/Makefile +1 -1
  153. data/ext/enterprise_script_service/mruby/README.md +5 -11
  154. data/ext/enterprise_script_service/mruby/Rakefile +18 -108
  155. data/ext/enterprise_script_service/mruby/TODO.md +17 -0
  156. data/ext/enterprise_script_service/mruby/appveyor.yml +29 -26
  157. data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
  158. data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
  159. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +4 -21
  160. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +4 -4
  161. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +3 -20
  162. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +4 -21
  163. data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
  164. data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
  165. 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
  166. data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
  167. data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
  168. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +4 -21
  169. data/ext/enterprise_script_service/mruby/{appveyor_config.rb → build_config/ci/gcc-clang.rb} +11 -8
  170. data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
  171. data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
  172. data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
  173. data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
  174. data/ext/enterprise_script_service/mruby/build_config/dreamcast_shelf.rb +94 -0
  175. data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
  176. data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
  177. data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
  178. data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
  179. data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
  180. data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
  181. data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
  182. data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
  183. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +142 -49
  184. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
  185. data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
  186. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +53 -30
  187. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
  188. data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
  189. data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
  190. data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
  191. data/ext/enterprise_script_service/mruby/doc/opcode.md +102 -103
  192. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
  193. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
  194. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
  195. data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
  196. data/ext/enterprise_script_service/mruby/include/mrbconf.h +88 -66
  197. data/ext/enterprise_script_service/mruby/include/mruby.h +160 -104
  198. data/ext/enterprise_script_service/mruby/include/mruby/array.h +27 -6
  199. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +80 -46
  200. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
  201. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +76 -55
  202. data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
  203. data/ext/enterprise_script_service/mruby/include/mruby/common.h +14 -1
  204. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +20 -6
  205. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  206. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +18 -52
  207. data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
  208. data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
  209. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
  210. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
  211. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +74 -14
  212. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -1
  213. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +19 -9
  214. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +37 -63
  215. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
  216. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +29 -24
  217. data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
  218. data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
  219. data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
  220. data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
  221. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +93 -21
  222. data/ext/enterprise_script_service/mruby/include/mruby/string.h +12 -16
  223. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
  224. data/ext/enterprise_script_service/mruby/include/mruby/value.h +60 -59
  225. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
  226. data/ext/enterprise_script_service/mruby/include/mruby/version.h +25 -6
  227. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -72
  228. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +71 -78
  229. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
  230. data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
  231. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +84 -32
  232. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
  233. data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
  234. data/ext/enterprise_script_service/mruby/lib/mruby/source.rb +3 -1
  235. data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
  236. data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
  237. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -81
  238. data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
  239. data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
  240. data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
  241. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -32
  242. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +10 -12
  243. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +0 -13
  244. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +30 -18
  245. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
  246. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
  247. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
  248. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
  249. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
  250. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -4
  251. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
  252. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +6 -2
  253. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
  254. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
  255. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +46 -35
  256. data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
  257. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
  258. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +41 -28
  259. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
  260. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -2
  261. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +26 -6
  262. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
  263. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +6 -2
  264. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
  265. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
  266. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -1
  267. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +495 -436
  268. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
  269. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
  270. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +637 -220
  271. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +13734 -0
  272. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +20 -23
  273. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +2 -2
  274. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +9 -9
  275. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
  276. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
  277. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
  278. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
  279. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +3 -3
  280. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +19 -238
  281. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +21 -0
  282. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +19 -15
  283. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +31 -5
  284. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
  285. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +5 -6
  286. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
  287. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +39 -7
  288. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +2 -8
  289. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
  290. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +0 -16
  291. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +9 -14
  292. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +107 -59
  293. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +22 -38
  294. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +417 -203
  295. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +20 -12
  296. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +33 -2
  297. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +58 -50
  298. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +13 -14
  299. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
  300. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
  301. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +56 -73
  302. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +13 -4
  303. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
  304. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +80 -78
  305. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
  306. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
  307. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +8 -16
  308. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -13
  309. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
  310. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
  311. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
  312. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
  313. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +120 -67
  314. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
  315. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +65 -26
  316. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +34 -21
  317. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
  318. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
  319. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
  320. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
  321. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +21 -43
  322. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
  323. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +12 -20
  324. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
  325. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
  326. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
  327. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +5 -5
  328. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
  329. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/mrbgem.rake +1 -1
  330. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
  331. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/sockettest.c +3 -2
  332. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +161 -93
  333. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +9 -25
  334. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
  335. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +17 -14
  336. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
  337. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +23 -36
  338. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +7 -6
  339. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  340. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
  341. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
  342. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +17 -44
  343. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
  344. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +37 -41
  345. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
  346. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
  347. data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
  348. data/ext/enterprise_script_service/mruby/mrblib/00class.rb +10 -0
  349. data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
  350. data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
  351. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
  352. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +3 -23
  353. data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
  354. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
  355. data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
  356. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
  357. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
  358. data/ext/enterprise_script_service/mruby/src/array.c +67 -90
  359. data/ext/enterprise_script_service/mruby/src/backtrace.c +18 -19
  360. data/ext/enterprise_script_service/mruby/src/class.c +819 -211
  361. data/ext/enterprise_script_service/mruby/src/codedump.c +226 -197
  362. data/ext/enterprise_script_service/mruby/src/debug.c +14 -11
  363. data/ext/enterprise_script_service/mruby/src/dump.c +470 -207
  364. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  365. data/ext/enterprise_script_service/mruby/src/error.c +94 -20
  366. data/ext/enterprise_script_service/mruby/src/etc.c +56 -39
  367. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +103 -27
  368. data/ext/enterprise_script_service/mruby/src/gc.c +86 -349
  369. data/ext/enterprise_script_service/mruby/src/hash.c +1058 -723
  370. data/ext/enterprise_script_service/mruby/src/kernel.c +78 -226
  371. data/ext/enterprise_script_service/mruby/src/load.c +215 -159
  372. data/ext/enterprise_script_service/mruby/src/numeric.c +400 -382
  373. data/ext/enterprise_script_service/mruby/src/object.c +115 -90
  374. data/ext/enterprise_script_service/mruby/src/print.c +31 -6
  375. data/ext/enterprise_script_service/mruby/src/proc.c +56 -45
  376. data/ext/enterprise_script_service/mruby/src/range.c +49 -33
  377. data/ext/enterprise_script_service/mruby/src/state.c +58 -42
  378. data/ext/enterprise_script_service/mruby/src/string.c +151 -156
  379. data/ext/enterprise_script_service/mruby/src/symbol.c +132 -66
  380. data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
  381. data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
  382. data/ext/enterprise_script_service/mruby/src/vm.c +655 -645
  383. data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
  384. data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
  385. data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
  386. data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
  387. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +64 -61
  388. data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
  389. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
  390. data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
  391. data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
  392. data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
  393. data/ext/enterprise_script_service/mruby/tasks/toolchains/android.rake +46 -1
  394. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +8 -7
  395. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +13 -17
  396. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +21 -25
  397. data/ext/enterprise_script_service/mruby/test/assert.rb +5 -4
  398. data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
  399. data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
  400. data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
  401. data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
  402. data/ext/enterprise_script_service/mruby/test/t/ensure.rb +8 -26
  403. data/ext/enterprise_script_service/mruby/test/t/exception.rb +2 -2
  404. data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
  405. data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
  406. data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
  407. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +16 -25
  408. data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
  409. data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
  410. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
  411. data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
  412. data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
  413. data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
  414. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
  415. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
  416. data/ext/enterprise_script_service/mruby_config.rb +2 -5
  417. data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
  418. data/ext/enterprise_script_service/msgpack/.github/depends/boost.sh +56 -0
  419. data/ext/enterprise_script_service/msgpack/.github/workflows/coverage.yml +62 -0
  420. data/ext/enterprise_script_service/msgpack/.github/workflows/gha.yml +304 -0
  421. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +11 -0
  422. data/ext/enterprise_script_service/msgpack/CMakeLists.txt +82 -39
  423. data/ext/enterprise_script_service/msgpack/Files.cmake +22 -12
  424. data/ext/enterprise_script_service/msgpack/QUICKSTART-C.md +26 -29
  425. data/ext/enterprise_script_service/msgpack/README.md +3 -2
  426. data/ext/enterprise_script_service/msgpack/appveyor.yml +6 -2
  427. data/ext/enterprise_script_service/msgpack/ci/build_cmake.sh +3 -1
  428. data/ext/enterprise_script_service/msgpack/cmake/CodeCoverage.cmake +55 -0
  429. data/ext/enterprise_script_service/msgpack/codecov.yml +36 -0
  430. data/ext/enterprise_script_service/msgpack/example/CMakeLists.txt +9 -5
  431. data/ext/enterprise_script_service/msgpack/example/boost/CMakeLists.txt +1 -1
  432. data/ext/enterprise_script_service/msgpack/example/c/CMakeLists.txt +17 -6
  433. data/ext/enterprise_script_service/msgpack/example/c/boundary.c +296 -0
  434. data/ext/enterprise_script_service/msgpack/example/c/jsonconv.c +419 -0
  435. data/ext/enterprise_script_service/msgpack/example/c/simple_c.c +1 -1
  436. data/ext/enterprise_script_service/msgpack/example/cpp03/CMakeLists.txt +3 -3
  437. data/ext/enterprise_script_service/msgpack/example/cpp11/CMakeLists.txt +2 -2
  438. data/ext/enterprise_script_service/msgpack/example/x3/CMakeLists.txt +2 -2
  439. data/ext/enterprise_script_service/msgpack/include/msgpack/pack.h +24 -1
  440. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +5 -4
  441. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/boost/optional.hpp +4 -4
  442. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp +8 -8
  443. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/map.hpp +4 -4
  444. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector.hpp +4 -4
  445. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_char.hpp +8 -8
  446. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_unsigned_char.hpp +8 -8
  447. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +4 -4
  448. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/unpack.hpp +6 -6
  449. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  450. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +4 -4
  451. data/ext/enterprise_script_service/msgpack/make_file_list.sh +38 -11
  452. data/ext/enterprise_script_service/msgpack/src/vrefbuffer.c +6 -0
  453. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +86 -64
  454. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +4 -0
  455. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +4 -0
  456. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +4 -0
  457. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +4 -1
  458. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +4 -0
  459. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +4 -0
  460. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +4 -47
  461. data/ext/enterprise_script_service/msgpack/test/buffer_c.cpp +148 -0
  462. data/ext/enterprise_script_service/msgpack/test/carray.cpp +4 -0
  463. data/ext/enterprise_script_service/msgpack/test/cases.cpp +8 -4
  464. data/ext/enterprise_script_service/msgpack/test/convert.cpp +8 -4
  465. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +4 -0
  466. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +4 -0
  467. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +4 -0
  468. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +4 -0
  469. data/ext/enterprise_script_service/msgpack/test/json.cpp +4 -0
  470. data/ext/enterprise_script_service/msgpack/test/limit.cpp +8 -4
  471. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +4 -0
  472. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +159 -0
  473. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +4 -0
  474. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +32 -27
  475. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +4 -0
  476. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +4 -0
  477. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +4 -1
  478. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +4 -0
  479. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +4 -0
  480. data/ext/enterprise_script_service/msgpack/test/object.cpp +4 -1
  481. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +12 -8
  482. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +30 -26
  483. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +4 -0
  484. data/ext/enterprise_script_service/msgpack/test/raw.cpp +4 -0
  485. data/ext/enterprise_script_service/msgpack/test/reference.cpp +4 -0
  486. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +4 -0
  487. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +4 -0
  488. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +4 -0
  489. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +4 -0
  490. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +8 -4
  491. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +4 -0
  492. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +4 -0
  493. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +16 -12
  494. data/ext/enterprise_script_service/msgpack/test/version.cpp +4 -0
  495. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +4 -0
  496. data/ext/enterprise_script_service/msgpack/test/zone.cpp +4 -0
  497. data/lib/script_core/engine.rb +24 -5
  498. data/lib/script_core/executable.rb +4 -3
  499. data/lib/script_core/version.rb +1 -1
  500. data/lib/tasks/script_core.rake +3 -1
  501. data/script_core.gemspec +1 -2
  502. data/spec/dummy/app/lib/script_engine.rb +64 -5
  503. data/spec/script_core_spec.rb +13 -0
  504. metadata +123 -61
  505. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +0 -559
  506. data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +0 -570
  507. data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +0 -562
  508. data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +0 -562
  509. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +0 -562
  510. data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +0 -542
  511. data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +0 -559
  512. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +0 -559
  513. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +0 -626
  514. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +0 -626
  515. data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +0 -558
  516. data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +0 -692
  517. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +0 -559
  518. data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_whitelist.tests +0 -32
  519. data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_blacklist.tests +0 -32
  520. data/ext/enterprise_script_service/mruby/TODO +0 -8
  521. data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
  522. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
  523. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
  524. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
  525. data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
  526. data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
  527. data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
  528. data/ext/enterprise_script_service/mruby/travis_config.rb +0 -54
  529. data/ext/enterprise_script_service/msgpack/.travis.yml +0 -258
@@ -14,6 +14,7 @@
14
14
  #include <mruby/error.h>
15
15
  #include <mruby/numeric.h>
16
16
  #include <mruby/data.h>
17
+ #include <mruby/presym.h>
17
18
 
18
19
  struct backtrace_location {
19
20
  int32_t lineno;
@@ -29,7 +30,7 @@ mrb_value mrb_exc_inspect(mrb_state *mrb, mrb_value exc);
29
30
  mrb_value mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace);
30
31
 
31
32
  static void
32
- each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtrace_func func, void *data)
33
+ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *data)
33
34
  {
34
35
  ptrdiff_t i;
35
36
 
@@ -39,8 +40,9 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
39
40
  for (i=ciidx; i >= 0; i--) {
40
41
  struct backtrace_location loc;
41
42
  mrb_callinfo *ci;
42
- mrb_irep *irep;
43
+ const mrb_irep *irep;
43
44
  const mrb_code *pc;
45
+ uint32_t idx;
44
46
 
45
47
  ci = &mrb->c->cibase[i];
46
48
 
@@ -50,21 +52,18 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
50
52
  irep = ci->proc->body.irep;
51
53
  if (!irep) continue;
52
54
 
53
- if (mrb->c->cibase[i].err) {
54
- pc = mrb->c->cibase[i].err;
55
- }
56
- else if (i+1 <= ciidx) {
57
- if (!mrb->c->cibase[i + 1].pc) continue;
58
- pc = &mrb->c->cibase[i+1].pc[-1];
55
+ if (mrb->c->cibase[i].pc) {
56
+ pc = &mrb->c->cibase[i].pc[-1];
59
57
  }
60
58
  else {
61
- pc = pc0;
59
+ continue;
62
60
  }
63
61
 
64
- loc.lineno = mrb_debug_get_line(mrb, irep, pc - irep->iseq);
62
+ idx = (uint32_t)(pc - irep->iseq);
63
+ loc.lineno = mrb_debug_get_line(mrb, irep, idx);
65
64
  if (loc.lineno == -1) continue;
66
65
 
67
- loc.filename = mrb_debug_get_filename(mrb, irep, pc - irep->iseq);
66
+ loc.filename = mrb_debug_get_filename(mrb, irep, idx);
68
67
  if (!loc.filename) {
69
68
  loc.filename = "(unknown)";
70
69
  }
@@ -74,12 +73,12 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
74
73
  }
75
74
  }
76
75
 
77
- #ifndef MRB_DISABLE_STDIO
76
+ #ifndef MRB_NO_STDIO
78
77
 
79
78
  static void
80
79
  print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
81
80
  {
82
- int i;
81
+ mrb_int i;
83
82
  mrb_int n = RARRAY_LEN(backtrace);
84
83
  mrb_value *loc, mesg;
85
84
  FILE *stream = stderr;
@@ -89,7 +88,7 @@ print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
89
88
  for (i=n-1,loc=&RARRAY_PTR(backtrace)[i]; i>0; i--,loc--) {
90
89
  if (mrb_string_p(*loc)) {
91
90
  fprintf(stream, "\t[%d] %.*s\n",
92
- i, (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
91
+ (int)i, (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
93
92
  }
94
93
  }
95
94
  if (mrb_string_p(*loc)) {
@@ -114,7 +113,7 @@ mrb_print_backtrace(mrb_state *mrb)
114
113
  return;
115
114
  }
116
115
 
117
- backtrace = mrb_obj_iv_get(mrb, mrb->exc, mrb_intern_lit(mrb, "backtrace"));
116
+ backtrace = mrb_obj_iv_get(mrb, mrb->exc, MRB_SYM(backtrace));
118
117
  if (mrb_nil_p(backtrace)) return;
119
118
  if (!mrb_array_p(backtrace)) backtrace = mrb_unpack_backtrace(mrb, backtrace);
120
119
  print_backtrace(mrb, mrb->exc, backtrace);
@@ -159,19 +158,19 @@ packed_backtrace(mrb_state *mrb)
159
158
  int size;
160
159
  void *ptr;
161
160
 
162
- each_backtrace(mrb, ciidx, mrb->c->ci->pc, count_backtrace_i, &len);
161
+ each_backtrace(mrb, ciidx, count_backtrace_i, &len);
163
162
  size = len * sizeof(struct backtrace_location);
164
163
  ptr = mrb_malloc(mrb, size);
165
164
  backtrace = mrb_data_object_alloc(mrb, NULL, ptr, &bt_type);
166
165
  backtrace->flags = (uint32_t)len;
167
- each_backtrace(mrb, ciidx, mrb->c->ci->pc, pack_backtrace_i, &ptr);
166
+ each_backtrace(mrb, ciidx, pack_backtrace_i, &ptr);
168
167
  return mrb_obj_value(backtrace);
169
168
  }
170
169
 
171
170
  void
172
171
  mrb_keep_backtrace(mrb_state *mrb, mrb_value exc)
173
172
  {
174
- mrb_sym sym = mrb_intern_lit(mrb, "backtrace");
173
+ mrb_sym sym = MRB_SYM(backtrace);
175
174
  mrb_value backtrace;
176
175
  int ai;
177
176
 
@@ -221,7 +220,7 @@ mrb_exc_backtrace(mrb_state *mrb, mrb_value exc)
221
220
  mrb_sym attr_name;
222
221
  mrb_value backtrace;
223
222
 
224
- attr_name = mrb_intern_lit(mrb, "backtrace");
223
+ attr_name = MRB_SYM(backtrace);
225
224
  backtrace = mrb_iv_get(mrb, exc, attr_name);
226
225
  if (mrb_nil_p(backtrace) || mrb_array_p(backtrace)) {
227
226
  return backtrace;
@@ -17,48 +17,284 @@
17
17
  #include <mruby/data.h>
18
18
  #include <mruby/istruct.h>
19
19
  #include <mruby/opcode.h>
20
+ #include <mruby/presym.h>
20
21
 
21
- KHASH_DEFINE(mt, mrb_sym, mrb_method_t, TRUE, kh_int_hash_func, kh_int_hash_equal)
22
+ union mt_ptr {
23
+ struct RProc *proc;
24
+ mrb_func_t func;
25
+ };
26
+
27
+ struct mt_elem {
28
+ union mt_ptr ptr;
29
+ size_t func_p:1;
30
+ size_t noarg_p:1;
31
+ mrb_sym key:sizeof(mrb_sym)*8-2;
32
+ };
33
+
34
+ /* method table structure */
35
+ typedef struct mt_tbl {
36
+ size_t size;
37
+ size_t alloc;
38
+ struct mt_elem *table;
39
+ } mt_tbl;
40
+
41
+ /* Creates the method table. */
42
+ static mt_tbl*
43
+ mt_new(mrb_state *mrb)
44
+ {
45
+ mt_tbl *t;
46
+
47
+ t = (mt_tbl*)mrb_malloc(mrb, sizeof(mt_tbl));
48
+ t->size = 0;
49
+ t->alloc = 0;
50
+ t->table = NULL;
51
+
52
+ return t;
53
+ }
54
+
55
+ static struct mt_elem *mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr);
56
+
57
+ static void
58
+ mt_rehash(mrb_state *mrb, mt_tbl *t)
59
+ {
60
+ size_t old_alloc = t->alloc;
61
+ size_t new_alloc = old_alloc+1;
62
+ struct mt_elem *old_table = t->table;
63
+
64
+ khash_power2(new_alloc);
65
+ if (old_alloc == new_alloc) return;
66
+
67
+ t->alloc = new_alloc;
68
+ t->size = 0;
69
+ t->table = (struct mt_elem*)mrb_calloc(mrb, sizeof(struct mt_elem), new_alloc);
70
+
71
+ for (size_t i = 0; i < old_alloc; i++) {
72
+ struct mt_elem *slot = &old_table[i];
73
+
74
+ /* key = 0 means empty or deleted */
75
+ if (slot->key != 0) {
76
+ mt_put(mrb, t, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
77
+ }
78
+ }
79
+ mrb_free(mrb, old_table);
80
+ }
81
+
82
+ #define slot_empty_p(slot) ((slot)->key == 0 && (slot)->func_p == 0)
83
+
84
+ /* Set the value for the symbol in the method table. */
85
+ static struct mt_elem*
86
+ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr)
87
+ {
88
+ size_t hash, pos, start;
89
+ struct mt_elem *dslot = NULL;
90
+
91
+ if (t->alloc == 0) {
92
+ mt_rehash(mrb, t);
93
+ }
94
+ hash = kh_int_hash_func(mrb, sym);
95
+ start = pos = hash & (t->alloc-1);
96
+ for (;;) {
97
+ struct mt_elem *slot = &t->table[pos];
98
+
99
+ if (slot->key == sym) {
100
+ slot->func_p = func_p;
101
+ slot->noarg_p = noarg_p;
102
+ slot->ptr = ptr;
103
+ return slot;
104
+ }
105
+ else if (slot->key == 0) { /* empty or deleted */
106
+ if (slot->func_p == 0) { /* empty */
107
+ t->size++;
108
+ slot->key = sym;
109
+ slot->func_p = func_p;
110
+ slot->noarg_p = noarg_p;
111
+ slot->ptr = ptr;
112
+ return slot;
113
+ }
114
+ else if (!dslot) { /* deleted */
115
+ dslot = slot;
116
+ }
117
+ }
118
+ pos = (pos+1) & (t->alloc-1);
119
+ if (pos == start) { /* not found */
120
+ if (dslot) {
121
+ t->size++;
122
+ dslot->key = sym;
123
+ dslot->func_p = func_p;
124
+ dslot->noarg_p = noarg_p;
125
+ dslot->ptr = ptr;
126
+ return dslot;
127
+ }
128
+ /* no room */
129
+ mt_rehash(mrb, t);
130
+ start = pos = hash & (t->alloc-1);
131
+ }
132
+ }
133
+ }
134
+
135
+ /* Get a value for a symbol from the method table. */
136
+ static struct mt_elem*
137
+ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym)
138
+ {
139
+ size_t hash, pos, start;
140
+
141
+ if (t == NULL) return NULL;
142
+ if (t->alloc == 0) return NULL;
143
+ if (t->size == 0) return NULL;
144
+
145
+ hash = kh_int_hash_func(mrb, sym);
146
+ start = pos = hash & (t->alloc-1);
147
+ for (;;) {
148
+ struct mt_elem *slot = &t->table[pos];
149
+
150
+ if (slot->key == sym) {
151
+ return slot;
152
+ }
153
+ else if (slot_empty_p(slot)) {
154
+ return NULL;
155
+ }
156
+ pos = (pos+1) & (t->alloc-1);
157
+ if (pos == start) { /* not found */
158
+ return NULL;
159
+ }
160
+ }
161
+ }
162
+
163
+ /* Deletes the value for the symbol from the method table. */
164
+ static mrb_bool
165
+ mt_del(mrb_state *mrb, mt_tbl *t, mrb_sym sym)
166
+ {
167
+ size_t hash, pos, start;
168
+
169
+ if (t == NULL) return FALSE;
170
+ if (t->alloc == 0) return FALSE;
171
+ if (t->size == 0) return FALSE;
172
+
173
+ hash = kh_int_hash_func(mrb, sym);
174
+ start = pos = hash & (t->alloc-1);
175
+ for (;;) {
176
+ struct mt_elem *slot = &t->table[pos];
177
+
178
+ if (slot->key == sym) {
179
+ t->size--;
180
+ slot->key = 0;
181
+ slot->func_p = 1;
182
+ return TRUE;
183
+ }
184
+ else if (slot_empty_p(slot)) {
185
+ return FALSE;
186
+ }
187
+ pos = (pos+1) & (t->alloc-1);
188
+ if (pos == start) { /* not found */
189
+ return FALSE;
190
+ }
191
+ }
192
+ }
193
+
194
+ /* Copy the method table. */
195
+ static struct mt_tbl*
196
+ mt_copy(mrb_state *mrb, mt_tbl *t)
197
+ {
198
+ mt_tbl *t2;
199
+ size_t i;
200
+
201
+ if (t == NULL) return NULL;
202
+ if (t->alloc == 0) return NULL;
203
+ if (t->size == 0) return NULL;
204
+
205
+ t2 = mt_new(mrb);
206
+ for (i=0; i<t->alloc; i++) {
207
+ struct mt_elem *slot = &t->table[i];
208
+
209
+ if (slot->key) {
210
+ mt_put(mrb, t2, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
211
+ }
212
+ }
213
+ return t2;
214
+ }
215
+
216
+ /* Free memory of the method table. */
217
+ static void
218
+ mt_free(mrb_state *mrb, mt_tbl *t)
219
+ {
220
+ mrb_free(mrb, t->table);
221
+ mrb_free(mrb, t);
222
+ }
223
+
224
+ MRB_API void
225
+ mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *p)
226
+ {
227
+ mt_tbl *t = c->mt;
228
+ size_t i;
229
+
230
+ if (t == NULL) return;
231
+ if (t->alloc == 0) return;
232
+ if (t->size == 0) return;
233
+
234
+ for (i=0; i<t->alloc; i++) {
235
+ struct mt_elem *slot = &t->table[i];
236
+
237
+ if (slot->key) {
238
+ mrb_method_t m;
239
+
240
+ if (slot->func_p) {
241
+ MRB_METHOD_FROM_FUNC(m, slot->ptr.func);
242
+ }
243
+ else {
244
+ MRB_METHOD_FROM_PROC(m, slot->ptr.proc);
245
+ }
246
+ if (slot->noarg_p) {
247
+ MRB_METHOD_NOARG_SET(m);
248
+ }
249
+
250
+ if (fn(mrb, slot->key, m, p) != 0)
251
+ return;
252
+ }
253
+ }
254
+ return;
255
+ }
22
256
 
23
257
  void
24
258
  mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c)
25
259
  {
26
- khiter_t k;
27
- khash_t(mt) *h = c->mt;
260
+ mt_tbl *t = c->mt;
261
+ size_t i;
28
262
 
29
- if (!h) return;
30
- for (k = kh_begin(h); k != kh_end(h); k++) {
31
- if (kh_exist(h, k)) {
32
- mrb_method_t m = kh_value(h, k);
263
+ if (t == NULL) return;
264
+ if (t->alloc == 0) return;
265
+ if (t->size == 0) return;
33
266
 
34
- if (MRB_METHOD_PROC_P(m)) {
35
- struct RProc *p = MRB_METHOD_PROC(m);
36
- mrb_gc_mark(mrb, (struct RBasic*)p);
37
- }
267
+ for (i=0; i<t->alloc; i++) {
268
+ struct mt_elem *slot = &t->table[i];
269
+
270
+ if (slot->key && !slot->func_p) { /* Proc pointer */
271
+ struct RProc *p = slot->ptr.proc;
272
+ mrb_gc_mark(mrb, (struct RBasic*)p);
38
273
  }
39
274
  }
275
+ return;
40
276
  }
41
277
 
42
278
  size_t
43
279
  mrb_gc_mark_mt_size(mrb_state *mrb, struct RClass *c)
44
280
  {
45
- khash_t(mt) *h = c->mt;
281
+ struct mt_tbl *h = c->mt;
46
282
 
47
283
  if (!h) return 0;
48
- return kh_size(h);
284
+ return h->size;
49
285
  }
50
286
 
51
287
  void
52
288
  mrb_gc_free_mt(mrb_state *mrb, struct RClass *c)
53
289
  {
54
- kh_destroy(mt, mrb, c->mt);
290
+ if (c->mt) mt_free(mrb, c->mt);
55
291
  }
56
292
 
57
293
  void
58
294
  mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb_sym id)
59
295
  {
60
296
  mrb_value name;
61
- mrb_sym nsym = mrb_intern_lit(mrb, "__classname__");
297
+ mrb_sym nsym = MRB_SYM(__classname__);
62
298
 
63
299
  if (mrb_obj_iv_defined(mrb, (struct RObject*)c, nsym)) return;
64
300
  if (outer == NULL || outer == mrb->object_class) {
@@ -68,7 +304,7 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
68
304
  name = mrb_class_path(mrb, outer);
69
305
  if (mrb_nil_p(name)) { /* unnamed outer class */
70
306
  if (outer != mrb->object_class && outer != c) {
71
- mrb_obj_iv_set_force(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"),
307
+ mrb_obj_iv_set_force(mrb, (struct RObject*)c, MRB_SYM(__outer__),
72
308
  mrb_obj_value(outer));
73
309
  }
74
310
  return;
@@ -107,7 +343,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
107
343
  if (o->c->tt == MRB_TT_SCLASS) return;
108
344
  sc = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_SCLASS, mrb->class_class);
109
345
  sc->flags |= MRB_FL_CLASS_IS_INHERITED;
110
- sc->mt = kh_init(mt, mrb);
346
+ sc->mt = mt_new(mrb);
111
347
  sc->iv = 0;
112
348
  if (o->tt == MRB_TT_CLASS) {
113
349
  c = (struct RClass*)o;
@@ -132,7 +368,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
132
368
  o->c = sc;
133
369
  mrb_field_write_barrier(mrb, (struct RBasic*)o, (struct RBasic*)sc);
134
370
  mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)o);
135
- mrb_obj_iv_set(mrb, (struct RObject*)sc, mrb_intern_lit(mrb, "__attached__"), mrb_obj_value(o));
371
+ mrb_obj_iv_set(mrb, (struct RObject*)sc, MRB_SYM(__attached__), mrb_obj_value(o));
136
372
  sc->flags |= o->flags & MRB_FL_OBJ_IS_FROZEN;
137
373
  }
138
374
 
@@ -229,6 +465,15 @@ mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id)
229
465
  return define_module(mrb, id, mrb_class_ptr(outer));
230
466
  }
231
467
 
468
+ MRB_API struct RClass*
469
+ mrb_define_module_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
470
+ {
471
+ struct RClass * c = define_module(mrb, name, outer);
472
+
473
+ setup_class(mrb, outer, c, name);
474
+ return c;
475
+ }
476
+
232
477
  MRB_API struct RClass*
233
478
  mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name)
234
479
  {
@@ -283,12 +528,10 @@ mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super)
283
528
  }
284
529
 
285
530
  static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value);
286
- #ifdef MRB_METHOD_CACHE
287
- static void mc_clear_all(mrb_state *mrb);
288
- static void mc_clear_by_id(mrb_state *mrb, struct RClass*, mrb_sym);
531
+ #ifndef MRB_NO_METHOD_CACHE
532
+ static void mc_clear(mrb_state *mrb);
289
533
  #else
290
- #define mc_clear_all(mrb)
291
- #define mc_clear_by_id(mrb,c,s)
534
+ #define mc_clear(mrb)
292
535
  #endif
293
536
 
294
537
  static void
@@ -302,7 +545,7 @@ mrb_class_inherited(mrb_state *mrb, struct RClass *super, struct RClass *klass)
302
545
  super->flags |= MRB_FL_CLASS_IS_INHERITED;
303
546
  s = mrb_obj_value(super);
304
547
  mrb_mc_clear_by_class(mrb, klass);
305
- mid = mrb_intern_lit(mrb, "inherited");
548
+ mid = MRB_SYM(inherited);
306
549
  if (!mrb_func_basic_p(mrb, s, mid, mrb_bob_init)) {
307
550
  mrb_value c = mrb_obj_value(klass);
308
551
  mrb_funcall_argv(mrb, s, mid, 1, &c);
@@ -349,21 +592,29 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
349
592
  MRB_API mrb_bool
350
593
  mrb_class_defined(mrb_state *mrb, const char *name)
351
594
  {
352
- mrb_value sym = mrb_check_intern_cstr(mrb, name);
353
- if (mrb_nil_p(sym)) {
354
- return FALSE;
355
- }
356
- return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_symbol(sym));
595
+ mrb_sym sym = mrb_intern_check_cstr(mrb, name);
596
+ if (!sym) return FALSE;
597
+ return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), sym);
598
+ }
599
+
600
+ MRB_API mrb_bool
601
+ mrb_class_defined_id(mrb_state *mrb, mrb_sym name)
602
+ {
603
+ return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), name);
357
604
  }
358
605
 
359
606
  MRB_API mrb_bool
360
607
  mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name)
361
608
  {
362
- mrb_value sym = mrb_check_intern_cstr(mrb, name);
363
- if (mrb_nil_p(sym)) {
364
- return FALSE;
365
- }
366
- return mrb_const_defined_at(mrb, mrb_obj_value(outer), mrb_symbol(sym));
609
+ mrb_sym sym = mrb_intern_check_cstr(mrb, name);
610
+ if (!sym) return FALSE;
611
+ return mrb_const_defined_at(mrb, mrb_obj_value(outer), sym);
612
+ }
613
+
614
+ MRB_API mrb_bool
615
+ mrb_class_defined_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
616
+ {
617
+ return mrb_const_defined_at(mrb, mrb_obj_value(outer), name);
367
618
  }
368
619
 
369
620
  MRB_API struct RClass*
@@ -372,6 +623,12 @@ mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
372
623
  return class_from_sym(mrb, outer, mrb_intern_cstr(mrb, name));
373
624
  }
374
625
 
626
+ MRB_API struct RClass*
627
+ mrb_class_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
628
+ {
629
+ return class_from_sym(mrb, outer, name);
630
+ }
631
+
375
632
  MRB_API struct RClass*
376
633
  mrb_class_get(mrb_state *mrb, const char *name)
377
634
  {
@@ -379,11 +636,16 @@ mrb_class_get(mrb_state *mrb, const char *name)
379
636
  }
380
637
 
381
638
  MRB_API struct RClass*
382
- mrb_exc_get(mrb_state *mrb, const char *name)
639
+ mrb_class_get_id(mrb_state *mrb, mrb_sym name)
640
+ {
641
+ return mrb_class_get_under_id(mrb, mrb->object_class, name);
642
+ }
643
+
644
+ MRB_API struct RClass*
645
+ mrb_exc_get_id(mrb_state *mrb, mrb_sym name)
383
646
  {
384
647
  struct RClass *exc, *e;
385
- mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class),
386
- mrb_intern_cstr(mrb, name));
648
+ mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), name);
387
649
 
388
650
  if (!mrb_class_p(c)) {
389
651
  mrb_raise(mrb, mrb->eException_class, "exception corrupted");
@@ -404,12 +666,24 @@ mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
404
666
  return module_from_sym(mrb, outer, mrb_intern_cstr(mrb, name));
405
667
  }
406
668
 
669
+ MRB_API struct RClass*
670
+ mrb_module_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
671
+ {
672
+ return module_from_sym(mrb, outer, name);
673
+ }
674
+
407
675
  MRB_API struct RClass*
408
676
  mrb_module_get(mrb_state *mrb, const char *name)
409
677
  {
410
678
  return mrb_module_get_under(mrb, mrb->object_class, name);
411
679
  }
412
680
 
681
+ MRB_API struct RClass*
682
+ mrb_module_get_id(mrb_state *mrb, mrb_sym name)
683
+ {
684
+ return mrb_module_get_under_id(mrb, mrb->object_class, name);
685
+ }
686
+
413
687
  /*!
414
688
  * Defines a class under the namespace of \a outer.
415
689
  * \param outer a class which contains the new class.
@@ -427,9 +701,8 @@ mrb_module_get(mrb_state *mrb, const char *name)
427
701
  * \a super, the function just returns the defined class.
428
702
  */
429
703
  MRB_API struct RClass*
430
- mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super)
704
+ mrb_define_class_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name, struct RClass *super)
431
705
  {
432
- mrb_sym id = mrb_intern_cstr(mrb, name);
433
706
  struct RClass * c;
434
707
 
435
708
  #if 0
@@ -437,34 +710,45 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s
437
710
  mrb_warn(mrb, "no super class for '%C::%n', Object assumed", outer, id);
438
711
  }
439
712
  #endif
440
- c = define_class(mrb, id, super, outer);
441
- setup_class(mrb, outer, c, id);
713
+ c = define_class(mrb, name, super, outer);
714
+ setup_class(mrb, outer, c, name);
442
715
  return c;
443
716
  }
444
717
 
718
+ MRB_API struct RClass*
719
+ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super)
720
+ {
721
+ return mrb_define_class_under_id(mrb, outer, mrb_intern_cstr(mrb, name), super);
722
+ }
723
+
445
724
  MRB_API void
446
725
  mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_t m)
447
726
  {
448
- khash_t(mt) *h;
449
- khiter_t k;
727
+ mt_tbl *h;
728
+ union mt_ptr ptr;
729
+
450
730
  MRB_CLASS_ORIGIN(c);
451
731
  h = c->mt;
452
-
453
732
  mrb_check_frozen(mrb, c);
454
- if (!h) h = c->mt = kh_init(mt, mrb);
455
- k = kh_put(mt, mrb, h, mid);
456
- kh_value(h, k) = m;
457
- if (MRB_METHOD_PROC_P(m) && !MRB_METHOD_UNDEF_P(m)) {
733
+ if (!h) h = c->mt = mt_new(mrb);
734
+ if (MRB_METHOD_PROC_P(m)) {
458
735
  struct RProc *p = MRB_METHOD_PROC(m);
459
736
 
460
- p->flags |= MRB_PROC_SCOPE;
461
- p->c = NULL;
462
- mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)p);
463
- if (!MRB_PROC_ENV_P(p)) {
464
- MRB_PROC_SET_TARGET_CLASS(p, c);
737
+ ptr.proc = p;
738
+ if (p) {
739
+ p->flags |= MRB_PROC_SCOPE;
740
+ p->c = NULL;
741
+ mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)p);
742
+ if (!MRB_PROC_ENV_P(p)) {
743
+ MRB_PROC_SET_TARGET_CLASS(p, c);
744
+ }
465
745
  }
466
746
  }
467
- mc_clear_by_id(mrb, c, mid);
747
+ else {
748
+ ptr.func = MRB_METHOD_FUNC(m);
749
+ }
750
+ mt_put(mrb, h, mid, MRB_METHOD_FUNC_P(m), MRB_METHOD_NOARG_P(m), ptr);
751
+ mc_clear(mrb);
468
752
  }
469
753
 
470
754
  MRB_API void
@@ -474,6 +758,9 @@ mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t f
474
758
  int ai = mrb_gc_arena_save(mrb);
475
759
 
476
760
  MRB_METHOD_FROM_FUNC(m, func);
761
+ #ifndef MRB_USE_METHOD_T_STRUCT
762
+ mrb_assert(MRB_METHOD_FUNC(m) == func);
763
+ #endif
477
764
  if (aspec == MRB_ARGS_NONE()) {
478
765
  MRB_METHOD_NOARG_SET(m);
479
766
  }
@@ -529,18 +816,18 @@ mrb_get_argc(mrb_state *mrb)
529
816
  mrb_int argc = mrb->c->ci->argc;
530
817
 
531
818
  if (argc < 0) {
532
- struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
819
+ struct RArray *a = mrb_ary_ptr(mrb->c->ci->stack[1]);
533
820
 
534
821
  argc = ARY_LEN(a);
535
822
  }
536
823
  return argc;
537
824
  }
538
825
 
539
- MRB_API mrb_value*
826
+ MRB_API const mrb_value*
540
827
  mrb_get_argv(mrb_state *mrb)
541
828
  {
542
829
  mrb_int argc = mrb->c->ci->argc;
543
- mrb_value *array_argv = mrb->c->stack + 1;
830
+ mrb_value *array_argv = mrb->c->ci->stack + 1;
544
831
  if (argc < 0) {
545
832
  struct RArray *a = mrb_ary_ptr(*array_argv);
546
833
 
@@ -549,6 +836,23 @@ mrb_get_argv(mrb_state *mrb)
549
836
  return array_argv;
550
837
  }
551
838
 
839
+ MRB_API mrb_value
840
+ mrb_get_arg1(mrb_state *mrb)
841
+ {
842
+ mrb_int argc = mrb->c->ci->argc;
843
+ mrb_value *array_argv = mrb->c->ci->stack + 1;
844
+ if (argc < 0) {
845
+ struct RArray *a = mrb_ary_ptr(*array_argv);
846
+
847
+ argc = ARY_LEN(a);
848
+ array_argv = ARY_PTR(a);
849
+ }
850
+ if (argc != 1) {
851
+ mrb_argnum_error(mrb, argc, 1, 1);
852
+ }
853
+ return array_argv[0];
854
+ }
855
+
552
856
  void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
553
857
 
554
858
  /*
@@ -567,17 +871,18 @@ void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
567
871
  S: String [mrb_value] when ! follows, the value may be nil
568
872
  A: Array [mrb_value] when ! follows, the value may be nil
569
873
  H: Hash [mrb_value] when ! follows, the value may be nil
570
- s: String [char*,mrb_int] Receive two arguments; s! gives (NULL,0) for nil
571
- z: String [char*] NUL terminated string; z! gives NULL for nil
572
- a: Array [mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil
573
- f: Fixnum/Float [mrb_float]
574
- i: Fixnum/Float [mrb_int]
874
+ s: String [const char*,mrb_int] Receive two arguments; s! gives (NULL,0) for nil
875
+ z: String [const char*] NUL terminated string; z! gives NULL for nil
876
+ a: Array [const mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil
877
+ c: Class/Module [strcut RClass*]
878
+ f: Integer/Float [mrb_float]
879
+ i: Integer/Float [mrb_int]
575
880
  b: boolean [mrb_bool]
576
881
  n: String/Symbol [mrb_sym]
577
882
  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
578
883
  I: inline struct [void*]
579
884
  &: block [mrb_value] &! raises exception if no block given
580
- *: rest argument [mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack
885
+ *: rest argument [const mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack
581
886
  |: optional Following arguments are optional
582
887
  ?: optional given [mrb_bool] true if preceding argument (optional) is given
583
888
  ':': keyword args [mrb_kwargs const] Get keyword arguments
@@ -590,14 +895,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
590
895
  mrb_int i = 0;
591
896
  va_list ap;
592
897
  mrb_int argc = mrb->c->ci->argc;
593
- mrb_value *array_argv = mrb->c->stack+1;
898
+ mrb_value *array_argv = mrb->c->ci->stack+1;
594
899
  mrb_bool argv_on_stack = argc >= 0;
595
900
  mrb_bool opt = FALSE;
596
901
  mrb_bool opt_skip = TRUE;
597
902
  mrb_bool given = TRUE;
598
903
  mrb_value kdict;
599
904
  mrb_bool reqkarg = FALSE;
600
- mrb_int needargc = 0;
905
+ int argc_min = 0, argc_max = 0;
601
906
 
602
907
  if (!argv_on_stack) {
603
908
  struct RArray *a = mrb_ary_ptr(*array_argv);
@@ -615,6 +920,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
615
920
  break;
616
921
  case '*':
617
922
  opt_skip = FALSE;
923
+ argc_max = -1;
618
924
  if (!reqkarg) reqkarg = strchr(fmt, ':') ? TRUE : FALSE;
619
925
  goto check_exit;
620
926
  case '!':
@@ -626,13 +932,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
626
932
  if (opt) opt_skip = FALSE;
627
933
  break;
628
934
  default:
629
- if (!opt) needargc ++;
935
+ if (!opt) argc_min++;
936
+ argc_max++;
630
937
  break;
631
938
  }
632
939
  }
633
940
 
634
941
  check_exit:
635
- if (reqkarg && argc > needargc && mrb_hash_p(kdict = ARGV[argc - 1])) {
942
+ if (reqkarg && argc > argc_min && mrb_hash_p(kdict = ARGV[argc - 1])) {
636
943
  mrb_hash_check_kdict(mrb, kdict);
637
944
  argc --;
638
945
  }
@@ -655,7 +962,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
655
962
  given = FALSE;
656
963
  }
657
964
  else {
658
- mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
965
+ mrb_argnum_error(mrb, argc, argc_min, argc_max);
659
966
  }
660
967
  }
661
968
  break;
@@ -696,6 +1003,22 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
696
1003
  }
697
1004
  }
698
1005
  break;
1006
+ case 'c':
1007
+ {
1008
+ struct RClass **p;
1009
+
1010
+ p = va_arg(ap, struct RClass**);
1011
+ if (i < argc) {
1012
+ mrb_value ss;
1013
+
1014
+ ss = argv[i++];
1015
+ if (!class_ptr_p(ss)) {
1016
+ mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss);
1017
+ }
1018
+ *p = mrb_class_ptr(ss);
1019
+ }
1020
+ }
1021
+ break;
699
1022
  case 'S':
700
1023
  {
701
1024
  mrb_value *p;
@@ -738,10 +1061,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
738
1061
  case 's':
739
1062
  {
740
1063
  mrb_value ss;
741
- char **ps = 0;
1064
+ const char **ps = 0;
742
1065
  mrb_int *pl = 0;
743
1066
 
744
- ps = va_arg(ap, char**);
1067
+ ps = va_arg(ap, const char**);
745
1068
  pl = va_arg(ap, mrb_int*);
746
1069
  if (i < argc) {
747
1070
  ss = argv[i++];
@@ -779,10 +1102,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
779
1102
  {
780
1103
  mrb_value aa;
781
1104
  struct RArray *a;
782
- mrb_value **pb;
1105
+ const mrb_value **pb;
783
1106
  mrb_int *pl;
784
1107
 
785
- pb = va_arg(ap, mrb_value**);
1108
+ pb = va_arg(ap, const mrb_value**);
786
1109
  pl = va_arg(ap, mrb_int*);
787
1110
  if (i < argc) {
788
1111
  aa = argv[i++];
@@ -815,7 +1138,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
815
1138
  }
816
1139
  }
817
1140
  break;
818
- #ifndef MRB_WITHOUT_FLOAT
1141
+ #ifndef MRB_NO_FLOAT
819
1142
  case 'f':
820
1143
  {
821
1144
  mrb_float *p;
@@ -833,7 +1156,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
833
1156
 
834
1157
  p = va_arg(ap, mrb_int*);
835
1158
  if (i < argc) {
836
- *p = mrb_fixnum(mrb_to_int(mrb, argv[i++]));
1159
+ *p = mrb_integer(mrb_to_int(mrb, argv[i++]));
837
1160
  }
838
1161
  }
839
1162
  break;
@@ -885,10 +1208,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
885
1208
 
886
1209
  p = va_arg(ap, mrb_value*);
887
1210
  if (mrb->c->ci->argc < 0) {
888
- bp = mrb->c->stack + 2;
1211
+ bp = mrb->c->ci->stack + 2;
889
1212
  }
890
1213
  else {
891
- bp = mrb->c->stack + mrb->c->ci->argc + 1;
1214
+ bp = mrb->c->ci->stack + mrb->c->ci->argc + 1;
892
1215
  }
893
1216
  if (altmode && mrb_nil_p(*bp)) {
894
1217
  mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
@@ -911,11 +1234,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
911
1234
 
912
1235
  case '*':
913
1236
  {
914
- mrb_value **var;
1237
+ const mrb_value **var;
915
1238
  mrb_int *pl;
916
- mrb_bool nocopy = altmode || argv_on_stack ? TRUE : FALSE;
1239
+ mrb_bool nocopy = (altmode || !argv_on_stack) ? TRUE : FALSE;
917
1240
 
918
- var = va_arg(ap, mrb_value**);
1241
+ var = va_arg(ap, const mrb_value**);
919
1242
  pl = va_arg(ap, mrb_int*);
920
1243
  if (argc > i) {
921
1244
  *pl = argc-i;
@@ -950,7 +1273,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
950
1273
  else {
951
1274
  uint32_t kwnum = kwargs->num;
952
1275
  uint32_t required = kwargs->required;
953
- const char *const *kname = kwargs->table;
1276
+ const mrb_sym *kname = kwargs->table;
954
1277
  mrb_value *values = kwargs->values;
955
1278
  uint32_t j;
956
1279
  const uint32_t keyword_max = 40;
@@ -960,16 +1283,16 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
960
1283
  }
961
1284
 
962
1285
  for (j = required; j > 0; j --, kname ++, values ++) {
963
- mrb_value k = mrb_symbol_value(mrb_intern_cstr(mrb, *kname));
1286
+ mrb_value k = mrb_symbol_value(*kname);
964
1287
  if (!mrb_hash_key_p(mrb, ksrc, k)) {
965
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "missing keyword: %s", *kname);
1288
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "missing keyword: %n", *kname);
966
1289
  }
967
1290
  *values = mrb_hash_delete_key(mrb, ksrc, k);
968
1291
  mrb_gc_protect(mrb, *values);
969
1292
  }
970
1293
 
971
1294
  for (j = kwnum - required; j > 0; j --, kname ++, values ++) {
972
- mrb_value k = mrb_symbol_value(mrb_intern_cstr(mrb, *kname));
1295
+ mrb_value k = mrb_symbol_value(*kname);
973
1296
  if (mrb_hash_key_p(mrb, ksrc, k)) {
974
1297
  *values = mrb_hash_delete_key(mrb, ksrc, k);
975
1298
  mrb_gc_protect(mrb, *values);
@@ -1002,7 +1325,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
1002
1325
  #undef ARGV
1003
1326
 
1004
1327
  if (!c && argc > i) {
1005
- mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
1328
+ mrb_argnum_error(mrb, argc, argc_min, argc_max);
1006
1329
  }
1007
1330
 
1008
1331
  finish:
@@ -1023,7 +1346,7 @@ boot_defclass(mrb_state *mrb, struct RClass *super)
1023
1346
  else {
1024
1347
  c->super = mrb->object_class;
1025
1348
  }
1026
- c->mt = kh_init(mt, mrb);
1349
+ c->mt = mt_new(mrb);
1027
1350
  return c;
1028
1351
  }
1029
1352
 
@@ -1031,7 +1354,7 @@ static void
1031
1354
  boot_initmod(mrb_state *mrb, struct RClass *mod)
1032
1355
  {
1033
1356
  if (!mod->mt) {
1034
- mod->mt = kh_init(mt, mrb);
1357
+ mod->mt = mt_new(mrb);
1035
1358
  }
1036
1359
  }
1037
1360
 
@@ -1062,8 +1385,10 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
1062
1385
  void *klass_mt = find_origin(c)->mt;
1063
1386
 
1064
1387
  while (m) {
1065
- int superclass_seen = 0;
1388
+ int original_seen = FALSE;
1389
+ int superclass_seen = FALSE;
1066
1390
 
1391
+ if (c == ins_pos) original_seen = TRUE;
1067
1392
  if (m->flags & MRB_FL_CLASS_IS_PREPENDED)
1068
1393
  goto skip;
1069
1394
 
@@ -1072,16 +1397,17 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
1072
1397
 
1073
1398
  p = c->super;
1074
1399
  while (p) {
1400
+ if (c == p) original_seen = TRUE;
1075
1401
  if (p->tt == MRB_TT_ICLASS) {
1076
1402
  if (p->mt == m->mt) {
1077
- if (!superclass_seen) {
1403
+ if (!superclass_seen && original_seen) {
1078
1404
  ins_pos = p; /* move insert point */
1079
1405
  }
1080
1406
  goto skip;
1081
1407
  }
1082
1408
  } else if (p->tt == MRB_TT_CLASS) {
1083
1409
  if (!search_super) break;
1084
- superclass_seen = 1;
1410
+ superclass_seen = TRUE;
1085
1411
  }
1086
1412
  p = p->super;
1087
1413
  }
@@ -1090,15 +1416,26 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
1090
1416
  m->flags |= MRB_FL_CLASS_IS_INHERITED;
1091
1417
  ins_pos->super = ic;
1092
1418
  mrb_field_write_barrier(mrb, (struct RBasic*)ins_pos, (struct RBasic*)ic);
1093
- mrb_mc_clear_by_class(mrb, ins_pos);
1094
1419
  ins_pos = ic;
1095
1420
  skip:
1096
1421
  m = m->super;
1097
1422
  }
1098
- mc_clear_all(mrb);
1423
+ mc_clear(mrb);
1099
1424
  return 0;
1100
1425
  }
1101
1426
 
1427
+ static int
1428
+ fix_include_module(mrb_state *mrb, struct RBasic *obj, void *data)
1429
+ {
1430
+ struct RClass **m = (struct RClass**)data;
1431
+
1432
+ if (obj->tt == MRB_TT_ICLASS && obj->c == m[0] && (obj->flags & MRB_FL_CLASS_IS_ORIGIN) == 0) {
1433
+ struct RClass *ic = (struct RClass*)obj;
1434
+ include_module_at(mrb, ic, ic, m[1], 1);
1435
+ }
1436
+ return MRB_EACH_OBJ_OK;
1437
+ }
1438
+
1102
1439
  MRB_API void
1103
1440
  mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
1104
1441
  {
@@ -1106,50 +1443,96 @@ mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
1106
1443
  if (include_module_at(mrb, c, find_origin(c), m, 1) < 0) {
1107
1444
  mrb_raise(mrb, E_ARGUMENT_ERROR, "cyclic include detected");
1108
1445
  }
1446
+ if (c->tt == MRB_TT_MODULE && (c->flags & MRB_FL_CLASS_IS_INHERITED)) {
1447
+ struct RClass *data[2];
1448
+ data[0] = c;
1449
+ data[1] = m;
1450
+ mrb_objspace_each_objects(mrb, fix_include_module, data);
1451
+ }
1452
+ }
1453
+
1454
+ static int
1455
+ fix_prepend_module(mrb_state *mrb, struct RBasic *obj, void *data)
1456
+ {
1457
+ struct RClass **m = (struct RClass**)data;
1458
+ struct RClass *c = (struct RClass*)obj;
1459
+
1460
+ if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
1461
+ struct RClass *p = c->super;
1462
+ struct RClass *ins_pos = c;
1463
+ while (p) {
1464
+ if (c == m[0]) break;
1465
+ if (p == m[0]->super->c) {
1466
+ ins_pos = c;
1467
+ }
1468
+ if (p->tt == MRB_TT_CLASS) break;
1469
+ if (p->c == m[0]) {
1470
+ include_module_at(mrb, ins_pos, ins_pos, m[1], 0);
1471
+ break;
1472
+ }
1473
+ c = p;
1474
+ p = p->super;
1475
+ }
1476
+ }
1477
+ return MRB_EACH_OBJ_OK;
1109
1478
  }
1110
1479
 
1111
1480
  MRB_API void
1112
1481
  mrb_prepend_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
1113
1482
  {
1114
1483
  struct RClass *origin;
1115
- int changed = 0;
1116
1484
 
1117
1485
  mrb_check_frozen(mrb, c);
1118
1486
  if (!(c->flags & MRB_FL_CLASS_IS_PREPENDED)) {
1119
- origin = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, c);
1487
+ struct RClass *c0;
1488
+
1489
+ if (c->tt == MRB_TT_ICLASS) {
1490
+ c0 = c->c;
1491
+ }
1492
+ else {
1493
+ c0 = c;
1494
+ }
1495
+ origin = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, c0);
1120
1496
  origin->flags |= MRB_FL_CLASS_IS_ORIGIN | MRB_FL_CLASS_IS_INHERITED;
1121
1497
  origin->super = c->super;
1122
1498
  c->super = origin;
1123
1499
  origin->mt = c->mt;
1124
- c->mt = kh_init(mt, mrb);
1500
+ c->mt = NULL;
1501
+ origin->iv = c->iv;
1125
1502
  mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)origin);
1126
1503
  c->flags |= MRB_FL_CLASS_IS_PREPENDED;
1127
1504
  }
1128
- changed = include_module_at(mrb, c, c, m, 0);
1129
- if (changed < 0) {
1505
+ if (include_module_at(mrb, c, c, m, 0) < 0) {
1130
1506
  mrb_raise(mrb, E_ARGUMENT_ERROR, "cyclic prepend detected");
1131
1507
  }
1508
+ if (c->tt == MRB_TT_MODULE &&
1509
+ (c->flags & (MRB_FL_CLASS_IS_INHERITED|MRB_FL_CLASS_IS_PREPENDED))) {
1510
+ struct RClass *data[2];
1511
+ data[0] = c;
1512
+ data[1] = m;
1513
+ mrb_objspace_each_objects(mrb, fix_prepend_module, data);
1514
+ }
1132
1515
  }
1133
1516
 
1134
1517
  static mrb_value
1135
1518
  mrb_mod_prepend_features(mrb_state *mrb, mrb_value mod)
1136
1519
  {
1137
- mrb_value klass;
1520
+ struct RClass *c;
1138
1521
 
1139
1522
  mrb_check_type(mrb, mod, MRB_TT_MODULE);
1140
- mrb_get_args(mrb, "C", &klass);
1141
- mrb_prepend_module(mrb, mrb_class_ptr(klass), mrb_class_ptr(mod));
1523
+ mrb_get_args(mrb, "c", &c);
1524
+ mrb_prepend_module(mrb, c, mrb_class_ptr(mod));
1142
1525
  return mod;
1143
1526
  }
1144
1527
 
1145
1528
  static mrb_value
1146
1529
  mrb_mod_append_features(mrb_state *mrb, mrb_value mod)
1147
1530
  {
1148
- mrb_value klass;
1531
+ struct RClass *c;
1149
1532
 
1150
1533
  mrb_check_type(mrb, mod, MRB_TT_MODULE);
1151
- mrb_get_args(mrb, "C", &klass);
1152
- mrb_include_module(mrb, mrb_class_ptr(klass), mrb_class_ptr(mod));
1534
+ mrb_get_args(mrb, "c", &c);
1535
+ mrb_include_module(mrb, c, mrb_class_ptr(mod));
1153
1536
  return mod;
1154
1537
  }
1155
1538
 
@@ -1212,10 +1595,9 @@ mrb_mod_ancestors(mrb_state *mrb, mrb_value self)
1212
1595
  static mrb_value
1213
1596
  mrb_mod_extend_object(mrb_state *mrb, mrb_value mod)
1214
1597
  {
1215
- mrb_value obj;
1598
+ mrb_value obj = mrb_get_arg1(mrb);
1216
1599
 
1217
1600
  mrb_check_type(mrb, mod, MRB_TT_MODULE);
1218
- mrb_get_args(mrb, "o", &obj);
1219
1601
  mrb_include_module(mrb, mrb_class_ptr(mrb_singleton_class(mrb, obj)), mrb_class_ptr(mod));
1220
1602
  return mod;
1221
1603
  }
@@ -1242,33 +1624,44 @@ mrb_mod_dummy_visibility(mrb_state *mrb, mrb_value mod)
1242
1624
  return mod;
1243
1625
  }
1244
1626
 
1245
- MRB_API mrb_value
1246
- mrb_singleton_class(mrb_state *mrb, mrb_value v)
1627
+ /* returns mrb_class_ptr(mrb_singleton_class()) */
1628
+ /* except that it return NULL for immediate values */
1629
+ MRB_API struct RClass*
1630
+ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v)
1247
1631
  {
1248
1632
  struct RBasic *obj;
1249
1633
 
1250
1634
  switch (mrb_type(v)) {
1251
1635
  case MRB_TT_FALSE:
1252
1636
  if (mrb_nil_p(v))
1253
- return mrb_obj_value(mrb->nil_class);
1254
- return mrb_obj_value(mrb->false_class);
1637
+ return mrb->nil_class;
1638
+ return mrb->false_class;
1255
1639
  case MRB_TT_TRUE:
1256
- return mrb_obj_value(mrb->true_class);
1640
+ return mrb->true_class;
1257
1641
  case MRB_TT_CPTR:
1258
- return mrb_obj_value(mrb->object_class);
1259
1642
  case MRB_TT_SYMBOL:
1260
- case MRB_TT_FIXNUM:
1261
- #ifndef MRB_WITHOUT_FLOAT
1643
+ case MRB_TT_INTEGER:
1644
+ #ifndef MRB_NO_FLOAT
1262
1645
  case MRB_TT_FLOAT:
1263
1646
  #endif
1264
- mrb_raise(mrb, E_TYPE_ERROR, "can't define singleton");
1265
- return mrb_nil_value(); /* not reached */
1647
+ return NULL;
1266
1648
  default:
1267
1649
  break;
1268
1650
  }
1269
1651
  obj = mrb_basic_ptr(v);
1270
1652
  prepare_singleton_class(mrb, obj);
1271
- return mrb_obj_value(obj->c);
1653
+ return obj->c;
1654
+ }
1655
+
1656
+ MRB_API mrb_value
1657
+ mrb_singleton_class(mrb_state *mrb, mrb_value v)
1658
+ {
1659
+ struct RClass *c = mrb_singleton_class_ptr(mrb, v);
1660
+
1661
+ if (c == NULL) {
1662
+ mrb_raise(mrb, E_TYPE_ERROR, "can't define singleton");
1663
+ }
1664
+ return mrb_obj_value(c);
1272
1665
  }
1273
1666
 
1274
1667
  MRB_API void
@@ -1278,29 +1671,43 @@ mrb_define_singleton_method(mrb_state *mrb, struct RObject *o, const char *name,
1278
1671
  mrb_define_method_id(mrb, o->c, mrb_intern_cstr(mrb, name), func, aspec);
1279
1672
  }
1280
1673
 
1674
+ MRB_API void
1675
+ mrb_define_singleton_method_id(mrb_state *mrb, struct RObject *o, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
1676
+ {
1677
+ prepare_singleton_class(mrb, (struct RBasic*)o);
1678
+ mrb_define_method_id(mrb, o->c, name, func, aspec);
1679
+ }
1680
+
1281
1681
  MRB_API void
1282
1682
  mrb_define_class_method(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t func, mrb_aspec aspec)
1283
1683
  {
1284
1684
  mrb_define_singleton_method(mrb, (struct RObject*)c, name, func, aspec);
1285
1685
  }
1286
1686
 
1687
+ MRB_API void
1688
+ mrb_define_class_method_id(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
1689
+ {
1690
+ mrb_define_singleton_method_id(mrb, (struct RObject*)c, name, func, aspec);
1691
+ }
1692
+
1693
+ MRB_API void
1694
+ mrb_define_module_function_id(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
1695
+ {
1696
+ mrb_define_class_method_id(mrb, c, name, func, aspec);
1697
+ mrb_define_method_id(mrb, c, name, func, aspec);
1698
+ }
1699
+
1287
1700
  MRB_API void
1288
1701
  mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t func, mrb_aspec aspec)
1289
1702
  {
1290
- mrb_define_class_method(mrb, c, name, func, aspec);
1291
- mrb_define_method(mrb, c, name, func, aspec);
1703
+ mrb_define_module_function_id(mrb, c, mrb_intern_cstr(mrb, name), func, aspec);
1292
1704
  }
1293
1705
 
1294
- #ifdef MRB_METHOD_CACHE
1706
+ #ifndef MRB_NO_METHOD_CACHE
1295
1707
  static void
1296
- mc_clear_all(mrb_state *mrb)
1708
+ mc_clear(mrb_state *mrb)
1297
1709
  {
1298
- struct mrb_cache_entry *mc = mrb->cache;
1299
- int i;
1300
-
1301
- for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
1302
- mc[i].c = 0;
1303
- }
1710
+ memset(mrb->cache, 0, MRB_METHOD_CACHE_SIZE*sizeof(mrb->cache[0]));
1304
1711
  }
1305
1712
 
1306
1713
  void
@@ -1310,40 +1717,21 @@ mrb_mc_clear_by_class(mrb_state *mrb, struct RClass *c)
1310
1717
  int i;
1311
1718
 
1312
1719
  if (c->flags & MRB_FL_CLASS_IS_INHERITED) {
1313
- mc_clear_all(mrb);
1314
- c->flags &= ~MRB_FL_CLASS_IS_INHERITED;
1720
+ mc_clear(mrb);
1315
1721
  return;
1316
1722
  }
1317
1723
  for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
1318
1724
  if (mc[i].c == c) mc[i].c = 0;
1319
1725
  }
1320
1726
  }
1321
-
1322
- static void
1323
- mc_clear_by_id(mrb_state *mrb, struct RClass *c, mrb_sym mid)
1324
- {
1325
- struct mrb_cache_entry *mc = mrb->cache;
1326
- int i;
1327
-
1328
- if (c->flags & MRB_FL_CLASS_IS_INHERITED) {
1329
- mc_clear_all(mrb);
1330
- c->flags &= ~MRB_FL_CLASS_IS_INHERITED;
1331
- return;
1332
- }
1333
- for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
1334
- if (mc[i].c == c || mc[i].mid == mid)
1335
- mc[i].c = 0;
1336
- }
1337
- }
1338
1727
  #endif
1339
1728
 
1340
1729
  MRB_API mrb_method_t
1341
1730
  mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
1342
1731
  {
1343
- khiter_t k;
1344
1732
  mrb_method_t m;
1345
1733
  struct RClass *c = *cp;
1346
- #ifdef MRB_METHOD_CACHE
1734
+ #ifndef MRB_NO_METHOD_CACHE
1347
1735
  struct RClass *oc = c;
1348
1736
  int h = kh_int_hash_func(mrb, ((intptr_t)oc) ^ mid) & (MRB_METHOD_CACHE_SIZE-1);
1349
1737
  struct mrb_cache_entry *mc = &mrb->cache[h];
@@ -1355,15 +1743,23 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
1355
1743
  #endif
1356
1744
 
1357
1745
  while (c) {
1358
- khash_t(mt) *h = c->mt;
1746
+ mt_tbl *h = c->mt;
1359
1747
 
1360
1748
  if (h) {
1361
- k = kh_get(mt, mrb, h, mid);
1362
- if (k != kh_end(h)) {
1363
- m = kh_value(h, k);
1364
- if (MRB_METHOD_UNDEF_P(m)) break;
1749
+ struct mt_elem *e = mt_get(mrb, h, mid);
1750
+ if (e) {
1751
+ if (e->ptr.proc == 0) break;
1365
1752
  *cp = c;
1366
- #ifdef MRB_METHOD_CACHE
1753
+ if (e->func_p) {
1754
+ MRB_METHOD_FROM_FUNC(m, e->ptr.func);
1755
+ }
1756
+ else {
1757
+ MRB_METHOD_FROM_PROC(m, e->ptr.proc);
1758
+ }
1759
+ if (e->noarg_p) {
1760
+ MRB_METHOD_NOARG_SET(m);
1761
+ }
1762
+ #ifndef MRB_NO_METHOD_CACHE
1367
1763
  mc->c = oc;
1368
1764
  mc->c0 = c;
1369
1765
  mc->mid = mid;
@@ -1438,7 +1834,7 @@ static mrb_value
1438
1834
  mod_attr_define(mrb_state *mrb, mrb_value mod, mrb_value (*accessor)(mrb_state *, mrb_value), mrb_sym (*access_name)(mrb_state *, mrb_sym))
1439
1835
  {
1440
1836
  struct RClass *c = mrb_class_ptr(mod);
1441
- mrb_value *argv;
1837
+ const mrb_value *argv;
1442
1838
  mrb_int argc, i;
1443
1839
  int ai;
1444
1840
 
@@ -1481,9 +1877,8 @@ static mrb_value
1481
1877
  attr_writer(mrb_state *mrb, mrb_value obj)
1482
1878
  {
1483
1879
  mrb_value name = mrb_proc_cfunc_env_get(mrb, 0);
1484
- mrb_value val;
1880
+ mrb_value val = mrb_get_arg1(mrb);
1485
1881
 
1486
- mrb_get_args(mrb, "o", &val);
1487
1882
  mrb_iv_set(mrb, obj, to_sym(mrb, name), val);
1488
1883
  return val;
1489
1884
  }
@@ -1528,13 +1923,13 @@ mrb_value
1528
1923
  mrb_instance_new(mrb_state *mrb, mrb_value cv)
1529
1924
  {
1530
1925
  mrb_value obj, blk;
1531
- mrb_value *argv;
1926
+ const mrb_value *argv;
1532
1927
  mrb_int argc;
1533
1928
  mrb_sym init;
1534
1929
 
1535
1930
  mrb_get_args(mrb, "*!&", &argv, &argc, &blk);
1536
1931
  obj = mrb_instance_alloc(mrb, cv);
1537
- init = mrb_intern_lit(mrb, "initialize");
1932
+ init = MRB_SYM(initialize);
1538
1933
  if (!mrb_func_basic_p(mrb, obj, init, mrb_bob_init)) {
1539
1934
  mrb_funcall_with_block(mrb, obj, init, argc, argv, blk);
1540
1935
  }
@@ -1548,7 +1943,7 @@ mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *arg
1548
1943
  mrb_sym mid;
1549
1944
 
1550
1945
  obj = mrb_instance_alloc(mrb, mrb_obj_value(c));
1551
- mid = mrb_intern_lit(mrb, "initialize");
1946
+ mid = MRB_SYM(initialize);
1552
1947
  if (!mrb_func_basic_p(mrb, obj, mid, mrb_bob_init)) {
1553
1948
  mrb_funcall_argv(mrb, obj, mid, argc, argv);
1554
1949
  }
@@ -1580,7 +1975,7 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv)
1580
1975
  super = mrb_obj_value(mrb->object_class);
1581
1976
  }
1582
1977
  new_class = mrb_obj_value(mrb_class_new(mrb, mrb_class_ptr(super)));
1583
- mid = mrb_intern_lit(mrb, "initialize");
1978
+ mid = MRB_SYM(initialize);
1584
1979
  if (mrb_func_basic_p(mrb, new_class, mid, mrb_class_initialize)) {
1585
1980
  mrb_class_initialize(mrb, new_class);
1586
1981
  }
@@ -1651,21 +2046,11 @@ mrb_bob_not(mrb_state *mrb, mrb_value cv)
1651
2046
  mrb_value
1652
2047
  mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
1653
2048
  {
1654
- mrb_value arg;
2049
+ mrb_value arg = mrb_get_arg1(mrb);
1655
2050
 
1656
- mrb_get_args(mrb, "o", &arg);
1657
2051
  return mrb_bool_value(mrb_obj_equal(mrb, self, arg));
1658
2052
  }
1659
2053
 
1660
- static mrb_value
1661
- mrb_obj_not_equal_m(mrb_state *mrb, mrb_value self)
1662
- {
1663
- mrb_value arg;
1664
-
1665
- mrb_get_args(mrb, "o", &arg);
1666
- return mrb_bool_value(!mrb_equal(mrb, self, arg));
1667
- }
1668
-
1669
2054
  MRB_API mrb_bool
1670
2055
  mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid)
1671
2056
  {
@@ -1688,7 +2073,7 @@ MRB_API mrb_value
1688
2073
  mrb_class_path(mrb_state *mrb, struct RClass *c)
1689
2074
  {
1690
2075
  mrb_value path;
1691
- mrb_sym nsym = mrb_intern_lit(mrb, "__classname__");
2076
+ mrb_sym nsym = MRB_SYM(__classname__);
1692
2077
 
1693
2078
  path = mrb_obj_iv_get(mrb, (struct RObject*)c, nsym);
1694
2079
  if (mrb_nil_p(path)) {
@@ -1716,7 +2101,10 @@ mrb_class_real(struct RClass* cl)
1716
2101
  MRB_API const char*
1717
2102
  mrb_class_name(mrb_state *mrb, struct RClass* c)
1718
2103
  {
1719
- mrb_value name = class_name_str(mrb, c);
2104
+ mrb_value name;
2105
+
2106
+ if (c == NULL) return NULL;
2107
+ name = class_name_str(mrb, c);
1720
2108
  return RSTRING_PTR(name);
1721
2109
  }
1722
2110
 
@@ -1790,7 +2178,7 @@ mrb_module_new(mrb_state *mrb)
1790
2178
  * called with an explicit receiver, as <code>class</code> is also a
1791
2179
  * reserved word in Ruby.
1792
2180
  *
1793
- * 1.class #=> Fixnum
2181
+ * 1.class #=> Integer
1794
2182
  * self.class #=> Object
1795
2183
  */
1796
2184
 
@@ -1840,6 +2228,12 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const
1840
2228
  mrb_alias_method(mrb, klass, mrb_intern_cstr(mrb, name1), mrb_intern_cstr(mrb, name2));
1841
2229
  }
1842
2230
 
2231
+ MRB_API void
2232
+ mrb_define_alias_id(mrb_state *mrb, struct RClass *klass, mrb_sym a, mrb_sym b)
2233
+ {
2234
+ mrb_alias_method(mrb, klass, a, b);
2235
+ }
2236
+
1843
2237
  /*
1844
2238
  * call-seq:
1845
2239
  * mod.to_s -> string
@@ -1852,9 +2246,8 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const
1852
2246
  mrb_value
1853
2247
  mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
1854
2248
  {
1855
-
1856
2249
  if (mrb_sclass_p(klass)) {
1857
- mrb_value v = mrb_iv_get(mrb, klass, mrb_intern_lit(mrb, "__attached__"));
2250
+ mrb_value v = mrb_iv_get(mrb, klass, MRB_SYM(__attached__));
1858
2251
  mrb_value str = mrb_str_new_lit(mrb, "#<Class:");
1859
2252
 
1860
2253
  if (class_ptr_p(v)) {
@@ -1890,7 +2283,7 @@ undef_method(mrb_state *mrb, struct RClass *c, mrb_sym a)
1890
2283
  mrb_define_method_raw(mrb, c, a, m);
1891
2284
  }
1892
2285
 
1893
- void
2286
+ MRB_API void
1894
2287
  mrb_undef_method_id(mrb_state *mrb, struct RClass *c, mrb_sym a)
1895
2288
  {
1896
2289
  if (!mrb_obj_respond_to(mrb, c, a)) {
@@ -1905,18 +2298,36 @@ mrb_undef_method(mrb_state *mrb, struct RClass *c, const char *name)
1905
2298
  undef_method(mrb, c, mrb_intern_cstr(mrb, name));
1906
2299
  }
1907
2300
 
2301
+ MRB_API void
2302
+ mrb_undef_class_method_id(mrb_state *mrb, struct RClass *c, mrb_sym name)
2303
+ {
2304
+ mrb_undef_method_id(mrb, mrb_class_ptr(mrb_singleton_class(mrb, mrb_obj_value(c))), name);
2305
+ }
2306
+
1908
2307
  MRB_API void
1909
2308
  mrb_undef_class_method(mrb_state *mrb, struct RClass *c, const char *name)
1910
2309
  {
1911
2310
  mrb_undef_method(mrb, mrb_class_ptr(mrb_singleton_class(mrb, mrb_obj_value(c))), name);
1912
2311
  }
1913
2312
 
2313
+ MRB_API void
2314
+ mrb_remove_method(mrb_state *mrb, struct RClass *c, mrb_sym mid)
2315
+ {
2316
+ mt_tbl *h;
2317
+
2318
+ MRB_CLASS_ORIGIN(c);
2319
+ h = c->mt;
2320
+
2321
+ if (h && mt_del(mrb, h, mid)) return;
2322
+ mrb_name_error(mrb, mid, "method '%n' not defined in %C", mid, c);
2323
+ }
2324
+
1914
2325
  static mrb_value
1915
2326
  mrb_mod_undef(mrb_state *mrb, mrb_value mod)
1916
2327
  {
1917
2328
  struct RClass *c = mrb_class_ptr(mod);
1918
2329
  mrb_int argc;
1919
- mrb_value *argv;
2330
+ const mrb_value *argv;
1920
2331
 
1921
2332
  mrb_get_args(mrb, "*", &argv, &argc);
1922
2333
  while (argc--) {
@@ -1960,13 +2371,11 @@ mrb_const_get_sym(mrb_state *mrb, mrb_value mod, mrb_sym id)
1960
2371
  static mrb_value
1961
2372
  mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
1962
2373
  {
1963
- mrb_value path;
2374
+ mrb_value path = mrb_get_arg1(mrb);
1964
2375
  mrb_sym id;
1965
2376
  char *ptr;
1966
2377
  mrb_int off, end, len;
1967
2378
 
1968
- mrb_get_args(mrb, "o", &path);
1969
-
1970
2379
  if (mrb_symbol_p(path)) {
1971
2380
  /* const get with symbol */
1972
2381
  id = mrb_symbol(path);
@@ -2077,10 +2486,9 @@ mrb_mod_method_defined(mrb_state *mrb, mrb_value mod)
2077
2486
  return mrb_bool_value(mrb_obj_respond_to(mrb, mrb_class_ptr(mod), id));
2078
2487
  }
2079
2488
 
2080
- static mrb_value
2081
- mod_define_method(mrb_state *mrb, mrb_value self)
2489
+ mrb_value
2490
+ mrb_mod_define_method_m(mrb_state *mrb, struct RClass *c)
2082
2491
  {
2083
- struct RClass *c = mrb_class_ptr(self);
2084
2492
  struct RProc *p;
2085
2493
  mrb_method_t m;
2086
2494
  mrb_sym mid;
@@ -2110,19 +2518,24 @@ mod_define_method(mrb_state *mrb, mrb_value self)
2110
2518
  return mrb_symbol_value(mid);
2111
2519
  }
2112
2520
 
2521
+ static mrb_value
2522
+ mod_define_method(mrb_state *mrb, mrb_value self)
2523
+ {
2524
+ return mrb_mod_define_method_m(mrb, mrb_class_ptr(self));
2525
+ }
2526
+
2113
2527
  static mrb_value
2114
2528
  top_define_method(mrb_state *mrb, mrb_value self)
2115
2529
  {
2116
- return mod_define_method(mrb, mrb_obj_value(mrb->object_class));
2530
+ return mrb_mod_define_method_m(mrb, mrb->object_class);
2117
2531
  }
2118
2532
 
2119
2533
  static mrb_value
2120
2534
  mrb_mod_eqq(mrb_state *mrb, mrb_value mod)
2121
2535
  {
2122
- mrb_value obj;
2536
+ mrb_value obj = mrb_get_arg1(mrb);
2123
2537
  mrb_bool eqq;
2124
2538
 
2125
- mrb_get_args(mrb, "o", &obj);
2126
2539
  eqq = mrb_obj_is_kind_of(mrb, obj, mrb_class_ptr(mod));
2127
2540
 
2128
2541
  return mrb_bool_value(eqq);
@@ -2139,7 +2552,7 @@ mrb_mod_dup(mrb_state *mrb, mrb_value self)
2139
2552
  static mrb_value
2140
2553
  mrb_mod_module_function(mrb_state *mrb, mrb_value mod)
2141
2554
  {
2142
- mrb_value *argv;
2555
+ const mrb_value *argv;
2143
2556
  mrb_int argc, i;
2144
2557
  mrb_sym mid;
2145
2558
  mrb_method_t m;
@@ -2173,6 +2586,202 @@ mrb_mod_module_function(mrb_state *mrb, mrb_value mod)
2173
2586
  return mod;
2174
2587
  }
2175
2588
 
2589
+ static struct RClass*
2590
+ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
2591
+ {
2592
+ struct RClass *klass = mrb_basic_ptr(obj)->c;
2593
+
2594
+ if (klass->tt != MRB_TT_SCLASS)
2595
+ return klass;
2596
+ else {
2597
+ /* copy singleton(unnamed) class */
2598
+ struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
2599
+
2600
+ switch (mrb_type(obj)) {
2601
+ case MRB_TT_CLASS:
2602
+ case MRB_TT_SCLASS:
2603
+ break;
2604
+ default:
2605
+ clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass));
2606
+ break;
2607
+ }
2608
+ clone->super = klass->super;
2609
+ if (klass->iv) {
2610
+ mrb_iv_copy(mrb, mrb_obj_value(clone), mrb_obj_value(klass));
2611
+ mrb_obj_iv_set(mrb, (struct RObject*)clone, MRB_SYM(__attached__), obj);
2612
+ }
2613
+ if (klass->mt) {
2614
+ clone->mt = mt_copy(mrb, klass->mt);
2615
+ }
2616
+ else {
2617
+ clone->mt = mt_new(mrb);
2618
+ }
2619
+ clone->tt = MRB_TT_SCLASS;
2620
+ return clone;
2621
+ }
2622
+ }
2623
+
2624
+ static void
2625
+ copy_class(mrb_state *mrb, mrb_value dst, mrb_value src)
2626
+ {
2627
+ struct RClass *dc = mrb_class_ptr(dst);
2628
+ struct RClass *sc = mrb_class_ptr(src);
2629
+ /* if the origin is not the same as the class, then the origin and
2630
+ the current class need to be copied */
2631
+ if (sc->flags & MRB_FL_CLASS_IS_PREPENDED) {
2632
+ struct RClass *c0 = sc->super;
2633
+ struct RClass *c1 = dc;
2634
+
2635
+ /* copy prepended iclasses */
2636
+ while (!(c0->flags & MRB_FL_CLASS_IS_ORIGIN)) {
2637
+ c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
2638
+ c1 = c1->super;
2639
+ c0 = c0->super;
2640
+ }
2641
+ c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
2642
+ c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
2643
+ }
2644
+ if (sc->mt) {
2645
+ dc->mt = mt_copy(mrb, sc->mt);
2646
+ }
2647
+ else {
2648
+ dc->mt = mt_new(mrb);
2649
+ }
2650
+ dc->super = sc->super;
2651
+ MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc));
2652
+ }
2653
+
2654
+ /* 15.3.1.3.16 */
2655
+ static mrb_value
2656
+ mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
2657
+ {
2658
+ mrb_value orig = mrb_get_arg1(mrb);
2659
+
2660
+ if (mrb_obj_equal(mrb, self, orig)) return self;
2661
+ if ((mrb_type(self) != mrb_type(orig)) || (mrb_obj_class(mrb, self) != mrb_obj_class(mrb, orig))) {
2662
+ mrb_raise(mrb, E_TYPE_ERROR, "initialize_copy should take same class object");
2663
+ }
2664
+ return self;
2665
+ }
2666
+
2667
+ static void
2668
+ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
2669
+ {
2670
+ switch (mrb_type(obj)) {
2671
+ case MRB_TT_ICLASS:
2672
+ copy_class(mrb, dest, obj);
2673
+ return;
2674
+ case MRB_TT_CLASS:
2675
+ case MRB_TT_MODULE:
2676
+ copy_class(mrb, dest, obj);
2677
+ mrb_iv_copy(mrb, dest, obj);
2678
+ mrb_iv_remove(mrb, dest, MRB_SYM(__classname__));
2679
+ break;
2680
+ case MRB_TT_OBJECT:
2681
+ case MRB_TT_SCLASS:
2682
+ case MRB_TT_HASH:
2683
+ case MRB_TT_DATA:
2684
+ case MRB_TT_EXCEPTION:
2685
+ mrb_iv_copy(mrb, dest, obj);
2686
+ break;
2687
+ case MRB_TT_ISTRUCT:
2688
+ mrb_istruct_copy(dest, obj);
2689
+ break;
2690
+
2691
+ default:
2692
+ break;
2693
+ }
2694
+ if (!mrb_func_basic_p(mrb, dest, MRB_SYM(initialize_copy), mrb_obj_init_copy)) {
2695
+ mrb_funcall_id(mrb, dest, MRB_SYM(initialize_copy), 1, obj);
2696
+ }
2697
+ }
2698
+
2699
+ /* 15.3.1.3.8 */
2700
+ /*
2701
+ * call-seq:
2702
+ * obj.clone -> an_object
2703
+ *
2704
+ * Produces a shallow copy of <i>obj</i>---the instance variables of
2705
+ * <i>obj</i> are copied, but not the objects they reference. Copies
2706
+ * the frozen state of <i>obj</i>. See also the discussion
2707
+ * under <code>Object#dup</code>.
2708
+ *
2709
+ * class Klass
2710
+ * attr_accessor :str
2711
+ * end
2712
+ * s1 = Klass.new #=> #<Klass:0x401b3a38>
2713
+ * s1.str = "Hello" #=> "Hello"
2714
+ * s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
2715
+ * s2.str[1,4] = "i" #=> "i"
2716
+ * s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
2717
+ * s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
2718
+ *
2719
+ * This method may have class-specific behavior. If so, that
2720
+ * behavior will be documented under the #+initialize_copy+ method of
2721
+ * the class.
2722
+ *
2723
+ * Some Class(True False Nil Symbol Integer Float) Object cannot clone.
2724
+ */
2725
+ MRB_API mrb_value
2726
+ mrb_obj_clone(mrb_state *mrb, mrb_value self)
2727
+ {
2728
+ struct RObject *p;
2729
+ mrb_value clone;
2730
+
2731
+ if (mrb_immediate_p(self)) {
2732
+ return self;
2733
+ }
2734
+ if (mrb_sclass_p(self)) {
2735
+ mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
2736
+ }
2737
+ p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
2738
+ p->c = mrb_singleton_class_clone(mrb, self);
2739
+ mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
2740
+ clone = mrb_obj_value(p);
2741
+ init_copy(mrb, clone, self);
2742
+ p->flags |= mrb_obj_ptr(self)->flags & MRB_FL_OBJ_IS_FROZEN;
2743
+
2744
+ return clone;
2745
+ }
2746
+
2747
+ /* 15.3.1.3.9 */
2748
+ /*
2749
+ * call-seq:
2750
+ * obj.dup -> an_object
2751
+ *
2752
+ * Produces a shallow copy of <i>obj</i>---the instance variables of
2753
+ * <i>obj</i> are copied, but not the objects they reference.
2754
+ * <code>dup</code> copies the frozen state of <i>obj</i>. See also
2755
+ * the discussion under <code>Object#clone</code>. In general,
2756
+ * <code>clone</code> and <code>dup</code> may have different semantics
2757
+ * in descendant classes. While <code>clone</code> is used to duplicate
2758
+ * an object, including its internal state, <code>dup</code> typically
2759
+ * uses the class of the descendant object to create the new instance.
2760
+ *
2761
+ * This method may have class-specific behavior. If so, that
2762
+ * behavior will be documented under the #+initialize_copy+ method of
2763
+ * the class.
2764
+ */
2765
+
2766
+ MRB_API mrb_value
2767
+ mrb_obj_dup(mrb_state *mrb, mrb_value obj)
2768
+ {
2769
+ struct RBasic *p;
2770
+ mrb_value dup;
2771
+
2772
+ if (mrb_immediate_p(obj)) {
2773
+ return obj;
2774
+ }
2775
+ if (mrb_sclass_p(obj)) {
2776
+ mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
2777
+ }
2778
+ p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
2779
+ dup = mrb_obj_value(p);
2780
+ init_copy(mrb, dup, obj);
2781
+
2782
+ return dup;
2783
+ }
2784
+
2176
2785
  /* implementation of __id__ */
2177
2786
  mrb_value mrb_obj_id_m(mrb_state *mrb, mrb_value self);
2178
2787
  /* implementation of instance_eval */
@@ -2195,29 +2804,29 @@ static const mrb_code new_iseq[] = {
2195
2804
  OP_RETURN, 0x0 /* OP_RETURN R0 */
2196
2805
  };
2197
2806
 
2807
+ MRB_PRESYM_DEFINE_VAR_AND_INITER(new_syms, 2, MRB_SYM(allocate), MRB_SYM(initialize))
2808
+
2809
+ static const mrb_irep new_irep = {
2810
+ 3, 6, 0, MRB_IREP_STATIC,
2811
+ new_iseq, NULL, new_syms, NULL, NULL, NULL,
2812
+ sizeof(new_iseq), 0, 2, 0, 0,
2813
+ };
2814
+
2198
2815
  static void
2199
2816
  init_class_new(mrb_state *mrb, struct RClass *cls)
2200
2817
  {
2201
2818
  struct RProc *p;
2202
2819
  mrb_method_t m;
2203
- mrb_irep *new_irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep));
2204
- static const mrb_irep mrb_irep_zero = { 0 };
2205
-
2206
- *new_irep = mrb_irep_zero;
2207
- new_irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*2);
2208
- new_irep->syms[0] = mrb_intern_lit(mrb, "allocate");
2209
- new_irep->syms[1] = mrb_intern_lit(mrb, "initialize");
2210
- new_irep->slen = 2;
2211
- new_irep->flags = MRB_ISEQ_NO_FREE;
2212
- new_irep->iseq = new_iseq;
2213
- new_irep->ilen = sizeof(new_iseq);
2214
- new_irep->nregs = 6;
2215
- new_irep->nlocals = 3;
2216
- p = mrb_proc_new(mrb, new_irep);
2820
+
2821
+ MRB_PRESYM_INIT_SYMBOLS(mrb, new_syms);
2822
+ p = mrb_proc_new(mrb, &new_irep);
2217
2823
  MRB_METHOD_FROM_PROC(m, p);
2218
- mrb_define_method_raw(mrb, cls, mrb_intern_lit(mrb, "new"), m);
2824
+ mrb_define_method_raw(mrb, cls, MRB_SYM(new), m);
2219
2825
  }
2220
2826
 
2827
+ /* implementation of #send method */
2828
+ mrb_value mrb_f_send(mrb_state *mrb, mrb_value self);
2829
+
2221
2830
  void
2222
2831
  mrb_init_class(mrb_state *mrb)
2223
2832
  {
@@ -2239,16 +2848,16 @@ mrb_init_class(mrb_state *mrb)
2239
2848
  make_metaclass(mrb, cls);
2240
2849
 
2241
2850
  /* name basic classes */
2242
- mrb_define_const(mrb, bob, "BasicObject", mrb_obj_value(bob));
2243
- mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj));
2244
- mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod));
2245
- mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls));
2851
+ mrb_define_const_id(mrb, bob, MRB_SYM(BasicObject), mrb_obj_value(bob));
2852
+ mrb_define_const_id(mrb, obj, MRB_SYM(Object), mrb_obj_value(obj));
2853
+ mrb_define_const_id(mrb, obj, MRB_SYM(Module), mrb_obj_value(mod));
2854
+ mrb_define_const_id(mrb, obj, MRB_SYM(Class), mrb_obj_value(cls));
2246
2855
 
2247
2856
  /* name each classes */
2248
- mrb_class_name_class(mrb, NULL, bob, mrb_intern_lit(mrb, "BasicObject"));
2249
- mrb_class_name_class(mrb, NULL, obj, mrb_intern_lit(mrb, "Object")); /* 15.2.1 */
2250
- mrb_class_name_class(mrb, NULL, mod, mrb_intern_lit(mrb, "Module")); /* 15.2.2 */
2251
- mrb_class_name_class(mrb, NULL, cls, mrb_intern_lit(mrb, "Class")); /* 15.2.3 */
2857
+ mrb_class_name_class(mrb, NULL, bob, MRB_SYM(BasicObject));
2858
+ mrb_class_name_class(mrb, NULL, obj, MRB_SYM(Object)); /* 15.2.1 */
2859
+ mrb_class_name_class(mrb, NULL, mod, MRB_SYM(Module)); /* 15.2.2 */
2860
+ mrb_class_name_class(mrb, NULL, cls, MRB_SYM(Class)); /* 15.2.3 */
2252
2861
 
2253
2862
  mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); /* 15.2.17 */
2254
2863
  MRB_SET_INSTANCE_TT(mrb->proc_class, MRB_TT_PROC);
@@ -2257,7 +2866,6 @@ mrb_init_class(mrb_state *mrb)
2257
2866
  mrb_define_method(mrb, bob, "initialize", mrb_bob_init, MRB_ARGS_NONE());
2258
2867
  mrb_define_method(mrb, bob, "!", mrb_bob_not, MRB_ARGS_NONE());
2259
2868
  mrb_define_method(mrb, bob, "==", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.1 */
2260
- mrb_define_method(mrb, bob, "!=", mrb_obj_not_equal_m, MRB_ARGS_REQ(1));
2261
2869
  mrb_define_method(mrb, bob, "__id__", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.4 */
2262
2870
  mrb_define_method(mrb, bob, "__send__", mrb_f_send, MRB_ARGS_REQ(1)|MRB_ARGS_REST()|MRB_ARGS_BLOCK()); /* 15.3.1.3.5 */
2263
2871
  mrb_define_method(mrb, bob, "equal?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.11 */