script_core 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -2,15 +2,14 @@
2
2
  spec.license = 'MIT'
3
3
  spec.author = 'mruby developers'
4
4
  spec.summary = 'mruby compiler executable'
5
-
6
5
  spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler'
7
6
 
8
7
  exec = exefile("#{build.build_dir}/bin/mrbc")
9
- mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten
8
+ mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }
10
9
 
11
- file exec => mrbc_objs + [build.libmruby_core_static] do |t|
10
+ file exec => mrbc_objs << build.libmruby_core_static do |t|
12
11
  build.linker.run t.name, t.prerequisites
13
12
  end
14
13
 
15
- build.bins << 'mrbc' unless build.bins.find { |v| v == 'mrbc' }
14
+ build.bins << 'mrbc'
16
15
  end
@@ -1,7 +1,7 @@
1
1
  #include <mruby.h>
2
2
 
3
- #ifdef MRB_DISABLE_STDIO
4
- # error mruby-bin-mrbc conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-mrbc conflicts 'MRB_NO_STDIO' in your build configuration
5
5
  #endif
6
6
 
7
7
  #include <stdlib.h>
@@ -20,6 +20,7 @@ struct mrbc_args {
20
20
  const char *prog;
21
21
  const char *outfile;
22
22
  const char *initname;
23
+ mrb_bool dump_struct : 1;
23
24
  mrb_bool check_syntax : 1;
24
25
  mrb_bool verbose : 1;
25
26
  mrb_bool remove_lv : 1;
@@ -32,10 +33,11 @@ usage(const char *name)
32
33
  static const char *const usage_msg[] = {
33
34
  "switches:",
34
35
  "-c check syntax only",
35
- "-o<outfile> place the output into <outfile>",
36
+ "-o<outfile> place the output into <outfile>; required for multi-files",
36
37
  "-v print version number, then turn on verbose mode",
37
38
  "-g produce debugging information",
38
39
  "-B<symbol> binary <symbol> output in C language format",
40
+ "-S dump C struct (requires -B)",
39
41
  "--remove-lv remove local variables",
40
42
  "--verbose run at verbose mode",
41
43
  "--version print the version",
@@ -44,7 +46,7 @@ usage(const char *name)
44
46
  };
45
47
  const char *const *p = usage_msg;
46
48
 
47
- printf("Usage: %s [switches] programfile\n", name);
49
+ printf("Usage: %s [switches] programfile...\n", name);
48
50
  while (*p)
49
51
  printf(" %s\n", *p++);
50
52
  }
@@ -105,6 +107,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
105
107
  args->outfile = get_outfilename(mrb, argv[i] + 2, "");
106
108
  }
107
109
  break;
110
+ case 'S':
111
+ args->dump_struct = TRUE;
112
+ break;
108
113
  case 'B':
109
114
  if (argv[i][2] == '\0' && argv[i+1]) {
110
115
  i++;
@@ -238,13 +243,18 @@ static int
238
243
  dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, struct mrbc_args *args)
239
244
  {
240
245
  int n = MRB_DUMP_OK;
241
- mrb_irep *irep = proc->body.irep;
246
+ const mrb_irep *irep = proc->body.irep;
242
247
 
243
248
  if (args->remove_lv) {
244
- mrb_irep_remove_lv(mrb, irep);
249
+ mrb_irep_remove_lv(mrb, (mrb_irep*)irep);
245
250
  }
246
251
  if (args->initname) {
247
- n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
252
+ if (args->dump_struct) {
253
+ n = mrb_dump_irep_cstruct(mrb, irep, args->flags, wfp, args->initname);
254
+ }
255
+ else {
256
+ n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
257
+ }
248
258
  if (n == MRB_DUMP_INVALID_ARGUMENT) {
249
259
  fprintf(stderr, "%s: invalid C language symbol name\n", args->initname);
250
260
  }
@@ -261,7 +271,7 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st
261
271
  int
262
272
  main(int argc, char **argv)
263
273
  {
264
- mrb_state *mrb = mrb_open();
274
+ mrb_state *mrb = mrb_open_core(NULL, NULL);
265
275
  int n, result;
266
276
  struct mrbc_args args;
267
277
  FILE *wfp;
@@ -334,7 +344,7 @@ mrb_init_mrblib(mrb_state *mrb)
334
344
  {
335
345
  }
336
346
 
337
- #ifndef DISABLE_GEMS
347
+ #ifndef MRB_NO_GEMS
338
348
  void
339
349
  mrb_init_mrbgems(mrb_state *mrb)
340
350
  {
@@ -19,7 +19,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
19
19
  script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
20
20
  File.write script.path, 'p "ok"'
21
21
  system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
22
- o = `#{cmd('mruby')} -b #{bin.path}`.strip
22
+ o = `#{cmd('mruby')} #{bin.path}`.strip
23
23
  assert_equal '"ok"', o
24
24
  end
25
25
 
@@ -33,7 +33,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
33
33
 
34
34
  # .mrb file
35
35
  `#{cmd('mrbc')} -o "#{bin.path}" "#{script.path}"`
36
- assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} -b "#{bin.path}"`.chomp
36
+ assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} "#{bin.path}"`.chomp
37
37
 
38
38
  # one liner
39
39
  assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp
@@ -48,7 +48,7 @@ def assert_mruby(exp_out, exp_err, exp_success, args)
48
48
  script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
49
49
  File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]'
50
50
  system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
51
- assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} -b #{bin.path}`.chomp!
51
+ assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} #{bin.path}`.chomp!
52
52
  end
53
53
 
54
54
  assert '__END__', '8.6' do
@@ -129,7 +129,7 @@ def hoge
129
129
  end
130
130
 
131
131
  assert('mruby -v option') do
132
- ver_re = '\Amruby \d+\.\d+\.\d+ \(\d+-\d+-\d+\)\n'
132
+ ver_re = '\Amruby \d+\.\d+\.\d+.* \(\d+-\d+-\d+\)\n'
133
133
  assert_mruby(/#{ver_re}\z/, "", true, %w[-v])
134
134
  assert_mruby(/#{ver_re}^[^\n]*NODE.*\n:end\n\z/m, "", true, %w[-v -e p(:end)])
135
135
  end
@@ -162,3 +162,24 @@ def hoge
162
162
  code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end"
163
163
  assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code])
164
164
  end
165
+
166
+ assert('top level local variables are in file scope') do
167
+ arb, amrb = Tempfile.new('a.rb'), Tempfile.new('a.mrb')
168
+ brb, bmrb = Tempfile.new('b.rb'), Tempfile.new('b.mrb')
169
+ crb, cmrb = Tempfile.new('c.rb'), Tempfile.new('c.mrb')
170
+ drb, dmrb = Tempfile.new('d.rb'), Tempfile.new('d.mrb')
171
+
172
+ File.write arb.path, 'a = 1'
173
+ system "#{cmd('mrbc')} -g -o #{amrb.path} #{arb.path}"
174
+ File.write brb.path, 'p a'
175
+ system "#{cmd('mrbc')} -g -o #{bmrb.path} #{brb.path}"
176
+ assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-r", arb.path, brb.path])
177
+ assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-b", "-r", amrb.path, bmrb.path])
178
+
179
+ File.write crb.path, 'a, b, c = 1, 2, 3; A = -> { b = -2; [a, b, c] }'
180
+ system "#{cmd('mrbc')} -g -o #{cmrb.path} #{crb.path}"
181
+ File.write drb.path, 'a, b = 5, 6; p A.call; p a, b'
182
+ system "#{cmd('mrbc')} -g -o #{dmrb.path} #{drb.path}"
183
+ assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-r", crb.path, drb.path])
184
+ assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-b", "-r", cmrb.path, dmrb.path])
185
+ end
@@ -7,6 +7,6 @@
7
7
  spec.add_test_dependency('mruby-print', :core => 'mruby-print')
8
8
 
9
9
  if build.cxx_exception_enabled?
10
- build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c", "#{spec.build_dir}/tools/mruby/mruby.cxx")
10
+ build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c")
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  #include <mruby.h>
2
2
 
3
- #ifdef MRB_DISABLE_STDIO
4
- # error mruby-bin-mruby conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-mruby conflicts 'MRB_NO_STDIO' in your build configuration
5
5
  #endif
6
6
 
7
7
  #include <stdlib.h>
@@ -10,6 +10,12 @@
10
10
  #include <mruby/compile.h>
11
11
  #include <mruby/dump.h>
12
12
  #include <mruby/variable.h>
13
+ #include <mruby/proc.h>
14
+
15
+ #if defined(_WIN32) || defined(_WIN64)
16
+ # include <io.h> /* for setmode */
17
+ # include <fcntl.h>
18
+ #endif
13
19
 
14
20
  struct _args {
15
21
  FILE *rfp;
@@ -217,7 +223,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
217
223
  }
218
224
  else {
219
225
  args->rfp = strcmp(argv[0], "-") == 0 ?
220
- stdin : fopen(argv[0], args->mrbfile ? "rb" : "r");
226
+ stdin : fopen(argv[0], "rb");
221
227
  if (args->rfp == NULL) {
222
228
  fprintf(stderr, "%s: Cannot open program file: %s\n", opts->program, argv[0]);
223
229
  return EXIT_FAILURE;
@@ -227,6 +233,11 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
227
233
  argc--; argv++;
228
234
  }
229
235
  }
236
+ #if defined(_WIN32) || defined(_WIN64)
237
+ if (args->rfp == stdin) {
238
+ _setmode(_fileno(stdin), O_BINARY);
239
+ }
240
+ #endif
230
241
  args->argv = (char **)mrb_realloc(mrb, args->argv, sizeof(char*) * (argc + 1));
231
242
  memcpy(args->argv, argv, (argc+1) * sizeof(char*));
232
243
  args->argc = argc;
@@ -307,7 +318,8 @@ main(int argc, char **argv)
307
318
 
308
319
  /* Load libraries */
309
320
  for (i = 0; i < args.libc; i++) {
310
- FILE *lfp = fopen(args.libv[i], args.mrbfile ? "rb" : "r");
321
+ struct REnv *e;
322
+ FILE *lfp = fopen(args.libv[i], "rb");
311
323
  if (lfp == NULL) {
312
324
  fprintf(stderr, "%s: Cannot open library file: %s\n", *argv, args.libv[i]);
313
325
  mrbc_context_free(mrb, c);
@@ -318,9 +330,13 @@ main(int argc, char **argv)
318
330
  v = mrb_load_irep_file_cxt(mrb, lfp, c);
319
331
  }
320
332
  else {
321
- v = mrb_load_file_cxt(mrb, lfp, c);
333
+ v = mrb_load_detect_file_cxt(mrb, lfp, c);
322
334
  }
323
335
  fclose(lfp);
336
+ e = mrb_vm_ci_env(mrb->c->cibase);
337
+ mrb_vm_ci_env_set(mrb->c->cibase, NULL);
338
+ mrb_env_unshare(mrb, e);
339
+ mrbc_cleanup_local_variables(mrb, c);
324
340
  }
325
341
 
326
342
  /* Load program */
@@ -328,7 +344,7 @@ main(int argc, char **argv)
328
344
  v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
329
345
  }
330
346
  else if (args.rfp) {
331
- v = mrb_load_file_cxt(mrb, args.rfp, c);
347
+ v = mrb_load_detect_file_cxt(mrb, args.rfp, c);
332
348
  }
