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
@@ -13,13 +13,14 @@
13
13
  #include <mruby/variable.h>
14
14
  #include <mruby/error.h>
15
15
  #include <mruby/istruct.h>
16
+ #include <mruby/presym.h>
16
17
 
17
18
  MRB_API mrb_bool
18
19
  mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func)
19
20
  {
20
21
  struct RClass *c = mrb_class(mrb, obj);
21
22
  mrb_method_t m = mrb_method_search_vm(mrb, &c, mid);
22
- struct RProc *p;
23
+ const struct RProc *p;
23
24
 
24
25
  if (MRB_METHOD_UNDEF_P(m)) return FALSE;
25
26
  if (MRB_METHOD_FUNC_P(m))
@@ -33,7 +34,7 @@ mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func)
33
34
  static mrb_bool
34
35
  mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj)
35
36
  {
36
- return mrb_func_basic_p(mrb, obj, mrb_intern_lit(mrb, "to_s"), mrb_any_to_s);
37
+ return mrb_func_basic_p(mrb, obj, MRB_SYM(to_s), mrb_any_to_s);
37
38
  }
38
39
 
39
40
  /* 15.3.1.3.17 */
@@ -96,7 +97,19 @@ mrb_equal_m(mrb_state *mrb, mrb_value self)
96
97
  mrb_value
97
98
  mrb_obj_id_m(mrb_state *mrb, mrb_value self)
98
99
  {
99
- return mrb_fixnum_value(mrb_obj_id(self));
100
+ return mrb_int_value(mrb, mrb_obj_id(self));
101
+ }
102
+
103
+ static int
104
+ env_bidx(struct REnv *e)
105
+ {
106
+ int bidx;
107
+
108
+ /* use saved block arg position */
109
+ bidx = MRB_ENV_BIDX(e);
110
+ /* bidx may be useless (e.g. define_method) */
111
+ if (bidx >= MRB_ENV_LEN(e)) return -1;
112
+ return bidx;
100
113
  }
101
114
 
102
115
  /* 15.3.1.2.2 */
@@ -129,7 +142,9 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
129
142
  mrb_callinfo *ci = &mrb->c->ci[-1];
130
143
  mrb_callinfo *cibase = mrb->c->cibase;
131
144
  mrb_value *bp;
132
- struct RProc *p;
145
+ int bidx;
146
+ struct REnv *e = NULL;
147
+ const struct RProc *p;
133
148
 
134
149
  if (ci <= cibase) {
135
150
  /* toplevel does not have block */
@@ -139,33 +154,39 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
139
154
  /* search method/class/module proc */
140
155
  while (p) {
141
156
  if (MRB_PROC_SCOPE_P(p)) break;
157
+ e = MRB_PROC_ENV(p);
142
158
  p = p->upper;
143
159
  }
144
160
  if (p == NULL) return mrb_false_value();
161
+ if (e) {
162
+ bidx = env_bidx(e);
163
+ if (bidx < 0) return mrb_false_value();
164
+ bp = &e->stack[bidx];
165
+ goto block_given;
166
+ }
145
167
  /* search ci corresponding to proc */
146
168
  while (cibase < ci) {
147
169
  if (ci->proc == p) break;
148
170
  ci--;
149
171
  }
150
172
  if (ci == cibase) {
151
- return mrb_false_value();
173
+ /* proc is closure */
174
+ if (!MRB_PROC_ENV_P(p)) return mrb_false_value();
175
+ e = MRB_PROC_ENV(p);
176
+ bidx = env_bidx(e);
177
+ if (bidx < 0) return mrb_false_value();
178
+ bp = &e->stack[bidx];
152
179
  }
153
- else if (ci->env) {
154
- struct REnv *e = ci->env;
155
- int bidx;
156
-
180
+ else if ((e = mrb_vm_ci_env(ci)) != NULL) {
157
181
  /* top-level does not have block slot (always false) */
158
- if (e->stack == mrb->c->stbase)
159
- return mrb_false_value();
160
- /* use saved block arg position */
161
- bidx = MRB_ENV_BIDX(e);
182
+ if (e->stack == mrb->c->stbase) return mrb_false_value();
183
+ bidx = env_bidx(e);
162
184
  /* bidx may be useless (e.g. define_method) */
163
- if (bidx >= MRB_ENV_LEN(e))
164
- return mrb_false_value();
185
+ if (bidx < 0) return mrb_false_value();
165
186
  bp = &e->stack[bidx];
166
187
  }
167
188
  else {
168
- bp = ci[1].stackent+1;
189
+ bp = ci->stack+1;
169
190
  if (ci->argc >= 0) {
170
191
  bp += ci->argc;
171
192
  }
@@ -173,6 +194,7 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
173
194
  bp++;
174
195
  }
175
196
  }
197
+ block_given:
176
198
  if (mrb_nil_p(*bp))
177
199
  return mrb_false_value();
178
200
  return mrb_true_value();
@@ -187,7 +209,7 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
187
209
  * called with an explicit receiver, as <code>class</code> is also a
188
210
  * reserved word in Ruby.
189
211
  *
190
- * 1.class #=> Fixnum
212
+ * 1.class #=> Integer
191
213
  * self.class #=> Object
192
214
  */
193
215
  static mrb_value
@@ -196,189 +218,8 @@ mrb_obj_class_m(mrb_state *mrb, mrb_value self)
196
218
  return mrb_obj_value(mrb_obj_class(mrb, self));
197
219
  }
198
220
 
