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
@@ -1,4 +1,9 @@
1
1
  %{
2
+ /* Workaround for `enable_cxx_exception` (#5199) */
3
+ #if defined __cplusplus && __cplusplus >= 201103L
4
+ # define register
5
+ #endif
6
+
2
7
  struct kwtable {const char *name; int id[2]; enum mrb_lex_state_enum state;};
3
8
  %}
4
9
 
@@ -1,5 +1,5 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$' /home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords */
2
+ /* Command-line: gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$' mrbgems/mruby-compiler/core/keywords */
3
3
 
4
4
  #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
5
5
  && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -28,10 +28,15 @@
28
28
  #error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
29
29
  #endif
30
30
 
31
- #line 1 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
31
+ #line 1 "mrbgems/mruby-compiler/core/keywords"
32
+
33
+ /* Workaround for `enable_cxx_exception` (#5199) */
34
+ #if defined __cplusplus && __cplusplus >= 201103L
35
+ # define register
36
+ #endif
32
37
 
33
38
  struct kwtable {const char *name; int id[2]; enum mrb_lex_state_enum state;};
34
- #line 5 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
39
+ #line 10 "mrbgems/mruby-compiler/core/keywords"
35
40
  struct kwtable;
36
41
 
37
42
  #define TOTAL_KEYWORDS 40
@@ -101,87 +106,87 @@ mrb_reserved_word (register const char *str, register size_t len)
101
106
  static const struct kwtable wordlist[] =
