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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +2 -2
- data/ext/enterprise_script_service/Rakefile +1 -1
- data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +117 -74
- data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +41 -37
- data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
- data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
- data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
- data/ext/enterprise_script_service/mruby/.travis.yml +2 -2
- data/ext/enterprise_script_service/mruby/.yamllint +8 -0
- data/ext/enterprise_script_service/mruby/AUTHORS +3 -0
- data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
- data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
- data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
- data/ext/enterprise_script_service/mruby/LICENSE +1 -1
- data/ext/enterprise_script_service/mruby/Makefile +1 -1
- data/ext/enterprise_script_service/mruby/README.md +4 -14
- data/ext/enterprise_script_service/mruby/Rakefile +18 -108
- data/ext/enterprise_script_service/mruby/TODO.md +17 -0
- data/ext/enterprise_script_service/mruby/appveyor.yml +31 -25
- data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
- data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +2 -19
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +2 -2
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +1 -18
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +2 -19
- data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
- 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
- data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +2 -19
- data/ext/enterprise_script_service/mruby/{travis_config.rb → build_config/ci/gcc-clang.rb} +10 -10
- data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
- data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
- data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_dreamcast_shelf.rb → build_config/dreamcast_shelf.rb} +5 -19
- data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
- data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
- data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
- data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
- data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
- data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
- data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
- data/ext/enterprise_script_service/mruby/doc/guides/compile.md +138 -49
- data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
- data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
- data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +49 -22
- data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
- data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
- data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
- data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
- data/ext/enterprise_script_service/mruby/doc/opcode.md +93 -107
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
- data/ext/enterprise_script_service/mruby/include/mrbconf.h +81 -62
- data/ext/enterprise_script_service/mruby/include/mruby.h +137 -96
- data/ext/enterprise_script_service/mruby/include/mruby/array.h +23 -6
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +73 -48
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +79 -48
- data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
- data/ext/enterprise_script_service/mruby/include/mruby/common.h +4 -1
- data/ext/enterprise_script_service/mruby/include/mruby/compile.h +13 -7
- data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/dump.h +17 -35
- data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
- data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
- data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
- data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
- data/ext/enterprise_script_service/mruby/include/mruby/irep.h +64 -14
- data/ext/enterprise_script_service/mruby/include/mruby/khash.h +6 -14
- data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +36 -63
- data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
- data/ext/enterprise_script_service/mruby/include/mruby/ops.h +27 -23
- data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
- data/ext/enterprise_script_service/mruby/include/mruby/proc.h +80 -13
- data/ext/enterprise_script_service/mruby/include/mruby/string.h +10 -15
- data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
- data/ext/enterprise_script_service/mruby/include/mruby/value.h +29 -19
- data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
- data/ext/enterprise_script_service/mruby/include/mruby/version.h +26 -7
- data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -44
- data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +55 -37
- data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
- data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
- data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +75 -32
- data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
- data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
- data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
- data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
- data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -88
- data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
- data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +5 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +28 -19
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +41 -34
- data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +19 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +22 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +2 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +430 -399
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +559 -217
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +4774 -4193
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +18 -19
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +8 -7
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +17 -25
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +18 -13
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +30 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +55 -52
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +4 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +99 -87
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +2 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +2 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +7 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +43 -58
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +77 -74
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +5 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +38 -88
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +62 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +32 -19
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +20 -40
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +11 -17
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +102 -71
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +4 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +13 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +18 -25
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +6 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +16 -44
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +27 -27
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
- data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
- data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
- data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrblib/hash.rb +0 -20
- data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
- data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
- data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
- data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
- data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
- data/ext/enterprise_script_service/mruby/src/array.c +43 -80
- data/ext/enterprise_script_service/mruby/src/backtrace.c +16 -17
- data/ext/enterprise_script_service/mruby/src/class.c +774 -182
- data/ext/enterprise_script_service/mruby/src/codedump.c +223 -198
- data/ext/enterprise_script_service/mruby/src/debug.c +6 -6
- data/ext/enterprise_script_service/mruby/src/dump.c +466 -141
- data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
- data/ext/enterprise_script_service/mruby/src/error.c +36 -13
- data/ext/enterprise_script_service/mruby/src/etc.c +43 -34
- data/ext/enterprise_script_service/mruby/src/fmt_fp.c +5 -6
- data/ext/enterprise_script_service/mruby/src/gc.c +73 -71
- data/ext/enterprise_script_service/mruby/src/hash.c +1050 -707
- data/ext/enterprise_script_service/mruby/src/kernel.c +75 -220
- data/ext/enterprise_script_service/mruby/src/load.c +196 -166
- data/ext/enterprise_script_service/mruby/src/numeric.c +352 -314
- data/ext/enterprise_script_service/mruby/src/object.c +97 -90
- data/ext/enterprise_script_service/mruby/src/print.c +4 -3
- data/ext/enterprise_script_service/mruby/src/proc.c +48 -56
- data/ext/enterprise_script_service/mruby/src/range.c +45 -21
- data/ext/enterprise_script_service/mruby/src/state.c +25 -32
- data/ext/enterprise_script_service/mruby/src/string.c +59 -101
- data/ext/enterprise_script_service/mruby/src/symbol.c +121 -56
- data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
- data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
- data/ext/enterprise_script_service/mruby/src/vm.c +617 -602
- data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
- data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
- data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
- data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
- data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +83 -77
- data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
- data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
- data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
- data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
- data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
- data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +6 -5
- data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +10 -14
- data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +17 -21
- data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
- data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
- data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
- data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
- data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
- data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
- data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
- data/ext/enterprise_script_service/mruby/test/t/kernel.rb +1 -1
- data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
- data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
- data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
- data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
- data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
- data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
- data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
- data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
- data/ext/enterprise_script_service/mruby_config.rb +2 -5
- data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
- data/lib/script_core/version.rb +1 -1
- data/spec/script_core_spec.rb +13 -0
- metadata +61 -23
- data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +0 -24
- data/ext/enterprise_script_service/mruby/TODO +0 -8
- data/ext/enterprise_script_service/mruby/appveyor_config.rb +0 -46
- data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
- data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
- data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
- data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
- data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
- data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
@@ -12,10 +12,27 @@ class Range
|
|
12
12
|
def each(&block)
|
13
13
|
return to_enum :each unless block
|
14
14
|
|
15
|
-
val = self.
|
16
|
-
last = self.
|
15
|
+
val = self.begin
|
16
|
+
last = self.end
|
17
17
|
|
18
|
-
if val.kind_of?(Fixnum) && last.
|
18
|
+
if val.kind_of?(Fixnum) && last.nil?
|
19
|
+
i = val
|
20
|
+
while true
|
21
|
+
block.call(i)
|
22
|
+
i += 1
|
23
|
+
end
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
if val.kind_of?(String) && last.nil?
|
28
|
+
if val.respond_to? :__upto_endless
|
29
|
+
return val.__upto_endless(&block)
|
30
|
+
else
|
31
|
+
str_each = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if val.kind_of?(Integer) && last.kind_of?(Integer) # fixnums are special
|
19
36
|
lim = last
|
20
37
|
lim += 1 unless exclude_end?
|
21
38
|
i = val
|
@@ -56,6 +73,11 @@ def hash
|
|
56
73
|
h += 1 if self.exclude_end?
|
57
74
|
h
|
58
75
|
end
|
76
|
+
|
77
|
+
def to_a
|
78
|
+
raise RangeError, "cannot convert endless range to an array" if self.last.nil?
|
79
|
+
super
|
80
|
+
end
|
59
81
|
end
|
60
82
|
|
61
83
|
##
|
@@ -5,8 +5,8 @@
|
|
5
5
|
#include <mruby.h>
|
6
6
|
#include <mruby/compile.h>
|
7
7
|
|
8
|
-
#include
|
9
|
-
#include
|
8
|
+
#include <src/libfuzzer/libfuzzer_macro.h>
|
9
|
+
#include <ruby.pb.h>
|
10
10
|
#include "proto_to_ruby.h"
|
11
11
|
|
12
12
|
using namespace ruby_fuzzer;
|
@@ -10,7 +10,7 @@
|
|
10
10
|
#include <mruby/string.h>
|
11
11
|
#include <mruby/range.h>
|
12
12
|
#include <mruby/proc.h>
|
13
|
-
#include <mruby/
|
13
|
+
#include <mruby/presym.h>
|
14
14
|
#include "value_array.h"
|
15
15
|
|
16
16
|
#define ARY_DEFAULT_LEN 4
|
@@ -280,7 +280,7 @@ static mrb_value
|
|
280
280
|
mrb_ary_s_create(mrb_state *mrb, mrb_value klass)
|
281
281
|
{
|
282
282
|
mrb_value ary;
|
283
|
-
mrb_value *vals;
|
283
|
+
const mrb_value *vals;
|
284
284
|
mrb_int len;
|
285
285
|
struct RArray *a;
|
286
286
|
|
@@ -340,7 +340,7 @@ mrb_ary_plus(mrb_state *mrb, mrb_value self)
|
|
340
340
|
{
|
341
341
|
struct RArray *a1 = mrb_ary_ptr(self);
|
342
342
|
struct RArray *a2;
|
343
|
-
mrb_value *ptr;
|
343
|
+
const mrb_value *ptr;
|
344
344
|
mrb_int blen, len1;
|
345
345
|
|
346
346
|
mrb_get_args(mrb, "a", &ptr, &blen);
|
@@ -508,22 +508,26 @@ mrb_ary_push(mrb_state *mrb, mrb_value ary, mrb_value elem)
|
|
508
508
|
static mrb_value
|
509
509
|
mrb_ary_push_m(mrb_state *mrb, mrb_value self)
|
510
510
|
{
|
511
|
-
|
512
|
-
|
511
|
+
mrb_int argc;
|
512
|
+
const mrb_value *argv;
|
513
|
+
mrb_int len, len2;
|
513
514
|
struct RArray *a;
|
514
515
|
|
515
|
-
|
516
|
+
argc = mrb_get_argc(mrb);
|
517
|
+
argv = mrb_get_argv(mrb);
|
516
518
|
a = mrb_ary_ptr(self);
|
517
519
|
ary_modify(mrb, a);
|
518
520
|
len = ARY_LEN(a);
|
519
|
-
len2 = len +
|
521
|
+
len2 = len + argc;
|
520
522
|
if (ARY_CAPA(a) < len2) {
|
521
523
|
ary_expand_capa(mrb, a, len2);
|
522
524
|
}
|
523
|
-
array_copy(ARY_PTR(a)+len, argv,
|
525
|
+
array_copy(ARY_PTR(a)+len, argv, argc);
|
524
526
|
ARY_SET_LEN(a, len2);
|
525
|
-
|
526
|
-
|
527
|
+
while (argc--) {
|
528
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, *argv);
|
529
|
+
argv++;
|
530
|
+
}
|
527
531
|
return self;
|
528
532
|
}
|
529
533
|
|
@@ -611,7 +615,8 @@ static mrb_value
|
|
611
615
|
mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
|
612
616
|
{
|
613
617
|
struct RArray *a = mrb_ary_ptr(self);
|
614
|
-
mrb_value *vals
|
618
|
+
const mrb_value *vals;
|
619
|
+
mrb_value *ptr;
|
615
620
|
mrb_int alen, len;
|
616
621
|
|
617
622
|
mrb_get_args(mrb, "*!", &vals, &alen);
|
@@ -818,17 +823,17 @@ mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len)
|
|
818
823
|
static mrb_int
|
819
824
|
aget_index(mrb_state *mrb, mrb_value index)
|
820
825
|
{
|
821
|
-
if (
|
822
|
-
return
|
826
|
+
if (mrb_integer_p(index)) {
|
827
|
+
return mrb_integer(index);
|
823
828
|
}
|
824
|
-
#ifndef
|
829
|
+
#ifndef MRB_NO_FLOAT
|
825
830
|
else if (mrb_float_p(index)) {
|
826
831
|
return (mrb_int)mrb_float(index);
|
827
832
|
}
|
828
833
|
#endif
|
829
834
|
else {
|
830
835
|
mrb_int i, argc;
|
831
|
-
mrb_value *argv;
|
836
|
+
const mrb_value *argv;
|
832
837
|
|
833
838
|
mrb_get_args(mrb, "i*!", &i, &argv, &argc);
|
834
839
|
return i;
|
@@ -881,8 +886,8 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
|
|
881
886
|
else {
|
882
887
|
return mrb_nil_value();
|
883
888
|
}
|
884
|
-
case
|
885
|
-
return mrb_ary_ref(mrb, self,
|
889
|
+
case MRB_TT_INTEGER:
|
890
|
+
return mrb_ary_ref(mrb, self, mrb_integer(index));
|
886
891
|
default:
|
887
892
|
return mrb_ary_ref(mrb, self, aget_index(mrb, index));
|
888
893
|
}
|
@@ -941,9 +946,9 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self)
|
|
941
946
|
mrb_value v1, v2, v3;
|
942
947
|
mrb_int i, len;
|
943
948
|
|
944
|
-
|
949
|
+
ary_modify(mrb, mrb_ary_ptr(self));
|
945
950
|
if (mrb_get_argc(mrb) == 2) {
|
946
|
-
mrb_value *vs = mrb_get_argv(mrb);
|
951
|
+
const mrb_value *vs = mrb_get_argv(mrb);
|
947
952
|
v1 = vs[0]; v2 = vs[1];
|
948
953
|
|
949
954
|
/* a[n..m] = v */
|
@@ -1076,22 +1081,26 @@ mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
|
|
1076
1081
|
MRB_API mrb_value
|
1077
1082
|
mrb_ary_splat(mrb_state *mrb, mrb_value v)
|
1078
1083
|
{
|
1079
|
-
mrb_value
|
1084
|
+
mrb_value ary;
|
1085
|
+
struct RArray *a;
|
1080
1086
|
|
1081
1087
|
if (mrb_array_p(v)) {
|
1082
|
-
|
1088
|
+
a = ary_dup(mrb, mrb_ary_ptr(v));
|
1089
|
+
return mrb_obj_value(a);
|
1083
1090
|
}
|
1084
1091
|
|
1085
|
-
if (!mrb_respond_to(mrb, v,
|
1092
|
+
if (!mrb_respond_to(mrb, v, MRB_SYM(to_a))) {
|
1086
1093
|
return mrb_ary_new_from_values(mrb, 1, &v);
|
1087
1094
|
}
|
1088
1095
|
|
1089
|
-
|
1090
|
-
if (mrb_nil_p(
|
1096
|
+
ary = mrb_funcall_id(mrb, v, MRB_SYM(to_a), 0);
|
1097
|
+
if (mrb_nil_p(ary)) {
|
1091
1098
|
return mrb_ary_new_from_values(mrb, 1, &v);
|
1092
1099
|
}
|
1093
|
-
mrb_ensure_array_type(mrb,
|
1094
|
-
|
1100
|
+
mrb_ensure_array_type(mrb, ary);
|
1101
|
+
a = mrb_ary_ptr(ary);
|
1102
|
+
a = ary_dup(mrb, a);
|
1103
|
+
return mrb_obj_value(a);
|
1095
1104
|
}
|
1096
1105
|
|
1097
1106
|
static mrb_value
|
@@ -1115,8 +1124,14 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self)
|
|
1115
1124
|
else if (!ARY_EMBED_P(a)){
|
1116
1125
|
mrb_free(mrb, a->as.heap.ptr);
|
1117
1126
|
}
|
1118
|
-
|
1119
|
-
|
1127
|
+
if (MRB_ARY_EMBED_LEN_MAX > 0) {
|
1128
|
+
ARY_SET_EMBED_LEN(a, 0);
|
1129
|
+
}
|
1130
|
+
else {
|
1131
|
+
a->as.heap.ptr = NULL;
|
1132
|
+
a->as.heap.aux.capa = 0;
|
1133
|
+
ARY_SET_LEN(a, 0);
|
1134
|
+
}
|
1120
1135
|
return self;
|
1121
1136
|
}
|
1122
1137
|
|
@@ -1273,56 +1288,6 @@ mrb_ary_svalue(mrb_state *mrb, mrb_value ary)
|
|
1273
1288
|
}
|
1274
1289
|
}
|
1275
1290
|
|
1276
|
-
static const mrb_code each_iseq[] = {
|
1277
|
-
OP_ENTER, 0x0, 0x00, 0x1, /* OP_ENTER 0:0:0:0:0:0:1 */
|
1278
|
-
OP_JMPIF, 0x1, 0x0, 19, /* OP_JMPIF R1 19 */
|
1279
|
-
OP_LOADSELF, 0x3, /* OP_LOADSELF R3 */
|
1280
|
-
OP_LOADSYM, 0x4, 0x0, /* OP_LOADSYM R4 :each*/
|
1281
|
-
OP_SEND, 0x3, 0x1, 0x1, /* OP_SEND R3 :to_enum 1 */
|
1282
|
-
OP_RETURN, 0x3, /* OP_RETURN R3 */
|
1283
|
-
OP_LOADI_0, 0x2, /* OP_LOADI_0 R2 */
|
1284
|
-
OP_JMP, 0x0, 43, /* OP_JMP 49 */
|
1285
|
-
OP_MOVE, 0x3, 0x1, /* OP_MOVE R3 R1 */
|
1286
|
-
OP_LOADSELF, 0x4, /* OP_LOADSELF R4 */
|
1287
|
-
OP_MOVE, 0x5, 0x2, /* OP_MOVE R5 R2 */
|
1288
|
-
OP_SEND, 0x4, 0x2, 0x1, /* OP_SEND R4 :[] 1 */
|
1289
|
-
OP_SEND, 0x3, 0x3, 0x1, /* OP_SEND R3 :call 1 */
|
1290
|
-
OP_ADDI, 0x2, 1, /* OP_ADDI R3 1 */
|
1291
|
-
OP_MOVE, 0x3, 0x2, /* OP_MOVE R3 R2 */
|
1292
|
-
OP_LOADSELF, 0x4, /* OP_LOADSELF R4 */
|
1293
|
-
OP_SEND, 0x4, 0x4, 0x0, /* OP_SEND R4 :length 0 */
|
1294
|
-
OP_LT, 0x3, /* OP_LT R3 */
|
1295
|
-
OP_JMPIF, 0x3, 0x0, 24, /* OP_JMPIF R3 24 */
|
1296
|
-
OP_RETURN, 0x0 /* OP_RETURN R3 */
|
1297
|
-
};
|
1298
|
-
|
1299
|
-
static void
|
1300
|
-
init_ary_each(mrb_state *mrb, struct RClass *ary)
|
1301
|
-
{
|
1302
|
-
struct RProc *p;
|
1303
|
-
mrb_method_t m;
|
1304
|
-
mrb_irep *each_irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep));
|
1305
|
-
static const mrb_irep mrb_irep_zero = { 0 };
|
1306
|
-
|
1307
|
-
*each_irep = mrb_irep_zero;
|
1308
|
-
each_irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*5);
|
1309
|
-
each_irep->syms[0] = mrb_intern_lit(mrb, "each");
|
1310
|
-
each_irep->syms[1] = mrb_intern_lit(mrb, "to_enum");
|
1311
|
-
each_irep->syms[2] = mrb_intern_lit(mrb, "[]");
|
1312
|
-
each_irep->syms[3] = mrb_intern_lit(mrb, "call");
|
1313
|
-
each_irep->syms[4] = mrb_intern_lit(mrb, "length");
|
1314
|
-
each_irep->slen = 5;
|
1315
|
-
each_irep->flags = MRB_ISEQ_NO_FREE;
|
1316
|
-
each_irep->iseq = each_iseq;
|
1317
|
-
each_irep->ilen = sizeof(each_iseq);
|
1318
|
-
each_irep->nregs = 7;
|
1319
|
-
each_irep->nlocals = 3;
|
1320
|
-
p = mrb_proc_new(mrb, each_irep);
|
1321
|
-
p->flags |= MRB_PROC_SCOPE | MRB_PROC_STRICT;
|
1322
|
-
MRB_METHOD_FROM_PROC(m, p);
|
1323
|
-
mrb_define_method_raw(mrb, ary, mrb_intern_lit(mrb, "each"), m);
|
1324
|
-
}
|
1325
|
-
|
1326
1291
|
void
|
1327
1292
|
mrb_init_array(mrb_state *mrb)
|
1328
1293
|
{
|
@@ -1363,6 +1328,4 @@ mrb_init_array(mrb_state *mrb)
|
|
1363
1328
|
mrb_define_method(mrb, a, "__ary_cmp", mrb_ary_cmp, MRB_ARGS_REQ(1));
|
1364
1329
|
mrb_define_method(mrb, a, "__ary_index", mrb_ary_index_m, MRB_ARGS_REQ(1)); /* kept for mruby-array-ext */
|
1365
1330
|
mrb_define_method(mrb, a, "__svalue", mrb_ary_svalue, MRB_ARGS_NONE());
|
1366
|
-
|
1367
|
-
init_ary_each(mrb, a);
|
1368
1331
|
}
|
@@ -14,6 +14,7 @@
|
|
14
14
|
#include <mruby/error.h>
|
15
15
|
#include <mruby/numeric.h>
|
16
16
|
#include <mruby/data.h>
|
17
|
+
#include <mruby/presym.h>
|
17
18
|
|
18
19
|
struct backtrace_location {
|
19
20
|
int32_t lineno;
|
@@ -29,7 +30,7 @@ mrb_value mrb_exc_inspect(mrb_state *mrb, mrb_value exc);
|
|
29
30
|
mrb_value mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace);
|
30
31
|
|
31
32
|
static void
|
32
|
-
each_backtrace(mrb_state *mrb, ptrdiff_t ciidx,
|
33
|
+
each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *data)
|
33
34
|
{
|
34
35
|
ptrdiff_t i;
|
35
36
|
|
@@ -39,8 +40,9 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
|
|
39
40
|
for (i=ciidx; i >= 0; i--) {
|
40
41
|
struct backtrace_location loc;
|
41
42
|
mrb_callinfo *ci;
|
42
|
-
mrb_irep *irep;
|
43
|
+
const mrb_irep *irep;
|
43
44
|
const mrb_code *pc;
|
45
|
+
uint32_t idx;
|
44
46
|
|
45
47
|
ci = &mrb->c->cibase[i];
|
46
48
|
|
@@ -50,21 +52,18 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
|
|
50
52
|
irep = ci->proc->body.irep;
|
51
53
|
if (!irep) continue;
|
52
54
|
|
53
|
-
if (mrb->c->cibase[i].
|
54
|
-
pc = mrb->c->cibase[i].
|
55
|
-
}
|
56
|
-
else if (i+1 <= ciidx) {
|
57
|
-
if (!mrb->c->cibase[i + 1].pc) continue;
|
58
|
-
pc = &mrb->c->cibase[i+1].pc[-1];
|
55
|
+
if (mrb->c->cibase[i].pc) {
|
56
|
+
pc = &mrb->c->cibase[i].pc[-1];
|
59
57
|
}
|
60
58
|
else {
|
61
|
-
|
59
|
+
continue;
|
62
60
|
}
|
63
61
|
|
64
|
-
|
62
|
+
idx = (uint32_t)(pc - irep->iseq);
|
63
|
+
loc.lineno = mrb_debug_get_line(mrb, irep, idx);
|
65
64
|
if (loc.lineno == -1) continue;
|
66
65
|
|
67
|
-
loc.filename = mrb_debug_get_filename(mrb, irep,
|
66
|
+
loc.filename = mrb_debug_get_filename(mrb, irep, idx);
|
68
67
|
if (!loc.filename) {
|
69
68
|
loc.filename = "(unknown)";
|
70
69
|
}
|
@@ -74,7 +73,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
|
|
74
73
|
}
|
75
74
|
}
|
76
75
|
|
77
|
-
#ifndef
|
76
|
+
#ifndef MRB_NO_STDIO
|
78
77
|
|
79
78
|
static void
|
80
79
|
print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
|
@@ -114,7 +113,7 @@ mrb_print_backtrace(mrb_state *mrb)
|
|
114
113
|
return;
|
115
114
|
}
|
116
115
|
|
117
|
-
backtrace = mrb_obj_iv_get(mrb, mrb->exc,
|
116
|
+
backtrace = mrb_obj_iv_get(mrb, mrb->exc, MRB_SYM(backtrace));
|
118
117
|
if (mrb_nil_p(backtrace)) return;
|
119
118
|
if (!mrb_array_p(backtrace)) backtrace = mrb_unpack_backtrace(mrb, backtrace);
|
120
119
|
print_backtrace(mrb, mrb->exc, backtrace);
|
@@ -159,19 +158,19 @@ packed_backtrace(mrb_state *mrb)
|
|
159
158
|
int size;
|
160
159
|
void *ptr;
|
161
160
|
|
162
|
-
each_backtrace(mrb, ciidx,
|
161
|
+
each_backtrace(mrb, ciidx, count_backtrace_i, &len);
|
163
162
|
size = len * sizeof(struct backtrace_location);
|
164
163
|
ptr = mrb_malloc(mrb, size);
|
165
164
|
backtrace = mrb_data_object_alloc(mrb, NULL, ptr, &bt_type);
|
166
165
|
backtrace->flags = (uint32_t)len;
|
167
|
-
each_backtrace(mrb, ciidx,
|
166
|
+
each_backtrace(mrb, ciidx, pack_backtrace_i, &ptr);
|
168
167
|
return mrb_obj_value(backtrace);
|
169
168
|
}
|
170
169
|
|
171
170
|
void
|
172
171
|
mrb_keep_backtrace(mrb_state *mrb, mrb_value exc)
|
173
172
|
{
|
174
|
-
mrb_sym sym =
|
173
|
+
mrb_sym sym = MRB_SYM(backtrace);
|
175
174
|
mrb_value backtrace;
|
176
175
|
int ai;
|
177
176
|
|
@@ -221,7 +220,7 @@ mrb_exc_backtrace(mrb_state *mrb, mrb_value exc)
|
|
221
220
|
mrb_sym attr_name;
|
222
221
|
mrb_value backtrace;
|
223
222
|
|
224
|
-
attr_name =
|
223
|
+
attr_name = MRB_SYM(backtrace);
|
225
224
|
backtrace = mrb_iv_get(mrb, exc, attr_name);
|
226
225
|
if (mrb_nil_p(backtrace) || mrb_array_p(backtrace)) {
|
227
226
|
return backtrace;
|
@@ -17,48 +17,284 @@
|
|
17
17
|
#include <mruby/data.h>
|
18
18
|
#include <mruby/istruct.h>
|
19
19
|
#include <mruby/opcode.h>
|
20
|
+
#include <mruby/presym.h>
|
20
21
|
|
21
|
-
|
22
|
+
union mt_ptr {
|
23
|
+
struct RProc *proc;
|
24
|
+
mrb_func_t func;
|
25
|
+
};
|
26
|
+
|
27
|
+
struct mt_elem {
|
28
|
+
union mt_ptr ptr;
|
29
|
+
size_t func_p:1;
|
30
|
+
size_t noarg_p:1;
|
31
|
+
mrb_sym key:sizeof(mrb_sym)*8-2;
|
32
|
+
};
|
33
|
+
|
34
|
+
/* method table structure */
|
35
|
+
typedef struct mt_tbl {
|
36
|
+
size_t size;
|
37
|
+
size_t alloc;
|
38
|
+
struct mt_elem *table;
|
39
|
+
} mt_tbl;
|
40
|
+
|
41
|
+
/* Creates the method table. */
|
42
|
+
static mt_tbl*
|
43
|
+
mt_new(mrb_state *mrb)
|
44
|
+
{
|
45
|
+
mt_tbl *t;
|
46
|
+
|
47
|
+
t = (mt_tbl*)mrb_malloc(mrb, sizeof(mt_tbl));
|
48
|
+
t->size = 0;
|
49
|
+
t->alloc = 0;
|
50
|
+
t->table = NULL;
|
51
|
+
|
52
|
+
return t;
|
53
|
+
}
|
54
|
+
|
55
|
+
static struct mt_elem *mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr);
|
56
|
+
|
57
|
+
static void
|
58
|
+
mt_rehash(mrb_state *mrb, mt_tbl *t)
|
59
|
+
{
|
60
|
+
size_t old_alloc = t->alloc;
|
61
|
+
size_t new_alloc = old_alloc+1;
|
62
|
+
struct mt_elem *old_table = t->table;
|
63
|
+
|
64
|
+
khash_power2(new_alloc);
|
65
|
+
if (old_alloc == new_alloc) return;
|
66
|
+
|
67
|
+
t->alloc = new_alloc;
|
68
|
+
t->size = 0;
|
69
|
+
t->table = (struct mt_elem*)mrb_calloc(mrb, sizeof(struct mt_elem), new_alloc);
|
70
|
+
|
71
|
+
for (size_t i = 0; i < old_alloc; i++) {
|
72
|
+
struct mt_elem *slot = &old_table[i];
|
73
|
+
|
74
|
+
/* key = 0 means empty or deleted */
|
75
|
+
if (slot->key != 0) {
|
76
|
+
mt_put(mrb, t, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
mrb_free(mrb, old_table);
|
80
|
+
}
|
81
|
+
|
82
|
+
#define slot_empty_p(slot) ((slot)->key == 0 && (slot)->func_p == 0)
|
83
|
+
|
84
|
+
/* Set the value for the symbol in the method table. */
|
85
|
+
static struct mt_elem*
|
86
|
+
mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr)
|
87
|
+
{
|
88
|
+
size_t hash, pos, start;
|
89
|
+
struct mt_elem *dslot = NULL;
|
90
|
+
|
91
|
+
if (t->alloc == 0) {
|
92
|
+
mt_rehash(mrb, t);
|
93
|
+
}
|
94
|
+
hash = kh_int_hash_func(mrb, sym);
|
95
|
+
start = pos = hash & (t->alloc-1);
|
96
|
+
for (;;) {
|
97
|
+
struct mt_elem *slot = &t->table[pos];
|
98
|
+
|
99
|
+
if (slot->key == sym) {
|
100
|
+
slot->func_p = func_p;
|
101
|
+
slot->noarg_p = noarg_p;
|
102
|
+
slot->ptr = ptr;
|
103
|
+
return slot;
|
104
|
+
}
|
105
|
+
else if (slot->key == 0) { /* empty or deleted */
|
106
|
+
if (slot->func_p == 0) { /* empty */
|
107
|
+
t->size++;
|
108
|
+
slot->key = sym;
|
109
|
+
slot->func_p = func_p;
|
110
|
+
slot->noarg_p = noarg_p;
|
111
|
+
slot->ptr = ptr;
|
112
|
+
return slot;
|
113
|
+
}
|
114
|
+
else if (!dslot) { /* deleted */
|
115
|
+
dslot = slot;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
pos = (pos+1) & (t->alloc-1);
|
119
|
+
if (pos == start) { /* not found */
|
120
|
+
if (dslot) {
|
121
|
+
t->size++;
|
122
|
+
dslot->key = sym;
|
123
|
+
dslot->func_p = func_p;
|
124
|
+
dslot->noarg_p = noarg_p;
|
125
|
+
dslot->ptr = ptr;
|
126
|
+
return dslot;
|
127
|
+
}
|
128
|
+
/* no room */
|
129
|
+
mt_rehash(mrb, t);
|
130
|
+
start = pos = hash & (t->alloc-1);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
/* Get a value for a symbol from the method table. */
|
136
|
+
static struct mt_elem*
|
137
|
+
mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym)
|
138
|
+
{
|
139
|
+
size_t hash, pos, start;
|
140
|
+
|
141
|
+
if (t == NULL) return NULL;
|
142
|
+
if (t->alloc == 0) return NULL;
|
143
|
+
if (t->size == 0) return NULL;
|
144
|
+
|
145
|
+
hash = kh_int_hash_func(mrb, sym);
|
146
|
+
start = pos = hash & (t->alloc-1);
|
147
|
+
for (;;) {
|
148
|
+
struct mt_elem *slot = &t->table[pos];
|
149
|
+
|
150
|
+
if (slot->key == sym) {
|
151
|
+
return slot;
|
152
|
+
}
|
153
|
+
else if (slot_empty_p(slot)) {
|
154
|
+
return NULL;
|
155
|
+
}
|
156
|
+
pos = (pos+1) & (t->alloc-1);
|
157
|
+
if (pos == start) { /* not found */
|
158
|
+
return NULL;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
/* Deletes the value for the symbol from the method table. */
|
164
|
+
static mrb_bool
|
165
|
+
mt_del(mrb_state *mrb, mt_tbl *t, mrb_sym sym)
|
166
|
+
{
|
167
|
+
size_t hash, pos, start;
|
168
|
+
|
169
|
+
if (t == NULL) return FALSE;
|
170
|
+
if (t->alloc == 0) return FALSE;
|
171
|
+
if (t->size == 0) return FALSE;
|
172
|
+
|
173
|
+
hash = kh_int_hash_func(mrb, sym);
|
174
|
+
start = pos = hash & (t->alloc-1);
|
175
|
+
for (;;) {
|
176
|
+
struct mt_elem *slot = &t->table[pos];
|
177
|
+
|
178
|
+
if (slot->key == sym) {
|
179
|
+
t->size--;
|
180
|
+
slot->key = 0;
|
181
|
+
slot->func_p = 1;
|
182
|
+
return TRUE;
|
183
|
+
}
|
184
|
+
else if (slot_empty_p(slot)) {
|
185
|
+
return FALSE;
|
186
|
+
}
|
187
|
+
pos = (pos+1) & (t->alloc-1);
|
188
|
+
if (pos == start) { /* not found */
|
189
|
+
return FALSE;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
/* Copy the method table. */
|
195
|
+
static struct mt_tbl*
|
196
|
+
mt_copy(mrb_state *mrb, mt_tbl *t)
|
197
|
+
{
|
198
|
+
mt_tbl *t2;
|
199
|
+
size_t i;
|
200
|
+
|
201
|
+
if (t == NULL) return NULL;
|
202
|
+
if (t->alloc == 0) return NULL;
|
203
|
+
if (t->size == 0) return NULL;
|
204
|
+
|
205
|
+
t2 = mt_new(mrb);
|
206
|
+
for (i=0; i<t->alloc; i++) {
|
207
|
+
struct mt_elem *slot = &t->table[i];
|
208
|
+
|
209
|
+
if (slot->key) {
|
210
|
+
mt_put(mrb, t2, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
return t2;
|
214
|
+
}
|
215
|
+
|
216
|
+
/* Free memory of the method table. */
|
217
|
+
static void
|
218
|
+
mt_free(mrb_state *mrb, mt_tbl *t)
|
219
|
+
{
|
220
|
+
mrb_free(mrb, t->table);
|
221
|
+
mrb_free(mrb, t);
|
222
|
+
}
|
223
|
+
|
224
|
+
MRB_API void
|
225
|
+
mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *p)
|
226
|
+
{
|
227
|
+
mt_tbl *t = c->mt;
|
228
|
+
size_t i;
|
229
|
+
|
230
|
+
if (t == NULL) return;
|
231
|
+
if (t->alloc == 0) return;
|
232
|
+
if (t->size == 0) return;
|
233
|
+
|
234
|
+
for (i=0; i<t->alloc; i++) {
|
235
|
+
struct mt_elem *slot = &t->table[i];
|
236
|
+
|
237
|
+
if (slot->key) {
|
238
|
+
mrb_method_t m;
|
239
|
+
|
240
|
+
if (slot->func_p) {
|
241
|
+
MRB_METHOD_FROM_FUNC(m, slot->ptr.func);
|
242
|
+
}
|
243
|
+
else {
|
244
|
+
MRB_METHOD_FROM_PROC(m, slot->ptr.proc);
|
245
|
+
}
|
246
|
+
if (slot->noarg_p) {
|
247
|
+
MRB_METHOD_NOARG_SET(m);
|
248
|
+
}
|
249
|
+
|
250
|
+
if (fn(mrb, slot->key, m, p) != 0)
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
return;
|
255
|
+
}
|
22
256
|
|
23
257
|
void
|
24
258
|
mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c)
|
25
259
|
{
|
26
|
-
|
27
|
-
|
260
|
+
mt_tbl *t = c->mt;
|
261
|
+
size_t i;
|
28
262
|
|
29
|
-
if (
|
30
|
-
|
31
|
-
|
32
|
-
mrb_method_t m = kh_value(h, k);
|
263
|
+
if (t == NULL) return;
|
264
|
+
if (t->alloc == 0) return;
|
265
|
+
if (t->size == 0) return;
|
33
266
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
267
|
+
for (i=0; i<t->alloc; i++) {
|
268
|
+
struct mt_elem *slot = &t->table[i];
|
269
|
+
|
270
|
+
if (slot->key && !slot->func_p) { /* Proc pointer */
|
271
|
+
struct RProc *p = slot->ptr.proc;
|
272
|
+
mrb_gc_mark(mrb, (struct RBasic*)p);
|
38
273
|
}
|
39
274
|
}
|
275
|
+
return;
|
40
276
|
}
|
41
277
|
|
42
278
|
size_t
|
43
279
|
mrb_gc_mark_mt_size(mrb_state *mrb, struct RClass *c)
|
44
280
|
{
|
45
|
-
|
281
|
+
struct mt_tbl *h = c->mt;
|
46
282
|
|
47
283
|
if (!h) return 0;
|
48
|
-
return
|
284
|
+
return h->size;
|
49
285
|
}
|
50
286
|
|
51
287
|
void
|
52
288
|
mrb_gc_free_mt(mrb_state *mrb, struct RClass *c)
|
53
289
|
{
|
54
|
-
|
290
|
+
if (c->mt) mt_free(mrb, c->mt);
|
55
291
|
}
|
56
292
|
|
57
293
|
void
|
58
294
|
mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb_sym id)
|
59
295
|
{
|
60
296
|
mrb_value name;
|
61
|
-
mrb_sym nsym =
|
297
|
+
mrb_sym nsym = MRB_SYM(__classname__);
|
62
298
|
|
63
299
|
if (mrb_obj_iv_defined(mrb, (struct RObject*)c, nsym)) return;
|
64
300
|
if (outer == NULL || outer == mrb->object_class) {
|
@@ -68,7 +304,7 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
|
|
68
304
|
name = mrb_class_path(mrb, outer);
|
69
305
|
if (mrb_nil_p(name)) { /* unnamed outer class */
|
70
306
|
if (outer != mrb->object_class && outer != c) {
|
71
|
-
mrb_obj_iv_set_force(mrb, (struct RObject*)c,
|
307
|
+
mrb_obj_iv_set_force(mrb, (struct RObject*)c, MRB_SYM(__outer__),
|
72
308
|
mrb_obj_value(outer));
|
73
309
|
}
|
74
310
|
return;
|
@@ -107,7 +343,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
|
|
107
343
|
if (o->c->tt == MRB_TT_SCLASS) return;
|
108
344
|
sc = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_SCLASS, mrb->class_class);
|
109
345
|
sc->flags |= MRB_FL_CLASS_IS_INHERITED;
|
110
|
-
sc->mt =
|
346
|
+
sc->mt = mt_new(mrb);
|
111
347
|
sc->iv = 0;
|
112
348
|
if (o->tt == MRB_TT_CLASS) {
|
113
349
|
c = (struct RClass*)o;
|
@@ -132,7 +368,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
|
|
132
368
|
o->c = sc;
|
133
369
|
mrb_field_write_barrier(mrb, (struct RBasic*)o, (struct RBasic*)sc);
|
134
370
|
mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)o);
|
135
|
-
mrb_obj_iv_set(mrb, (struct RObject*)sc,
|
371
|
+
mrb_obj_iv_set(mrb, (struct RObject*)sc, MRB_SYM(__attached__), mrb_obj_value(o));
|
136
372
|
sc->flags |= o->flags & MRB_FL_OBJ_IS_FROZEN;
|
137
373
|
}
|
138
374
|
|
@@ -229,6 +465,15 @@ mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id)
|
|
229
465
|
return define_module(mrb, id, mrb_class_ptr(outer));
|
230
466
|
}
|
231
467
|
|
468
|
+
MRB_API struct RClass*
|
469
|
+
mrb_define_module_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
|
470
|
+
{
|
471
|
+
struct RClass * c = define_module(mrb, name, outer);
|
472
|
+
|
473
|
+
setup_class(mrb, outer, c, name);
|
474
|
+
return c;
|
475
|
+
}
|
476
|
+
|
232
477
|
MRB_API struct RClass*
|
233
478
|
mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name)
|
234
479
|
{
|
@@ -283,12 +528,10 @@ mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super)
|
|
283
528
|
}
|
284
529
|
|
285
530
|
static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value);
|
286
|
-
#
|
287
|
-
static void
|
288
|
-
static void mc_clear_by_id(mrb_state *mrb, struct RClass*, mrb_sym);
|
531
|
+
#ifndef MRB_NO_METHOD_CACHE
|
532
|
+
static void mc_clear(mrb_state *mrb);
|
289
533
|
#else
|
290
|
-
#define
|
291
|
-
#define mc_clear_by_id(mrb,c,s)
|
534
|
+
#define mc_clear(mrb)
|
292
535
|
#endif
|
293
536
|
|
294
537
|
static void
|
@@ -302,7 +545,7 @@ mrb_class_inherited(mrb_state *mrb, struct RClass *super, struct RClass *klass)
|
|
302
545
|
super->flags |= MRB_FL_CLASS_IS_INHERITED;
|
303
546
|
s = mrb_obj_value(super);
|
304
547
|
mrb_mc_clear_by_class(mrb, klass);
|
305
|
-
mid =
|
548
|
+
mid = MRB_SYM(inherited);
|
306
549
|
if (!mrb_func_basic_p(mrb, s, mid, mrb_bob_init)) {
|
307
550
|
mrb_value c = mrb_obj_value(klass);
|
308
551
|
mrb_funcall_argv(mrb, s, mid, 1, &c);
|
@@ -349,21 +592,29 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
|
|
349
592
|
MRB_API mrb_bool
|
350
593
|
mrb_class_defined(mrb_state *mrb, const char *name)
|
351
594
|
{
|
352
|
-
|
353
|
-
if (
|
354
|
-
|
355
|
-
|
356
|
-
|
595
|
+
mrb_sym sym = mrb_intern_check_cstr(mrb, name);
|
596
|
+
if (!sym) return FALSE;
|
597
|
+
return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), sym);
|
598
|
+
}
|
599
|
+
|
600
|
+
MRB_API mrb_bool
|
601
|
+
mrb_class_defined_id(mrb_state *mrb, mrb_sym name)
|
602
|
+
{
|
603
|
+
return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), name);
|
357
604
|
}
|
358
605
|
|
359
606
|
MRB_API mrb_bool
|
360
607
|
mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name)
|
361
608
|
{
|
362
|
-
|
363
|
-
if (
|
364
|
-
|
365
|
-
|
366
|
-
|
609
|
+
mrb_sym sym = mrb_intern_check_cstr(mrb, name);
|
610
|
+
if (!sym) return FALSE;
|
611
|
+
return mrb_const_defined_at(mrb, mrb_obj_value(outer), sym);
|
612
|
+
}
|
613
|
+
|
614
|
+
MRB_API mrb_bool
|
615
|
+
mrb_class_defined_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
|
616
|
+
{
|
617
|
+
return mrb_const_defined_at(mrb, mrb_obj_value(outer), name);
|
367
618
|
}
|
368
619
|
|
369
620
|
MRB_API struct RClass*
|
@@ -372,6 +623,12 @@ mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
|
|
372
623
|
return class_from_sym(mrb, outer, mrb_intern_cstr(mrb, name));
|
373
624
|
}
|
374
625
|
|
626
|
+
MRB_API struct RClass*
|
627
|
+
mrb_class_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
|
628
|
+
{
|
629
|
+
return class_from_sym(mrb, outer, name);
|
630
|
+
}
|
631
|
+
|
375
632
|
MRB_API struct RClass*
|
376
633
|
mrb_class_get(mrb_state *mrb, const char *name)
|
377
634
|
{
|
@@ -379,11 +636,16 @@ mrb_class_get(mrb_state *mrb, const char *name)
|
|
379
636
|
}
|
380
637
|
|
381
638
|
MRB_API struct RClass*
|
382
|
-
|
639
|
+
mrb_class_get_id(mrb_state *mrb, mrb_sym name)
|
640
|
+
{
|
641
|
+
return mrb_class_get_under_id(mrb, mrb->object_class, name);
|
642
|
+
}
|
643
|
+
|
644
|
+
MRB_API struct RClass*
|
645
|
+
mrb_exc_get_id(mrb_state *mrb, mrb_sym name)
|
383
646
|
{
|
384
647
|
struct RClass *exc, *e;
|
385
|
-
mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class),
|
386
|
-
mrb_intern_cstr(mrb, name));
|
648
|
+
mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), name);
|
387
649
|
|
388
650
|
if (!mrb_class_p(c)) {
|
389
651
|
mrb_raise(mrb, mrb->eException_class, "exception corrupted");
|
@@ -404,12 +666,24 @@ mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
|
|
404
666
|
return module_from_sym(mrb, outer, mrb_intern_cstr(mrb, name));
|
405
667
|
}
|
406
668
|
|
669
|
+
MRB_API struct RClass*
|
670
|
+
mrb_module_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name)
|
671
|
+
{
|
672
|
+
return module_from_sym(mrb, outer, name);
|
673
|
+
}
|
674
|
+
|
407
675
|
MRB_API struct RClass*
|
408
676
|
mrb_module_get(mrb_state *mrb, const char *name)
|
409
677
|
{
|
410
678
|
return mrb_module_get_under(mrb, mrb->object_class, name);
|
411
679
|
}
|
412
680
|
|
681
|
+
MRB_API struct RClass*
|
682
|
+
mrb_module_get_id(mrb_state *mrb, mrb_sym name)
|
683
|
+
{
|
684
|
+
return mrb_module_get_under_id(mrb, mrb->object_class, name);
|
685
|
+
}
|
686
|
+
|
413
687
|
/*!
|
414
688
|
* Defines a class under the namespace of \a outer.
|
415
689
|
* \param outer a class which contains the new class.
|
@@ -427,9 +701,8 @@ mrb_module_get(mrb_state *mrb, const char *name)
|
|
427
701
|
* \a super, the function just returns the defined class.
|
428
702
|
*/
|
429
703
|
MRB_API struct RClass*
|
430
|
-
|
704
|
+
mrb_define_class_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name, struct RClass *super)
|
431
705
|
{
|
432
|
-
mrb_sym id = mrb_intern_cstr(mrb, name);
|
433
706
|
struct RClass * c;
|
434
707
|
|
435
708
|
#if 0
|
@@ -437,34 +710,45 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s
|
|
437
710
|
mrb_warn(mrb, "no super class for '%C::%n', Object assumed", outer, id);
|
438
711
|
}
|
439
712
|
#endif
|
440
|
-
c = define_class(mrb,
|
441
|
-
setup_class(mrb, outer, c,
|
713
|
+
c = define_class(mrb, name, super, outer);
|
714
|
+
setup_class(mrb, outer, c, name);
|
442
715
|
return c;
|
443
716
|
}
|
444
717
|
|
718
|
+
MRB_API struct RClass*
|
719
|
+
mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super)
|
720
|
+
{
|
721
|
+
return mrb_define_class_under_id(mrb, outer, mrb_intern_cstr(mrb, name), super);
|
722
|
+
}
|
723
|
+
|
445
724
|
MRB_API void
|
446
725
|
mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_t m)
|
447
726
|
{
|
448
|
-
|
449
|
-
|
727
|
+
mt_tbl *h;
|
728
|
+
union mt_ptr ptr;
|
729
|
+
|
450
730
|
MRB_CLASS_ORIGIN(c);
|
451
731
|
h = c->mt;
|
452
|
-
|
453
732
|
mrb_check_frozen(mrb, c);
|
454
|
-
if (!h) h = c->mt =
|
455
|
-
|
456
|
-
kh_value(h, k) = m;
|
457
|
-
if (MRB_METHOD_PROC_P(m) && !MRB_METHOD_UNDEF_P(m)) {
|
733
|
+
if (!h) h = c->mt = mt_new(mrb);
|
734
|
+
if (MRB_METHOD_PROC_P(m)) {
|
458
735
|
struct RProc *p = MRB_METHOD_PROC(m);
|
459
736
|
|
460
|
-
|
461
|
-
p
|
462
|
-
|
463
|
-
|
464
|
-
|
737
|
+
ptr.proc = p;
|
738
|
+
if (p) {
|
739
|
+
p->flags |= MRB_PROC_SCOPE;
|
740
|
+
p->c = NULL;
|
741
|
+
mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)p);
|
742
|
+
if (!MRB_PROC_ENV_P(p)) {
|
743
|
+
MRB_PROC_SET_TARGET_CLASS(p, c);
|
744
|
+
}
|
465
745
|
}
|
466
746
|
}
|
467
|
-
|
747
|
+
else {
|
748
|
+
ptr.func = MRB_METHOD_FUNC(m);
|
749
|
+
}
|
750
|
+
mt_put(mrb, h, mid, MRB_METHOD_FUNC_P(m), MRB_METHOD_NOARG_P(m), ptr);
|
751
|
+
mc_clear(mrb);
|
468
752
|
}
|
469
753
|
|
470
754
|
MRB_API void
|
@@ -474,6 +758,9 @@ mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t f
|
|
474
758
|
int ai = mrb_gc_arena_save(mrb);
|
475
759
|
|
476
760
|
MRB_METHOD_FROM_FUNC(m, func);
|
761
|
+
#ifndef MRB_USE_METHOD_T_STRUCT
|
762
|
+
mrb_assert(MRB_METHOD_FUNC(m) == func);
|
763
|
+
#endif
|
477
764
|
if (aspec == MRB_ARGS_NONE()) {
|
478
765
|
MRB_METHOD_NOARG_SET(m);
|
479
766
|
}
|
@@ -529,18 +816,18 @@ mrb_get_argc(mrb_state *mrb)
|
|
529
816
|
mrb_int argc = mrb->c->ci->argc;
|
530
817
|
|
531
818
|
if (argc < 0) {
|
532
|
-
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
|
819
|
+
struct RArray *a = mrb_ary_ptr(mrb->c->ci->stack[1]);
|
533
820
|
|
534
821
|
argc = ARY_LEN(a);
|
535
822
|
}
|
536
823
|
return argc;
|
537
824
|
}
|
538
825
|
|
539
|
-
MRB_API mrb_value*
|
826
|
+
MRB_API const mrb_value*
|
540
827
|
mrb_get_argv(mrb_state *mrb)
|
541
828
|
{
|
542
829
|
mrb_int argc = mrb->c->ci->argc;
|
543
|
-
mrb_value *array_argv = mrb->c->stack + 1;
|
830
|
+
mrb_value *array_argv = mrb->c->ci->stack + 1;
|
544
831
|
if (argc < 0) {
|
545
832
|
struct RArray *a = mrb_ary_ptr(*array_argv);
|
546
833
|
|
@@ -553,7 +840,7 @@ MRB_API mrb_value
|
|
553
840
|
mrb_get_arg1(mrb_state *mrb)
|
554
841
|
{
|
555
842
|
mrb_int argc = mrb->c->ci->argc;
|
556
|
-
mrb_value *array_argv = mrb->c->stack + 1;
|
843
|
+
mrb_value *array_argv = mrb->c->ci->stack + 1;
|
557
844
|
if (argc < 0) {
|
558
845
|
struct RArray *a = mrb_ary_ptr(*array_argv);
|
559
846
|
|
@@ -561,7 +848,7 @@ mrb_get_arg1(mrb_state *mrb)
|
|
561
848
|
array_argv = ARY_PTR(a);
|
562
849
|
}
|
563
850
|
if (argc != 1) {
|
564
|
-
|
851
|
+
mrb_argnum_error(mrb, argc, 1, 1);
|
565
852
|
}
|
566
853
|
return array_argv[0];
|
567
854
|
}
|
@@ -584,17 +871,18 @@ void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
|
|
584
871
|
S: String [mrb_value] when ! follows, the value may be nil
|
585
872
|
A: Array [mrb_value] when ! follows, the value may be nil
|
586
873
|
H: Hash [mrb_value] when ! follows, the value may be nil
|
587
|
-
s: String [char*,mrb_int]
|
588
|
-
z: String [char*]
|
589
|
-
a: Array [mrb_value*,mrb_int]
|
590
|
-
|
591
|
-
|
874
|
+
s: String [const char*,mrb_int] Receive two arguments; s! gives (NULL,0) for nil
|
875
|
+
z: String [const char*] NUL terminated string; z! gives NULL for nil
|
876
|
+
a: Array [const mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil
|
877
|
+
c: Class/Module [strcut RClass*]
|
878
|
+
f: Integer/Float [mrb_float]
|
879
|
+
i: Integer/Float [mrb_int]
|
592
880
|
b: boolean [mrb_bool]
|
593
881
|
n: String/Symbol [mrb_sym]
|
594
882
|
d: data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified; when ! follows, the value may be nil
|
595
883
|
I: inline struct [void*]
|
596
884
|
&: block [mrb_value] &! raises exception if no block given
|
597
|
-
*: rest argument [mrb_value*,mrb_int]
|
885
|
+
*: rest argument [const mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack
|
598
886
|
|: optional Following arguments are optional
|
599
887
|
?: optional given [mrb_bool] true if preceding argument (optional) is given
|
600
888
|
':': keyword args [mrb_kwargs const] Get keyword arguments
|
@@ -607,14 +895,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
607
895
|
mrb_int i = 0;
|
608
896
|
va_list ap;
|
609
897
|
mrb_int argc = mrb->c->ci->argc;
|
610
|
-
mrb_value *array_argv = mrb->c->stack+1;
|
898
|
+
mrb_value *array_argv = mrb->c->ci->stack+1;
|
611
899
|
mrb_bool argv_on_stack = argc >= 0;
|
612
900
|
mrb_bool opt = FALSE;
|
613
901
|
mrb_bool opt_skip = TRUE;
|
614
902
|
mrb_bool given = TRUE;
|
615
903
|
mrb_value kdict;
|
616
904
|
mrb_bool reqkarg = FALSE;
|
617
|
-
|
905
|
+
int argc_min = 0, argc_max = 0;
|
618
906
|
|
619
907
|
if (!argv_on_stack) {
|
620
908
|
struct RArray *a = mrb_ary_ptr(*array_argv);
|
@@ -632,6 +920,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
632
920
|
break;
|
633
921
|
case '*':
|
634
922
|
opt_skip = FALSE;
|
923
|
+
argc_max = -1;
|
635
924
|
if (!reqkarg) reqkarg = strchr(fmt, ':') ? TRUE : FALSE;
|
636
925
|
goto check_exit;
|
637
926
|
case '!':
|
@@ -643,13 +932,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
643
932
|
if (opt) opt_skip = FALSE;
|
644
933
|
break;
|
645
934
|
default:
|
646
|
-
if (!opt)
|
935
|
+
if (!opt) argc_min++;
|
936
|
+
argc_max++;
|
647
937
|
break;
|
648
938
|
}
|
649
939
|
}
|
650
940
|
|
651
941
|
check_exit:
|
652
|
-
if (reqkarg && argc >
|
942
|
+
if (reqkarg && argc > argc_min && mrb_hash_p(kdict = ARGV[argc - 1])) {
|
653
943
|
mrb_hash_check_kdict(mrb, kdict);
|
654
944
|
argc --;
|
655
945
|
}
|
@@ -672,7 +962,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
672
962
|
given = FALSE;
|
673
963
|
}
|
674
964
|
else {
|
675
|
-
|
965
|
+
mrb_argnum_error(mrb, argc, argc_min, argc_max);
|
676
966
|
}
|
677
967
|
}
|
678
968
|
break;
|
@@ -713,6 +1003,22 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
713
1003
|
}
|
714
1004
|
}
|
715
1005
|
break;
|
1006
|
+
case 'c':
|
1007
|
+
{
|
1008
|
+
struct RClass **p;
|
1009
|
+
|
1010
|
+
p = va_arg(ap, struct RClass**);
|
1011
|
+
if (i < argc) {
|
1012
|
+
mrb_value ss;
|
1013
|
+
|
1014
|
+
ss = argv[i++];
|
1015
|
+
if (!class_ptr_p(ss)) {
|
1016
|
+
mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss);
|
1017
|
+
}
|
1018
|
+
*p = mrb_class_ptr(ss);
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
break;
|
716
1022
|
case 'S':
|
717
1023
|
{
|
718
1024
|
mrb_value *p;
|
@@ -755,10 +1061,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
755
1061
|
case 's':
|
756
1062
|
{
|
757
1063
|
mrb_value ss;
|
758
|
-
char **ps = 0;
|
1064
|
+
const char **ps = 0;
|
759
1065
|
mrb_int *pl = 0;
|
760
1066
|
|
761
|
-
ps = va_arg(ap, char**);
|
1067
|
+
ps = va_arg(ap, const char**);
|
762
1068
|
pl = va_arg(ap, mrb_int*);
|
763
1069
|
if (i < argc) {
|
764
1070
|
ss = argv[i++];
|
@@ -796,10 +1102,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
796
1102
|
{
|
797
1103
|
mrb_value aa;
|
798
1104
|
struct RArray *a;
|
799
|
-
mrb_value **pb;
|
1105
|
+
const mrb_value **pb;
|
800
1106
|
mrb_int *pl;
|
801
1107
|
|
802
|
-
pb = va_arg(ap, mrb_value**);
|
1108
|
+
pb = va_arg(ap, const mrb_value**);
|
803
1109
|
pl = va_arg(ap, mrb_int*);
|
804
1110
|
if (i < argc) {
|
805
1111
|
aa = argv[i++];
|
@@ -832,7 +1138,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
832
1138
|
}
|
833
1139
|
}
|
834
1140
|
break;
|
835
|
-
#ifndef
|
1141
|
+
#ifndef MRB_NO_FLOAT
|
836
1142
|
case 'f':
|
837
1143
|
{
|
838
1144
|
mrb_float *p;
|
@@ -850,7 +1156,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
850
1156
|
|
851
1157
|
p = va_arg(ap, mrb_int*);
|
852
1158
|
if (i < argc) {
|
853
|
-
*p =
|
1159
|
+
*p = mrb_integer(mrb_to_int(mrb, argv[i++]));
|
854
1160
|
}
|
855
1161
|
}
|
856
1162
|
break;
|
@@ -902,10 +1208,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
902
1208
|
|
903
1209
|
p = va_arg(ap, mrb_value*);
|
904
1210
|
if (mrb->c->ci->argc < 0) {
|
905
|
-
bp = mrb->c->stack + 2;
|
1211
|
+
bp = mrb->c->ci->stack + 2;
|
906
1212
|
}
|
907
1213
|
else {
|
908
|
-
bp = mrb->c->stack + mrb->c->ci->argc + 1;
|
1214
|
+
bp = mrb->c->ci->stack + mrb->c->ci->argc + 1;
|
909
1215
|
}
|
910
1216
|
if (altmode && mrb_nil_p(*bp)) {
|
911
1217
|
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
|
@@ -928,11 +1234,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
928
1234
|
|
929
1235
|
case '*':
|
930
1236
|
{
|
931
|
-
mrb_value **var;
|
1237
|
+
const mrb_value **var;
|
932
1238
|
mrb_int *pl;
|
933
1239
|
mrb_bool nocopy = (altmode || !argv_on_stack) ? TRUE : FALSE;
|
934
1240
|
|
935
|
-
var = va_arg(ap, mrb_value**);
|
1241
|
+
var = va_arg(ap, const mrb_value**);
|
936
1242
|
pl = va_arg(ap, mrb_int*);
|
937
1243
|
if (argc > i) {
|
938
1244
|
*pl = argc-i;
|
@@ -967,7 +1273,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
967
1273
|
else {
|
968
1274
|
uint32_t kwnum = kwargs->num;
|
969
1275
|
uint32_t required = kwargs->required;
|
970
|
-
const
|
1276
|
+
const mrb_sym *kname = kwargs->table;
|
971
1277
|
mrb_value *values = kwargs->values;
|
972
1278
|
uint32_t j;
|
973
1279
|
const uint32_t keyword_max = 40;
|
@@ -977,16 +1283,16 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
977
1283
|
}
|
978
1284
|
|
979
1285
|
for (j = required; j > 0; j --, kname ++, values ++) {
|
980
|
-
mrb_value k = mrb_symbol_value(
|
1286
|
+
mrb_value k = mrb_symbol_value(*kname);
|
981
1287
|
if (!mrb_hash_key_p(mrb, ksrc, k)) {
|
982
|
-
mrb_raisef(mrb, E_ARGUMENT_ERROR, "missing keyword: %
|
1288
|
+
mrb_raisef(mrb, E_ARGUMENT_ERROR, "missing keyword: %n", *kname);
|
983
1289
|
}
|
984
1290
|
*values = mrb_hash_delete_key(mrb, ksrc, k);
|
985
1291
|
mrb_gc_protect(mrb, *values);
|
986
1292
|
}
|
987
1293
|
|
988
1294
|
for (j = kwnum - required; j > 0; j --, kname ++, values ++) {
|
989
|
-
mrb_value k = mrb_symbol_value(
|
1295
|
+
mrb_value k = mrb_symbol_value(*kname);
|
990
1296
|
if (mrb_hash_key_p(mrb, ksrc, k)) {
|
991
1297
|
*values = mrb_hash_delete_key(mrb, ksrc, k);
|
992
1298
|
mrb_gc_protect(mrb, *values);
|
@@ -1019,7 +1325,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
|
1019
1325
|
#undef ARGV
|
1020
1326
|
|
1021
1327
|
if (!c && argc > i) {
|
1022
|
-
|
1328
|
+
mrb_argnum_error(mrb, argc, argc_min, argc_max);
|
1023
1329
|
}
|
1024
1330
|
|
1025
1331
|
finish:
|
@@ -1040,7 +1346,7 @@ boot_defclass(mrb_state *mrb, struct RClass *super)
|
|
1040
1346
|
else {
|
1041
1347
|
c->super = mrb->object_class;
|
1042
1348
|
}
|
1043
|
-
c->mt =
|
1349
|
+
c->mt = mt_new(mrb);
|
1044
1350
|
return c;
|
1045
1351
|
}
|
1046
1352
|
|
@@ -1048,7 +1354,7 @@ static void
|
|
1048
1354
|
boot_initmod(mrb_state *mrb, struct RClass *mod)
|
1049
1355
|
{
|
1050
1356
|
if (!mod->mt) {
|
1051
|
-
mod->mt =
|
1357
|
+
mod->mt = mt_new(mrb);
|
1052
1358
|
}
|
1053
1359
|
}
|
1054
1360
|
|
@@ -1079,8 +1385,10 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
|
|
1079
1385
|
void *klass_mt = find_origin(c)->mt;
|
1080
1386
|
|
1081
1387
|
while (m) {
|
1082
|
-
int
|
1388
|
+
int original_seen = FALSE;
|
1389
|
+
int superclass_seen = FALSE;
|
1083
1390
|
|
1391
|
+
if (c == ins_pos) original_seen = TRUE;
|
1084
1392
|
if (m->flags & MRB_FL_CLASS_IS_PREPENDED)
|
1085
1393
|
goto skip;
|
1086
1394
|
|
@@ -1089,16 +1397,17 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
|
|
1089
1397
|
|
1090
1398
|
p = c->super;
|
1091
1399
|
while (p) {
|
1400
|
+
if (c == p) original_seen = TRUE;
|
1092
1401
|
if (p->tt == MRB_TT_ICLASS) {
|
1093
1402
|
if (p->mt == m->mt) {
|
1094
|
-
if (!superclass_seen) {
|
1403
|
+
if (!superclass_seen && original_seen) {
|
1095
1404
|
ins_pos = p; /* move insert point */
|
1096
1405
|
}
|
1097
1406
|
goto skip;
|
1098
1407
|
}
|
1099
1408
|
} else if (p->tt == MRB_TT_CLASS) {
|
1100
1409
|
if (!search_super) break;
|
1101
|
-
superclass_seen =
|
1410
|
+
superclass_seen = TRUE;
|
1102
1411
|
}
|
1103
1412
|
p = p->super;
|
1104
1413
|
}
|
@@ -1107,15 +1416,26 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru
|
|
1107
1416
|
m->flags |= MRB_FL_CLASS_IS_INHERITED;
|
1108
1417
|
ins_pos->super = ic;
|
1109
1418
|
mrb_field_write_barrier(mrb, (struct RBasic*)ins_pos, (struct RBasic*)ic);
|
1110
|
-
mrb_mc_clear_by_class(mrb, ins_pos);
|
1111
1419
|
ins_pos = ic;
|
1112
1420
|
skip:
|
1113
1421
|
m = m->super;
|
1114
1422
|
}
|
1115
|
-
|
1423
|
+
mc_clear(mrb);
|
1116
1424
|
return 0;
|
1117
1425
|
}
|
1118
1426
|
|
1427
|
+
static int
|
1428
|
+
fix_include_module(mrb_state *mrb, struct RBasic *obj, void *data)
|
1429
|
+
{
|
1430
|
+
struct RClass **m = (struct RClass**)data;
|
1431
|
+
|
1432
|
+
if (obj->tt == MRB_TT_ICLASS && obj->c == m[0] && (obj->flags & MRB_FL_CLASS_IS_ORIGIN) == 0) {
|
1433
|
+
struct RClass *ic = (struct RClass*)obj;
|
1434
|
+
include_module_at(mrb, ic, ic, m[1], 1);
|
1435
|
+
}
|
1436
|
+
return MRB_EACH_OBJ_OK;
|
1437
|
+
}
|
1438
|
+
|
1119
1439
|
MRB_API void
|
1120
1440
|
mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
|
1121
1441
|
{
|
@@ -1123,50 +1443,96 @@ mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
|
|
1123
1443
|
if (include_module_at(mrb, c, find_origin(c), m, 1) < 0) {
|
1124
1444
|
mrb_raise(mrb, E_ARGUMENT_ERROR, "cyclic include detected");
|
1125
1445
|
}
|
1446
|
+
if (c->tt == MRB_TT_MODULE && (c->flags & MRB_FL_CLASS_IS_INHERITED)) {
|
1447
|
+
struct RClass *data[2];
|
1448
|
+
data[0] = c;
|
1449
|
+
data[1] = m;
|
1450
|
+
mrb_objspace_each_objects(mrb, fix_include_module, data);
|
1451
|
+
}
|
1452
|
+
}
|
1453
|
+
|
1454
|
+
static int
|
1455
|
+
fix_prepend_module(mrb_state *mrb, struct RBasic *obj, void *data)
|
1456
|
+
{
|
1457
|
+
struct RClass **m = (struct RClass**)data;
|
1458
|
+
struct RClass *c = (struct RClass*)obj;
|
1459
|
+
|
1460
|
+
if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
|
1461
|
+
struct RClass *p = c->super;
|
1462
|
+
struct RClass *ins_pos = c;
|
1463
|
+
while (p) {
|
1464
|
+
if (c == m[0]) break;
|
1465
|
+
if (p == m[0]->super->c) {
|
1466
|
+
ins_pos = c;
|
1467
|
+
}
|
1468
|
+
if (p->tt == MRB_TT_CLASS) break;
|
1469
|
+
if (p->c == m[0]) {
|
1470
|
+
include_module_at(mrb, ins_pos, ins_pos, m[1], 0);
|
1471
|
+
break;
|
1472
|
+
}
|
1473
|
+
c = p;
|
1474
|
+
p = p->super;
|
1475
|
+
}
|
1476
|
+
}
|
1477
|
+
return MRB_EACH_OBJ_OK;
|
1126
1478
|
}
|
1127
1479
|
|
1128
1480
|
MRB_API void
|
1129
1481
|
mrb_prepend_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
|
1130
1482
|
{
|
1131
1483
|
struct RClass *origin;
|
1132
|
-
int changed = 0;
|
1133
1484
|
|
1134
1485
|
mrb_check_frozen(mrb, c);
|
1135
1486
|
if (!(c->flags & MRB_FL_CLASS_IS_PREPENDED)) {
|
1136
|
-
|
1487
|
+
struct RClass *c0;
|
1488
|
+
|
1489
|
+
if (c->tt == MRB_TT_ICLASS) {
|
1490
|
+
c0 = c->c;
|
1491
|
+
}
|
1492
|
+
else {
|
1493
|
+
c0 = c;
|
1494
|
+
}
|
1495
|
+
origin = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, c0);
|
1137
1496
|
origin->flags |= MRB_FL_CLASS_IS_ORIGIN | MRB_FL_CLASS_IS_INHERITED;
|
1138
1497
|
origin->super = c->super;
|
1139
1498
|
c->super = origin;
|
1140
1499
|
origin->mt = c->mt;
|
1141
|
-
c->mt =
|
1500
|
+
c->mt = NULL;
|
1501
|
+
origin->iv = c->iv;
|
1142
1502
|
mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)origin);
|
1143
1503
|
c->flags |= MRB_FL_CLASS_IS_PREPENDED;
|
1144
1504
|
}
|
1145
|
-
|
1146
|
-
if (changed < 0) {
|
1505
|
+
if (include_module_at(mrb, c, c, m, 0) < 0) {
|
1147
1506
|
mrb_raise(mrb, E_ARGUMENT_ERROR, "cyclic prepend detected");
|
1148
1507
|
}
|
1508
|
+
if (c->tt == MRB_TT_MODULE &&
|
1509
|
+
(c->flags & (MRB_FL_CLASS_IS_INHERITED|MRB_FL_CLASS_IS_PREPENDED))) {
|
1510
|
+
struct RClass *data[2];
|
1511
|
+
data[0] = c;
|
1512
|
+
data[1] = m;
|
1513
|
+
mrb_objspace_each_objects(mrb, fix_prepend_module, data);
|
1514
|
+
}
|
1149
1515
|
}
|
1150
1516
|
|
1151
1517
|
static mrb_value
|
1152
1518
|
mrb_mod_prepend_features(mrb_state *mrb, mrb_value mod)
|
1153
1519
|
{
|
1154
|
-
|
1520
|
+
struct RClass *c;
|
1155
1521
|
|
1156
1522
|
mrb_check_type(mrb, mod, MRB_TT_MODULE);
|
1157
|
-
mrb_get_args(mrb, "
|
1158
|
-
mrb_prepend_module(mrb,
|
1523
|
+
mrb_get_args(mrb, "c", &c);
|
1524
|
+
mrb_prepend_module(mrb, c, mrb_class_ptr(mod));
|
1159
1525
|
return mod;
|
1160
1526
|
}
|
1161
1527
|
|
1162
1528
|
static mrb_value
|
1163
1529
|
mrb_mod_append_features(mrb_state *mrb, mrb_value mod)
|
1164
1530
|
{
|
1165
|
-
|
1531
|
+
struct RClass *c;
|
1166
1532
|
|
1167
1533
|
mrb_check_type(mrb, mod, MRB_TT_MODULE);
|
1168
|
-
mrb_get_args(mrb, "
|
1169
|
-
mrb_include_module(mrb,
|
1534
|
+
mrb_get_args(mrb, "c", &c);
|
1535
|
+
mrb_include_module(mrb, c, mrb_class_ptr(mod));
|
1170
1536
|
return mod;
|
1171
1537
|
}
|
1172
1538
|
|
@@ -1273,10 +1639,9 @@ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v)
|
|
1273
1639
|
case MRB_TT_TRUE:
|
1274
1640
|
return mrb->true_class;
|
1275
1641
|
case MRB_TT_CPTR:
|
1276
|
-
return mrb->object_class;
|
1277
1642
|
case MRB_TT_SYMBOL:
|
1278
|
-
case
|
1279
|
-
#ifndef
|
1643
|
+
case MRB_TT_INTEGER:
|
1644
|
+
#ifndef MRB_NO_FLOAT
|
1280
1645
|
case MRB_TT_FLOAT:
|
1281
1646
|
#endif
|
1282
1647
|
return NULL;
|
@@ -1306,29 +1671,43 @@ mrb_define_singleton_method(mrb_state *mrb, struct RObject *o, const char *name,
|
|
1306
1671
|
mrb_define_method_id(mrb, o->c, mrb_intern_cstr(mrb, name), func, aspec);
|
1307
1672
|
}
|
1308
1673
|
|
1674
|
+
MRB_API void
|
1675
|
+
mrb_define_singleton_method_id(mrb_state *mrb, struct RObject *o, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
|
1676
|
+
{
|
1677
|
+
prepare_singleton_class(mrb, (struct RBasic*)o);
|
1678
|
+
mrb_define_method_id(mrb, o->c, name, func, aspec);
|
1679
|
+
}
|
1680
|
+
|
1309
1681
|
MRB_API void
|
1310
1682
|
mrb_define_class_method(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t func, mrb_aspec aspec)
|
1311
1683
|
{
|
1312
1684
|
mrb_define_singleton_method(mrb, (struct RObject*)c, name, func, aspec);
|
1313
1685
|
}
|
1314
1686
|
|
1687
|
+
MRB_API void
|
1688
|
+
mrb_define_class_method_id(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
|
1689
|
+
{
|
1690
|
+
mrb_define_singleton_method_id(mrb, (struct RObject*)c, name, func, aspec);
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
MRB_API void
|
1694
|
+
mrb_define_module_function_id(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_func_t func, mrb_aspec aspec)
|
1695
|
+
{
|
1696
|
+
mrb_define_class_method_id(mrb, c, name, func, aspec);
|
1697
|
+
mrb_define_method_id(mrb, c, name, func, aspec);
|
1698
|
+
}
|
1699
|
+
|
1315
1700
|
MRB_API void
|
1316
1701
|
mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t func, mrb_aspec aspec)
|
1317
1702
|
{
|
1318
|
-
|
1319
|
-
mrb_define_method(mrb, c, name, func, aspec);
|
1703
|
+
mrb_define_module_function_id(mrb, c, mrb_intern_cstr(mrb, name), func, aspec);
|
1320
1704
|
}
|
1321
1705
|
|
1322
|
-
#
|
1706
|
+
#ifndef MRB_NO_METHOD_CACHE
|
1323
1707
|
static void
|
1324
|
-
|
1708
|
+
mc_clear(mrb_state *mrb)
|
1325
1709
|
{
|
1326
|
-
|
1327
|
-
int i;
|
1328
|
-
|
1329
|
-
for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
|
1330
|
-
mc[i].c = 0;
|
1331
|
-
}
|
1710
|
+
memset(mrb->cache, 0, MRB_METHOD_CACHE_SIZE*sizeof(mrb->cache[0]));
|
1332
1711
|
}
|
1333
1712
|
|
1334
1713
|
void
|
@@ -1338,40 +1717,21 @@ mrb_mc_clear_by_class(mrb_state *mrb, struct RClass *c)
|
|
1338
1717
|
int i;
|
1339
1718
|
|
1340
1719
|
if (c->flags & MRB_FL_CLASS_IS_INHERITED) {
|
1341
|
-
|
1342
|
-
c->flags &= ~MRB_FL_CLASS_IS_INHERITED;
|
1720
|
+
mc_clear(mrb);
|
1343
1721
|
return;
|
1344
1722
|
}
|
1345
1723
|
for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
|
1346
1724
|
if (mc[i].c == c) mc[i].c = 0;
|
1347
1725
|
}
|
1348
1726
|
}
|
1349
|
-
|
1350
|
-
static void
|
1351
|
-
mc_clear_by_id(mrb_state *mrb, struct RClass *c, mrb_sym mid)
|
1352
|
-
{
|
1353
|
-
struct mrb_cache_entry *mc = mrb->cache;
|
1354
|
-
int i;
|
1355
|
-
|
1356
|
-
if (c->flags & MRB_FL_CLASS_IS_INHERITED) {
|
1357
|
-
mc_clear_all(mrb);
|
1358
|
-
c->flags &= ~MRB_FL_CLASS_IS_INHERITED;
|
1359
|
-
return;
|
1360
|
-
}
|
1361
|
-
for (i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
|
1362
|
-
if (mc[i].c == c || mc[i].mid == mid)
|
1363
|
-
mc[i].c = 0;
|
1364
|
-
}
|
1365
|
-
}
|
1366
1727
|
#endif
|
1367
1728
|
|
1368
1729
|
MRB_API mrb_method_t
|
1369
1730
|
mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
|
1370
1731
|
{
|
1371
|
-
khiter_t k;
|
1372
1732
|
mrb_method_t m;
|
1373
1733
|
struct RClass *c = *cp;
|
1374
|
-
#
|
1734
|
+
#ifndef MRB_NO_METHOD_CACHE
|
1375
1735
|
struct RClass *oc = c;
|
1376
1736
|
int h = kh_int_hash_func(mrb, ((intptr_t)oc) ^ mid) & (MRB_METHOD_CACHE_SIZE-1);
|
1377
1737
|
struct mrb_cache_entry *mc = &mrb->cache[h];
|
@@ -1383,15 +1743,23 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
|
|
1383
1743
|
#endif
|
1384
1744
|
|
1385
1745
|
while (c) {
|
1386
|
-
|
1746
|
+
mt_tbl *h = c->mt;
|
1387
1747
|
|
1388
1748
|
if (h) {
|
1389
|
-
|
1390
|
-
if (
|
1391
|
-
|
1392
|
-
if (MRB_METHOD_UNDEF_P(m)) break;
|
1749
|
+
struct mt_elem *e = mt_get(mrb, h, mid);
|
1750
|
+
if (e) {
|
1751
|
+
if (e->ptr.proc == 0) break;
|
1393
1752
|
*cp = c;
|
1394
|
-
|
1753
|
+
if (e->func_p) {
|
1754
|
+
MRB_METHOD_FROM_FUNC(m, e->ptr.func);
|
1755
|
+
}
|
1756
|
+
else {
|
1757
|
+
MRB_METHOD_FROM_PROC(m, e->ptr.proc);
|
1758
|
+
}
|
1759
|
+
if (e->noarg_p) {
|
1760
|
+
MRB_METHOD_NOARG_SET(m);
|
1761
|
+
}
|
1762
|
+
#ifndef MRB_NO_METHOD_CACHE
|
1395
1763
|
mc->c = oc;
|
1396
1764
|
mc->c0 = c;
|
1397
1765
|
mc->mid = mid;
|
@@ -1466,7 +1834,7 @@ static mrb_value
|
|
1466
1834
|
mod_attr_define(mrb_state *mrb, mrb_value mod, mrb_value (*accessor)(mrb_state *, mrb_value), mrb_sym (*access_name)(mrb_state *, mrb_sym))
|
1467
1835
|
{
|
1468
1836
|
struct RClass *c = mrb_class_ptr(mod);
|
1469
|
-
mrb_value *argv;
|
1837
|
+
const mrb_value *argv;
|
1470
1838
|
mrb_int argc, i;
|
1471
1839
|
int ai;
|
1472
1840
|
|
@@ -1555,13 +1923,13 @@ mrb_value
|
|
1555
1923
|
mrb_instance_new(mrb_state *mrb, mrb_value cv)
|
1556
1924
|
{
|
1557
1925
|
mrb_value obj, blk;
|
1558
|
-
mrb_value *argv;
|
1926
|
+
const mrb_value *argv;
|
1559
1927
|
mrb_int argc;
|
1560
1928
|
mrb_sym init;
|
1561
1929
|
|
1562
1930
|
mrb_get_args(mrb, "*!&", &argv, &argc, &blk);
|
1563
1931
|
obj = mrb_instance_alloc(mrb, cv);
|
1564
|
-
init =
|
1932
|
+
init = MRB_SYM(initialize);
|
1565
1933
|
if (!mrb_func_basic_p(mrb, obj, init, mrb_bob_init)) {
|
1566
1934
|
mrb_funcall_with_block(mrb, obj, init, argc, argv, blk);
|
1567
1935
|
}
|
@@ -1575,7 +1943,7 @@ mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *arg
|
|
1575
1943
|
mrb_sym mid;
|
1576
1944
|
|
1577
1945
|
obj = mrb_instance_alloc(mrb, mrb_obj_value(c));
|
1578
|
-
mid =
|
1946
|
+
mid = MRB_SYM(initialize);
|
1579
1947
|
if (!mrb_func_basic_p(mrb, obj, mid, mrb_bob_init)) {
|
1580
1948
|
mrb_funcall_argv(mrb, obj, mid, argc, argv);
|
1581
1949
|
}
|
@@ -1607,7 +1975,7 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv)
|
|
1607
1975
|
super = mrb_obj_value(mrb->object_class);
|
1608
1976
|
}
|
1609
1977
|
new_class = mrb_obj_value(mrb_class_new(mrb, mrb_class_ptr(super)));
|
1610
|
-
mid =
|
1978
|
+
mid = MRB_SYM(initialize);
|
1611
1979
|
if (mrb_func_basic_p(mrb, new_class, mid, mrb_class_initialize)) {
|
1612
1980
|
mrb_class_initialize(mrb, new_class);
|
1613
1981
|
}
|
@@ -1705,7 +2073,7 @@ MRB_API mrb_value
|
|
1705
2073
|
mrb_class_path(mrb_state *mrb, struct RClass *c)
|
1706
2074
|
{
|
1707
2075
|
mrb_value path;
|
1708
|
-
mrb_sym nsym =
|
2076
|
+
mrb_sym nsym = MRB_SYM(__classname__);
|
1709
2077
|
|
1710
2078
|
path = mrb_obj_iv_get(mrb, (struct RObject*)c, nsym);
|
1711
2079
|
if (mrb_nil_p(path)) {
|
@@ -1810,7 +2178,7 @@ mrb_module_new(mrb_state *mrb)
|
|
1810
2178
|
* called with an explicit receiver, as <code>class</code> is also a
|
1811
2179
|
* reserved word in Ruby.
|
1812
2180
|
*
|
1813
|
-
* 1.class #=>
|
2181
|
+
* 1.class #=> Integer
|
1814
2182
|
* self.class #=> Object
|
1815
2183
|
*/
|
1816
2184
|
|
@@ -1860,6 +2228,12 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const
|
|
1860
2228
|
mrb_alias_method(mrb, klass, mrb_intern_cstr(mrb, name1), mrb_intern_cstr(mrb, name2));
|
1861
2229
|
}
|
1862
2230
|
|
2231
|
+
MRB_API void
|
2232
|
+
mrb_define_alias_id(mrb_state *mrb, struct RClass *klass, mrb_sym a, mrb_sym b)
|
2233
|
+
{
|
2234
|
+
mrb_alias_method(mrb, klass, a, b);
|
2235
|
+
}
|
2236
|
+
|
1863
2237
|
/*
|
1864
2238
|
* call-seq:
|
1865
2239
|
* mod.to_s -> string
|
@@ -1872,9 +2246,8 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const
|
|
1872
2246
|
mrb_value
|
1873
2247
|
mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
|
1874
2248
|
{
|
1875
|
-
|
1876
2249
|
if (mrb_sclass_p(klass)) {
|
1877
|
-
mrb_value v = mrb_iv_get(mrb, klass,
|
2250
|
+
mrb_value v = mrb_iv_get(mrb, klass, MRB_SYM(__attached__));
|
1878
2251
|
mrb_value str = mrb_str_new_lit(mrb, "#<Class:");
|
1879
2252
|
|
1880
2253
|
if (class_ptr_p(v)) {
|
@@ -1910,7 +2283,7 @@ undef_method(mrb_state *mrb, struct RClass *c, mrb_sym a)
|
|
1910
2283
|
mrb_define_method_raw(mrb, c, a, m);
|
1911
2284
|
}
|
1912
2285
|
|
1913
|
-
void
|
2286
|
+
MRB_API void
|
1914
2287
|
mrb_undef_method_id(mrb_state *mrb, struct RClass *c, mrb_sym a)
|
1915
2288
|
{
|
1916
2289
|
if (!mrb_obj_respond_to(mrb, c, a)) {
|
@@ -1925,18 +2298,36 @@ mrb_undef_method(mrb_state *mrb, struct RClass *c, const char *name)
|
|
1925
2298
|
undef_method(mrb, c, mrb_intern_cstr(mrb, name));
|
1926
2299
|
}
|
1927
2300
|
|
2301
|
+
MRB_API void
|
2302
|
+
mrb_undef_class_method_id(mrb_state *mrb, struct RClass *c, mrb_sym name)
|
2303
|
+
{
|
2304
|
+
mrb_undef_method_id(mrb, mrb_class_ptr(mrb_singleton_class(mrb, mrb_obj_value(c))), name);
|
2305
|
+
}
|
2306
|
+
|
1928
2307
|
MRB_API void
|
1929
2308
|
mrb_undef_class_method(mrb_state *mrb, struct RClass *c, const char *name)
|
1930
2309
|
{
|
1931
2310
|
mrb_undef_method(mrb, mrb_class_ptr(mrb_singleton_class(mrb, mrb_obj_value(c))), name);
|
1932
2311
|
}
|
1933
2312
|
|
2313
|
+
MRB_API void
|
2314
|
+
mrb_remove_method(mrb_state *mrb, struct RClass *c, mrb_sym mid)
|
2315
|
+
{
|
2316
|
+
mt_tbl *h;
|
2317
|
+
|
2318
|
+
MRB_CLASS_ORIGIN(c);
|
2319
|
+
h = c->mt;
|
2320
|
+
|
2321
|
+
if (h && mt_del(mrb, h, mid)) return;
|
2322
|
+
mrb_name_error(mrb, mid, "method '%n' not defined in %C", mid, c);
|
2323
|
+
}
|
2324
|
+
|
1934
2325
|
static mrb_value
|
1935
2326
|
mrb_mod_undef(mrb_state *mrb, mrb_value mod)
|
1936
2327
|
{
|
1937
2328
|
struct RClass *c = mrb_class_ptr(mod);
|
1938
2329
|
mrb_int argc;
|
1939
|
-
mrb_value *argv;
|
2330
|
+
const mrb_value *argv;
|
1940
2331
|
|
1941
2332
|
mrb_get_args(mrb, "*", &argv, &argc);
|
1942
2333
|
while (argc--) {
|
@@ -2095,10 +2486,9 @@ mrb_mod_method_defined(mrb_state *mrb, mrb_value mod)
|
|
2095
2486
|
return mrb_bool_value(mrb_obj_respond_to(mrb, mrb_class_ptr(mod), id));
|
2096
2487
|
}
|
2097
2488
|
|
2098
|
-
|
2099
|
-
|
2489
|
+
mrb_value
|
2490
|
+
mrb_mod_define_method_m(mrb_state *mrb, struct RClass *c)
|
2100
2491
|
{
|
2101
|
-
struct RClass *c = mrb_class_ptr(self);
|
2102
2492
|
struct RProc *p;
|
2103
2493
|
mrb_method_t m;
|
2104
2494
|
mrb_sym mid;
|
@@ -2128,10 +2518,16 @@ mod_define_method(mrb_state *mrb, mrb_value self)
|
|
2128
2518
|
return mrb_symbol_value(mid);
|
2129
2519
|
}
|
2130
2520
|
|
2521
|
+
static mrb_value
|
2522
|
+
mod_define_method(mrb_state *mrb, mrb_value self)
|
2523
|
+
{
|
2524
|
+
return mrb_mod_define_method_m(mrb, mrb_class_ptr(self));
|
2525
|
+
}
|
2526
|
+
|
2131
2527
|
static mrb_value
|
2132
2528
|
top_define_method(mrb_state *mrb, mrb_value self)
|
2133
2529
|
{
|
2134
|
-
return
|
2530
|
+
return mrb_mod_define_method_m(mrb, mrb->object_class);
|
2135
2531
|
}
|
2136
2532
|
|
2137
2533
|
static mrb_value
|
@@ -2156,7 +2552,7 @@ mrb_mod_dup(mrb_state *mrb, mrb_value self)
|
|
2156
2552
|
static mrb_value
|
2157
2553
|
mrb_mod_module_function(mrb_state *mrb, mrb_value mod)
|
2158
2554
|
{
|
2159
|
-
mrb_value *argv;
|
2555
|
+
const mrb_value *argv;
|
2160
2556
|
mrb_int argc, i;
|
2161
2557
|
mrb_sym mid;
|
2162
2558
|
mrb_method_t m;
|
@@ -2190,6 +2586,202 @@ mrb_mod_module_function(mrb_state *mrb, mrb_value mod)
|
|
2190
2586
|
return mod;
|
2191
2587
|
}
|
2192
2588
|
|
2589
|
+
static struct RClass*
|
2590
|
+
mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
|
2591
|
+
{
|
2592
|
+
struct RClass *klass = mrb_basic_ptr(obj)->c;
|
2593
|
+
|
2594
|
+
if (klass->tt != MRB_TT_SCLASS)
|
2595
|
+
return klass;
|
2596
|
+
else {
|
2597
|
+
/* copy singleton(unnamed) class */
|
2598
|
+
struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
|
2599
|
+
|
2600
|
+
switch (mrb_type(obj)) {
|
2601
|
+
case MRB_TT_CLASS:
|
2602
|
+
case MRB_TT_SCLASS:
|
2603
|
+
break;
|
2604
|
+
default:
|
2605
|
+
clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass));
|
2606
|
+
break;
|
2607
|
+
}
|
2608
|
+
clone->super = klass->super;
|
2609
|
+
if (klass->iv) {
|
2610
|
+
mrb_iv_copy(mrb, mrb_obj_value(clone), mrb_obj_value(klass));
|
2611
|
+
mrb_obj_iv_set(mrb, (struct RObject*)clone, MRB_SYM(__attached__), obj);
|
2612
|
+
}
|
2613
|
+
if (klass->mt) {
|
2614
|
+
clone->mt = mt_copy(mrb, klass->mt);
|
2615
|
+
}
|
2616
|
+
else {
|
2617
|
+
clone->mt = mt_new(mrb);
|
2618
|
+
}
|
2619
|
+
clone->tt = MRB_TT_SCLASS;
|
2620
|
+
return clone;
|
2621
|
+
}
|
2622
|
+
}
|
2623
|
+
|
2624
|
+
static void
|
2625
|
+
copy_class(mrb_state *mrb, mrb_value dst, mrb_value src)
|
2626
|
+
{
|
2627
|
+
struct RClass *dc = mrb_class_ptr(dst);
|
2628
|
+
struct RClass *sc = mrb_class_ptr(src);
|
2629
|
+
/* if the origin is not the same as the class, then the origin and
|
2630
|
+
the current class need to be copied */
|
2631
|
+
if (sc->flags & MRB_FL_CLASS_IS_PREPENDED) {
|
2632
|
+
struct RClass *c0 = sc->super;
|
2633
|
+
struct RClass *c1 = dc;
|
2634
|
+
|
2635
|
+
/* copy prepended iclasses */
|
2636
|
+
while (!(c0->flags & MRB_FL_CLASS_IS_ORIGIN)) {
|
2637
|
+
c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
|
2638
|
+
c1 = c1->super;
|
2639
|
+
c0 = c0->super;
|
2640
|
+
}
|
2641
|
+
c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
|
2642
|
+
c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
|
2643
|
+
}
|
2644
|
+
if (sc->mt) {
|
2645
|
+
dc->mt = mt_copy(mrb, sc->mt);
|
2646
|
+
}
|
2647
|
+
else {
|
2648
|
+
dc->mt = mt_new(mrb);
|
2649
|
+
}
|
2650
|
+
dc->super = sc->super;
|
2651
|
+
MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc));
|
2652
|
+
}
|
2653
|
+
|
2654
|
+
/* 15.3.1.3.16 */
|
2655
|
+
static mrb_value
|
2656
|
+
mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
|
2657
|
+
{
|
2658
|
+
mrb_value orig = mrb_get_arg1(mrb);
|
2659
|
+
|
2660
|
+
if (mrb_obj_equal(mrb, self, orig)) return self;
|
2661
|
+
if ((mrb_type(self) != mrb_type(orig)) || (mrb_obj_class(mrb, self) != mrb_obj_class(mrb, orig))) {
|
2662
|
+
mrb_raise(mrb, E_TYPE_ERROR, "initialize_copy should take same class object");
|
2663
|
+
}
|
2664
|
+
return self;
|
2665
|
+
}
|
2666
|
+
|
2667
|
+
static void
|
2668
|
+
init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
|
2669
|
+
{
|
2670
|
+
switch (mrb_type(obj)) {
|
2671
|
+
case MRB_TT_ICLASS:
|
2672
|
+
copy_class(mrb, dest, obj);
|
2673
|
+
return;
|
2674
|
+
case MRB_TT_CLASS:
|
2675
|
+
case MRB_TT_MODULE:
|
2676
|
+
copy_class(mrb, dest, obj);
|
2677
|
+
mrb_iv_copy(mrb, dest, obj);
|
2678
|
+
mrb_iv_remove(mrb, dest, MRB_SYM(__classname__));
|
2679
|
+
break;
|
2680
|
+
case MRB_TT_OBJECT:
|
2681
|
+
case MRB_TT_SCLASS:
|
2682
|
+
case MRB_TT_HASH:
|
2683
|
+
case MRB_TT_DATA:
|
2684
|
+
case MRB_TT_EXCEPTION:
|
2685
|
+
mrb_iv_copy(mrb, dest, obj);
|
2686
|
+
break;
|
2687
|
+
case MRB_TT_ISTRUCT:
|
2688
|
+
mrb_istruct_copy(dest, obj);
|
2689
|
+
break;
|
2690
|
+
|
2691
|
+
default:
|
2692
|
+
break;
|
2693
|
+
}
|
2694
|
+
if (!mrb_func_basic_p(mrb, dest, MRB_SYM(initialize_copy), mrb_obj_init_copy)) {
|
2695
|
+
mrb_funcall_id(mrb, dest, MRB_SYM(initialize_copy), 1, obj);
|
2696
|
+
}
|
2697
|
+
}
|
2698
|
+
|
2699
|
+
/* 15.3.1.3.8 */
|
2700
|
+
/*
|
2701
|
+
* call-seq:
|
2702
|
+
* obj.clone -> an_object
|
2703
|
+
*
|
2704
|
+
* Produces a shallow copy of <i>obj</i>---the instance variables of
|
2705
|
+
* <i>obj</i> are copied, but not the objects they reference. Copies
|
2706
|
+
* the frozen state of <i>obj</i>. See also the discussion
|
2707
|
+
* under <code>Object#dup</code>.
|
2708
|
+
*
|
2709
|
+
* class Klass
|
2710
|
+
* attr_accessor :str
|
2711
|
+
* end
|
2712
|
+
* s1 = Klass.new #=> #<Klass:0x401b3a38>
|
2713
|
+
* s1.str = "Hello" #=> "Hello"
|
2714
|
+
* s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
|
2715
|
+
* s2.str[1,4] = "i" #=> "i"
|
2716
|
+
* s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
|
2717
|
+
* s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
|
2718
|
+
*
|
2719
|
+
* This method may have class-specific behavior. If so, that
|
2720
|
+
* behavior will be documented under the #+initialize_copy+ method of
|
2721
|
+
* the class.
|
2722
|
+
*
|
2723
|
+
* Some Class(True False Nil Symbol Integer Float) Object cannot clone.
|
2724
|
+
*/
|
2725
|
+
MRB_API mrb_value
|
2726
|
+
mrb_obj_clone(mrb_state *mrb, mrb_value self)
|
2727
|
+
{
|
2728
|
+
struct RObject *p;
|
2729
|
+
mrb_value clone;
|
2730
|
+
|
2731
|
+
if (mrb_immediate_p(self)) {
|
2732
|
+
return self;
|
2733
|
+
}
|
2734
|
+
if (mrb_sclass_p(self)) {
|
2735
|
+
mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
|
2736
|
+
}
|
2737
|
+
p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
|
2738
|
+
p->c = mrb_singleton_class_clone(mrb, self);
|
2739
|
+
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
|
2740
|
+
clone = mrb_obj_value(p);
|
2741
|
+
init_copy(mrb, clone, self);
|
2742
|
+
p->flags |= mrb_obj_ptr(self)->flags & MRB_FL_OBJ_IS_FROZEN;
|
2743
|
+
|
2744
|
+
return clone;
|
2745
|
+
}
|
2746
|
+
|
2747
|
+
/* 15.3.1.3.9 */
|
2748
|
+
/*
|
2749
|
+
* call-seq:
|
2750
|
+
* obj.dup -> an_object
|
2751
|
+
*
|
2752
|
+
* Produces a shallow copy of <i>obj</i>---the instance variables of
|
2753
|
+
* <i>obj</i> are copied, but not the objects they reference.
|
2754
|
+
* <code>dup</code> copies the frozen state of <i>obj</i>. See also
|
2755
|
+
* the discussion under <code>Object#clone</code>. In general,
|
2756
|
+
* <code>clone</code> and <code>dup</code> may have different semantics
|
2757
|
+
* in descendant classes. While <code>clone</code> is used to duplicate
|
2758
|
+
* an object, including its internal state, <code>dup</code> typically
|
2759
|
+
* uses the class of the descendant object to create the new instance.
|
2760
|
+
*
|
2761
|
+
* This method may have class-specific behavior. If so, that
|
2762
|
+
* behavior will be documented under the #+initialize_copy+ method of
|
2763
|
+
* the class.
|
2764
|
+
*/
|
2765
|
+
|
2766
|
+
MRB_API mrb_value
|
2767
|
+
mrb_obj_dup(mrb_state *mrb, mrb_value obj)
|
2768
|
+
{
|
2769
|
+
struct RBasic *p;
|
2770
|
+
mrb_value dup;
|
2771
|
+
|
2772
|
+
if (mrb_immediate_p(obj)) {
|
2773
|
+
return obj;
|
2774
|
+
}
|
2775
|
+
if (mrb_sclass_p(obj)) {
|
2776
|
+
mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
|
2777
|
+
}
|
2778
|
+
p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
|
2779
|
+
dup = mrb_obj_value(p);
|
2780
|
+
init_copy(mrb, dup, obj);
|
2781
|
+
|
2782
|
+
return dup;
|
2783
|
+
}
|
2784
|
+
|
2193
2785
|
/* implementation of __id__ */
|
2194
2786
|
mrb_value mrb_obj_id_m(mrb_state *mrb, mrb_value self);
|
2195
2787
|
/* implementation of instance_eval */
|
@@ -2212,29 +2804,29 @@ static const mrb_code new_iseq[] = {
|
|
2212
2804
|
OP_RETURN, 0x0 /* OP_RETURN R0 */
|
2213
2805
|
};
|
2214
2806
|
|
2807
|
+
MRB_PRESYM_DEFINE_VAR_AND_INITER(new_syms, 2, MRB_SYM(allocate), MRB_SYM(initialize))
|
2808
|
+
|
2809
|
+
static const mrb_irep new_irep = {
|
2810
|
+
3, 6, 0, MRB_IREP_STATIC,
|
2811
|
+
new_iseq, NULL, new_syms, NULL, NULL, NULL,
|
2812
|
+
sizeof(new_iseq), 0, 2, 0, 0,
|
2813
|
+
};
|
2814
|
+
|
2215
2815
|
static void
|
2216
2816
|
init_class_new(mrb_state *mrb, struct RClass *cls)
|
2217
2817
|
{
|
2218
2818
|
struct RProc *p;
|
2219
2819
|
mrb_method_t m;
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
*new_irep = mrb_irep_zero;
|
2224
|
-
new_irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*2);
|
2225
|
-
new_irep->syms[0] = mrb_intern_lit(mrb, "allocate");
|
2226
|
-
new_irep->syms[1] = mrb_intern_lit(mrb, "initialize");
|
2227
|
-
new_irep->slen = 2;
|
2228
|
-
new_irep->flags = MRB_ISEQ_NO_FREE;
|
2229
|
-
new_irep->iseq = new_iseq;
|
2230
|
-
new_irep->ilen = sizeof(new_iseq);
|
2231
|
-
new_irep->nregs = 6;
|
2232
|
-
new_irep->nlocals = 3;
|
2233
|
-
p = mrb_proc_new(mrb, new_irep);
|
2820
|
+
|
2821
|
+
MRB_PRESYM_INIT_SYMBOLS(mrb, new_syms);
|
2822
|
+
p = mrb_proc_new(mrb, &new_irep);
|
2234
2823
|
MRB_METHOD_FROM_PROC(m, p);
|
2235
|
-
mrb_define_method_raw(mrb, cls,
|
2824
|
+
mrb_define_method_raw(mrb, cls, MRB_SYM(new), m);
|
2236
2825
|
}
|
2237
2826
|
|
2827
|
+
/* implementation of #send method */
|
2828
|
+
mrb_value mrb_f_send(mrb_state *mrb, mrb_value self);
|
2829
|
+
|
2238
2830
|
void
|
2239
2831
|
mrb_init_class(mrb_state *mrb)
|
2240
2832
|
{
|
@@ -2256,16 +2848,16 @@ mrb_init_class(mrb_state *mrb)
|
|
2256
2848
|
make_metaclass(mrb, cls);
|
2257
2849
|
|
2258
2850
|
/* name basic classes */
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2851
|
+
mrb_define_const_id(mrb, bob, MRB_SYM(BasicObject), mrb_obj_value(bob));
|
2852
|
+
mrb_define_const_id(mrb, obj, MRB_SYM(Object), mrb_obj_value(obj));
|
2853
|
+
mrb_define_const_id(mrb, obj, MRB_SYM(Module), mrb_obj_value(mod));
|
2854
|
+
mrb_define_const_id(mrb, obj, MRB_SYM(Class), mrb_obj_value(cls));
|
2263
2855
|
|
2264
2856
|
/* name each classes */
|
2265
|
-
mrb_class_name_class(mrb, NULL, bob,
|
2266
|
-
mrb_class_name_class(mrb, NULL, obj,
|
2267
|
-
mrb_class_name_class(mrb, NULL, mod,
|
2268
|
-
mrb_class_name_class(mrb, NULL, cls,
|
2857
|
+
mrb_class_name_class(mrb, NULL, bob, MRB_SYM(BasicObject));
|
2858
|
+
mrb_class_name_class(mrb, NULL, obj, MRB_SYM(Object)); /* 15.2.1 */
|
2859
|
+
mrb_class_name_class(mrb, NULL, mod, MRB_SYM(Module)); /* 15.2.2 */
|
2860
|
+
mrb_class_name_class(mrb, NULL, cls, MRB_SYM(Class)); /* 15.2.3 */
|
2269
2861
|
|
2270
2862
|
mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); /* 15.2.17 */
|
2271
2863
|
MRB_SET_INSTANCE_TT(mrb->proc_class, MRB_TT_PROC);
|