199
- static struct RClass*
200
- mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
201
- {
202
- struct RClass *klass = mrb_basic_ptr(obj)->c;
203
-
204
- if (klass->tt != MRB_TT_SCLASS)
205
- return klass;
206
- else {
207
- /* copy singleton(unnamed) class */
208
- struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
209
-
210
- switch (mrb_type(obj)) {
211
- case MRB_TT_CLASS:
212
- case MRB_TT_SCLASS:
213
- break;
214
- default:
215
- clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass));
216
- break;
217
- }
218
- clone->super = klass->super;
219
- if (klass->iv) {
220
- mrb_iv_copy(mrb, mrb_obj_value(clone), mrb_obj_value(klass));
221
- mrb_obj_iv_set(mrb, (struct RObject*)clone, mrb_intern_lit(mrb, "__attached__"), obj);
222
- }
223
- if (klass->mt) {
224
- clone->mt = kh_copy(mt, mrb, klass->mt);
225
- }
226
- else {
227
- clone->mt = kh_init(mt, mrb);
228
- }
229
- clone->tt = MRB_TT_SCLASS;
230
- return clone;
231
- }
232
- }
233
-
234
- static void
235
- copy_class(mrb_state *mrb, mrb_value dst, mrb_value src)
236
- {
237
- struct RClass *dc = mrb_class_ptr(dst);
238
- struct RClass *sc = mrb_class_ptr(src);
239
- /* if the origin is not the same as the class, then the origin and
240
- the current class need to be copied */
241
- if (sc->flags & MRB_FL_CLASS_IS_PREPENDED) {
242
- struct RClass *c0 = sc->super;
243
- struct RClass *c1 = dc;
244
-
245
- /* copy prepended iclasses */
246
- while (!(c0->flags & MRB_FL_CLASS_IS_ORIGIN)) {
247
- c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
248
- c1 = c1->super;
249
- c0 = c0->super;
250
- }
251
- c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
252
- c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
253
- }
254
- if (sc->mt) {
255
- dc->mt = kh_copy(mt, mrb, sc->mt);
256
- }
257
- else {
258
- dc->mt = kh_init(mt, mrb);
259
- }
260
- dc->super = sc->super;
261
- MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc));
262
- }
263
-
264
- static void
265
- init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
266
- {
267
- switch (mrb_type(obj)) {
268
- case MRB_TT_ICLASS:
269
- copy_class(mrb, dest, obj);
270
- return;
271
- case MRB_TT_CLASS:
272
- case MRB_TT_MODULE:
273
- copy_class(mrb, dest, obj);
274
- mrb_iv_copy(mrb, dest, obj);
275
- mrb_iv_remove(mrb, dest, mrb_intern_lit(mrb, "__classname__"));
276
- break;
277
- case MRB_TT_OBJECT:
278
- case MRB_TT_SCLASS:
279
- case MRB_TT_HASH:
280
- case MRB_TT_DATA:
281
- case MRB_TT_EXCEPTION:
282
- mrb_iv_copy(mrb, dest, obj);
283
- break;
284
- case MRB_TT_ISTRUCT:
285
- mrb_istruct_copy(dest, obj);
286
- break;
287
-
288
- default:
289
- break;
290
- }
291
- mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
292
- }
293
-
294
- /* 15.3.1.3.8 */
295
- /*
296
- * call-seq:
297
- * obj.clone -> an_object
298
- *
299
- * Produces a shallow copy of <i>obj</i>---the instance variables of
300
- * <i>obj</i> are copied, but not the objects they reference. Copies
301
- * the frozen state of <i>obj</i>. See also the discussion
302
- * under <code>Object#dup</code>.
303
- *
304
- * class Klass
305
- * attr_accessor :str
306
- * end
307
- * s1 = Klass.new #=> #<Klass:0x401b3a38>
308
- * s1.str = "Hello" #=> "Hello"
309
- * s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
310
- * s2.str[1,4] = "i" #=> "i"
311
- * s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
312
- * s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
313
- *
314
- * This method may have class-specific behavior. If so, that
315
- * behavior will be documented under the #+initialize_copy+ method of
316
- * the class.
317
- *
318
- * Some Class(True False Nil Symbol Fixnum Float) Object cannot clone.
319
- */
320
- MRB_API mrb_value
321
- mrb_obj_clone(mrb_state *mrb, mrb_value self)
322
- {
323
- struct RObject *p;
324
- mrb_value clone;
325
-
326
- if (mrb_immediate_p(self)) {
327
- return self;
328
- }
329
- if (mrb_sclass_p(self)) {
330
- mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
331
- }
332
- p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
333
- p->c = mrb_singleton_class_clone(mrb, self);
334
- mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
335
- clone = mrb_obj_value(p);
336
- init_copy(mrb, clone, self);
337
- p->flags |= mrb_obj_ptr(self)->flags & MRB_FL_OBJ_IS_FROZEN;
338
-
339
- return clone;
340
- }
341
-
342
- /* 15.3.1.3.9 */
343
- /*
344
- * call-seq:
345
- * obj.dup -> an_object
346
- *
347
- * Produces a shallow copy of <i>obj</i>---the instance variables of
348
- * <i>obj</i> are copied, but not the objects they reference.
349
- * <code>dup</code> copies the frozen state of <i>obj</i>. See also
350
- * the discussion under <code>Object#clone</code>. In general,
351
- * <code>clone</code> and <code>dup</code> may have different semantics
352
- * in descendant classes. While <code>clone</code> is used to duplicate
353
- * an object, including its internal state, <code>dup</code> typically
354
- * uses the class of the descendant object to create the new instance.
355
- *
356
- * This method may have class-specific behavior. If so, that
357
- * behavior will be documented under the #+initialize_copy+ method of
358
- * the class.
359
- */
360
-
361
- MRB_API mrb_value
362
- mrb_obj_dup(mrb_state *mrb, mrb_value obj)
363
- {
364
- struct RBasic *p;
365
- mrb_value dup;
366
-
367
- if (mrb_immediate_p(obj)) {
368
- return obj;
369
- }
370
- if (mrb_sclass_p(obj)) {
371
- mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
372
- }
373
- p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
374
- dup = mrb_obj_value(p);
375
- init_copy(mrb, dup, obj);
376
-
377
- return dup;
378
- }
379
-
380
221
  static mrb_value
381
- mrb_obj_extend(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value obj)
222
+ mrb_obj_extend(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value obj)
382
223
  {
383
224
  mrb_int i;
384
225
 
@@ -389,8 +230,8 @@ mrb_obj_extend(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value obj)
389
230
  mrb_check_type(mrb, argv[i], MRB_TT_MODULE);
390
231
  }
