script_core 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +2 -2
  4. data/ext/enterprise_script_service/Rakefile +1 -1
  5. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +117 -74
  6. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +41 -37
  7. data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
  8. data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
  9. data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
  10. data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
  11. data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
  12. data/ext/enterprise_script_service/mruby/.travis.yml +2 -2
  13. data/ext/enterprise_script_service/mruby/.yamllint +8 -0
  14. data/ext/enterprise_script_service/mruby/AUTHORS +3 -0
  15. data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
  16. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
  17. data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
  18. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  19. data/ext/enterprise_script_service/mruby/Makefile +1 -1
  20. data/ext/enterprise_script_service/mruby/README.md +4 -14
  21. data/ext/enterprise_script_service/mruby/Rakefile +18 -108
  22. data/ext/enterprise_script_service/mruby/TODO.md +17 -0
  23. data/ext/enterprise_script_service/mruby/appveyor.yml +31 -25
  24. data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
  25. data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
  26. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +2 -19
  27. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +2 -2
  28. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +1 -18
  29. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +2 -19
  30. data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
  31. data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
  32. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_android_armeabi_v7a_neon_hard.rb → build_config/android_armeabi_v7a_neon_hard.rb} +0 -15
  33. data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
  34. data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
  35. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +2 -19
  36. data/ext/enterprise_script_service/mruby/{travis_config.rb → build_config/ci/gcc-clang.rb} +10 -10
  37. data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
  38. data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
  39. data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
  40. data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
  41. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_dreamcast_shelf.rb → build_config/dreamcast_shelf.rb} +5 -19
  42. data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
  43. data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
  44. data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
  45. data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
  46. data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
  47. data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
  48. data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
  49. data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
  50. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +138 -49
  51. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
  52. data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
  53. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +49 -22
  54. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
  55. data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
  56. data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
  57. data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
  58. data/ext/enterprise_script_service/mruby/doc/opcode.md +93 -107
  59. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
  60. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
  61. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
  62. data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
  63. data/ext/enterprise_script_service/mruby/include/mrbconf.h +81 -62
  64. data/ext/enterprise_script_service/mruby/include/mruby.h +137 -96
  65. data/ext/enterprise_script_service/mruby/include/mruby/array.h +23 -6
  66. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +73 -48
  67. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
  68. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +79 -48
  69. data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
  70. data/ext/enterprise_script_service/mruby/include/mruby/common.h +4 -1
  71. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +13 -7
  72. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  73. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +17 -35
  74. data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
  75. data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
  76. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
  77. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
  78. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +64 -14
  79. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +6 -14
  80. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +36 -63
  81. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
  82. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +27 -23
  83. data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
  84. data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
  85. data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
  86. data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
  87. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +80 -13
  88. data/ext/enterprise_script_service/mruby/include/mruby/string.h +10 -15
  89. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
  90. data/ext/enterprise_script_service/mruby/include/mruby/value.h +29 -19
  91. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
  92. data/ext/enterprise_script_service/mruby/include/mruby/version.h +26 -7
  93. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -44
  94. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +55 -37
  95. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
  96. data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
  97. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +75 -32
  98. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
  99. data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
  100. data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
  101. data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
  102. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -88
  103. data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
  104. data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
  105. data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -1
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +5 -4
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +28 -19
  109. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
  110. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
  111. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
  112. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
  113. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
  114. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -3
  115. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
  116. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -4
  117. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
  118. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
  119. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +41 -34
  120. data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
  121. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
  122. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +19 -9
  123. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
  124. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -1
  125. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +22 -6
  126. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
  127. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +2 -2
  128. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
  129. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
  130. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +2 -1
  131. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +430 -399
  132. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
  133. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
  134. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +559 -217
  135. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +4774 -4193
  136. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +18 -19
  137. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +1 -1
  138. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +8 -7
  139. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
  140. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
  141. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
  142. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
  143. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +17 -25
  144. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +18 -13
  145. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +30 -2
  146. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
  147. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +2 -2
  148. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
  149. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +2 -2
  150. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
  151. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +2 -2
  152. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +55 -52
  153. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +4 -2
  154. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +99 -87
  155. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +2 -0
  156. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +2 -3
  157. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +1 -1
  158. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +7 -6
  159. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
  160. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
  161. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +43 -58
  162. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +4 -4
  163. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
  164. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +77 -74
  165. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
  166. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
  167. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +5 -4
  168. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -12
  169. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
  170. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
  171. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
  172. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
  173. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +38 -88
  174. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
  175. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +62 -26
  176. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +32 -19
  177. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
  178. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
  179. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
  180. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
  181. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +20 -40
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +11 -17
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +4 -4
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +102 -71
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +4 -2
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +13 -9
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +18 -25
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +6 -5
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +16 -44
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +27 -27
  203. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
  204. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
  205. data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
  206. data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
  207. data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
  208. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
  209. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +0 -20
  210. data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
  211. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
  212. data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
  213. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
  214. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
  215. data/ext/enterprise_script_service/mruby/src/array.c +43 -80
  216. data/ext/enterprise_script_service/mruby/src/backtrace.c +16 -17
  217. data/ext/enterprise_script_service/mruby/src/class.c +774 -182
  218. data/ext/enterprise_script_service/mruby/src/codedump.c +223 -198
  219. data/ext/enterprise_script_service/mruby/src/debug.c +6 -6
  220. data/ext/enterprise_script_service/mruby/src/dump.c +466 -141
  221. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  222. data/ext/enterprise_script_service/mruby/src/error.c +36 -13
  223. data/ext/enterprise_script_service/mruby/src/etc.c +43 -34
  224. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +5 -6
  225. data/ext/enterprise_script_service/mruby/src/gc.c +73 -71
  226. data/ext/enterprise_script_service/mruby/src/hash.c +1050 -707
  227. data/ext/enterprise_script_service/mruby/src/kernel.c +75 -220
  228. data/ext/enterprise_script_service/mruby/src/load.c +196 -166
  229. data/ext/enterprise_script_service/mruby/src/numeric.c +352 -314
  230. data/ext/enterprise_script_service/mruby/src/object.c +97 -90
  231. data/ext/enterprise_script_service/mruby/src/print.c +4 -3
  232. data/ext/enterprise_script_service/mruby/src/proc.c +48 -56
  233. data/ext/enterprise_script_service/mruby/src/range.c +45 -21
  234. data/ext/enterprise_script_service/mruby/src/state.c +25 -32
  235. data/ext/enterprise_script_service/mruby/src/string.c +59 -101
  236. data/ext/enterprise_script_service/mruby/src/symbol.c +121 -56
  237. data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
  238. data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
  239. data/ext/enterprise_script_service/mruby/src/vm.c +617 -602
  240. data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
  241. data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
  242. data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
  243. data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
  244. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +83 -77
  245. data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
  246. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
  247. data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
  248. data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
  249. data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
  250. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +6 -5
  251. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +10 -14
  252. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +17 -21
  253. data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
  254. data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
  255. data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
  256. data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
  257. data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
  258. data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
  259. data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
  260. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +1 -1
  261. data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
  262. data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
  263. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
  264. data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
  265. data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
  266. data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
  267. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
  268. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
  269. data/ext/enterprise_script_service/mruby_config.rb +2 -5
  270. data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
  271. data/lib/script_core/version.rb +1 -1
  272. data/spec/script_core_spec.rb +13 -0
  273. metadata +61 -23
  274. data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +0 -24
  275. data/ext/enterprise_script_service/mruby/TODO +0 -8
  276. data/ext/enterprise_script_service/mruby/appveyor_config.rb +0 -46
  277. data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
  278. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
  279. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
  280. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
  281. data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
  282. data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
  283. data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <stddef.h>
8
8
  #include <stdarg.h>
9
- #ifndef MRB_WITHOUT_FLOAT
9
+ #ifndef MRB_NO_FLOAT
10
10
  #include <math.h>
11
11
  #endif
12
12
  #include <mruby.h>
@@ -23,8 +23,10 @@
23
23
  #include <mruby/opcode.h>
24
24
  #include "value_array.h"
25
25
  #include <mruby/throw.h>
26
+ #include <mruby/dump.h>
27
+ #include <mruby/presym.h>
26
28
 
27
- #ifdef MRB_DISABLE_STDIO
29
+ #ifdef MRB_NO_STDIO
28
30
  #if defined(__cplusplus)
29
31
  extern "C" {
30
32
  #endif
@@ -37,14 +39,6 @@ void abort(void);
37
39
  #define STACK_INIT_SIZE 128
38
40
  #define CALLINFO_INIT_SIZE 32
39
41
 
40
- #ifndef ENSURE_STACK_INIT_SIZE
41
- #define ENSURE_STACK_INIT_SIZE 16
42
- #endif
43
-
44
- #ifndef RESCUE_STACK_INIT_SIZE
45
- #define RESCUE_STACK_INIT_SIZE 16
46
- #endif
47
-
48
42
  /* Define amount of linear stack growth. */
49
43
  #ifndef MRB_STACK_GROWTH
50
44
  #define MRB_STACK_GROWTH 128
@@ -55,11 +49,6 @@ void abort(void);
55
49
  #define MRB_FUNCALL_DEPTH_MAX 512
56
50
  #endif
57
51
 
58
- /* Maximum depth of ecall() recursion. */
59
- #ifndef MRB_ECALL_DEPTH_MAX
60
- #define MRB_ECALL_DEPTH_MAX 512
61
- #endif
62
-
63
52
  /* Maximum stack depth. Should be set lower on memory constrained systems.
64
53
  The value below allows about 60000 recursive calls in the simplest case. */
65
54
  #ifndef MRB_STACK_MAX
@@ -102,26 +91,20 @@ void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value
102
91
  static inline void
103
92
  stack_clear(mrb_value *from, size_t count)
104
93
  {
105
- #ifndef MRB_NAN_BOXING
106
- const mrb_value mrb_value_zero = { { 0 } };
107
-
108
- while (count-- > 0) {
109
- *from++ = mrb_value_zero;
110
- }
111
- #else
94
+ #ifdef MRB_NAN_BOXING
112
95
  while (count-- > 0) {
113
96
  SET_NIL_VALUE(*from);
114
97
  from++;
115
98
  }
99
+ #else
100
+ memset(from, 0, sizeof(mrb_value)*count);
116
101
  #endif
117
102
  }
118
103
 
119
104
  static inline void
120
105
  stack_copy(mrb_value *dst, const mrb_value *src, size_t size)
121
106
  {
122
- while (size-- > 0) {
123
- *dst++ = *src++;
124
- }
107
+ memcpy(dst, src, sizeof(mrb_value)*size);
125
108
  }
126
109
 
127
110
  static void
@@ -132,14 +115,13 @@ stack_init(mrb_state *mrb)
132
115
  /* mrb_assert(mrb->stack == NULL); */
133
116
  c->stbase = (mrb_value *)mrb_calloc(mrb, STACK_INIT_SIZE, sizeof(mrb_value));
134
117
  c->stend = c->stbase + STACK_INIT_SIZE;
135
- c->stack = c->stbase;
136
118
 
137
119
  /* mrb_assert(ci == NULL); */
138
120
  c->cibase = (mrb_callinfo *)mrb_calloc(mrb, CALLINFO_INIT_SIZE, sizeof(mrb_callinfo));
139
121
  c->ciend = c->cibase + CALLINFO_INIT_SIZE;
140
122
  c->ci = c->cibase;
141
- c->ci->target_class = mrb->object_class;
142
- c->ci->stackent = c->stack;
123
+ c->ci->u.target_class = mrb->object_class;
124
+ c->ci->stack = c->stbase;
143
125
  }
144
126
 
145
127
  static inline void
@@ -149,7 +131,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t oldsize
149
131
 
150
132
  if (newbase == oldbase) return;
151
133
  while (ci <= mrb->c->ci) {
152
- struct REnv *e = ci->env;
134
+ struct REnv *e = mrb_vm_ci_env(ci);
153
135
  mrb_value *st;
154
136
 
155
137
  if (e && MRB_ENV_ONSTACK_P(e) &&
@@ -159,7 +141,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t oldsize
159
141
  e->stack = newbase + off;
160
142
  }
161
143
 
162
- if (ci->proc && MRB_PROC_ENV_P(ci->proc) && ci->env != MRB_PROC_ENV(ci->proc)) {
144
+ if (ci->proc && MRB_PROC_ENV_P(ci->proc) && e != MRB_PROC_ENV(ci->proc)) {
163
145
  e = MRB_PROC_ENV(ci->proc);
164
146
 
165
147
  if (e && MRB_ENV_ONSTACK_P(e) &&
@@ -170,7 +152,7 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t oldsize
170
152
  }
171
153
  }
172
154
 
173
- ci->stackent = newbase + (ci->stackent - oldbase);
155
+ ci->stack = newbase + (ci->stack - oldbase);
174
156
  ci++;
175
157
  }
176
158
  }
@@ -184,7 +166,7 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room)
184
166
  mrb_value *newstack;
185
167
  size_t oldsize = mrb->c->stend - mrb->c->stbase;
186
168
  size_t size = oldsize;
187
- size_t off = mrb->c->stack - mrb->c->stbase;
169
+ size_t off = mrb->c->ci->stack ? mrb->c->stend - mrb->c->ci->stack : 0;
188
170
 
189
171
  if (off > size) size = off;
190
172
  #ifdef MRB_STACK_EXTEND_DOUBLING
@@ -202,14 +184,13 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room)
202
184
  size += room;
203
185
  #endif
204
186
 
205
- newstack = (mrb_value *)mrb_realloc(mrb, mrb->c->stbase, sizeof(mrb_value) * size);
187
+ newstack = (mrb_value *)mrb_realloc_simple(mrb, mrb->c->stbase, sizeof(mrb_value) * size);
206
188
  if (newstack == NULL) {
207
189
  mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
208
190
  }
209
191
  stack_clear(&(newstack[oldsize]), size - oldsize);
210
192
  envadjust(mrb, oldbase, newstack, oldsize);
211
193
  mrb->c->stbase = newstack;
212
- mrb->c->stack = mrb->c->stbase + off;
213
194
  mrb->c->stend = mrb->c->stbase + size;
214
195
 
