script_core 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -2,15 +2,14 @@
2
2
  spec.license = 'MIT'
3
3
  spec.author = 'mruby developers'
4
4
  spec.summary = 'mruby compiler executable'
5
-
6
5
  spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler'
7
6
 
8
7
  exec = exefile("#{build.build_dir}/bin/mrbc")
9
- mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten
8
+ mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }
10
9
 
11
- file exec => mrbc_objs + [build.libmruby_core_static] do |t|
10
+ file exec => mrbc_objs << build.libmruby_core_static do |t|
12
11
  build.linker.run t.name, t.prerequisites
13
12
  end
14
13
 
15
- build.bins << 'mrbc' unless build.bins.find { |v| v == 'mrbc' }
14
+ build.bins << 'mrbc'
16
15
  end
@@ -1,7 +1,11 @@
1
- #include <stdio.h>
1
+ #include <mruby.h>
2
+
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-mrbc conflicts 'MRB_NO_STDIO' in your build configuration
5
+ #endif
6
+
2
7
  #include <stdlib.h>
3
8
  #include <string.h>
4
- #include <mruby.h>
5
9
  #include <mruby/compile.h>
6
10
  #include <mruby/dump.h>
7
11
  #include <mruby/proc.h>
@@ -16,6 +20,7 @@ struct mrbc_args {
16
20
  const char *prog;
17
21
  const char *outfile;
18
22
  const char *initname;
23
+ mrb_bool dump_struct : 1;
19
24
  mrb_bool check_syntax : 1;
20
25
  mrb_bool verbose : 1;
21
26
  mrb_bool remove_lv : 1;
@@ -28,12 +33,11 @@ usage(const char *name)
28
33
  static const char *const usage_msg[] = {
29
34
  "switches:",
30
35
  "-c check syntax only",
31
- "-o<outfile> place the output into <outfile>",
36
+ "-o<outfile> place the output into <outfile>; required for multi-files",
32
37
  "-v print version number, then turn on verbose mode",
33
38
  "-g produce debugging information",
34
39
  "-B<symbol> binary <symbol> output in C language format",
35
- "-e generate little endian iseq data",
36
- "-E generate big endian iseq data",
40
+ "-S dump C struct (requires -B)",
37
41
  "--remove-lv remove local variables",
38
42
  "--verbose run at verbose mode",
39
43
  "--version print the version",
@@ -42,7 +46,7 @@ usage(const char *name)
42
46
  };
43
47
  const char *const *p = usage_msg;
44
48
 
45
- printf("Usage: %s [switches] programfile\n", name);
49
+ printf("Usage: %s [switches] programfile...\n", name);
46
50
  while (*p)
47
51
  printf(" %s\n", *p++);
48
52
  }
@@ -50,19 +54,26 @@ usage(const char *name)
50
54
  static char *
51
55
  get_outfilename(mrb_state *mrb, char *infile, const char *ext)
52
56
  {
53
- size_t infilelen;
54
- size_t extlen;
57
+ size_t ilen, flen, elen;
55
58
  char *outfile;
56
- char *p;
59
+ char *p = NULL;
57
60
 
58
- infilelen = strlen(infile);
59
- extlen = strlen(ext);
60
- outfile = (char*)mrb_malloc(mrb, infilelen + extlen + 1);
61
- memcpy(outfile, infile, infilelen + 1);
61
+ ilen = strlen(infile);
62
+ flen = ilen;
62
63
  if (*ext) {
63
- if ((p = strrchr(outfile, '.')) == NULL)
64
- p = outfile + infilelen;
65
- memcpy(p, ext, extlen + 1);
64
+ elen = strlen(ext);
65
+ if ((p = strrchr(infile, '.'))) {
66
+ ilen = p - infile;
67
+ }
68
+ flen += elen;
69
+ }
70
+ else {
71
+ flen = ilen;
72
+ }
73
+ outfile = (char*)mrb_malloc(mrb, flen+1);
74
+ strncpy(outfile, infile, ilen+1);
75
+ if (p) {
76
+ strncpy(outfile+ilen, ext, elen+1);
66
77
  }
67
78
 
68
79
  return outfile;
@@ -96,6 +107,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
96
107
  args->outfile = get_outfilename(mrb, argv[i] + 2, "");
97
108
  }
98
109
  break;
110
+ case 'S':
111
+ args->dump_struct = TRUE;
112
+ break;
99
113
  case 'B':
100
114
  if (argv[i][2] == '\0' && argv[i+1]) {
101
115
  i++;
@@ -120,10 +134,8 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
120
134
  args->flags |= DUMP_DEBUG_INFO;
121
135
  break;
122
136
  case 'E':
123
- args->flags = DUMP_ENDIAN_BIG | (args->flags & ~DUMP_ENDIAN_MASK);
124
- break;
125
137
  case 'e':
126
- args->flags = DUMP_ENDIAN_LIL | (args->flags & ~DUMP_ENDIAN_MASK);
138
+ fprintf(stderr, "%s: -e/-E option no longer needed.\n", args->prog);
127
139
  break;
128
140
  case 'h':
129
141
  return -1;
@@ -156,10 +168,6 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
156
168
  break;
157
169
  }
158
170
  }
159
- if (args->verbose && args->initname && (args->flags & DUMP_ENDIAN_MASK) == 0) {
160
- fprintf(stderr, "%s: generating %s endian C file. specify -e/-E for cross compiling.\n",
161
- args->prog, bigendian_p() ? "big" : "little");
162
- }
163
171
  return i;
164
172
  }
165
173
 
@@ -235,13 +243,18 @@ static int
235
243
  dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, struct mrbc_args *args)
236
244
  {
237
245
  int n = MRB_DUMP_OK;
238
- mrb_irep *irep = proc->body.irep;
246
+ const mrb_irep *irep = proc->body.irep;
239
247
 
240
248
  if (args->remove_lv) {
241
- mrb_irep_remove_lv(mrb, irep);
249
+ mrb_irep_remove_lv(mrb, (mrb_irep*)irep);
242
250
  }
243
251
  if (args->initname) {
244
- n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
252
+ if (args->dump_struct) {
253
+ n = mrb_dump_irep_cstruct(mrb, irep, args->flags, wfp, args->initname);
254
+ }
255
+ else {
256
+ n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
257
+ }
245
258
  if (n == MRB_DUMP_INVALID_ARGUMENT) {
246
259
  fprintf(stderr, "%s: invalid C language symbol name\n", args->initname);
247
260
  }
@@ -258,7 +271,7 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st
258
271
  int
259
272
  main(int argc, char **argv)
260
273
  {
261
- mrb_state *mrb = mrb_open();
274
+ mrb_state *mrb = mrb_open_core(NULL, NULL);
262
275
  int n, result;
263
276
  struct mrbc_args args;
264
277
  FILE *wfp;
@@ -331,7 +344,7 @@ mrb_init_mrblib(mrb_state *mrb)
331
344
  {
332
345
  }
333
346
 
334
- #ifndef DISABLE_GEMS
347
+ #ifndef MRB_NO_GEMS
335
348
  void
336
349
  mrb_init_mrbgems(mrb_state *mrb)
337
350
  {
@@ -19,7 +19,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
19
19
  script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
20
20
  File.write script.path, 'p "ok"'
21
21
  system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
22
- o = `#{cmd('mruby')} -b #{bin.path}`.strip
22
+ o = `#{cmd('mruby')} #{bin.path}`.strip
23
23
  assert_equal '"ok"', o
24
24
  end
25
25
 
@@ -33,7 +33,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
33
33
 
34
34
  # .mrb file
35
35
  `#{cmd('mrbc')} -o "#{bin.path}" "#{script.path}"`
36
- assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} -b "#{bin.path}"`.chomp
36
+ assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} "#{bin.path}"`.chomp
37
37
 
38
38
  # one liner
39
39
  assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp
@@ -48,7 +48,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
48
48
  script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
49
49
  File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]'
50
50
  system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
51
- assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} -b #{bin.path}`.chomp!
51
+ assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} #{bin.path}`.chomp!
52
52
  end
53
53
 
54
54
  assert '__END__', '8.6' do
@@ -129,7 +129,7 @@ def hoge
129
129
  end
130
130
 
131
131
  assert('mruby -v option') do
132
- ver_re = '\Amruby \d+\.\d+\.\d+ \(\d+-\d+-\d+\)\n'
132
+ ver_re = '\Amruby \d+\.\d+\.\d+.* \(\d+-\d+-\d+\)\n'
133
133
  assert_mruby(/#{ver_re}\z/, "", true, %w[-v])
134
134
  assert_mruby(/#{ver_re}^[^\n]*NODE.*\n:end\n\z/m, "", true, %w[-v -e p(:end)])
135
135
  end
@@ -162,3 +162,24 @@ def hoge
162
162
  code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end"
163
163
  assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code])
164
164
  end
165
+
166
+ assert('top level local variables are in file scope') do
167
+ arb, amrb = Tempfile.new('a.rb'), Tempfile.new('a.mrb')
168
+ brb, bmrb = Tempfile.new('b.rb'), Tempfile.new('b.mrb')
169
+ crb, cmrb = Tempfile.new('c.rb'), Tempfile.new('c.mrb')
170
+ drb, dmrb = Tempfile.new('d.rb'), Tempfile.new('d.mrb')
171
+
172
+ File.write arb.path, 'a = 1'
173
+ system "#{cmd('mrbc')} -g -o #{amrb.path} #{arb.path}"
174
+ File.write brb.path, 'p a'
175
+ system "#{cmd('mrbc')} -g -o #{bmrb.path} #{brb.path}"
176
+ assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-r", arb.path, brb.path])
177
+ assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-b", "-r", amrb.path, bmrb.path])
178
+
179
+ File.write crb.path, 'a, b, c = 1, 2, 3; A = -> { b = -2; [a, b, c] }'
180
+ system "#{cmd('mrbc')} -g -o #{cmrb.path} #{crb.path}"
181
+ File.write drb.path, 'a, b = 5, 6; p A.call; p a, b'
182
+ system "#{cmd('mrbc')} -g -o #{dmrb.path} #{drb.path}"
183
+ assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-r", crb.path, drb.path])
184
+ assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-b", "-r", cmrb.path, dmrb.path])
185
+ end
@@ -4,10 +4,9 @@
4
4
  spec.summary = 'mruby command'
5
5
  spec.bins = %w(mruby)
6
6
  spec.add_dependency('mruby-compiler', :core => 'mruby-compiler')
7
- spec.add_dependency('mruby-error', :core => 'mruby-error')
8
7
  spec.add_test_dependency('mruby-print', :core => 'mruby-print')
9
8
 
10
9
  if build.cxx_exception_enabled?
11
- build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c", "#{spec.build_dir}/tools/mruby/mruby.cxx")
10
+ build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c")
12
11
  end
13
12
  end
@@ -1,11 +1,21 @@
1
- #include <stdio.h>
1
+ #include <mruby.h>
2
+
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-mruby conflicts 'MRB_NO_STDIO' in your build configuration
5
+ #endif
6
+
2
7
  #include <stdlib.h>
3
8
  #include <string.h>
4
- #include <mruby.h>
5
9
  #include <mruby/array.h>
6
10
  #include <mruby/compile.h>
7
11
  #include <mruby/dump.h>
8
12
  #include <mruby/variable.h>
13
+ #include <mruby/proc.h>
14
+
15
+ #if defined(_WIN32) || defined(_WIN64)
16
+ # include <io.h> /* for setmode */
17
+ # include <fcntl.h>
18
+ #endif
9
19
 
10
20
  struct _args {
11
21
  FILE *rfp;
@@ -213,7 +223,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
213
223
  }
214
224
  else {
215
225
  args->rfp = strcmp(argv[0], "-") == 0 ?
216
- stdin : fopen(argv[0], args->mrbfile ? "rb" : "r");
226
+ stdin : fopen(argv[0], "rb");
217
227
  if (args->rfp == NULL) {
218
228
  fprintf(stderr, "%s: Cannot open program file: %s\n", opts->program, argv[0]);
219
229
  return EXIT_FAILURE;
@@ -223,6 +233,11 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
223
233
  argc--; argv++;
224
234
  }
225
235
  }