102
107
  {
103
108
  {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
104
- #line 15 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
109
+ #line 20 "mrbgems/mruby-compiler/core/keywords"
105
110
  {"break", {keyword_break, keyword_break}, EXPR_MID},
106
- #line 20 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
111
+ #line 25 "mrbgems/mruby-compiler/core/keywords"
107
112
  {"else", {keyword_else, keyword_else}, EXPR_BEG},
108
- #line 30 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
113
+ #line 35 "mrbgems/mruby-compiler/core/keywords"
109
114
  {"nil", {keyword_nil, keyword_nil}, EXPR_END},
110
- #line 23 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
115
+ #line 28 "mrbgems/mruby-compiler/core/keywords"
111
116
  {"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
112
- #line 22 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
117
+ #line 27 "mrbgems/mruby-compiler/core/keywords"
113
118
  {"end", {keyword_end, keyword_end}, EXPR_END},
114
- #line 39 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
119
+ #line 44 "mrbgems/mruby-compiler/core/keywords"
115
120
  {"then", {keyword_then, keyword_then}, EXPR_BEG},
116
- #line 31 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
121
+ #line 36 "mrbgems/mruby-compiler/core/keywords"
117
122
  {"not", {keyword_not, keyword_not}, EXPR_ARG},
118
- #line 24 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
123
+ #line 29 "mrbgems/mruby-compiler/core/keywords"
119
124
  {"false", {keyword_false, keyword_false}, EXPR_END},
120
- #line 37 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
125
+ #line 42 "mrbgems/mruby-compiler/core/keywords"
121
126
  {"self", {keyword_self, keyword_self}, EXPR_END},
122
- #line 21 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
127
+ #line 26 "mrbgems/mruby-compiler/core/keywords"
123
128
  {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
124
- #line 34 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
129
+ #line 39 "mrbgems/mruby-compiler/core/keywords"
125
130
  {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
126
- #line 40 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
131
+ #line 45 "mrbgems/mruby-compiler/core/keywords"
127
132
  {"true", {keyword_true, keyword_true}, EXPR_END},
128
- #line 43 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
133
+ #line 48 "mrbgems/mruby-compiler/core/keywords"
129
134
  {"until", {keyword_until, modifier_until}, EXPR_VALUE},
130
- #line 42 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
135
+ #line 47 "mrbgems/mruby-compiler/core/keywords"
131
136
  {"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
132
- #line 36 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
137
+ #line 41 "mrbgems/mruby-compiler/core/keywords"
133
138
  {"return", {keyword_return, keyword_return}, EXPR_MID},
134
- #line 18 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
139
+ #line 23 "mrbgems/mruby-compiler/core/keywords"
135
140
  {"def", {keyword_def, keyword_def}, EXPR_FNAME},
136
- #line 13 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
141
+ #line 18 "mrbgems/mruby-compiler/core/keywords"
137
142
  {"and", {keyword_and, keyword_and}, EXPR_VALUE},
138
- #line 19 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
143
+ #line 24 "mrbgems/mruby-compiler/core/keywords"
139
144
  {"do", {keyword_do, keyword_do}, EXPR_BEG},
140
- #line 46 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
145
+ #line 51 "mrbgems/mruby-compiler/core/keywords"
141
146
  {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
142
- #line 25 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
147
+ #line 30 "mrbgems/mruby-compiler/core/keywords"
143
148
  {"for", {keyword_for, keyword_for}, EXPR_VALUE},
144
- #line 41 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
149
+ #line 46 "mrbgems/mruby-compiler/core/keywords"
145
150
  {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
146
- #line 32 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
151
+ #line 37 "mrbgems/mruby-compiler/core/keywords"
147
152
  {"or", {keyword_or, keyword_or}, EXPR_VALUE},
148
- #line 27 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
153
+ #line 32 "mrbgems/mruby-compiler/core/keywords"
149
154
  {"in", {keyword_in, keyword_in}, EXPR_VALUE},
150
- #line 44 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
155
+ #line 49 "mrbgems/mruby-compiler/core/keywords"
151
156
  {"when", {keyword_when, keyword_when}, EXPR_VALUE},
152
- #line 35 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
157
+ #line 40 "mrbgems/mruby-compiler/core/keywords"
153
158
  {"retry", {keyword_retry, keyword_retry}, EXPR_END},
154
- #line 26 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
159
+ #line 31 "mrbgems/mruby-compiler/core/keywords"
155
160
  {"if", {keyword_if, modifier_if}, EXPR_VALUE},
156
- #line 16 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
161
+ #line 21 "mrbgems/mruby-compiler/core/keywords"
157
162
  {"case", {keyword_case, keyword_case}, EXPR_VALUE},
158
- #line 33 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
163
+ #line 38 "mrbgems/mruby-compiler/core/keywords"
159
164
  {"redo", {keyword_redo, keyword_redo}, EXPR_END},
160
- #line 29 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
165
+ #line 34 "mrbgems/mruby-compiler/core/keywords"
161
166
  {"next", {keyword_next, keyword_next}, EXPR_MID},
162
- #line 38 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
167
+ #line 43 "mrbgems/mruby-compiler/core/keywords"
163
168
  {"super", {keyword_super, keyword_super}, EXPR_ARG},
164
- #line 28 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
169
+ #line 33 "mrbgems/mruby-compiler/core/keywords"
165
170
  {"module", {keyword_module, keyword_module}, EXPR_VALUE},
166
- #line 14 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
171
+ #line 19 "mrbgems/mruby-compiler/core/keywords"
167
172
  {"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
168
- #line 9 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
173
+ #line 14 "mrbgems/mruby-compiler/core/keywords"
169
174
  {"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
170
- #line 8 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
175
+ #line 13 "mrbgems/mruby-compiler/core/keywords"
171
176
  {"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
172
- #line 7 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
177
+ #line 12 "mrbgems/mruby-compiler/core/keywords"
173
178
  {"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
174
- #line 11 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
179
+ #line 16 "mrbgems/mruby-compiler/core/keywords"
175
180
  {"END", {keyword_END, keyword_END}, EXPR_END},
176
- #line 12 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
181
+ #line 17 "mrbgems/mruby-compiler/core/keywords"
177
182
  {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
178
- #line 10 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
183
+ #line 15 "mrbgems/mruby-compiler/core/keywords"
179
184
  {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
180
185
  {""},
181
- #line 17 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
186
+ #line 22 "mrbgems/mruby-compiler/core/keywords"
182
187
  {"class", {keyword_class, keyword_class}, EXPR_CLASS},
183
188
  {""}, {""},
184
- #line 45 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
189
+ #line 50 "mrbgems/mruby-compiler/core/keywords"
185
190
  {"while", {keyword_while, modifier_while}, EXPR_VALUE}
186
191
  };
187
192
 
@@ -199,5 +204,5 @@ mrb_reserved_word (register const char *str, register size_t len)
199
204
  }
200
205
  return 0;
201
206
  }
202
- #line 47 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
207
+ #line 52 "mrbgems/mruby-compiler/core/keywords"
203
208
 
@@ -21,6 +21,8 @@
21
21
  #include <mruby/error.h>
22
22
  #include <mruby/throw.h>
23
23
  #include <mruby/string.h>
24
+ #include <mruby/dump.h>
25
+ #include <mruby/presym.h>
24
26
  #include "node.h"
25
27
 
26
28
  #define YYLEX_PARAM p
@@ -69,6 +71,7 @@ typedef unsigned int stack_type;
69
71
  #define nsym(x) ((node*)(intptr_t)(x))
70
72
  #define nint(x) ((node*)(intptr_t)(x))
71
73
  #define intn(x) ((int)(intptr_t)(x))
74
+ #define typen(x) ((enum node_type)(intptr_t)(x))
72
75
 
73
76
  #define NUM_SUFFIX_R (1<<0)
74
77
  #define NUM_SUFFIX_I (1<<1)
@@ -87,7 +90,7 @@ intern_gen(parser_state *p, const char *s, size_t len)
87
90
  }
88
91
  #define intern(s,len) intern_gen(p,(s),(len))
89
92
 
90
- #define intern_lit(s) mrb_intern_lit(p->mrb, s)
93
+ #define intern_op(op) MRB_OPSYM_2(p->mrb, op)
91
94
 
92
95
  static void
93
96
  cons_free_gen(parser_state *p, node *cons)
@@ -265,7 +268,7 @@ local_unnest(parser_state *p)
265
268
  static mrb_bool
266
269
  local_var_p(parser_state *p, mrb_sym sym)
267
270
  {
268
- struct RProc *u;
271
+ const struct RProc *u;
269
272
  node *l = p->locals;
270
273
 
271
274
  while (l) {
@@ -279,11 +282,13 @@ local_var_p(parser_state *p, mrb_sym sym)
279
282
 
280
283
  u = p->upper;
281
284
  while (u && !MRB_PROC_CFUNC_P(u)) {
282
- struct mrb_irep *ir = u->body.irep;
283
- uint_fast16_t n = ir->nlocals;
284
- const struct mrb_locals *v = ir->lv;
285
- for (; n > 1; n --, v ++) {
286
- if (v->name == sym) return TRUE;
285
+ const struct mrb_irep *ir = u->body.irep;
286
+ const mrb_sym *v = ir->lv;
287
+ int i;
288
+
289
+ if (!v) break;
290
+ for (i=0; i+1 < ir->nlocals; i++) {
291
+ if (v[i] == sym) return TRUE;
287
292
  }
288
293
  if (MRB_PROC_SCOPE_P(u)) break;
289
294
  u = u->upper;
@@ -311,14 +316,14 @@ static void
311
316
  local_add_blk(parser_state *p, mrb_sym blk)
312
317
  {
313
318
  /* allocate register for block */
314
- local_add_f(p, blk ? blk : mrb_intern_lit(p->mrb, "&"));
319
+ local_add_f(p, blk ? blk : intern_op(and));
315
320
  }
316
321
 
317
322
  static void
318
323
  local_add_kw(parser_state *p, mrb_sym kwd)
319
324
  {
320
325
  /* allocate register for keywords hash */
321
- local_add_f(p, kwd ? kwd : mrb_intern_lit(p->mrb, "**"));
326
+ local_add_f(p, kwd ? kwd : intern_op(pow));
322
327
  }
323
328
 
324
329
  static node*
@@ -730,7 +735,19 @@ new_module(parser_state *p, node *m, node *b)
730
735
  static node*
731
736
  new_def(parser_state *p, mrb_sym m, node *a, node *b)
732
737
  {
733
- return list5((node*)NODE_DEF, nsym(m), locals_node(p), a, b);
738
+ return list5((node*)NODE_DEF, nsym(m), 0, a, b);
739
+ }
740
+
741
+ static void
742
+ defn_setup(parser_state *p, node *d, node *a, node *b)
743
+ {
744
+ node *n = d->cdr->cdr;
745
+
746
+ n->car = locals_node(p);
747
+ p->cmdarg_stack = intn(n->cdr->car);
748
+ n->cdr->car = a;
749
+ local_resume(p, n->cdr->cdr->car);
750
+ n->cdr->cdr->car = b;
734
751
  }
735
752
 
736
753
  /* (:sdef obj m lv (arg . body)) */
@@ -738,7 +755,19 @@ static node*
738
755
  new_sdef(parser_state *p, node *o, mrb_sym m, node *a, node *b)
739
756
  {
740
757
  void_expr_error(p, o);
741
- return list6((node*)NODE_SDEF, o, nsym(m), locals_node(p), a, b);
758
+ return list6((node*)NODE_SDEF, o, nsym(m), 0, a, b);
759
+ }
760
+
761
+ static void
762
+ defs_setup(parser_state *p, node *d, node *a, node *b)
763
+ {
764
+ node *n = d->cdr->cdr->cdr;
765
+
766
+ n->car = locals_node(p);
767
+ p->cmdarg_stack = intn(n->cdr->car);
768
+ n->cdr->car = a;
769
+ local_resume(p, n->cdr->cdr->car);
770
+ n->cdr->cdr->car = b;
742
771
  }
743
772
 
744
773
  /* (:arg . sym) */
@@ -752,7 +781,7 @@ static void
752
781
  local_add_margs(parser_state *p, node *n)
753
782
  {
754
783
  while (n) {
755
- if (n->car->car == (node*)NODE_MASGN) {
784
+ if (typen(n->car->car) == NODE_MASGN) {
756
785
  node *t = n->car->cdr->cdr;
757
786
 
758
787
  n->car->cdr->cdr = NULL;
@@ -932,13 +961,13 @@ new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
932
961
  static node*
933
962
  new_imaginary(parser_state *p, node *imaginary)
934
963
  {
935
- return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Complex"), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1);
964
+ return new_call(p, new_const(p, MRB_SYM_2(p->mrb, Kernel)), MRB_SYM_2(p->mrb, Complex), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1);
936
965
  }
937
966
 
938
967
  static node*
939
968
  new_rational(parser_state *p, node *rational)
940
969
  {
941
- return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Rational"), list1(list1(rational)), 1);
970
+ return new_call(p, new_const(p, MRB_SYM_2(p->mrb, Kernel)), MRB_SYM_2(p->mrb, Rational), list1(list1(rational)), 1);
942
971
  }
943
972
 
944
973
  /* (:int . i) */
@@ -955,7 +984,7 @@ new_int(parser_state *p, const char *s, int base, int suffix)
955
984
  return result;
956
985
  }
957
986
 
958
- #ifndef MRB_WITHOUT_FLOAT
987
+ #ifndef MRB_NO_FLOAT
959
988
  /* (:float . i) */
960
989
  static node*
961
990
  new_float(parser_state *p, const char *s, int suffix)
@@ -988,7 +1017,7 @@ new_dstr(parser_state *p, node *a)
988
1017
  static int
989
1018
  string_node_p(node *n)
990
1019
  {
991
- return (int)((enum node_type)(intptr_t)n->car == NODE_STR);
1020
+ return (int)(typen(n->car) == NODE_STR);
992
1021
  }
993
1022
 
994
1023
  static node*
@@ -1180,7 +1209,7 @@ call_with_block(parser_state *p, node *a, node *b)
1180
1209
  {
1181
1210
  node *n;
1182
1211
 
1183
- switch ((enum node_type)intn(a->car)) {
1212
+ switch (typen(a->car)) {
1184
1213
  case NODE_SUPER:
1185
1214
  case NODE_ZSUPER:
1186
1215
  if (!a->cdr) a->cdr = cons(0, b);
@@ -1254,7 +1283,7 @@ typedef enum mrb_string_type string_type;
1254
1283
  static node*
1255
1284
  new_strterm(parser_state *p, string_type type, int term, int paren)
1256
1285
  {
1257
- return cons(nint(type), cons((node*)0, cons(nint(paren), nint(term))));
1286
+ return cons(nint(type), cons(nint(0), cons(nint(paren), nint(term))));
1258
1287
  }
1259
1288
 
1260
1289
  static void
@@ -1407,15 +1436,24 @@ heredoc_end(parser_state *p)
1407
1436
  keyword__FILE__
1408
1437
  keyword__ENCODING__
1409
1438
 
1410
- %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL_TAG
1411
- %token <nd> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP
1439
+ %token <id> tIDENTIFIER "local variable or method"
1440
+ %token <id> tFID "method"
1441
+ %token <id> tGVAR "global variable"
1442
+ %token <id> tIVAR "instance variable"
1443
+ %token <id> tCONSTANT "constant"
1444
+ %token <id> tCVAR "class variable"
1445
+ %token <id> tLABEL_TAG "label"
1446
+ %token <nd> tINTEGER "integer literal"
1447
+ %token <nd> tFLOAT "float literal"
1448
+ %token <nd> tCHAR "character literal"
1449
+ %token <nd> tXSTRING tREGEXP
1412
1450
  %token <nd> tSTRING tSTRING_PART tSTRING_MID
1413
1451
  %token <nd> tNTH_REF tBACK_REF
1414
1452
  %token <num> tREGEXP_END
1415
- %token <num> tNUMPARAM
1453
+ %token <num> tNUMPARAM "numbered paraemeter"
1416
1454
 
1417
1455
  %type <nd> singleton string string_fragment string_rep string_interp xstring regexp
1418
- %type <nd> literal numeric cpath symbol
1456
+ %type <nd> literal numeric cpath symbol defn_head defs_head
1419
1457
  %type <nd> top_compstmt top_stmts top_stmt
1420
1458
  %type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
1421
1459
  %type <nd> expr_value arg_rhs primary_value
@@ -1425,7 +1463,7 @@ heredoc_end(parser_state *p)
1425
1463
  %type <nd> command_args aref_args opt_block_arg block_arg var_ref var_lhs
1426
1464
  %type <nd> command_asgn command_rhs mrhs superclass block_call block_command
1427
1465
  %type <nd> f_block_optarg f_block_opt
1428
- %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_margs
1466
+ %type <nd> f_arglist_paren f_arglist f_args f_arg f_arg_item f_optarg f_margs
1429
1467
  %type <nd> assoc_list assocs assoc undef_list backref for_var
1430
1468
  %type <nd> block_param opt_block_param block_param_def f_opt
1431
1469
  %type <nd> bv_decls opt_bv_decl bvar f_larglist lambda_body
@@ -1440,38 +1478,41 @@ heredoc_end(parser_state *p)
1440
1478
  %type <nd> f_block_kwarg f_block_kw block_args_tail opt_block_args_tail
1441
1479
  %type <id> f_label
1442
1480
 
1443
- %token tUPLUS /* unary+ */
1444
- %token tUMINUS /* unary- */
1445
- %token tPOW /* ** */
1446
- %token tCMP /* <=> */
1447
- %token tEQ /* == */
1448
- %token tEQQ /* === */
1449
- %token tNEQ /* != */
1450
- %token tGEQ /* >= */
1451
- %token tLEQ /* <= */
1452
- %token tANDOP tOROP /* && and || */
1453
- %token tMATCH tNMATCH /* =~ and !~ */
1454
- %token tDOT2 tDOT3 /* .. and ... */
1481
+ %token tUPLUS "unary plus"
1482
+ %token tUMINUS "unary minus"
1483
+ %token tCMP "<=>"
1484
+ %token tEQ "=="
1485
+ %token tEQQ "==="
1486
+ %token tNEQ "!="
1487
+ %token tGEQ ">="
1488
+ %token tLEQ "<="
1489
+ %token tANDOP "&&"
1490
+ %token tOROP "||"
1491
+ %token tMATCH "=~"
1492
+ %token tNMATCH "!~"
1493
+ %token tDOT2 ".."
1494
+ %token tDOT3 "..."
1495
+ %token tBDOT2 tBDOT3 /* (.. and (... */
1455
1496
  %token tAREF tASET /* [] and []= */
1456
- %token tLSHFT tRSHFT /* << and >> */
1457
- %token tCOLON2 /* :: */
1497
+ %token tLSHFT "<<"
1498
+ %token tRSHFT ">>"
1499
+ %token tCOLON2 "::"
1458
1500
  %token tCOLON3 /* :: at EXPR_BEG */
1459
1501
  %token <id> tOP_ASGN /* +=, -= etc. */
1460
- %token tASSOC /* => */
1461
- %token tLPAREN /* ( */
1462
- %token tLPAREN_ARG /* ( */
1463
- %token tRPAREN /* ) */
1464
- %token tLBRACK /* [ */
1465
- %token tLBRACE /* { */
1466
- %token tLBRACE_ARG /* { */
1467
- %token tSTAR /* * */
1468
- %token tDSTAR /* ** */
1469
- %token tAMPER /* & */
1470
- %token tLAMBDA /* -> */
1471
- %token tANDDOT /* &. */
1472
- %token tSYMBEG tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG
1473
- %token tSTRING_BEG tXSTRING_BEG tSTRING_DVAR tLAMBEG
1474
- %token <nd> tHEREDOC_BEG /* <<, <<- */
1502
+ %token tASSOC "=>"
1503
+ %token tLPAREN tLPAREN_ARG "("
1504
+ %token tRPAREN ")"
1505
+ %token tLBRACK "["
1506
+ %token tLBRACE tLBRACE_ARG "{"
1507
+ %token tSTAR "*"
1508
+ %token tPOW tDSTAR "**"
1509
+ %token tAMPER "&"
1510
+ %token tLAMBDA "->"
1511
+ %token tANDDOT "&."
1512
+ %token tSYMBEG "symbol"
1513
+ %token tSTRING_BEG "string literal"
1514
+ %token tXSTRING_BEG tSTRING_DVAR tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG tLAMBEG
1515
+ %token <nd> tHEREDOC_BEG "here document"
1475
1516
  %token tHEREDOC_END tLITERAL_DELIM tHD_LITERAL_DELIM
1476
1517
  %token <nd> tHD_STRING_PART tHD_STRING_MID
1477
1518
 
@@ -1488,7 +1529,7 @@ heredoc_end(parser_state *p)
1488
1529
  %right '=' tOP_ASGN
1489
1530
  %left modifier_rescue
1490
1531
  %right '?' ':' tLABEL_TAG
1491
- %nonassoc tDOT2 tDOT3
1532
+ %nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
1492
1533
  %left tOROP
1493
1534
  %left tANDOP
1494
1535
  %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
@@ -1658,6 +1699,13 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
1658
1699
  {
1659
1700
  $$ = new_masgn(p, $1, new_array(p, $3));
1660
1701
  }
1702
+ | arg tASSOC tIDENTIFIER
1703
+ {
1704
+ node *lhs = new_lvar(p, $3);
1705
+ void_expr_error(p, $1);
1706
+ assignable(p, lhs);
1707
+ $$ = new_asgn(p, lhs, $1);
1708
+ }
1661
1709
  | expr
1662
1710
  ;
1663
1711
 
@@ -1671,7 +1719,7 @@ command_asgn : lhs '=' command_rhs
1671
1719
  }
1672
1720
  | primary_value '[' opt_call_args ']' tOP_ASGN command_rhs
1673
1721
  {
1674
- $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6);
1722
+ $$ = new_op_asgn(p, new_call(p, $1, intern_op(aref), $3, '.'), $5, $6);
1675
1723
  }
1676
1724
  | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
1677
1725
  {
@@ -1726,6 +1774,31 @@ expr : command_call
1726
1774
  | arg
1727
1775
  ;
1728
1776
 
1777
+
1778
+ defn_head : keyword_def fname
1779
+ {
1780
+ $$ = new_def(p, $2, nint(p->cmdarg_stack), local_switch(p));
1781
+ p->cmdarg_stack = 0;
1782
+ p->in_def++;
1783
+ nvars_block(p);
1784
+ }
1785
+ ;
1786
+
1787
+ defs_head : keyword_def singleton dot_or_colon
1788
+ {
1789
+ p->lstate = EXPR_FNAME;
1790
+ }
1791
+ fname
1792
+ {
1793
+ $$ = new_sdef(p, $2, $5, nint(p->cmdarg_stack), local_switch(p));
1794
+ p->cmdarg_stack = 0;
1795
+ p->in_def++;
1796
+ p->in_single++;
1797
+ nvars_block(p);
1798
+ p->lstate = EXPR_ENDFN; /* force for args */
1799
+ }
1800
+ ;
1801
+
1729
1802
  expr_value : expr
1730
1803
  {
1731
1804
  if (!$1) $$ = new_nil(p);
@@ -1902,7 +1975,7 @@ mlhs_node : variable
1902
1975
  }
1903
1976
  | primary_value '[' opt_call_args ']'
1904
1977
  {
1905
- $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
1978
+ $$ = new_call(p, $1, intern_op(aref), $3, '.');
1906
1979
  }
1907
1980
  | primary_value call_op tIDENTIFIER
1908
1981
  {
@@ -1941,7 +2014,7 @@ lhs : variable
1941
2014
  }
1942
2015
  | primary_value '[' opt_call_args ']'
1943
2016
  {
1944
- $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
2017
+ $$ = new_call(p, $1, intern_op(aref), $3, '.');
1945
2018
  }
1946
2019
  | primary_value call_op tIDENTIFIER
1947
2020
  {
@@ -1987,11 +2060,11 @@ cname : tIDENTIFIER
1987
2060
 
1988
2061
  cpath : tCOLON3 cname
1989
2062
  {
1990
- $$ = cons((node*)1, nsym($2));
2063
+ $$ = cons(nint(1), nsym($2));
1991
2064
  }
1992
2065
  | cname
1993
2066
  {
1994
- $$ = cons((node*)0, nsym($1));
2067
+ $$ = cons(nint(0), nsym($1));
1995
2068
  }
1996
2069
  | primary_value tCOLON2 cname
1997
2070
  {
@@ -2029,36 +2102,36 @@ undef_list : fsym
2029
2102
  }
2030
2103
  ;
2031
2104
 
2032
- op : '|' { $$ = intern_lit("|"); }
2033
- | '^' { $$ = intern_lit("^"); }
2034
- | '&' { $$ = intern_lit("&"); }
2035
- | tCMP { $$ = intern_lit("<=>"); }
2036
- | tEQ { $$ = intern_lit("=="); }
2037
- | tEQQ { $$ = intern_lit("==="); }
2038
- | tMATCH { $$ = intern_lit("=~"); }
2039
- | tNMATCH { $$ = intern_lit("!~"); }
2040
- | '>' { $$ = intern_lit(">"); }
2041
- | tGEQ { $$ = intern_lit(">="); }
2042
- | '<' { $$ = intern_lit("<"); }
2043
- | tLEQ { $$ = intern_lit("<="); }
2044
- | tNEQ { $$ = intern_lit("!="); }
2045
- | tLSHFT { $$ = intern_lit("<<"); }
2046
- | tRSHFT { $$ = intern_lit(">>"); }
2047
- | '+' { $$ = intern_lit("+"); }
2048
- | '-' { $$ = intern_lit("-"); }
2049
- | '*' { $$ = intern_lit("*"); }
2050
- | tSTAR { $$ = intern_lit("*"); }
2051
- | '/' { $$ = intern_lit("/"); }
2052
- | '%' { $$ = intern_lit("%"); }
2053
- | tPOW { $$ = intern_lit("**"); }
2054
- | tDSTAR { $$ = intern_lit("**"); }
2055
- | '!' { $$ = intern_lit("!"); }
2056
- | '~' { $$ = intern_lit("~"); }
2057
- | tUPLUS { $$ = intern_lit("+@"); }
2058
- | tUMINUS { $$ = intern_lit("-@"); }
2059
- | tAREF { $$ = intern_lit("[]"); }
2060
- | tASET { $$ = intern_lit("[]="); }
2061
- | '`' { $$ = intern_lit("`"); }
2105
+ op : '|' { $$ = intern_op(or); }
2106
+ | '^' { $$ = intern_op(xor); }
2107
+ | '&' { $$ = intern_op(and); }
2108
+ | tCMP { $$ = intern_op(cmp); }
2109
+ | tEQ { $$ = intern_op(eq); }
2110
+ | tEQQ { $$ = intern_op(eqq); }
2111
+ | tMATCH { $$ = intern_op(match); }
2112
+ | tNMATCH { $$ = intern_op(nmatch); }
2113
+ | '>' { $$ = intern_op(gt); }
2114
+ | tGEQ { $$ = intern_op(ge); }
2115
+ | '<' { $$ = intern_op(lt); }
2116
+ | tLEQ { $$ = intern_op(le); }
2117
+ | tNEQ { $$ = intern_op(neq); }
2118
+ | tLSHFT { $$ = intern_op(lshift); }
2119
+ | tRSHFT { $$ = intern_op(rshift); }
2120
+ | '+' { $$ = intern_op(add); }
2121
+ | '-' { $$ = intern_op(sub); }
2122
+ | '*' { $$ = intern_op(mul); }
2123
+ | tSTAR { $$ = intern_op(mul); }
2124
+ | '/' { $$ = intern_op(div); }
2125
+ | '%' { $$ = intern_op(mod); }
2126
+ | tPOW { $$ = intern_op(pow); }
2127
+ | tDSTAR { $$ = intern_op(pow); }
2128
+ | '!' { $$ = intern_op(not); }
2129
+ | '~' { $$ = intern_op(neg); }
2130
+ | tUPLUS { $$ = intern_op(plus); }
2131
+ | tUMINUS { $$ = intern_op(minus); }
2132
+ | tAREF { $$ = intern_op(aref); }
2133
+ | tASET { $$ = intern_op(aset); }
2134
+ | '`' { $$ = intern_op(tick); }
2062
2135
  ;
2063
2136
 
2064
2137
  reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
@@ -2085,7 +2158,7 @@ arg : lhs '=' arg_rhs
2085
2158
  }
2086
2159
  | primary_value '[' opt_call_args ']' tOP_ASGN arg_rhs
2087
2160
  {
2088
- $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6);
2161
+ $$ = new_op_asgn(p, new_call(p, $1, intern_op(aref), $3, '.'), $5, $6);
2089
2162
  }
2090
2163
  | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
2091
2164
  {
@@ -2118,10 +2191,26 @@ arg : lhs '=' arg_rhs
2118
2191
  {
2119
2192
  $$ = new_dot2(p, $1, $3);
2120
2193
  }
2194
+ | arg tDOT2
2195
+ {
2196
+ $$ = new_dot2(p, $1, new_nil(p));
2197
+ }
2198
+ | tBDOT2 arg
2199
+ {
2200
+ $$ = new_dot2(p, new_nil(p), $2);
2201
+ }
2121
2202
  | arg tDOT3 arg
2122
2203
  {
2123
2204
  $$ = new_dot3(p, $1, $3);
2124
2205
  }
2206
+ | arg tDOT3
2207
+ {
2208
+ $$ = new_dot3(p, $1, new_nil(p));
2209
+ }
2210
+ | tBDOT3 arg
2211
+ {
2212
+ $$ = new_dot3(p, new_nil(p), $2);
2213
+ }
2125
2214
  | arg '+' arg
2126
2215
  {
2127
2216
  $$ = call_bin_op(p, $1, "+", $3);
@@ -2246,6 +2335,42 @@ arg : lhs '=' arg_rhs
2246
2335
  {
2247
2336
  $$ = new_if(p, cond($1), $3, $6);
2248
2337
  }
2338
+ | defn_head f_arglist_paren '=' arg
2339
+ {
2340
+ $$ = $1;
2341
+ void_expr_error(p, $4);
2342
+ defn_setup(p, $$, $2, $4);
2343
+ nvars_unnest(p);
2344
+ p->in_def--;
2345
+ }
2346
+ | defn_head f_arglist_paren '=' arg modifier_rescue arg
2347
+ {
2348
+ $$ = $1;
2349
+ void_expr_error(p, $4);
2350
+ void_expr_error(p, $6);
2351
+ defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
2352
+ nvars_unnest(p);
2353
+ p->in_def--;
2354
+ }
2355
+ | defs_head f_arglist_paren '=' arg
2356
+ {
2357
+ $$ = $1;
2358
+ void_expr_error(p, $4);
2359
+ defs_setup(p, $$, $2, $4);
2360
+ nvars_unnest(p);
2361
+ p->in_def--;
2362
+ p->in_single--;
2363
+ }
2364
+ | defs_head f_arglist_paren '=' arg modifier_rescue arg
2365
+ {
2366
+ $$ = $1;
2367
+ void_expr_error(p, $4);
2368
+ void_expr_error(p, $6);
2369
+ defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
2370
+ nvars_unnest(p);
2371
+ p->in_def--;
2372
+ p->in_single--;
2373
+ }
2249
2374
  | primary
2250
2375
  {
2251
2376
  $$ = $1;
@@ -2285,19 +2410,35 @@ paren_args : '(' opt_call_args ')'
2285
2410
  {
2286
2411
  $$ = $2;
2287
2412
  }
2288
- | '(' tDOT3 rparen
2413
+ | '(' args comma tBDOT3 rparen
2289
2414
  {
2290
2415
  #if 1
2291
- mrb_sym r = mrb_intern_lit(p->mrb, "*");
2292
- mrb_sym b = mrb_intern_lit(p->mrb, "&");
2416
+ mrb_sym r = intern_op(mul);
2417
+ mrb_sym b = intern_op(and);
2418
+ $$ = cons(push($2, new_splat(p, new_lvar(p, r))),
2419
+ new_block_arg(p, new_lvar(p, b)));
2420
+ #else
2421
+ mrb_sym r = intern_op(mul);
2422
+ mrb_sym k = intern_op(pow);
2423
+ mrb_sym b = intern_op(and);
2424
+ $$ = cons(list2(push($2, new_splat(p, new_lvar(p, r))),
2425
+ new_kw_hash(p, list1(cons(new_kw_rest_args(p, 0), new_lvar(p, k))))),
2426
+ new_block_arg(p, new_lvar(p, b)));
2427
+ #endif
2428
+ }
2429
+ | '(' tBDOT3 rparen
2430
+ {
2431
+ #if 1
2432
+ mrb_sym r = intern_op(mul);
2433
+ mrb_sym b = intern_op(and);
2293
2434
  if (local_var_p(p, r) && local_var_p(p, b)) {
2294
2435
  $$ = cons(list1(new_splat(p, new_lvar(p, r))),
2295
2436
  new_block_arg(p, new_lvar(p, b)));
2296
2437
  }
2297
2438
  #else
2298
- mrb_sym r = mrb_intern_lit(p->mrb, "*");
2299
- mrb_sym k = mrb_intern_lit(p->mrb, "**");
2300
- mrb_sym b = mrb_intern_lit(p->mrb, "&");
2439
+ mrb_sym r = intern_op(mul);
2440
+ mrb_sym k = intern_op(pow);
2441
+ mrb_sym b = intern_op(and);
2301
2442
  if (local_var_p(p, r) && local_var_p(p, k) && local_var_p(p, b)) {
2302
2443
  $$ = cons(list2(new_splat(p, new_lvar(p, r)),
2303
2444
  new_kw_hash(p, list1(cons(new_kw_rest_args(p, 0), new_lvar(p, k))))),
@@ -2645,50 +2786,26 @@ primary : literal
2645
2786
  local_resume(p, $<nd>3);
2646
2787
  nvars_unnest(p);
2647
2788
  }
2648
- | keyword_def fname
2649
- {
2650
- $<stack>$ = p->cmdarg_stack;
2651
- p->cmdarg_stack = 0;
2652
- }
2653
- {
2654
- p->in_def++;
2655
- $<nd>$ = local_switch(p);
2656
- nvars_block(p);
2657
- }
2789
+ | defn_head
2658
2790
  f_arglist
2659
2791
  bodystmt
2660
2792
  keyword_end
2661
2793
  {
2662
- $$ = new_def(p, $2, $5, $6);
2663
- SET_LINENO($$, $1);
2664
- local_resume(p, $<nd>4);
2794
+ $$ = $1;
2795
+ defn_setup(p, $$, $2, $3);
2665
2796
  nvars_unnest(p);
2666
2797
  p->in_def--;
2667
- p->cmdarg_stack = $<stack>3;
2668
- }
2669
- | keyword_def singleton dot_or_colon
2670
- {
2671
- p->lstate = EXPR_FNAME;
2672
- $<stack>$ = p->cmdarg_stack;
2673
- p->cmdarg_stack = 0;
2674
- }
2675
- fname
2676
- {
2677
- p->in_single++;
2678
- p->lstate = EXPR_ENDFN; /* force for args */
2679
- $<nd>$ = local_switch(p);
2680
- nvars_block(p);
2681
2798
  }
2799
+ | defs_head
2682
2800
  f_arglist
2683
2801
  bodystmt
2684
2802
  keyword_end
2685
2803
  {
2686
- $$ = new_sdef(p, $2, $5, $7, $8);
2687
- SET_LINENO($$, $1);
2688
- local_resume(p, $<nd>6);
2804
+ $$ = $1;
2805
+ defs_setup(p, $$, $2, $3);
2689
2806
  nvars_unnest(p);
2807
+ p->in_def--;
2690
2808
  p->in_single--;
2691
- p->cmdarg_stack = $<stack>4;
2692
2809
  }
2693
2810
  | keyword_break
2694
2811
  {
@@ -2762,11 +2879,11 @@ f_margs : f_arg
2762
2879
  | f_arg ',' tSTAR
2763
2880
  {
2764
2881
  local_add_f(p, 0);
2765
- $$ = list3($1, (node*)-1, 0);
2882
+ $$ = list3($1, nint(-1), 0);
2766
2883
  }
2767
2884
  | f_arg ',' tSTAR ',' f_arg
2768
2885
  {
2769
- $$ = list3($1, (node*)-1, $5);
2886
+ $$ = list3($1, nint(-1), $5);
2770
2887
  }
2771
2888
  | tSTAR f_norm_arg
2772
2889
  {
@@ -2779,7 +2896,7 @@ f_margs : f_arg
2779
2896
  | tSTAR
2780
2897
  {
2781
2898
  local_add_f(p, 0);
2782
- $$ = list3(0, (node*)-1, 0);
2899
+ $$ = list3(0, nint(-1), 0);
2783
2900
  }
2784
2901
  | tSTAR ','
2785
2902
  {
@@ -2787,7 +2904,7 @@ f_margs : f_arg
2787
2904
  }
2788
2905
  f_arg
2789
2906
  {
2790
- $$ = list3(0, (node*)-1, $4);
2907
+ $$ = list3(0, nint(-1), $4);
2791
2908
  }
2792
2909
  ;
2793
2910
 
@@ -2968,7 +3085,7 @@ do_block : keyword_do_block
2968
3085
 
2969
3086
  block_call : command do_block
2970
3087
  {
2971
- if ($1->car == (node*)NODE_YIELD) {
3088
+ if (typen($1->car) == NODE_YIELD) {
2972
3089
  yyerror(p, "block given to yield");
2973
3090
  }
2974
3091
  else {
@@ -3010,11 +3127,11 @@ method_call : operation paren_args
3010
3127
  }
3011
3128
  | primary_value call_op paren_args
3012
3129
  {
3013
- $$ = new_call(p, $1, intern_lit("call"), $3, $2);
3130
+ $$ = new_call(p, $1, MRB_SYM_2(p->mrb, call), $3, $2);
3014
3131
  }
3015
3132
  | primary_value tCOLON2 paren_args
3016
3133
  {
3017
- $$ = new_call(p, $1, intern_lit("call"), $3, tCOLON2);
3134
+ $$ = new_call(p, $1, MRB_SYM_2(p->mrb, call), $3, tCOLON2);
3018
3135
  }
3019
3136
  | keyword_super paren_args
3020
3137
  {
@@ -3026,7 +3143,7 @@ method_call : operation paren_args
3026
3143
  }
3027
3144
  | primary_value '[' opt_call_args ']'
3028
3145
  {
3029
- $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
3146
+ $$ = new_call(p, $1, intern_op(aref), $3, '.');
3030
3147
  }
3031
3148
  ;
3032
3149
 
@@ -3399,30 +3516,51 @@ superclass : /* term */
3399
3516
  } */
3400
3517
  ;
3401
3518
 
3402
- f_arglist : '(' f_args rparen
3519
+ f_arglist_paren : '(' f_args rparen
3403
3520
  {
3404
3521
  $$ = $2;
3405
3522
  p->lstate = EXPR_BEG;
3406
3523
  p->cmd_start = TRUE;
3407
3524
  }
3408
- | '(' tDOT3 rparen
3525
+ | '(' f_arg ',' tBDOT3 rparen
3409
3526
  {
3410
3527
  #if 1
3411
3528
  /* til real keyword args implemented */
3412
- mrb_sym r = mrb_intern_lit(p->mrb, "*");
3413
- mrb_sym b = mrb_intern_lit(p->mrb, "&");
3529
+ mrb_sym r = intern_op(mul);
3530
+ mrb_sym b = intern_op(and);
3531
+ local_add_f(p, r);
3532
+ $$ = new_args(p, $2, 0, r, 0,
3533
+ new_args_tail(p, 0, 0, b));
3534
+ #else
3535
+ mrb_sym r = intern_op(mul);
3536
+ mrb_sym k = intern_op(pow);
3537
+ mrb_sym b = intern_op(and);
3538
+ local_add_f(p, r); local_add_f(p, k);
3539
+ $$ = new_args(p, $2, 0, r, 0,
3540
+ new_args_tail(p, 0, new_kw_rest_args(p, nsym(k)), b));
3541
+ #endif
3542
+ }
3543
+ | '(' tBDOT3 rparen
3544
+ {
3545
+ #if 1
3546
+ /* til real keyword args implemented */
3547
+ mrb_sym r = intern_op(mul);
3548
+ mrb_sym b = intern_op(and);
3414
3549
  local_add_f(p, r);
3415
3550
  $$ = new_args(p, 0, 0, r, 0,
3416
3551
  new_args_tail(p, 0, 0, b));
3417
3552
  #else
3418
- mrb_sym r = mrb_intern_lit(p->mrb, "*");
3419
- mrb_sym k = mrb_intern_lit(p->mrb, "**");
3420
- mrb_sym b = mrb_intern_lit(p->mrb, "&");
3553
+ mrb_sym r = intern_op(mul);
3554
+ mrb_sym k = intern_op(pow);
3555
+ mrb_sym b = intern_op(and);
3421
3556
  local_add_f(p, r); local_add_f(p, k);
3422
3557
  $$ = new_args(p, 0, 0, r, 0,
3423
3558
  new_args_tail(p, 0, new_kw_rest_args(p, nsym(k)), b));
3424
3559
  #endif
3425
3560
  }
3561
+ ;
3562
+
3563
+ f_arglist : f_arglist_paren
3426
3564
  | f_args term
3427
3565
  {
3428
3566
  $$ = $1;
@@ -3580,7 +3718,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_args_tail
3580
3718
  }
3581
3719
  | /* none */
3582
3720
  {
3583
- local_add_f(p, mrb_intern_lit(p->mrb, "&"));
3721
+ local_add_f(p, intern_op(and));
3584
3722
  $$ = new_args(p, 0, 0, 0, 0, 0);
3585
3723
  }
3586
3724
  ;
@@ -3704,7 +3842,7 @@ f_rest_arg : restarg_mark tIDENTIFIER
3704
3842
  }
3705
3843
  | restarg_mark
3706
3844
  {
3707
- local_add_f(p, mrb_intern_lit(p->mrb, "*"));
3845
+ local_add_f(p, intern_op(mul));
3708
3846
  $$ = -1;
3709
3847
  }
3710
3848
  ;
@@ -3740,7 +3878,7 @@ singleton : var_ref
3740
3878
  yyerror(p, "can't define singleton method for ().");
3741
3879
  }
3742
3880
  else {
3743
- switch ((enum node_type)intn($3->car)) {
3881
+ switch (typen($3->car)) {
3744
3882
  case NODE_STR:
3745
3883
  case NODE_DSTR:
3746
3884
  case NODE_XSTR:
@@ -3795,7 +3933,7 @@ assoc : arg tASSOC arg
3795
3933
  | string_fragment label_tag arg
3796
3934
  {
3797
3935
  void_expr_error(p, $3);
3798
- if ($1->car == (node*)NODE_DSTR) {
3936
+ if (typen($1->car) == NODE_DSTR) {
3799
3937
  $$ = cons(new_dsym(p, $1), $3);
3800
3938
  }
3801
3939
  else {
@@ -3893,7 +4031,7 @@ yyerror(parser_state *p, const char *s)
3893
4031
  size_t n;
3894
4032
 
3895
4033
  if (! p->capture_errors) {
3896
- #ifndef MRB_DISABLE_STDIO
4034
+ #ifndef MRB_NO_STDIO
3897
4035
  if (p->filename_sym) {
3898
4036
  const char *filename = mrb_sym_name_len(p->mrb, p->filename_sym, NULL);
3899
4037
  fprintf(stderr, "%s:%d:%d: %s\n", filename, p->lineno, p->column, s);
@@ -3932,7 +4070,7 @@ yywarn(parser_state *p, const char *s)
3932
4070
  size_t n;
3933
4071
 
3934
4072
  if (! p->capture_errors) {
3935
- #ifndef MRB_DISABLE_STDIO
4073
+ #ifndef MRB_NO_STDIO
3936
4074
  if (p->filename_sym) {
3937
4075
  const char *filename = mrb_sym_name_len(p->mrb, p->filename_sym, NULL);
3938
4076
  fprintf(stderr, "%s:%d:%d: warning: %s\n", filename, p->lineno, p->column, s);
@@ -4032,20 +4170,20 @@ static inline int
4032
4170
  nextc0(parser_state *p)
4033
4171
  {
4034
4172
  int c;
4035
- #ifndef MRB_DISABLE_STDIO
4036
- if (p->f) {
4037
- if (feof(p->f)) return -1;
4038
- c = fgetc(p->f);
4039
- if (c == EOF) return -1;
4173
+
4174
+ if (p->s && p->s < p->send) {
4175
+ c = (unsigned char)*p->s++;
4040
4176
  }
4041
- else
4177
+ else {
4178
+ #ifndef MRB_NO_STDIO
4179
+ if (p->f) {
4180
+ c = fgetc(p->f);
4181
+ if (feof(p->f)) return -1;
4182
+ }
4183
+ else
4042
4184
  #endif
4043
- if (!p->s || p->s >= p->send) {
4044
4185
  return -1;
4045
- }
4046
- else {
4047
- c = (unsigned char)*p->s++;
4048
- }
4186
+ }
4049
4187
  return c;
4050
4188
  }
4051
4189
 
@@ -4121,7 +4259,7 @@ peekc_n(parser_state *p, int n)
4121
4259
  list = push(list, nint(c0));
4122
4260
  } while(n--);
4123
4261
  if (p->pb) {
4124
- p->pb = append((node*)list, p->pb);
4262
+ p->pb = append(list, p->pb);
4125
4263
  }
4126
4264
  else {
4127
4265
  p->pb = list;
@@ -4141,7 +4279,7 @@ peeks(parser_state *p, const char *s)
4141
4279
  {
4142
4280
  size_t len = strlen(s);
4143
4281
 
4144
- #ifndef MRB_DISABLE_STDIO
4282
+ #ifndef MRB_NO_STDIO
4145
4283
  if (p->f) {
4146
4284
  int n = 0;
4147
4285
  while (*s) {
@@ -4499,6 +4637,88 @@ read_escape(parser_state *p)
4499
4637
  }
4500
4638
  }
4501
4639
 
4640
+ static void
4641
+ heredoc_count_indent(parser_heredoc_info *hinf, const char *str, size_t len, size_t spaces, size_t *offset)
4642
+ {
4643
+ size_t indent = 0;
4644
+ *offset = 0;
4645
+ for (size_t i = 0; i < len; i++) {
4646
+ size_t size;
4647
+ if (str[i] == '\n')
4648
+ break;
4649
+ else if (str[i] == '\t')
4650
+ size = 8;
4651
+ else if (ISSPACE(str[i]))
4652
+ size = 1;
4653
+ else
4654
+ break;
4655
+ size_t nindent = indent + size;
4656
+ if (nindent > spaces || nindent > hinf->indent)
4657
+ break;
4658
+ indent = nindent;
4659
+ *offset += 1;
4660
+ }
4661
+ }
4662
+
4663
+ static void
4664
+ heredoc_remove_indent(parser_state *p, parser_heredoc_info *hinf)
4665
+ {
4666
+ if (!hinf->remove_indent || hinf->indent == 0)
4667
+ return;
4668
+ node *indented, *n, *pair, *escaped, *nspaces;
4669
+ const char *str;
4670
+ size_t len, spaces, offset, start, end;
4671
+ indented = hinf->indented;
4672
+ while (indented) {
4673
+ n = indented->car;
4674
+ pair = n->car;
4675
+ str = (char*)pair->car;
4676
+ len = (size_t)pair->cdr;
4677
+ escaped = n->cdr->car;
4678
+ nspaces = n->cdr->cdr;
4679
+ if (escaped) {
4680
+ char *newstr = strndup(str, len);
4681
+ size_t newlen = 0;
4682
+ start = 0;
4683
+ while (start < len) {
4684
+ end = escaped ? (size_t)escaped->car : len;
4685
+ spaces = (size_t)nspaces->car;
4686
+ size_t esclen = end - start;
4687
+ heredoc_count_indent(hinf, str + start, esclen, spaces, &offset);
4688
+ esclen -= offset;
4689
+ memcpy(newstr + newlen, str + start + offset, esclen);
4690
+ newlen += esclen;
4691
+ start = end;
4692
+ if (escaped)
4693
+ escaped = escaped->cdr;
4694
+ nspaces = nspaces->cdr;
4695
+ }
4696
+ if (newlen < len)
4697
+ newstr[newlen] = '\0';
4698
+ pair->car = (node*)newstr;
4699
+ pair->cdr = (node*)newlen;
4700
+ } else {
4701
+ spaces = (size_t)nspaces->car;
4702
+ heredoc_count_indent(hinf, str, len, spaces, &offset);
4703
+ pair->car = (node*)(str + offset);
4704
+ pair->cdr = (node*)(len - offset);
4705
+ }
4706
+ indented = indented->cdr;
4707
+ }
4708
+ }
4709
+
4710
+ static void
4711
+ heredoc_push_indented(parser_state *p, parser_heredoc_info *hinf, node *pair, node *escaped, node *nspaces, mrb_bool empty_line)
4712
+ {
4713
+ hinf->indented = push(hinf->indented, cons(pair, cons(escaped, nspaces)));
4714
+ while (nspaces) {
4715
+ size_t tspaces = (size_t)nspaces->car;
4716
+ if ((hinf->indent == ~0U || tspaces < hinf->indent) && !empty_line)
4717
+ hinf->indent = tspaces;
4718
+ nspaces = nspaces->cdr;
4719
+ }
4720
+ }
4721
+
4502
4722
  static int
4503
4723
  parse_string(parser_state *p)
4504
4724
  {
@@ -4509,10 +4729,19 @@ parse_string(parser_state *p)
4509
4729
  int end = intn(p->lex_strterm->cdr->cdr->cdr);
4510
4730
  parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL;
4511
4731
 
4732
+ mrb_bool unindent = hinf && hinf->remove_indent;
4733
+ mrb_bool head = hinf && hinf->line_head;
4734
+ mrb_bool empty = TRUE;
4735
+ size_t spaces = 0;
4736
+ size_t pos = -1;
4737
+ node *escaped = NULL;
4738
+ node *nspaces = NULL;
4739
+
4512
4740
  if (beg == 0) beg = -3; /* should never happen */
4513
4741
  if (end == 0) end = -3;
4514
4742
  newtok(p);
4515
4743
  while ((c = nextc(p)) != end || nest_level != 0) {
4744
+ pos++;
4516
4745
  if (hinf && (c == '\n' || c < 0)) {
4517
4746
  mrb_bool line_head;
4518
4747
  tokadd(p, '\n');
@@ -4532,6 +4761,7 @@ parse_string(parser_state *p)
4532
4761
  }
4533
4762
  }
4534
4763
  if ((len-1 == hinf->term_len) && (strncmp(s, hinf->term, len-1) == 0)) {
4764
+ heredoc_remove_indent(p, hinf);
4535
4765
  return tHEREDOC_END;
4536
4766
  }
4537
4767
  }
@@ -4550,9 +4780,22 @@ parse_string(parser_state *p)
4550
4780
  }
4551
4781
  return 0;
4552
4782
  }
4553
- pylval.nd = new_str(p, tok(p), toklen(p));
4783
+ node *nd = new_str(p, tok(p), toklen(p));
4784
+ pylval.nd = nd;
4785
+ if (unindent && head) {
4786
+ nspaces = push(nspaces, nint(spaces));
4787
+ heredoc_push_indented(p, hinf, nd->cdr, escaped, nspaces, empty && line_head);
4788
+ }
4554
4789
  return tHD_STRING_MID;
4555
4790
  }
4791
+ if (unindent && empty) {
4792
+ if (c == '\t')
4793
+ spaces += 8;
4794
+ else if (ISSPACE(c))
4795
+ ++spaces;
4796
+ else
4797
+ empty = FALSE;
4798
+ }
4556
4799
  if (c < 0) {
4557
4800
  yyerror(p, "unterminated string meets end of file");
4558
4801
  return 0;
@@ -4574,6 +4817,13 @@ parse_string(parser_state *p)
4574
4817
  else if (c == '\n') {
4575
4818
  p->lineno++;
4576
4819
  p->column = 0;
4820
+ if (unindent) {
4821
+ nspaces = push(nspaces, nint(spaces));
4822
+ escaped = push(escaped, nint(pos));
4823
+ pos--;
4824
+ empty = TRUE;
4825
+ spaces = 0;
4826
+ }
4577
4827
  if (type & STR_FUNC_ARRAY) {
4578
4828
  tokadd(p, '\n');
4579
4829
  }
@@ -4623,8 +4873,13 @@ parse_string(parser_state *p)
4623
4873
  tokfix(p);
4624
4874
  p->lstate = EXPR_BEG;
4625
4875
  p->cmd_start = TRUE;
4626
- pylval.nd = new_str(p, tok(p), toklen(p));
4876
+ node *nd = new_str(p, tok(p), toklen(p));
4877
+ pylval.nd = nd;
4627
4878
  if (hinf) {
4879
+ if (unindent && head) {
4880
+ nspaces = push(nspaces, nint(spaces));
4881
+ heredoc_push_indented(p, hinf, nd->cdr, escaped, nspaces, FALSE);
4882
+ }
4628
4883
  hinf->line_head = FALSE;
4629
4884
  return tHD_STRING_PART;
4630
4885
  }
@@ -4745,7 +5000,7 @@ number_literal_suffix(parser_state *p)
4745
5000
  int mask = NUM_SUFFIX_R|NUM_SUFFIX_I;
4746
5001
 
4747
5002
  while ((c = nextc(p)) != -1) {
4748
- list = push(list, (node*)(intptr_t)c);
5003
+ list = push(list, nint(c));
4749
5004
 
4750
5005
  if ((mask & NUM_SUFFIX_I) && c == 'i') {
4751
5006
  result |= (mask & NUM_SUFFIX_I);
@@ -4762,7 +5017,7 @@ number_literal_suffix(parser_state *p)
4762
5017
  if (!ISASCII(c) || ISALPHA(c) || c == '_') {
4763
5018
  p->column = column;
4764
5019
  if (p->pb) {
4765
- p->pb = append((node*)list, p->pb);
5020
+ p->pb = append(list, p->pb);
4766
5021
  }
4767
5022
  else {
4768
5023
  p->pb = list;
@@ -4781,6 +5036,7 @@ heredoc_identifier(parser_state *p)
4781
5036
  int c;
4782
5037
  int type = str_heredoc;
4783
5038
  mrb_bool indent = FALSE;
5039
+ mrb_bool squiggly = FALSE;
4784
5040
  mrb_bool quote = FALSE;
4785
5041
  node *newnode;
4786
5042
  parser_heredoc_info *info;
@@ -4790,8 +5046,11 @@ heredoc_identifier(parser_state *p)
4790
5046
  pushback(p, c);
4791
5047
  return 0;
4792
5048
  }
4793
- if (c == '-') {
4794
- indent = TRUE;
5049
+ if (c == '-' || c == '~') {
5050
+ if (c == '-')
5051
+ indent = TRUE;
5052
+ if (c == '~')
5053
+ squiggly = TRUE;
4795
5054
  c = nextc(p);
4796
5055
  }
4797
5056
  if (c == '\'' || c == '"') {
@@ -4818,6 +5077,7 @@ heredoc_identifier(parser_state *p)
4818
5077
  if (! identchar(c)) {
4819
5078
  pushback(p, c);
4820
5079
  if (indent) pushback(p, '-');
5080
+ if (squiggly) pushback(p, '~');
4821
5081
  return 0;
4822
5082
  }
4823
5083
  newtok(p);
@@ -4834,7 +5094,10 @@ heredoc_identifier(parser_state *p)
4834
5094
  if (! quote)
4835
5095
  type |= STR_FUNC_EXPAND;
4836
5096
  info->type = (string_type)type;
4837
- info->allow_indent = indent;
5097
+ info->allow_indent = indent || squiggly;
5098
+ info->remove_indent = squiggly;
5099
+ info->indent = ~0U;
5100
+ info->indented = NULL;
4838
5101
  info->line_head = TRUE;
4839
5102
  info->doc = NULL;
4840
5103
  p->heredocs_from_nextline = push(p->heredocs_from_nextline, newnode);
@@ -4961,7 +5224,7 @@ parser_yylex(parser_state *p)
4961
5224
  case '*':
4962
5225
  if ((c = nextc(p)) == '*') {
4963
5226
  if ((c = nextc(p)) == '=') {
4964
- pylval.id = intern_lit("**");
5227
+ pylval.id = intern_op(pow);
4965
5228
  p->lstate = EXPR_BEG;
4966
5229
  return tOP_ASGN;
4967
5230
  }
@@ -4979,7 +5242,7 @@ parser_yylex(parser_state *p)
4979
5242
  }
4980
5243
  else {
4981
5244
  if (c == '=') {
4982
- pylval.id = intern_lit("*");
5245
+ pylval.id = intern_op(mul);
4983
5246
  p->lstate = EXPR_BEG;
4984
5247
  return tOP_ASGN;
4985
5248
  }
@@ -5095,7 +5358,7 @@ parser_yylex(parser_state *p)
5095
5358
  }
5096
5359
  if (c == '<') {
5097
5360
  if ((c = nextc(p)) == '=') {
5098
- pylval.id = intern_lit("<<");
5361
+ pylval.id = intern_op(lshift);
5099
5362
  p->lstate = EXPR_BEG;
5100
5363
  return tOP_ASGN;
5101
5364
  }
@@ -5117,7 +5380,7 @@ parser_yylex(parser_state *p)
5117
5380
  }
5118
5381
  if (c == '>') {
5119
5382
  if ((c = nextc(p)) == '=') {
5120
- pylval.id = intern_lit(">>");
5383
+ pylval.id = intern_op(rshift);
5121
5384
  p->lstate = EXPR_BEG;
5122
5385
  return tOP_ASGN;
5123
5386
  }
@@ -5225,7 +5488,7 @@ parser_yylex(parser_state *p)
5225
5488
  if ((c = nextc(p)) == '&') {
5226
5489
  p->lstate = EXPR_BEG;
5227
5490
  if ((c = nextc(p)) == '=') {
5228
- pylval.id = intern_lit("&&");
5491
+ pylval.id = intern_op(andand);
5229
5492
  p->lstate = EXPR_BEG;
5230
5493
  return tOP_ASGN;
5231
5494
  }
@@ -5237,7 +5500,7 @@ parser_yylex(parser_state *p)
5237
5500
  return tANDDOT;
5238
5501
  }
5239
5502
  else if (c == '=') {
5240
- pylval.id = intern_lit("&");
5503
+ pylval.id = intern_op(and);
5241
5504
  p->lstate = EXPR_BEG;
5242
5505
  return tOP_ASGN;
5243
5506
  }
@@ -5264,7 +5527,7 @@ parser_yylex(parser_state *p)
5264
5527
  if ((c = nextc(p)) == '|') {
5265
5528
  p->lstate = EXPR_BEG;
5266
5529
  if ((c = nextc(p)) == '=') {
5267
- pylval.id = intern_lit("||");
5530
+ pylval.id = intern_op(oror);
5268
5531
  p->lstate = EXPR_BEG;
5269
5532
  return tOP_ASGN;
5270
5533
  }
@@ -5272,7 +5535,7 @@ parser_yylex(parser_state *p)
5272
5535
  return tOROP;
5273
5536
  }
5274
5537
  if (c == '=') {
5275
- pylval.id = intern_lit("|");
5538
+ pylval.id = intern_op(or);
5276
5539
  p->lstate = EXPR_BEG;
5277
5540
  return tOP_ASGN;
5278
5541
  }
@@ -5296,7 +5559,7 @@ parser_yylex(parser_state *p)
5296
5559
  return '+';
5297
5560
  }
5298
5561
  if (c == '=') {
5299
- pylval.id = intern_lit("+");
5562
+ pylval.id = intern_op(add);
5300
5563
  p->lstate = EXPR_BEG;
5301
5564
  return tOP_ASGN;
5302
5565
  }
@@ -5324,7 +5587,7 @@ parser_yylex(parser_state *p)
5324
5587
  return '-';
5325
5588
  }
5326
5589
  if (c == '=') {
5327
- pylval.id = intern_lit("-");
5590
+ pylval.id = intern_op(sub);
5328
5591
  p->lstate = EXPR_BEG;
5329
5592
  return tOP_ASGN;
5330
5593
  }
@@ -5345,20 +5608,23 @@ parser_yylex(parser_state *p)
5345
5608
  return '-';
5346
5609
 
5347
5610
  case '.':
5348
- p->lstate = EXPR_BEG;
5349
- if ((c = nextc(p)) == '.') {
5611
+ {
5612
+ int is_beg = IS_BEG();
5613
+ p->lstate = EXPR_BEG;
5350
5614
  if ((c = nextc(p)) == '.') {
5351
- return tDOT3;
5615
+ if ((c = nextc(p)) == '.') {
5616
+ return is_beg ? tBDOT3 : tDOT3;
5617
+ }
5618
+ pushback(p, c);
5619
+ return is_beg ? tBDOT2 : tDOT2;
5352
5620
  }
5353
5621
  pushback(p, c);
5354
- return tDOT2;
5355
- }
5356
- pushback(p, c);
5357
- if (c >= 0 && ISDIGIT(c)) {
5358
- yyerror(p, "no .<digit> floating literal anymore; put 0 before dot");
5622
+ if (c >= 0 && ISDIGIT(c)) {
5623
+ yyerror(p, "no .<digit> floating literal anymore; put 0 before dot");
5624
+ }
5625
+ p->lstate = EXPR_DOT;
5626
+ return '.';
5359
5627
  }
5360
- p->lstate = EXPR_DOT;
5361
- return '.';
5362
5628
 
5363
5629
  start_num:
5364
5630
  case '0': case '1': case '2': case '3': case '4':
@@ -5574,7 +5840,7 @@ parser_yylex(parser_state *p)
5574
5840
  }
5575
5841
  tokfix(p);
5576
5842
  if (is_float) {
5577
- #ifdef MRB_WITHOUT_FLOAT
5843
+ #ifdef MRB_NO_FLOAT
5578
5844
  yywarning_s(p, "floating point numbers are not supported", tok(p));
5579
5845
  pylval.nd = new_int(p, "0", 10, 0);
5580
5846
  return tINTEGER;
@@ -5592,6 +5858,10 @@ parser_yylex(parser_state *p)
5592
5858
  errno = 0;
5593
5859
  }
5594
5860
  suffix = number_literal_suffix(p);
5861
+ if (seen_e && (suffix & NUM_SUFFIX_R)) {
5862
+ pushback(p, 'r');
5863
+ suffix &= ~NUM_SUFFIX_R;
5864
+ }
5595
5865
  pylval.nd = new_float(p, tok(p), suffix);
5596
5866
  return tFLOAT;
5597
5867
  #endif
@@ -5629,14 +5899,14 @@ parser_yylex(parser_state *p)
5629
5899
  p->lstate = EXPR_BEG;
5630
5900
  return tLABEL_TAG;
5631
5901
  }
5632
- if (!ISSPACE(c) || IS_BEG()) {
5902
+ if (IS_END() || ISSPACE(c) || c == '#') {
5633
5903
  pushback(p, c);
5634
- p->lstate = EXPR_FNAME;
5635
- return tSYMBEG;
5904
+ p->lstate = EXPR_BEG;
5905
+ return ':';
5636
5906
  }
5637
5907
  pushback(p, c);
5638
- p->lstate = EXPR_BEG;
5639
- return ':';
5908
+ p->lstate = EXPR_FNAME;
5909
+ return tSYMBEG;
5640
5910
 
5641
5911
  case '/':
5642
5912
  if (IS_BEG()) {
@@ -5644,7 +5914,7 @@ parser_yylex(parser_state *p)
5644
5914
  return tREGEXP_BEG;
5645
5915
  }
5646
5916
  if ((c = nextc(p)) == '=') {
5647
- pylval.id = intern_lit("/");
5917
+ pylval.id = intern_op(div);
5648
5918
  p->lstate = EXPR_BEG;
5649
5919
  return tOP_ASGN;
5650
5920
  }
@@ -5663,7 +5933,7 @@ parser_yylex(parser_state *p)
5663
5933
 
5664
5934
  case '^':
5665
5935
  if ((c = nextc(p)) == '=') {
5666
- pylval.id = intern_lit("^");
5936
+ pylval.id = intern_op(xor);
5667
5937
  p->lstate = EXPR_BEG;
5668
5938
  return tOP_ASGN;
5669
5939
  }
@@ -5716,6 +5986,7 @@ parser_yylex(parser_state *p)
5716
5986
  p->paren_nest++;
5717
5987
  if (p->lstate == EXPR_FNAME || p->lstate == EXPR_DOT) {
5718
5988
  p->lstate = EXPR_ARG;
5989
+ p->paren_nest--;
5719
5990
  if ((c = nextc(p)) == ']') {
5720
5991
  if ((c = nextc(p)) == '=') {
5721
5992
  return tASET;
@@ -5840,7 +6111,7 @@ parser_yylex(parser_state *p)
5840
6111
  }
5841
6112
  }
5842
6113
  if ((c = nextc(p)) == '=') {
5843
- pylval.id = intern_lit("%");
6114
+ pylval.id = intern_op(mod);
5844
6115
  p->lstate = EXPR_BEG;
5845
6116
  return tOP_ASGN;
5846
6117
  }
@@ -6043,7 +6314,7 @@ parser_yylex(parser_state *p)
6043
6314
  break;
6044
6315
 
6045
6316
  case '_':
6046
- if (toklen(p) == 2 && ISDIGIT(tok(p)[1]) && p->nvars) {
6317
+ if (p->lstate != EXPR_FNAME && toklen(p) == 2 && ISDIGIT(tok(p)[1]) && p->nvars) {
6047
6318
  int n = tok(p)[1] - '0';
6048
6319
  int nvar;
6049
6320
 
@@ -6304,7 +6575,7 @@ mrb_parser_new(mrb_state *mrb)
6304
6575
  p->pool = pool;
6305
6576
 
6306
6577
  p->s = p->send = NULL;
6307
- #ifndef MRB_DISABLE_STDIO
6578
+ #ifndef MRB_NO_STDIO
6308
6579
  p->f = NULL;
6309
6580
  #endif
6310
6581
 
@@ -6376,11 +6647,21 @@ mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser
6376
6647
  c->partial_data = data;
6377
6648
  }
6378
6649
 
6650
+ MRB_API void
6651
+ mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c)
6652
+ {
6653
+ if (c->syms) {
6654
+ mrb_free(mrb, c->syms);
6655
+ c->syms = NULL;
6656
+ c->slen = 0;
6657
+ }
6658
+ }
6659
+
6379
6660
  MRB_API void
6380
6661
  mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
6381
6662
  {
6382
6663
  mrb_sym sym;
6383
- size_t i;
6664
+ uint16_t i;
6384
6665
  mrb_sym* new_table;
6385
6666
 
6386
6667
  sym = mrb_intern_cstr(p->mrb, f);
@@ -6389,7 +6670,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
6389
6670
 
6390
6671
  for (i = 0; i < p->filename_table_length; ++i) {
6391
6672
  if (p->filename_table[i] == sym) {
6392
- p->current_filename_index = (int)i;
6673
+ p->current_filename_index = i;
6393
6674
  return;
6394
6675
  }
6395
6676
  }
@@ -6416,20 +6697,32 @@ mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) {
6416
6697
  }
6417
6698
  }
6418
6699
 
6419
- #ifndef MRB_DISABLE_STDIO
6420
- MRB_API parser_state*
6421
- mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c)
6700
+ #ifndef MRB_NO_STDIO
6701
+ static struct mrb_parser_state *
6702
+ mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t prebufsize, mrbc_context *c)
6422
6703
  {
6423
6704
  parser_state *p;
6424
6705
 
6425
6706
  p = mrb_parser_new(mrb);
6426
6707
  if (!p) return NULL;
6427
- p->s = p->send = NULL;
6708
+ if (prebuf) {
6709
+ p->s = (const char *)prebuf;
6710
+ p->send = (const char *)prebuf + prebufsize;
6711
+ }
6712
+ else {
6713
+ p->s = p->send = NULL;
6714
+ }
6428
6715
  p->f = f;
6429
6716
 
6430
6717
  mrb_parser_parse(p, c);
6431
6718
  return p;
6432
6719
  }
6720
+
6721
+ MRB_API parser_state*
6722
+ mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c)
6723
+ {
6724
+ return mrb_parse_file_continue(mrb, f, NULL, 0, c);
6725
+ }
6433
6726
  #endif
6434
6727
 
6435
6728
  MRB_API parser_state*
@@ -6458,7 +6751,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
6458
6751
  struct RClass *target = mrb->object_class;
6459
6752
  struct RProc *proc;
6460
6753
  mrb_value v;
6461
- unsigned int keep = 0;
6754
+ mrb_int keep = 0;
6462
6755
 
6463
6756
  if (!p) {
6464
6757
  return mrb_undef_value();
@@ -6478,7 +6771,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
6478
6771
  }
6479
6772
  else {
6480
6773
  if (mrb->exc == NULL) {
6481
- mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
6774
+ mrb->exc = mrb_obj_ptr(mrb_exc_new_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
6482
6775
  }
6483
6776
  mrb_parser_free(p);
6484
6777
  return mrb_undef_value();
@@ -6488,7 +6781,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
6488
6781
  mrb_parser_free(p);
6489
6782
  if (proc == NULL) {
6490
6783
  if (mrb->exc == NULL) {
6491
- mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
6784
+ mrb->exc = mrb_obj_ptr(mrb_exc_new_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
6492
6785
  }
6493
6786
  return mrb_undef_value();
6494
6787
  }
@@ -6507,14 +6800,14 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
6507
6800
  }
6508
6801
  MRB_PROC_SET_TARGET_CLASS(proc, target);
6509
6802
  if (mrb->c->ci) {
6510
- mrb->c->ci->target_class = target;
6803
+ mrb_vm_ci_target_class_set(mrb->c->ci, target);
6511
6804
  }
6512
6805
  v = mrb_top_run(mrb, proc, mrb_top_self(mrb), keep);
6513
6806
  if (mrb->exc) return mrb_nil_value();
6514
6807
  return v;
6515
6808
  }
6516
6809
 
6517
- #ifndef MRB_DISABLE_STDIO
6810
+ #ifndef MRB_NO_STDIO
6518
6811
  MRB_API mrb_value
6519
6812
  mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c)
6520
6813
  {
@@ -6526,6 +6819,55 @@ mrb_load_file(mrb_state *mrb, FILE *f)
6526
6819
  {
6527
6820
  return mrb_load_file_cxt(mrb, f, NULL);
6528
6821
  }
6822
+
6823
+ #define DETECT_SIZE 64
6824
+
6825
+ /*
6826
+ * In order to be recognized as a `.mrb` file, the following three points must be satisfied:
6827
+ * - File starts with "RITE"
6828
+ * - At least `sizeof(struct rite_binary_header)` bytes can be read
6829
+ * - `NUL` is included in the first 64 bytes of the file
6830
+ */
6831
+ MRB_API mrb_value
6832
+ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c)
6833
+ {
6834
+ union {
6835
+ char b[DETECT_SIZE];
6836
+ struct rite_binary_header h;
6837
+ } leading;
6838
+ size_t bufsize;
6839
+
6840
+ if (mrb == NULL || fp == NULL) {
6841
+ return mrb_nil_value();
6842
+ }
6843
+
6844
+ bufsize = fread(leading.b, sizeof(char), sizeof(leading), fp);
6845
+ if (bufsize < sizeof(leading.h) ||
6846
+ memcmp(leading.h.binary_ident, RITE_BINARY_IDENT, sizeof(leading.h.binary_ident)) != 0 ||
6847
+ memchr(leading.b, '\0', bufsize) == NULL) {
6848
+ return mrb_load_exec(mrb, mrb_parse_file_continue(mrb, fp, leading.b, bufsize, c), c);
6849
+ }
6850
+ else {
6851
+ size_t binsize;
6852
+ uint8_t *bin;
6853
+ mrb_value bin_obj = mrb_nil_value(); /* temporary string object */
6854
+ mrb_value result;
6855
+
6856
+ binsize = bin_to_uint32(leading.h.binary_size);
6857
+ bin_obj = mrb_str_new(mrb, NULL, binsize);
6858
+ bin = (uint8_t *)RSTRING_PTR(bin_obj);
6859
+ memcpy(bin, leading.b, bufsize);
6860
+ if (binsize > bufsize &&
6861
+ fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) {
6862
+ binsize = bufsize;
6863
+ /* The error is reported by mrb_load_irep_buf_cxt() */
6864
+ }
6865
+
6866
+ result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c);
6867
+ if (mrb_string_p(bin_obj)) mrb_str_resize(mrb, bin_obj, 0);
6868
+ return result;
6869
+ }
6870
+ }
6529
6871
  #endif
6530
6872
 
6531
6873
  MRB_API mrb_value
@@ -6552,7 +6894,7 @@ mrb_load_string(mrb_state *mrb, const char *s)
6552
6894
  return mrb_load_string_cxt(mrb, s, NULL);
6553
6895
  }
6554
6896
 
6555
- #ifndef MRB_DISABLE_STDIO
6897
+ #ifndef MRB_NO_STDIO
6556
6898
 
6557
6899
  static void
6558
6900
  dump_prefix(node *tree, int offset)
@@ -6627,7 +6969,7 @@ str_dump(mrb_state *mrb, const char *str, int len)
6627
6969
  int ai = mrb_gc_arena_save(mrb);
6628
6970
  mrb_value s;
6629
6971
  # if INT_MAX > MRB_INT_MAX / 4
6630
- /* check maximum length with "\xNN" charactor */
6972
+ /* check maximum length with "\xNN" character */
6631
6973
  if (len > MRB_INT_MAX / 4) {
6632
6974
  len = MRB_INT_MAX / 4;
6633
6975
  }
@@ -6642,7 +6984,7 @@ str_dump(mrb_state *mrb, const char *str, int len)
6642
6984
  void
6643
6985
  mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
6644
6986
  {
6645
- #ifndef MRB_DISABLE_STDIO
6987
+ #ifndef MRB_NO_STDIO
6646
6988
  int nodetype;
6647
6989
 
6648
6990
  if (!tree) return;
@@ -6969,7 +7311,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
6969
7311
  if (n2->car) {
6970
7312
  dump_prefix(n2, offset+2);
6971
7313
  printf("rest:\n");
6972
- if (n2->car == (node*)-1) {
7314
+ if (n2->car == nint(-1)) {
6973
7315
  dump_prefix(n2, offset+2);
6974
7316
  printf("(empty)\n");
6975
7317
  }
@@ -7211,11 +7553,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
7211
7553
 
7212
7554
  case NODE_CLASS:
7213
7555
  printf("NODE_CLASS:\n");
7214
- if (tree->car->car == (node*)0) {
7556
+ if (tree->car->car == nint(0)) {
7215
7557
  dump_prefix(tree, offset+1);
7216
7558
  printf(":%s\n", mrb_sym_name(mrb, sym(tree->car->cdr)));
7217
7559
  }
7218
- else if (tree->car->car == (node*)1) {
7560
+ else if (tree->car->car == nint(1)) {
7219
7561
  dump_prefix(tree, offset+1);
7220
7562
  printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr)));
7221
7563
  }
@@ -7236,11 +7578,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
7236
7578
 
7237
7579
  case NODE_MODULE:
7238
7580
  printf("NODE_MODULE:\n");
7239
- if (tree->car->car == (node*)0) {
7581
+ if (tree->car->car == nint(0)) {
7240
7582
  dump_prefix(tree, offset+1);
7241
7583
  printf(":%s\n", mrb_sym_name(mrb, sym(tree->car->cdr)));
7242
7584
  }
7243
- else if (tree->car->car == (node*)1) {
7585
+ else if (tree->car->car == nint(1)) {
7244
7586
  dump_prefix(tree, offset+1);
7245
7587
  printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr)));
7246
7588
  }