333
349
  else {
334
350
  char* utf8 = mrb_utf8_from_locale(args.cmdline, -1);
@@ -32,7 +32,7 @@
32
32
  o = `#{cmd('mruby-strip')} #{compiled1.path}`
33
33
  assert_equal 0, $?.exitstatus
34
34
  assert_equal "", o
35
- assert_equal `#{cmd('mruby')} #{script_file.path}`, `#{cmd('mruby')} -b #{compiled1.path}`
35
+ assert_equal `#{cmd('mruby')} #{script_file.path}`, `#{cmd('mruby')} #{compiled1.path}`
36
36
 
37
37
  o = `#{cmd('mruby-strip')} #{compiled1.path} #{compiled2.path}`
38
38
  assert_equal 0, $?.exitstatus
@@ -1,7 +1,7 @@
1
1
  #include <mruby.h>
2
2
 
3
- #ifdef MRB_DISABLE_STDIO
4
- # error mruby-bin-strip conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
3
+ #ifdef MRB_NO_STDIO
4
+ # error mruby-bin-strip conflicts 'MRB_NO_STDIO' in your build configuration
5
5
  #endif
6
6
 
7
7
  #include <stdlib.h>
@@ -0,0 +1,5 @@
1
+ MRuby::Gem::Specification.new('mruby-catch') do |spec|
2
+ spec.license = 'MIT'
3
+ spec.author = 'mruby developers'
4
+ spec.summary = 'Catch / Throw non-local Jump'
5
+ end
@@ -0,0 +1,27 @@
1
+ class ThrowCatchJump < Exception
2
+ def initialize(tag, val)
3
+ @tag = tag
4
+ @val = val
5
+ super("uncaught throw :#{tag}")
6
+ end
7
+ def _tag
8
+ @tag
9
+ end
10
+ def _val
11
+ @val
12
+ end
13
+ end
14
+
15
+ module Kernel
16
+ def catch(tag, &block)
17
+ block.call(tag)
18
+ rescue ThrowCatchJump => e
19
+ unless e._tag == tag
20
+ raise e
21
+ end
22
+ return e._val
23
+ end
24
+ def throw(tag, val=nil)
25
+ raise ThrowCatchJump.new(tag, val)
26
+ end
27
+ end
@@ -1,6 +1,7 @@
1
1
  #include "mruby.h"
2
2
  #include "mruby/class.h"
3
3
  #include "mruby/string.h"
4
+ #include "mruby/proc.h"
4
5
 
5
6
  static mrb_value
6
7
  mrb_mod_name(mrb_state *mrb, mrb_value self)
@@ -51,7 +52,7 @@ mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
51
52
  if (mrb->c->ci->acc < 0) {
52
53
  return mrb_yield_with_class(mrb, blk, argc, argv, self, c);
53
54
  }
54
- mrb->c->ci->target_class = c;
55
+ mrb_vm_ci_target_class_set(mrb->c->ci, c);
55
56
  return mrb_yield_cont(mrb, blk, self, argc, argv);
56
57
  }
57
58
 
@@ -5,16 +5,17 @@
5
5
  */
6
6
 
7
7
  #include <ctype.h>
8
- #include <limits.h>
9
8
  #include <stdlib.h>
10
9
  #include <string.h>
11
10
  #include <math.h>
12
11
  #include <mruby.h>
13
12
  #include <mruby/compile.h>
14
13
  #include <mruby/proc.h>
14
+ #include <mruby/dump.h>
15
15
  #include <mruby/numeric.h>
16
16
  #include <mruby/string.h>
17
17
  #include <mruby/debug.h>
18
+ #include <mruby/presym.h>
18
19
  #include "node.h"
19
20
  #include <mruby/opcode.h>
20
21
  #include <mruby/re.h>