236
+ #if defined(_WIN32) || defined(_WIN64)
237
+ if (args->rfp == stdin) {
238
+ _setmode(_fileno(stdin), O_BINARY);
239
+ }
240
+ #endif
226
241
  args->argv = (char **)mrb_realloc(mrb, args->argv, sizeof(char*) * (argc + 1));
227
242
  memcpy(args->argv, argv, (argc+1) * sizeof(char*));
228
243
  args->argc = argc;
@@ -303,7 +318,8 @@ main(int argc, char **argv)
303
318
 
304
319
  /* Load libraries */
305
320
  for (i = 0; i < args.libc; i++) {
306
- FILE *lfp = fopen(args.libv[i], args.mrbfile ? "rb" : "r");
321
+ struct REnv *e;
322
+ FILE *lfp = fopen(args.libv[i], "rb");
307
323
  if (lfp == NULL) {
308
324
  fprintf(stderr, "%s: Cannot open library file: %s\n", *argv, args.libv[i]);
309
325
  mrbc_context_free(mrb, c);
@@ -314,9 +330,13 @@ main(int argc, char **argv)
314
330
  v = mrb_load_irep_file_cxt(mrb, lfp, c);
315
331
  }
316
332
  else {
317
- v = mrb_load_file_cxt(mrb, lfp, c);
333
+ v = mrb_load_detect_file_cxt(mrb, lfp, c);
318
334
  }
319
335
  fclose(lfp);
336
+ e = mrb_vm_ci_env(mrb->c->cibase);
337
+ mrb_vm_ci_env_set(mrb->c->cibase, NULL);
338
+ mrb_env_unshare(mrb, e);
339
+ mrbc_cleanup_local_variables(mrb, c);
320
340
  }
321
341
 
322
342
  /* Load program */
@@ -324,7 +344,7 @@ main(int argc, char **argv)
324
344
  v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
325
345
  }
326
346
  else if (args.rfp) {
327
- v = mrb_load_file_cxt(mrb, args.rfp, c);
347
+ v = mrb_load_detect_file_cxt(mrb, args.rfp, c);
328
348
  }
329
349
  else {
330
350
  char* utf8 = mrb_utf8_from_locale(args.cmdline, -1);
@@ -32,7 +32,7 @@
32
32
  o = `#{cmd('mruby-strip')} #{compiled1.path}`
33
33
  assert_equal 0, $?.exitstatus
34
34
  assert_equal "", o
35
- assert_equal `#{cmd('mruby')} #{script_file.path}`, `#{cmd('mruby')} -b #{compiled1.path}`
35
+ assert_equal `#{cmd('mruby')} #{script_file.path}`, `#{cmd('mruby')} #{compiled1.path}`
36
36
 
37
37
  o = `#{cmd('mruby-strip')} #{compiled1.path} #{compiled2.path}`
38
38
  assert_equal 0, $?.exitstatus
@@ -1,7 +1,11 @@
1
- #include <stdio.h>
1
+ #include <mruby.h>
2
+
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-strip conflicts 'MRB_NO_STDIO' in your build configuration
5
+ #endif
6
+
2
7
  #include <stdlib.h>
3
8
  #include <string.h>
4
- #include <mruby.h>
5
9
  #include <mruby/irep.h>
6
10
  #include <mruby/dump.h>
7
11
 
@@ -0,0 +1,5 @@
1
+ MRuby::Gem::Specification.new('mruby-catch') do |spec|
2
+ spec.license = 'MIT'
3
+ spec.author = 'mruby developers'
4
+ spec.summary = 'Catch / Throw non-local Jump'
5
+ end
@@ -0,0 +1,27 @@
1
+ class ThrowCatchJump < Exception
2
+ def initialize(tag, val)
3
+ @tag = tag
4
+ @val = val
5
+ super("uncaught throw :#{tag}")
6
+ end
7
+ def _tag
8
+ @tag
9
+ end
10
+ def _val
11
+ @val
12
+ end
13
+ end
14
+
15
+ module Kernel
16
+ def catch(tag, &block)
17
+ block.call(tag)
18
+ rescue ThrowCatchJump => e
19
+ unless e._tag == tag
20
+ raise e
21
+ end
22
+ return e._val
23
+ end
24
+ def throw(tag, val=nil)
25
+ raise ThrowCatchJump.new(tag, val)
26
+ end
27
+ end
@@ -1,6 +1,7 @@
1
1
  #include "mruby.h"
2
2
  #include "mruby/class.h"
3
3
  #include "mruby/string.h"
4
+ #include "mruby/proc.h"
4
5
 
5
6
  static mrb_value
6
7
  mrb_mod_name(mrb_state *mrb, mrb_value self)
@@ -43,10 +44,15 @@ mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
43
44
  const mrb_value *argv;
44
45
  mrb_int argc;
45
46
  mrb_value blk;
47
+ struct RClass *c;
46
48
 
47
49
  mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
48
50
 
49
- mrb->c->ci->target_class = mrb_class_ptr(self);
51
+ c = mrb_class_ptr(self);
52
+ if (mrb->c->ci->acc < 0) {
53
+ return mrb_yield_with_class(mrb, blk, argc, argv, self, c);
54
+ }
55
+ mrb_vm_ci_target_class_set(mrb->c->ci, c);
50
56
  return mrb_yield_cont(mrb, blk, self, argc, argv);
51
57
  }
52
58
 
@@ -5,16 +5,17 @@
5
5
  */
6
6
 
7
7
  #include <ctype.h>
8
- #include <limits.h>
9
8
  #include <stdlib.h>
10
9
  #include <string.h>
11
10
  #include <math.h>
12
11
  #include <mruby.h>
13
12
  #include <mruby/compile.h>
14
13
  #include <mruby/proc.h>
14
+ #include <mruby/dump.h>
15
15
  #include <mruby/numeric.h>
16
16
  #include <mruby/string.h>
17
17
  #include <mruby/debug.h>
18
+ #include <mruby/presym.h>
18
19
  #include "node.h"
19
20
  #include <mruby/opcode.h>
20
21
  #include <mruby/re.h>