391
232
  while (argc--) {
392
- mrb_funcall(mrb, argv[argc], "extend_object", 1, obj);
393
- mrb_funcall(mrb, argv[argc], "extended", 1, obj);
233
+ mrb_funcall_id(mrb, argv[argc], MRB_SYM(extend_object), 1, obj);
234
+ mrb_funcall_id(mrb, argv[argc], MRB_SYM(extended), 1, obj);
394
235
  }
395
236
  return obj;
396
237
  }
@@ -423,7 +264,7 @@ mrb_obj_extend(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value obj)
423
264
  static mrb_value
424
265
  mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
425
266
  {
426
- mrb_value *argv;
267
+ const mrb_value *argv;
427
268
  mrb_int argc;
428
269
 
429
270
  mrb_get_args(mrb, "*", &argv, &argc);
@@ -454,20 +295,20 @@ mrb_obj_frozen(mrb_state *mrb, mrb_value self)
454
295
  * call-seq:
455
296
  * obj.hash -> fixnum
456
297
  *
457
- * Generates a <code>Fixnum</code> hash value for this object. This
298
+ * Generates a <code>Integer</code> hash value for this object. This
458
299
  * function must have the property that <code>a.eql?(b)</code> implies
459
300
  * <code>a.hash == b.hash</code>. The hash value is used by class
460
301
  * <code>Hash</code>. Any hash value that exceeds the capacity of a
461
- * <code>Fixnum</code> will be truncated before being used.
302
+ * <code>Integer</code> will be truncated before being used.
462
303
  */
463
304
  static mrb_value
464
305
  mrb_obj_hash(mrb_state *mrb, mrb_value self)
465
306
  {
466
- return mrb_fixnum_value(mrb_obj_id(self));
307
+ return mrb_int_value(mrb, mrb_obj_id(self));
467
308
  }
468
309
 
469
310
  /* 15.3.1.3.16 */
470
- static mrb_value
311
+ mrb_value
471
312
  mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
472
313
  {
473
314
  mrb_value orig = mrb_get_arg1(mrb);
@@ -479,7 +320,6 @@ mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
479
320
  return self;
480
321
  }
481
322
 
482
-
483
323
  MRB_API mrb_bool
484
324
  mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c)
485
325
  {
@@ -498,11 +338,11 @@ mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c)
498
338
  static mrb_value
499
339
  obj_is_instance_of(mrb_state *mrb, mrb_value self)
500
340
  {
501
- mrb_value arg;
341
+ struct RClass *c;
502
342
 
503
- mrb_get_args(mrb, "C", &arg);
343
+ mrb_get_args(mrb, "c", &c);
504
344
 
505
- return mrb_bool_value(mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg)));
345
+ return mrb_bool_value(mrb_obj_is_instance_of(mrb, self, c));
506
346
  }
507
347
 
508
348
  /* 15.3.1.3.24 */
@@ -535,16 +375,13 @@ obj_is_instance_of(mrb_state *mrb, mrb_value self)
535
375
  static mrb_value
536
376
  mrb_obj_is_kind_of_m(mrb_state *mrb, mrb_value self)
537
377
  {
538
- mrb_value arg;
378
+ struct RClass *c;
539
379
 
540
- mrb_get_args(mrb, "C", &arg);
380
+ mrb_get_args(mrb, "c", &c);
541
381
 
542
- return mrb_bool_value(mrb_obj_is_kind_of(mrb, self, mrb_class_ptr(arg)));
382
+ return mrb_bool_value(mrb_obj_is_kind_of(mrb, self, c));
543
383
  }
544
384
 
545
- KHASH_DECLARE(st, mrb_sym, char, FALSE)
546
- KHASH_DEFINE(st, mrb_sym, char, FALSE, kh_int_hash_func, kh_int_hash_equal)
547
-
548
385
  /* 15.3.1.3.32 */