@@ -39,8 +40,8 @@ enum looptype {
39
40
 
40
41
  struct loopinfo {
41
42
  enum looptype type;
42
- int pc0, pc1, pc2, pc3, acc;
43
- int ensure_level;
43
+ uint32_t pc0, pc1, pc2, pc3;
44
+ int acc;
44
45
  struct loopinfo *prev;
45
46
  };
46
47
 
@@ -54,14 +55,13 @@ typedef struct scope {
54
55
  node *lv;
55
56
 
56
57
  uint16_t sp;
57
- uint16_t pc;
58
- uint16_t lastpc;
59
- uint16_t lastlabel;
58
+ uint32_t pc;
59
+ uint32_t lastpc;
60
+ uint32_t lastlabel;
60
61
  int ainfo:15;
61
62
  mrb_bool mscope:1;
62
63
 
63
64
  struct loopinfo *loop;
64
- int ensure_level;
65
65
  mrb_sym filename_sym;
66
66
  uint16_t lineno;
67
67
 
@@ -70,6 +70,10 @@ typedef struct scope {
70
70
  uint32_t icapa;
71
71
 
72
72
  mrb_irep *irep;
73
+ mrb_pool_value *pool;
74
+ mrb_sym *syms;
75
+ mrb_irep **reps;
76
+ struct mrb_irep_catch_handler *catch_table;
73
77
  uint32_t pcapa, scapa, rcapa;
74
78
 
75
79
  uint16_t nlocals;
@@ -89,6 +93,15 @@ static struct loopinfo *loop_push(codegen_scope *s, enum looptype t);
89
93
  static void loop_break(codegen_scope *s, node *tree);
90
94
  static void loop_pop(codegen_scope *s, int val);
91
95
 
96
+ /*
97
+ * The search for catch handlers starts at the end of the table in mrb_vm_run().
98
+ * Therefore, the next handler to be added must meet one of the following conditions.
99
+ * - Larger start position
100
+ * - Same start position but smaller end position
101
+ */
102
+ static int catch_handler_new(codegen_scope *s);
103
+ static void catch_handler_set(codegen_scope *s, int ent, enum mrb_catch_type type, uint32_t begin, uint32_t end, uint32_t target);
104
+
92
105
  static void gen_assignment(codegen_scope *s, node *tree, int sp, int val);
93
106
  static void gen_vmassignment(codegen_scope *s, node *tree, int rhs, int val);
94
107
 
@@ -101,12 +114,31 @@ codegen_error(codegen_scope *s, const char *message)
101
114
  if (!s) return;
102
115
  while (s->prev) {
103
116
  codegen_scope *tmp = s->prev;
104
- mrb_free(s->mrb, s->iseq);
105
- mrb_free(s->mrb, s->lines);
117
+ if (s->irep) {
118
+ mrb_free(s->mrb, s->iseq);
119
+ for (int i=0; i<s->irep->plen; i++) {
120
+ mrb_pool_value *pv = &s->pool[i];
121
+ if ((pv->tt & 0x3) == IREP_TT_STR) {
122
+ mrb_free(s->mrb, (void*)pv->u.str);
123
+ }
124
+ }
125
+ mrb_free(s->mrb, s->pool);
126
+ mrb_free(s->mrb, s->syms);
127
+ mrb_free(s->mrb, s->catch_table);
128
+ if (s->reps) {
129
+ /* copied from mrb_irep_free() in state.c */
130
+ for (int i=0; i<s->irep->rlen; i++) {
131
+ if (s->reps[i])
132
+ mrb_irep_decref(s->mrb, (mrb_irep*)s->reps[i]);
133
+ }
134
+ mrb_free(s->mrb, s->reps);
135
+ }
136
+ mrb_free(s->mrb, s->lines);
137
+ }
106
138
  mrb_pool_close(s->mpool);
107
139
  s = tmp;
108
140
  }
109
- #ifndef MRB_DISABLE_STDIO
141
+ #ifndef MRB_NO_STDIO
110
142
  if (s->filename_sym && s->lineno) {
111
143
  const char *filename = mrb_sym_name_len(s->mrb, s->filename_sym, NULL);
112
144
  fprintf(stderr, "codegen error:%s:%d: %s\n", filename, s->lineno, message);
@@ -145,13 +177,15 @@ new_label(codegen_scope *s)
145
177
  static void
146
178
  emit_B(codegen_scope *s, uint32_t pc, uint8_t i)
147
179
  {
148
- if (pc >= MAXARG_S || s->icapa >= MAXARG_S) {
149
- codegen_error(s, "too big code block");
150
- }
151
180
  if (pc >= s->icapa) {
152
- s->icapa *= 2;
153
- if (s->icapa > MAXARG_S) {
154
- s->icapa = MAXARG_S;
181
+ if (pc == UINT32_MAX) {
182
+ codegen_error(s, "too big code block");
183
+ }
184
+ if (pc >= UINT32_MAX / 2) {
185
+ pc = UINT32_MAX;
186
+ }
187
+ else {
188
+ s->icapa *= 2;
155
189
  }
156
190
  s->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->icapa);
157
191
  if (s->lines) {
@@ -203,9 +237,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a)
203
237
  {
204
238
  s->lastpc = s->pc;
205
239
  if (a > 0xff) {
206
- gen_B(s, OP_EXT1);
207
- gen_B(s, i);
208
- gen_S(s, a);
240
+ codegen_error(s, "too big operand");
209
241
  }
210
242
  else {
211
243
  gen_B(s, i);
@@ -217,24 +249,30 @@ static void
217
249
  genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
218
250
  {
219
251
  s->lastpc = s->pc;
220
- if (a > 0xff && b > 0xff) {
221
- gen_B(s, OP_EXT3);
222
- gen_B(s, i);
223
- gen_S(s, a);
224
- gen_S(s, b);
252
+ if (a > 0xff || b > 0xff) {
253
+ codegen_error(s, "too big operand");
225
254
  }
226
- else if (b > 0xff) {
227
- gen_B(s, OP_EXT2);
255
+ else {
228
256
  gen_B(s, i);
229
257
  gen_B(s, (uint8_t)a);
230
- gen_S(s, b);
231
- }
232
- else if (a > 0xff) {
233
- gen_B(s, OP_EXT1);
234
- gen_B(s, i);
235
- gen_S(s, a);
236
258
  gen_B(s, (uint8_t)b);
237
259
  }
260
+ }
261
+
262
+ /* similar to `genop_2` but generate `genop_2S` with `i+1` */
263
+ /* works for OP_LOADL, OP_LOADSYM, OP_STRING */
264
+ static void
265
+ genop_bs(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
266
+ {
267
+ s->lastpc = s->pc;
268
+ if (a > 0xff || b > 0xffff) {
269
+ codegen_error(s, "too big operand");
270
+ }
271
+ if (b > 0xff) {
272
+ gen_B(s, i+1);
273
+ gen_B(s, (uint8_t)a);
274
+ gen_S(s, b);
275
+ }
238
276
  else {
239
277
  gen_B(s, i);
240
278
  gen_B(s, (uint8_t)a);
@@ -256,6 +294,14 @@ genop_2S(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
256
294
  gen_S(s, b);
257
295
  }
258
296
 
297
+ static void
298
+ genop_2SS(codegen_scope *s, mrb_code i, uint16_t a, uint32_t b)
299
+ {
300
+ genop_1(s, i, a);
301
+ gen_S(s, b>>16);
302
+ gen_S(s, b&0xffff);
303
+ }
304
+
259
305
  static void
260
306
  genop_W(codegen_scope *s, mrb_code i, uint32_t a)
261
307
  {
@@ -288,39 +334,13 @@ mrb_decode_insn(const mrb_code *pc)
288
334
  mrb_code insn = READ_B();
289
335
  uint16_t a = 0;
290
336
  uint16_t b = 0;
291
- uint8_t c = 0;
337
+ uint16_t c = 0;
292
338
 
293
339
  switch (insn) {
294
340
  #define FETCH_Z() /* empty */
295
341
  #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break;
296
342
  #include "mruby/ops.h"
297
343
  #undef OPCODE
298
- }
299
- switch (insn) {
300
- case OP_EXT1:
301
- insn = READ_B();
302
- switch (insn) {
303
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break;
304
- #include "mruby/ops.h"
305
- #undef OPCODE
306
- }
307
- break;
308
- case OP_EXT2:
309
- insn = READ_B();
310
- switch (insn) {
311
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break;
312
- #include "mruby/ops.h"
313
- #undef OPCODE
314
- }
315
- break;
316
- case OP_EXT3:
317
- insn = READ_B();
318
- switch (insn) {
319
- #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break;
320
- #include "mruby/ops.h"
321
- #undef OPCODE
322
- }
323
- break;
324
344
  default:
325
345
  break;
326
346
  }
@@ -349,22 +369,44 @@ no_peephole(codegen_scope *s)
349
369
  return no_optimize(s) || s->lastlabel == s->pc || s->pc == 0 || s->pc == s->lastpc;
350
370
  }
351
371
 
352
- static uint16_t
353
- genjmp(codegen_scope *s, mrb_code i, uint16_t pc)
372
+ #define JMPLINK_START UINT32_MAX
373
+
374
+ static void
375
+ gen_jmpdst(codegen_scope *s, uint32_t pc)
376
+ {
377
+
378
+ if (pc == JMPLINK_START) {
379
+ gen_S(s, 0);
380
+ }
381
+ else {
382
+ uint32_t pos2 = s->pc+2;
383
+ int32_t off = pc - pos2;
384
+
385
+ if (off > INT16_MAX || INT16_MIN > off) {
386
+ codegen_error(s, "too big jump offset");
387
+ }
388
+ gen_S(s, (uint16_t)off);
389
+ }
390
+ }
391
+
392
+ static uint32_t
393
+ genjmp(codegen_scope *s, mrb_code i, uint32_t pc)
354
394
  {
355
- uint16_t pos;
395
+ uint32_t pos;
356
396
 
357
397
  s->lastpc = s->pc;
358
398
  gen_B(s, i);
359
399
  pos = s->pc;
360
- gen_S(s, pc);
400
+ gen_jmpdst(s, pc);
361
401
  return pos;
362
402
  }
363
403
 
364
- static uint16_t
365
- genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
404
+ #define genjmp_0(s,i) genjmp(s,i,JMPLINK_START)
405
+
406
+ static uint32_t
407
+ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, uint32_t pc, int val)
366
408
  {
367
- uint16_t pos;
409
+ uint32_t pos;
368
410
 
369
411
  if (!no_peephole(s) && !val) {
370
412
  struct mrb_insn_data data = mrb_last_insn(s);
@@ -377,21 +419,20 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
377
419
 
378
420
  s->lastpc = s->pc;
379
421
  if (a > 0xff) {
380
- gen_B(s, OP_EXT1);
381
- gen_B(s, i);
382
- gen_S(s, a);
383
- pos = s->pc;
384
- gen_S(s, pc);
422
+ codegen_error(s, "too big operand");
423
+ pos = 0;
385
424
  }
386
425
  else {
387
426
  gen_B(s, i);
388
427
  gen_B(s, (uint8_t)a);
389
428
  pos = s->pc;
390
- gen_S(s, pc);
429
+ gen_jmpdst(s, pc);
391
430
  }
392
431
  return pos;
393
432
  }
394
433
 
434
+ #define genjmp2_0(s,i,a,val) genjmp2(s,i,a,JMPLINK_START,val)
435
+
395
436
  static void
396
437
  gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
397
438
  {
@@ -417,10 +458,13 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
417
458
  s->pc = s->lastpc;
418
459
  genop_1(s, data.insn, dst);
419
460
  break;
420
- case OP_LOADI: case OP_LOADINEG: case OP_LOADL: case OP_LOADSYM:
461
+ case OP_LOADI: case OP_LOADINEG:
462
+ case OP_LOADL: case OP_LOADSYM:
463
+ case OP_LOADL16: case OP_LOADSYM16:
421
464
  case OP_GETGV: case OP_GETSV: case OP_GETIV: case OP_GETCV:
422
- case OP_GETCONST: case OP_STRING:
465
+ case OP_GETCONST: case OP_STRING: case OP_STRING16:
423
466
  case OP_LAMBDA: case OP_BLOCK: case OP_METHOD: case OP_BLKPUSH:
467
+ case OP_LAMBDA16: case OP_BLOCK16: case OP_METHOD16:
424
468
  if (nopeep || data.a != src || data.a < s->nlocals) goto normal;
425
469
  s->pc = s->lastpc;
426
470
  genop_2(s, data.insn, dst, data.b);
@@ -488,21 +532,31 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
488
532
  }
489
533
  }
490
534
 
491
- static int
492
- dispatch(codegen_scope *s, uint16_t pos0)
535
+ static uint32_t
536
+ dispatch(codegen_scope *s, uint32_t pos0)
493
537
  {
494
- uint16_t newpos;
538
+ int32_t pos1;
539
+ int32_t offset;
540
+ int16_t newpos;
541
+
542
+ if (pos0 == JMPLINK_START) return 0;
495
543
 
544
+ pos1 = pos0 + 2;
545
+ offset = s->pc - pos1;
546
+ if (offset > INT16_MAX) {
547
+ codegen_error(s, "too big jmp offset");
548
+ }
496
549
  s->lastlabel = s->pc;
497
- newpos = PEEK_S(s->iseq+pos0);
498
- emit_S(s, pos0, s->pc);
499
- return newpos;
550
+ newpos = (int16_t)PEEK_S(s->iseq+pos0);
551
+ emit_S(s, pos0, (uint16_t)offset);
552
+ if (newpos == 0) return 0;
553
+ return pos1+newpos;
500
554
  }
501
555
 
502
556
  static void
503
- dispatch_linked(codegen_scope *s, uint16_t pos)
557
+ dispatch_linked(codegen_scope *s, uint32_t pos)
504
558
  {
505
- if (pos==0) return;
559
+ if (pos==JMPLINK_START) return;
506
560
  for (;;) {
507
561
  pos = dispatch(s, pos);
508
562
  if (pos==0) break;
@@ -539,37 +593,46 @@ static inline int
539
593
  new_lit(codegen_scope *s, mrb_value val)
540
594
  {
541
595
  int i;
542
- mrb_value *pv;
596
+ mrb_pool_value *pv;
543
597
 
544
598
  switch (mrb_type(val)) {
545
599
  case MRB_TT_STRING:
546
600
  for (i=0; i<s->irep->plen; i++) {
547
601
  mrb_int len;
548
- pv = &s->irep->pool[i];
549
-
550
- if (!mrb_string_p(*pv)) continue;
551
- if ((len = RSTRING_LEN(*pv)) != RSTRING_LEN(val)) continue;
552
- if (memcmp(RSTRING_PTR(*pv), RSTRING_PTR(val), len) == 0)
602
+ pv = &s->pool[i];
603
+ if (pv->tt & IREP_TT_NFLAG) continue;
604
+ len = pv->tt>>2;
605
+ if (RSTRING_LEN(val) != len) continue;
606
+ if (memcmp(pv->u.str, RSTRING_PTR(val), len) == 0)
553
607
  return i;
554
608
  }
555
609
  break;
556
- #ifndef MRB_WITHOUT_FLOAT
610
+ #ifndef MRB_NO_FLOAT
557
611
  case MRB_TT_FLOAT:
558
612
  for (i=0; i<s->irep->plen; i++) {
559
613
  mrb_float f1, f2;
560
- pv = &s->irep->pool[i];
561
- if (!mrb_float_p(*pv)) continue;
562
- f1 = mrb_float(*pv);
614
+ pv = &s->pool[i];
615
+ if (pv->tt != IREP_TT_FLOAT) continue;
616
+ pv = &s->pool[i];
617
+ f1 = pv->u.f;
563
618
  f2 = mrb_float(val);
564
619
  if (f1 == f2 && !signbit(f1) == !signbit(f2)) return i;
565
620
  }
566
621
  break;
567
622
  #endif
568
- case MRB_TT_FIXNUM:
623
+ case MRB_TT_INTEGER:
569
624
  for (i=0; i<s->irep->plen; i++) {
570
- pv = &s->irep->pool[i];
571
- if (!mrb_fixnum_p(*pv)) continue;
572
- if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i;
625
+ mrb_int v = mrb_integer(val);
626
+ pv = &s->pool[i];
627
+ if (pv->tt == IREP_TT_INT32) {
628
+ if (v == pv->u.i32) return i;
629
+ }
630
+ #ifdef MRB_64BIT
631
+ else if (pv->tt == IREP_TT_INT64) {
632
+ if (v == pv->u.i64) return i;
633
+ }
634
+ continue;
635
+ #endif
573
636
  }
574
637
  break;
575
638
  default:
@@ -579,26 +642,43 @@ new_lit(codegen_scope *s, mrb_value val)
579
642
 
580
643
  if (s->irep->plen == s->pcapa) {
581
644
  s->pcapa *= 2;
582
- s->irep->pool = (mrb_value *)codegen_realloc(s, s->irep->pool, sizeof(mrb_value)*s->pcapa);
645
+ s->pool = (mrb_pool_value*)codegen_realloc(s, s->pool, sizeof(mrb_pool_value)*s->pcapa);
583
646
  }
584
647
 
585
- pv = &s->irep->pool[s->irep->plen];
648
+ pv = &s->pool[s->irep->plen];
586
649
  i = s->irep->plen++;
587
650
 
588
651
  switch (mrb_type(val)) {
589
652
  case MRB_TT_STRING:
590
- *pv = mrb_str_pool(s->mrb, RSTRING_PTR(val), RSTRING_LEN(val), RSTR_NOFREE_P(RSTRING(val)));
653
+ if (RSTR_NOFREE_P(RSTRING(val))) {
654
+ pv->tt = (uint32_t)(RSTRING_LEN(val)<<2) | IREP_TT_SSTR;
655
+ pv->u.str = RSTRING_PTR(val);
656
+ }
657
+ else {
658
+ char *p;
659
+ mrb_int len = RSTRING_LEN(val);
660
+ pv->tt = (uint32_t)(len<<2) | IREP_TT_STR;
661
+ p = (char*)codegen_realloc(s, NULL, len+1);
662
+ memcpy(p, RSTRING_PTR(val), len);
663
+ p[len] = '\0';
664
+ pv->u.str = p;
665
+ }
591
666
  break;
592
667
 
593
- #ifndef MRB_WITHOUT_FLOAT
668
+ #ifndef MRB_NO_FLOAT
594
669
  case MRB_TT_FLOAT:
595
- #ifdef MRB_WORD_BOXING
596
- *pv = mrb_float_pool(s->mrb, mrb_float(val));
670
+ pv->tt = IREP_TT_FLOAT;
671
+ pv->u.f = mrb_float(val);
597
672
  break;
598
673
  #endif
674
+ case MRB_TT_INTEGER:
675
+ #ifdef MRB_INT64
676
+ pv->tt = IREP_TT_INT64;
677
+ pv->u.i64 = mrb_integer(val);
678
+ #else
679
+ pv->tt = IREP_TT_INT32;
680
+ pv->u.i32 = mrb_integer(val);
599
681
  #endif
600
- case MRB_TT_FIXNUM:
601
- *pv = val;
602
682
  break;
603
683
 
604
684
  default:
@@ -608,9 +688,6 @@ new_lit(codegen_scope *s, mrb_value val)
608
688
  return i;
609
689
  }
610
690
 
611
- /* maximum symbol numbers */
612
- #define MAXSYMLEN 0x10000
613
-
614
691
  static int
615
692
  new_sym(codegen_scope *s, mrb_sym sym)
616
693
  {
@@ -620,13 +697,16 @@ new_sym(codegen_scope *s, mrb_sym sym)
620
697
 
621
698
  len = s->irep->slen;
622
699
  for (i=0; i<len; i++) {
623
- if (s->irep->syms[i] == sym) return i;
700
+ if (s->syms[i] == sym) return i;
624
701
  }
625
702
  if (s->irep->slen >= s->scapa) {
626
703
  s->scapa *= 2;
627
- s->irep->syms = (mrb_sym*)codegen_realloc(s, s->irep->syms, sizeof(mrb_sym)*s->scapa);
704
+ if (s->scapa > 0xffff) {
705
+ codegen_error(s, "too many symbols");
706
+ }
707
+ s->syms = (mrb_sym*)codegen_realloc(s, s->syms, sizeof(mrb_sym)*s->scapa);
628
708
  }
629
- s->irep->syms[s->irep->slen] = sym;
709
+ s->syms[s->irep->slen] = sym;
630
710
  return s->irep->slen++;
631
711
  }
632
712
 
@@ -665,7 +745,7 @@ lv_idx(codegen_scope *s, mrb_sym id)
665
745
  static int
666
746
  search_upvar(codegen_scope *s, mrb_sym id, int *idx)
667
747
  {
668
- struct RProc *u;
748
+ const struct RProc *u;
669
749
  int lv = 0;
670
750
  codegen_scope *up = s->prev;
671
751
 
@@ -681,12 +761,14 @@ search_upvar(codegen_scope *s, mrb_sym id, int *idx)
681
761
  if (lv < 1) lv = 1;
682
762
  u = s->parser->upper;
683
763
  while (u && !MRB_PROC_CFUNC_P(u)) {
684
- struct mrb_irep *ir = u->body.irep;
764
+ const struct mrb_irep *ir = u->body.irep;
685
765
  uint_fast16_t n = ir->nlocals;
686
- const struct mrb_locals *v = ir->lv;
687
- for (; n > 1; n --, v ++) {
688
- if (v->name == id) {
689
- *idx = v->r;
766
+ int i;
767
+
768
+ const mrb_sym *v = ir->lv;
769
+ for (i=1; n > 1; n--, v++, i++) {
770
+ if (*v == id) {
771
+ *idx = i;
690
772
  return lv - 1;
691
773
  }
692
774
  }
@@ -737,7 +819,7 @@ for_body(codegen_scope *s, node *tree)
737
819
  genop_2(s, OP_BLOCK, cursp(), s->irep->rlen-1);
738
820
  push();pop(); /* space for a block */
739
821
  pop();
740
- idx = new_sym(s, mrb_intern_lit(s->mrb, "each"));
822
+ idx = new_sym(s, MRB_SYM_2(s->mrb, each));
741
823
  genop_3(s, OP_SENDB, cursp(), idx, 0);
742
824
  }
743
825
 
@@ -774,7 +856,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
774
856
  oa = node_len(tree->car->cdr->car);
775
857
  /* rest argument? */
776
858
  ra = tree->car->cdr->cdr->car ? 1 : 0;
777
- /* mandatory arugments after rest argument */
859
+ /* mandatory arguments after rest argument */
778
860
  pa = node_len(tree->car->cdr->cdr->cdr->car);
779
861
  pargs = tree->car->cdr->cdr->cdr->car;
780
862
  /* keyword arguments */
@@ -802,10 +884,10 @@ lambda_body(codegen_scope *s, node *tree, int blk)
802
884
  pos = new_label(s);
803
885
  for (i=0; i<oa; i++) {
804
886
  new_label(s);
805
- genjmp(s, OP_JMP, 0);
887
+ genjmp_0(s, OP_JMP);
806
888
  }
807
889
  if (oa > 0) {
808
- genjmp(s, OP_JMP, 0);
890
+ genjmp_0(s, OP_JMP);
809
891
  }
810
892
  opt = tree->car->cdr->car;
811
893
  i = 0;
@@ -852,7 +934,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
852
934
  if (def_arg) {
853
935
  int idx;
854
936
  genop_2(s, OP_KEY_P, lv_idx(s, kwd_sym), new_sym(s, kwd_sym));
855
- jmpif_key_p = genjmp2(s, OP_JMPIF, lv_idx(s, kwd_sym), 0, 0);
937
+ jmpif_key_p = genjmp2_0(s, OP_JMPIF, lv_idx(s, kwd_sym), NOVAL);
856
938
  codegen(s, def_arg, VAL);
857
939
  pop();
858
940
  idx = lv_idx(s, kwd_sym);
@@ -863,7 +945,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
863
945
  int lv = search_upvar(s, kwd_sym, &idx);
864
946
  genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
865
947
  }
866
- jmp_def_set = genjmp(s, OP_JMP, 0);
948
+ jmp_def_set = genjmp_0(s, OP_JMP);
867
949
  dispatch(s, jmpif_key_p);
868
950
  }
869
951
  genop_2(s, OP_KARG, lv_idx(s, kwd_sym), new_sym(s, kwd_sym));
@@ -1044,7 +1126,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
1044
1126
  if (safe) {
1045
1127
  int recv = cursp()-1;
1046
1128
  gen_move(s, cursp(), recv, 1);
1047
- skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1129
+ skip = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1048
1130
  }
1049
1131
  tree = tree->cdr->cdr->car;
1050
1132
  if (tree) {
@@ -1196,7 +1278,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
1196
1278
  break;
1197
1279
 
1198
1280
  default:
1199
- #ifndef MRB_DISABLE_STDIO
1281
+ #ifndef MRB_NO_STDIO
1200
1282
  fprintf(stderr, "unknown lhs %d\n", type);
1201
1283
  #endif
1202
1284
  break;
@@ -1325,34 +1407,6 @@ raise_error(codegen_scope *s, const char *msg)
1325
1407
  genop_1(s, OP_ERR, idx);
1326
1408
  }
1327
1409
 
1328
- #ifndef MRB_WITHOUT_FLOAT
1329
- static double
1330
- readint_float(codegen_scope *s, const char *p, int base)
1331
- {
1332
- const char *e = p + strlen(p);
1333
- double f = 0;
1334
- int n;
1335
-
1336
- if (*p == '+') p++;
1337
- while (p < e) {
1338
- char c = *p;
1339
- c = tolower((unsigned char)c);
1340
- for (n=0; n<base; n++) {
1341
- if (mrb_digitmap[n] == c) {
1342
- f *= base;
1343
- f += n;
1344
- break;
1345
- }
1346
- }
1347
- if (n == base) {
1348
- codegen_error(s, "malformed readint input");
1349
- }
1350
- p++;
1351
- }
1352
- return f;
1353
- }
1354
- #endif
1355
-
1356
1410
  static mrb_int
1357
1411
  readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_bool *overflow)
1358
1412
  {
@@ -1456,21 +1510,25 @@ codegen(codegen_scope *s, node *tree, int val)
1456
1510
 
1457
1511
  case NODE_RESCUE:
1458
1512
  {
1459
- int noexc, exend, pos1, pos2, tmp;
1513
+ int noexc;
1514
+ uint32_t exend, pos1, pos2, tmp;
1460
1515
  struct loopinfo *lp;
1516
+ int catch_entry, begin, end;
1461
1517
 
1462
1518
  if (tree->car == NULL) goto exit;
1463
1519
  lp = loop_push(s, LOOP_BEGIN);
1464
1520
  lp->pc0 = new_label(s);
1465
- lp->pc1 = genjmp(s, OP_ONERR, 0);
1521
+ catch_entry = catch_handler_new(s);
1522
+ begin = s->pc;
1466
1523
  codegen(s, tree->car, VAL);
1467
1524
  pop();
1468
1525
  lp->type = LOOP_RESCUE;
1469
- noexc = genjmp(s, OP_JMP, 0);
1470
- dispatch(s, lp->pc1);
1526
+ end = s->pc;
1527
+ noexc = genjmp_0(s, OP_JMP);
1528
+ catch_handler_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc);
1471
1529
  tree = tree->cdr;
1472
- exend = 0;
1473
- pos1 = 0;
1530
+ exend = JMPLINK_START;
1531
+ pos1 = JMPLINK_START;
1474
1532
  if (tree->car) {
1475
1533
  node *n2 = tree->car;
1476
1534
  int exc = cursp();
@@ -1481,22 +1539,22 @@ codegen(codegen_scope *s, node *tree, int val)
1481
1539
  node *n3 = n2->car;
1482
1540
  node *n4 = n3->car;
1483
1541
 
1484
- if (pos1) dispatch(s, pos1);
1485
- pos2 = 0;
1542
+ dispatch(s, pos1);
1543
+ pos2 = JMPLINK_START;
1486
1544
  do {
1487
1545
  if (n4 && n4->car && nint(n4->car->car) == NODE_SPLAT) {
1488
1546
  codegen(s, n4->car, VAL);
1489
1547
  gen_move(s, cursp(), exc, 0);
1490
1548
  push_n(2); pop_n(2); /* space for one arg and a block */
1491
1549
  pop();
1492
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1);
1550
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, __case_eqq)), 1);
1493
1551
  }
1494
1552
  else {
1495
1553
  if (n4) {
1496
1554
  codegen(s, n4->car, VAL);
1497
1555
  }
1498
1556
  else {
1499
- genop_2(s, OP_GETCONST, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "StandardError")));
1557
+ genop_2(s, OP_GETCONST, cursp(), new_sym(s, MRB_SYM_2(s->mrb, StandardError)));
1500
1558
  push();
1501
1559
  }
1502
1560
  pop();
@@ -1508,7 +1566,7 @@ codegen(codegen_scope *s, node *tree, int val)
1508
1566
  n4 = n4->cdr;
1509
1567
  }
1510
1568
  } while (n4);
1511
- pos1 = genjmp(s, OP_JMP, 0);
1569
+ pos1 = genjmp_0(s, OP_JMP);
1512
1570
  dispatch_linked(s, pos2);
1513
1571
 
1514
1572
  pop();
@@ -1524,15 +1582,14 @@ codegen(codegen_scope *s, node *tree, int val)
1524
1582
  n2 = n2->cdr;
1525
1583
  push();
1526
1584
  }
1527
- if (pos1) {
1585
+ if (pos1 != JMPLINK_START) {
1528
1586
  dispatch(s, pos1);
1529
- genop_1(s, OP_RAISE, exc);
1587
+ genop_1(s, OP_RAISEIF, exc);
1530
1588
  }
1531
1589
  }
1532
1590
  pop();
1533
1591
  tree = tree->cdr;
1534
1592
  dispatch(s, noexc);
1535
- genop_1(s, OP_POPERR, 1);
1536
1593
  if (tree->car) {
1537
1594
  codegen(s, tree->car, val);
1538
1595
  }
@@ -1548,14 +1605,22 @@ codegen(codegen_scope *s, node *tree, int val)
1548
1605
  if (!tree->cdr || !tree->cdr->cdr ||
1549
1606
  (nint(tree->cdr->cdr->car) == NODE_BEGIN &&
1550
1607
  tree->cdr->cdr->cdr)) {
1608
+ int catch_entry, begin, end, target;
1551
1609
  int idx;
1552
1610
 
1553
- s->ensure_level++;
1554
- idx = scope_body(s, tree->cdr, NOVAL);
1555
- genop_1(s, OP_EPUSH, idx);
1611
+ catch_entry = catch_handler_new(s);
1612
+ begin = s->pc;
1556
1613
  codegen(s, tree->car, val);
1557
- s->ensure_level--;
1558
- genop_1(s, OP_EPOP, 1);
1614
+ end = target = s->pc;
1615
+ push();
1616
+ idx = cursp();
1617
+ genop_1(s, OP_EXCEPT, idx);
1618
+ push();
1619
+ codegen(s, tree->cdr->cdr, NOVAL);
1620
+ pop();
1621
+ genop_1(s, OP_RAISEIF, idx);
1622
+ pop();
1623
+ catch_handler_set(s, catch_entry, MRB_CATCH_ENSURE, begin, end, target);
1559
1624
  }
1560
1625
  else { /* empty ensure ignored */
1561
1626
  codegen(s, tree->car, val);
@@ -1566,7 +1631,7 @@ codegen(codegen_scope *s, node *tree, int val)
1566
1631
  if (val) {
1567
1632
  int idx = lambda_body(s, tree, 1);
1568
1633
 
1569
- genop_2(s, OP_LAMBDA, cursp(), idx);
1634
+ genop_bs(s, OP_LAMBDA, cursp(), idx);
1570
1635
  push();
1571
1636
  }
1572
1637
  break;
@@ -1575,7 +1640,7 @@ codegen(codegen_scope *s, node *tree, int val)
1575
1640
  if (val) {
1576
1641
  int idx = lambda_body(s, tree, 1);
1577
1642
 
1578
- genop_2(s, OP_BLOCK, cursp(), idx);
1643
+ genop_bs(s, OP_BLOCK, cursp(), idx);
1579
1644
  push();
1580
1645
  }
1581
1646
  break;
@@ -1603,7 +1668,7 @@ codegen(codegen_scope *s, node *tree, int val)
1603
1668
  {
1604
1669
  node *n = tree->car->cdr;
1605
1670
  mrb_sym mid = nsym(n->cdr->car);
1606
- mrb_sym mnil = mrb_intern_lit(s->mrb, "nil?");
1671
+ mrb_sym mnil = MRB_SYM_Q_2(s->mrb, nil);
1607
1672
  if (mid == mnil && n->cdr->cdr->car == NULL) {
1608
1673
  nil_p = TRUE;
1609
1674
  codegen(s, n->car, VAL);
@@ -1617,17 +1682,17 @@ codegen(codegen_scope *s, node *tree, int val)
1617
1682
  pop();
1618
1683
  if (val || tree->cdr->car) {
1619
1684
  if (nil_p) {
1620
- pos2 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1621
- pos1 = genjmp(s, OP_JMP, 0);
1685
+ pos2 = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1686
+ pos1 = genjmp_0(s, OP_JMP);
1622
1687
  dispatch(s, pos2);
1623
1688
  }
1624
1689
  else {
1625
- pos1 = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
1690
+ pos1 = genjmp2_0(s, OP_JMPNOT, cursp(), val);
1626
1691
  }
1627
1692
  codegen(s, tree->cdr->car, val);
1628
1693
  if (val) pop();
1629
1694
  if (elsepart || val) {
1630
- pos2 = genjmp(s, OP_JMP, 0);
1695
+ pos2 = genjmp_0(s, OP_JMP);
1631
1696
  dispatch(s, pos1);
1632
1697
  codegen(s, elsepart, val);
1633
1698
  dispatch(s, pos2);
@@ -1639,10 +1704,10 @@ codegen(codegen_scope *s, node *tree, int val)
1639
1704
  else { /* empty then-part */
1640
1705
  if (elsepart) {
1641
1706
  if (nil_p) {
1642
- pos1 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
1707
+ pos1 = genjmp2_0(s, OP_JMPNIL, cursp(), val);
1643
1708
  }
1644
1709
  else {
1645
- pos1 = genjmp2(s, OP_JMPIF, cursp(), 0, val);
1710
+ pos1 = genjmp2_0(s, OP_JMPIF, cursp(), val);
1646
1711
  }
1647
1712
  codegen(s, elsepart, val);
1648
1713
  dispatch(s, pos1);
@@ -1661,7 +1726,7 @@ codegen(codegen_scope *s, node *tree, int val)
1661
1726
 
1662
1727
  codegen(s, tree->car, VAL);
1663
1728
  pop();
1664
- pos = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
1729
+ pos = genjmp2_0(s, OP_JMPNOT, cursp(), val);
1665
1730
  codegen(s, tree->cdr, val);
1666
1731
  dispatch(s, pos);
1667
1732
  }
@@ -1673,7 +1738,7 @@ codegen(codegen_scope *s, node *tree, int val)
1673
1738
 
1674
1739
  codegen(s, tree->car, VAL);
1675
1740
  pop();
1676
- pos = genjmp2(s, OP_JMPIF, cursp(), 0, val);
1741
+ pos = genjmp2_0(s, OP_JMPIF, cursp(), val);
1677
1742
  codegen(s, tree->cdr, val);
1678
1743
  dispatch(s, pos);
1679
1744
  }
@@ -1684,7 +1749,7 @@ codegen(codegen_scope *s, node *tree, int val)
1684
1749
  struct loopinfo *lp = loop_push(s, LOOP_NORMAL);
1685
1750
 
1686
1751
  lp->pc0 = new_label(s);
1687
- lp->pc1 = genjmp(s, OP_JMP, 0);
1752
+ lp->pc1 = genjmp_0(s, OP_JMP);
1688
1753
  lp->pc2 = new_label(s);
1689
1754
  codegen(s, tree->cdr, NOVAL);
1690
1755
  dispatch(s, lp->pc1);
@@ -1701,7 +1766,7 @@ codegen(codegen_scope *s, node *tree, int val)
1701
1766
  struct loopinfo *lp = loop_push(s, LOOP_NORMAL);
1702
1767
 
1703
1768
  lp->pc0 = new_label(s);
1704
- lp->pc1 = genjmp(s, OP_JMP, 0);
1769
+ lp->pc1 = genjmp_0(s, OP_JMP);
1705
1770
  lp->pc2 = new_label(s);
1706
1771
  codegen(s, tree->cdr, NOVAL);
1707
1772
  dispatch(s, lp->pc1);
@@ -1721,10 +1786,10 @@ codegen(codegen_scope *s, node *tree, int val)
1721
1786
  case NODE_CASE:
1722
1787
  {
1723
1788
  int head = 0;
1724
- int pos1, pos2, pos3, tmp;
1789
+ uint32_t pos1, pos2, pos3, tmp;
1725
1790
  node *n;
1726
1791
 
1727
- pos3 = 0;
1792
+ pos3 = JMPLINK_START;
1728
1793
  if (tree->car) {
1729
1794
  head = cursp();
1730
1795
  codegen(s, tree->car, VAL);
@@ -1732,17 +1797,17 @@ codegen(codegen_scope *s, node *tree, int val)
1732
1797
  tree = tree->cdr;
1733
1798
  while (tree) {
1734
1799
  n = tree->car->car;
1735
- pos1 = pos2 = 0;
1800
+ pos1 = pos2 = JMPLINK_START;
1736
1801
  while (n) {
1737
1802
  codegen(s, n->car, VAL);
1738
1803
  if (head) {
1739
1804
  gen_move(s, cursp(), head, 0);
1740
1805
  push(); push(); pop(); pop(); pop();
1741
1806
  if (nint(n->car->car) == NODE_SPLAT) {
1742
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1);
1807
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, __case_eqq)), 1);
1743
1808
  }
1744
1809
  else {
1745
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "===")), 1);
1810
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_OPSYM_2(s->mrb, eqq)), 1);
1746
1811
  }
1747
1812
  }
1748
1813
  else {
@@ -1753,20 +1818,20 @@ codegen(codegen_scope *s, node *tree, int val)
1753
1818
  n = n->cdr;
1754
1819
  }
1755
1820
  if (tree->car->car) {
1756
- pos1 = genjmp(s, OP_JMP, 0);
1821
+ pos1 = genjmp_0(s, OP_JMP);
1757
1822
  dispatch_linked(s, pos2);
1758
1823
  }
1759
1824
  codegen(s, tree->car->cdr, val);
1760
1825
  if (val) pop();
1761
1826
  tmp = genjmp(s, OP_JMP, pos3);
1762
1827
  pos3 = tmp;
1763
- if (pos1) dispatch(s, pos1);
1828
+ dispatch(s, pos1);
1764
1829
  tree = tree->cdr;
1765
1830
  }
1766
1831
  if (val) {
1767
- int pos = cursp();
1832
+ uint32_t pos = cursp();
1768
1833
  genop_1(s, OP_LOADNIL, cursp());
1769
- if (pos3) dispatch_linked(s, pos3);
1834
+ if (pos3 != JMPLINK_START) dispatch_linked(s, pos3);
1770
1835
  if (head) pop();
1771
1836
  if (cursp() != pos) {
1772
1837
  gen_move(s, cursp(), pos, 0);
@@ -1774,7 +1839,7 @@ codegen(codegen_scope *s, node *tree, int val)
1774
1839
  push();
1775
1840
  }
1776
1841
  else {
1777
- if (pos3) {
1842
+ if (pos3 != JMPLINK_START) {
1778
1843
  dispatch_linked(s, pos3);
1779
1844
  }
1780
1845
  if (head) {
@@ -2017,18 +2082,20 @@ codegen(codegen_scope *s, node *tree, int val)
2017
2082
  if ((len == 2 && name[0] == '|' && name[1] == '|') &&
2018
2083
  (nint(tree->car->car) == NODE_CONST ||
2019
2084
  nint(tree->car->car) == NODE_CVAR)) {
2020
- int onerr, noexc, exc;
2085
+ int catch_entry, begin, end;
2086
+ int noexc, exc;
2021
2087
  struct loopinfo *lp;
2022
2088
 
2023
- onerr = genjmp(s, OP_ONERR, 0);
2024
2089
  lp = loop_push(s, LOOP_BEGIN);
2025
- lp->pc1 = onerr;
2090
+ lp->pc0 = new_label(s);
2091
+ catch_entry = catch_handler_new(s);
2092
+ begin = s->pc;
2026
2093
  exc = cursp();
2027
2094
  codegen(s, tree->car, VAL);
2095
+ end = s->pc;
2096
+ noexc = genjmp_0(s, OP_JMP);
2028
2097
  lp->type = LOOP_RESCUE;
2029
- genop_1(s, OP_POPERR, 1);
2030
- noexc = genjmp(s, OP_JMP, 0);
2031
- dispatch(s, onerr);
2098
+ catch_handler_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc);
2032
2099
  genop_1(s, OP_EXCEPT, exc);
2033
2100
  genop_1(s, OP_LOADF, exc);
2034
2101
  dispatch(s, noexc);
@@ -2079,10 +2146,10 @@ codegen(codegen_scope *s, node *tree, int val)
2079
2146
  if (vsp >= 0) {
2080
2147
  gen_move(s, vsp, cursp(), 1);
2081
2148
  }
2082
- pos = genjmp2(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0, val);
2149
+ pos = genjmp2_0(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), val);
2083
2150
  }
2084
2151
  else {
2085
- pos = genjmp2(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0, val);
2152
+ pos = genjmp2_0(s, name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), val);
2086
2153
  }
2087
2154
  codegen(s, tree->cdr->cdr->car, VAL);
2088
2155
  pop();
@@ -2266,7 +2333,7 @@ codegen(codegen_scope *s, node *tree, int val)
2266
2333
  pop_n(n+1);
2267
2334
  genop_2S(s, OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf));
2268
2335
  if (sendv) n = CALL_MAXARGS;
2269
- genop_3(s, OP_SEND, cursp(), new_sym(s, mrb_intern_lit(s->mrb, "call")), n);
2336
+ genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, call)), n);
2270
2337
  if (val) push();
2271
2338
  }
2272
2339
  break;
@@ -2281,11 +2348,8 @@ codegen(codegen_scope *s, node *tree, int val)
2281
2348
  raise_error(s, "unexpected next");
2282
2349
  }
2283
2350
  else if (s->loop->type == LOOP_NORMAL) {
2284
- if (s->ensure_level > s->loop->ensure_level) {
2285
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
2286
- }
2287
2351
  codegen(s, tree, NOVAL);
2288
- genjmp(s, OP_JMP, s->loop->pc0);
2352
+ genjmp(s, OP_JMPUW, s->loop->pc0);
2289
2353
  }
2290
2354
  else {
2291
2355
  if (tree) {
@@ -2305,10 +2369,7 @@ codegen(codegen_scope *s, node *tree, int val)
2305
2369
  raise_error(s, "unexpected redo");
2306
2370
  }
2307
2371
  else {
2308
- if (s->ensure_level > s->loop->ensure_level) {
2309
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
2310
- }
2311
- genjmp(s, OP_JMP, s->loop->pc2);
2372
+ genjmp(s, OP_JMPUW, s->loop->pc2);
2312
2373
  }
2313
2374
  if (val) push();
2314
2375
  break;
@@ -2316,32 +2377,16 @@ codegen(codegen_scope *s, node *tree, int val)
2316
2377
  case NODE_RETRY:
2317
2378
  {
2318
2379
  const char *msg = "unexpected retry";
2380
+ const struct loopinfo *lp = s->loop;
2319
2381
 
2320
- if (!s->loop) {
2382
+ while (lp && lp->type != LOOP_RESCUE) {
2383
+ lp = lp->prev;
2384
+ }
2385
+ if (!lp) {
2321
2386
  raise_error(s, msg);
2322
2387
  }
2323
2388
  else {
2324
- struct loopinfo *lp = s->loop;
2325
- int n = 0;
2326
-
2327
- while (lp && lp->type != LOOP_RESCUE) {
2328
- if (lp->type == LOOP_BEGIN) {
2329
- n++;
2330
- }
2331
- lp = lp->prev;
2332
- }
2333
- if (!lp) {
2334
- raise_error(s, msg);
2335
- }
2336
- else {
2337
- if (n > 0) {
2338
- genop_1(s, OP_POPERR, n);
2339
- }
2340
- if (s->ensure_level > lp->ensure_level) {
2341
- genop_1(s, OP_EPOP, s->ensure_level - lp->ensure_level);
2342
- }
2343
- genjmp(s, OP_JMP, lp->pc0);
2344
- }
2389
+ genjmp(s, OP_JMPUW, lp->pc0);
2345
2390
  }
2346
2391
  if (val) push();
2347
2392
  }
@@ -2447,45 +2492,41 @@ codegen(codegen_scope *s, node *tree, int val)
2447
2492
  mrb_bool overflow;
2448
2493
 
2449
2494
  i = readint_mrb_int(s, p, base, FALSE, &overflow);
2450
- #ifndef MRB_WITHOUT_FLOAT
2451
2495
  if (overflow) {
2452
- double f = readint_float(s, p, base);
2453
- int off = new_lit(s, mrb_float_value(s->mrb, f));
2454
-
2455
- genop_2(s, OP_LOADL, cursp(), off);
2496
+ codegen_error(s, "integer overflow");
2456
2497
  }
2457
- else
2458
- #endif
2459
- {
2498
+ else {
2460
2499
  if (i < 0) {
2461
2500
  if (i == -1) genop_1(s, OP_LOADI__1, cursp());
2462
- else if (i >= -0xff) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2463
- else if (i >= -0x8000) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2501
+ else if (i >= -0xff) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2502
+ else if (i >= INT16_MIN) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2503
+ else if (i >= INT32_MIN) genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2464
2504
  else goto lit_int;
2465
2505
  }
2466
2506
  else if (i < 8) genop_1(s, OP_LOADI_0 + (uint8_t)i, cursp());
2467
2507
  else if (i <= 0xff) genop_2(s, OP_LOADI, cursp(), (uint16_t)i);
2468
- else if (i <= 0x7fff) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2508
+ else if (i <= INT16_MAX) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2509
+ else if (i <= INT32_MAX) genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2469
2510
  else {
2470
2511
  int off;
2471
2512
 
2472
2513
  lit_int:
2473
- off = new_lit(s, mrb_fixnum_value(i));
2474
- genop_2(s, OP_LOADL, cursp(), off);
2514
+ off = new_lit(s, mrb_int_value(s->mrb, i));
2515
+ genop_bs(s, OP_LOADL, cursp(), off);
2475
2516
  }
2476
2517
  }
2477
2518
  push();
2478
2519
  }
2479
2520
  break;
2480
2521
 
2481
- #ifndef MRB_WITHOUT_FLOAT
2522
+ #ifndef MRB_NO_FLOAT
2482
2523
  case NODE_FLOAT:
2483
2524
  if (val) {
2484
2525
  char *p = (char*)tree;
2485
2526
  mrb_float f = mrb_float_read(p, NULL);
2486
2527
  int off = new_lit(s, mrb_float_value(s->mrb, f));
2487
2528
 
2488
- genop_2(s, OP_LOADL, cursp(), off);
2529
+ genop_bs(s, OP_LOADL, cursp(), off);
2489
2530
  push();
2490
2531
  }
2491
2532
  break;
@@ -2495,14 +2536,14 @@ codegen(codegen_scope *s, node *tree, int val)
2495
2536
  {
2496
2537
  nt = nint(tree->car);
2497
2538
  switch (nt) {
2498
- #ifndef MRB_WITHOUT_FLOAT
2539
+ #ifndef MRB_NO_FLOAT
2499
2540
  case NODE_FLOAT:
2500
2541
  if (val) {
2501
2542
  char *p = (char*)tree->cdr;
2502
2543
  mrb_float f = mrb_float_read(p, NULL);
2503
2544
  int off = new_lit(s, mrb_float_value(s->mrb, -f));
2504
2545
 
2505
- genop_2(s, OP_LOADL, cursp(), off);
2546
+ genop_bs(s, OP_LOADL, cursp(), off);
2506
2547
  push();
2507
2548
  }
2508
2549
  break;
@@ -2516,36 +2557,32 @@ codegen(codegen_scope *s, node *tree, int val)
2516
2557
  mrb_bool overflow;
2517
2558
 
2518
2559
  i = readint_mrb_int(s, p, base, TRUE, &overflow);
2519
- #ifndef MRB_WITHOUT_FLOAT
2520
2560
  if (overflow) {
2521
- double f = readint_float(s, p, base);
2522
- int off = new_lit(s, mrb_float_value(s->mrb, -f));
2523
-
2524
- genop_2(s, OP_LOADL, cursp(), off);
2561
+ codegen_error(s, "integer overflow");
2525
2562
  }
2526
2563
  else {
2527
- #endif
2528
2564
  if (i == -1) genop_1(s, OP_LOADI__1, cursp());
2529
2565
  else if (i >= -0xff) {
2530
2566
  genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
2531
2567
  }
2532
- else if (i >= -0x8000) {
2568
+ else if (i >= INT16_MIN) {
2533
2569
  genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
2534
2570
  }
2571
+ else if (i >= INT32_MIN) {
2572
+ genop_2SS(s, OP_LOADI32, cursp(), (uint32_t)i);
2573
+ }
2535
2574
  else {
2536
- int off = new_lit(s, mrb_fixnum_value(i));
2537
- genop_2(s, OP_LOADL, cursp(), off);
2575
+ int off = new_lit(s, mrb_int_value(s->mrb, i));
2576
+ genop_bs(s, OP_LOADL, cursp(), off);
2538
2577
  }
2539
- #ifndef MRB_WITHOUT_FLOAT
2540
2578
  }
2541
- #endif
2542
2579
  push();
2543
2580
  }
2544
2581
  break;
2545
2582
 
2546
2583
  default:
2547
2584
  if (val) {
2548
- int sym = new_sym(s, mrb_intern_lit(s->mrb, "-@"));
2585
+ int sym = new_sym(s, MRB_OPSYM_2(s->mrb, minus));
2549
2586
  codegen(s, tree, VAL);
2550
2587
  pop();
2551
2588
  genop_3(s, OP_SEND, cursp(), sym, 0);
@@ -2567,7 +2604,7 @@ codegen(codegen_scope *s, node *tree, int val)
2567
2604
  int off = new_lit(s, mrb_str_new(s->mrb, p, len));
2568
2605
 
2569
2606
  mrb_gc_arena_restore(s->mrb, ai);
2570
- genop_2(s, OP_STRING, cursp(), off);
2607
+ genop_bs(s, OP_STRING, cursp(), off);
2571
2608
  push();
2572
2609
  }
2573
2610
  break;
@@ -2618,7 +2655,7 @@ codegen(codegen_scope *s, node *tree, int val)
2618
2655
  {
2619
2656
  node *n;
2620
2657
  int ai = mrb_gc_arena_save(s->mrb);
2621
- int sym = new_sym(s, mrb_intern_lit(s->mrb, "Kernel"));
2658
+ int sym = new_sym(s, MRB_SYM_2(s->mrb, Kernel));
2622
2659
 
2623
2660
  genop_1(s, OP_LOADSELF, cursp());
2624
2661
  push();
@@ -2637,7 +2674,7 @@ codegen(codegen_scope *s, node *tree, int val)
2637
2674
  }
2638
2675
  push(); /* for block */
2639
2676
  pop_n(3);
2640
- sym = new_sym(s, mrb_intern_lit(s->mrb, "`"));
2677
+ sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */
2641
2678
  genop_3(s, OP_SEND, cursp(), sym, 1);
2642
2679
  if (val) push();
2643
2680
  mrb_gc_arena_restore(s->mrb, ai);
@@ -2654,10 +2691,10 @@ codegen(codegen_scope *s, node *tree, int val)
2654
2691
 
2655
2692
  genop_1(s, OP_LOADSELF, cursp());
2656
2693
  push();
2657
- genop_2(s, OP_STRING, cursp(), off);
2694
+ genop_bs(s, OP_STRING, cursp(), off);
2658
2695
  push(); push();
2659
2696
  pop_n(3);
2660
- sym = new_sym(s, mrb_intern_lit(s->mrb, "`"));
2697
+ sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */
2661
2698
  genop_3(s, OP_SEND, cursp(), sym, 1);
2662
2699
  if (val) push();
2663
2700
  mrb_gc_arena_restore(s->mrb, ai);
@@ -2677,12 +2714,12 @@ codegen(codegen_scope *s, node *tree, int val)
2677
2714
  genop_1(s, OP_OCLASS, cursp());
2678
2715
  genop_2(s, OP_GETMCNST, cursp(), sym);
2679
2716
  push();
2680
- genop_2(s, OP_STRING, cursp(), off);
2717
+ genop_bs(s, OP_STRING, cursp(), off);
2681
2718
  push();
2682
2719
  if (p2 || p3) {
2683
2720
  if (p2) { /* opt */
2684
2721
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2685
- genop_2(s, OP_STRING, cursp(), off);
2722
+ genop_bs(s, OP_STRING, cursp(), off);
2686
2723
  }
2687
2724
  else {
2688
2725
  genop_1(s, OP_LOADNIL, cursp());
@@ -2691,14 +2728,14 @@ codegen(codegen_scope *s, node *tree, int val)
2691
2728
  argc++;
2692
2729
  if (p3) { /* enc */
2693
2730
  off = new_lit(s, mrb_str_new(s->mrb, p3, 1));
2694
- genop_2(s, OP_STRING, cursp(), off);
2731
+ genop_bs(s, OP_STRING, cursp(), off);
2695
2732
  push();
2696
2733
  argc++;
2697
2734
  }
2698
2735
  }
2699
2736
  push(); /* space for a block */
2700
2737
  pop_n(argc+2);
2701
- sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
2738
+ sym = new_sym(s, MRB_SYM_2(s->mrb, compile));
2702
2739
  genop_3(s, OP_SEND, cursp(), sym, argc);
2703
2740
  mrb_gc_arena_restore(s->mrb, ai);
2704
2741
  push();
@@ -2731,7 +2768,7 @@ codegen(codegen_scope *s, node *tree, int val)
2731
2768
  p = (char*)n->car;
2732
2769
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p));
2733
2770
  codegen(s, tree->car, VAL);
2734
- genop_2(s, OP_STRING, cursp(), off);
2771
+ genop_bs(s, OP_STRING, cursp(), off);
2735
2772
  pop();
2736
2773
  genop_1(s, OP_STRCAT, cursp());
2737
2774
  push();
@@ -2739,20 +2776,20 @@ codegen(codegen_scope *s, node *tree, int val)
2739
2776
  if (n->cdr->car) { /* opt */
2740
2777
  char *p2 = (char*)n->cdr->car;
2741
2778
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2742
- genop_2(s, OP_STRING, cursp(), off);
2779
+ genop_bs(s, OP_STRING, cursp(), off);
2743
2780
  push();
2744
2781
  argc++;
2745
2782
  }
2746
2783
  if (n->cdr->cdr) { /* enc */
2747
2784
  char *p2 = (char*)n->cdr->cdr;
2748
2785
  off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
2749
- genop_2(s, OP_STRING, cursp(), off);
2786
+ genop_bs(s, OP_STRING, cursp(), off);
2750
2787
  push();
2751
2788
  argc++;
2752
2789
  }
2753
2790
  push(); /* space for a block */
2754
2791
  pop_n(argc+2);
2755
- sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
2792
+ sym = new_sym(s, MRB_SYM_2(s->mrb, compile));
2756
2793
  genop_3(s, OP_SEND, cursp(), sym, argc);
2757
2794
  mrb_gc_arena_restore(s->mrb, ai);
2758
2795
  push();
@@ -2773,7 +2810,7 @@ codegen(codegen_scope *s, node *tree, int val)
2773
2810
  if (val) {
2774
2811
  int sym = new_sym(s, nsym(tree));
2775
2812
 
2776
- genop_2(s, OP_LOADSYM, cursp(), sym);
2813
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2777
2814
  push();
2778
2815
  }
2779
2816
  break;
@@ -2874,7 +2911,7 @@ codegen(codegen_scope *s, node *tree, int val)
2874
2911
  }
2875
2912
  else {
2876
2913
  idx = scope_body(s, body, val);
2877
- genop_2(s, OP_EXEC, cursp(), idx);
2914
+ genop_bs(s, OP_EXEC, cursp(), idx);
2878
2915
  }
2879
2916
  if (val) {
2880
2917
  push();
@@ -2906,7 +2943,7 @@ codegen(codegen_scope *s, node *tree, int val)
2906
2943
  }
2907
2944
  else {
2908
2945
  idx = scope_body(s, tree->cdr->car, val);
2909
- genop_2(s, OP_EXEC, cursp(), idx);
2946
+ genop_bs(s, OP_EXEC, cursp(), idx);
2910
2947
  }
2911
2948
  if (val) {
2912
2949
  push();
@@ -2927,7 +2964,7 @@ codegen(codegen_scope *s, node *tree, int val)
2927
2964
  }
2928
2965
  else {
2929
2966
  idx = scope_body(s, tree->cdr->car, val);
2930
- genop_2(s, OP_EXEC, cursp(), idx);
2967
+ genop_bs(s, OP_EXEC, cursp(), idx);
2931
2968
  }
2932
2969
  if (val) {
2933
2970
  push();
@@ -2942,12 +2979,12 @@ codegen(codegen_scope *s, node *tree, int val)
2942
2979
 
2943
2980
  genop_1(s, OP_TCLASS, cursp());
2944
2981
  push();
2945
- genop_2(s, OP_METHOD, cursp(), idx);
2982
+ genop_bs(s, OP_METHOD, cursp(), idx);
2946
2983
  push(); pop();
2947
2984
  pop();
2948
2985
  genop_2(s, OP_DEF, cursp(), sym);
2949
2986
  if (val) {
2950
- genop_2(s, OP_LOADSYM, cursp(), sym);
2987
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2951
2988
  push();
2952
2989
  }
2953
2990
  }
@@ -2963,11 +3000,11 @@ codegen(codegen_scope *s, node *tree, int val)
2963
3000
  pop();
2964
3001
  genop_1(s, OP_SCLASS, cursp());
2965
3002
  push();
2966
- genop_2(s, OP_METHOD, cursp(), idx);
3003
+ genop_bs(s, OP_METHOD, cursp(), idx);
2967
3004
  pop();
2968
3005
  genop_2(s, OP_DEF, cursp(), sym);
2969
3006
  if (val) {
2970
- genop_2(s, OP_LOADSYM, cursp(), sym);
3007
+ genop_bs(s, OP_LOADSYM, cursp(), sym);
2971
3008
  push();
2972
3009
  }
2973
3010
  }
@@ -2985,99 +3022,100 @@ codegen(codegen_scope *s, node *tree, int val)
2985
3022
  }
2986
3023
 
2987
3024
  static void
2988
- scope_add_irep(codegen_scope *s, mrb_irep *irep)
3025
+ scope_add_irep(codegen_scope *s)
2989
3026
  {
2990
- if (s->irep == NULL) {
2991
- s->irep = irep;
3027
+ mrb_irep *irep;
3028
+ codegen_scope *prev = s->prev;
3029
+
3030
+ if (prev->irep == NULL) {
3031
+ irep = mrb_add_irep(s->mrb);
3032
+ prev->irep = s->irep = irep;
2992
3033
  return;
2993
3034
  }
2994
- if (s->irep->rlen == s->rcapa) {
2995
- s->rcapa *= 2;
2996
- s->irep->reps = (mrb_irep**)codegen_realloc(s, s->irep->reps, sizeof(mrb_irep*)*s->rcapa);
3035
+ else {
3036
+ if (prev->irep->rlen == UINT16_MAX) {
3037
+ codegen_error(s, "too many nested blocks/methods");
3038
+ }
3039
+ s->irep = irep = mrb_add_irep(s->mrb);
3040
+ if (prev->irep->rlen == prev->rcapa) {
3041
+ prev->rcapa *= 2;
3042
+ prev->reps = (mrb_irep**)codegen_realloc(s, prev->reps, sizeof(mrb_irep*)*prev->rcapa);
3043
+ }
3044
+ prev->reps[prev->irep->rlen] = irep;
3045
+ prev->irep->rlen++;
2997
3046
  }
2998
- s->irep->reps[s->irep->rlen] = irep;
2999
- s->irep->rlen++;
3000
3047
  }
3001
3048
 
3002
3049
  static codegen_scope*
3003
- scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
3050
+ scope_new(mrb_state *mrb, codegen_scope *prev, node *nlv)
3004
3051
  {
3005
3052
  static const codegen_scope codegen_scope_zero = { 0 };
3006
3053
  mrb_pool *pool = mrb_pool_open(mrb);
3007
- codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
3054
+ codegen_scope *s = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
3008
3055
 
3009
- if (!p) {
3056
+ if (!s) {
3010
3057
  if (prev)
3011
3058
  codegen_error(prev, "unexpected scope");
3012
3059
  return NULL;
3013
3060
  }
3014
- *p = codegen_scope_zero;
3015
- p->mrb = mrb;
3016
- p->mpool = pool;
3017
- if (!prev) return p;
3018
- p->prev = prev;
3019
- p->ainfo = -1;
3020
- p->mscope = 0;
3021
-
3022
- p->irep = mrb_add_irep(mrb);
3023
- scope_add_irep(prev, p->irep);
3024
-
3025
- p->rcapa = 8;
3026
- p->irep->reps = (mrb_irep**)mrb_malloc(mrb, sizeof(mrb_irep*)*p->rcapa);
3027
-
3028
- p->icapa = 1024;
3029
- p->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa);
3030
- p->irep->iseq = NULL;
3031
-
3032
- p->pcapa = 32;
3033
- p->irep->pool = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value)*p->pcapa);
3034
- p->irep->plen = 0;
3035
-
3036
- p->scapa = 256;
3037
- p->irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*p->scapa);
3038
- p->irep->slen = 0;
3039
-
3040
- p->lv = lv;
3041
- p->sp += node_len(lv)+1; /* add self */
3042
- p->nlocals = p->sp;
3043
- if (lv) {
3044
- node *n = lv;
3061
+ *s = codegen_scope_zero;
3062
+ s->mrb = mrb;
3063
+ s->mpool = pool;
3064
+ if (!prev) return s;
3065
+ s->prev = prev;
3066
+ s->ainfo = -1;
3067
+ s->mscope = 0;
3068
+
3069
+ scope_add_irep(s);
3070
+
3071
+ s->rcapa = 8;
3072
+ s->reps = (mrb_irep**)mrb_malloc(mrb, sizeof(mrb_irep*)*s->rcapa);
3073
+
3074
+ s->icapa = 1024;
3075
+ s->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*s->icapa);
3076
+
3077
+ s->pcapa = 32;
3078
+ s->pool = (mrb_pool_value*)mrb_malloc(mrb, sizeof(mrb_pool_value)*s->pcapa);
3079
+
3080
+ s->scapa = 256;
3081
+ s->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*s->scapa);
3082
+
3083
+ s->lv = nlv;
3084
+ s->sp += node_len(nlv)+1; /* add self */
3085
+ s->nlocals = s->sp;
3086
+ if (nlv) {
3087
+ mrb_sym *lv;
3088
+ node *n = nlv;
3045
3089
  size_t i = 0;
3046
3090
 
3047
- p->irep->lv = (struct mrb_locals*)mrb_malloc(mrb, sizeof(struct mrb_locals) * (p->nlocals - 1));
3048
- for (i=0, n=lv; n; i++,n=n->cdr) {
3049
- p->irep->lv[i].name = lv_name(n);
3050
- if (lv_name(n)) {
3051
- p->irep->lv[i].r = lv_idx(p, lv_name(n));
3052
- }
3053
- else {
3054
- p->irep->lv[i].r = 0;
3055
- }
3091
+ s->irep->lv = lv = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*(s->nlocals-1));
3092
+ for (i=0, n=nlv; n; i++,n=n->cdr) {
3093
+ lv[i] = lv_name(n);
3056
3094
  }
3057
- mrb_assert(i + 1 == p->nlocals);
3095
+ mrb_assert(i + 1 == s->nlocals);
3058
3096
  }
3059
- p->ai = mrb_gc_arena_save(mrb);
3097
+ s->ai = mrb_gc_arena_save(mrb);
3060
3098
 
3061
- p->filename_sym = prev->filename_sym;
3062
- if (p->filename_sym) {
3063
- p->lines = (uint16_t*)mrb_malloc(mrb, sizeof(short)*p->icapa);
3099
+ s->filename_sym = prev->filename_sym;
3100
+ if (s->filename_sym) {
3101
+ s->lines = (uint16_t*)mrb_malloc(mrb, sizeof(short)*s->icapa);
3064
3102
  }
3065
- p->lineno = prev->lineno;
3103
+ s->lineno = prev->lineno;
3066
3104
 
3067
3105
  /* debug setting */
3068
- p->debug_start_pos = 0;
3069
- if (p->filename_sym) {
3070
- mrb_debug_info_alloc(mrb, p->irep);
3106
+ s->debug_start_pos = 0;
3107
+ if (s->filename_sym) {
3108
+ mrb_debug_info_alloc(mrb, s->irep);
3071
3109
  }
3072
3110
  else {
3073
- p->irep->debug_info = NULL;
3111
+ s->irep->debug_info = NULL;
3074
3112
  }
3075
- p->parser = prev->parser;
3076
- p->filename_index = prev->filename_index;
3113
+ s->parser = prev->parser;
3114
+ s->filename_index = prev->filename_index;
3077
3115
 
3078
- p->rlev = prev->rlev+1;
3116
+ s->rlev = prev->rlev+1;
3079
3117
 
3080
- return p;
3118
+ return s;
3081
3119
  }
3082
3120
 
3083
3121
  static void
@@ -3086,17 +3124,26 @@ scope_finish(codegen_scope *s)
3086
3124
  mrb_state *mrb = s->mrb;
3087
3125
  mrb_irep *irep = s->irep;
3088
3126
 
3089
- if (s->nlocals >= 0x3ff) {
3127
+ if (s->nlocals > 0xff) {
3090
3128
  codegen_error(s, "too many local variables");
3091
3129
  }
3092
3130
  irep->flags = 0;
3093
3131
  if (s->iseq) {
3094
- irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc);
3132
+ size_t catchsize = sizeof(struct mrb_irep_catch_handler) * irep->clen;
3133
+ irep->iseq = (const mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc + catchsize);
3095
3134
  irep->ilen = s->pc;
3135
+ if (irep->clen > 0) {
3136
+ memcpy((void *)(irep->iseq + irep->ilen), s->catch_table, catchsize);
3137
+ }
3138
+ }
3139
+ else {
3140
+ irep->clen = 0;
3096
3141
  }
3097
- irep->pool = (mrb_value*)codegen_realloc(s, irep->pool, sizeof(mrb_value)*irep->plen);
3098
- irep->syms = (mrb_sym*)codegen_realloc(s, irep->syms, sizeof(mrb_sym)*irep->slen);
3099
- irep->reps = (mrb_irep**)codegen_realloc(s, irep->reps, sizeof(mrb_irep*)*irep->rlen);
3142
+ mrb_free(s->mrb, s->catch_table);
3143
+ s->catch_table = NULL;
3144
+ irep->pool = (const mrb_pool_value*)codegen_realloc(s, s->pool, sizeof(mrb_pool_value)*irep->plen);
3145
+ irep->syms = (const mrb_sym*)codegen_realloc(s, s->syms, sizeof(mrb_sym)*irep->slen);
3146
+ irep->reps = (const mrb_irep**)codegen_realloc(s, s->reps, sizeof(mrb_irep*)*irep->rlen);
3100
3147
  if (s->filename_sym) {
3101
3148
  mrb_sym fname = mrb_parser_get_filename(s->parser, s->filename_index);
3102
3149
  const char *filename = mrb_sym_name_len(s->mrb, fname, NULL);
@@ -3119,9 +3166,8 @@ loop_push(codegen_scope *s, enum looptype t)
3119
3166
  struct loopinfo *p = (struct loopinfo *)codegen_palloc(s, sizeof(struct loopinfo));
3120
3167
 
3121
3168
  p->type = t;
3122
- p->pc0 = p->pc1 = p->pc2 = p->pc3 = 0;
3169
+ p->pc0 = p->pc1 = p->pc2 = p->pc3 = JMPLINK_START;
3123
3170
  p->prev = s->loop;
3124
- p->ensure_level = s->ensure_level;
3125
3171
  p->acc = cursp();
3126
3172
  s->loop = p;
3127
3173
 
@@ -3137,7 +3183,6 @@ loop_break(codegen_scope *s, node *tree)
3137
3183
  }
3138
3184
  else {
3139
3185
  struct loopinfo *loop;
3140
- int n = 0;
3141
3186
 
3142
3187
  if (tree) {
3143
3188
  gen_retval(s, tree);
@@ -3146,7 +3191,6 @@ loop_break(codegen_scope *s, node *tree)
3146
3191
  loop = s->loop;
3147
3192
  while (loop) {
3148
3193
  if (loop->type == LOOP_BEGIN) {
3149
- n++;
3150
3194
  loop = loop->prev;
3151
3195
  }
3152
3196
  else if (loop->type == LOOP_RESCUE) {
@@ -3160,20 +3204,14 @@ loop_break(codegen_scope *s, node *tree)
3160
3204
  raise_error(s, "unexpected break");
3161
3205
  return;
3162
3206
  }
3163
- if (n > 0) {
3164
- genop_1(s, OP_POPERR, n);
3165
- }
3166
3207
 
3167
3208
  if (loop->type == LOOP_NORMAL) {
3168
3209
  int tmp;
3169
3210
 
3170
- if (s->ensure_level > s->loop->ensure_level) {
3171
- genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level);
3172
- }
3173
3211
  if (tree) {
3174
3212
  gen_move(s, loop->acc, cursp(), 0);
3175
3213
  }
3176
- tmp = genjmp(s, OP_JMP, loop->pc3);
3214
+ tmp = genjmp(s, OP_JMPUW, loop->pc3);
3177
3215
  loop->pc3 = tmp;
3178
3216
  }
3179
3217
  else {
@@ -3196,6 +3234,28 @@ loop_pop(codegen_scope *s, int val)
3196
3234
  if (val) push();
3197
3235
  }
3198
3236
 
3237
+ static int
3238
+ catch_handler_new(codegen_scope *s)
3239
+ {
3240
+ size_t newsize = sizeof(struct mrb_irep_catch_handler) * (s->irep->clen + 1);
3241
+ s->catch_table = (struct mrb_irep_catch_handler *)codegen_realloc(s, (void *)s->catch_table, newsize);
3242
+ return s->irep->clen ++;
3243
+ }
3244
+
3245
+ static void
3246
+ catch_handler_set(codegen_scope *s, int ent, enum mrb_catch_type type, uint32_t begin, uint32_t end, uint32_t target)
3247
+ {
3248
+ struct mrb_irep_catch_handler *e;
3249
+
3250
+ mrb_assert(ent >= 0 && ent < s->irep->clen);
3251
+
3252
+ e = &s->catch_table[ent];
3253
+ uint8_to_bin(type, &e->type);
3254
+ mrb_irep_catch_handler_pack(begin, e->begin);
3255
+ mrb_irep_catch_handler_pack(end, e->end);
3256
+ mrb_irep_catch_handler_pack(target, e->target);
3257
+ }
3258
+
3199
3259
  static struct RProc*
3200
3260
  generate_code(mrb_state *mrb, parser_state *p, int val)
3201
3261
  {
@@ -3242,13 +3302,14 @@ mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
3242
3302
  {
3243
3303
  int i;
3244
3304
 
3305
+ if (irep->flags & MRB_IREP_NO_FREE) return;
3245
3306
  if (irep->lv) {
3246
- mrb_free(mrb, irep->lv);
3307
+ mrb_free(mrb, (void*)irep->lv);
3247
3308
  irep->lv = NULL;
3248
3309
  }
3249
-
3310
+ if (!irep->reps) return;
3250
3311
  for (i = 0; i < irep->rlen; ++i) {
3251
- mrb_irep_remove_lv(mrb, irep->reps[i]);
3312
+ mrb_irep_remove_lv(mrb, (mrb_irep*)irep->reps[i]);
3252
3313
  }
3253
3314
  }
3254
3315
 
@@ -3262,6 +3323,7 @@ uint8_t mrb_insn_size[] = {
3262
3323
  #define BB 3
3263
3324
  #define BBB 4
3264
3325
  #define BS 4
3326
+ #define BSS 6
3265
3327
  #define SB 4
3266
3328
  #define OPCODE(_,x) x,
3267
3329
  #include "mruby/ops.h"
@@ -3269,38 +3331,7 @@ uint8_t mrb_insn_size[] = {
3269
3331
  #undef B
3270
3332
  #undef BB
3271
3333
  #undef BS
3334
+ #undef BSS
3272
3335
  #undef SB
3273
3336
  #undef BBB
3274
3337
  };
3275
- /* EXT1 instruction sizes */
3276
- uint8_t mrb_insn_size1[] = {
3277
- #define B 3
3278
- #define BB 4
3279
- #define BBB 5
3280
- #define BS 5
3281
- #define SB 5
3282
- #define OPCODE(_,x) x,
3283
- #include "mruby/ops.h"
3284
- #undef OPCODE
3285
- #undef B
3286
- };
3287
- /* EXT2 instruction sizes */
3288
- uint8_t mrb_insn_size2[] = {
3289
- #define B 2
3290
- #define OPCODE(_,x) x,
3291
- #include "mruby/ops.h"
3292
- #undef OPCODE
3293
- #undef BB
3294
- #undef BBB
3295
- #undef BS
3296
- #undef SB
3297
- };
3298
- /* EXT3 instruction sizes */
3299
- #define BB 5
3300
- #define BBB 6
3301
- #define BS 4
3302
- #define SB 5
3303
- uint8_t mrb_insn_size3[] = {
3304
- #define OPCODE(_,x) x,
3305
- #include "mruby/ops.h"
3306
- };