@@ -39,8 +40,8 @@ enum looptype {
39
40
 
40
41
  struct loopinfo {
41
42
  enum looptype type;
42
- int pc0, pc1, pc2, pc3, acc;
43
- int ensure_level;
43
+ uint32_t pc0, pc1, pc2, pc3;
44
+ int acc;
44
45
  struct loopinfo *prev;
45
46
  };
46
47
 
@@ -54,14 +55,13 @@ typedef struct scope {
54
55
  node *lv;
55
56
 
56
57
  uint16_t sp;
57
- uint16_t pc;
58
- uint16_t lastpc;
59
- uint16_t lastlabel;
58
+ uint32_t pc;
59
+ uint32_t lastpc;
60
+ uint32_t lastlabel;
60
61
  int ainfo:15;
61
62
  mrb_bool mscope:1;
62
63
 
63
64
  struct loopinfo *loop;
64
- int ensure_level;
65
65
  mrb_sym filename_sym;
66
66
  uint16_t lineno;
67
67
 
@@ -70,6 +70,10 @@ typedef struct scope {
70
70
  uint32_t icapa;
71
71
 
72
72
  mrb_irep *irep;
73
+ mrb_pool_value *pool;
74
+ mrb_sym *syms;
75
+ mrb_irep **reps;
76
+ struct mrb_irep_catch_handler *catch_table;
73
77
  uint32_t pcapa, scapa, rcapa;
74
78
 
75
79
  uint16_t nlocals;
@@ -89,6 +93,15 @@ static struct loopinfo *loop_push(codegen_scope *s, enum looptype t);
89
93
  static void loop_break(codegen_scope *s, node *tree);
90
94
  static void loop_pop(codegen_scope *s, int val);
91
95
 
96
+ /*
97
+ * The search for catch handlers starts at the end of the table in mrb_vm_run().
98
+ * Therefore, the next handler to be added must meet one of the following conditions.
99
+ * - Larger start position
100
+ * - Same start position but smaller end position
101
+ */
102
+ static int catch_handler_new(codegen_scope *s);
103
+ static void catch_handler_set(codegen_scope *s, int ent, enum mrb_catch_type type, uint32_t begin, uint32_t end, uint32_t target);
104
+
92
105
  static void gen_assignment(codegen_scope *s, node *tree, int sp, int val);
93
106
  static void gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val);
94
107
 
@@ -101,12 +114,31 @@ codegen_error(codegen_scope *s, const char *message)
101
114
  if (!s) return;
102
115
  while (s->prev) {
103
116
  codegen_scope *tmp = s->prev;
104
- mrb_free(s->mrb, s->iseq);
105
- mrb_free(s->mrb, s->lines);
117
+ if (s->irep) {
118
+ mrb_free(s->mrb, s->iseq);
119
+ for (int i=0; i<s->irep->plen; i++) {
120
+ mrb_pool_value *pv = &s->pool[i];
121
+ if ((pv->tt & 0x3) == IREP_TT_STR) {
122
+ mrb_free(s->mrb, (void*)pv->u.str);
123
+ }
124
+ }
125
+ mrb_free(s->mrb, s->pool);
126
+ mrb_free(s->mrb, s->syms);
127
+ mrb_free(s->mrb, s->catch_table);
128
+ if (s->reps) {
129
+ /* copied from mrb_irep_free() in state.c */
130
+ for (int i=0; i<s->irep->rlen; i++) {
131
+ if (s->reps[i])
132
+ mrb_irep_decref(s->mrb, (mrb_irep*)s->reps[i]);
133
+ }
134
+ mrb_free(s->mrb, s->reps);
135
+ }
136
+ mrb_free(s->mrb, s->lines);
137
+ }
106
138
  mrb_pool_close(s->mpool);
107
139
  s = tmp;
108
140
  }
109
- #ifndef MRB_DISABLE_STDIO
141
+ #ifndef MRB_NO_STDIO
110
142
  if (s->filename_sym && s->lineno) {
111
143
  const char *filename = mrb_sym_name_len(s->mrb, s->filename_sym, NULL);
112
144
  fprintf(stderr, "codegen error:%s:%d: %s\n", filename, s->lineno, message);
@@ -145,13 +177,15 @@ new_label(codegen_scope *s)
145
177
  static void
146
178
  emit_B(codegen_scope *s, uint32_t pc, uint8_t i)
147
179
  {
148
- if (pc >= MAXARG_S || s->icapa >= MAXARG_S) {
149
- codegen_error(s, "too big code block");
150
- }
151
180
  if (pc >= s->icapa) {
152
- s->icapa *= 2;
153
- if (s->icapa > MAXARG_S) {
154
- s->icapa = MAXARG_S;
181
+ if (pc == UINT32_MAX) {
182
+ codegen_error(s, "too big code block");
183
+ }
184
+ if (pc >= UINT32_MAX / 2) {
185
+ pc = UINT32_MAX;
186
+ }
187
+ else {
188
+ s->icapa *= 2;
155
189
  }
156
190
  s->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->icapa);
157
191
  if (s->lines) {
@@ -203,9 +237,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a)
203
237
  {
204
238
  s->lastpc = s->pc;
205
239
  if (a > 0xff) {
206
- gen_B(s, OP_EXT1);
207
- gen_B(s, i);
208
- gen_S(s, a);
240
+ codegen_error(s, "too big operand");
209
241
  }
210
242
  else {
211
243
  gen_B(s, i);
@@ -217,24 +249,30 @@ static void
217
249
  genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
218
250
  {
219
251
  s->lastpc = s->pc;
220
- if (a > 0xff && b > 0xff) {
221
- gen_B(s, OP_EXT3);
222
- gen_B(s, i);
223
- gen_S(s, a);
224
- gen_S(s, b);
252
+ if (a > 0xff || b > 0xff) {
253
+ codegen_error(s, "too big operand");
225
254
  }
226
- else if (b > 0xff) {
227
- gen_B(s, OP_EXT2);
255
+ else {
228
256
  gen_B(s, i);
229
257
  gen_B(s, (uint8_t)a);
230
- gen_S(s, b);
231
- }
232
- else if (a > 0xff) {
233
- gen_B(s, OP_EXT1);
234
- gen_B(s, i);
235
- gen_S(s, a);
236
258
  gen_B(s, (uint8_t)b);
237
259
  }
260
+ }
261
+
262
+ /* similar to `genop_2` but generate `genop_2S` with `i+1` */
263
+ /* works for OP_LOADL, OP_LOADSYM, OP_STRING */
264
+ static void
265
+ genop_bs(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
266
+ {
267
+ s->lastpc = s->pc;
268
+ if (a > 0xff || b > 0xffff) {
269
+ codegen_error(s, "too big operand");
270
+ }
271
+ if (b > 0xff) {
272
+ gen_B(s, i+1);
273
+ gen_B(s, (uint8_t)a);
274
+ gen_S(s, b);
275
+ }
238
276
  else {
239
277
  gen_B(s, i);
240
278
  gen_B(s, (uint8_t)a);
@@ -256,6 +294,14 @@ genop_2S(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
256
294
  gen_S(s, b);
257
295
  }
258
296
 
297
+ static void
298
+ genop_2SS(codegen_scope *s, mrb_code i, uint16_t a, uint32_t b)
299
+ {
300
+ genop_1(s, i, a);
301
+ gen_S(s, b>>16);
302
+ gen_S(s, b&0xffff);
303
+ }
304
+
259
305
  static void
260
306
  genop_W(codegen_scope *s, mrb_code i, uint32_t a)
261
307
  {
@@ -281,15 +327,6 @@ no_optimize(codegen_scope *s)
281
327
  return FALSE;
282
328
  }
283
329
 
284
- static
285
- mrb_bool
286
- on_eval(codegen_scope *s)
287
- {
288
- if (s && s->parser && s->parser->on_eval)
289
- return TRUE;
290
- return FALSE;
291
- }
292
-
293
330
  struct mrb_insn_data
294
331
  mrb_decode_insn(const mrb_code *pc)
295
332
  {
@@ -297,39 +334,13 @@ mrb_decode_insn(const mrb_code *pc)
297
334
  mrb_code insn = READ_B();
298
335
  uint16_t a = 0;
299
336
  uint16_t b = 0;
300
- uint8_t c = 0;
337
+ uint16_t c = 0;
301
338
 
302
339
  switch (insn) {
303
340
  #define FETCH_Z() /* empty */
304
341
  #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break;
305
342
  #include "mruby/ops.h"
306
343
  #undef OPCODE
307
- }
308
- switch (insn) {
309
- case OP_EXT1:
310
- insn = READ_B();
311
- switch (insn) {
312
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break;
313
- #include "mruby/ops.h"
314
- #undef OPCODE
315
- }
316
- break;
317
- case OP_EXT2:
318
- insn = READ_B();
319
- switch (insn) {
320
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break;
321
- #include "mruby/ops.h"
322
- #undef OPCODE
323
- }
324
- break;
325
- case OP_EXT3:
326
- insn = READ_B();
327
- switch (insn) {
328
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break;
329
- #include "mruby/ops.h"
330
- #undef OPCODE
331
- }
332
- break;
333
344
  default:
334
345
  break;
335
346
  }
@@ -358,22 +369,44 @@ no_peephole(codegen_scope *s)
358
369
  return no_optimize(s) || s->lastlabel == s->pc || s->pc == 0 || s->pc == s->lastpc;
359
370
  }
360
371
 
361
- static uint16_t
362
- genjmp(codegen_scope *s, mrb_code i, uint16_t pc)
372
+ #define JMPLINK_START UINT32_MAX
373
+
374
+ static void
375
+ gen_jmpdst(codegen_scope *s, uint32_t pc)
363
376
  {
364
- uint16_t pos;
377
+
378
+ if (pc == JMPLINK_START) {
379
+ gen_S(s, 0);
380
+ }
381
+ else {
382
+ uint32_t pos2 = s->pc+2;
383
+ int32_t off = pc - pos2;
384
+
385
+ if (off > INT16_MAX || INT16_MIN > off) {
386
+ codegen_error(s, "too big jump offset");
387
+ }
388
+ gen_S(s, (uint16_t)off);
389
+ }
390
+ }
391
+
392
+ static uint32_t
393
+ genjmp(codegen_scope *s, mrb_code i, uint32_t pc)
394
+ {
395
+ uint32_t pos;
365
396
 
366
397
  s->lastpc = s->pc;
367
398
  gen_B(s, i);
368
399
  pos = s->pc;
369
- gen_S(s, pc);
400
+ gen_jmpdst(s, pc);
370
401
  return pos;
371
402
  }
372
403
 
373
- static uint16_t
374
- genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
404
+ #define genjmp_0(s,i) genjmp(s,i,JMPLINK_START)
405
+
406
+ static uint32_t
407
+ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, uint32_t pc, int val)
375
408
  {
376
- uint16_t pos;
409
+ uint32_t pos;
377
410
 
378
411
  if (!no_peephole(s) && !val) {
379
412
  struct mrb_insn_data data = mrb_last_insn(s);
@@ -386,30 +419,26 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
386
419
 
387
420
  s->lastpc = s->pc;
388
421
  if (a > 0xff) {
389
- gen_B(s, OP_EXT1);
390
- gen_B(s, i);
391
- gen_S(s, a);
392
- pos = s->pc;
393
- gen_S(s, pc);
422
+ codegen_error(s, "too big operand");
423
+ pos = 0;
394
424
  }
395
425
  else {
396
426
  gen_B(s, i);
397
427
  gen_B(s, (uint8_t)a);
398
428
  pos = s->pc;
399
- gen_S(s, pc);
429
+ gen_jmpdst(s, pc);
400
430
  }
401
431
  return pos;
402
432
  }
403
433
 
434
+ #define genjmp2_0(s,i,a,val) genjmp2(s,i,a,JMPLINK_START,val)
435
+
404
436
  static void
405
437
  gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
406
438
  {
407
439
  if (no_peephole(s)) {
408
440
  normal:
409
441
  genop_2(s, OP_MOVE, dst, src);
410
- if (on_eval(s)) {
411
- genop_0(s, OP_NOP);
412
- }
413
442
  return;
414
443
  }
415
444
  else {
@@ -429,10 +458,13 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
429
458
  s->pc = s->lastpc;
430
459
  genop_1(s, data.insn, dst);
431
460
  break;
432
- case OP_LOADI: case OP_LOADINEG: case OP_LOADL: case OP_LOADSYM:
461
+ case OP_LOADI: case OP_LOADINEG:
462
+ case OP_LOADL: case OP_LOADSYM:
463
+ case OP_LOADL16: case OP_LOADSYM16:
433
464
  case OP_GETGV: case OP_GETSV: case OP_GETIV: case OP_GETCV:
434
- case OP_GETCONST: case OP_STRING:
465
+ case OP_GETCONST: case OP_STRING: case OP_STRING16:
435
466
  case OP_LAMBDA: case OP_BLOCK: case OP_METHOD: case OP_BLKPUSH:
467
+ case OP_LAMBDA16: case OP_BLOCK16: case OP_METHOD16:
436
468
  if (nopeep || data.a != src || data.a < s->nlocals) goto normal;
437
469
  s->pc = s->lastpc;
438
470
  genop_2(s, data.insn, dst, data.b);
@@ -500,21 +532,31 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
500
532
  }
501
533
  }
502
534
 
503
- static int
504
- dispatch(codegen_scope *s, uint16_t pos0)
535
+ static uint32_t
536
+ dispatch(codegen_scope *s, uint32_t pos0)
505
537
  {
506
- uint16_t newpos;
538
+ int32_t pos1;
539
+ int32_t offset;
540
+ int16_t newpos;
507
541
 
542
+ if (pos0 == JMPLINK_START) return 0;
543
+
544
+ pos1 = pos0 + 2;
545
+ offset = s->pc - pos1;
546
+ if (offset > INT16_MAX) {
547
+ codegen_error(s, "too big jmp offset");
548
+ }
508
549
  s->lastlabel = s->pc;
509
- newpos = PEEK_S(s->iseq+pos0);
510
- emit_S(s, pos0, s->pc);
511
- return newpos;
550
+ newpos = (int16_t)PEEK_S(s->iseq+pos0);
551
+ emit_S(s, pos0, (uint16_t)offset);
552
+ if (newpos == 0) return 0;
553
+ return pos1+newpos;
512
554
  }
513
555
 
514
556
  static void
515
- dispatch_linked(codegen_scope *s, uint16_t pos)
557
+ dispatch_linked(codegen_scope *s, uint32_t pos)
516
558
  {
517
- if (pos==0) return;
559
+ if (pos==JMPLINK_START) return;
518
560
  for (;;) {
519
561
  pos = dispatch(s, pos);
520
562
  if (pos==0) break;
@@ -551,37 +593,46 @@ static inline int
551
593
  new_lit(codegen_scope *s, mrb_value val)
552
594
  {
553
595
  int i;
554
- mrb_value *pv;
596
+ mrb_pool_value *pv;
555
597
 
556
598
  switch (mrb_type(val)) {
557
599
  case MRB_TT_STRING:
558
600
  for (i=0; i<s->irep->plen; i++) {
559
601
  mrb_int len;
560
- pv = &s->irep->pool[i];
561
-
562
- if (!mrb_string_p(*pv)) continue;
563
- if ((len = RSTRING_LEN(*pv)) != RSTRING_LEN(val)) continue;
564
- if (memcmp(RSTRING_PTR(*pv), RSTRING_PTR(val), len) == 0)
602
+ pv = &s->pool[i];
603
+ if (pv->tt & IREP_TT_NFLAG) continue;
604
+ len = pv->tt>>2;
605
+ if (RSTRING_LEN(val) != len) continue;
606
+ if (memcmp(pv->u.str, RSTRING_PTR(val), len) == 0)
565
607
  return i;
566
608
  }
567
609
  break;
568
- #ifndef MRB_WITHOUT_FLOAT
610
+ #ifndef MRB_NO_FLOAT
569
611
  case MRB_TT_FLOAT:
570
612
  for (i=0; i<s->irep->plen; i++) {
571
613
  mrb_float f1, f2;
572
- pv = &s->irep->pool[i];
573
- if (!mrb_float_p(*pv)) continue;
574
- f1 = mrb_float(*pv);
614
+ pv = &s->pool[i];
615
+ if (pv->tt != IREP_TT_FLOAT) continue;
616
+ pv = &s->pool[i];
617
+ f1 = pv->u.f;
575
618
  f2 = mrb_float(val);
576
619
  if (f1 == f2 && !signbit(f1) == !signbit(f2)) return i;
577
620
  }
578
621
  break;
579
622
  #endif
580
- case MRB_TT_FIXNUM:
623
+ case MRB_TT_INTEGER:
581
624
  for (i=0; i<s->irep->plen; i++) {
582
- pv = &s->irep->pool[i];
583
- if (!mrb_fixnum_p(*pv)) continue;
584
- if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i;
625
+ mrb_int v = mrb_integer(val);
626
+ pv = &s->pool[i];
627
+ if (pv->tt == IREP_TT_INT32) {
628
+ if (v == pv->u.i32) return i;
629
+ }
630
+ #ifdef MRB_64BIT
631
+ else if (pv->tt == IREP_TT_INT64) {
632
+ if (v == pv->u.i64) return i;
633
+ }
634
+ continue;
635
+ #endif
585
636
  }
586
637
  break;
587
638
  default:
@@ -591,26 +642,43 @@ new_lit(codegen_scope *s, mrb_value val)
591
642
 
592
643
  if (s->irep->plen == s->pcapa) {
593
644
  s->pcapa *= 2;
594
- s->irep->pool = (mrb_value *)codegen_realloc(s, s->irep->pool, sizeof(mrb_value)*s->pcapa);
645
+ s->pool = (mrb_pool_value*)codegen_realloc(s, s->pool, sizeof(mrb_pool_value)*s->pcapa);
595
646
  }
596
647
 
597
- pv = &s->irep->pool[s->irep->plen];
648
+ pv = &s->pool[s->irep->plen];
598
649
  i = s->irep->plen++;
599
650
 
600
651
  switch (mrb_type(val)) {
601
652
  case MRB_TT_STRING:
602
- *pv = mrb_str_pool(s->mrb, RSTRING_PTR(val), RSTRING_LEN(val), RSTR_NOFREE_P(RSTRING(val)));
653
+ if (RSTR_NOFREE_P(RSTRING(val))) {
654
+ pv->tt = (uint32_t)(RSTRING_LEN(val)<<2) | IREP_TT_SSTR;
655
+ pv->u.str = RSTRING_PTR(val);
656
+ }
657
+ else {
658
+ char *p;
659
+ mrb_int len = RSTRING_LEN(val);
660
+ pv->tt = (uint32_t)(len<<2) | IREP_TT_STR;
661
+ p = (char*)codegen_realloc(s, NULL, len+1);
662
+ memcpy(p, RSTRING_PTR(val), len);
663
+ p[len] = '\0';
664
+ pv->u.str = p;
665
+ }
603
666
  break;
604
667
 
605
- #ifndef MRB_WITHOUT_FLOAT
668
+ #ifndef MRB_NO_FLOAT
606
669
  case MRB_TT_FLOAT:
607
- #ifdef MRB_WORD_BOXING
608
- *pv = mrb_float_pool(s->mrb, mrb_float(val));
670
+ pv->tt = IREP_TT_FLOAT;
671
+ pv->u.f = mrb_float(val);
609
672
  break;
610
673
  #endif
674
+ case MRB_TT_INTEGER:
675
+ #ifdef MRB_INT64
676
+ pv->tt = IREP_TT_INT64;
677
+ pv->u.i64 = mrb_integer(val);
678
+ #else
679
+ pv->tt = IREP_TT_INT32;
680
+ pv->u.i32 = mrb_integer(val);
611
681
  #endif
612
- case MRB_TT_FIXNUM:
613
- *pv = val;
614
682
  break;
615
683
 
616
684
  default:
@@ -620,9 +688,6 @@ new_lit(codegen_scope *s, mrb_value val)
620
688
  return i;
621
689
  }
622
690
 
623
- /* maximum symbol numbers */
624
- #define MAXSYMLEN 0x10000
625
-
626
691
  static int
627
692
  new_sym(codegen_scope *s, mrb_sym sym)
628
693
  {
@@ -632,13 +697,16 @@ new_sym(codegen_scope *s, mrb_sym sym)
632
697
 
633
698
  len = s->irep->slen;
634
699
  for (i=0; i<len; i++) {
635
- if (s->irep->syms[i] == sym) return i;
700
+ if (s->syms[i] == sym) return i;
636
701
  }
637
702
  if (s->irep->slen >= s->scapa) {
638
703
  s->scapa *= 2;
639
- s->irep->syms = (mrb_sym*)codegen_realloc(s, s->irep->syms, sizeof(mrb_sym)*s->scapa);
704
+ if (s->scapa > 0xffff) {
705
+ codegen_error(s, "too many symbols");
706
+ }
707
+ s->syms = (mrb_sym*)codegen_realloc(s, s->syms, sizeof(mrb_sym)*s->scapa);
640
708
  }
641
- s->irep->syms[s->irep->slen] = sym;
709
+ s->syms[s->irep->slen] = sym;
642
710
  return s->irep->slen++;
643
711
  }
644
712
 
@@ -674,6 +742,45 @@ lv_idx(codegen_scope *s, mrb_sym id)
674
742
  return 0;
675
743
  }
676
744
 
745
+ static int
746
+ search_upvar(codegen_scope *s, mrb_sym id, int *idx)
747
+ {
748
+ const struct RProc *u;
749
+ int lv = 0;
750
+ codegen_scope *up = s->prev;
751
+
752
+ while (up) {
753
+ *idx = lv_idx(up, id);
754
+ if (*idx > 0) {
755
+ return lv;
756
+ }
757
+ lv ++;
758
+ up = up->prev;
759
+ }
760
+
761
+ if (lv < 1) lv = 1;
762
+ u = s->parser->upper;
763
+ while (u && !MRB_PROC_CFUNC_P(u)) {
764
+ const struct mrb_irep *ir = u->body.irep;
765
+ uint_fast16_t n = ir->nlocals;
766
+ int i;
767
+
768
+ const mrb_sym *v = ir->lv;
769
+ for (i=1; n > 1; n--, v++, i++) {
770
+ if (*v == id) {
771
+ *idx = i;
772
+ return lv - 1;
773
+ }
774
+ }
775
+ if (MRB_PROC_SCOPE_P(u)) break;
776
+ u = u->upper;
777
+ lv ++;
778
+ }
779
+
780
+ codegen_error(s, "Can't found local variables");
781
+ return -1; /* not reached */
782
+ }
783
+
677
784
  static void
678
785
  for_body(codegen_scope *s, node *tree)
679
786
  {
@@ -712,7 +819,7 @@ for_body(codegen_scope *s, node *tree)
712
819
  genop_2(s, OP_BLOCK, cursp(), s->irep->rlen-1);
713
820
  push();pop(); /* space for a block */
714
821
  pop();
715
- idx = new_sym(s, mrb_intern_lit(s->mrb, "each"));
822
+ idx = new_sym(s, MRB_SYM_2(s->mrb, each));
716
823
  genop_3(s, OP_SENDB, cursp(), idx, 0);
717
824
  }
718
825
 
@@ -749,7 +856,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
749
856
  oa = node_len(tree->car->cdr->car);
750
857
  /* rest argument? */
751
858
  ra = tree->car->cdr->cdr->car ? 1 : 0;
752
- /* mandatory arugments after rest argument */
859
+ /* mandatory arguments after rest argument */
753
860
  pa = node_len(tree->car->cdr->cdr->cdr->car);
754
861
  pargs = tree->car->cdr->cdr->cdr->car;
755
862
  /* keyword arguments */
@@ -777,21 +884,28 @@ lambda_body(codegen_scope *s, node *tree, int blk)
777
884
  pos = new_label(s);
778
885
  for (i=0; i<oa; i++) {
779
886
  new_label(s);
780
- genjmp(s, OP_JMP, 0);
887
+ genjmp_0(s, OP_JMP);
781
888
  }
782
889
  if (oa > 0) {
783
- genjmp(s, OP_JMP, 0);
890
+ genjmp_0(s, OP_JMP);
784
891
  }
785
892
  opt = tree->car->cdr->car;
786
893
  i = 0;
787
894
  while (opt) {
788
895
  int idx;
896
+ mrb_sym id = nsym(opt->car->car);
789
897
 
790
898
  dispatch(s, pos+i*3+1);
791
899
  codegen(s, opt->car->cdr, VAL);
792
900
  pop();
793
- idx = lv_idx(s, nsym(opt->car->car));
794
- gen_move(s, idx, cursp(), 0);
901
+ idx = lv_idx(s, id);
902
+ if (idx > 0) {
903
+ gen_move(s, idx, cursp(), 0);
904
+ }
905
+ else {
906
+ int lv = search_upvar(s, id, &idx);
907
+ genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
908
+ }
795
909
  i++;
796
910
  opt = opt->cdr;
797
911
  }
@@ -818,12 +932,20 @@ lambda_body(codegen_scope *s, node *tree, int blk)
818
932
  mrb_assert(nint(kwd->car) == NODE_KW_ARG);
819
933
 
820
934
  if (def_arg) {
935
+ int idx;
821
936
  genop_2(s, OP_KEY_P, lv_idx(s, kwd_sym), new_sym(s, kwd_sym));
822
- jmpif_key_p = genjmp2(s, OP_JMPIF, lv_idx(s, kwd_sym), 0, 0);
937
+ jmpif_key_p = genjmp2_0(s, OP_JMPIF, lv_idx(s, kwd_sym), NOVAL);
823
938
  codegen(s, def_arg, VAL);
824
939
  pop();
825
- gen_move(s, lv_idx(s, kwd_sym), cursp(), 0);
826
- jmp_def_set = genjmp(s, OP_JMP, 0);
940
+ idx = lv_idx(s, kwd_sym);
941
+ if (idx > 0) {
942
+ gen_move(s, idx, cursp(), 0);
943
+ }
944
+ else {
945
+ int lv = search_upvar(s, kwd_sym, &idx);
946
+ genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
947
+ }
948
+ jmp_def_set = genjmp_0(s, OP_JMP);
827
949
  dispatch(s, jmpif_key_p);
828
950
  }
829
951
  genop_2(s, OP_KARG, lv_idx(s, kwd_sym), new_sym(s, kwd_sym));
@@ -1004,7 +1126,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
1004
1126
  if (safe) {
1005
1127
  int recv = cursp()-1;
1006
1128
  gen_move(s, cursp(), recv, 1);
1007
- skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1129
+ skip = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1008
1130
  }
1009
1131
  tree = tree->cdr->cdr->car;
1010
1132
  if (tree) {
@@ -1103,23 +1225,12 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
1103
1225
  if (idx > 0) {
1104
1226
  if (idx != sp) {
1105
1227
  gen_move(s, idx, sp, val);
1106
- if (val && on_eval(s)) genop_0(s, OP_NOP);
1107
1228
  }
1108
1229
  break;
1109
1230
  }
1110
1231
  else { /* upvar */
1111
- int lv = 0;
1112
- codegen_scope *up = s->prev;
1113
-
1114
- while (up) {
1115
- idx = lv_idx(up, nsym(tree));
1116
- if (idx > 0) {
1117
- genop_3(s, OP_SETUPVAR, sp, idx, lv);
1118
- break;
1119
- }
1120
- lv++;
1121
- up = up->prev;
1122
- }
1232
+ int lv = search_upvar(s, nsym(tree), &idx);
1233
+ genop_3(s, OP_SETUPVAR, sp, idx, lv);
1123
1234
  }
1124
1235
  break;
1125
1236
  case NODE_NVAR:
@@ -1167,7 +1278,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
1167
1278
  break;
1168
1279
 
1169
1280
  default:
1170
- #ifndef MRB_DISABLE_STDIO
1281
+ #ifndef MRB_NO_STDIO
1171
1282
  fprintf(stderr, "unknown lhs %d\n", type);
1172
1283
  #endif
1173
1284
  break;
@@ -1296,34 +1407,6 @@ raise_error(codegen_scope *s, const char *msg)
1296
1407
  genop_1(s, OP_ERR, idx);
1297
1408
  }
1298
1409
 
1299
- #ifndef MRB_WITHOUT_FLOAT
1300
- static double
1301
- readint_float(codegen_scope *s, const char *p, int base)
1302
- {
1303
- const char *e = p + strlen(p);
1304
- double f = 0;
1305
- int n;
1306
-
1307
- if (*p == '+') p++;
1308
- while (p < e) {
1309
- char c = *p;
1310
- c = tolower((unsigned char)c);
1311
- for (n=0; n<base; n++) {
1312
- if (mrb_digitmap[n] == c) {
1313
- f *= base;
1314
- f += n;
1315
- break;
1316
- }
1317
- }
1318
- if (n == base) {
1319
- codegen_error(s, "malformed readint input");
1320
- }
1321
- p++;
1322
- }
1323
- return f;
1324
- }
1325
- #endif
1326
-
1327
1410
  static mrb_int
1328
1411
  readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_bool *overflow)
1329
1412
  {
@@ -1427,21 +1510,25 @@ codegen(codegen_scope *s, node *tree, int val)
1427
1510
 
1428
1511
  case NODE_RESCUE:
1429
1512
  {
1430
- int noexc, exend, pos1, pos2, tmp;
1513
+ int noexc;
1514
+ uint32_t exend, pos1, pos2, tmp;
1431
1515
  struct loopinfo *lp;
1516
+ int catch_entry, begin, end;
1432
1517
 
1433
1518
  if (tree->car == NULL) goto exit;
1434
1519
  lp = loop_push(s, LOOP_BEGIN);
1435
1520
  lp->pc0 = new_label(s);
1436
- lp->pc1 = genjmp(s, OP_ONERR, 0);
1521
+ catch_entry = catch_handler_new(s);
1522
+ begin = s->pc;
1437
1523
  codegen(s, tree->car, VAL);
1438
1524
  pop();
1439
1525
  lp->type = LOOP_RESCUE;
1440
- noexc = genjmp(s, OP_JMP, 0);
1441
- dispatch(s, lp->pc1);
1526
+ end = s->pc;
1527
+ noexc = genjmp_0(s, OP_JMP);
1528
+ catch_handler_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc);
1442
1529
  tree = tree->cdr;
1443
- exend = 0;
1444
- pos1 = 0;
1530
+ exend = JMPLINK_START;
1531
+ pos1 = JMPLINK_START;
1445
1532
  if (tree->car) {
1446
1533
  node *n2 = tree->car;
1447
1534
  int exc = cursp();
@@ -1452,22 +1539,22 @@ codegen(codegen_scope *s, node *tree, int val)
1452
1539
  node *n3 = n2->car;
1453
1540
  node *n4 = n3->car;
1454
1541
 
1455
- if (pos1) dispatch(s, pos1);
1456
- pos2 = 0;
1542
+ dispatch(s, pos1);
1543
+ pos2 = JMPLINK_START;
1457
1544
  do {
1458
1545
  if (n4 && n4->car && nint(n4->car->car) == NODE_SPLAT) {
1459
1546
  codegen(s, n4->car, VAL);
1460
1547
  gen_move(s, cursp(), exc, 0);
1461
1548
  push_n(2); pop_n(2); /* space for one arg and a block */
1462
1549
  pop();
1463
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1);
1550
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, __case_eqq)), 1);
1464
1551
  }
1465
1552
  else {
1466
1553
  if (n4) {
1467
1554
  codegen(s, n4->car, VAL);
1468
1555
  }
1469
1556
  else {
1470
- genop_2(s, OP_GETCONST, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "StandardError")));
1557
+ genop_2(s, OP_GETCONST, cursp(), new_sym(s, MRB_SYM_2(s->mrb, StandardError)));
1471
1558
  push();
1472
1559
  }
1473
1560
  pop();
@@ -1479,7 +1566,7 @@ codegen(codegen_scope *s, node *tree, int val)
1479
1566
  n4 = n4->cdr;
1480
1567
  }
1481
1568
  } while (n4);
1482
- pos1 = genjmp(s, OP_JMP, 0);
1569
+ pos1 = genjmp_0(s, OP_JMP);
1483
1570
  dispatch_linked(s, pos2);
1484
1571
 
1485
1572
  pop();
@@ -1495,15 +1582,14 @@ codegen(codegen_scope *s, node *tree, int val)
1495
1582
  n2 = n2->cdr;
1496
1583
  push();
1497
1584
  }
1498
- if (pos1) {
1585
+ if (pos1 != JMPLINK_START) {
1499
1586
  dispatch(s, pos1);
1500
- genop_1(s, OP_RAISE, exc);
1587
+ genop_1(s, OP_RAISEIF, exc);
1501
1588
  }
1502
1589
  }
1503
1590
  pop();
1504
1591
  tree = tree->cdr;
1505
1592
  dispatch(s, noexc);
1506
- genop_1(s, OP_POPERR, 1);
1507
1593
  if (tree->car) {
1508
1594
  codegen(s, tree->car, val);
1509
1595
  }
@@ -1519,14 +1605,22 @@ codegen(codegen_scope *s, node *tree, int val)
1519
1605
  if (!tree->cdr || !tree->cdr->cdr ||
1520
1606
  (nint(tree->cdr->cdr->car) == NODE_BEGIN &&
1521
1607
  tree->cdr->cdr->cdr)) {
1608
+ int catch_entry, begin, end, target;
1522
1609
  int idx;
1523
1610
 
1524
- s->ensure_level++;
1525
- idx = scope_body(s, tree->cdr, NOVAL);
1526
- genop_1(s, OP_EPUSH, idx);
1611
+ catch_entry = catch_handler_new(s);
1612
+ begin = s->pc;
1527
1613
  codegen(s, tree->car, val);
1528
- s->ensure_level--;
1529
- genop_1(s, OP_EPOP, 1);
1614
+ end = target = s->pc;
1615
+ push();
1616
+ idx = cursp();
1617
+ genop_1(s, OP_EXCEPT, idx);
1618
+ push();
1619
+ codegen(s, tree->cdr->cdr, NOVAL);
1620
+ pop();
1621
+ genop_1(s, OP_RAISEIF, idx);
1622
+ pop();
1623
+ catch_handler_set(s, catch_entry, MRB_CATCH_ENSURE, begin, end, target);
1530
1624
  }
1531
1625
  else { /* empty ensure ignored */
1532
1626
  codegen(s, tree->car, val);
@@ -1537,7 +1631,7 @@ codegen(codegen_scope *s, node *tree, int val)
1537
1631
  if (val) {
1538
1632
  int idx = lambda_body(s, tree, 1);
1539
1633
 
1540
- genop_2(s, OP_LAMBDA, cursp(), idx);
1634
+ genop_bs(s, OP_LAMBDA, cursp(), idx);
1541
1635
  push();
1542
1636
  }
1543
1637
  break;
@@ -1546,7 +1640,7 @@ codegen(codegen_scope *s, node *tree, int val)
1546
1640
  if (val) {
1547
1641
  int idx = lambda_body(s, tree, 1);
1548
1642
 
1549
- genop_2(s, OP_BLOCK, cursp(), idx);
1643
+ genop_bs(s, OP_BLOCK, cursp(), idx);
1550
1644
  push();
1551
1645
  }
1552
1646
  break;
@@ -1574,7 +1668,7 @@ codegen(codegen_scope *s, node *tree, int val)
1574
1668
  {
1575
1669
  node *n = tree->car->cdr;
1576
1670
  mrb_sym mid = nsym(n->cdr->car);
1577
- mrb_sym mnil = mrb_intern_lit(s->mrb, "nil?");
1671
+ mrb_sym mnil = MRB_SYM_Q_2(s->mrb, nil);
1578
1672
  if (mid == mnil && n->cdr->cdr->car == NULL) {
1579
1673
  nil_p = TRUE;
1580
1674
  codegen(s, n->car, VAL);
@@ -1588,17 +1682,17 @@ codegen(codegen_scope *s, node *tree, int val)
1588
1682
  pop();
1589
1683
  if (val || tree->cdr->car) {
1590
1684
  if (nil_p) {
1591
- pos2 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1592
- pos1 = genjmp(s, OP_JMP, 0);
1685
+ pos2 = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1686
+ pos1 = genjmp_0(s, OP_JMP);
1593
1687
  dispatch(s, pos2);
1594
1688
  }
1595
1689
  else {
1596
- pos1 = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
1690
+ pos1 = genjmp2_0(s, OP_JMPNOT, cursp(), val);
1597
1691
  }
1598
1692
  codegen(s, tree->cdr->car, val);
1599
1693
  if (val) pop();
1600
1694
  if (elsepart || val) {
1601
- pos2 = genjmp(s, OP_JMP, 0);
1695
+ pos2 = genjmp_0(s, OP_JMP);
1602
1696
  dispatch(s, pos1);
1603
1697
  codegen(s, elsepart, val);
1604
1698
  dispatch(s, pos2);
@@ -1610,10 +1704,10 @@ codegen(codegen_scope *s, node *tree, int val)
1610
1704
  else { /* empty then-part */
1611
1705
  if (elsepart) {
1612
1706
  if (nil_p) {
1613
- pos1 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1707
+ pos1 = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1614
1708
  }
1615
1709
  else {
1616
- pos1 = genjmp2(s, OP_JMPIF, cursp(), 0, val);
1710
+ pos1 = genjmp2_0(s, OP_JMPIF, cursp(), val);
1617
1711
  }
1618
1712
  codegen(s, elsepart, val);
1619
1713
  dispatch(s, pos1);
@@ -1632,7 +1726,7 @@ codegen(codegen_scope *s, node *tree, int val)
1632
1726
 
1633
1727
  codegen(s, tree->car, VAL);
1634
1728
  pop();
1635
- pos = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
1729
+ pos = genjmp2_0(s, OP_JMPNOT, cursp(), val);
1636
1730
  codegen(s, tree->cdr, val);
1637
1731
  dispatch(s, pos);
1638
1732
  }
@@ -1644,7 +1738,7 @@ codegen(codegen_scope *s, node *tree, int val)
1644
1738
 
1645
1739
  codegen(s, tree->car, VAL);
1646
1740
  pop();
1647
- pos = genjmp2(s, OP_JMPIF, cursp(), 0, val);
1741
+ pos = genjmp2_0(s, OP_JMPIF, cursp(), val);
1648
1742
  codegen(s, tree->cdr, val);
1649
1743
  dispatch(s, pos);
1650
1744
  }
@@ -1655,7 +1749,7 @@ codegen(codegen_scope *s, node *tree, int val)
1655
1749
  struct loopinfo *lp = loop_push(s, LOOP_NORMAL);
1656
1750
 
1657
1751
  lp->pc0 = new_label(s);
1658
- lp->pc1 = genjmp(s, OP_JMP, 0);
1752
+ lp->pc1 = genjmp_0(s, OP_JMP);
1659
1753
  lp->pc2 = new_label(s);
1660
1754
  codegen(s, tree->cdr, NOVAL);
1661
1755
  dispatch(s, lp->pc1);
@@ -1672,7 +1766,7 @@ codegen(codegen_scope *s, node *tree, int val)
1672
1766
  struct loopinfo *lp = loop_push(s, LOOP_NORMAL);
1673
1767
 
1674
1768
  lp->pc0 = new_label(s);
1675
- lp->pc1 = genjmp(s, OP_JMP, 0);
1769
+ lp->pc1 = genjmp_0(s, OP_JMP);
1676
1770
  lp->pc2 = new_label(s);
1677
1771
  codegen(s, tree->cdr, NOVAL);
1678
1772
  dispatch(s, lp->pc1);
@@ -1692,10 +1786,10 @@ codegen(codegen_scope *s, node *tree, int val)
1692
1786
  case NODE_CASE:
1693
1787
  {
1694
1788
  int head = 0;
1695
- int pos1, pos2, pos3, tmp;
1789
+ uint32_t pos1, pos2, pos3, tmp;
1696
1790
  node *n;
1697
1791
 
1698
- pos3 = 0;
1792
+ pos3 = JMPLINK_START;
1699
1793
  if (tree->car) {
1700
1794
  head = cursp();
1701
1795
  codegen(s, tree->car, VAL);
@@ -1703,17 +1797,17 @@ codegen(codegen_scope *s, node *tree, int val)
1703
1797
  tree = tree->cdr;
1704
1798
  while (tree) {
1705
1799
  n = tree->car->car;
1706
- pos1 = pos2 = 0;
1800
+ pos1 = pos2 = JMPLINK_START;
1707
1801
  while (n) {
1708
1802
  codegen(s, n->car, VAL);
1709
1803
  if (head) {
1710
1804
  gen_move(s, cursp(), head, 0);
1711
1805
  push(); push(); pop(); pop(); pop();
1712
1806
  if (nint(n->car->car) == NODE_SPLAT) {
1713
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1);
1807
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, __case_eqq)), 1);
1714
1808
  }
1715
1809
  else {
1716
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "===")), 1);
1810
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_OPSYM_2(s->mrb, eqq)), 1);
1717
1811
  }
1718
1812
  }
1719
1813
  else {
@@ -1724,20 +1818,20 @@ codegen(codegen_scope *s, node *tree, int val)
1724
1818
  n = n->cdr;
1725
1819
  }
1726
1820
  if (tree->car->car) {
1727
- pos1 = genjmp(s, OP_JMP, 0);
1821
+ pos1 = genjmp_0(s, OP_JMP);
1728
1822
  dispatch_linked(s, pos2);
1729
1823
  }
1730
1824
  codegen(s, tree->car->cdr, val);
1731
1825
  if (val) pop();
1732
1826
  tmp = genjmp(s, OP_JMP, pos3);
1733
1827
  pos3 = tmp;
1734
- if (pos1) dispatch(s, pos1);
1828
+ dispatch(s, pos1);
1735
1829
  tree = tree->cdr;
1736
1830
  }
1737
1831
  if (val) {
1738
- int pos = cursp();
1832
+ uint32_t pos = cursp();
1739
1833
  genop_1(s, OP_LOADNIL, cursp());
1740
- if (pos3) dispatch_linked(s, pos3);
1834
+ if (pos3 != JMPLINK_START) dispatch_linked(s, pos3);
1741
1835
  if (head) pop();
1742
1836
  if (cursp() != pos) {
1743
1837
  gen_move(s, cursp(), pos, 0);
@@ -1745,7 +1839,7 @@ codegen(codegen_scope *s, node *tree, int val)
1745
1839
  push();
1746
1840
  }
1747
1841
  else {
1748
- if (pos3) {
1842
+ if (pos3 != JMPLINK_START) {
1749
1843
  dispatch_linked(s, pos3);
1750
1844
  }
1751
1845
  if (head) {
@@ -1860,7 +1954,7 @@ codegen(codegen_scope *s, node *tree, int val)
1860
1954
  len++;
1861
1955
  }
1862
1956
  tree = tree->cdr;
1863
- if (val && len == 255) {
1957
+ if (val && cursp() > 127) {
1864
1958
  pop_n(len*2);
1865
1959
  if (!update) {
1866
1960
  genop_2(s, OP_HASH, cursp(), len);
@@ -1988,18 +2082,20 @@ codegen(codegen_scope *s, node *tree, int val)
1988
2082
  if ((len == 2 && name[0] == '|' && name[1] == '|') &&
1989
2083
  (nint(tree->car->car) == NODE_CONST ||
1990
2084
  nint(tree->car->car) == NODE_CVAR)) {
1991
- int onerr, noexc, exc;
2085
+ int catch_entry, begin, end;
2086
+ int noexc, exc;
1992
2087
  struct loopinfo *lp;
1993
2088
 
1994
- onerr = genjmp(s, OP_ONERR, 0);
1995
2089
  lp = loop_push(s, LOOP_BEGIN);
1996
- lp->pc1 = onerr;
2090
+ lp->pc0 = new_label(s);
2091
+ catch_entry = catch_handler_new(s);
2092
+ begin = s->pc;
1997
2093
  exc = cursp();
1998
2094
  codegen(s, tree->car, VAL);
2095
+ end = s->pc;
2096
+ noexc = genjmp_0(s, OP_JMP);
1999
2097
  lp->type = LOOP_RESCUE;
2000
- genop_1(s, OP_POPERR, 1);
2001
- noexc = genjmp(s, OP_JMP, 0);
2002
- dispatch(s, onerr);
2098
+ catch_handler_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc);
2003
2099
  genop_1(s, OP_EXCEPT, exc);
2004
2100
  genop_1(s, OP_LOADF, exc);
2005
2101
  dispatch(s, noexc);
@@ -2050,10 +2146,10 @@ codegen(codegen_scope *s, node *tree, int val)
2050
2146
  if (vsp >= 0) {
2051
2147
  gen_move(s, vsp, cursp(), 1);
2052
2148
  }
2053
- pos = genjmp2(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0, val);
2149
+ pos = genjmp2_0(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), val);
2054
2150
  }
2055
2151
  else {
2056
- pos = genjmp2(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0, val);
2152
+ pos = genjmp2_0(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), val);
2057
2153
  }
2058
2154
  codegen(s, tree->cdr->cdr->car, VAL);
2059
2155
  pop();
@@ -2237,7 +2333,7 @@ codegen(codegen_scope *s, node *tree, int val)
2237
2333
  pop_n(n+1);
2238
2334
  genop_2S(s, OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf));
2239
2335
  if (sendv) n = CALL_MAXARGS;
2240
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "call")), n);
2336
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, call)), n);
2241
2337
  if (val) push();
2242
2338
  }
2243
2339
  break;
@@ -2252,11 +2348,8 @@ codegen(codegen_scope *s, node *tree, int val)
2252
2348
  raise_error(s, "unexpected next");
2253
2349
  }
2254
2350
  else if (s->loop->type == LOOP_NORMAL) {
2255
- if (s->ensure_level > s->loop->ensure_level) {
2256
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
2257
- }
2258
2351
  codegen(s, tree, NOVAL);
2259
- genjmp(s, OP_JMP, s->loop->pc0);
2352
+ genjmp(s, OP_JMPUW, s->loop->pc0);
2260
2353
  }
2261
2354
  else {
2262
2355
  if (tree) {
@@ -2276,10 +2369,7 @@ codegen(codegen_scope *s, node *tree, int val)
2276
2369
  raise_error(s, "unexpected redo");
2277
2370
  }
2278
2371
  else {
2279
- if (s->ensure_level > s->loop->ensure_level) {
2280
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
2281
- }
2282
- genjmp(s, OP_JMP, s->loop->pc2);
2372
+ genjmp(s, OP_JMPUW, s->loop->pc2);
2283
2373
  }
2284
2374
  if (val) push();
2285
2375
  break;
@@ -2287,32 +2377,16 @@ codegen(codegen_scope *s, node *tree, int val)
2287
2377
  case NODE_RETRY:
2288
2378
  {
2289
2379
  const char *msg = "unexpected retry";
2380
+ const struct loopinfo *lp = s->loop;
2290
2381
 
2291
- if (!s->loop) {
2382
+ while (lp && lp->type != LOOP_RESCUE) {
2383
+ lp = lp->prev;
2384
+ }
2385
+ if (!lp) {
2292
2386
  raise_error(s, msg);
2293
2387
  }
2294
2388
  else {
2295
- struct loopinfo *lp = s->loop;
2296
- int n = 0;
2297
-
2298
- while (lp && lp->type != LOOP_RESCUE) {
2299
- if (lp->type == LOOP_BEGIN) {
2300
- n++;
2301
- }
2302
- lp = lp->prev;
2303
- }
2304
- if (!lp) {
2305
- raise_error(s, msg);
2306
- }
2307
- else {
2308
- if (n > 0) {
2309
- genop_1(s, OP_POPERR, n);
2310
- }
2311
- if (s->ensure_level > lp->ensure_level) {
2312
- genop_1(s, OP_EPOP, s->ensure_level - lp->ensure_level);
2313
- }
2314
- genjmp(s, OP_JMP, lp->pc0);
2315
- }
2389
+ genjmp(s, OP_JMPUW, lp->pc0);
2316
2390
  }
2317
2391
  if (val) push();
2318
2392
  }
@@ -2324,21 +2398,10 @@ codegen(codegen_scope *s, node *tree, int val)
2324
2398
 
2325
2399
  if (idx > 0) {
2326
2400
  gen_move(s, cursp(), idx, val);
2327
- if (val && on_eval(s)) genop_0(s, OP_NOP);
2328
2401
  }
2329
2402
  else {
2330
- int lv = 0;
2331
- codegen_scope *up = s->prev;
2332
-
2333
- while (up) {
2334
- idx = lv_idx(up, nsym(tree));
2335
- if (idx > 0) {
2336
- genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
2337
- break;
2338
- }
2339
- lv++;
2340
- up = up->prev;
2341
- }
2403
+ int lv = search_upvar(s, nsym(tree), &idx);
2404
+ genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
2342
2405
  }
2343
2406
  push();
2344
2407
  }
@@ -2349,7 +2412,6 @@ codegen(codegen_scope *s, node *tree, int val)
2349
2412
  int idx = nint(tree);
2350
2413
 
2351
2414
  gen_move(s, cursp(), idx, val);
2352
- if (val && on_eval(s)) genop_0(s, OP_NOP);
2353
2415
 
2354
2416
  push();
2355
2417
  }
@@ -2430,37 +2492,41 @@ codegen(codegen_scope *s, node *tree, int val)
2430
2492
  mrb_bool overflow;
2431
2493
 
2432
2494
  i = readint_mrb_int(s, p, base, FALSE, &overflow);
2433
- #ifndef MRB_WITHOUT_FLOAT
2434
2495
  if (overflow) {
2435
- double f = readint_float(s, p, base);
2436
- int off = new_lit(s, mrb_float_value(s->mrb, f));
2437
-
2438
- genop_2(s, OP_LOADL, cursp(), off);
2496
+ codegen_error(s, "integer overflow");
2439
2497
  }
2440
- else
2441
- #endif
2442
- {
2443
- if (i == -1) genop_1(s, OP_LOADI__1, cursp());
2444
- else if (i < 0) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2498
+ else {
2499
+ if (i < 0) {
2500
+ if (i == -1) genop_1(s, OP_LOADI__1, cursp());
2501
+ else if (i >= -0xff) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2502
+ else if (i >= INT16_MIN) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2503
+ else if (i >= INT32_MIN) genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2504
+ else goto lit_int;
2505
+ }
2445
2506
  else if (i < 8) genop_1(s, OP_LOADI_0 + (uint8_t)i, cursp());
2446
- else if (i <= 0xffff) genop_2(s, OP_LOADI, cursp(), (uint16_t)i);
2507
+ else if (i <= 0xff) genop_2(s, OP_LOADI, cursp(), (uint16_t)i);
2508
+ else if (i <= INT16_MAX) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2509
+ else if (i <= INT32_MAX) genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2447
2510
  else {
2448
- int off = new_lit(s, mrb_fixnum_value(i));
2449
- genop_2(s, OP_LOADL, cursp(), off);
2511
+ int off;
2512
+
2513
+ lit_int:
2514
+ off = new_lit(s, mrb_int_value(s->mrb, i));
2515
+ genop_bs(s, OP_LOADL, cursp(), off);
2450
2516
  }
2451
2517
  }
2452
2518
  push();
2453
2519
  }
2454
2520
  break;
2455
2521
 
2456
- #ifndef MRB_WITHOUT_FLOAT
2522
+ #ifndef MRB_NO_FLOAT
2457
2523
  case NODE_FLOAT:
2458
2524
  if (val) {
2459
2525
  char *p = (char*)tree;
2460
2526
  mrb_float f = mrb_float_read(p, NULL);
2461
2527
  int off = new_lit(s, mrb_float_value(s->mrb, f));
2462
2528
 
2463
- genop_2(s, OP_LOADL, cursp(), off);
2529
+ genop_bs(s, OP_LOADL, cursp(), off);
2464
2530
  push();
2465
2531
  }
2466
2532
  break;
@@ -2470,14 +2536,14 @@ codegen(codegen_scope *s, node *tree, int val)
2470
2536
  {
2471
2537
  nt = nint(tree->car);
2472
2538
  switch (nt) {
2473
- #ifndef MRB_WITHOUT_FLOAT
2539
+ #ifndef MRB_NO_FLOAT
2474
2540
  case NODE_FLOAT:
2475
2541
  if (val) {
2476
2542
  char *p = (char*)tree->cdr;
2477
2543
  mrb_float f = mrb_float_read(p, NULL);
2478
2544
  int off = new_lit(s, mrb_float_value(s->mrb, -f));
2479
2545
 
2480
- genop_2(s, OP_LOADL, cursp(), off);
2546
+ genop_bs(s, OP_LOADL, cursp(), off);
2481
2547
  push();
2482
2548
  }
2483
2549
  break;
@@ -2491,33 +2557,32 @@ codegen(codegen_scope *s, node *tree, int val)
2491
2557
  mrb_bool overflow;
2492
2558
 
2493
2559
  i = readint_mrb_int(s, p, base, TRUE, &overflow);
2494
- #ifndef MRB_WITHOUT_FLOAT
2495
2560
  if (overflow) {
2496
- double f = readint_float(s, p, base);
2497
- int off = new_lit(s, mrb_float_value(s->mrb, -f));
2498
-
2499
- genop_2(s, OP_LOADL, cursp(), off);
2561
+ codegen_error(s, "integer overflow");
2500
2562
  }
2501
2563
  else {
2502
- #endif
2503
2564
  if (i == -1) genop_1(s, OP_LOADI__1, cursp());
2504
- else if (i >= -0xffff) {
2565
+ else if (i >= -0xff) {
2505
2566
  genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2506
2567
  }
2568
+ else if (i >= INT16_MIN) {
2569
+ genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2570
+ }
2571
+ else if (i >= INT32_MIN) {
2572
+ genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2573
+ }
2507
2574
  else {
2508
- int off = new_lit(s, mrb_fixnum_value(i));
2509
- genop_2(s, OP_LOADL, cursp(), off);
2575
+ int off = new_lit(s, mrb_int_value(s->mrb, i));
2576
+ genop_bs(s, OP_LOADL, cursp(), off);
2510
2577
  }
2511
- #ifndef MRB_WITHOUT_FLOAT
2512
2578
  }
2513
- #endif
2514
2579
  push();
2515
2580
  }
2516
2581
  break;
2517
2582
 
2518
2583
  default:
2519
2584
  if (val) {
2520
- int sym = new_sym(s, mrb_intern_lit(s->mrb, "-@"));
2585
+ int sym = new_sym(s, MRB_OPSYM_2(s->mrb, minus));
2521
2586
  codegen(s, tree, VAL);
2522
2587
  pop();
2523
2588
  genop_3(s, OP_SEND, cursp(), sym, 0);
@@ -2539,7 +2604,7 @@ codegen(codegen_scope *s, node *tree, int val)
2539
2604
  int off = new_lit(s, mrb_str_new(s->mrb, p, len));
2540
2605
 
2541
2606
  mrb_gc_arena_restore(s->mrb, ai);
2542
- genop_2(s, OP_STRING, cursp(), off);
2607
+ genop_bs(s, OP_STRING, cursp(), off);
2543
2608
  push();
2544
2609
  }
2545
2610
  break;
@@ -2590,7 +2655,7 @@ codegen(codegen_scope *s, node *tree, int val)
2590
2655
  {
2591
2656
  node *n;
2592
2657
  int ai = mrb_gc_arena_save(s->mrb);
2593
- int sym = new_sym(s, mrb_intern_lit(s->mrb, "Kernel"));
2658
+ int sym = new_sym(s, MRB_SYM_2(s->mrb, Kernel));
2594
2659
 
2595
2660
  genop_1(s, OP_LOADSELF, cursp());
2596
2661
  push();
@@ -2609,7 +2674,7 @@ codegen(codegen_scope *s, node *tree, int val)
2609
2674
  }
2610
2675
  push(); /* for block */
2611
2676
  pop_n(3);
2612
- sym = new_sym(s, mrb_intern_lit(s->mrb, "`"));
2677
+ sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */
2613
2678
  genop_3(s, OP_SEND, cursp(), sym, 1);
2614
2679
  if (val) push();
2615
2680
  mrb_gc_arena_restore(s->mrb, ai);
@@ -2626,10 +2691,10 @@ codegen(codegen_scope *s, node *tree, int val)
2626
2691
 
2627
2692
  genop_1(s, OP_LOADSELF, cursp());
2628
2693
  push();
2629
- genop_2(s, OP_STRING, cursp(), off);
2694
+ genop_bs(s, OP_STRING, cursp(), off);
2630
2695
  push(); push();
2631
2696
  pop_n(3);
2632
- sym = new_sym(s, mrb_intern_lit(s->mrb, "`"));
2697
+ sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */
2633
2698
  genop_3(s, OP_SEND, cursp(), sym, 1);
2634
2699
  if (val) push();
2635
2700
  mrb_gc_arena_restore(s->mrb, ai);
@@ -2649,12 +2714,12 @@ codegen(codegen_scope *s, node *tree, int val)
2649
2714
  genop_1(s, OP_OCLASS, cursp());
2650
2715
  genop_2(s, OP_GETMCNST, cursp(), sym);
2651
2716
  push();
2652
- genop_2(s, OP_STRING, cursp(), off);
2717
+ genop_bs(s, OP_STRING, cursp(), off);
2653
2718
  push();
2654
2719
  if (p2 || p3) {
2655
2720
  if (p2) { /* opt */
2656
2721
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2657
- genop_2(s, OP_STRING, cursp(), off);
2722
+ genop_bs(s, OP_STRING, cursp(), off);
2658
2723
  }
2659
2724
  else {
2660
2725
  genop_1(s, OP_LOADNIL, cursp());
@@ -2663,14 +2728,14 @@ codegen(codegen_scope *s, node *tree, int val)
2663
2728
  argc++;
2664
2729
  if (p3) { /* enc */
2665
2730
  off = new_lit(s, mrb_str_new(s->mrb, p3, 1));
2666
- genop_2(s, OP_STRING, cursp(), off);
2731
+ genop_bs(s, OP_STRING, cursp(), off);
2667
2732
  push();
2668
2733
  argc++;
2669
2734
  }
2670
2735
  }
2671
2736
  push(); /* space for a block */
2672
2737
  pop_n(argc+2);
2673
- sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
2738
+ sym = new_sym(s, MRB_SYM_2(s->mrb, compile));
2674
2739
  genop_3(s, OP_SEND, cursp(), sym, argc);
2675
2740
  mrb_gc_arena_restore(s->mrb, ai);
2676
2741
  push();
@@ -2703,7 +2768,7 @@ codegen(codegen_scope *s, node *tree, int val)
2703
2768
  p = (char*)n->car;
2704
2769
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p));
2705
2770
  codegen(s, tree->car, VAL);
2706
- genop_2(s, OP_STRING, cursp(), off);
2771
+ genop_bs(s, OP_STRING, cursp(), off);
2707
2772
  pop();
2708
2773
  genop_1(s, OP_STRCAT, cursp());
2709
2774
  push();
@@ -2711,20 +2776,20 @@ codegen(codegen_scope *s, node *tree, int val)
2711
2776
  if (n->cdr->car) { /* opt */
2712
2777
  char *p2 = (char*)n->cdr->car;
2713
2778
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2714
- genop_2(s, OP_STRING, cursp(), off);
2779
+ genop_bs(s, OP_STRING, cursp(), off);
2715
2780
  push();
2716
2781
  argc++;
2717
2782
  }
2718
2783
  if (n->cdr->cdr) { /* enc */
2719
2784
  char *p2 = (char*)n->cdr->cdr;
2720
2785
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2721
- genop_2(s, OP_STRING, cursp(), off);
2786
+ genop_bs(s, OP_STRING, cursp(), off);
2722
2787
  push();
2723
2788
  argc++;
2724
2789
  }
2725
2790
  push(); /* space for a block */
2726
2791
  pop_n(argc+2);
2727
- sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
2792
+ sym = new_sym(s, MRB_SYM_2(s->mrb, compile));
2728
2793
  genop_3(s, OP_SEND, cursp(), sym, argc);
2729
2794
  mrb_gc_arena_restore(s->mrb, ai);
2730
2795
  push();
@@ -2745,7 +2810,7 @@ codegen(codegen_scope *s, node *tree, int val)
2745
2810
  if (val) {
2746
2811
  int sym = new_sym(s, nsym(tree));
2747
2812
 
2748
- genop_2(s, OP_LOADSYM, cursp(), sym);
2813
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2749
2814
  push();
2750
2815
  }
2751
2816
  break;
@@ -2846,7 +2911,7 @@ codegen(codegen_scope *s, node *tree, int val)
2846
2911
  }
2847
2912
  else {
2848
2913
  idx = scope_body(s, body, val);
2849
- genop_2(s, OP_EXEC, cursp(), idx);
2914
+ genop_bs(s, OP_EXEC, cursp(), idx);
2850
2915
  }
2851
2916
  if (val) {
2852
2917
  push();
@@ -2878,7 +2943,7 @@ codegen(codegen_scope *s, node *tree, int val)
2878
2943
  }
2879
2944
  else {
2880
2945
  idx = scope_body(s, tree->cdr->car, val);
2881
- genop_2(s, OP_EXEC, cursp(), idx);
2946
+ genop_bs(s, OP_EXEC, cursp(), idx);
2882
2947
  }
2883
2948
  if (val) {
2884
2949
  push();
@@ -2899,7 +2964,7 @@ codegen(codegen_scope *s, node *tree, int val)
2899
2964
  }
2900
2965
  else {
2901
2966
  idx = scope_body(s, tree->cdr->car, val);
2902
- genop_2(s, OP_EXEC, cursp(), idx);
2967
+ genop_bs(s, OP_EXEC, cursp(), idx);
2903
2968
  }
2904
2969
  if (val) {
2905
2970
  push();
@@ -2914,12 +2979,12 @@ codegen(codegen_scope *s, node *tree, int val)
2914
2979
 
2915
2980
  genop_1(s, OP_TCLASS, cursp());
2916
2981
  push();
2917
- genop_2(s, OP_METHOD, cursp(), idx);
2982
+ genop_bs(s, OP_METHOD, cursp(), idx);
2918
2983
  push(); pop();
2919
2984
  pop();
2920
2985
  genop_2(s, OP_DEF, cursp(), sym);
2921
2986
  if (val) {
2922
- genop_2(s, OP_LOADSYM, cursp(), sym);
2987
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2923
2988
  push();
2924
2989
  }
2925
2990
  }
@@ -2935,11 +3000,11 @@ codegen(codegen_scope *s, node *tree, int val)
2935
3000
  pop();
2936
3001
  genop_1(s, OP_SCLASS, cursp());
2937
3002
  push();
2938
- genop_2(s, OP_METHOD, cursp(), idx);
3003
+ genop_bs(s, OP_METHOD, cursp(), idx);
2939
3004
  pop();
2940
3005
  genop_2(s, OP_DEF, cursp(), sym);
2941
3006
  if (val) {
2942
- genop_2(s, OP_LOADSYM, cursp(), sym);
3007
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2943
3008
  push();
2944
3009
  }
2945
3010
  }
@@ -2957,99 +3022,100 @@ codegen(codegen_scope *s, node *tree, int val)
2957
3022
  }