549
386
  /*
550
387
  * call_seq:
@@ -687,7 +524,7 @@ static mrb_value
687
524
  mrb_obj_missing(mrb_state *mrb, mrb_value mod)
688
525
  {
689
526
  mrb_sym name;
690
- mrb_value *a;
527
+ const mrb_value *a;
691
528
  mrb_int alen;
692
529
 
693
530
  mrb_get_args(mrb, "n*!", &name, &a, &alen);
@@ -727,7 +564,7 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
727
564
  mrb_get_args(mrb, "n|b", &id, &priv);
728
565
  respond_to_p = basic_obj_respond_to(mrb, self, id, !priv);
729
566
  if (!respond_to_p) {
730
- rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
567
+ rtm_id = MRB_SYM_Q(respond_to_missing);
731
568
  if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) {
732
569
  mrb_value args[2], v;
733
570
  args[0] = mrb_symbol_value(id);
@@ -744,9 +581,27 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self)
744
581
  {
745
582
  mrb_value v = mrb_get_arg1(mrb);
746
583
  mrb_int i, len;
747
- mrb_sym eqq = mrb_intern_lit(mrb, "===");
748
- mrb_value ary = mrb_ary_splat(mrb, self);
584
+ mrb_sym eqq = MRB_OPSYM(eqq);
585
+ mrb_value ary;
749
586
 
587
+ if (mrb_array_p(self)) {
588
+ ary = self;
589
+ }
590
+ else if (mrb_nil_p(self)) {
591
+ return mrb_false_value();
592
+ }
593
+ else if (!mrb_respond_to(mrb, self, mrb_intern_lit(mrb, "to_a"))) {
594
+ mrb_value c = mrb_funcall_argv(mrb, self, eqq, 1, &v);
595
+ if (mrb_test(c)) return mrb_true_value();
596
+ return mrb_false_value();
597
+ }
598
+ else {
599
+ ary = mrb_funcall(mrb, self, "to_a", 0);
600
+ if (mrb_nil_p(ary)) {
601
+ return mrb_funcall_argv(mrb, self, eqq, 1, &v);
602
+ }
603
+ mrb_ensure_array_type(mrb, ary);
604
+ }
750
605
  len = RARRAY_LEN(ary);
751
606
  for (i=0; i<len; i++) {
752
607
  mrb_value c = mrb_funcall_argv(mrb, mrb_ary_entry(ary, i), eqq, 1, &v);
@@ -15,6 +15,7 @@
15
15
  #include <mruby/debug.h>
16
16
  #include <mruby/error.h>
17
17
  #include <mruby/data.h>
18
+ #include <mruby/endian.h>
18
19
 
19
20
  #if SIZE_MAX < UINT32_MAX
20
21
  # error size_t must be at least 32 bits wide
@@ -25,58 +26,56 @@
25
26
 
26
27
  #define SIZE_ERROR_MUL(nmemb, size) ((size_t)(nmemb) > SIZE_MAX / (size))
27
28
 
28
- static size_t
29
- skip_padding(const uint8_t *buf)
30
- {
31
- const size_t align = MRB_DUMP_ALIGNMENT;
32
- return -(intptr_t)buf & (align-1);
33
- }
34
-
35
- static size_t
36
- offset_crc_body(void)
37
- {
38
- struct rite_binary_header header;
39
- return ((uint8_t *)header.binary_crc - (uint8_t *)&header) + sizeof(header.binary_crc);
40
- }
41
-
42
- #ifndef MRB_WITHOUT_FLOAT
43
- double mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck);
29
+ #define DEFINE_READ_IREP_FUNC(funcdecl, basecall) \
30
+ funcdecl \
31
+ { \
32
+ int ai = mrb_gc_arena_save(mrb); \
33
+ struct RProc *proc = basecall; \
34
+ struct mrb_irep *irep = (mrb_irep*)(proc ? proc->body.irep : NULL); \
35
+ if (irep) proc->body.irep = NULL; \
36
+ mrb_gc_arena_restore(mrb, ai); \
37
+ return irep; \
38
+ }
44
39
 
40
+ #ifndef MRB_NO_FLOAT
45
41
  static double
46
- str_to_double(mrb_state *mrb, const char *p, size_t len)
42
+ str_to_double(mrb_state *mrb, const char *p)
47
43
  {
48
- /* `i`, `inf`, `infinity` */
49
- if (len > 0 && p[0] == 'i') return INFINITY;
50
-
51
- /* `I`, `-inf`, `-infinity` */
52
- if (p[0] == 'I' || (len > 1 && p[0] == '-' && p[1] == 'i')) return -INFINITY;
53
- return mrb_str_len_to_dbl(mrb, p, len, TRUE);
44
+ /* dump IEEE754 little endian binary */
45
+ union {
46
+ char s[sizeof(double)];
47
+ double f;
48
+ } u;
49
+
50
+ if (littleendian) {
51
+ memcpy(u.s, p, sizeof(double));
52
+ }
53
+ else {
54
+ size_t i;
55
+ for (i=0; i<sizeof(double); i++) {
56
+ u.s[i] = p[sizeof(double)-i-1];
57
+ }
58
+ }
59
+ return u.f;
54
60
  }
55
61
  #endif
56
62
 
57
- mrb_value mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, int badcheck);
58
-
59
- static void
60
- tempirep_free(mrb_state *mrb, void *p)
61
- {
62
- if (p) mrb_irep_decref(mrb, (mrb_irep *)p);
63
- }
64
-
65
- static const mrb_data_type tempirep_type = { "temporary irep", tempirep_free };
63
+ mrb_value mrb_str_len_to_inum(mrb_state *mrb, const char *str, size_t len, mrb_int base, int badcheck);
66
64
 