215
196
  /* Raise an exception if the new stack size will be too large,
@@ -222,15 +203,15 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room)
222
203
  MRB_API void
223
204
  mrb_stack_extend(mrb_state *mrb, mrb_int room)
224
205
  {
225
- if (mrb->c->stack + room >= mrb->c->stend) {
206
+ if (!mrb->c->ci->stack || mrb->c->ci->stack + room >= mrb->c->stend) {
226
207
  stack_extend_alloc(mrb, room);
227
208
  }
228
209
  }
229
210
 
230
211
  static inline struct REnv*
231
- uvenv(mrb_state *mrb, int up)
212
+ uvenv(mrb_state *mrb, mrb_int up)
232
213
  {
233
- struct RProc *proc = mrb->c->ci->proc;
214
+ const struct RProc *proc = mrb->c->ci->proc;
234
215
  struct REnv *e;
235
216
 
236
217
  while (up--) {
@@ -245,7 +226,7 @@ uvenv(mrb_state *mrb, int up)
245
226
 
246
227
  while (cb <= ci) {
247
228
  if (ci->proc == proc) {
248
- return ci->env;
229
+ return mrb_vm_ci_env(ci);
249
230
  }
250
231
  ci--;
251
232
  }
@@ -253,8 +234,8 @@ uvenv(mrb_state *mrb, int up)
253
234
  return NULL;
254
235
  }
255
236
 
256
- static inline struct RProc*
257
- top_proc(mrb_state *mrb, struct RProc *proc)
237
+ static inline const struct RProc*
238
+ top_proc(mrb_state *mrb, const struct RProc *proc)
258
239
  {
259
240
  while (proc->upper) {
260
241
  if (MRB_PROC_SCOPE_P(proc) || MRB_PROC_STRICT_P(proc))
@@ -269,14 +250,12 @@ top_proc(mrb_state *mrb, struct RProc *proc)
269
250
  #define CI_ACC_RESUMED -3
270
251
 
271
252
  static inline mrb_callinfo*
272
- cipush(mrb_state *mrb)
253
+ cipush(mrb_state *mrb, mrb_int push_stacks, mrb_int acc,
254
+ struct RClass *target_class, const struct RProc *proc, mrb_sym mid, mrb_int argc)
273
255
  {
274
256
  struct mrb_context *c = mrb->c;
275
- static const mrb_callinfo ci_zero = { 0 };
276
257
  mrb_callinfo *ci = c->ci;
277
258
 
278
- int ridx = ci->ridx;
279
-
280
259
  if (ci + 1 == c->ciend) {
281
260
  ptrdiff_t size = ci - c->cibase;
282
261
 
@@ -285,9 +264,12 @@ cipush(mrb_state *mrb)
285
264
  c->ciend = c->cibase + size * 2;
286
265
  }
287
266
  ci = ++c->ci;
288
- *ci = ci_zero;
289
- ci->epos = mrb->c->eidx;
290
- ci->ridx = ridx;
267
+ ci->mid = mid;
268
+ mrb_vm_ci_proc_set(ci, proc);
269
+ ci->stack = ci[-1].stack + push_stacks;
270
+ ci->argc = (int16_t)argc;
271
+ ci->acc = (int16_t)acc;
272
+ ci->u.target_class = target_class;
291
273
 
292
274
  return ci;
293
275
  }
@@ -302,7 +284,7 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e)
302
284
 
303
285
  if (!MRB_ENV_ONSTACK_P(e)) return;
304
286
  if (e->cxt != mrb->c) return;
305
- if (e == mrb->c->cibase->env) return; /* for mirb */
287
+ if (e == mrb_vm_ci_env(mrb->c->cibase)) return; /* for mirb */
306
288
  p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
307
289
  if (len > 0) {
308
290
  stack_copy(p, e->stack, len);
@@ -313,73 +295,19 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e)
313
295
  }
314
296
  }
315
297
 
316
- static inline void
298
+ static inline mrb_callinfo*
317
299
  cipop(mrb_state *mrb)
318
300
  {
319
301
  struct mrb_context *c = mrb->c;
320
- struct REnv *env = c->ci->env;
302
+ struct REnv *env = mrb_vm_ci_env(c->ci);
321
303
 
322
304
  c->ci--;
323
305
  if (env) mrb_env_unshare(mrb, env);
306
+ return c->ci;
324
307
  }
325
308
 
326
309
  void mrb_exc_set(mrb_state *mrb, mrb_value exc);
327
- static mrb_value mrb_run(mrb_state *mrb, struct RProc* proc, mrb_value self);
328
-
329
- static void
330
- ecall(mrb_state *mrb)
331
- {
332
- struct RProc *p;
333
- struct mrb_context *c = mrb->c;
334
- mrb_callinfo *ci = c->ci;
335
- struct RObject *exc;
336
- struct REnv *env;
337
- ptrdiff_t cioff;
338
- int ai = mrb_gc_arena_save(mrb);
339
- uint16_t i;
340
- int nregs;
341
-
342
- if (c->eidx == 0) return;
343
- i = --c->eidx;
344
-
345
- /* restrict total call depth of ecall() */
346
- if (++mrb->ecall_nest > MRB_ECALL_DEPTH_MAX) {
347
- mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
348
- }
349
- p = c->ensure[i];
350
- if (!p) return;
351
- mrb_assert(!MRB_PROC_CFUNC_P(p));
352
- c->ensure[i] = NULL;
353
- nregs = p->upper->body.irep->nregs;
354
- if (ci->proc && !MRB_PROC_CFUNC_P(ci->proc) &&
355
- ci->proc->body.irep->nregs > nregs) {
356
- nregs = ci->proc->body.irep->nregs;
357
- }
358
- cioff = ci - c->cibase;
359
- ci = cipush(mrb);
360
- ci->stackent = mrb->c->stack;
361
- ci->mid = ci[-1].mid;
362
- ci->acc = CI_ACC_SKIP;
363
- ci->argc = 0;
364
- ci->proc = p;
365
- ci->target_class = MRB_PROC_TARGET_CLASS(p);
366
- env = MRB_PROC_ENV(p);
367
- mrb_assert(env);
368
- c->stack += nregs;
369
- exc = mrb->exc; mrb->exc = 0;
370
- if (exc) {
371
- mrb_gc_protect(mrb, mrb_obj_value(exc));
372
- }
373
- if (mrb->c->fib) {
374
- mrb_gc_protect(mrb, mrb_obj_value(mrb->c->fib));
375
- }
376
- mrb_run(mrb, p, env->stack[0]);
377
- mrb->c = c;
378
- c->ci = c->cibase + cioff;
379
- if (!mrb->exc) mrb->exc = exc;
380
- mrb_gc_arena_restore(mrb, ai);
381
- mrb->ecall_nest--;
382
- }
310
+ static mrb_value mrb_run(mrb_state *mrb, const struct RProc* proc, mrb_value self);
383
311
 
384
312
  #ifndef MRB_FUNCALL_ARGC_MAX
385
313
  #define MRB_FUNCALL_ARGC_MAX 16
@@ -405,11 +333,30 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, mrb_int argc, ...)
405
333
  return mrb_funcall_argv(mrb, self, mid, argc, argv);
406
334
  }
407
335
 
408
- static int
336
+ MRB_API mrb_value
337
+ mrb_funcall_id(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc, ...)
338
+ {
339
+ mrb_value argv[MRB_FUNCALL_ARGC_MAX];
340
+ va_list ap;
341
+ mrb_int i;
342
+
343
+ if (argc > MRB_FUNCALL_ARGC_MAX) {
344
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=" MRB_STRINGIZE(MRB_FUNCALL_ARGC_MAX) ")");
345
+ }
346
+
347
+ va_start(ap, argc);
348
+ for (i = 0; i < argc; i++) {
349
+ argv[i] = va_arg(ap, mrb_value);
350
+ }
351
+ va_end(ap);
352
+ return mrb_funcall_argv(mrb, self, mid, argc, argv);
353
+ }
354
+
355
+ static mrb_int
409
356
  ci_nregs(mrb_callinfo *ci)
410
357
  {
411
- struct RProc *p;
412
- int n = 0;
358
+ const struct RProc *p;
359
+ mrb_int n = 0;
413
360
 
414
361
  if (!ci) return 3;
415
362
  p = ci->proc;
@@ -447,7 +394,6 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
447
394
  }