2958
3023
 
2959
3024
  static void
2960
- scope_add_irep(codegen_scope *s, mrb_irep *irep)
3025
+ scope_add_irep(codegen_scope *s)
2961
3026
  {
2962
- if (s->irep == NULL) {
2963
- s->irep = irep;
3027
+ mrb_irep *irep;
3028
+ codegen_scope *prev = s->prev;
3029
+
3030
+ if (prev->irep == NULL) {
3031
+ irep = mrb_add_irep(s->mrb);
3032
+ prev->irep = s->irep = irep;
2964
3033
  return;
2965
3034
  }
2966
- if (s->irep->rlen == s->rcapa) {
2967
- s->rcapa *= 2;
2968
- s->irep->reps = (mrb_irep**)codegen_realloc(s, s->irep->reps, sizeof(mrb_irep*)*s->rcapa);
3035
+ else {
3036
+ if (prev->irep->rlen == UINT16_MAX) {
3037
+ codegen_error(s, "too many nested blocks/methods");
3038
+ }
3039
+ s->irep = irep = mrb_add_irep(s->mrb);
3040
+ if (prev->irep->rlen == prev->rcapa) {
3041
+ prev->rcapa *= 2;
3042
+ prev->reps = (mrb_irep**)codegen_realloc(s, prev->reps, sizeof(mrb_irep*)*prev->rcapa);
3043
+ }
3044
+ prev->reps[prev->irep->rlen] = irep;
3045
+ prev->irep->rlen++;
2969
3046
  }
2970
- s->irep->reps[s->irep->rlen] = irep;
2971
- s->irep->rlen++;
2972
3047
  }
2973
3048
 
2974
3049
  static codegen_scope*
2975
- scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
3050
+ scope_new(mrb_state *mrb, codegen_scope *prev, node *nlv)
2976
3051
  {
2977
3052
  static const codegen_scope codegen_scope_zero = { 0 };
2978
3053
  mrb_pool *pool = mrb_pool_open(mrb);
2979
- codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
3054
+ codegen_scope *s = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
2980
3055
 
2981
- if (!p) {
3056
+ if (!s) {
2982
3057
  if (prev)
2983
3058
  codegen_error(prev, "unexpected scope");
2984
3059
  return NULL;
2985
3060
  }
2986
- *p = codegen_scope_zero;
2987
- p->mrb = mrb;
2988
- p->mpool = pool;
2989
- if (!prev) return p;
2990
- p->prev = prev;
2991
- p->ainfo = -1;
2992
- p->mscope = 0;
2993
-
2994
- p->irep = mrb_add_irep(mrb);
2995
- scope_add_irep(prev, p->irep);
2996
-
2997
- p->rcapa = 8;
2998
- p->irep->reps = (mrb_irep**)mrb_malloc(mrb, sizeof(mrb_irep*)*p->rcapa);
2999
-
3000
- p->icapa = 1024;
3001
- p->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa);
3002
- p->irep->iseq = NULL;
3003
-
3004
- p->pcapa = 32;
3005
- p->irep->pool = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value)*p->pcapa);
3006
- p->irep->plen = 0;
3007
-
3008
- p->scapa = 256;
3009
- p->irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*p->scapa);
3010
- p->irep->slen = 0;
3011
-
3012
- p->lv = lv;
3013
- p->sp += node_len(lv)+1; /* add self */
3014
- p->nlocals = p->sp;
3015
- if (lv) {
3016
- node *n = lv;
3061
+ *s = codegen_scope_zero;
3062
+ s->mrb = mrb;
3063
+ s->mpool = pool;
3064
+ if (!prev) return s;
3065
+ s->prev = prev;
3066
+ s->ainfo = -1;
3067
+ s->mscope = 0;
3068
+
3069
+ scope_add_irep(s);
3070
+
3071
+ s->rcapa = 8;
3072
+ s->reps = (mrb_irep**)mrb_malloc(mrb, sizeof(mrb_irep*)*s->rcapa);
3073
+
3074
+ s->icapa = 1024;
3075
+ s->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*s->icapa);
3076
+
3077
+ s->pcapa = 32;
3078
+ s->pool = (mrb_pool_value*)mrb_malloc(mrb, sizeof(mrb_pool_value)*s->pcapa);
3079
+
3080
+ s->scapa = 256;
3081
+ s->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*s->scapa);
3082
+
3083
+ s->lv = nlv;
3084
+ s->sp += node_len(nlv)+1; /* add self */
3085
+ s->nlocals = s->sp;
3086
+ if (nlv) {
3087
+ mrb_sym *lv;
3088
+ node *n = nlv;
3017
3089
  size_t i = 0;
3018
3090
 
3019
- p->irep->lv = (struct mrb_locals*)mrb_malloc(mrb, sizeof(struct mrb_locals) * (p->nlocals - 1));
3020
- for (i=0, n=lv; n; i++,n=n->cdr) {
3021
- p->irep->lv[i].name = lv_name(n);
3022
- if (lv_name(n)) {
3023
- p->irep->lv[i].r = lv_idx(p, lv_name(n));
3024
- }
3025
- else {
3026
- p->irep->lv[i].r = 0;
3027
- }
3091
+ s->irep->lv = lv = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*(s->nlocals-1));
3092
+ for (i=0, n=nlv; n; i++,n=n->cdr) {
3093
+ lv[i] = lv_name(n);
3028
3094
  }
3029
- mrb_assert(i + 1 == p->nlocals);
3095
+ mrb_assert(i + 1 == s->nlocals);
3030
3096
  }