67
- static mrb_irep*
68
- read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags)
65
+ static mrb_bool
66
+ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags, mrb_irep **irepp)
69
67
  {
70
68
  int i;
71
69
  const uint8_t *src = bin;
72
70
  ptrdiff_t diff;
73
71
  uint16_t tt, pool_data_len, snl;
74
72
  int plen;
75
- struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
76
- mrb_irep *irep = mrb_add_irep(mrb);
73
+ mrb_pool_value *pool;
74
+ mrb_sym *syms;
77
75
  int ai = mrb_gc_arena_save(mrb);
76
+ mrb_irep *irep = mrb_add_irep(mrb);
78
77
 
79
- irep_obj->data = irep;
78
+ *irepp = irep;
80
79
 
81
80
  /* skip record size */
82
81
  src += sizeof(uint32_t);
@@ -90,163 +89,199 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
90
89
  src += sizeof(uint16_t);
91
90
 
92
91
  /* number of child irep */
93
- irep->rlen = (size_t)bin_to_uint16(src);
92
+ irep->rlen = (uint8_t)bin_to_uint16(src);
94
93
  src += sizeof(uint16_t);
95
94
 
96
95
  /* Binary Data Section */
97
- /* ISEQ BLOCK */
98
- irep->ilen = (uint16_t)bin_to_uint32(src);
99
- src += sizeof(uint32_t);
100
- src += skip_padding(src);
96
+ /* ISEQ BLOCK (and CATCH HANDLER TABLE BLOCK) */
97
+ irep->clen = bin_to_uint16(src); /* number of catch handler */
98
+ src += sizeof(uint16_t);
99
+ irep->ilen = bin_to_uint16(src);
100
+ src += sizeof(uint16_t);
101
101
 
102
102
  if (irep->ilen > 0) {
103
+ size_t data_len = sizeof(mrb_code) * irep->ilen +
104
+ sizeof(struct mrb_irep_catch_handler) * irep->clen;
105
+ mrb_static_assert1(sizeof(struct mrb_irep_catch_handler) == 13);
103
106
  if (SIZE_ERROR_MUL(irep->ilen, sizeof(mrb_code))) {
104
- return NULL;
107
+ return FALSE;
105
108
  }
106
109
  if ((flags & FLAG_SRC_MALLOC) == 0) {
107
110
  irep->iseq = (mrb_code*)src;
108
- src += sizeof(mrb_code) * irep->ilen;
109
111
  irep->flags |= MRB_ISEQ_NO_FREE;
110
112
  }
111
113
  else {
112
- size_t data_len = sizeof(mrb_code) * irep->ilen;
113
114
  void *buf = mrb_malloc(mrb, data_len);
114
115
  irep->iseq = (mrb_code *)buf;
115
116
  memcpy(buf, src, data_len);
116
- src += data_len;
117
117
  }
118
+ src += data_len;
118
119
  }
119
120
 
120
121
  /* POOL BLOCK */
121
- plen = bin_to_uint32(src); /* number of pool */
122
- src += sizeof(uint32_t);
122
+ plen = bin_to_uint16(src); /* number of pool */
123
+ src += sizeof(uint16_t);
123
124
  if (plen > 0) {
124
125
  if (SIZE_ERROR_MUL(plen, sizeof(mrb_value))) {
125
- return NULL;
126
+ return FALSE;
126
127
  }
127
- irep->pool = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * plen);
128
+ irep->pool = pool = (mrb_pool_value*)mrb_calloc(mrb, sizeof(mrb_pool_value), plen);
128
129
 
129
130
  for (i = 0; i < plen; i++) {
130
- const char *s;
131
131
  mrb_bool st = (flags & FLAG_SRC_MALLOC)==0;
132
132
 
133
133
  tt = *src++; /* pool TT */
134
- pool_data_len = bin_to_uint16(src); /* pool data length */
135
- src += sizeof(uint16_t);
136
- s = (const char*)src;
137
- src += pool_data_len;
138
134
  switch (tt) { /* pool data */
139
- case IREP_TT_FIXNUM: {
140
- mrb_value num = mrb_str_len_to_inum(mrb, s, pool_data_len, 10, FALSE);
141
- #ifdef MRB_WITHOUT_FLOAT
142
- irep->pool[i] = num;
135
+ case IREP_TT_INT32:
136
+ {
137
+ mrb_int v = (int32_t)bin_to_uint32(src);
138
+ src += sizeof(uint32_t);
139
+ #ifdef MRB_64BIT
140
+ pool[i].tt = IREP_TT_INT64;
141
+ pool[i].u.i64 = (int64_t)v;
143
142
  #else
144
- irep->pool[i] = mrb_float_p(num)? mrb_float_pool(mrb, mrb_float(num)) : num;
143
+ pool[i].tt = IREP_TT_INT32;
144
+ pool[i].u.i32 = v;
145
145
  #endif
146
146
  }
147
147
  break;
148
+ case IREP_TT_INT64:
149
+ #ifdef MRB_64BIT
150
+ {
151
+ uint64_t i64 = bin_to_uint32(src);
152
+ src += sizeof(uint32_t);
153
+ i64 <<= 32;
154
+ i64 |= bin_to_uint32(src);
155
+ src += sizeof(uint32_t);
156
+ pool[i].u.i64 = (int64_t)i64;
157
+ }
158
+ break;
159
+ #else
160
+ return FALSE; /* INT64 not supported on MRB_32BIT */
161
+ #endif
148
162
 
149
- #ifndef MRB_WITHOUT_FLOAT
150
163
  case IREP_TT_FLOAT:
151
- irep->pool[i] = mrb_float_pool(mrb, str_to_double(mrb, s, pool_data_len));
164
+ #ifndef MRB_NO_FLOAT
165
+ pool[i].tt = tt;
166
+ pool[i].u.f = str_to_double(mrb, (const char*)src);
167
+ src += sizeof(double);
152
168
  break;
169
+ #else
170
+ return FALSE; /* MRB_NO_FLOAT */
153
171
  #endif
154
172
 
155
- case IREP_TT_STRING:
156
- irep->pool[i] = mrb_str_pool(mrb, s, pool_data_len, st);
173
+ case IREP_TT_STR:
174
+ pool_data_len = bin_to_uint16(src); /* pool data length */
175
+ src += sizeof(uint16_t);
176
+ if (st) {
177
+ pool[i].tt = (pool_data_len<<2) | IREP_TT_SSTR;
178
+ pool[i].u.str = (const char*)src;
179
+ }
180
+ else {
181
+ char *p;
182
+ pool[i].tt = (pool_data_len<<2) | IREP_TT_STR;
183
+ p = (char*)mrb_malloc(mrb, pool_data_len+1);
184
+ memcpy(p, src, pool_data_len+1);
185
+ pool[i].u.str = (const char*)p;
186
+ }
187
+ src += pool_data_len + 1;
157
188
  break;
158
189
 
159
190
  default:
160
191
  /* should not happen */
161
- irep->pool[i] = mrb_nil_value();
162
- break;
192
+ return FALSE;
163
193
  }
164
- irep->plen++;
165
- mrb_gc_arena_restore(mrb, ai);
194
+ irep->plen = i+1;
166
195
  }
167
196
  }
168
197
 
169
198
  /* SYMS BLOCK */
170
- irep->slen = (uint16_t)bin_to_uint32(src); /* syms length */
171
- src += sizeof(uint32_t);
199
+ irep->slen = bin_to_uint16(src); /* syms length */
200
+ src += sizeof(uint16_t);
172
201
  if (irep->slen > 0) {
173
202
  if (SIZE_ERROR_MUL(irep->slen, sizeof(mrb_sym))) {
174
- return NULL;
203
+ return FALSE;
175
204
  }
176
- irep->syms = (mrb_sym *)mrb_malloc(mrb, sizeof(mrb_sym) * irep->slen);
205
+ irep->syms = syms = (mrb_sym *)mrb_malloc(mrb, sizeof(mrb_sym) * irep->slen);
177
206
 
178
207
  for (i = 0; i < irep->slen; i++) {
179
208
  snl = bin_to_uint16(src); /* symbol name length */
180
209
  src += sizeof(uint16_t);
181
210
 
182
211
  if (snl == MRB_DUMP_NULL_SYM_LEN) {
183
- irep->syms[i] = 0;
212
+ syms[i] = 0;
184
213
  continue;
185
214
  }
186
215
 
187
216
  if (flags & FLAG_SRC_MALLOC) {
188
- irep->syms[i] = mrb_intern(mrb, (char *)src, snl);
217
+ syms[i] = mrb_intern(mrb, (char *)src, snl);
189
218
  }
190
219
  else {
191
- irep->syms[i] = mrb_intern_static(mrb, (char *)src, snl);
220
+ syms[i] = mrb_intern_static(mrb, (char *)src, snl);
192
221
  }
193
222
  src += snl + 1;
194
-
195
223
  mrb_gc_arena_restore(mrb, ai);
196
224
  }
197
225
  }
198
226
 
199
- irep->reps = (mrb_irep**)mrb_calloc(mrb, irep->rlen, sizeof(mrb_irep*));
200
-
201
227
  diff = src - bin;
202
228
  mrb_assert_int_fit(ptrdiff_t, diff, size_t, SIZE_MAX);
203
229
  *len = (size_t)diff;
204
230
 
205
- irep_obj->data = NULL;
206
-
207
- return irep;
231
+ return TRUE;
208
232
  }