448
395
  MRB_CATCH(&c_jmp) { /* error */
449
396
  while (nth_ci < (mrb->c->ci - mrb->c->cibase)) {
450
- mrb->c->stack = mrb->c->ci->stackent;
451
397
  cipop(mrb);
452
398
  }
453
399
  mrb->jmp = 0;
@@ -460,10 +406,10 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
460
406
  mrb_method_t m;
461
407
  struct RClass *c;
462
408
  mrb_callinfo *ci;
463
- int n = ci_nregs(mrb->c->ci);
409
+ mrb_int n = ci_nregs(mrb->c->ci);
464
410
  ptrdiff_t voff = -1;
465
411
 
466
- if (!mrb->c->stack) {
412
+ if (!mrb->c->stbase) {
467
413
  stack_init(mrb);
468
414
  }
469
415
  if (argc < 0) {
@@ -472,7 +418,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
472
418
  c = mrb_class(mrb, self);
473
419
  m = mrb_method_search_vm(mrb, &c, mid);
474
420
  if (MRB_METHOD_UNDEF_P(m)) {
475
- mrb_sym missing = mrb_intern_lit(mrb, "method_missing");
421
+ mrb_sym missing = MRB_SYM(method_missing);
476
422
  mrb_value args = mrb_ary_new_from_values(mrb, argc, argv);
477
423
  m = mrb_method_search_vm(mrb, &c, missing);
478
424
  if (MRB_METHOD_UNDEF_P(m)) {
@@ -480,18 +426,13 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
480
426
  }
481
427
  mrb_ary_unshift(mrb, args, mrb_symbol_value(mid));
482
428
  mrb_stack_extend(mrb, n+2);
483
- mrb->c->stack[n+1] = args;
429
+ mrb->c->ci->stack[n+1] = args;
484
430
  argc = -1;
485
431
  }
486
432
  if (mrb->c->ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {
487
433
  mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
488
434
  }
489
- ci = cipush(mrb);
490
- ci->mid = mid;
491
- ci->stackent = mrb->c->stack;
492
- ci->argc = (int)argc;
493
- ci->target_class = c;
494
- mrb->c->stack = mrb->c->stack + n;
435
+ ci = cipush(mrb, n, 0, c, NULL, mid, argc);
495
436
  if (argc < 0) argc = 1;
496
437
  if (mrb->c->stbase <= argv && argv < mrb->c->stend) {
497
438
  voff = argv - mrb->c->stbase;
@@ -499,7 +440,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
499
440
  if (argc >= CALL_MAXARGS) {
500
441
  mrb_value args = mrb_ary_new_from_values(mrb, argc, argv);
501
442
 
502
- mrb->c->stack[1] = args;
443
+ mrb->c->ci->stack[1] = args;
503
444
  ci->argc = -1;
504
445
  argc = 1;
505
446
  }
@@ -507,7 +448,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
507
448
  if (MRB_METHOD_PROC_P(m)) {
508
449
  struct RProc *p = MRB_METHOD_PROC(m);
509
450
 
510
- ci->proc = p;
451
+ mrb_vm_ci_proc_set(ci, p);
511
452
  if (!MRB_PROC_CFUNC_P(p)) {
512
453
  mrb_stack_extend(mrb, p->body.irep->nregs + argc);
513
454
  }
@@ -515,16 +456,15 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
515
456
  if (voff >= 0) {
516
457
  argv = mrb->c->stbase + voff;
517
458
  }
518
- mrb->c->stack[0] = self;
459
+ mrb->c->ci->stack[0] = self;
519
460
  if (ci->argc > 0) {
520
- stack_copy(mrb->c->stack+1, argv, argc);
461
+ stack_copy(mrb->c->ci->stack+1, argv, argc);
521
462
  }
522
- mrb->c->stack[argc+1] = blk;
463
+ mrb->c->ci->stack[argc+1] = blk;
523
464
 
524
465
  if (MRB_METHOD_CFUNC_P(m)) {
525
466
  ci->acc = CI_ACC_DIRECT;
526
467
  val = MRB_METHOD_CFUNC(m)(mrb, self);
527
- mrb->c->stack = mrb->c->ci->stackent;
528
468
  cipop(mrb);
529
469
  }
530
470
  else {
@@ -547,10 +487,10 @@ mrb_value
547
487
  mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p)
548
488
  {
549
489
  mrb_callinfo *ci = mrb->c->ci;
550
- int keep, nregs;
490
+ mrb_int keep, nregs;
551
491
 
552
- mrb->c->stack[0] = self;
553
- ci->proc = p;
492
+ mrb->c->ci->stack[0] = self;
493
+ mrb_vm_ci_proc_set(ci, p);
554
494
  if (MRB_PROC_CFUNC_P(p)) {
555
495
  return MRB_PROC_CFUNC(p)(mrb, self);
556
496
  }
@@ -562,14 +502,10 @@ mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p)
562
502
  }
563
503
  else {
564
504
  mrb_stack_extend(mrb, nregs);
565
- stack_clear(mrb->c->stack+keep, nregs-keep);
505
+ stack_clear(mrb->c->ci->stack+keep, nregs-keep);
566
506
  }
567
507
 
568
- ci = cipush(mrb);
569
- ci->target_class = 0;
570
- ci->pc = p->body.irep->iseq;
571
- ci->stackent = mrb->c->stack;
572
- ci->acc = 0;
508
+ cipush(mrb, 0, 0, NULL, NULL, 0, 0);
573
509
 
574
510
  return self;
575
511
  }
@@ -597,7 +533,8 @@ mrb_value
597
533
  mrb_f_send(mrb_state *mrb, mrb_value self)
598
534
  {
599
535
  mrb_sym name;
600
- mrb_value block, *argv, *regs;
536
+ mrb_value block, *regs;
537
+ const mrb_value *argv;
601
538
  mrb_int argc, i, len;
602
539
  mrb_method_t m;
603
540
  struct RClass *c;
@@ -617,8 +554,8 @@ mrb_f_send(mrb_state *mrb, mrb_value self)
617
554
  }
618
555
 
619
556
  ci->mid = name;
620
- ci->target_class = c;
621
- regs = mrb->c->stack+1;
557
+ ci->u.target_class = c;
558
+ regs = mrb->c->ci->stack+1;
622
559
  /* remove first symbol from arguments */
623
560
  if (ci->argc >= 0) {
624
561
  for (i=0,len=ci->argc; i<len; i++) {
@@ -632,7 +569,7 @@ mrb_f_send(mrb_state *mrb, mrb_value self)
632
569
 
633
570
  if (MRB_METHOD_CFUNC_P(m)) {
634
571
  if (MRB_METHOD_PROC_P(m)) {
635
- ci->proc = MRB_METHOD_PROC(m);
572
+ mrb_vm_ci_proc_set(ci, MRB_METHOD_PROC(m));
636
573
  }
637
574
  return MRB_METHOD_CFUNC(m)(mrb, self);
638
575
  }
@@ -653,29 +590,25 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c)
653
590
  if (ci->acc == CI_ACC_DIRECT) {
654
591
  return mrb_yield_with_class(mrb, blk, 1, &self, self, c);
655
592
  }
656
- ci->target_class = c;
593
+ ci->u.target_class = c;
657
594
  p = mrb_proc_ptr(blk);
658
- ci->proc = p;
595
+ mrb_vm_ci_proc_set(ci, p);
659
596
  ci->argc = 1;
660
597
  ci->mid = ci[-1].mid;
661
598
  if (MRB_PROC_CFUNC_P(p)) {
662
599
  mrb_stack_extend(mrb, 3);
663
- mrb->c->stack[0] = self;
664
- mrb->c->stack[1] = self;
665
- mrb->c->stack[2] = mrb_nil_value();
600
+ mrb->c->ci->stack[0] = self;
601
+ mrb->c->ci->stack[1] = self;
602
+ mrb->c->ci->stack[2] = mrb_nil_value();
666
603
  return MRB_PROC_CFUNC(p)(mrb, self);
667
604
  }
668
605
  nregs = p->body.irep->nregs;
669
606
  if (nregs < 3) nregs = 3;
670
607
  mrb_stack_extend(mrb, nregs);
671
- mrb->c->stack[0] = self;
672
- mrb->c->stack[1] = self;
673
- stack_clear(mrb->c->stack+2, nregs-2);
674
- ci = cipush(mrb);
675
- ci->target_class = 0;
676
- ci->pc = p->body.irep->iseq;
677
- ci->stackent = mrb->c->stack;
678
- ci->acc = 0;
608
+ mrb->c->ci->stack[0] = self;
609
+ mrb->c->ci->stack[1] = self;
610
+ stack_clear(mrb->c->ci->stack+2, nregs-2);
611
+ ci = cipush(mrb, 0, 0, NULL, NULL, 0, 0);
679
612
 
680
613
  return self;
681
614
  }
@@ -740,7 +673,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
740
673
  mrb_sym mid = mrb->c->ci->mid;
741
674
  mrb_callinfo *ci;
742
675
  mrb_value val;
743
- int n;
676
+ mrb_int n;
744
677
 
745
678
  if (mrb_nil_p(b)) {
746
679
  mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
@@ -751,13 +684,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
751
684
  mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
752
685
  }
753
686
  p = mrb_proc_ptr(b);
754
- ci = cipush(mrb);
755
- ci->mid = mid;
756
- ci->proc = p;
757
- ci->target_class = c;
758
- ci->acc = CI_ACC_SKIP;
759
- ci->stackent = mrb->c->stack;
760
- mrb->c->stack += n;
687
+ ci = cipush(mrb, n, CI_ACC_SKIP, c, p, mid, 0 /* dummy */);
761
688
  if (argc >= CALL_MAXARGS) {
762
689
  ci->argc = -1;
763
690
  n = 3;
@@ -767,19 +694,18 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
767
694
  n = argc + 2;
768
695
  }
769
696
  mrb_stack_extend(mrb, n);
770
- mrb->c->stack[0] = self;
697
+ mrb->c->ci->stack[0] = self;
771
698
  if (ci->argc < 0) {
772
- mrb->c->stack[1] = mrb_ary_new_from_values(mrb, argc, argv);
699
+ mrb->c->ci->stack[1] = mrb_ary_new_from_values(mrb, argc, argv);
773
700
  argc = 1;
774
701
  }
775
702
  else if (argc > 0) {
776
- stack_copy(mrb->c->stack+1, argv, argc);
703
+ stack_copy(mrb->c->ci->stack+1, argv, argc);
777
704
  }
778
- mrb->c->stack[argc+1] = mrb_nil_value();
705
+ mrb->c->ci->stack[argc+1] = mrb_nil_value();
779
706
 
780
707
  if (MRB_PROC_CFUNC_P(p)) {
781
708
  val = MRB_PROC_CFUNC(p)(mrb, self);
782
- mrb->c->stack = mrb->c->ci->stackent;
783
709
  cipop(mrb);
784
710
  }
785
711
  else {
@@ -821,24 +747,63 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const
821
747
  ci = mrb->c->ci;
822
748
 
823
749
  mrb_stack_extend(mrb, 3);
824
- mrb->c->stack[1] = mrb_ary_new_from_values(mrb, argc, argv);
825
- mrb->c->stack[2] = mrb_nil_value();
750
+ mrb->c->ci->stack[1] = mrb_ary_new_from_values(mrb, argc, argv);
751
+ mrb->c->ci->stack[2] = mrb_nil_value();
826
752
  ci->argc = -1;
827
753
  return mrb_exec_irep(mrb, self, p);
828
754
  }
829
755
 
830
756
  static struct RBreak*
831
- break_new(mrb_state *mrb, struct RProc *p, mrb_value val)
757
+ break_new(mrb_state *mrb, uint32_t tag, const struct RProc *p, mrb_value val)
832
758
  {
833
759
  struct RBreak *brk;
834
760
 
835
761
  brk = (struct RBreak*)mrb_obj_alloc(mrb, MRB_TT_BREAK, NULL);
836
762
  mrb_break_proc_set(brk, p);
837
763
  mrb_break_value_set(brk, val);
764
+ mrb_break_tag_set(brk, tag);
838
765
 
839
766
  return brk;
840
767
  }
841
768
 
769
+ #define MRB_CATCH_FILTER_RESCUE (UINT32_C(1) << MRB_CATCH_RESCUE)
770
+ #define MRB_CATCH_FILTER_ENSURE (UINT32_C(1) << MRB_CATCH_ENSURE)
771
+ #define MRB_CATCH_FILTER_ALL (MRB_CATCH_FILTER_RESCUE | MRB_CATCH_FILTER_ENSURE)
772
+
773
+ static const struct mrb_irep_catch_handler *
774
+ catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_t filter)
775
+ {
776
+ const mrb_irep *irep;
777
+ ptrdiff_t xpc;
778
+ size_t cnt;
779
+ const struct mrb_irep_catch_handler *e;
780
+
781
+ /* The comparison operators use `>` and `<=` because pc already points to the next instruction */
782
+ #define catch_cover_p(pc, beg, end) ((pc) > (ptrdiff_t)(beg) && (pc) <= (ptrdiff_t)(end))
783
+
784
+ if (ci->proc == NULL || MRB_PROC_CFUNC_P(ci->proc)) return NULL;
785
+ irep = ci->proc->body.irep;
786
+ if (irep->clen < 1) return NULL;
787
+ xpc = pc - irep->iseq;
788
+ /* If it retry at the top level, pc will be 0, so check with -1 as the start position */
789
+ mrb_assert(catch_cover_p(xpc, -1, irep->ilen));
790
+ if (!catch_cover_p(xpc, -1, irep->ilen)) return NULL;
791
+
792
+ /* Currently uses a simple linear search to avoid processing complexity. */
793
+ cnt = irep->clen;
794
+ e = mrb_irep_catch_handler_table(irep) + cnt - 1;
795
+ for (; cnt > 0; cnt --, e --) {
796
+ if (((UINT32_C(1) << e->type) & filter) &&
797
+ catch_cover_p(xpc, mrb_irep_catch_handler_unpack(e->begin), mrb_irep_catch_handler_unpack(e->end))) {
798
+ return e;
799
+ }
800
+ }
801
+
802
+ #undef catch_cover_p
803
+
804
+ return NULL;
805
+ }
806
+
842
807
  typedef enum {
843
808
  LOCALJUMP_ERROR_RETURN = 0,
844
809
  LOCALJUMP_ERROR_BREAK = 1,
@@ -869,7 +834,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
869
834
  mrb_int argc = mrb->c->ci->argc;
870
835
 
871
836
  if (argc < 0) {
872
- mrb_value args = mrb->c->stack[1];
837
+ mrb_value args = mrb->c->ci->stack[1];
873
838
  if (mrb_array_p(args)) {
874
839
  argc = RARRAY_LEN(args);
875
840
  }
@@ -885,9 +850,71 @@ argnum_error(mrb_state *mrb, mrb_int num)
885
850
  mrb_exc_set(mrb, exc);
886
851
  }
887
852
 
888
- #define ERR_PC_SET(mrb) mrb->c->ci->err = pc0;
889
- #define ERR_PC_CLR(mrb) mrb->c->ci->err = 0;
890
- #ifdef MRB_ENABLE_DEBUG_HOOK
853
+ static mrb_bool
854
+ break_tag_p(struct RBreak *brk, uint32_t tag)
855
+ {
856
+ return (brk != NULL && brk->tt == MRB_TT_BREAK) ? TRUE : FALSE;
857
+ }
858
+
859
+ static void
860
+ prepare_tagged_break(mrb_state *mrb, uint32_t tag, const struct RProc *proc, mrb_value val)
861
+ {
862
+ if (break_tag_p((struct RBreak*)mrb->exc, tag)) {
863
+ mrb_break_tag_set((struct RBreak*)mrb->exc, tag);
864
+ }
865
+ else {
866
+ mrb->exc = (struct RObject*)break_new(mrb, tag, proc, val);
867
+ }
868
+ }
869
+
870
+ #define THROW_TAGGED_BREAK(mrb, tag, proc, val) \
871
+ do { \
872
+ prepare_tagged_break(mrb, tag, proc, val); \
873
+ goto L_CATCH_TAGGED_BREAK; \
874
+ } while (0)
875
+
876
+ #define UNWIND_ENSURE(mrb, ci, pc, tag, proc, val) \
877
+ do { \
878
+ ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ENSURE); \
879
+ if (ch) { \
880
+ THROW_TAGGED_BREAK(mrb, tag, proc, val); \
881
+ } \
882
+ } while (0)
883
+
884
+ /*
885
+ * CHECKPOINT_RESTORE(tag) {
886
+ * This part is executed when jumping by the same "tag" of RBreak (it is not executed the first time).
887
+ * Write the code required (initialization of variables, etc.) for the subsequent processing.
888
+ * }
889
+ * CHECKPOINT_MAIN(tag) {
890
+ * This part is always executed.
891
+ * }
892
+ * CHECKPOINT_END(tag);
893
+ *
894
+ * ...
895
+ *
896
+ * // Jump to CHECKPOINT_RESTORE with the same "tag".
897
+ * goto CHECKPOINT_LABEL_MAKE(tag);
898
+ */
899
+
900
+ #define CHECKPOINT_LABEL_MAKE(tag) L_CHECKPOINT_ ## tag
901
+
902
+ #define CHECKPOINT_RESTORE(tag) \
903
+ do { \
904
+ if (FALSE) { \
905
+ CHECKPOINT_LABEL_MAKE(tag): \
906
+ do {
907
+
908
+ #define CHECKPOINT_MAIN(tag) \
909
+ } while (0); \
910
+ } \
911
+ do {
912
+
913
+ #define CHECKPOINT_END(tag) \
914
+ } while (0); \
915
+ } while (0)
916
+
917
+ #ifdef MRB_USE_DEBUG_HOOK
891
918
  #define CODE_FETCH_HOOK(mrb, irep, pc, regs) if ((mrb)->code_fetch_hook) (mrb)->code_fetch_hook((mrb), (irep), (pc), (regs));
892
919
  #else
893
920
  #define CODE_FETCH_HOOK(mrb, irep, pc, regs)
@@ -899,24 +926,24 @@ argnum_error(mrb_state *mrb, mrb_int num)
899
926
  #define BYTECODE_DECODER(x) (x)
900
927
  #endif
901
928
 
902
- #ifndef MRB_DISABLE_DIRECT_THREADING
929
+ #ifndef MRB_NO_DIRECT_THREADING
903
930
  #if defined __GNUC__ || defined __clang__ || defined __INTEL_COMPILER
904
931
  #define DIRECT_THREADED
905
932
  #endif
906
- #endif /* ifndef MRB_DISABLE_DIRECT_THREADING */
933
+ #endif /* ifndef MRB_NO_DIRECT_THREADING */
907
934
 
908
935
  #ifndef DIRECT_THREADED
909
936
 
910
937
  #define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) {
911
- #define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();; L_ ## insn ## _BODY:
912
- #define NEXT break
938
+ #define CASE(insn,ops) case insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc;
939
+ #define NEXT goto L_END_DISPATCH
913
940
  #define JUMP NEXT
914
- #define END_DISPATCH }}
941
+ #define END_DISPATCH L_END_DISPATCH:;}}
915
942
 
916
943
  #else
917
944
 
918
945
  #define INIT_DISPATCH JUMP; return mrb_nil_value();
919
- #define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); L_ ## insn ## _BODY:
946
+ #define CASE(insn,ops) L_ ## insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc;
920
947
  #define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn]
921
948
  #define JUMP NEXT
922
949
 
@@ -925,22 +952,22 @@ argnum_error(mrb_state *mrb, mrb_int num)
925
952
  #endif
926
953
 
927
954
  MRB_API mrb_value
928
- mrb_vm_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep)
955
+ mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep)
929
956
  {
930
- mrb_irep *irep = proc->body.irep;
957
+ const mrb_irep *irep = proc->body.irep;
931
958
  mrb_value result;
932
959
  struct mrb_context *c = mrb->c;
933
960
  ptrdiff_t cioff = c->ci - c->cibase;
934
- unsigned int nregs = irep->nregs;
961
+ mrb_int nregs = irep->nregs;
935
962
 
936
- if (!c->stack) {
963
+ if (!c->stbase) {
937
964
  stack_init(mrb);
938
965
  }
939
966
  if (stack_keep > nregs)
940
967
  nregs = stack_keep;
941
968
  mrb_stack_extend(mrb, nregs);
942
- stack_clear(c->stack + stack_keep, nregs - stack_keep);
943
- c->stack[0] = self;
969
+ stack_clear(c->ci->stack + stack_keep, nregs - stack_keep);
970
+ c->ci->stack[0] = self;
944
971
  result = mrb_vm_exec(mrb, proc, irep->iseq);
945
972
  if (mrb->c != c) {
946
973
  if (mrb->c->fib) {
@@ -957,8 +984,8 @@ mrb_vm_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stac
957
984
  static mrb_bool
958
985
  check_target_class(mrb_state *mrb)
959
986
  {
960
- if (!mrb->c->ci->target_class) {
961
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_TYPE_ERROR, "no target class or module");
987
+ if (!mrb_vm_ci_target_class(mrb->c->ci)) {
988
+ mrb_value exc = mrb_exc_new_lit(mrb, E_TYPE_ERROR, "no target class or module");
962
989
  mrb_exc_set(mrb, exc);
963
990
  return FALSE;
964
991
  }
@@ -968,21 +995,21 @@ check_target_class(mrb_state *mrb)
968
995
  void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
969
996
 
970
997
  MRB_API mrb_value
971
- mrb_vm_exec(mrb_state *mrb, struct RProc *proc, const mrb_code *pc)
998
+ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
972
999
  {
973
1000
  /* mrb_assert(MRB_PROC_CFUNC_P(proc)) */
974
- const mrb_code *pc0 = pc;
975
- mrb_irep *irep = proc->body.irep;
976
- mrb_value *pool = irep->pool;
977
- mrb_sym *syms = irep->syms;
1001
+ const mrb_irep *irep = proc->body.irep;
1002
+ const mrb_pool_value *pool = irep->pool;
1003
+ const mrb_sym *syms = irep->syms;
978
1004
  mrb_code insn;
979
1005
  int ai = mrb_gc_arena_save(mrb);
980
1006
  struct mrb_jmpbuf *prev_jmp = mrb->jmp;
981
1007
  struct mrb_jmpbuf c_jmp;
982
1008
  uint32_t a;
983
1009
  uint16_t b;
984
- uint8_t c;
1010
+ uint16_t c;
985
1011
  mrb_sym mid;
1012
+ const struct mrb_irep_catch_handler *ch;
986
1013
 
987
1014
  #ifdef DIRECT_THREADED
988
1015
  static void *optable[] = {
@@ -1005,9 +1032,9 @@ RETRY_TRY_BLOCK:
1005
1032
  goto L_RAISE;
1006
1033
  }
1007
1034
  mrb->jmp = &c_jmp;
1008
- mrb->c->ci->proc = proc;
1035
+ mrb_vm_ci_proc_set(mrb->c->ci, proc);
1009
1036
 
1010
- #define regs (mrb->c->stack)
1037
+ #define regs (mrb->c->ci->stack)
1011
1038
  INIT_DISPATCH {
1012
1039
  CASE(OP_NOP, Z) {
1013
1040
  /* do nothing */
@@ -1019,28 +1046,48 @@ RETRY_TRY_BLOCK:
1019
1046
  NEXT;
1020
1047
  }
1021
1048
 
1049
+ CASE(OP_LOADL16, BS) {
1050
+ goto op_loadl;
1051
+ }
1022
1052
  CASE(OP_LOADL, BB) {
1023
- #ifdef MRB_WORD_BOXING
1024
- mrb_value val = pool[b];
1025
- #ifndef MRB_WITHOUT_FLOAT
1026
- if (mrb_float_p(val)) {
1027
- val = mrb_float_value(mrb, mrb_float(val));
1028
- }
1029
- #endif
1030
- regs[a] = val;
1053
+ op_loadl:
1054
+ switch (pool[b].tt) { /* number */
1055
+ case IREP_TT_INT32:
1056
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i32);
1057
+ break;
1058
+ case IREP_TT_INT64:
1059
+ #if defined(MRB_INT64)
1060
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i64);
1061
+ break;
1031
1062
  #else
1032
- regs[a] = pool[b];
1063
+ #if defined(MRB_64BIT)
1064
+ if (INT32_MIN <= pool[b].u.i64 && pool[b].u.i64 <= INT32_MAX) {
1065
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i64);
1066
+ break;
1067
+ }
1068
+ #endif
1069
+ goto L_INT_OVERFLOW;
1070
+ #endif
1071
+ #ifndef MRB_NO_FLOAT
1072
+ case IREP_TT_FLOAT:
1073
+ regs[a] = mrb_float_value(mrb, pool[b].u.f);
1074
+ break;
1033
1075
  #endif
1076
+ default:
1077
+ /* should not happen (tt:string) */
1078
+ regs[a] = mrb_nil_value();
1079
+ break;
1080
+ }
1034
1081
  NEXT;
1035
1082
  }
1036
1083
 
1037
1084
  CASE(OP_LOADI, BB) {
1038
- SET_INT_VALUE(regs[a], b);
1085
+ SET_FIXNUM_VALUE(regs[a], b);
1039
1086
  NEXT;
1040
1087
  }
1041
1088
 
1042
1089
  CASE(OP_LOADINEG, BB) {
1043
- SET_INT_VALUE(regs[a], -b);
1090
+ SET_FIXNUM_VALUE(regs[a], -b);
1044
1091
  NEXT;
1045
1092
  }
1046
1093
 
@@ -1054,12 +1101,17 @@ RETRY_TRY_BLOCK:
1054
1101
  CASE(OP_LOADI_6,B) goto L_LOADI;
1055
1102
  CASE(OP_LOADI_7, B) {
1056
1103
  L_LOADI:
1057
- SET_INT_VALUE(regs[a], (mrb_int)insn - (mrb_int)OP_LOADI_0);
1104
+ SET_FIXNUM_VALUE(regs[a], (mrb_int)insn - (mrb_int)OP_LOADI_0);
1058
1105
  NEXT;
1059
1106
  }
1060
1107
 
1061
1108
  CASE(OP_LOADI16, BS) {
1062
- SET_INT_VALUE(regs[a], (mrb_int)(int16_t)b);
1109
+ SET_FIXNUM_VALUE(regs[a], (mrb_int)(int16_t)b);
1110
+ NEXT;
1111
+ }
1112
+
1113
+ CASE(OP_LOADI32, BSS) {
1114
+ SET_INT_VALUE(mrb, regs[a], (int32_t)(((uint32_t)b<<16)+c));
1063
1115
  NEXT;
1064
1116
  }
1065
1117
 
@@ -1068,6 +1120,11 @@ RETRY_TRY_BLOCK:
1068
1120
  NEXT;
1069
1121
  }
1070
1122
 
1123
+ CASE(OP_LOADSYM16, BS) {
1124
+ SET_SYM_VALUE(regs[a], syms[b]);
1125
+ NEXT;
1126
+ }
1127
+
1071
1128
  CASE(OP_LOADNIL, B) {
1072
1129
  SET_NIL_VALUE(regs[a]);
1073
1130
  NEXT;
@@ -1122,9 +1179,7 @@ RETRY_TRY_BLOCK:
1122
1179
 
1123
1180
  CASE(OP_GETCV, BB) {
1124
1181
  mrb_value val;
1125
- ERR_PC_SET(mrb);
1126
1182
  val = mrb_vm_cv_get(mrb, syms[b]);
1127
- ERR_PC_CLR(mrb);
1128
1183
  regs[a] = val;
1129
1184
  NEXT;
1130
1185
  }
@@ -1138,9 +1193,7 @@ RETRY_TRY_BLOCK:
1138
1193
  mrb_value val;
1139
1194
  mrb_sym sym = syms[b];
1140
1195
 
1141
- ERR_PC_SET(mrb);
1142
1196
  val = mrb_vm_const_get(mrb, sym);
1143
- ERR_PC_CLR(mrb);
1144
1197
  regs[a] = val;
1145
1198
  NEXT;
1146
1199
  }
@@ -1153,9 +1206,7 @@ RETRY_TRY_BLOCK:
1153
1206
  CASE(OP_GETMCNST, BB) {
1154
1207
  mrb_value val;
1155
1208
 
1156
- ERR_PC_SET(mrb);
1157
1209
  val = mrb_const_get(mrb, regs[a], syms[b]);
1158
- ERR_PC_CLR(mrb);
1159
1210
  regs[a] = val;
1160
1211
  NEXT;
1161
1212
  }
@@ -1193,57 +1244,75 @@ RETRY_TRY_BLOCK:
1193
1244
  }
1194
1245
 
1195
1246
  CASE(OP_JMP, S) {
1196
- pc = irep->iseq+a;
1247
+ pc += (int16_t)a;
1197
1248
  JUMP;
1198
1249
  }
1199
1250
  CASE(OP_JMPIF, BS) {
1200
1251
  if (mrb_test(regs[a])) {
1201
- pc = irep->iseq+b;
1252
+ pc += (int16_t)b;
1202
1253
  JUMP;
1203
1254
  }
1204
1255
  NEXT;
1205
1256
  }
1206
1257
  CASE(OP_JMPNOT, BS) {
1207
1258
  if (!mrb_test(regs[a])) {
1208
- pc = irep->iseq+b;
1259
+ pc += (int16_t)b;
1209
1260
  JUMP;
1210
1261
  }
1211
1262
  NEXT;
1212
1263
  }
1213
1264
  CASE(OP_JMPNIL, BS) {
1214
1265
  if (mrb_nil_p(regs[a])) {
1215
- pc = irep->iseq+b;
1266
+ pc += (int16_t)b;
1216
1267
  JUMP;
1217
1268
  }
1218
1269
  NEXT;
1219
1270
  }
1220
1271
 
1221
- CASE(OP_ONERR, S) {
1222
- /* check rescue stack */
1223
- if (mrb->c->ci->ridx == UINT16_MAX-1) {
1224
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "too many nested rescues");
1225
- mrb_exc_set(mrb, exc);
1226
- goto L_RAISE;
1272
+ CASE(OP_JMPUW, S) {
1273
+ a = (uint32_t)((pc - irep->iseq) + (int16_t)a);
1274
+ CHECKPOINT_RESTORE(RBREAK_TAG_JUMP) {
1275
+ struct RBreak *brk = (struct RBreak*)mrb->exc;
1276
+ mrb_value target = mrb_break_value_get(brk);
1277
+ mrb_assert(mrb_integer_p(target));
1278
+ a = (uint32_t)mrb_integer(target);
1279
+ mrb_assert(a >= 0 && a < irep->ilen);
1227
1280
  }
1228
- /* expand rescue stack */
1229
- if (mrb->c->rsize <= mrb->c->ci->ridx) {
1230
- if (mrb->c->rsize == 0) mrb->c->rsize = RESCUE_STACK_INIT_SIZE;
1231
- else {
1232
- mrb->c->rsize *= 2;
1233
- if (mrb->c->rsize <= mrb->c->ci->ridx) {
1234
- mrb->c->rsize = UINT16_MAX;
1281
+ CHECKPOINT_MAIN(RBREAK_TAG_JUMP) {
1282
+ ch = catch_handler_find(mrb, mrb->c->ci, pc, MRB_CATCH_FILTER_ENSURE);
1283
+ if (ch) {
1284
+ /* avoiding a jump from a catch handler into the same handler */
1285
+ if (a < mrb_irep_catch_handler_unpack(ch->begin) || a >= mrb_irep_catch_handler_unpack(ch->end)) {
1286
+ THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, proc, mrb_fixnum_value(a));
1235
1287
  }
1236
1288
  }
1237
- mrb->c->rescue = (uint16_t*)mrb_realloc(mrb, mrb->c->rescue, sizeof(uint16_t)*mrb->c->rsize);
1238
1289
  }
1239
- /* push rescue stack */
1240
- mrb->c->rescue[mrb->c->ci->ridx++] = a;
1241
- NEXT;
1290
+ CHECKPOINT_END(RBREAK_TAG_JUMP);
1291
+
1292
+ mrb->exc = NULL; /* clear break object */
1293
+ pc = irep->iseq + a;
1294
+ JUMP;
1242
1295
  }
1243
1296
 
1244
1297
  CASE(OP_EXCEPT, B) {
1245
- mrb_value exc = mrb_obj_value(mrb->exc);
1246
- mrb->exc = 0;
1298
+ mrb_value exc;
1299
+
1300
+ if (mrb->exc == NULL) {
1301
+ exc = mrb_nil_value();
1302
+ }
1303
+ else {
1304
+ switch (mrb->exc->tt) {
1305
+ case MRB_TT_BREAK:
1306
+ case MRB_TT_EXCEPTION:
1307
+ exc = mrb_obj_value(mrb->exc);
1308
+ break;
1309
+ default:
1310
+ mrb_assert(!"bad mrb_type");
1311
+ exc = mrb_nil_value();
1312
+ break;
1313
+ }
1314
+ mrb->exc = NULL;
1315
+ }
1247
1316
  regs[a] = exc;
1248
1317
  NEXT;
1249
1318
  }
@@ -1260,7 +1329,7 @@ RETRY_TRY_BLOCK:
1260
1329
  {
1261
1330
  mrb_value exc;
1262
1331
 
1263
- exc = mrb_exc_new_str_lit(mrb, E_TYPE_ERROR,
1332
+ exc = mrb_exc_new_lit(mrb, E_TYPE_ERROR,
1264
1333
  "class or module required for rescue clause");
1265
1334
  mrb_exc_set(mrb, exc);
1266
1335
  goto L_RAISE;
@@ -1271,82 +1340,19 @@ RETRY_TRY_BLOCK:
1271
1340
  NEXT;
1272
1341
  }
1273
1342
 
1274
- CASE(OP_POPERR, B) {
1275
- mrb->c->ci->ridx -= a;
1276
- NEXT;
1277
- }
1278
-
1279
- CASE(OP_RAISE, B) {
1280
- mrb_exc_set(mrb, regs[a]);
1281
- goto L_RAISE;
1282
- }
1283
-
1284
- CASE(OP_EPUSH, B) {
1285
- struct RProc *p;
1286
-
1287
- p = mrb_closure_new(mrb, irep->reps[a]);
1288
- /* check ensure stack */
1289
- if (mrb->c->eidx == UINT16_MAX-1) {
1290
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "too many nested ensures");
1291
- mrb_exc_set(mrb, exc);
1292
- goto L_RAISE;
1343
+ CASE(OP_RAISEIF, B) {
1344
+ mrb_value exc = regs[a];
1345
+ if (mrb_break_p(exc)) {
1346
+ mrb->exc = mrb_obj_ptr(exc);
1347
+ goto L_BREAK;
1293
1348
  }
1294
- /* expand ensure stack */
1295
- if (mrb->c->esize <= mrb->c->eidx+1) {
1296
- if (mrb->c->esize == 0) mrb->c->esize = ENSURE_STACK_INIT_SIZE;
1297
- else {
1298
- mrb->c->esize *= 2;
1299
- if (mrb->c->esize <= mrb->c->eidx) {
1300
- mrb->c->esize = UINT16_MAX;
1301
- }
1302
- }
1303
- mrb->c->ensure = (struct RProc**)mrb_realloc(mrb, mrb->c->ensure, sizeof(struct RProc*)*mrb->c->esize);
1349
+ mrb_exc_set(mrb, exc);
1350
+ if (mrb->exc) {
1351
+ goto L_RAISE;
1304
1352
  }
1305
- /* push ensure stack */
1306
- mrb->c->ensure[mrb->c->eidx++] = p;
1307
- mrb->c->ensure[mrb->c->eidx] = NULL;
1308
- mrb_gc_arena_restore(mrb, ai);
1309
1353
  NEXT;
1310
1354
  }
1311
1355
 
1312
- CASE(OP_EPOP, B) {
1313
- mrb_callinfo *ci = mrb->c->ci;
1314
- unsigned int n, epos = ci->epos;
1315
- mrb_value self = regs[0];
1316
- struct RClass *target_class = ci->target_class;
1317
-
1318
- if (mrb->c->eidx <= epos) {
1319
- NEXT;
1320
- }
1321
-
1322
- if (a > (int)mrb->c->eidx - epos)
1323
- a = mrb->c->eidx - epos;
1324
- for (n=0; n<a; n++) {
1325
- int nregs = irep->nregs;
1326
-
1327
- proc = mrb->c->ensure[epos+n];
1328
- mrb->c->ensure[epos+n] = NULL;
1329
- if (proc == NULL) continue;
1330
- irep = proc->body.irep;
1331
- ci = cipush(mrb);
1332
- ci->mid = ci[-1].mid;
1333
- ci->argc = 0;
1334
- ci->proc = proc;
1335
- ci->stackent = mrb->c->stack;
1336
- ci->target_class = target_class;
1337
- ci->pc = pc;
1338
- ci->acc = nregs;
1339
- mrb->c->stack += ci->acc;
1340
- mrb_stack_extend(mrb, irep->nregs);
1341
- regs[0] = self;
1342
- pc = irep->iseq;
1343
- }
1344
- pool = irep->pool;
1345
- syms = irep->syms;
1346
- mrb->c->eidx = epos;
1347
- JUMP;
1348
- }
1349
-
1350
1356
  CASE(OP_SENDV, BB) {
1351
1357
  c = CALL_MAXARGS;
1352
1358
  goto L_SEND;
@@ -1378,8 +1384,8 @@ RETRY_TRY_BLOCK:
1378
1384
  mid = syms[b];
1379
1385
  L_SENDB_SYM:
1380
1386
  {
1381
- int argc = (c == CALL_MAXARGS) ? -1 : c;
1382
- int bidx = (argc < 0) ? a+2 : a+c+1;
1387
+ mrb_int argc = (c == CALL_MAXARGS) ? -1 : c;
1388
+ mrb_int bidx = (argc < 0) ? a+2 : a+c+1;
1383
1389
  mrb_method_t m;
1384
1390
  struct RClass *cls;
1385
1391
  mrb_callinfo *ci = mrb->c->ci;
@@ -1390,19 +1396,18 @@ RETRY_TRY_BLOCK:
1390
1396
  recv = regs[a];
1391
1397
  blk = regs[bidx];
1392
1398
  if (!mrb_nil_p(blk) && !mrb_proc_p(blk)) {
1393
- blk = mrb_convert_type(mrb, blk, MRB_TT_PROC, "Proc", "to_proc");
1394
- /* The stack might have been reallocated during mrb_convert_type(),
1399
+ blk = mrb_type_convert(mrb, blk, MRB_TT_PROC, MRB_SYM(to_proc));
1400
+ /* The stack might have been reallocated during mrb_type_convert(),
1395
1401
  see #3622 */
1396
1402
  regs[bidx] = blk;
1397
1403
  }
1398
1404
  cls = mrb_class(mrb, recv);
1399
1405
  m = mrb_method_search_vm(mrb, &cls, mid);
1400
1406
  if (MRB_METHOD_UNDEF_P(m)) {
1401
- mrb_sym missing = mrb_intern_lit(mrb, "method_missing");
1407
+ mrb_sym missing = MRB_SYM(method_missing);
1402
1408
  m = mrb_method_search_vm(mrb, &cls, missing);
1403
1409
  if (MRB_METHOD_UNDEF_P(m) || (missing == mrb->c->ci->mid && mrb_obj_eq(mrb, regs[0], recv))) {
1404
1410
  mrb_value args = (argc < 0) ? regs[a+1] : mrb_ary_new_from_values(mrb, c, regs+a+1);
1405
- ERR_PC_SET(mrb);
1406
1411
  mrb_method_missing(mrb, mid, recv, args);
1407
1412
  }
1408
1413
  if (argc >= 0) {
@@ -1418,23 +1423,13 @@ RETRY_TRY_BLOCK:
1418
1423
  }
1419
1424
 
1420
1425
  /* push callinfo */
1421
- ci = cipush(mrb);
1422
- ci->mid = mid;
1423
- ci->stackent = mrb->c->stack;
1424
- ci->target_class = cls;
1425
- ci->argc = argc;
1426
-
1427
- ci->pc = pc;
1428
- ci->acc = a;
1429
-
1430
- /* prepare stack */
1431
- mrb->c->stack += a;
1426
+ ci = cipush(mrb, a, a, cls, NULL, mid, argc);
1432
1427
 
1433
1428
  if (MRB_METHOD_CFUNC_P(m)) {
1434
1429
  if (MRB_METHOD_PROC_P(m)) {
1435
1430
  struct RProc *p = MRB_METHOD_PROC(m);
1436
1431
 
1437
- ci->proc = p;
1432
+ mrb_vm_ci_proc_set(ci, p);
1438
1433
  recv = p->body.func(mrb, recv);
1439
1434
  }
1440
1435
  else if (MRB_METHOD_NOARG_P(m) &&
@@ -1451,11 +1446,11 @@ RETRY_TRY_BLOCK:
1451
1446
  ci = mrb->c->ci;
1452
1447
  if (mrb_proc_p(blk)) {
1453
1448
  struct RProc *p = mrb_proc_ptr(blk);
1454
- if (p && !MRB_PROC_STRICT_P(p) && MRB_PROC_ENV(p) == ci[-1].env) {
1449
+ if (p && !MRB_PROC_STRICT_P(p) && MRB_PROC_ENV(p) == mrb_vm_ci_env(&ci[-1])) {
1455
1450
  p->flags |= MRB_PROC_ORPHAN;
1456
1451
  }
1457
1452
  }
1458
- if (!ci->target_class) { /* return from context modifying method (resume/yield) */
1453
+ if (!ci->u.target_class) { /* return from context modifying method (resume/yield) */
1459
1454
  if (ci->acc == CI_ACC_RESUMED) {
1460
1455
  mrb->jmp = prev_jmp;
1461
1456
  return recv;
@@ -1468,16 +1463,15 @@ RETRY_TRY_BLOCK:
1468
1463
  syms = irep->syms;
1469
1464
  }
1470
1465
  }
1471
- mrb->c->stack[0] = recv;
1466
+ mrb->c->ci->stack[0] = recv;
1472
1467
  /* pop stackpos */
1473
- mrb->c->stack = ci->stackent;
1468
+ ci = cipop(mrb);
1474
1469
  pc = ci->pc;
1475
- cipop(mrb);
1476
1470
  JUMP;
1477
1471
  }
1478
1472
  else {
1479
1473
  /* setup environment for calling method */
1480
- proc = ci->proc = MRB_METHOD_PROC(m);
1474
+ mrb_vm_ci_proc_set(ci, (proc = MRB_METHOD_PROC(m)));
1481
1475
  irep = proc->body.irep;
1482
1476
  pool = irep->pool;
1483
1477
  syms = irep->syms;
@@ -1489,13 +1483,13 @@ RETRY_TRY_BLOCK:
1489
1483
 
1490
1484
  CASE(OP_CALL, Z) {
1491
1485
  mrb_callinfo *ci;
1492
- mrb_value recv = mrb->c->stack[0];
1486
+ mrb_value recv = mrb->c->ci->stack[0];
1493
1487
  struct RProc *m = mrb_proc_ptr(recv);
1494
1488
 
1495
1489
  /* replace callinfo */
1496
1490
  ci = mrb->c->ci;
1497
- ci->target_class = MRB_PROC_TARGET_CLASS(m);
1498
- ci->proc = m;
1491
+ ci->u.target_class = MRB_PROC_TARGET_CLASS(m);
1492
+ mrb_vm_ci_proc_set(ci, m);
1499
1493
  if (MRB_PROC_ENV_P(m)) {
1500
1494
  ci->mid = MRB_PROC_ENV(m)->mid;
1501
1495
  }
@@ -1507,11 +1501,9 @@ RETRY_TRY_BLOCK:
1507
1501
  mrb_gc_arena_shrink(mrb, ai);
1508
1502
  if (mrb->exc) goto L_RAISE;
1509
1503
  /* pop stackpos */
1510
- ci = mrb->c->ci;
1511
- mrb->c->stack = ci->stackent;
1512
- regs[ci->acc] = recv;
1504
+ ci = cipop(mrb);
1513
1505
  pc = ci->pc;
1514
- cipop(mrb);
1506
+ regs[ci[1].acc] = recv;
1515
1507
  irep = mrb->c->ci->proc->body.irep;
1516
1508
  pool = irep->pool;
1517
1509
  syms = irep->syms;
@@ -1522,10 +1514,10 @@ RETRY_TRY_BLOCK:
1522
1514
  proc = m;
1523
1515
  irep = m->body.irep;
1524
1516
  if (!irep) {
1525
- mrb->c->stack[0] = mrb_nil_value();
1517
+ mrb->c->ci->stack[0] = mrb_nil_value();
1526
1518
  a = 0;
1527
1519
  c = OP_R_NORMAL;
1528
- goto L_OP_RETURN_BODY;
1520
+ goto L_RETURN;
1529
1521
  }
1530
1522
  pool = irep->pool;
1531
1523
  syms = irep->syms;
@@ -1547,13 +1539,13 @@ RETRY_TRY_BLOCK:
1547
1539
  }
1548
1540
 
1549
1541
  CASE(OP_SUPER, BB) {
1550
- int argc = (b == CALL_MAXARGS) ? -1 : b;
1542
+ mrb_int argc = (b == CALL_MAXARGS) ? -1 : b;
1551
1543
  int bidx = (argc < 0) ? a+2 : a+b+1;
1552
1544
  mrb_method_t m;
1553
1545
  struct RClass *cls;
1554
1546
  mrb_callinfo *ci = mrb->c->ci;
1555
1547
  mrb_value recv, blk;
1556
- struct RProc *p = ci->proc;
1548
+ const struct RProc *p = ci->proc;
1557
1549
  mrb_sym mid = ci->mid;
1558
1550
  struct RClass* target_class = MRB_PROC_TARGET_CLASS(p);
1559
1551
 
@@ -1563,37 +1555,40 @@ RETRY_TRY_BLOCK:
1563
1555
  mrb_assert(bidx < irep->nregs);
1564
1556
 
1565
1557
  if (mid == 0 || !target_class) {
1566
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
1558
+ mrb_value exc = mrb_exc_new_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
1567
1559
  mrb_exc_set(mrb, exc);
1568
1560
  goto L_RAISE;
1569
1561
  }
1570
- if (target_class->tt == MRB_TT_MODULE) {
1571
- target_class = ci->target_class;
1562
+ if (target_class->flags & MRB_FL_CLASS_IS_PREPENDED) {
1563
+ target_class = mrb_vm_ci_target_class(ci);
1564
+ }
1565
+ else if (target_class->tt == MRB_TT_MODULE) {
1566
+ target_class = mrb_vm_ci_target_class(ci);
1572
1567
  if (target_class->tt != MRB_TT_ICLASS) {
1573
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "superclass info lost [mruby limitations]");
1568
+ mrb_value exc = mrb_exc_new_lit(mrb, E_RUNTIME_ERROR, "superclass info lost [mruby limitations]");
1574
1569
  mrb_exc_set(mrb, exc);
1575
1570
  goto L_RAISE;
1576
1571
  }
1577
1572
  }
1578
1573
  recv = regs[0];
1579
1574
  if (!mrb_obj_is_kind_of(mrb, recv, target_class)) {
1580
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_TYPE_ERROR,
1575
+ mrb_value exc = mrb_exc_new_lit(mrb, E_TYPE_ERROR,
1581
1576
  "self has wrong type to call super in this context");
1582
1577
  mrb_exc_set(mrb, exc);
1583
1578
  goto L_RAISE;
1584
1579
  }
1585
1580
  blk = regs[bidx];
1586
1581
  if (!mrb_nil_p(blk) && !mrb_proc_p(blk)) {
1587
- blk = mrb_convert_type(mrb, blk, MRB_TT_PROC, "Proc", "to_proc");
1582
+ blk = mrb_type_convert(mrb, blk, MRB_TT_PROC, MRB_SYM(to_proc));
1588
1583
  /* The stack or ci stack might have been reallocated during
1589
- mrb_convert_type(), see #3622 and #3784 */
1584
+ mrb_type_convert(), see #3622 and #3784 */
1590
1585
  regs[bidx] = blk;
1591
1586
  ci = mrb->c->ci;
1592
1587
  }
1593
1588
  cls = target_class->super;
1594
1589
  m = mrb_method_search_vm(mrb, &cls, mid);
1595
1590
  if (MRB_METHOD_UNDEF_P(m)) {
1596
- mrb_sym missing = mrb_intern_lit(mrb, "method_missing");
1591
+ mrb_sym missing = MRB_SYM(method_missing);
1597
1592
 
1598
1593
  if (mid != missing) {
1599
1594
  cls = mrb_class(mrb, recv);
@@ -1601,7 +1596,6 @@ RETRY_TRY_BLOCK:
1601
1596
  m = mrb_method_search_vm(mrb, &cls, missing);
1602
1597
  if (MRB_METHOD_UNDEF_P(m)) {
1603
1598
  mrb_value args = (argc < 0) ? regs[a+1] : mrb_ary_new_from_values(mrb, b, regs+a+1);
1604
- ERR_PC_SET(mrb);
1605
1599
  mrb_method_missing(mrb, mid, recv, args);
1606
1600
  }
1607
1601
  mid = missing;
@@ -1617,28 +1611,23 @@ RETRY_TRY_BLOCK:
1617
1611
  }
1618
1612
 
1619
1613
  /* push callinfo */
1620
- ci = cipush(mrb);
1621
- ci->mid = mid;
1622
- ci->stackent = mrb->c->stack;
1623
- ci->target_class = cls;
1624
- ci->pc = pc;
1625
- ci->argc = argc;
1614
+ ci = cipush(mrb, a, 0, cls, NULL, mid, argc);
1626
1615
 
1627
1616
  /* prepare stack */
1628
- mrb->c->stack += a;
1629
- mrb->c->stack[0] = recv;
1617
+ mrb->c->ci->stack[0] = recv;
1630
1618
 
1631
1619
  if (MRB_METHOD_CFUNC_P(m)) {
1632
1620
  mrb_value v;
1633
1621
 
1634
1622
  if (MRB_METHOD_PROC_P(m)) {
1635
- ci->proc = MRB_METHOD_PROC(m);
1623
+ mrb_vm_ci_proc_set(ci, MRB_METHOD_PROC(m));
1636
1624
  }
1637
1625
  v = MRB_METHOD_CFUNC(m)(mrb, recv);
1638
1626
  mrb_gc_arena_restore(mrb, ai);
1639
1627
  if (mrb->exc) goto L_RAISE;
1640
1628
  ci = mrb->c->ci;
1641
- if (!ci->target_class) { /* return from context modifying method (resume/yield) */
1629
+ mrb_assert(!mrb_break_p(v));
1630
+ if (!mrb_vm_ci_target_class(ci)) { /* return from context modifying method (resume/yield) */
1642
1631
  if (ci->acc == CI_ACC_RESUMED) {
1643
1632
  mrb->jmp = prev_jmp;
1644
1633
  return v;
@@ -1651,11 +1640,9 @@ RETRY_TRY_BLOCK:
1651
1640
  syms = irep->syms;
1652
1641
  }
1653
1642
  }
1654
- mrb->c->stack[0] = v;
1655
- /* pop stackpos */
1656
- mrb->c->stack = ci->stackent;
1643
+ mrb->c->ci->stack[0] = v;
1644
+ ci = cipop(mrb);
1657
1645
  pc = ci->pc;
1658
- cipop(mrb);
1659
1646
  JUMP;
1660
1647
  }
1661
1648
  else {
@@ -1663,7 +1650,7 @@ RETRY_TRY_BLOCK:
1663
1650
  ci->acc = a;
1664
1651
 
1665
1652
  /* setup environment for calling method */
1666
- proc = ci->proc = MRB_METHOD_PROC(m);
1653
+ mrb_vm_ci_proc_set(ci, (proc = MRB_METHOD_PROC(m)));
1667
1654
  irep = proc->body.irep;
1668
1655
  pool = irep->pool;
1669
1656
  syms = irep->syms;
@@ -1674,18 +1661,18 @@ RETRY_TRY_BLOCK:
1674
1661
  }
1675
1662
 
1676
1663
  CASE(OP_ARGARY, BS) {
1677
- int m1 = (b>>11)&0x3f;
1678
- int r = (b>>10)&0x1;
1679
- int m2 = (b>>5)&0x1f;
1680
- int kd = (b>>4)&0x1;
1681
- int lv = (b>>0)&0xf;
1664
+ mrb_int m1 = (b>>11)&0x3f;
1665
+ mrb_int r = (b>>10)&0x1;
1666
+ mrb_int m2 = (b>>5)&0x1f;
1667
+ mrb_int kd = (b>>4)&0x1;
1668
+ mrb_int lv = (b>>0)&0xf;
1682
1669
  mrb_value *stack;
1683
1670
 
1684
- if (mrb->c->ci->mid == 0 || mrb->c->ci->target_class == NULL) {
1671
+ if (mrb->c->ci->mid == 0 || mrb_vm_ci_target_class(mrb->c->ci) == NULL) {
1685
1672
  mrb_value exc;
1686
1673
 
1687
1674
  L_NOSUPER:
1688
- exc = mrb_exc_new_str_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
1675
+ exc = mrb_exc_new_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
1689
1676
  mrb_exc_set(mrb, exc);
1690
1677
  goto L_RAISE;
1691
1678
  }
@@ -1703,13 +1690,13 @@ RETRY_TRY_BLOCK:
1703
1690
  else {
1704
1691
  mrb_value *pp = NULL;
1705
1692
  struct RArray *rest;
1706
- int len = 0;
1693
+ mrb_int len = 0;
1707
1694
 
1708
1695
  if (mrb_array_p(stack[m1])) {
1709
1696
  struct RArray *ary = mrb_ary_ptr(stack[m1]);
1710
1697
 
1711
1698
  pp = ARY_PTR(ary);
1712
- len = (int)ARY_LEN(ary);
1699
+ len = ARY_LEN(ary);
1713
1700
  }
1714
1701
  regs[a] = mrb_ary_new_capa(mrb, m1+len+m2+kd);
1715
1702
  rest = mrb_ary_ptr(regs[a]);
@@ -1733,22 +1720,22 @@ RETRY_TRY_BLOCK:
1733
1720
  }
1734
1721
 
1735
1722
  CASE(OP_ENTER, W) {
1736
- int m1 = MRB_ASPEC_REQ(a);
1737
- int o = MRB_ASPEC_OPT(a);
1738
- int r = MRB_ASPEC_REST(a);
1739
- int m2 = MRB_ASPEC_POST(a);
1740
- int kd = (MRB_ASPEC_KEY(a) > 0 || MRB_ASPEC_KDICT(a))? 1 : 0;
1723
+ mrb_int m1 = MRB_ASPEC_REQ(a);
1724
+ mrb_int o = MRB_ASPEC_OPT(a);
1725
+ mrb_int r = MRB_ASPEC_REST(a);
1726
+ mrb_int m2 = MRB_ASPEC_POST(a);
1727
+ mrb_int kd = (MRB_ASPEC_KEY(a) > 0 || MRB_ASPEC_KDICT(a))? 1 : 0;
1741
1728
  /* unused
1742
1729
  int b = MRB_ASPEC_BLOCK(a);
1743
1730
  */
1744
- int argc = mrb->c->ci->argc;
1731
+ mrb_int argc = mrb->c->ci->argc;
1745
1732
  mrb_value *argv = regs+1;
1746
1733
  mrb_value * const argv0 = argv;
1747
- int const len = m1 + o + r + m2;
1748
- int const blk_pos = len + kd + 1;
1734
+ mrb_int const len = m1 + o + r + m2;
1735
+ mrb_int const blk_pos = len + kd + 1;
1749
1736
  mrb_value *blk = &argv[argc < 0 ? 1 : argc];
1750
- mrb_value kdict;
1751
- int kargs = kd;
1737
+ mrb_value kdict = mrb_nil_value();
1738
+ mrb_int kargs = kd;
1752
1739
 
1753
1740
  /* arguments is passed with Array */
1754
1741
  if (argc < 0) {
@@ -1800,7 +1787,7 @@ RETRY_TRY_BLOCK:
1800
1787
 
1801
1788
  /* no rest arguments */
1802
1789
  if (argc-kargs < len) {
1803
- int mlen = m2;
1790
+ mrb_int mlen = m2;
1804
1791
  if (argc < m1+m2) {
1805
1792
  mlen = m1 < argc ? argc - m1 : 0;
1806
1793
  }
@@ -1808,7 +1795,7 @@ RETRY_TRY_BLOCK:
1808
1795
  if (kd) regs[len + 1] = kdict;
1809
1796
 
1810
1797
  /* copy mandatory and optional arguments */
1811
- if (argv0 != argv) {
1798
+ if (argv0 != argv && argv) {
1812
1799
  value_move(&regs[1], argv, argc-mlen); /* m1 + o */
1813
1800
  }
1814
1801
  if (argc < m1) {
@@ -1821,16 +1808,16 @@ RETRY_TRY_BLOCK:
1821
1808
  if (mlen < m2) {
1822
1809
  stack_clear(&regs[len-m2+mlen+1], m2-mlen);
1823
1810
  }
1824
- /* initalize rest arguments with empty Array */
1811
+ /* initialize rest arguments with empty Array */
1825
1812
  if (r) {
1826
1813
  regs[m1+o+1] = mrb_ary_new_capa(mrb, 0);
1827
1814
  }
1828
- /* skip initailizer of passed arguments */
1815
+ /* skip initializer of passed arguments */
1829
1816
  if (o > 0 && argc-kargs > m1+m2)
1830
1817
  pc += (argc - kargs - m1 - m2)*3;
1831
1818
  }
1832
1819
  else {
1833
- int rnum = 0;
1820
+ mrb_int rnum = 0;
1834
1821
  if (argv0 != argv) {
1835
1822
  regs[blk_pos] = *blk; /* move block */
1836
1823
  if (kd) regs[len + 1] = kdict;
@@ -1856,7 +1843,7 @@ RETRY_TRY_BLOCK:
1856
1843
  }
1857
1844
 
1858
1845
  /* format arguments for generated code */
1859
- mrb->c->ci->argc = len + kd;
1846
+ mrb->c->ci->argc = (int16_t)(len + kd);
1860
1847
 
1861
1848
  /* clear local (but non-argument) variables */
1862
1849
  if (irep->nlocals-blk_pos-1 > 0) {
@@ -1916,13 +1903,7 @@ RETRY_TRY_BLOCK:
1916
1903
  c = OP_R_NORMAL;
1917
1904
  L_RETURN:
1918
1905
  {
1919
- mrb_callinfo *ci;
1920
-
1921
- #define ecall_adjust() do {\
1922
- ptrdiff_t cioff = ci - mrb->c->cibase;\
1923
- ecall(mrb);\
1924
- ci = mrb->c->cibase + cioff;\
1925
- } while (0)
1906
+ mrb_callinfo *ci;
1926
1907
 
1927
1908
  ci = mrb->c->ci;
1928
1909
  if (ci->mid) {
@@ -1938,42 +1919,38 @@ RETRY_TRY_BLOCK:
1938
1919
  struct RProc *p = mrb_proc_ptr(blk);
1939
1920
 
1940
1921
  if (!MRB_PROC_STRICT_P(p) &&
1941
- ci > mrb->c->cibase && MRB_PROC_ENV(p) == ci[-1].env) {
1922
+ ci > mrb->c->cibase && MRB_PROC_ENV(p) == mrb_vm_ci_env(&ci[-1])) {
1942
1923
  p->flags |= MRB_PROC_ORPHAN;
1943
1924
  }
1944
1925
  }
1945
1926
  }
1946
1927
 
1947
1928
  if (mrb->exc) {
1948
- mrb_callinfo *ci0;
1949
-
1950
1929
  L_RAISE:
1951
- ci0 = ci = mrb->c->ci;
1930
+ ci = mrb->c->ci;
1952
1931
  if (ci == mrb->c->cibase) {
1953
- if (ci->ridx == 0) goto L_FTOP;
1954
- goto L_RESCUE;
1932
+ ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL);
1933
+ if (ch == NULL) goto L_FTOP;
1934
+ goto L_CATCH;
1955
1935
  }
1956
- while (ci[0].ridx == ci[-1].ridx) {
1957
- cipop(mrb);
1958
- mrb->c->stack = ci->stackent;
1959
- if (ci->acc == CI_ACC_SKIP && prev_jmp) {
1936
+ while ((ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL)) == NULL) {
1937
+ ci = cipop(mrb);
1938
+ if (ci[1].acc == CI_ACC_SKIP && prev_jmp) {
1960
1939
  mrb->jmp = prev_jmp;
1961
1940
  MRB_THROW(prev_jmp);
1962
1941
  }
1963
- ci = mrb->c->ci;
1942
+ pc = ci[0].pc;
1964
1943
  if (ci == mrb->c->cibase) {
1965
- if (ci->ridx == 0) {
1944
+ ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL);
1945
+ if (ch == NULL) {
1966
1946
  L_FTOP: /* fiber top */
1967
1947
  if (mrb->c == mrb->root_c) {
1968
- mrb->c->stack = mrb->c->stbase;
1948
+ mrb->c->ci->stack = mrb->c->stbase;
1969
1949
  goto L_STOP;
1970
1950
  }
1971
1951
  else {
1972
1952
  struct mrb_context *c = mrb->c;
1973
1953
 
1974
- while (c->eidx > ci->epos) {
1975
- ecall_adjust();
1976
- }
1977
1954
  c->status = MRB_FIBER_TERMINATED;
1978
1955
  mrb->c = c->prev;
1979
1956
  c->prev = NULL;
@@ -1982,29 +1959,23 @@ RETRY_TRY_BLOCK:
1982
1959
  }
1983
1960
  break;
1984
1961
  }
1985
- /* call ensure only when we skip this callinfo */
1986
- if (ci[0].ridx == ci[-1].ridx) {
1987
- while (mrb->c->eidx > ci->epos) {
1988
- ecall_adjust();
1989
- }
1990
- }
1991
1962
  }
1992
- L_RESCUE:
1993
- if (ci->ridx == 0) goto L_STOP;
1963
+ L_CATCH:
1964
+ if (ch == NULL) goto L_STOP;
1965
+ if (FALSE) {
1966
+ L_CATCH_TAGGED_BREAK: /* from THROW_TAGGED_BREAK() or UNWIND_ENSURE() */
1967
+ ci = mrb->c->ci;
1968
+ }
1994
1969
  proc = ci->proc;
1995
1970
  irep = proc->body.irep;
1996
1971
  pool = irep->pool;
1997
1972
  syms = irep->syms;
1998
- if (ci < ci0) {
1999
- mrb->c->stack = ci[1].stackent;
2000
- }
2001
1973
  mrb_stack_extend(mrb, irep->nregs);
2002
- pc = irep->iseq+mrb->c->rescue[--ci->ridx];
1974
+ pc = irep->iseq + mrb_irep_catch_handler_unpack(ch->target);
2003
1975
  }
2004
1976
  else {
2005
- int acc;
1977
+ mrb_int acc;
2006
1978
  mrb_value v;
2007
- struct RProc *dst;
2008
1979
 
2009
1980
  ci = mrb->c->ci;
2010
1981
  v = regs[a];
@@ -2013,7 +1984,9 @@ RETRY_TRY_BLOCK:
2013
1984
  case OP_R_RETURN:
2014
1985
  /* Fall through to OP_R_NORMAL otherwise */
2015
1986
  if (ci->acc >=0 && MRB_PROC_ENV_P(proc) && !MRB_PROC_STRICT_P(proc)) {
2016
- mrb_callinfo *cibase = mrb->c->cibase;
1987
+ const struct RProc *dst;
1988
+ mrb_callinfo *cibase;
1989
+ cibase = mrb->c->cibase;
2017
1990
  dst = top_proc(mrb, proc);
2018
1991
 
2019
1992
  if (MRB_PROC_ENV_P(dst)) {
@@ -2024,44 +1997,79 @@ RETRY_TRY_BLOCK:
2024
1997
  goto L_RAISE;
2025
1998
  }
2026
1999
  }
2000
+ /* check jump destination */
2027
2001
  while (cibase <= ci && ci->proc != dst) {
2028
- if (ci->acc < 0) {
2002
+ if (ci->acc < 0) { /* jump cross C boudary */
2029
2003
  localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
2030
2004
  goto L_RAISE;
2031
2005
  }
2032
2006
  ci--;
2033
2007
  }
2034
- if (ci <= cibase) {
2008
+ if (ci <= cibase) { /* no jump destination */
2035
2009
  localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
2036
2010
  goto L_RAISE;
2037
2011
  }
2012
+ ci = mrb->c->ci;
2013
+ while (cibase <= ci && ci->proc != dst) {
2014
+ CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_BLOCK) {
2015
+ cibase = mrb->c->cibase;
2016
+ dst = top_proc(mrb, proc);
2017
+ }
2018
+ CHECKPOINT_MAIN(RBREAK_TAG_RETURN_BLOCK) {
2019
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_BLOCK, proc, v);
2020
+ }
2021
+ CHECKPOINT_END(RBREAK_TAG_RETURN_BLOCK);
2022
+ ci = cipop(mrb);
2023
+ pc = ci->pc;
2024
+ }
2025
+ proc = ci->proc;
2026
+ mrb->exc = NULL; /* clear break object */
2038
2027
  break;
2039
2028
  }
2040
2029
  /* fallthrough */
2041
2030
  case OP_R_NORMAL:
2042
2031
  NORMAL_RETURN:
2043
2032
  if (ci == mrb->c->cibase) {
2044
- struct mrb_context *c = mrb->c;
2033
+ struct mrb_context *c;
2034
+ c = mrb->c;
2045
2035
 
2046
2036
  if (!c->prev) { /* toplevel return */
2047
2037
  regs[irep->nlocals] = v;
2048
- goto L_STOP;
2038
+ goto CHECKPOINT_LABEL_MAKE(RBREAK_TAG_STOP);
2049
2039
  }
2050
- if (c->prev->ci == c->prev->cibase) {
2051
- mrb_value exc = mrb_exc_new_str_lit(mrb, E_FIBER_ERROR, "double resume");
2040
+ if (!c->vmexec && c->prev->ci == c->prev->cibase) {
2041
+ mrb_value exc = mrb_exc_new_lit(mrb, E_FIBER_ERROR, "double resume");
2052
2042
  mrb_exc_set(mrb, exc);
2053
2043
  goto L_RAISE;
2054
2044
  }
2055
- while (c->eidx > 0) {
2056
- ecall(mrb);
2045
+ CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_TOPLEVEL) {
2046
+ c = mrb->c;
2047
+ }
2048
+ CHECKPOINT_MAIN(RBREAK_TAG_RETURN_TOPLEVEL) {
2049
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_TOPLEVEL, proc, v);
2057
2050
  }
2051
+ CHECKPOINT_END(RBREAK_TAG_RETURN_TOPLEVEL);
2058
2052
  /* automatic yield at the end */
2059
2053
  c->status = MRB_FIBER_TERMINATED;
2060
2054
  mrb->c = c->prev;
2061
- c->prev = NULL;
2062
2055
  mrb->c->status = MRB_FIBER_RUNNING;
2056
+ c->prev = NULL;
2057
+ if (c->vmexec) {
2058
+ mrb_gc_arena_restore(mrb, ai);
2059
+ c->vmexec = FALSE;
2060
+ mrb->jmp = prev_jmp;
2061
+ return v;
2062
+ }
2063
2063
  ci = mrb->c->ci;
2064
2064
  }
2065
+ CHECKPOINT_RESTORE(RBREAK_TAG_RETURN) {
2066
+ /* do nothing */
2067
+ }
2068
+ CHECKPOINT_MAIN(RBREAK_TAG_RETURN) {
2069
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN, proc, v);
2070
+ }
2071
+ CHECKPOINT_END(RBREAK_TAG_RETURN);
2072
+ mrb->exc = NULL; /* clear break object */
2065
2073
  break;
2066
2074
  case OP_R_BREAK:
2067
2075
  if (MRB_PROC_STRICT_P(proc)) goto NORMAL_RETURN;
@@ -2069,7 +2077,7 @@ RETRY_TRY_BLOCK:
2069
2077
  mrb_value exc;
2070
2078
 
2071
2079
  L_BREAK_ERROR:
2072
- exc = mrb_exc_new_str_lit(mrb, E_LOCALJUMP_ERROR,
2080
+ exc = mrb_exc_new_lit(mrb, E_LOCALJUMP_ERROR,
2073
2081
  "break from proc-closure");
2074
2082
  mrb_exc_set(mrb, exc);
2075
2083
  goto L_RAISE;
@@ -2084,9 +2092,13 @@ RETRY_TRY_BLOCK:
2084
2092
  goto L_BREAK_ERROR;
2085
2093
  }
2086
2094
  }
2087
- while (mrb->c->eidx > mrb->c->ci->epos) {
2088
- ecall_adjust();
2095
+ CHECKPOINT_RESTORE(RBREAK_TAG_BREAK) {
2096
+ /* do nothing */
2097
+ }
2098
+ CHECKPOINT_MAIN(RBREAK_TAG_BREAK) {
2099
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK, proc, v);
2089
2100
  }
2101
+ CHECKPOINT_END(RBREAK_TAG_BREAK);
2090
2102
  /* break from fiber block */
2091
2103
  if (ci == mrb->c->cibase && ci->pc) {
2092
2104
  struct mrb_context *c = mrb->c;
@@ -2096,61 +2108,77 @@ RETRY_TRY_BLOCK:
2096
2108
  ci = mrb->c->ci;
2097
2109
  }
2098
2110
  if (ci->acc < 0) {
2111
+ ci = cipop(mrb);
2099
2112
  mrb_gc_arena_restore(mrb, ai);
2100
2113
  mrb->c->vmexec = FALSE;
2101
- mrb->exc = (struct RObject*)break_new(mrb, proc, v);
2114
+ mrb->exc = (struct RObject*)break_new(mrb, RBREAK_TAG_BREAK, proc, v);
2102
2115
  mrb->jmp = prev_jmp;
2103
2116
  MRB_THROW(prev_jmp);
2104
2117
  }
2105
2118
  if (FALSE) {
2119
+ struct RBreak *brk;
2120
+
2106
2121
  L_BREAK:
2107
- v = mrb_break_value_get((struct RBreak*)mrb->exc);
2108
- proc = mrb_break_proc_get((struct RBreak*)mrb->exc);
2109
- mrb->exc = NULL;
2122
+ brk = (struct RBreak*)mrb->exc;
2123
+ proc = mrb_break_proc_get(brk);
2124
+ v = mrb_break_value_get(brk);
2110
2125
  ci = mrb->c->ci;
2126
+
2127
+ switch (mrb_break_tag_get(brk)) {
2128
+ #define DISPATCH_CHECKPOINTS(n, i) case n: goto CHECKPOINT_LABEL_MAKE(n);
2129
+ RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS)
2130
+ #undef DISPATCH_CHECKPOINTS
2131
+ default:
2132
+ mrb_assert(!"wrong break tag");
2133
+ }
2111
2134
  }
2112
- mrb->c->stack = ci->stackent;
2113
- proc = proc->upper;
2114
- while (mrb->c->cibase < ci && ci[-1].proc != proc) {
2135
+ while (mrb->c->cibase < ci && ci[-1].proc != proc->upper) {
2115
2136
  if (ci[-1].acc == CI_ACC_SKIP) {
2116
- while (ci < mrb->c->ci) {
2117
- cipop(mrb);
2118
- }
2119
2137
  goto L_BREAK_ERROR;
2120
2138
  }
2121
- ci--;
2139
+ CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_UPPER) {
2140
+ /* do nothing */
2141
+ }
2142
+ CHECKPOINT_MAIN(RBREAK_TAG_BREAK_UPPER) {
2143
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_UPPER, proc, v);
2144
+ }
2145
+ CHECKPOINT_END(RBREAK_TAG_BREAK_UPPER);
2146
+ ci = cipop(mrb);
2147
+ pc = ci->pc;
2148
+ }
2149
+ CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_INTARGET) {
2150
+ /* do nothing */
2151
+ }
2152
+ CHECKPOINT_MAIN(RBREAK_TAG_BREAK_INTARGET) {
2153
+ UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_INTARGET, proc, v);
2122
2154
  }
2155
+ CHECKPOINT_END(RBREAK_TAG_BREAK_INTARGET);
2123
2156
  if (ci == mrb->c->cibase) {
2124
2157
  goto L_BREAK_ERROR;
2125
2158
  }
2159
+ mrb->exc = NULL; /* clear break object */
2126
2160
  break;
2127
2161
  default:
2128
2162
  /* cannot happen */
2129
2163
  break;
2130
2164
  }
2131
- while (ci < mrb->c->ci) {
2132
- cipop(mrb);
2133
- }
2134
- ci[0].ridx = ci[-1].ridx;
2135
- while (mrb->c->eidx > ci->epos) {
2136
- ecall_adjust();
2137
- }
2138
- if (mrb->c->vmexec && !ci->target_class) {
2165
+ mrb_assert(ci == mrb->c->ci);
2166
+ mrb_assert(mrb->exc == NULL);
2167
+
2168
+ if (mrb->c->vmexec && !mrb_vm_ci_target_class(ci)) {
2139
2169
  mrb_gc_arena_restore(mrb, ai);
2140
2170
  mrb->c->vmexec = FALSE;
2141
2171
  mrb->jmp = prev_jmp;
2142
2172
  return v;
2143
2173
  }
2144
2174
  acc = ci->acc;
2145
- mrb->c->stack = ci->stackent;
2146
- cipop(mrb);
2175
+ ci = cipop(mrb);
2147
2176
  if (acc == CI_ACC_SKIP || acc == CI_ACC_DIRECT) {
2148
2177
  mrb_gc_arena_restore(mrb, ai);
2149
2178
  mrb->jmp = prev_jmp;
2150
2179
  return v;
2151
2180
  }
2152
- pc = ci->pc;
2153
- ci = mrb->c->ci;
2181
+ pc = ci[0].pc;
2154
2182
  DEBUG(fprintf(stderr, "from :%s\n", mrb_sym_name(mrb, ci->mid)));
2155
2183
  proc = mrb->c->ci->proc;
2156
2184
  irep = proc->body.irep;
@@ -2189,34 +2217,40 @@ RETRY_TRY_BLOCK:
2189
2217
  NEXT;
2190
2218
  }
2191
2219
 
2220
+ L_INT_OVERFLOW:
2221
+ {
2222
+ mrb_value exc = mrb_exc_new_lit(mrb, E_RANGE_ERROR, "integer overflow");
2223
+ mrb_exc_set(mrb, exc);
2224
+ }
2225
+ goto L_RAISE;
2226
+
2192
2227
  #define TYPES2(a,b) ((((uint16_t)(a))<<8)|(((uint16_t)(b))&0xff))
2193
2228
  #define OP_MATH(op_name) \
2194
2229
  /* need to check if op is overridden */ \
2195
2230
  switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { \
2196
- OP_MATH_CASE_FIXNUM(op_name); \
2197
- OP_MATH_CASE_FLOAT(op_name, fixnum, float); \
2198
- OP_MATH_CASE_FLOAT(op_name, float, fixnum); \
2231
+ OP_MATH_CASE_INTEGER(op_name); \
2232
+ OP_MATH_CASE_FLOAT(op_name, integer, float); \
2233
+ OP_MATH_CASE_FLOAT(op_name, float, integer); \
2199
2234
  OP_MATH_CASE_FLOAT(op_name, float, float); \
2200
2235
  OP_MATH_CASE_STRING_##op_name(); \
2201
2236
  default: \
2202
2237
  c = 1; \
2203
- mid = mrb_intern_lit(mrb, MRB_STRINGIZE(OP_MATH_OP_##op_name)); \
2238
+ mid = MRB_OPSYM(op_name); \
2204
2239
  goto L_SEND_SYM; \
2205
2240
  } \
2206
2241
  NEXT;
2207
- #define OP_MATH_CASE_FIXNUM(op_name) \
2208
- case TYPES2(MRB_TT_FIXNUM, MRB_TT_FIXNUM): \
2242
+ #define OP_MATH_CASE_INTEGER(op_name) \
2243
+ case TYPES2(MRB_TT_INTEGER, MRB_TT_INTEGER): \
2209
2244
  { \
2210
- mrb_int x = mrb_fixnum(regs[a]), y = mrb_fixnum(regs[a+1]), z; \
2245
+ mrb_int x = mrb_integer(regs[a]), y = mrb_integer(regs[a+1]), z; \
2211
2246
  if (mrb_int_##op_name##_overflow(x, y, &z)) \
2212
- OP_MATH_OVERFLOW_INT(op_name, x, y, z); \
2247
+ OP_MATH_OVERFLOW_INT(); \
2213
2248
  else \
2214
- SET_INT_VALUE(regs[a], z); \
2249
+ SET_INT_VALUE(mrb,regs[a], z); \
2215
2250
  } \
2216
2251
  break
2217
- #ifdef MRB_WITHOUT_FLOAT
2252
+ #ifdef MRB_NO_FLOAT
2218
2253
  #define OP_MATH_CASE_FLOAT(op_name, t1, t2) (void)0
2219
- #define OP_MATH_OVERFLOW_INT(op_name, x, y, z) SET_INT_VALUE(regs[a], z)
2220
2254
  #else
2221
2255
  #define OP_MATH_CASE_FLOAT(op_name, t1, t2) \
2222
2256
  case TYPES2(OP_MATH_TT_##t1, OP_MATH_TT_##t2): \
@@ -2225,9 +2259,8 @@ RETRY_TRY_BLOCK:
2225
2259
  SET_FLOAT_VALUE(mrb, regs[a], z); \
2226
2260
  } \
2227
2261
  break
2228
- #define OP_MATH_OVERFLOW_INT(op_name, x, y, z) \
2229
- SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x OP_MATH_OP_##op_name (mrb_float)y)
2230
2262
  #endif
2263
+ #define OP_MATH_OVERFLOW_INT() goto L_INT_OVERFLOW
2231
2264
  #define OP_MATH_CASE_STRING_add() \
2232
2265
  case TYPES2(MRB_TT_STRING, MRB_TT_STRING): \
2233
2266
  regs[a] = mrb_str_plus(mrb, regs[a], regs[a+1]); \
@@ -2238,8 +2271,8 @@ RETRY_TRY_BLOCK:
2238
2271
  #define OP_MATH_OP_add +
2239
2272
  #define OP_MATH_OP_sub -
2240
2273
  #define OP_MATH_OP_mul *
2241
- #define OP_MATH_TT_fixnum MRB_TT_FIXNUM
2242
- #define OP_MATH_TT_float MRB_TT_FLOAT
2274
+ #define OP_MATH_TT_integer MRB_TT_INTEGER
2275
+ #define OP_MATH_TT_float MRB_TT_FLOAT
2243
2276
 
2244
2277
  CASE(OP_ADD, B) {
2245
2278
  OP_MATH(add);
@@ -2254,31 +2287,30 @@ RETRY_TRY_BLOCK:
2254
2287
  }
2255
2288
 
2256
2289
  CASE(OP_DIV, B) {
2257
- #ifndef MRB_WITHOUT_FLOAT
2258
- double x, y, f;
2290
+ mrb_int mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
2291
+ #ifndef MRB_NO_FLOAT
2292
+ mrb_float mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y);
2293
+ mrb_float x, y, f;
2259
2294
  #endif
2260
2295
 
2261
2296
  /* need to check if op is overridden */
2262
2297
  switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
2263
- case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
2264
- #ifdef MRB_WITHOUT_FLOAT
2298
+ case TYPES2(MRB_TT_INTEGER,MRB_TT_INTEGER):
2265
2299
  {
2266
- mrb_int x = mrb_fixnum(regs[a]);
2267
- mrb_int y = mrb_fixnum(regs[a+1]);
2268
- SET_INT_VALUE(regs[a], y ? x / y : 0);
2300
+ mrb_int x = mrb_integer(regs[a]);
2301
+ mrb_int y = mrb_integer(regs[a+1]);
2302
+ mrb_int div = mrb_num_div_int(mrb, x, y);
2303
+ SET_INT_VALUE(mrb, regs[a], div);
2269
2304
  }
2270
- break;
2271
- #else
2272
- x = (mrb_float)mrb_fixnum(regs[a]);
2273
- y = (mrb_float)mrb_fixnum(regs[a+1]);
2274
- break;
2275
- case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
2276
- x = (mrb_float)mrb_fixnum(regs[a]);
2305
+ NEXT;
2306
+ #ifndef MRB_NO_FLOAT
2307
+ case TYPES2(MRB_TT_INTEGER,MRB_TT_FLOAT):
2308
+ x = (mrb_float)mrb_integer(regs[a]);
2277
2309
  y = mrb_float(regs[a+1]);
2278
2310
  break;
2279
- case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
2311
+ case TYPES2(MRB_TT_FLOAT,MRB_TT_INTEGER):
2280
2312
  x = mrb_float(regs[a]);
2281
- y = (mrb_float)mrb_fixnum(regs[a+1]);
2313
+ y = (mrb_float)mrb_integer(regs[a+1]);
2282
2314
  break;
2283
2315
  case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):
2284
2316
  x = mrb_float(regs[a]);
@@ -2287,19 +2319,12 @@ RETRY_TRY_BLOCK:
2287
2319
  #endif
2288
2320
  default:
2289
2321
  c = 1;
2290
- mid = mrb_intern_lit(mrb, "/");
2322
+ mid = MRB_OPSYM(div);
2291
2323
  goto L_SEND_SYM;
2292
2324
  }
2293
2325
 
2294
- #ifndef MRB_WITHOUT_FLOAT
2295
- if (y == 0) {
2296
- if (x > 0) f = INFINITY;
2297
- else if (x < 0) f = -INFINITY;
2298
- else /* if (x == 0) */ f = NAN;
2299
- }
2300
- else {
2301
- f = x / y;
2302
- }
2326
+ #ifndef MRB_NO_FLOAT
2327
+ f = mrb_num_div_flo(mrb, x, y);
2303
2328
  SET_FLOAT_VALUE(mrb, regs[a], f);
2304
2329
  #endif
2305
2330
  NEXT;
@@ -2308,26 +2333,26 @@ RETRY_TRY_BLOCK:
2308
2333
  #define OP_MATHI(op_name) \
2309
2334
  /* need to check if op is overridden */ \
2310
2335
  switch (mrb_type(regs[a])) { \
2311
- OP_MATHI_CASE_FIXNUM(op_name); \
2336
+ OP_MATHI_CASE_INTEGER(op_name); \
2312
2337
  OP_MATHI_CASE_FLOAT(op_name); \
2313
2338
  default: \
2314
- SET_INT_VALUE(regs[a+1], b); \
2339
+ SET_INT_VALUE(mrb,regs[a+1], b); \
2315
2340
  c = 1; \
2316
- mid = mrb_intern_lit(mrb, MRB_STRINGIZE(OP_MATH_OP_##op_name)); \
2341
+ mid = MRB_OPSYM(op_name); \
2317
2342
  goto L_SEND_SYM; \
2318
2343
  } \
2319
2344
  NEXT;
2320
- #define OP_MATHI_CASE_FIXNUM(op_name) \
2321
- case MRB_TT_FIXNUM: \
2345
+ #define OP_MATHI_CASE_INTEGER(op_name) \
2346
+ case MRB_TT_INTEGER: \
2322
2347
  { \
2323
- mrb_int x = mrb_fixnum(regs[a]), y = (mrb_int)b, z; \
2348
+ mrb_int x = mrb_integer(regs[a]), y = (mrb_int)b, z; \
2324
2349
  if (mrb_int_##op_name##_overflow(x, y, &z)) \
2325
- OP_MATH_OVERFLOW_INT(op_name, x, y, z); \
2350
+ OP_MATH_OVERFLOW_INT(); \
2326
2351
  else \
2327
- SET_INT_VALUE(regs[a], z); \
2352
+ SET_INT_VALUE(mrb,regs[a], z); \
2328
2353
  } \
2329
2354
  break
2330
- #ifdef MRB_WITHOUT_FLOAT
2355
+ #ifdef MRB_NO_FLOAT
2331
2356
  #define OP_MATHI_CASE_FLOAT(op_name) (void)0
2332
2357
  #else
2333
2358
  #define OP_MATHI_CASE_FLOAT(op_name) \
@@ -2349,17 +2374,17 @@ RETRY_TRY_BLOCK:
2349
2374
 
2350
2375
  #define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1]))
2351
2376
 
2352
- #ifdef MRB_WITHOUT_FLOAT
2353
- #define OP_CMP(op) do {\
2377
+ #ifdef MRB_NO_FLOAT
2378
+ #define OP_CMP(op,sym) do {\
2354
2379
  int result;\
2355
2380
  /* need to check if - is overridden */\
2356
2381
  switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
2357
- case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):\
2382
+ case TYPES2(MRB_TT_INTEGER,MRB_TT_INTEGER):\
2358
2383
  result = OP_CMP_BODY(op,mrb_fixnum,mrb_fixnum);\
2359
2384
  break;\
2360
2385
  default:\
2361
2386
  c = 1;\
2362
- mid = mrb_intern_lit(mrb, # op);\
2387
+ mid = MRB_OPSYM(sym);\
2363
2388
  goto L_SEND_SYM;\
2364
2389
  }\
2365
2390
  if (result) {\
@@ -2370,17 +2395,17 @@ RETRY_TRY_BLOCK:
2370
2395
  }\
2371
2396
  } while(0)
2372
2397
  #else
2373
- #define OP_CMP(op) do {\
2398
+ #define OP_CMP(op, sym) do {\
2374
2399
  int result;\
2375
2400
  /* need to check if - is overridden */\
2376
2401
  switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
2377
- case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):\
2402
+ case TYPES2(MRB_TT_INTEGER,MRB_TT_INTEGER):\
2378
2403
  result = OP_CMP_BODY(op,mrb_fixnum,mrb_fixnum);\
2379
2404
  break;\
2380
- case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):\
2405
+ case TYPES2(MRB_TT_INTEGER,MRB_TT_FLOAT):\
2381
2406
  result = OP_CMP_BODY(op,mrb_fixnum,mrb_float);\
2382
2407
  break;\
2383
- case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):\
2408
+ case TYPES2(MRB_TT_FLOAT,MRB_TT_INTEGER):\
2384
2409
  result = OP_CMP_BODY(op,mrb_float,mrb_fixnum);\
2385
2410
  break;\
2386
2411
  case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):\
@@ -2388,7 +2413,7 @@ RETRY_TRY_BLOCK:
2388
2413
  break;\
2389
2414
  default:\
2390
2415
  c = 1;\
2391
- mid = mrb_intern_lit(mrb, # op);\
2416
+ mid = MRB_OPSYM(sym);\
2392
2417
  goto L_SEND_SYM;\
2393
2418
  }\
2394
2419
  if (result) {\
@@ -2405,28 +2430,28 @@ RETRY_TRY_BLOCK:
2405
2430
  SET_TRUE_VALUE(regs[a]);
2406
2431
  }
2407
2432
  else {
2408
- OP_CMP(==);
2433
+ OP_CMP(==,eq);
2409
2434
  }
2410
2435
  NEXT;
2411
2436
  }
2412
2437
 
2413
2438
  CASE(OP_LT, B) {
2414
- OP_CMP(<);
2439
+ OP_CMP(<,lt);
2415
2440
  NEXT;
2416
2441
  }
2417
2442
 
2418
2443
  CASE(OP_LE, B) {
2419
- OP_CMP(<=);
2444
+ OP_CMP(<=,le);
2420
2445
  NEXT;
2421
2446
  }
2422
2447
 
2423
2448
  CASE(OP_GT, B) {
2424
- OP_CMP(>);
2449
+ OP_CMP(>,gt);
2425
2450
  NEXT;
2426
2451
  }
2427
2452
 
2428
2453
  CASE(OP_GE, B) {
2429
- OP_CMP(>=);
2454
+ OP_CMP(>=,ge);
2430
2455
  NEXT;
2431
2456
  }
2432
2457
 
@@ -2537,10 +2562,19 @@ RETRY_TRY_BLOCK:
2537
2562
  NEXT;
2538
2563
  }
2539
2564
 
2565
+ CASE(OP_STRING16, BS) {
2566
+ goto op_string;
2567
+ }
2540
2568
  CASE(OP_STRING, BB) {
2541
- mrb_value str = mrb_str_dup(mrb, pool[b]);
2542
-
2543
- regs[a] = str;
2569
+ size_t len;
2570
+ op_string:
2571
+ len = pool[b].tt >> 2;
2572
+ if (pool[b].tt & IREP_TT_SFLAG) {
2573
+ regs[a] = mrb_str_new_static(mrb, pool[b].u.str, len);
2574
+ }
2575
+ else {
2576
+ regs[a] = mrb_str_new(mrb, pool[b].u.str, len);
2577
+ }
2544
2578
  mrb_gc_arena_restore(mrb, ai);
2545
2579
  NEXT;
2546
2580
  }
@@ -2588,7 +2622,7 @@ RETRY_TRY_BLOCK:
2588
2622
  L_MAKE_LAMBDA:
2589
2623
  {
2590
2624
  struct RProc *p;
2591
- mrb_irep *nirep = irep->reps[b];
2625
+ const mrb_irep *nirep = irep->reps[b];
2592
2626
 
2593
2627
  if (c & OP_L_CAPTURE) {
2594
2628
  p = mrb_closure_new(mrb, nirep);
@@ -2610,6 +2644,18 @@ RETRY_TRY_BLOCK:
2610
2644
  c = OP_L_METHOD;
2611
2645
  goto L_MAKE_LAMBDA;
2612
2646
  }
2647
+ CASE(OP_LAMBDA16, BS) {
2648
+ c = OP_L_LAMBDA;
2649
+ goto L_MAKE_LAMBDA;
2650
+ }
2651
+ CASE(OP_BLOCK16, BS) {
2652
+ c = OP_L_BLOCK;
2653
+ goto L_MAKE_LAMBDA;
2654
+ }
2655
+ CASE(OP_METHOD16, BS) {
2656
+ c = OP_L_METHOD;
2657
+ goto L_MAKE_LAMBDA;
2658
+ }
2613
2659
 
2614
2660
  CASE(OP_RANGE_INC, B) {
2615
2661
  mrb_value val = mrb_range_new(mrb, regs[a], regs[a+1], FALSE);
@@ -2639,6 +2685,7 @@ RETRY_TRY_BLOCK:
2639
2685
  super = regs[a+1];
2640
2686
  if (mrb_nil_p(base)) {
2641
2687
  baseclass = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
2688
+ if (!baseclass) baseclass = mrb->object_class;
2642
2689
  base = mrb_obj_value(baseclass);
2643
2690
  }
2644
2691
  c = mrb_vm_define_class(mrb, base, super, id);
@@ -2655,6 +2702,7 @@ RETRY_TRY_BLOCK:
2655
2702
  base = regs[a];
2656
2703
  if (mrb_nil_p(base)) {
2657
2704
  baseclass = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
2705
+ if (!baseclass) baseclass = mrb->object_class;
2658
2706
  base = mrb_obj_value(baseclass);
2659
2707
  }
2660
2708
  cls = mrb_vm_define_module(mrb, base, id);
@@ -2663,11 +2711,14 @@ RETRY_TRY_BLOCK:
2663
2711
  NEXT;
2664
2712
  }
2665
2713
 
2666
- CASE(OP_EXEC, BB) {
2667
- mrb_callinfo *ci;
2714
+ CASE(OP_EXEC16, BS)
2715
+ goto L_EXEC;
2716
+ CASE(OP_EXEC, BB)
2717
+ L_EXEC:
2718
+ {
2668
2719
  mrb_value recv = regs[a];
2669
2720
  struct RProc *p;
2670
- mrb_irep *nirep = irep->reps[b];
2721
+ const mrb_irep *nirep = irep->reps[b];
2671
2722
 
2672
2723
  /* prepare closure */
2673
2724
  p = mrb_proc_new(mrb, nirep);
@@ -2677,19 +2728,7 @@ RETRY_TRY_BLOCK:
2677
2728
  p->flags |= MRB_PROC_SCOPE;
2678
2729
 
2679
2730
  /* prepare call stack */
2680
- ci = cipush(mrb);
2681
- ci->pc = pc;
2682
- ci->acc = a;
2683
- ci->mid = 0;
2684
- ci->stackent = mrb->c->stack;
2685
- ci->argc = 0;
2686
- ci->target_class = mrb_class_ptr(recv);
2687
-
2688
- /* prepare stack */
2689
- mrb->c->stack += a;
2690
-
2691
- /* setup block to call */
2692
- ci->proc = p;
2731
+ cipush(mrb, a, a, mrb_class_ptr(recv), p, 0, 0);
2693
2732
 
2694
2733
  irep = p->body.irep;
2695
2734
  pool = irep->pool;
@@ -2719,7 +2758,7 @@ RETRY_TRY_BLOCK:
2719
2758
 
2720
2759
  CASE(OP_TCLASS, B) {
2721
2760
  if (!check_target_class(mrb)) goto L_RAISE;
2722
- regs[a] = mrb_obj_value(mrb->c->ci->target_class);
2761
+ regs[a] = mrb_obj_value(mrb_vm_ci_target_class(mrb->c->ci));
2723
2762
  NEXT;
2724
2763
  }
2725
2764
 
@@ -2727,7 +2766,7 @@ RETRY_TRY_BLOCK:
2727
2766
  struct RClass *target;
2728
2767
 
2729
2768
  if (!check_target_class(mrb)) goto L_RAISE;
2730
- target = mrb->c->ci->target_class;
2769
+ target = mrb_vm_ci_target_class(mrb->c->ci);
2731
2770
  mrb_alias_method(mrb, target, syms[a], syms[b]);
2732
2771
  NEXT;
2733
2772
  }
@@ -2735,17 +2774,17 @@ RETRY_TRY_BLOCK:
2735
2774
  struct RClass *target;
2736
2775
 
2737
2776
  if (!check_target_class(mrb)) goto L_RAISE;
2738
- target = mrb->c->ci->target_class;
2777
+ target = mrb_vm_ci_target_class(mrb->c->ci);
2739
2778
  mrb_undef_method_id(mrb, target, syms[a]);
2740
2779
  NEXT;
2741
2780
  }
2742
2781
 
2743
2782
  CASE(OP_DEBUG, Z) {
2744
2783
  FETCH_BBB();
2745
- #ifdef MRB_ENABLE_DEBUG_HOOK
2784
+ #ifdef MRB_USE_DEBUG_HOOK
2746
2785
  mrb->debug_op_hook(mrb, irep, pc, regs);
2747
2786
  #else
2748
- #ifndef MRB_DISABLE_STDIO
2787
+ #ifndef MRB_NO_STDIO
2749
2788
  printf("OP_DEBUG %d %d %d\n", a, b, c);
2750
2789
  #else
2751
2790
  abort();
@@ -2755,56 +2794,32 @@ RETRY_TRY_BLOCK:
2755
2794
  }
2756
2795
 
2757
2796
  CASE(OP_ERR, B) {
2758
- mrb_value msg = mrb_str_dup(mrb, pool[a]);
2797
+ size_t len = pool[a].tt >> 2;
2759
2798
  mrb_value exc;
2760
2799
 
2761
- exc = mrb_exc_new_str(mrb, E_LOCALJUMP_ERROR, msg);
2762
- ERR_PC_SET(mrb);
2800
+ mrb_assert((pool[a].tt&IREP_TT_NFLAG)==0);
2801
+ exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, pool[a].u.str, len);
2763
2802
  mrb_exc_set(mrb, exc);
2764
2803
  goto L_RAISE;
2765
2804
  }
2766
2805
 
2767
- CASE(OP_EXT1, Z) {
2768
- insn = READ_B();
2769
- switch (insn) {
2770
- #define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _1(); goto L_OP_ ## insn ## _BODY;
2771
- #include "mruby/ops.h"
2772
- #undef OPCODE
2773
- }
2774
- pc--;
2775
- NEXT;
2776
- }
2777
- CASE(OP_EXT2, Z) {
2778
- insn = READ_B();
2779
- switch (insn) {
2780
- #define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _2(); goto L_OP_ ## insn ## _BODY;
2781
- #include "mruby/ops.h"
2782
- #undef OPCODE
2783
- }
2784
- pc--;
2785
- NEXT;
2786
- }
2787
- CASE(OP_EXT3, Z) {
2788
- uint8_t insn = READ_B();
2789
- switch (insn) {
2790
- #define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _3(); goto L_OP_ ## insn ## _BODY;
2791
- #include "mruby/ops.h"
2792
- #undef OPCODE
2793
- }
2794
- pc--;
2806
+ CASE(OP_SENDVK, BB) { /* not yet implemented */
2795
2807
  NEXT;
2796
2808
  }
2797
2809
 
2798
2810
  CASE(OP_STOP, Z) {
2799
2811
  /* stop VM */
2800
- L_STOP:
2801
- while (mrb->c->eidx > 0) {
2802
- ecall(mrb);
2812
+ CHECKPOINT_RESTORE(RBREAK_TAG_STOP) {
2813
+ /* do nothing */
2803
2814
  }
2804
- mrb->c->cibase->ridx = 0;
2805
- ERR_PC_CLR(mrb);
2815
+ CHECKPOINT_MAIN(RBREAK_TAG_STOP) {
2816
+ UNWIND_ENSURE(mrb, mrb->c->ci, pc, RBREAK_TAG_STOP, proc, mrb_nil_value());
2817
+ }
2818
+ CHECKPOINT_END(RBREAK_TAG_STOP);
2819
+ L_STOP:
2806
2820
  mrb->jmp = prev_jmp;
2807
2821
  if (mrb->exc) {
2822
+ mrb_assert(mrb->exc->tt == MRB_TT_EXCEPTION);
2808
2823
  return mrb_obj_value(mrb->exc);
2809
2824
  }
2810
2825
  return regs[irep->nlocals];
@@ -2814,14 +2829,19 @@ RETRY_TRY_BLOCK:
2814
2829
  #undef regs
2815
2830
  }
2816
2831
  MRB_CATCH(&c_jmp) {
2832
+ mrb_callinfo *ci = mrb->c->ci;
2833
+ while (ci > mrb->c->cibase && ci->acc == CI_ACC_DIRECT) {
2834
+ ci = cipop(mrb);
2835
+ }
2817
2836
  exc_catched = TRUE;
2837
+ pc = ci->pc;
2818
2838
  goto RETRY_TRY_BLOCK;
2819
2839
  }
2820
2840
  MRB_END_EXC(&c_jmp);
2821
2841
  }
2822
2842
 
2823
2843
  static mrb_value
2824
- mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
2844
+ mrb_run(mrb_state *mrb, const struct RProc *proc, mrb_value self)
2825
2845
  {
2826
2846
  if (mrb->c->ci->argc < 0) {
2827
2847
  return mrb_vm_run(mrb, proc, self, 3); /* receiver, args and block) */
@@ -2832,34 +2852,29 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
2832
2852
  }
2833
2853
 
2834
2854
  MRB_API mrb_value
2835
- mrb_top_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep)
2855
+ mrb_top_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep)
2836
2856
  {
2837
- mrb_callinfo *ci;
2838
2857
  mrb_value v;
2839
2858
 
2840
2859
  if (!mrb->c->cibase) {
2841
2860
  return mrb_vm_run(mrb, proc, self, stack_keep);
2842
2861
  }
2843
2862
  if (mrb->c->ci == mrb->c->cibase) {
2844
- mrb->c->ci->env = NULL;
2863
+ mrb_vm_ci_env_set(mrb->c->ci, NULL);
2845
2864
  return mrb_vm_run(mrb, proc, self, stack_keep);
2846
2865
  }
2847
- ci = cipush(mrb);
2848
- ci->stackent = mrb->c->stack;
2849
- ci->mid = 0;
2850
- ci->acc = CI_ACC_SKIP;
2851
- ci->target_class = mrb->object_class;
2866
+ cipush(mrb, 0, CI_ACC_SKIP, mrb->object_class, NULL, 0, 0);
2852
2867
  v = mrb_vm_run(mrb, proc, self, stack_keep);
2853
2868
 
2854
2869
  return v;
2855
2870
  }
2856
2871
 
2857
- #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
2858
- # if !defined(MRB_ENABLE_CXX_ABI)
2872
+ #if defined(MRB_USE_CXX_EXCEPTION) && defined(__cplusplus)
2873
+ # if !defined(MRB_USE_CXX_ABI)
2859
2874
  } /* end of extern "C" */
2860
2875
  # endif
2861
2876
  mrb_int mrb_jmpbuf::jmpbuf_id = 0;
2862
- # if !defined(MRB_ENABLE_CXX_ABI)
2877
+ # if !defined(MRB_USE_CXX_ABI)
2863
2878
  extern "C" {
2864
2879
  # endif
2865
2880
  #endif