3031
- p->ai = mrb_gc_arena_save(mrb);
3097
+ s->ai = mrb_gc_arena_save(mrb);
3032
3098
 
3033
- p->filename_sym = prev->filename_sym;
3034
- if (p->filename_sym) {
3035
- p->lines = (uint16_t*)mrb_malloc(mrb, sizeof(short)*p->icapa);
3099
+ s->filename_sym = prev->filename_sym;
3100
+ if (s->filename_sym) {
3101
+ s->lines = (uint16_t*)mrb_malloc(mrb, sizeof(short)*s->icapa);
3036
3102
  }
3037
- p->lineno = prev->lineno;
3103
+ s->lineno = prev->lineno;
3038
3104
 
3039
3105
  /* debug setting */
3040
- p->debug_start_pos = 0;
3041
- if (p->filename_sym) {
3042
- mrb_debug_info_alloc(mrb, p->irep);
3106
+ s->debug_start_pos = 0;
3107
+ if (s->filename_sym) {
3108
+ mrb_debug_info_alloc(mrb, s->irep);
3043
3109
  }
3044
3110
  else {
3045
- p->irep->debug_info = NULL;
3111
+ s->irep->debug_info = NULL;
3046
3112
  }
3047
- p->parser = prev->parser;
3048
- p->filename_index = prev->filename_index;
3113
+ s->parser = prev->parser;
3114
+ s->filename_index = prev->filename_index;
3049
3115
 
3050
- p->rlev = prev->rlev+1;
3116
+ s->rlev = prev->rlev+1;
3051
3117
 
3052
- return p;
3118
+ return s;
3053
3119
  }
3054
3120
 
3055
3121
  static void
@@ -3058,17 +3124,26 @@ scope_finish(codegen_scope *s)
3058
3124
  mrb_state *mrb = s->mrb;
3059
3125
  mrb_irep *irep = s->irep;
3060
3126
 
3061
- if (s->nlocals >= 0x3ff) {
3127
+ if (s->nlocals > 0xff) {
3062
3128
  codegen_error(s, "too many local variables");
3063
3129
  }
3064
3130
  irep->flags = 0;
3065
3131
  if (s->iseq) {
3066
- irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc);
3132
+ size_t catchsize = sizeof(struct mrb_irep_catch_handler) * irep->clen;
3133
+ irep->iseq = (const mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc + catchsize);
3067
3134
  irep->ilen = s->pc;
3135
+ if (irep->clen > 0) {
3136
+ memcpy((void *)(irep->iseq + irep->ilen), s->catch_table, catchsize);
3137
+ }
3138
+ }
3139
+ else {
3140
+ irep->clen = 0;
3068
3141
  }
3069
- irep->pool = (mrb_value*)codegen_realloc(s, irep->pool, sizeof(mrb_value)*irep->plen);
3070
- irep->syms = (mrb_sym*)codegen_realloc(s, irep->syms, sizeof(mrb_sym)*irep->slen);
3071
- irep->reps = (mrb_irep**)codegen_realloc(s, irep->reps, sizeof(mrb_irep*)*irep->rlen);
3142
+ mrb_free(s->mrb, s->catch_table);
3143
+ s->catch_table = NULL;
3144
+ irep->pool = (const mrb_pool_value*)codegen_realloc(s, s->pool, sizeof(mrb_pool_value)*irep->plen);
3145
+ irep->syms = (const mrb_sym*)codegen_realloc(s, s->syms, sizeof(mrb_sym)*irep->slen);
3146
+ irep->reps = (const mrb_irep**)codegen_realloc(s, s->reps, sizeof(mrb_irep*)*irep->rlen);
3072
3147
  if (s->filename_sym) {
3073
3148
  mrb_sym fname = mrb_parser_get_filename(s->parser, s->filename_index);
3074
3149
  const char *filename = mrb_sym_name_len(s->mrb, fname, NULL);
@@ -3091,9 +3166,8 @@ loop_push(codegen_scope *s, enum looptype t)
3091
3166
  struct loopinfo *p = (struct loopinfo *)codegen_palloc(s, sizeof(struct loopinfo));
3092
3167
 
3093
3168
  p->type = t;
3094
- p->pc0 = p->pc1 = p->pc2 = p->pc3 = 0;
3169
+ p->pc0 = p->pc1 = p->pc2 = p->pc3 = JMPLINK_START;
3095
3170
  p->prev = s->loop;
3096
- p->ensure_level = s->ensure_level;
3097
3171
  p->acc = cursp();
3098
3172
  s->loop = p;
3099
3173
 
@@ -3109,7 +3183,6 @@ loop_break(codegen_scope *s, node *tree)
3109
3183
  }
3110
3184
  else {
3111
3185
  struct loopinfo *loop;
3112
- int n = 0;
3113
3186
 
3114
3187
  if (tree) {
3115
3188
  gen_retval(s, tree);
@@ -3118,7 +3191,6 @@ loop_break(codegen_scope *s, node *tree)
3118
3191
  loop = s->loop;
3119
3192
  while (loop) {
3120
3193
  if (loop->type == LOOP_BEGIN) {
3121
- n++;
3122
3194
  loop = loop->prev;
3123
3195
  }
3124
3196
  else if (loop->type == LOOP_RESCUE) {
@@ -3132,20 +3204,14 @@ loop_break(codegen_scope *s, node *tree)
3132
3204
  raise_error(s, "unexpected break");
3133
3205
  return;
3134
3206
  }
3135
- if (n > 0) {
3136
- genop_1(s, OP_POPERR, n);
3137
- }
3138
3207
 
3139
3208
  if (loop->type == LOOP_NORMAL) {
3140
3209
  int tmp;
3141
3210
 
3142
- if (s->ensure_level > s->loop->ensure_level) {
3143
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
3144
- }
3145
3211
  if (tree) {
3146
3212
  gen_move(s, loop->acc, cursp(), 0);
3147
3213
  }
3148
- tmp = genjmp(s, OP_JMP, loop->pc3);
3214
+ tmp = genjmp(s, OP_JMPUW, loop->pc3);
3149
3215
  loop->pc3 = tmp;
3150
3216
  }
3151
3217
  else {
@@ -3168,6 +3234,28 @@ loop_pop(codegen_scope *s, int val)
3168
3234
  if (val) push();
3169
3235
  }
3170
3236
 
3237
+ static int
3238
+ catch_handler_new(codegen_scope *s)
3239
+ {
3240
+ size_t newsize = sizeof(struct mrb_irep_catch_handler) * (s->irep->clen + 1);
3241
+ s->catch_table = (struct mrb_irep_catch_handler *)codegen_realloc(s, (void *)s->catch_table, newsize);
3242
+ return s->irep->clen ++;
3243
+ }
3244
+
3245
+ static void
3246
+ catch_handler_set(codegen_scope *s, int ent, enum mrb_catch_type type, uint32_t begin, uint32_t end, uint32_t target)
3247
+ {
3248
+ struct mrb_irep_catch_handler *e;
3249
+
3250
+ mrb_assert(ent >= 0 && ent < s->irep->clen);
3251
+
3252
+ e = &s->catch_table[ent];
3253
+ uint8_to_bin(type, &e->type);
3254
+ mrb_irep_catch_handler_pack(begin, e->begin);
3255
+ mrb_irep_catch_handler_pack(end, e->end);
3256
+ mrb_irep_catch_handler_pack(target, e->target);
3257
+ }
3258
+
3171
3259
  static struct RProc*
3172
3260
  generate_code(mrb_state *mrb, parser_state *p, int val)
3173
3261
  {
@@ -3214,13 +3302,14 @@ mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
3214
3302
  {
3215
3303
  int i;
3216
3304
 
3305
+ if (irep->flags & MRB_IREP_NO_FREE) return;
3217
3306
  if (irep->lv) {
3218
- mrb_free(mrb, irep->lv);
3307
+ mrb_free(mrb, (void*)irep->lv);
3219
3308
  irep->lv = NULL;
3220
3309
  }
3221
-
3310
+ if (!irep->reps) return;
3222
3311
  for (i = 0; i < irep->rlen; ++i) {
3223
- mrb_irep_remove_lv(mrb, irep->reps[i]);
3312
+ mrb_irep_remove_lv(mrb, (mrb_irep*)irep->reps[i]);
3224
3313
  }
3225
3314
  }
3226
3315
 
@@ -3234,6 +3323,7 @@ uint8_t mrb_insn_size[] = {
3234
3323
  #define BB 3
3235
3324
  #define BBB 4
3236
3325
  #define BS 4
3326
+ #define BSS 6
3237
3327
  #define SB 4
3238
3328
  #define OPCODE(_,x) x,
3239
3329
  #include "mruby/ops.h"
@@ -3241,38 +3331,7 @@ uint8_t mrb_insn_size[] = {
3241
3331
  #undef B
3242
3332
  #undef BB
3243
3333
  #undef BS
3334
+ #undef BSS
3244
3335
  #undef SB
3245
3336
  #undef BBB
3246
3337
  };
3247
- /* EXT1 instruction sizes */
3248
- uint8_t mrb_insn_size1[] = {
3249
- #define B 3
3250
- #define BB 4
3251
- #define BBB 5
3252
- #define BS 5
3253
- #define SB 5
3254
- #define OPCODE(_,x) x,
3255
- #include "mruby/ops.h"
3256
- #undef OPCODE
3257
- #undef B
3258
- };
3259
- /* EXT2 instruction sizes */
3260
- uint8_t mrb_insn_size2[] = {
3261
- #define B 2
3262
- #define OPCODE(_,x) x,
3263
- #include "mruby/ops.h"
3264
- #undef OPCODE
3265
- #undef BB
3266
- #undef BBB
3267
- #undef BS
3268
- #undef SB
3269
- };
3270
- /* EXT3 instruction sizes */
3271
- #define BB 5
3272
- #define BBB 6
3273
- #define BS 4
3274
- #define SB 5
3275
- uint8_t mrb_insn_size3[] = {
3276
- #define OPCODE(_,x) x,
3277
- #include "mruby/ops.h"
3278
- };