209
233
 
210
- static mrb_irep*
211
- read_irep_record(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags)
234
+ static mrb_bool
235
+ read_irep_record(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags, mrb_irep **irepp)
212
236
  {
213
- struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
214
237
  int ai = mrb_gc_arena_save(mrb);
215
- mrb_irep *irep = read_irep_record_1(mrb, bin, len, flags);
238
+ mrb_bool readsuccess = read_irep_record_1(mrb, bin, len, flags, irepp);
239
+ mrb_irep **reps;
216
240
  int i;
217
241
 
218
242
  mrb_gc_arena_restore(mrb, ai);
219
- if (irep == NULL) {
220
- return NULL;
243
+ if (!readsuccess) {
244
+ return FALSE;
221
245
  }
222
246
 
223
- irep_obj->data = irep;
247
+ reps = (mrb_irep**)mrb_calloc(mrb, (*irepp)->rlen, sizeof(mrb_irep*));
248
+ (*irepp)->reps = (const mrb_irep**)reps;
224
249
 
225
250
  bin += *len;
226
- for (i=0; i<irep->rlen; i++) {
251
+ for (i=0; i<(*irepp)->rlen; i++) {
227
252
  size_t rlen;
228
253
 
229
- irep->reps[i] = read_irep_record(mrb, bin, &rlen, flags);
254
+ readsuccess = read_irep_record(mrb, bin, &rlen, flags, &reps[i]);
230
255
  mrb_gc_arena_restore(mrb, ai);
231
- if (irep->reps[i] == NULL) {
232
- return NULL;
256
+ if (!readsuccess) {
257
+ return FALSE;
233
258
  }
234
259
  bin += rlen;
235
260
  *len += rlen;
236
261
  }
237
262
 
238
- irep_obj->data = NULL;
239
-
240
- return irep;
263
+ return TRUE;
241
264
  }
242
265
 
243
266
  static mrb_irep*
244
- read_section_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
267
+ read_section_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags, struct RProc **proc)
245
268
  {
246
269
  size_t len;
247
270
 
271
+ /*
272
+ * This proc object keeps all the data in progress to avoid memory leaks
273
+ * if something goes wrong while reading irep.
274
+ */
275
+ *proc = mrb_proc_new(mrb, NULL);
276
+
277
+ mrb_irep **irepp = (mrb_irep**)&(*proc)->body.irep;
248
278
  bin += sizeof(struct rite_section_irep_header);
249
- return read_irep_record(mrb, bin, &len, flags);
279
+ if (read_irep_record(mrb, bin, &len, flags, irepp)) {
280
+ return *irepp;
281
+ }
282
+ else {
283
+ return NULL;
284
+ }
250
285
  }
251
286
 
252
287
  static int
@@ -257,25 +292,26 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t *
257
292
  size_t record_size;
258
293
  uint16_t f_idx;
259
294
  int i;
295
+ mrb_irep_debug_info *debug;
260
296
 
261
297
  if (irep->debug_info) { return MRB_DUMP_INVALID_IREP; }
262
298
 
263
- irep->debug_info = (mrb_irep_debug_info*)mrb_calloc(mrb, 1, sizeof(mrb_irep_debug_info));
264
- irep->debug_info->pc_count = (uint32_t)irep->ilen;
299
+ irep->debug_info = debug = (mrb_irep_debug_info*)mrb_calloc(mrb, 1, sizeof(mrb_irep_debug_info));
300
+ debug->pc_count = (uint32_t)irep->ilen;
265
301
 
266
302
  record_size = (size_t)bin_to_uint32(bin);
267
303
  bin += sizeof(uint32_t);
268
304
 
269
- irep->debug_info->flen = bin_to_uint16(bin);
270
- irep->debug_info->files = (mrb_irep_debug_info_file**)mrb_calloc(mrb, irep->debug_info->flen, sizeof(mrb_irep_debug_info*));
305
+ debug->flen = bin_to_uint16(bin);
306
+ debug->files = (mrb_irep_debug_info_file**)mrb_calloc(mrb, irep->debug_info->flen, sizeof(mrb_irep_debug_info*));
271
307
  bin += sizeof(uint16_t);
272
308
 
273
- for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
309
+ for (f_idx = 0; f_idx < debug->flen; ++f_idx) {
274
310
  mrb_irep_debug_info_file *file;
275
311
  uint16_t filename_idx;
276
312
 
277
313
  file = (mrb_irep_debug_info_file *)mrb_calloc(mrb, 1, sizeof(*file));
278
- irep->debug_info->files[f_idx] = file;
314
+ debug->files[f_idx] = file;
279
315
 
280
316
  file->start_pos = bin_to_uint32(bin);
281
317
  bin += sizeof(uint32_t);
@@ -329,7 +365,7 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t *
329
365
  size_t len;
330
366
  int ret;
331
367
 
332
- ret = read_debug_record(mrb, bin, irep->reps[i], &len, filenames, filenames_len);
368
+ ret = read_debug_record(mrb, bin, (mrb_irep*)irep->reps[i], &len, filenames, filenames_len);
333
369
  if (ret != MRB_DUMP_OK) return ret;
334
370
  bin += len;
335
371
  }
@@ -393,34 +429,31 @@ static int
393
429
  read_lv_record(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, size_t *record_len, mrb_sym const *syms, uint32_t syms_len)
394
430
  {
395
431
  const uint8_t *bin = start;
432
+ mrb_sym *lv;
396
433
  ptrdiff_t diff;
397
434
  int i;
398
435
 
399
- irep->lv = (struct mrb_locals*)mrb_malloc(mrb, sizeof(struct mrb_locals) * (irep->nlocals - 1));
436
+ irep->lv = lv = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) * (irep->nlocals - 1));
400
437
 
401
- for (i = 0; i + 1< irep->nlocals; ++i) {
438
+ for (i = 0; i + 1 < irep->nlocals; ++i) {
402
439
  uint16_t const sym_idx = bin_to_uint16(bin);
403
440
  bin += sizeof(uint16_t);
404
441
  if (sym_idx == RITE_LV_NULL_MARK) {
405
- irep->lv[i].name = 0;
406
- irep->lv[i].r = 0;
442
+ lv[i] = 0;
407
443
  }
408
444
  else {
409
445
  if (sym_idx >= syms_len) {
410
446
  return MRB_DUMP_GENERAL_FAILURE;
411
447
  }
412
- irep->lv[i].name = syms[sym_idx];
413
-
414
- irep->lv[i].r = bin_to_uint16(bin);
448
+ lv[i] = syms[sym_idx];
415
449
  }
416
- bin += sizeof(uint16_t);
417
450
  }
418
451
 
419
452
  for (i = 0; i < irep->rlen; ++i) {
420
453
  size_t len;
421
454
  int ret;
422
455
 
423
- ret = read_lv_record(mrb, bin, irep->reps[i], &len, syms, syms_len);
456
+ ret = read_lv_record(mrb, bin, (mrb_irep*)irep->reps[i], &len, syms, syms_len);
424
457
  if (ret != MRB_DUMP_OK) return ret;
425
458
  bin += len;
426
459
  }
@@ -479,7 +512,7 @@ lv_exit:
479
512
  }
480
513
 
481
514
  static int
482
- read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_t *crc, uint8_t *flags)
515
+ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint8_t *flags)
483
516
  {
484
517
  const struct rite_binary_header *header = (const struct rite_binary_header *)bin;
485
518
 
@@ -491,13 +524,15 @@ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_
491
524
  return MRB_DUMP_INVALID_FILE_HEADER;
492
525
  }
493
526
 
494
- if (memcmp(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version)) != 0) {
527
+ /* if major version is different, they are incompatible */
528
+ if (memcmp(header->major_version, RITE_BINARY_MAJOR_VER, sizeof(header->major_version)) != 0) {
495
529
  return MRB_DUMP_INVALID_FILE_HEADER;
496
530
  }
497
-
498
- if (crc) {
499
- *crc = bin_to_uint16(header->binary_crc);
531
+ /* if minor version is different, we can accept the older version */
532
+ if (memcmp(header->minor_version, RITE_BINARY_MINOR_VER, sizeof(header->minor_version)) > 0) {
533
+ return MRB_DUMP_INVALID_FILE_HEADER;
500
534
  }
535
+
501
536
  *bin_size = (size_t)bin_to_uint32(header->binary_size);
502
537
 
503
538
  if (bufsize < *bin_size) {
@@ -507,40 +542,30 @@ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_
507
542
  return MRB_DUMP_OK;
508
543
  }
509
544
 
510
- static mrb_irep*
545
+ static struct RProc*
511
546
  read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
512
547
  {
513
548
  int result;
514
- struct RData *irep_obj = NULL;
549
+ struct RProc *proc = NULL;
515
550
  mrb_irep *irep = NULL;
516
551
  const struct rite_section_header *section_header;
517
- uint16_t crc;
518
552
  size_t bin_size = 0;
519
- size_t n;
520
553
 
521
554
  if ((mrb == NULL) || (bin == NULL)) {
522
555
  return NULL;
523
556
  }
524
557
 
525
- result = read_binary_header(bin, bufsize, &bin_size, &crc, &flags);
558
+ result = read_binary_header(bin, bufsize, &bin_size, &flags);
526
559
  if (result != MRB_DUMP_OK) {
527
560
  return NULL;
528
561
  }
529
562
 
530
- n = offset_crc_body();
531
- if (crc != calc_crc_16_ccitt(bin + n, bin_size - n, 0)) {
532
- return NULL;
533
- }
534
-
535
- irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
536
-
537
563
  bin += sizeof(struct rite_binary_header);
538
564
  do {
539
565
  section_header = (const struct rite_section_header *)bin;
540
566
  if (memcmp(section_header->section_ident, RITE_SECTION_IREP_IDENT, sizeof(section_header->section_ident)) == 0) {
541
- irep = read_section_irep(mrb, bin, flags);
567
+ irep = read_section_irep(mrb, bin, flags, &proc);
542
568
  if (!irep) return NULL;
543
- irep_obj->data = irep;
544
569
  }
545
570
  else if (memcmp(section_header->section_ident, RITE_SECTION_DEBUG_IDENT, sizeof(section_header->section_ident)) == 0) {
546
571
  if (!irep) return NULL; /* corrupted data */
@@ -559,13 +584,11 @@ read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
559
584
  bin += bin_to_uint32(section_header->section_size);
560
585
  } while (memcmp(section_header->section_ident, RITE_BINARY_EOF, sizeof(section_header->section_ident)) != 0);
561
586
 
562
- irep_obj->data = NULL;
563
-
564
- return irep;
587
+ return proc;
565
588
  }
566
589
 
567
- mrb_irep*
568
- mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
590
+ static struct RProc*
591
+ mrb_proc_read_irep(mrb_state *mrb, const uint8_t *bin)
569
592
  {
570
593
  #if defined(MRB_USE_LINK_TIME_RO_DATA_P) || defined(MRB_USE_CUSTOM_RO_DATA_P)
571
594
  uint8_t flags = mrb_ro_data_p((char*)bin) ? FLAG_SRC_STATIC : FLAG_SRC_MALLOC;
@@ -576,34 +599,38 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
576
599
  return read_irep(mrb, bin, (size_t)-1, flags);
577
600
  }
578
601
 
579
- MRB_API mrb_irep*
580
- mrb_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
602
+ DEFINE_READ_IREP_FUNC(
603
+ mrb_irep *mrb_read_irep(mrb_state *mrb, const uint8_t *bin),
604
+ mrb_proc_read_irep(mrb, bin))
605
+
606
+ static struct RProc*
607
+ mrb_proc_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
581
608
  {
582
609
  return read_irep(mrb, (const uint8_t *)buf, bufsize, FLAG_SRC_MALLOC);
583
610
  }
584
611
 
612
+ DEFINE_READ_IREP_FUNC(
613
+ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize),
614
+ mrb_proc_read_irep_buf(mrb, buf, bufsize))
615
+
585
616
  void mrb_exc_set(mrb_state *mrb, mrb_value exc);
586
617
 
587
618
  static void
588
619
  irep_error(mrb_state *mrb)
589
620
  {
590
- mrb_exc_set(mrb, mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "irep load error"));
621
+ mrb_exc_set(mrb, mrb_exc_new_lit(mrb, E_SCRIPT_ERROR, "irep load error"));
591
622
  }
592
623
 
593
624
  void mrb_codedump_all(mrb_state*, struct RProc*);
594
625
 
595
626
  static mrb_value
596
- load_irep(mrb_state *mrb, mrb_irep *irep, mrbc_context *c)
627
+ load_irep(mrb_state *mrb, struct RProc *proc, mrbc_context *c)
597
628
  {
598
- struct RProc *proc;
599
-
600
- if (!irep) {
629
+ if (!proc || !proc->body.irep) {
601
630
  irep_error(mrb);
602
631
  return mrb_nil_value();
603
632
  }
604
- proc = mrb_proc_new(mrb, irep);
605
633
  proc->c = NULL;
606
- mrb_irep_decref(mrb, irep);
607
634
  if (c && c->dump_result) mrb_codedump_all(mrb, proc);
608
635
  if (c && c->no_exec) return mrb_obj_value(proc);
609
636
  return mrb_top_run(mrb, proc, mrb_top_self(mrb), 0);
@@ -612,22 +639,15 @@ load_irep(mrb_state *mrb, mrb_irep *irep, mrbc_context *c)
612
639
  MRB_API mrb_value
613
640
  mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
614
641
  {
615
- struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
616
- mrb_irep *irep = mrb_read_irep(mrb, bin);
617
- mrb_value ret;
618
-
619
- irep_obj->data = irep;
620
- mrb_irep_incref(mrb, irep);
621
- ret = load_irep(mrb, irep, c);
622
- irep_obj->data = NULL;
623
- mrb_irep_decref(mrb, irep);
624
- return ret;
642
+ struct RProc *proc = mrb_proc_read_irep(mrb, bin);
643
+ if (!proc) return mrb_undef_value();
644
+ return load_irep(mrb, proc, c);
625
645
  }
626
646
 
627
647
  MRB_API mrb_value
628
648
  mrb_load_irep_buf_cxt(mrb_state *mrb, const void *buf, size_t bufsize, mrbc_context *c)
629
649
  {
630
- return load_irep(mrb, mrb_read_irep_buf(mrb, buf, bufsize), c);
650
+ return load_irep(mrb, mrb_proc_read_irep_buf(mrb, buf, bufsize), c);
631
651
  }
632
652
 
633
653
  MRB_API mrb_value
@@ -642,12 +662,18 @@ mrb_load_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
642
662
  return mrb_load_irep_buf_cxt(mrb, buf, bufsize, NULL);
643
663
  }
644
664
 
645
- #ifndef MRB_DISABLE_STDIO
665
+ MRB_API mrb_value
666
+ mrb_load_proc(mrb_state *mrb, const struct RProc *proc)
667
+ {
668
+ return mrb_vm_run(mrb, proc, mrb_top_self(mrb), 0);
669
+ }
670
+
671
+ #ifndef MRB_NO_STDIO
646
672
 
647
- mrb_irep*
648
- mrb_read_irep_file(mrb_state *mrb, FILE* fp)
673
+ static struct RProc*
674
+ mrb_proc_read_irep_file(mrb_state *mrb, FILE *fp)
649
675
  {
650
- mrb_irep *irep = NULL;
676
+ struct RProc *proc = NULL;
651
677
  uint8_t *buf;
652
678
  const size_t header_size = sizeof(struct rite_binary_header);
653
679
  size_t buf_size = 0;
@@ -662,7 +688,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
662
688
  if (fread(buf, header_size, 1, fp) == 0) {
663
689
  goto irep_exit;
664
690
  }
665
- result = read_binary_header(buf, (size_t)-1, &buf_size, NULL, &flags);
691
+ result = read_binary_header(buf, (size_t)-1, &buf_size, &flags);
666
692
  if (result != MRB_DUMP_OK || buf_size <= header_size) {
667
693
  goto irep_exit;
668
694
  }
@@ -671,17 +697,21 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
671
697
  if (fread(buf+header_size, buf_size-header_size, 1, fp) == 0) {
672
698
  goto irep_exit;
673
699
  }
674
- irep = read_irep(mrb, buf, (size_t)-1, FLAG_SRC_MALLOC);
700
+ proc = read_irep(mrb, buf, (size_t)-1, FLAG_SRC_MALLOC);
675
701
 
676
702
  irep_exit:
677
703
  mrb_free(mrb, buf);
678
- return irep;
704
+ return proc;
679
705
  }
680
706
 
707
+ DEFINE_READ_IREP_FUNC(
708
+ mrb_irep *mrb_read_irep_file(mrb_state *mrb, FILE *fp),
709
+ mrb_proc_read_irep_file(mrb, fp))
710
+
681
711
  MRB_API mrb_value
682
712
  mrb_load_irep_file_cxt(mrb_state *mrb, FILE* fp, mrbc_context *c)
683
713
  {
684
- return load_irep(mrb, mrb_read_irep_file(mrb, fp), c);
714
+ return load_irep(mrb, mrb_proc_read_irep_file(mrb, fp), c);
685
715
  }
686
716
 
687
717
  MRB_API mrb_value
@@ -689,4 +719,4 @@ mrb_load_irep_file(mrb_state *mrb, FILE* fp)
689
719
  {
690
720
  return mrb_load_irep_file_cxt(mrb, fp, NULL);
691
721
  }
692
- #endif /* MRB_DISABLE_STDIO */
722
+ #endif /* MRB_NO_STDIO */