enclave 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +182 -0
- data/Rakefile +30 -0
- data/ext/enclave/enclave.c +390 -0
- data/ext/enclave/extconf.rb +33 -0
- data/ext/enclave/mruby/Makefile +63 -0
- data/ext/enclave/mruby/Rakefile +102 -0
- data/ext/enclave/mruby/benchmark/bm_ao_render.rb +309 -0
- data/ext/enclave/mruby/benchmark/bm_app_lc_fizzbuzz.rb +51 -0
- data/ext/enclave/mruby/benchmark/bm_fib.rb +6 -0
- data/ext/enclave/mruby/benchmark/bm_mandel_term.rb +34 -0
- data/ext/enclave/mruby/benchmark/bm_so_lists.rb +49 -0
- data/ext/enclave/mruby/benchmark/bm_so_mandelbrot.rb +65 -0
- data/ext/enclave/mruby/benchmark/vm_dispatch_bench.c +197 -0
- data/ext/enclave/mruby/benchmark/vm_optimization_bench.rb +513 -0
- data/ext/enclave/mruby/build/host/include/mrbconf.h +230 -0
- data/ext/enclave/mruby/build/host/include/mruby/array.h +303 -0
- data/ext/enclave/mruby/build/host/include/mruby/boxing_nan.h +169 -0
- data/ext/enclave/mruby/build/host/include/mruby/boxing_no.h +59 -0
- data/ext/enclave/mruby/build/host/include/mruby/boxing_word.h +248 -0
- data/ext/enclave/mruby/build/host/include/mruby/class.h +157 -0
- data/ext/enclave/mruby/build/host/include/mruby/common.h +127 -0
- data/ext/enclave/mruby/build/host/include/mruby/compile.h +187 -0
- data/ext/enclave/mruby/build/host/include/mruby/data.h +76 -0
- data/ext/enclave/mruby/build/host/include/mruby/debug.h +75 -0
- data/ext/enclave/mruby/build/host/include/mruby/dump.h +159 -0
- data/ext/enclave/mruby/build/host/include/mruby/endian.h +44 -0
- data/ext/enclave/mruby/build/host/include/mruby/error.h +168 -0
- data/ext/enclave/mruby/build/host/include/mruby/gc.h +77 -0
- data/ext/enclave/mruby/build/host/include/mruby/hash.h +234 -0
- data/ext/enclave/mruby/build/host/include/mruby/internal.h +278 -0
- data/ext/enclave/mruby/build/host/include/mruby/irep.h +142 -0
- data/ext/enclave/mruby/build/host/include/mruby/istruct.h +50 -0
- data/ext/enclave/mruby/build/host/include/mruby/khash.h +455 -0
- data/ext/enclave/mruby/build/host/include/mruby/mempool.h +19 -0
- data/ext/enclave/mruby/build/host/include/mruby/numeric.h +174 -0
- data/ext/enclave/mruby/build/host/include/mruby/object.h +44 -0
- data/ext/enclave/mruby/build/host/include/mruby/opcode.h +73 -0
- data/ext/enclave/mruby/build/host/include/mruby/ops.h +133 -0
- data/ext/enclave/mruby/build/host/include/mruby/presym/id.h +895 -0
- data/ext/enclave/mruby/build/host/include/mruby/presym/scanning.h +82 -0
- data/ext/enclave/mruby/build/host/include/mruby/presym/table.h +1787 -0
- data/ext/enclave/mruby/build/host/include/mruby/presym.h +65 -0
- data/ext/enclave/mruby/build/host/include/mruby/proc.h +184 -0
- data/ext/enclave/mruby/build/host/include/mruby/range.h +77 -0
- data/ext/enclave/mruby/build/host/include/mruby/re.h +16 -0
- data/ext/enclave/mruby/build/host/include/mruby/string.h +428 -0
- data/ext/enclave/mruby/build/host/include/mruby/throw.h +81 -0
- data/ext/enclave/mruby/build/host/include/mruby/value.h +471 -0
- data/ext/enclave/mruby/build/host/include/mruby/variable.h +108 -0
- data/ext/enclave/mruby/build/host/include/mruby/version.h +143 -0
- data/ext/enclave/mruby/build/host/include/mruby.h +1632 -0
- data/ext/enclave/mruby/build/host/mrbc/include/mruby/presym/id.h +281 -0
- data/ext/enclave/mruby/build/host/mrbc/include/mruby/presym/table.h +559 -0
- data/ext/enclave/mruby/build/host/mrbgems/gem_init.c +164 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-array-ext/gem_init.c +650 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-binding/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-catch/gem_init.c +86 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-class-ext/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-compar-ext/gem_init.c +99 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-complex/gem_init.c +362 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-data/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-enum-chain/gem_init.c +229 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-enum-ext/gem_init.c +1420 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-enum-lazy/gem_init.c +602 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-enumerator/gem_init.c +822 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-eval/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-fiber/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-hash-ext/gem_init.c +591 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-kernel-ext/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-math/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-metaprog/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-method/gem_init.c +153 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-numeric-ext/gem_init.c +211 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-object-ext/gem_init.c +94 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-objectspace/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-pack/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-proc-binding/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-proc-ext/gem_init.c +237 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-random/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-range-ext/gem_init.c +205 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-rational/gem_init.c +147 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-set/gem_init.c +487 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-sprintf/gem_init.c +83 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-string-ext/gem_init.c +220 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-struct/gem_init.c +175 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-symbol-ext/gem_init.c +153 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-time/gem_init.c +21 -0
- data/ext/enclave/mruby/build/host/mrbgems/mruby-toplevel-ext/gem_init.c +78 -0
- data/ext/enclave/mruby/build/host/mrblib/mrblib.c +1758 -0
- data/ext/enclave/mruby/build_config/ArduinoDue.rb +72 -0
- data/ext/enclave/mruby/build_config/IntelEdison.rb +69 -0
- data/ext/enclave/mruby/build_config/IntelGalileo.rb +88 -0
- data/ext/enclave/mruby/build_config/RX630.rb +63 -0
- data/ext/enclave/mruby/build_config/android_arm64_v8a.rb +11 -0
- data/ext/enclave/mruby/build_config/android_armeabi_v7a_neon_hard.rb +13 -0
- data/ext/enclave/mruby/build_config/bench.rb +11 -0
- data/ext/enclave/mruby/build_config/boxing.rb +19 -0
- data/ext/enclave/mruby/build_config/chipKITMax32.rb +68 -0
- data/ext/enclave/mruby/build_config/ci/gcc-clang.rb +40 -0
- data/ext/enclave/mruby/build_config/ci/msvc.rb +20 -0
- data/ext/enclave/mruby/build_config/clang-asan.rb +11 -0
- data/ext/enclave/mruby/build_config/cosmopolitan.rb +86 -0
- data/ext/enclave/mruby/build_config/cross-32bit.rb +14 -0
- data/ext/enclave/mruby/build_config/cross-mingw-winetest.rb +90 -0
- data/ext/enclave/mruby/build_config/cross-mingw.rb +14 -0
- data/ext/enclave/mruby/build_config/default.rb +83 -0
- data/ext/enclave/mruby/build_config/dreamcast_shelf.rb +81 -0
- data/ext/enclave/mruby/build_config/emscripten-cxx.rb +12 -0
- data/ext/enclave/mruby/build_config/emscripten.rb +10 -0
- data/ext/enclave/mruby/build_config/gameboyadvance.rb +72 -0
- data/ext/enclave/mruby/build_config/helpers/wine_runner.rb +71 -0
- data/ext/enclave/mruby/build_config/host-cxx.rb +12 -0
- data/ext/enclave/mruby/build_config/host-debug.rb +20 -0
- data/ext/enclave/mruby/build_config/host-f32.rb +14 -0
- data/ext/enclave/mruby/build_config/host-gprof.rb +14 -0
- data/ext/enclave/mruby/build_config/host-m32.rb +15 -0
- data/ext/enclave/mruby/build_config/host-nofloat.rb +22 -0
- data/ext/enclave/mruby/build_config/host-shared.rb +36 -0
- data/ext/enclave/mruby/build_config/i586-pc-msdosdjgpp.rb +76 -0
- data/ext/enclave/mruby/build_config/luckfox_pico.rb +106 -0
- data/ext/enclave/mruby/build_config/milkv_duo.rb +106 -0
- data/ext/enclave/mruby/build_config/minimal.rb +4 -0
- data/ext/enclave/mruby/build_config/mrbc.rb +10 -0
- data/ext/enclave/mruby/build_config/nintendo_switch.rb +73 -0
- data/ext/enclave/mruby/build_config/nintendo_wii.rb +95 -0
- data/ext/enclave/mruby/build_config/no-float.rb +17 -0
- data/ext/enclave/mruby/build_config/playstationportable.rb +78 -0
- data/ext/enclave/mruby/build_config/serenity.rb +26 -0
- data/ext/enclave/mruby/build_config.rb +9 -0
- data/ext/enclave/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +5 -0
- data/ext/enclave/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +23 -0
- data/ext/enclave/mruby/examples/mrbgems/c_and_ruby_extension_example/test/example.rb +7 -0
- data/ext/enclave/mruby/examples/mrbgems/c_extension_example/src/example.c +23 -0
- data/ext/enclave/mruby/examples/mrbgems/c_extension_example/test/example.c +7 -0
- data/ext/enclave/mruby/examples/mrbgems/c_extension_example/test/example.rb +3 -0
- data/ext/enclave/mruby/examples/mrbgems/cdata_extension_example/src/example.c +77 -0
- data/ext/enclave/mruby/examples/mrbgems/cdata_extension_example/test/example.c +7 -0
- data/ext/enclave/mruby/examples/mrbgems/mruby-YOUR-bigint/core/bigint.c +70 -0
- data/ext/enclave/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +5 -0
- data/ext/enclave/mruby/examples/mrbgems/ruby_extension_example/test/example.rb +3 -0
- data/ext/enclave/mruby/include/mrbconf.h +230 -0
- data/ext/enclave/mruby/include/mruby/array.h +303 -0
- data/ext/enclave/mruby/include/mruby/boxing_nan.h +169 -0
- data/ext/enclave/mruby/include/mruby/boxing_no.h +59 -0
- data/ext/enclave/mruby/include/mruby/boxing_word.h +248 -0
- data/ext/enclave/mruby/include/mruby/class.h +157 -0
- data/ext/enclave/mruby/include/mruby/common.h +127 -0
- data/ext/enclave/mruby/include/mruby/compile.h +187 -0
- data/ext/enclave/mruby/include/mruby/data.h +76 -0
- data/ext/enclave/mruby/include/mruby/debug.h +75 -0
- data/ext/enclave/mruby/include/mruby/dump.h +159 -0
- data/ext/enclave/mruby/include/mruby/endian.h +44 -0
- data/ext/enclave/mruby/include/mruby/error.h +168 -0
- data/ext/enclave/mruby/include/mruby/gc.h +77 -0
- data/ext/enclave/mruby/include/mruby/hash.h +234 -0
- data/ext/enclave/mruby/include/mruby/internal.h +278 -0
- data/ext/enclave/mruby/include/mruby/irep.h +142 -0
- data/ext/enclave/mruby/include/mruby/istruct.h +50 -0
- data/ext/enclave/mruby/include/mruby/khash.h +455 -0
- data/ext/enclave/mruby/include/mruby/mempool.h +19 -0
- data/ext/enclave/mruby/include/mruby/numeric.h +174 -0
- data/ext/enclave/mruby/include/mruby/object.h +44 -0
- data/ext/enclave/mruby/include/mruby/opcode.h +73 -0
- data/ext/enclave/mruby/include/mruby/ops.h +133 -0
- data/ext/enclave/mruby/include/mruby/presym/scanning.h +82 -0
- data/ext/enclave/mruby/include/mruby/presym.h +65 -0
- data/ext/enclave/mruby/include/mruby/proc.h +184 -0
- data/ext/enclave/mruby/include/mruby/range.h +77 -0
- data/ext/enclave/mruby/include/mruby/re.h +16 -0
- data/ext/enclave/mruby/include/mruby/string.h +428 -0
- data/ext/enclave/mruby/include/mruby/throw.h +81 -0
- data/ext/enclave/mruby/include/mruby/value.h +471 -0
- data/ext/enclave/mruby/include/mruby/variable.h +108 -0
- data/ext/enclave/mruby/include/mruby/version.h +143 -0
- data/ext/enclave/mruby/include/mruby.h +1632 -0
- data/ext/enclave/mruby/lib/mruby/amalgam.rb +568 -0
- data/ext/enclave/mruby/lib/mruby/build/command.rb +383 -0
- data/ext/enclave/mruby/lib/mruby/build/load_gems.rb +383 -0
- data/ext/enclave/mruby/lib/mruby/build.rb +616 -0
- data/ext/enclave/mruby/lib/mruby/core_ext.rb +61 -0
- data/ext/enclave/mruby/lib/mruby/doc.rb +51 -0
- data/ext/enclave/mruby/lib/mruby/gem.rb +585 -0
- data/ext/enclave/mruby/lib/mruby/lockfile.rb +81 -0
- data/ext/enclave/mruby/lib/mruby/presym.rb +167 -0
- data/ext/enclave/mruby/lib/mruby/source.rb +32 -0
- data/ext/enclave/mruby/mrbgems/default-no-fpu.gembox +3 -0
- data/ext/enclave/mruby/mrbgems/default-no-stdio.gembox +4 -0
- data/ext/enclave/mruby/mrbgems/default.gembox +25 -0
- data/ext/enclave/mruby/mrbgems/full-core.gembox +6 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-dir/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-dir/src/dir_hal.c +193 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-io/mrbgem.rake +8 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-io/src/io_hal.c +602 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-socket/mrbgem.rake +8 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-socket/src/socket_hal.c +158 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-task/README.md +102 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-task/mrbgem.rake +8 -0
- data/ext/enclave/mruby/mrbgems/hal-posix-task/src/task_hal.c +252 -0
- data/ext/enclave/mruby/mrbgems/hal-win-dir/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/hal-win-dir/src/dir_hal.c +249 -0
- data/ext/enclave/mruby/mrbgems/hal-win-io/mrbgem.rake +11 -0
- data/ext/enclave/mruby/mrbgems/hal-win-io/src/io_hal.c +646 -0
- data/ext/enclave/mruby/mrbgems/hal-win-socket/mrbgem.rake +12 -0
- data/ext/enclave/mruby/mrbgems/hal-win-socket/src/socket_hal.c +177 -0
- data/ext/enclave/mruby/mrbgems/hal-win-task/README.md +109 -0
- data/ext/enclave/mruby/mrbgems/hal-win-task/mrbgem.rake +11 -0
- data/ext/enclave/mruby/mrbgems/hal-win-task/src/task_hal.c +187 -0
- data/ext/enclave/mruby/mrbgems/math.gembox +12 -0
- data/ext/enclave/mruby/mrbgems/metaprog.gembox +21 -0
- data/ext/enclave/mruby/mrbgems/mruby-array-ext/README.md +87 -0
- data/ext/enclave/mruby/mrbgems/mruby-array-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +784 -0
- data/ext/enclave/mruby/mrbgems/mruby-array-ext/src/array.c +1583 -0
- data/ext/enclave/mruby/mrbgems/mruby-array-ext/test/array.rb +849 -0
- data/ext/enclave/mruby/mrbgems/mruby-benchmark/README.md +257 -0
- data/ext/enclave/mruby/mrbgems/mruby-benchmark/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-benchmark/mrblib/benchmark.rb +131 -0
- data/ext/enclave/mruby/mrbgems/mruby-benchmark/test/benchmark.rb +244 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/README-fgmp.md +154 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/README.md +44 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/core/bigint.c +6335 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/core/bigint.h +117 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-bigint/test/bigint.rb +157 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-config/README.md +46 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-config/mrbgem.rake +49 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-config/mruby-config +46 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-config/mruby-config.bat +92 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/README.md +63 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +283 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +703 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +523 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h +26 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c +238 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h +14 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +88 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.h +13 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apistring.c +34 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apistring.h +14 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c +436 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c +509 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c +71 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c +64 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +768 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +159 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +24 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdberror.h +19 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/README.md +94 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +58 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +808 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.c +1035 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.h +185 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c +797 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.h +132 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.c +1118 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.h +153 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c +516 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h +95 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_history.c +185 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_history.h +76 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c +491 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.h +137 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mrbc/README.md +58 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mrbc/bintest/mrbc.rb +30 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +15 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +362 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/stub.c +104 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mruby/README.md +47 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +178 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +380 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-strip/README.md +38 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-strip/bintest/mruby_strip.rb +73 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-strip/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby_strip.c +139 -0
- data/ext/enclave/mruby/mrbgems/mruby-binding/README.md +256 -0
- data/ext/enclave/mruby/mrbgems/mruby-binding/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-binding/src/binding.c +518 -0
- data/ext/enclave/mruby/mrbgems/mruby-binding/test/binding.c +14 -0
- data/ext/enclave/mruby/mrbgems/mruby-binding/test/binding.rb +64 -0
- data/ext/enclave/mruby/mrbgems/mruby-catch/README.md +94 -0
- data/ext/enclave/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-catch/mrblib/catch.rb +29 -0
- data/ext/enclave/mruby/mrbgems/mruby-catch/src/catch.c +149 -0
- data/ext/enclave/mruby/mrbgems/mruby-catch/test/catch.rb +86 -0
- data/ext/enclave/mruby/mrbgems/mruby-class-ext/README.md +81 -0
- data/ext/enclave/mruby/mrbgems/mruby-class-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-class-ext/src/class.c +377 -0
- data/ext/enclave/mruby/mrbgems/mruby-class-ext/test/class.rb +46 -0
- data/ext/enclave/mruby/mrbgems/mruby-class-ext/test/module.rb +109 -0
- data/ext/enclave/mruby/mrbgems/mruby-cmath/README.md +45 -0
- data/ext/enclave/mruby/mrbgems/mruby-cmath/mrbgem.rake +8 -0
- data/ext/enclave/mruby/mrbgems/mruby-cmath/src/cmath.c +426 -0
- data/ext/enclave/mruby/mrbgems/mruby-cmath/test/cmath.rb +41 -0
- data/ext/enclave/mruby/mrbgems/mruby-compar-ext/README.md +65 -0
- data/ext/enclave/mruby/mrbgems/mruby-compar-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb +75 -0
- data/ext/enclave/mruby/mrbgems/mruby-compar-ext/test/compar.rb +21 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/README.md +28 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/codegen.c +7316 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/keywords +52 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/lex.def +207 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/node.h +784 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/parse.y +8977 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/core/y.tab.c +16136 -0
- data/ext/enclave/mruby/mrbgems/mruby-compiler/mrbgem.rake +42 -0
- data/ext/enclave/mruby/mrbgems/mruby-complex/README.md +55 -0
- data/ext/enclave/mruby/mrbgems/mruby-complex/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-complex/mrblib/complex.rb +259 -0
- data/ext/enclave/mruby/mrbgems/mruby-complex/src/complex.c +597 -0
- data/ext/enclave/mruby/mrbgems/mruby-complex/test/complex.rb +174 -0
- data/ext/enclave/mruby/mrbgems/mruby-data/README.md +126 -0
- data/ext/enclave/mruby/mrbgems/mruby-data/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-data/src/data.c +550 -0
- data/ext/enclave/mruby/mrbgems/mruby-data/test/data.rb +76 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/README.md +53 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/include/dir_hal.h +79 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/mrbgem.rake +35 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/mrblib/dir.rb +124 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/src/dir.c +493 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/test/dir.rb +138 -0
- data/ext/enclave/mruby/mrbgems/mruby-dir/test/dirtest.c +125 -0
- data/ext/enclave/mruby/mrbgems/mruby-encoding/README.md +96 -0
- data/ext/enclave/mruby/mrbgems/mruby-encoding/mrbgem.rake +8 -0
- data/ext/enclave/mruby/mrbgems/mruby-encoding/src/encoding.c +128 -0
- data/ext/enclave/mruby/mrbgems/mruby-encoding/test/numeric.rb +27 -0
- data/ext/enclave/mruby/mrbgems/mruby-encoding/test/string.rb +30 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-chain/README.md +80 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-chain/mrbgem.rake +6 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-chain/mrblib/chain.rb +149 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-chain/test/enum_chain.rb +108 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-ext/README.md +487 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb +938 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-ext/test/enum.rb +223 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-lazy/README.md +91 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-lazy/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-lazy/mrblib/lazy.rb +363 -0
- data/ext/enclave/mruby/mrbgems/mruby-enum-lazy/test/lazy.rb +59 -0
- data/ext/enclave/mruby/mrbgems/mruby-enumerator/README.md +89 -0
- data/ext/enclave/mruby/mrbgems/mruby-enumerator/mrbgem.rake +6 -0
- data/ext/enclave/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +861 -0
- data/ext/enclave/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +664 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/README.md +83 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/mrblib/errno.rb +50 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/src/errno.c +335 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/src/gen.rb +18 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/src/known_errors.def +156 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/src/known_errors_def.cstub +780 -0
- data/ext/enclave/mruby/mrbgems/mruby-errno/test/errno.rb +57 -0
- data/ext/enclave/mruby/mrbgems/mruby-error/README.md +103 -0
- data/ext/enclave/mruby/mrbgems/mruby-error/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-error/src/exception.c +143 -0
- data/ext/enclave/mruby/mrbgems/mruby-error/test/exception.c +60 -0
- data/ext/enclave/mruby/mrbgems/mruby-error/test/exception.rb +55 -0
- data/ext/enclave/mruby/mrbgems/mruby-eval/README.md +26 -0
- data/ext/enclave/mruby/mrbgems/mruby-eval/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-eval/src/eval.c +437 -0
- data/ext/enclave/mruby/mrbgems/mruby-eval/test/binding.rb +81 -0
- data/ext/enclave/mruby/mrbgems/mruby-eval/test/eval.rb +185 -0
- data/ext/enclave/mruby/mrbgems/mruby-exit/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-exit/src/mruby_exit.c +83 -0
- data/ext/enclave/mruby/mrbgems/mruby-fiber/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-fiber/src/fiber.c +575 -0
- data/ext/enclave/mruby/mrbgems/mruby-fiber/test/fiber.rb +210 -0
- data/ext/enclave/mruby/mrbgems/mruby-fiber/test/fiber2.rb +155 -0
- data/ext/enclave/mruby/mrbgems/mruby-fiber/test/fibertest.c +87 -0
- data/ext/enclave/mruby/mrbgems/mruby-hash-ext/README.md +392 -0
- data/ext/enclave/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +6 -0
- data/ext/enclave/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +408 -0
- data/ext/enclave/mruby/mrbgems/mruby-hash-ext/src/hash_ext.c +392 -0
- data/ext/enclave/mruby/mrbgems/mruby-hash-ext/test/hash.rb +317 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/README.md +198 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/include/io_hal.h +451 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/include/mruby/io.h +76 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/mrbgem.rake +34 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/mrblib/file.rb +109 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +24 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/mrblib/io.rb +303 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/mrblib/kernel.rb +175 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/src/file.c +1192 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/src/file_test.c +403 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/src/io.c +2260 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/src/mruby_io_gem.c +21 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/test/file.rb +415 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/test/file_test.rb +112 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/test/io.rb +668 -0
- data/ext/enclave/mruby/mrbgems/mruby-io/test/mruby_io_test.c +293 -0
- data/ext/enclave/mruby/mrbgems/mruby-kernel-ext/README.md +165 -0
- data/ext/enclave/mruby/mrbgems/mruby-kernel-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +316 -0
- data/ext/enclave/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb +134 -0
- data/ext/enclave/mruby/mrbgems/mruby-math/README.md +77 -0
- data/ext/enclave/mruby/mrbgems/mruby-math/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-math/src/math.c +753 -0
- data/ext/enclave/mruby/mrbgems/mruby-math/test/math.rb +201 -0
- data/ext/enclave/mruby/mrbgems/mruby-metaprog/README.md +123 -0
- data/ext/enclave/mruby/mrbgems/mruby-metaprog/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-metaprog/src/metaprog.c +739 -0
- data/ext/enclave/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +465 -0
- data/ext/enclave/mruby/mrbgems/mruby-method/README.md +66 -0
- data/ext/enclave/mruby/mrbgems/mruby-method/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-method/mrblib/method.rb +73 -0
- data/ext/enclave/mruby/mrbgems/mruby-method/src/method.c +890 -0
- data/ext/enclave/mruby/mrbgems/mruby-method/test/method.rb +514 -0
- data/ext/enclave/mruby/mrbgems/mruby-numeric-ext/README.md +78 -0
- data/ext/enclave/mruby/mrbgems/mruby-numeric-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb +125 -0
- data/ext/enclave/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +527 -0
- data/ext/enclave/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +137 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/README.md +144 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/mrblib/object.rb +33 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/src/object.c +128 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/test/nil.rb +16 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/test/object.rb +67 -0
- data/ext/enclave/mruby/mrbgems/mruby-object-ext/test/object_ext.c +17 -0
- data/ext/enclave/mruby/mrbgems/mruby-objectspace/README.md +59 -0
- data/ext/enclave/mruby/mrbgems/mruby-objectspace/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +188 -0
- data/ext/enclave/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +60 -0
- data/ext/enclave/mruby/mrbgems/mruby-os-memsize/README.md +75 -0
- data/ext/enclave/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-os-memsize/src/memsize.c +271 -0
- data/ext/enclave/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
- data/ext/enclave/mruby/mrbgems/mruby-pack/README.md +140 -0
- data/ext/enclave/mruby/mrbgems/mruby-pack/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-pack/src/pack.c +2129 -0
- data/ext/enclave/mruby/mrbgems/mruby-pack/test/pack.rb +202 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-binding/README.md +140 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-binding/mrbgem.rake +10 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-binding/src/proc_binding.c +76 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-binding/test/proc_binding.c +14 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-binding/test/proc_binding.rb +22 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/README.md +107 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb +130 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/src/proc.c +267 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/test/proc.c +62 -0
- data/ext/enclave/mruby/mrbgems/mruby-proc-ext/test/proc.rb +130 -0
- data/ext/enclave/mruby/mrbgems/mruby-random/README.md +272 -0
- data/ext/enclave/mruby/mrbgems/mruby-random/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-random/src/random.c +608 -0
- data/ext/enclave/mruby/mrbgems/mruby-random/test/random.rb +151 -0
- data/ext/enclave/mruby/mrbgems/mruby-range-ext/README.md +93 -0
- data/ext/enclave/mruby/mrbgems/mruby-range-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +155 -0
- data/ext/enclave/mruby/mrbgems/mruby-range-ext/src/range.c +236 -0
- data/ext/enclave/mruby/mrbgems/mruby-range-ext/test/range.rb +211 -0
- data/ext/enclave/mruby/mrbgems/mruby-rational/README.md +61 -0
- data/ext/enclave/mruby/mrbgems/mruby-rational/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-rational/mrblib/rational.rb +66 -0
- data/ext/enclave/mruby/mrbgems/mruby-rational/src/rational.c +1269 -0
- data/ext/enclave/mruby/mrbgems/mruby-rational/test/rational.rb +316 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/LICENSE +24 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/README.md +260 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/mrbgem.rake +9 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/mrblib/set.rb +325 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/mruby-set.gem +6 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/src/set.c +1535 -0
- data/ext/enclave/mruby/mrbgems/mruby-set/test/set.rb +764 -0
- data/ext/enclave/mruby/mrbgems/mruby-sleep/README.md +29 -0
- data/ext/enclave/mruby/mrbgems/mruby-sleep/example/sleep.rb +2 -0
- data/ext/enclave/mruby/mrbgems/mruby-sleep/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-sleep/src/sleep.c +187 -0
- data/ext/enclave/mruby/mrbgems/mruby-sleep/test/sleep_test.rb +29 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/README.md +56 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/include/socket_hal.h +83 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/mrbgem.rake +37 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/mrblib/socket.rb +1131 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/src/const.cstub +480 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/src/const.def +172 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/src/gen.rb +17 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/src/socket.c +1374 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/addrinfo.rb +91 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/basicsocket.rb +17 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/ipsocket.rb +44 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/socket.rb +38 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/sockettest.c +84 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/tcpsocket.rb +4 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/udpsocket.rb +16 -0
- data/ext/enclave/mruby/mrbgems/mruby-socket/test/unix.rb +130 -0
- data/ext/enclave/mruby/mrbgems/mruby-sprintf/README.md +235 -0
- data/ext/enclave/mruby/mrbgems/mruby-sprintf/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-sprintf/mrblib/string.rb +24 -0
- data/ext/enclave/mruby/mrbgems/mruby-sprintf/src/sprintf.c +1195 -0
- data/ext/enclave/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +92 -0
- data/ext/enclave/mruby/mrbgems/mruby-strftime/README.md +140 -0
- data/ext/enclave/mruby/mrbgems/mruby-strftime/mrbgem.rake +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-strftime/src/strftime.c +119 -0
- data/ext/enclave/mruby/mrbgems/mruby-strftime/test/strftime.rb +152 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/README.md +886 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +166 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/src/string.c +2290 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/test/numeric.rb +27 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/test/range.rb +26 -0
- data/ext/enclave/mruby/mrbgems/mruby-string-ext/test/string.rb +765 -0
- data/ext/enclave/mruby/mrbgems/mruby-struct/README.md +105 -0
- data/ext/enclave/mruby/mrbgems/mruby-struct/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-struct/mrblib/struct.rb +69 -0
- data/ext/enclave/mruby/mrbgems/mruby-struct/src/struct.c +812 -0
- data/ext/enclave/mruby/mrbgems/mruby-struct/test/struct.rb +303 -0
- data/ext/enclave/mruby/mrbgems/mruby-symbol-ext/README.md +50 -0
- data/ext/enclave/mruby/mrbgems/mruby-symbol-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb +72 -0
- data/ext/enclave/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +79 -0
- data/ext/enclave/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +55 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/README.md +770 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/inspection.rb +65 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/priority.rb +41 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/producer_consumer.rb +58 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/simple.rb +27 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/statistics.rb +59 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/suspend_resume.rb +47 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/examples/task_pass.rb +21 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/include/task.h +143 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/include/task_hal.h +162 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/mrbgem.rake +36 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/src/task.c +1573 -0
- data/ext/enclave/mruby/mrbgems/mruby-task/test/task.rb +185 -0
- data/ext/enclave/mruby/mrbgems/mruby-test/README.md +7 -0
- data/ext/enclave/mruby/mrbgems/mruby-test/driver.c +315 -0
- data/ext/enclave/mruby/mrbgems/mruby-test/mrbgem.rake +173 -0
- data/ext/enclave/mruby/mrbgems/mruby-test/vformat.c +151 -0
- data/ext/enclave/mruby/mrbgems/mruby-test-inline-struct/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-test-inline-struct/test/inline.c +92 -0
- data/ext/enclave/mruby/mrbgems/mruby-test-inline-struct/test/inline.rb +118 -0
- data/ext/enclave/mruby/mrbgems/mruby-time/README.md +102 -0
- data/ext/enclave/mruby/mrbgems/mruby-time/include/mruby/time.h +27 -0
- data/ext/enclave/mruby/mrbgems/mruby-time/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-time/src/time.c +1739 -0
- data/ext/enclave/mruby/mrbgems/mruby-time/test/time.rb +313 -0
- data/ext/enclave/mruby/mrbgems/mruby-toplevel-ext/README.md +32 -0
- data/ext/enclave/mruby/mrbgems/mruby-toplevel-ext/mrbgem.rake +5 -0
- data/ext/enclave/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb +24 -0
- data/ext/enclave/mruby/mrbgems/mruby-toplevel-ext/test/toplevel.rb +23 -0
- data/ext/enclave/mruby/mrbgems/stdlib-ext.gembox +21 -0
- data/ext/enclave/mruby/mrbgems/stdlib-io.gembox +15 -0
- data/ext/enclave/mruby/mrbgems/stdlib.gembox +63 -0
- data/ext/enclave/mruby/mrblib/10error.rb +23 -0
- data/ext/enclave/mruby/mrblib/array.rb +102 -0
- data/ext/enclave/mruby/mrblib/compar.rb +102 -0
- data/ext/enclave/mruby/mrblib/enum.rb +358 -0
- data/ext/enclave/mruby/mrblib/hash.rb +276 -0
- data/ext/enclave/mruby/mrblib/kernel.rb +45 -0
- data/ext/enclave/mruby/mrblib/numeric.rb +160 -0
- data/ext/enclave/mruby/mrblib/range.rb +98 -0
- data/ext/enclave/mruby/mrblib/string.rb +173 -0
- data/ext/enclave/mruby/mrblib/symbol.rb +8 -0
- data/ext/enclave/mruby/oss-fuzz/mruby_fuzzer.c +18 -0
- data/ext/enclave/mruby/oss-fuzz/proto_to_ruby.h +55 -0
- data/ext/enclave/mruby/src/allocf.c +37 -0
- data/ext/enclave/mruby/src/array.c +2302 -0
- data/ext/enclave/mruby/src/backtrace.c +294 -0
- data/ext/enclave/mruby/src/cdump.c +498 -0
- data/ext/enclave/mruby/src/class.c +4394 -0
- data/ext/enclave/mruby/src/codedump.c +693 -0
- data/ext/enclave/mruby/src/debug.c +290 -0
- data/ext/enclave/mruby/src/dump.c +998 -0
- data/ext/enclave/mruby/src/enum.c +30 -0
- data/ext/enclave/mruby/src/error.c +937 -0
- data/ext/enclave/mruby/src/etc.c +421 -0
- data/ext/enclave/mruby/src/fmt_fp.c +372 -0
- data/ext/enclave/mruby/src/gc.c +1610 -0
- data/ext/enclave/mruby/src/hash.c +2355 -0
- data/ext/enclave/mruby/src/init.c +50 -0
- data/ext/enclave/mruby/src/kernel.c +718 -0
- data/ext/enclave/mruby/src/load.c +760 -0
- data/ext/enclave/mruby/src/mempool.c +225 -0
- data/ext/enclave/mruby/src/numeric.c +2420 -0
- data/ext/enclave/mruby/src/numops.c +112 -0
- data/ext/enclave/mruby/src/object.c +883 -0
- data/ext/enclave/mruby/src/print.c +136 -0
- data/ext/enclave/mruby/src/proc.c +572 -0
- data/ext/enclave/mruby/src/range.c +597 -0
- data/ext/enclave/mruby/src/readfloat.c +228 -0
- data/ext/enclave/mruby/src/readint.c +27 -0
- data/ext/enclave/mruby/src/readnum.c +43 -0
- data/ext/enclave/mruby/src/state.c +247 -0
- data/ext/enclave/mruby/src/string.c +3577 -0
- data/ext/enclave/mruby/src/symbol.c +1023 -0
- data/ext/enclave/mruby/src/value_array.h +28 -0
- data/ext/enclave/mruby/src/variable.c +1475 -0
- data/ext/enclave/mruby/src/version.c +17 -0
- data/ext/enclave/mruby/src/vm.c +3696 -0
- data/ext/enclave/mruby/tasks/amalgam.rake +34 -0
- data/ext/enclave/mruby/tasks/benchmark.rake +93 -0
- data/ext/enclave/mruby/tasks/bin.rake +23 -0
- data/ext/enclave/mruby/tasks/core.rake +12 -0
- data/ext/enclave/mruby/tasks/doc.rake +118 -0
- data/ext/enclave/mruby/tasks/install.rake +40 -0
- data/ext/enclave/mruby/tasks/libmruby.rake +90 -0
- data/ext/enclave/mruby/tasks/mrbgems.rake +152 -0
- data/ext/enclave/mruby/tasks/mrblib.rake +29 -0
- data/ext/enclave/mruby/tasks/presym.rake +57 -0
- data/ext/enclave/mruby/tasks/test.rake +84 -0
- data/ext/enclave/mruby/tasks/toolchains/android.rake +228 -0
- data/ext/enclave/mruby/tasks/toolchains/clang.rake +8 -0
- data/ext/enclave/mruby/tasks/toolchains/emscripten.rake +57 -0
- data/ext/enclave/mruby/tasks/toolchains/gcc.rake +74 -0
- data/ext/enclave/mruby/tasks/toolchains/openwrt.rake +32 -0
- data/ext/enclave/mruby/tasks/toolchains/visualcpp.rake +48 -0
- data/ext/enclave/mruby/test/assert.rb +404 -0
- data/ext/enclave/mruby/test/bintest.rb +55 -0
- data/ext/enclave/mruby/test/t/argumenterror.rb +37 -0
- data/ext/enclave/mruby/test/t/array.rb +478 -0
- data/ext/enclave/mruby/test/t/basicobject.rb +10 -0
- data/ext/enclave/mruby/test/t/bs_block.rb +621 -0
- data/ext/enclave/mruby/test/t/bs_literal.rb +38 -0
- data/ext/enclave/mruby/test/t/class.rb +505 -0
- data/ext/enclave/mruby/test/t/codegen.rb +196 -0
- data/ext/enclave/mruby/test/t/comparable.rb +79 -0
- data/ext/enclave/mruby/test/t/ensure.rb +36 -0
- data/ext/enclave/mruby/test/t/enumerable.rb +134 -0
- data/ext/enclave/mruby/test/t/exception.rb +425 -0
- data/ext/enclave/mruby/test/t/false.rb +31 -0
- data/ext/enclave/mruby/test/t/float.rb +296 -0
- data/ext/enclave/mruby/test/t/gc.rb +45 -0
- data/ext/enclave/mruby/test/t/hash.rb +976 -0
- data/ext/enclave/mruby/test/t/indexerror.rb +6 -0
- data/ext/enclave/mruby/test/t/integer.rb +247 -0
- data/ext/enclave/mruby/test/t/iterations.rb +61 -0
- data/ext/enclave/mruby/test/t/kernel.rb +462 -0
- data/ext/enclave/mruby/test/t/lang.rb +74 -0
- data/ext/enclave/mruby/test/t/literals.rb +386 -0
- data/ext/enclave/mruby/test/t/localjumperror.rb +13 -0
- data/ext/enclave/mruby/test/t/methods.rb +138 -0
- data/ext/enclave/mruby/test/t/module.rb +931 -0
- data/ext/enclave/mruby/test/t/nameerror.rb +28 -0
- data/ext/enclave/mruby/test/t/nil.rb +39 -0
- data/ext/enclave/mruby/test/t/nomethoderror.rb +22 -0
- data/ext/enclave/mruby/test/t/numeric.rb +114 -0
- data/ext/enclave/mruby/test/t/object.rb +10 -0
- data/ext/enclave/mruby/test/t/proc.rb +198 -0
- data/ext/enclave/mruby/test/t/range.rb +194 -0
- data/ext/enclave/mruby/test/t/rangeerror.rb +6 -0
- data/ext/enclave/mruby/test/t/regexperror.rb +4 -0
- data/ext/enclave/mruby/test/t/runtimeerror.rb +6 -0
- data/ext/enclave/mruby/test/t/standarderror.rb +6 -0
- data/ext/enclave/mruby/test/t/string.rb +981 -0
- data/ext/enclave/mruby/test/t/superclass.rb +46 -0
- data/ext/enclave/mruby/test/t/symbol.rb +30 -0
- data/ext/enclave/mruby/test/t/syntax.rb +1296 -0
- data/ext/enclave/mruby/test/t/true.rb +31 -0
- data/ext/enclave/mruby/test/t/typeerror.rb +6 -0
- data/ext/enclave/mruby/test/t/unicode.rb +39 -0
- data/ext/enclave/mruby/test/t/vformat.rb +57 -0
- data/ext/enclave/mruby/tools/lrama/LEGAL.md +12 -0
- data/ext/enclave/mruby/tools/lrama/MIT +21 -0
- data/ext/enclave/mruby/tools/lrama/NEWS.md +696 -0
- data/ext/enclave/mruby/tools/lrama/exe/lrama +7 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/bitmap.rb +34 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/command.rb +68 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/context.rb +499 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/derivation.rb +66 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/example.rb +129 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/path.rb +29 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/production_path.rb +19 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/start_path.rb +23 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/state_item.rb +8 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/transition_path.rb +19 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples/triple.rb +23 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/counterexamples.rb +298 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/diagnostics.rb +36 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/digraph.rb +83 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/auxiliary.rb +9 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/binding.rb +67 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code/destructor_code.rb +42 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code/initial_action_code.rb +36 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code/no_reference_code.rb +30 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code/printer_code.rb +42 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code/rule_action.rb +92 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/code.rb +53 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/counter.rb +17 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/destructor.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/error_token.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/parameterizing_rule/resolver.rb +62 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/parameterizing_rule/rhs.rb +40 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/parameterizing_rule/rule.rb +24 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/parameterizing_rule.rb +5 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/percent_code.rb +14 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/precedence.rb +13 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/printer.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/reference.rb +16 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/rule.rb +75 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/rule_builder.rb +255 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/stdlib.y +122 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/symbol.rb +105 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/symbols/resolver.rb +301 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/symbols.rb +3 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/type.rb +20 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar/union.rb +12 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar.rb +407 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/grammar_validator.rb +37 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/grammar_file.rb +40 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/location.rb +115 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token/char.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token/ident.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token/instantiate_rule.rb +30 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token/tag.rb +16 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token/user_code.rb +83 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer/token.rb +70 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/lexer.rb +191 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/logger.rb +21 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/option_parser.rb +169 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/options.rb +28 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/output.rb +459 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/parser.rb +2144 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/report/duration.rb +27 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/report/profile.rb +16 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/report.rb +4 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state/reduce.rb +37 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state/reduce_reduce_conflict.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state/resolved_conflict.rb +31 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state/shift.rb +15 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state/shift_reduce_conflict.rb +11 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/state.rb +433 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/states/item.rb +91 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/states.rb +595 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/states_reporter.rb +362 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/trace_reporter.rb +45 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama/version.rb +5 -0
- data/ext/enclave/mruby/tools/lrama/lib/lrama.rb +22 -0
- data/ext/enclave/mruby/tools/lrama/template/bison/_yacc.h +71 -0
- data/ext/enclave/mruby/tools/lrama/template/bison/yacc.c +2068 -0
- data/ext/enclave/mruby/tools/lrama/template/bison/yacc.h +40 -0
- data/ext/enclave/sandbox_build_config.rb +15 -0
- data/ext/enclave/sandbox_core.c +722 -0
- data/ext/enclave/sandbox_core.h +87 -0
- data/lib/enclave/result.rb +29 -0
- data/lib/enclave/tool.rb +38 -0
- data/lib/enclave/version.rb +3 -0
- data/lib/enclave.rb +73 -0
- metadata +819 -0
|
@@ -0,0 +1,2302 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** array.c - Array class
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <mruby.h>
|
|
8
|
+
#include <mruby/array.h>
|
|
9
|
+
#include <mruby/class.h>
|
|
10
|
+
#include <mruby/string.h>
|
|
11
|
+
#include <mruby/range.h>
|
|
12
|
+
#include <mruby/proc.h>
|
|
13
|
+
#include <mruby/internal.h>
|
|
14
|
+
#include <mruby/presym.h>
|
|
15
|
+
#include "value_array.h"
|
|
16
|
+
|
|
17
|
+
#define ARY_DEFAULT_LEN 4
|
|
18
|
+
#define ARY_SHRINK_RATIO 5 /* must be larger than 2 */
|
|
19
|
+
#define ARY_C_MAX_SIZE (SIZE_MAX / sizeof(mrb_value))
|
|
20
|
+
#ifndef MRB_ARY_LENGTH_MAX
|
|
21
|
+
#define MRB_ARY_LENGTH_MAX 131072
|
|
22
|
+
#endif
|
|
23
|
+
#define ARY_MAX_SIZE ((mrb_int)((ARY_C_MAX_SIZE < (size_t)MRB_INT_MAX) ? ARY_C_MAX_SIZE : MRB_INT_MAX-1))
|
|
24
|
+
|
|
25
|
+
/* Raises an ArgumentError when array size exceeds limits */
|
|
26
|
+
static void
|
|
27
|
+
ary_too_big(mrb_state *mrb)
|
|
28
|
+
{
|
|
29
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Checks if array size would exceed limits and raises error if so */
|
|
33
|
+
static inline void
|
|
34
|
+
ary_check_too_big(mrb_state *mrb, mrb_int a, mrb_int b)
|
|
35
|
+
{
|
|
36
|
+
if (a > ARY_MAX_SIZE - b || a < 0)
|
|
37
|
+
ary_too_big(mrb);
|
|
38
|
+
#if MRB_ARY_LENGTH_MAX != 0
|
|
39
|
+
if (a > MRB_ARY_LENGTH_MAX - b || a < 0)
|
|
40
|
+
ary_too_big(mrb);
|
|
41
|
+
#endif
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Creates a new RArray with specified capacity */
|
|
45
|
+
static struct RArray*
|
|
46
|
+
ary_new_capa(mrb_state *mrb, mrb_int capa)
|
|
47
|
+
{
|
|
48
|
+
ary_check_too_big(mrb, capa, 0);
|
|
49
|
+
|
|
50
|
+
size_t blen = capa * sizeof(mrb_value);
|
|
51
|
+
struct RArray *a = MRB_OBJ_ALLOC(mrb, MRB_TT_ARRAY, mrb->array_class);
|
|
52
|
+
|
|
53
|
+
if (capa <= MRB_ARY_EMBED_LEN_MAX) {
|
|
54
|
+
ARY_SET_EMBED_LEN(a, 0);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
a->as.heap.ptr = (mrb_value *)mrb_malloc(mrb, blen);
|
|
58
|
+
a->as.heap.aux.capa = capa;
|
|
59
|
+
a->as.heap.len = 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return a;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new array with a specified initial capacity.
|
|
67
|
+
*
|
|
68
|
+
* This function allocates an array that can hold at least `capa` elements
|
|
69
|
+
* without needing to immediately reallocate memory. If `capa` is 0,
|
|
70
|
+
* it may still allocate a small default capacity.
|
|
71
|
+
*
|
|
72
|
+
* @param mrb The mruby state.
|
|
73
|
+
* @param capa The initial capacity desired for the array.
|
|
74
|
+
* @return A new mrb_value representing the created array.
|
|
75
|
+
*/
|
|
76
|
+
MRB_API mrb_value
|
|
77
|
+
mrb_ary_new_capa(mrb_state *mrb, mrb_int capa)
|
|
78
|
+
{
|
|
79
|
+
struct RArray *a = ary_new_capa(mrb, capa);
|
|
80
|
+
return mrb_obj_value(a);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new, empty array.
|
|
85
|
+
*
|
|
86
|
+
* This function is equivalent to calling `mrb_ary_new_capa` with a capacity of 0.
|
|
87
|
+
* The array will dynamically resize as elements are added.
|
|
88
|
+
*
|
|
89
|
+
* @param mrb The mruby state.
|
|
90
|
+
* @return A new mrb_value representing the created empty array.
|
|
91
|
+
*/
|
|
92
|
+
MRB_API mrb_value
|
|
93
|
+
mrb_ary_new(mrb_state *mrb)
|
|
94
|
+
{
|
|
95
|
+
return mrb_ary_new_capa(mrb, 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* To copy array, use this instead of memcpy because of portability
|
|
100
|
+
* * gcc on ARM may fail optimization of memcpy
|
|
101
|
+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56620
|
|
102
|
+
* * gcc on MIPS also fail
|
|
103
|
+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39755
|
|
104
|
+
* * memcpy doesn't exist on freestanding environment
|
|
105
|
+
*
|
|
106
|
+
* If you optimize for binary size, use memcpy instead of this at your own risk
|
|
107
|
+
* of above portability issue.
|
|
108
|
+
*
|
|
109
|
+
* See also https://togetter.com/li/462898 (Japanese)
|
|
110
|
+
*/
|
|
111
|
+
/* Portable array copy function to avoid memcpy issues on some platforms */
|
|
112
|
+
static inline void
|
|
113
|
+
array_copy(mrb_value *dst, const mrb_value *src, mrb_int size)
|
|
114
|
+
{
|
|
115
|
+
for (mrb_int i = 0; i < size; i++) {
|
|
116
|
+
dst[i] = src[i];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Creates a new RArray initialized with values from an array */
|
|
121
|
+
static struct RArray*
|
|
122
|
+
ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals)
|
|
123
|
+
{
|
|
124
|
+
struct RArray *a = ary_new_capa(mrb, size);
|
|
125
|
+
|
|
126
|
+
array_copy(ARY_PTR(a), vals, size);
|
|
127
|
+
ARY_SET_LEN(a, size);
|
|
128
|
+
|
|
129
|
+
return a;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new array initialized with a given sequence of values.
|
|
134
|
+
*
|
|
135
|
+
* This function allocates an array and copies `size` elements from the `vals`
|
|
136
|
+
* pointer into the new array.
|
|
137
|
+
*
|
|
138
|
+
* @param mrb The mruby state.
|
|
139
|
+
* @param size The number of values to initialize the array with.
|
|
140
|
+
* @param vals A pointer to an array of `mrb_value`s to copy into the new array.
|
|
141
|
+
* @return A new mrb_value representing the created array.
|
|
142
|
+
*/
|
|
143
|
+
MRB_API mrb_value
|
|
144
|
+
mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals)
|
|
145
|
+
{
|
|
146
|
+
struct RArray *a = ary_new_from_values(mrb, size, vals);
|
|
147
|
+
return mrb_obj_value(a);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new array of size 2, typically used to represent an association (key-value pair).
|
|
152
|
+
*
|
|
153
|
+
* The first element of the array is `car` (often the key), and the second element
|
|
154
|
+
* is `cdr` (often the value).
|
|
155
|
+
*
|
|
156
|
+
* @param mrb The mruby state.
|
|
157
|
+
* @param car The first value to be placed in the array.
|
|
158
|
+
* @param cdr The second value to be placed in the array.
|
|
159
|
+
* @return A new mrb_value representing the created 2-element array.
|
|
160
|
+
*/
|
|
161
|
+
MRB_API mrb_value
|
|
162
|
+
mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr)
|
|
163
|
+
{
|
|
164
|
+
struct RArray *a = ary_new_capa(mrb, 2);
|
|
165
|
+
mrb_value *p = ARY_PTR(a);
|
|
166
|
+
|
|
167
|
+
p[0] = car;
|
|
168
|
+
p[1] = cdr;
|
|
169
|
+
ARY_SET_LEN(a, 2);
|
|
170
|
+
return mrb_obj_value(a);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Fills array elements with nil values */
|
|
174
|
+
static void
|
|
175
|
+
ary_fill_with_nil(mrb_value *ptr, mrb_int size)
|
|
176
|
+
{
|
|
177
|
+
mrb_value nil = mrb_nil_value();
|
|
178
|
+
|
|
179
|
+
while (size--) {
|
|
180
|
+
*ptr++ = nil;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#define ary_modify_check(mrb, a) mrb_check_frozen((mrb), (a))
|
|
185
|
+
|
|
186
|
+
/* Prepares array for modification, handling shared arrays and frozen check */
|
|
187
|
+
static void
|
|
188
|
+
ary_modify(mrb_state *mrb, struct RArray *a)
|
|
189
|
+
{
|
|
190
|
+
ary_modify_check(mrb, a);
|
|
191
|
+
|
|
192
|
+
if (ARY_SHARED_P(a)) {
|
|
193
|
+
mrb_shared_array *shared = a->as.heap.aux.shared;
|
|
194
|
+
|
|
195
|
+
if (shared->refcnt == 1 && a->as.heap.ptr == shared->ptr) {
|
|
196
|
+
a->as.heap.ptr = shared->ptr;
|
|
197
|
+
a->as.heap.aux.capa = a->as.heap.len;
|
|
198
|
+
mrb_free(mrb, shared);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
mrb_value *p = a->as.heap.ptr;
|
|
202
|
+
mrb_value *ptr = (mrb_value*)mrb_malloc(mrb, a->as.heap.len * sizeof(mrb_value));
|
|
203
|
+
|
|
204
|
+
if (p) {
|
|
205
|
+
array_copy(ptr, p, a->as.heap.len);
|
|
206
|
+
}
|
|
207
|
+
a->as.heap.ptr = ptr;
|
|
208
|
+
a->as.heap.aux.capa = a->as.heap.len;
|
|
209
|
+
mrb_ary_decref(mrb, shared);
|
|
210
|
+
}
|
|
211
|
+
ARY_UNSET_SHARED_FLAG(a);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Prepares an array for modification.
|
|
217
|
+
*
|
|
218
|
+
* This function ensures that the array is not frozen and is not shared.
|
|
219
|
+
* If the array is shared and has multiple references, this function will
|
|
220
|
+
* duplicate the array data to ensure that modifications do not affect
|
|
221
|
+
* other references. It also triggers a write barrier for the garbage collector.
|
|
222
|
+
*
|
|
223
|
+
* @param mrb The mruby state.
|
|
224
|
+
* @param a A pointer to the RArray structure to modify.
|
|
225
|
+
*/
|
|
226
|
+
MRB_API void
|
|
227
|
+
mrb_ary_modify(mrb_state *mrb, struct RArray* a)
|
|
228
|
+
{
|
|
229
|
+
mrb_write_barrier(mrb, (struct RBasic*)a);
|
|
230
|
+
ary_modify(mrb, a);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* Converts array to shared representation for copy-on-write semantics */
|
|
234
|
+
static void
|
|
235
|
+
ary_make_shared(mrb_state *mrb, struct RArray *a)
|
|
236
|
+
{
|
|
237
|
+
if (!ARY_SHARED_P(a) && !ARY_EMBED_P(a)) {
|
|
238
|
+
mrb_shared_array *shared = (mrb_shared_array*)mrb_malloc(mrb, sizeof(mrb_shared_array));
|
|
239
|
+
mrb_value *ptr = a->as.heap.ptr;
|
|
240
|
+
mrb_int len = a->as.heap.len;
|
|
241
|
+
|
|
242
|
+
shared->refcnt = 1;
|
|
243
|
+
if (a->as.heap.aux.capa > len) {
|
|
244
|
+
a->as.heap.ptr = shared->ptr = (mrb_value*)mrb_realloc(mrb, ptr, sizeof(mrb_value)*len+1);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
shared->ptr = ptr;
|
|
248
|
+
}
|
|
249
|
+
shared->len = len;
|
|
250
|
+
a->as.heap.aux.shared = shared;
|
|
251
|
+
ARY_SET_SHARED_FLAG(a);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* Creates a shared copy of array for temporary GC protection.
|
|
256
|
+
* Frozen arrays are returned as-is (cannot be modified).
|
|
257
|
+
* Embedded arrays get full copy (cannot be shared).
|
|
258
|
+
* Heap arrays get zero-copy shared reference.
|
|
259
|
+
*/
|
|
260
|
+
MRB_API mrb_value
|
|
261
|
+
mrb_ary_make_shared_copy(mrb_state *mrb, mrb_value ary)
|
|
262
|
+
{
|
|
263
|
+
struct RArray *orig = mrb_ary_ptr(ary);
|
|
264
|
+
|
|
265
|
+
// Frozen arrays don't need protection
|
|
266
|
+
if (mrb_frozen_p(orig)) {
|
|
267
|
+
return ary;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Embedded arrays can't be shared - make full copy
|
|
271
|
+
if (ARY_EMBED_P(orig)) {
|
|
272
|
+
return mrb_ary_dup(mrb, ary);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Make original array shared if not already
|
|
276
|
+
if (!ARY_SHARED_P(orig)) {
|
|
277
|
+
ary_make_shared(mrb, orig);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Create new array that shares the buffer
|
|
281
|
+
struct RArray *shared = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
|
|
282
|
+
|
|
283
|
+
shared->as.heap.ptr = orig->as.heap.ptr;
|
|
284
|
+
shared->as.heap.len = orig->as.heap.len;
|
|
285
|
+
shared->as.heap.aux.shared = orig->as.heap.aux.shared;
|
|
286
|
+
shared->as.heap.aux.shared->refcnt++;
|
|
287
|
+
ARY_SET_SHARED_FLAG(shared);
|
|
288
|
+
mrb_write_barrier(mrb, (struct RBasic*)shared);
|
|
289
|
+
|
|
290
|
+
return mrb_obj_value(shared);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* Expands array capacity to accommodate at least len elements */
|
|
294
|
+
static void
|
|
295
|
+
ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len)
|
|
296
|
+
{
|
|
297
|
+
mrb_int capa = ARY_CAPA(a);
|
|
298
|
+
|
|
299
|
+
ary_check_too_big(mrb, len, 0);
|
|
300
|
+
if (capa < ARY_DEFAULT_LEN) {
|
|
301
|
+
capa = ARY_DEFAULT_LEN;
|
|
302
|
+
}
|
|
303
|
+
while (capa < len) {
|
|
304
|
+
if (capa <= ARY_MAX_SIZE / 2) {
|
|
305
|
+
capa *= 2;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
capa = len;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (capa > ARY_MAX_SIZE) {
|
|
312
|
+
ary_too_big(mrb);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (ARY_EMBED_P(a)) {
|
|
316
|
+
mrb_value *ptr = ARY_EMBED_PTR(a);
|
|
317
|
+
mrb_int slen = ARY_EMBED_LEN(a);
|
|
318
|
+
mrb_value *expanded_ptr = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value)*capa);
|
|
319
|
+
|
|
320
|
+
ARY_UNSET_EMBED_FLAG(a);
|
|
321
|
+
array_copy(expanded_ptr, ptr, slen);
|
|
322
|
+
a->as.heap.len = slen;
|
|
323
|
+
a->as.heap.aux.capa = capa;
|
|
324
|
+
a->as.heap.ptr = expanded_ptr;
|
|
325
|
+
}
|
|
326
|
+
else if (capa > a->as.heap.aux.capa) {
|
|
327
|
+
mrb_value *expanded_ptr = (mrb_value*)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa);
|
|
328
|
+
|
|
329
|
+
a->as.heap.aux.capa = capa;
|
|
330
|
+
a->as.heap.ptr = expanded_ptr;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/* Shrinks array capacity to save memory when array becomes much smaller */
|
|
335
|
+
static void
|
|
336
|
+
ary_shrink_capa(mrb_state *mrb, struct RArray *a)
|
|
337
|
+
{
|
|
338
|
+
if (ARY_EMBED_P(a)) return;
|
|
339
|
+
|
|
340
|
+
mrb_int capa = a->as.heap.aux.capa;
|
|
341
|
+
|
|
342
|
+
if (capa < ARY_DEFAULT_LEN * 2) return;
|
|
343
|
+
if (capa <= a->as.heap.len * ARY_SHRINK_RATIO) return;
|
|
344
|
+
|
|
345
|
+
do {
|
|
346
|
+
capa /= 2;
|
|
347
|
+
if (capa < ARY_DEFAULT_LEN) {
|
|
348
|
+
capa = ARY_DEFAULT_LEN;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
} while (capa > a->as.heap.len * ARY_SHRINK_RATIO);
|
|
352
|
+
|
|
353
|
+
if (capa > a->as.heap.len && capa < a->as.heap.aux.capa) {
|
|
354
|
+
a->as.heap.aux.capa = capa;
|
|
355
|
+
a->as.heap.ptr = (mrb_value*)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Resizes an array to a new length.
|
|
361
|
+
*
|
|
362
|
+
* If `new_len` is smaller than the current length, the array is truncated.
|
|
363
|
+
* If `new_len` is larger than the current length, the array is expanded,
|
|
364
|
+
* and new elements are filled with `nil`.
|
|
365
|
+
* This function modifies the array in place.
|
|
366
|
+
*
|
|
367
|
+
* @param mrb The mruby state.
|
|
368
|
+
* @param ary The array (mrb_value) to resize.
|
|
369
|
+
* @param new_len The desired new length of the array.
|
|
370
|
+
* @return The resized array (the same mrb_value as `ary`).
|
|
371
|
+
*/
|
|
372
|
+
MRB_API mrb_value
|
|
373
|
+
mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len)
|
|
374
|
+
{
|
|
375
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
376
|
+
|
|
377
|
+
ary_modify(mrb, a);
|
|
378
|
+
mrb_int old_len = RARRAY_LEN(ary);
|
|
379
|
+
if (old_len != new_len) {
|
|
380
|
+
if (new_len < old_len) {
|
|
381
|
+
ary_shrink_capa(mrb, a);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
ary_expand_capa(mrb, a, new_len);
|
|
385
|
+
ary_fill_with_nil(ARY_PTR(a) + old_len, new_len - old_len);
|
|
386
|
+
}
|
|
387
|
+
ARY_SET_LEN(a, new_len);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return ary;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/*
|
|
394
|
+
* call-seq:
|
|
395
|
+
* Array[obj, ...] -> new_array
|
|
396
|
+
*
|
|
397
|
+
* Creates a new Array containing the given objects:
|
|
398
|
+
*
|
|
399
|
+
* Array[1, 'a', /^A/] # => [1, "a", /^A/]
|
|
400
|
+
* Array[1, 2, 3] # => [1, 2, 3]
|
|
401
|
+
* Array[] # => []
|
|
402
|
+
*/
|
|
403
|
+
static mrb_value
|
|
404
|
+
mrb_ary_s_create(mrb_state *mrb, mrb_value klass)
|
|
405
|
+
{
|
|
406
|
+
const mrb_value *vals;
|
|
407
|
+
mrb_int len;
|
|
408
|
+
|
|
409
|
+
mrb_get_args(mrb, "*!", &vals, &len);
|
|
410
|
+
mrb_value ary = mrb_ary_new_from_values(mrb, len, vals);
|
|
411
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
412
|
+
a->c = mrb_class_ptr(klass);
|
|
413
|
+
|
|
414
|
+
return ary;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
static void ary_replace(mrb_state*, struct RArray*, struct RArray*);
|
|
418
|
+
|
|
419
|
+
/*
|
|
420
|
+
* call-seq:
|
|
421
|
+
* Array.new(size=0, default=nil) -> new_array
|
|
422
|
+
* Array.new(array) -> new_array
|
|
423
|
+
* Array.new(size) {|index| ... } -> new_array
|
|
424
|
+
*
|
|
425
|
+
* Returns a new Array.
|
|
426
|
+
*
|
|
427
|
+
* With no block and no arguments, returns a new empty Array object.
|
|
428
|
+
*
|
|
429
|
+
* With no block and a single `size` argument, returns a new Array object
|
|
430
|
+
* of the given size whose elements are all `nil`:
|
|
431
|
+
*
|
|
432
|
+
* a = Array.new(3)
|
|
433
|
+
* a # => [nil, nil, nil]
|
|
434
|
+
* a.size # => 3
|
|
435
|
+
*
|
|
436
|
+
* With no block and arguments `size` and `default`, returns an Array object
|
|
437
|
+
* of the given size; each element is the same `default` object:
|
|
438
|
+
*
|
|
439
|
+
* a = Array.new(3, 'x')
|
|
440
|
+
* a # => ['x', 'x', 'x']
|
|
441
|
+
*
|
|
442
|
+
* With a block and argument `size`, returns an Array object of the given size;
|
|
443
|
+
* the block is called with each successive integer `index`;
|
|
444
|
+
* the element for that `index` is the return value from the block:
|
|
445
|
+
*
|
|
446
|
+
* a = Array.new(3) {|index| "Element #{index}" }
|
|
447
|
+
* a # => ["Element 0", "Element 1", "Element 2"]
|
|
448
|
+
*
|
|
449
|
+
* With a single Array argument `array`, returns a new Array formed from `array`:
|
|
450
|
+
*
|
|
451
|
+
* a = Array.new([:foo, 'bar', 2])
|
|
452
|
+
* a.class # => Array
|
|
453
|
+
* a # => [:foo, "bar", 2]
|
|
454
|
+
*/
|
|
455
|
+
static mrb_value
|
|
456
|
+
mrb_ary_init(mrb_state *mrb, mrb_value ary)
|
|
457
|
+
{
|
|
458
|
+
mrb_value ss = mrb_fixnum_value(0);
|
|
459
|
+
mrb_value obj = mrb_nil_value();
|
|
460
|
+
mrb_value blk = mrb_nil_value();
|
|
461
|
+
|
|
462
|
+
mrb_get_args(mrb, "|oo&", &ss, &obj, &blk);
|
|
463
|
+
|
|
464
|
+
if (mrb_array_p(ss) && mrb_nil_p(obj) && mrb_nil_p(blk)) {
|
|
465
|
+
ary_replace(mrb, mrb_ary_ptr(ary), mrb_ary_ptr(ss));
|
|
466
|
+
return ary;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
mrb_int size = mrb_as_int(mrb, ss);
|
|
470
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
471
|
+
|
|
472
|
+
if (ARY_CAPA(a) < size) {
|
|
473
|
+
ary_expand_capa(mrb, a, size);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
477
|
+
for (mrb_int i=0; i<size; i++) {
|
|
478
|
+
mrb_value val;
|
|
479
|
+
if (mrb_nil_p(blk)) {
|
|
480
|
+
val = obj;
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
val = mrb_yield(mrb, blk, mrb_fixnum_value(i));
|
|
484
|
+
}
|
|
485
|
+
mrb_ary_set(mrb, ary, i, val);
|
|
486
|
+
mrb_gc_arena_restore(mrb, ai); // for mrb_funcall
|
|
487
|
+
}
|
|
488
|
+
return ary;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/* Internal helper to concatenate two arrays */
|
|
492
|
+
static void
|
|
493
|
+
ary_concat(mrb_state *mrb, struct RArray *a, struct RArray *a2)
|
|
494
|
+
{
|
|
495
|
+
mrb_int len = ARY_LEN(a);
|
|
496
|
+
|
|
497
|
+
if (len == 0) {
|
|
498
|
+
ary_replace(mrb, a, a2);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
mrb_int len2 = ARY_LEN(a2);
|
|
503
|
+
ary_check_too_big(mrb, len2, len);
|
|
504
|
+
ary_modify(mrb, a);
|
|
505
|
+
|
|
506
|
+
mrb_int newlen = len + len2;
|
|
507
|
+
if (ARY_CAPA(a) < newlen) {
|
|
508
|
+
ary_expand_capa(mrb, a, newlen);
|
|
509
|
+
}
|
|
510
|
+
array_copy(ARY_PTR(a)+len, ARY_PTR(a2), len2);
|
|
511
|
+
mrb_write_barrier(mrb, (struct RBasic*)a);
|
|
512
|
+
ARY_SET_LEN(a, newlen);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Concatenates one array to another.
|
|
517
|
+
*
|
|
518
|
+
* Appends all elements from the `other` array to the `self` array.
|
|
519
|
+
* This function modifies the `self` array in place.
|
|
520
|
+
*
|
|
521
|
+
* @param mrb The mruby state.
|
|
522
|
+
* @param self The array (mrb_value) to which elements will be added.
|
|
523
|
+
* @param other The array (mrb_value) whose elements will be appended.
|
|
524
|
+
*/
|
|
525
|
+
MRB_API void
|
|
526
|
+
mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other)
|
|
527
|
+
{
|
|
528
|
+
struct RArray *a2 = mrb_ary_ptr(other);
|
|
529
|
+
|
|
530
|
+
ary_concat(mrb, mrb_ary_ptr(self), a2);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/*
|
|
534
|
+
* call-seq:
|
|
535
|
+
* array.concat(*other_arrays) -> self
|
|
536
|
+
*
|
|
537
|
+
* Adds to `array` all elements from each \Array in `other_arrays`; returns `self`:
|
|
538
|
+
*
|
|
539
|
+
* a = [0, 1]
|
|
540
|
+
* a.concat([2, 3], [4, 5]) # => [0, 1, 2, 3, 4, 5]
|
|
541
|
+
*/
|
|
542
|
+
|
|
543
|
+
static mrb_value
|
|
544
|
+
mrb_ary_concat_m(mrb_state *mrb, mrb_value self)
|
|
545
|
+
{
|
|
546
|
+
mrb_value *args;
|
|
547
|
+
mrb_int len;
|
|
548
|
+
|
|
549
|
+
mrb_get_args(mrb, "*!", &args, &len);
|
|
550
|
+
for (int i=0; i<len; i++) {
|
|
551
|
+
mrb_ensure_array_type(mrb, args[i]);
|
|
552
|
+
}
|
|
553
|
+
for (int i=0; i<len; i++) {
|
|
554
|
+
mrb_ary_concat(mrb, self, args[i]);
|
|
555
|
+
}
|
|
556
|
+
return self;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/*
|
|
560
|
+
* call-seq:
|
|
561
|
+
* array + other_array -> new_array
|
|
562
|
+
*
|
|
563
|
+
* Returns a new Array containing all elements of `array`
|
|
564
|
+
* followed by all elements of `other_array`:
|
|
565
|
+
*
|
|
566
|
+
* a = [0, 1] + [2, 3]
|
|
567
|
+
* a # => [0, 1, 2, 3]
|
|
568
|
+
*/
|
|
569
|
+
static mrb_value
|
|
570
|
+
mrb_ary_plus(mrb_state *mrb, mrb_value self)
|
|
571
|
+
{
|
|
572
|
+
struct RArray *a1 = mrb_ary_ptr(self);
|
|
573
|
+
const mrb_value *ptr;
|
|
574
|
+
mrb_int blen;
|
|
575
|
+
|
|
576
|
+
mrb_get_args(mrb, "a", &ptr, &blen);
|
|
577
|
+
ary_check_too_big(mrb, ARY_LEN(a1), blen);
|
|
578
|
+
mrb_int len1 = ARY_LEN(a1);
|
|
579
|
+
struct RArray *a2 = ary_new_capa(mrb, len1 + blen);
|
|
580
|
+
array_copy(ARY_PTR(a2), ARY_PTR(a1), len1);
|
|
581
|
+
array_copy(ARY_PTR(a2) + len1, ptr, blen);
|
|
582
|
+
ARY_SET_LEN(a2, len1+blen);
|
|
583
|
+
|
|
584
|
+
return mrb_obj_value(a2);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
#define ARY_REPLACE_SHARED_MIN 20
|
|
588
|
+
|
|
589
|
+
/* Internal helper to replace array contents with another array */
|
|
590
|
+
static void
|
|
591
|
+
ary_replace(mrb_state *mrb, struct RArray *a, struct RArray *b)
|
|
592
|
+
{
|
|
593
|
+
mrb_int len = ARY_LEN(b);
|
|
594
|
+
|
|
595
|
+
ary_modify_check(mrb, a);
|
|
596
|
+
if (a == b) return;
|
|
597
|
+
if (ARY_SHARED_P(a)) {
|
|
598
|
+
mrb_ary_decref(mrb, a->as.heap.aux.shared);
|
|
599
|
+
a->as.heap.aux.capa = 0;
|
|
600
|
+
a->as.heap.len = 0;
|
|
601
|
+
a->as.heap.ptr = NULL;
|
|
602
|
+
ARY_UNSET_SHARED_FLAG(a);
|
|
603
|
+
}
|
|
604
|
+
if (ARY_SHARED_P(b)) {
|
|
605
|
+
shared_b:
|
|
606
|
+
if (ARY_EMBED_P(a)) {
|
|
607
|
+
ARY_UNSET_EMBED_FLAG(a);
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
mrb_free(mrb, a->as.heap.ptr);
|
|
611
|
+
}
|
|
612
|
+
a->as.heap.ptr = b->as.heap.ptr;
|
|
613
|
+
a->as.heap.len = len;
|
|
614
|
+
a->as.heap.aux.shared = b->as.heap.aux.shared;
|
|
615
|
+
a->as.heap.aux.shared->refcnt++;
|
|
616
|
+
ARY_SET_SHARED_FLAG(a);
|
|
617
|
+
mrb_write_barrier(mrb, (struct RBasic*)a);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (!mrb_frozen_p(b) && len > ARY_REPLACE_SHARED_MIN) {
|
|
621
|
+
ary_make_shared(mrb, b);
|
|
622
|
+
goto shared_b;
|
|
623
|
+
}
|
|
624
|
+
if (ARY_CAPA(a) < len)
|
|
625
|
+
ary_expand_capa(mrb, a, len);
|
|
626
|
+
array_copy(ARY_PTR(a), ARY_PTR(b), len);
|
|
627
|
+
mrb_write_barrier(mrb, (struct RBasic*)a);
|
|
628
|
+
ARY_SET_LEN(a, len);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Replaces the contents of an array with the contents of another array.
|
|
633
|
+
*
|
|
634
|
+
* After this operation, the `self` array will contain the same elements
|
|
635
|
+
* as the `other` array. This function modifies the `self` array in place.
|
|
636
|
+
*
|
|
637
|
+
* @param mrb The mruby state.
|
|
638
|
+
* @param self The array (mrb_value) whose contents will be replaced.
|
|
639
|
+
* @param other The array (mrb_value) from which to copy the elements.
|
|
640
|
+
*/
|
|
641
|
+
MRB_API void
|
|
642
|
+
mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other)
|
|
643
|
+
{
|
|
644
|
+
struct RArray *a1 = mrb_ary_ptr(self);
|
|
645
|
+
struct RArray *a2 = mrb_ary_ptr(other);
|
|
646
|
+
|
|
647
|
+
if (a1 != a2) {
|
|
648
|
+
ary_replace(mrb, a1, a2);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/*
|
|
653
|
+
* call-seq:
|
|
654
|
+
* array.replace(other_array) -> self
|
|
655
|
+
* array.initialize_copy(other_array) -> self
|
|
656
|
+
*
|
|
657
|
+
* Replaces the contents of `self` with the contents of `other_array`;
|
|
658
|
+
* returns `self`:
|
|
659
|
+
*
|
|
660
|
+
* a = [0, 1, 2]
|
|
661
|
+
* a.replace(['foo', 'bar']) # => ["foo", "bar"]
|
|
662
|
+
* a # => ["foo", "bar"]
|
|
663
|
+
*/
|
|
664
|
+
static mrb_value
|
|
665
|
+
mrb_ary_replace_m(mrb_state *mrb, mrb_value self)
|
|
666
|
+
{
|
|
667
|
+
mrb_value other;
|
|
668
|
+
|
|
669
|
+
mrb_get_args(mrb, "A", &other);
|
|
670
|
+
mrb_ary_replace(mrb, self, other);
|
|
671
|
+
|
|
672
|
+
return self;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/*
|
|
676
|
+
* call-seq:
|
|
677
|
+
* array * int -> new_array
|
|
678
|
+
* array * str -> new_string
|
|
679
|
+
*
|
|
680
|
+
* When the argument is an Integer `n`,
|
|
681
|
+
* returns a new Array built by concatenating `n` copies of `self`:
|
|
682
|
+
*
|
|
683
|
+
* a = ['x', 'y']
|
|
684
|
+
* a * 3 # => ["x", "y", "x", "y", "x", "y"]
|
|
685
|
+
*
|
|
686
|
+
* When the argument is a String `separator`,
|
|
687
|
+
* equivalent to `array.join(separator)`:
|
|
688
|
+
*
|
|
689
|
+
* [1, 2, 3] * '|' # => "1|2|3"
|
|
690
|
+
*/
|
|
691
|
+
static mrb_value
|
|
692
|
+
mrb_ary_times(mrb_state *mrb, mrb_value self)
|
|
693
|
+
{
|
|
694
|
+
struct RArray *a1 = mrb_ary_ptr(self);
|
|
695
|
+
|
|
696
|
+
mrb_value arg = mrb_get_arg1(mrb);
|
|
697
|
+
mrb_value tmp = mrb_check_string_type(mrb, arg);
|
|
698
|
+
if (!mrb_nil_p(tmp)) {
|
|
699
|
+
return mrb_ary_join(mrb, self, tmp);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
mrb_int times = mrb_as_int(mrb, arg);
|
|
703
|
+
if (times < 0) {
|
|
704
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argument");
|
|
705
|
+
}
|
|
706
|
+
if (times == 0) return mrb_ary_new(mrb);
|
|
707
|
+
if (ARY_MAX_SIZE / times < ARY_LEN(a1)) {
|
|
708
|
+
ary_too_big(mrb);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
mrb_int len1 = ARY_LEN(a1);
|
|
712
|
+
struct RArray *a2 = ary_new_capa(mrb, len1 * times);
|
|
713
|
+
ARY_SET_LEN(a2, len1 * times);
|
|
714
|
+
|
|
715
|
+
mrb_value *ptr = ARY_PTR(a2);
|
|
716
|
+
while (times--) {
|
|
717
|
+
array_copy(ptr, ARY_PTR(a1), len1);
|
|
718
|
+
ptr += len1;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return mrb_obj_value(a2);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/*
|
|
725
|
+
* call-seq:
|
|
726
|
+
* array.reverse! -> self
|
|
727
|
+
*
|
|
728
|
+
* Reverses `self` in place:
|
|
729
|
+
*
|
|
730
|
+
* a = ['foo', 'bar', 'two']
|
|
731
|
+
* a.reverse! # => ["two", "bar", "foo"]
|
|
732
|
+
* a # => ["two", "bar", "foo"]
|
|
733
|
+
*/
|
|
734
|
+
static mrb_value
|
|
735
|
+
mrb_ary_reverse_bang(mrb_state *mrb, mrb_value self)
|
|
736
|
+
{
|
|
737
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
738
|
+
mrb_int len = ARY_LEN(a);
|
|
739
|
+
|
|
740
|
+
if (len > 1) {
|
|
741
|
+
ary_modify(mrb, a);
|
|
742
|
+
|
|
743
|
+
mrb_value *p1 = ARY_PTR(a);
|
|
744
|
+
mrb_value *p2 = p1 + len - 1;
|
|
745
|
+
|
|
746
|
+
while (p1 < p2) {
|
|
747
|
+
mrb_value tmp = *p1;
|
|
748
|
+
*p1++ = *p2;
|
|
749
|
+
*p2-- = tmp;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return self;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/*
|
|
756
|
+
* call-seq:
|
|
757
|
+
* array.reverse -> new_array
|
|
758
|
+
*
|
|
759
|
+
* Returns a new Array with the elements of `self` in reverse order:
|
|
760
|
+
*
|
|
761
|
+
* a = ['foo', 'bar', 'two']
|
|
762
|
+
* a1 = a.reverse
|
|
763
|
+
* a1 # => ["two", "bar", "foo"]
|
|
764
|
+
* a # => ["foo", "bar", "two"]
|
|
765
|
+
*/
|
|
766
|
+
static mrb_value
|
|
767
|
+
mrb_ary_reverse(mrb_state *mrb, mrb_value self)
|
|
768
|
+
{
|
|
769
|
+
struct RArray *a = mrb_ary_ptr(self), *b = ary_new_capa(mrb, ARY_LEN(a));
|
|
770
|
+
mrb_int len = ARY_LEN(a);
|
|
771
|
+
|
|
772
|
+
if (len > 0) {
|
|
773
|
+
mrb_value *p1 = ARY_PTR(a);
|
|
774
|
+
mrb_value *e = p1 + len;
|
|
775
|
+
mrb_value *p2 = ARY_PTR(b) + len - 1;
|
|
776
|
+
while (p1 < e) {
|
|
777
|
+
*p2-- = *p1++;
|
|
778
|
+
}
|
|
779
|
+
ARY_SET_LEN(b, len);
|
|
780
|
+
}
|
|
781
|
+
return mrb_obj_value(b);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Pushes an element onto the end of an array.
|
|
786
|
+
*
|
|
787
|
+
* This function appends `elem` to the `ary` array, increasing its length by one.
|
|
788
|
+
* The array capacity may be expanded if necessary.
|
|
789
|
+
* This function modifies the array in place.
|
|
790
|
+
*
|
|
791
|
+
* @param mrb The mruby state.
|
|
792
|
+
* @param ary The array (mrb_value) to push the element onto.
|
|
793
|
+
* @param elem The mrb_value to append to the array.
|
|
794
|
+
*/
|
|
795
|
+
MRB_API void
|
|
796
|
+
mrb_ary_push(mrb_state *mrb, mrb_value ary, mrb_value elem)
|
|
797
|
+
{
|
|
798
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
799
|
+
mrb_int len = ARY_LEN(a);
|
|
800
|
+
|
|
801
|
+
ary_modify(mrb, a);
|
|
802
|
+
if (len == ARY_CAPA(a))
|
|
803
|
+
ary_expand_capa(mrb, a, len + 1);
|
|
804
|
+
ARY_PTR(a)[len] = elem;
|
|
805
|
+
ARY_SET_LEN(a, len+1);
|
|
806
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, elem);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/*
|
|
810
|
+
* call-seq:
|
|
811
|
+
* array.push(*objects) -> self
|
|
812
|
+
* array << object -> self
|
|
813
|
+
*
|
|
814
|
+
* Appends trailing elements.
|
|
815
|
+
*
|
|
816
|
+
* Appends each argument in `objects` to `self`; returns `self`:
|
|
817
|
+
*
|
|
818
|
+
* a = [:foo, 'bar', 2]
|
|
819
|
+
* a.push(:baz, :bat) # => [:foo, "bar", 2, :baz, :bat]
|
|
820
|
+
*
|
|
821
|
+
* Appends `object` to `self`; returns `self`:
|
|
822
|
+
*
|
|
823
|
+
* a = [:foo, 'bar', 2]
|
|
824
|
+
* a << :baz # => [:foo, "bar", 2, :baz]
|
|
825
|
+
*/
|
|
826
|
+
static mrb_value
|
|
827
|
+
mrb_ary_push_m(mrb_state *mrb, mrb_value self)
|
|
828
|
+
{
|
|
829
|
+
mrb_int argc = mrb_get_argc(mrb);
|
|
830
|
+
if (argc == 1) {
|
|
831
|
+
mrb_ary_push(mrb, self, mrb_get_argv(mrb)[0]);
|
|
832
|
+
return self;
|
|
833
|
+
}
|
|
834
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
835
|
+
mrb_int len = ARY_LEN(a);
|
|
836
|
+
mrb_int len2 = len + argc;
|
|
837
|
+
ary_modify(mrb, a);
|
|
838
|
+
if (ARY_CAPA(a) < len2) {
|
|
839
|
+
ary_expand_capa(mrb, a, len2);
|
|
840
|
+
}
|
|
841
|
+
const mrb_value *argv = mrb_get_argv(mrb);
|
|
842
|
+
array_copy(ARY_PTR(a)+len, argv, argc);
|
|
843
|
+
ARY_SET_LEN(a, len2);
|
|
844
|
+
while (argc--) {
|
|
845
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, *argv);
|
|
846
|
+
argv++;
|
|
847
|
+
}
|
|
848
|
+
return self;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Removes and returns the last element from an array.
|
|
853
|
+
*
|
|
854
|
+
* If the array is empty, returns `nil`.
|
|
855
|
+
* This function modifies the array in place.
|
|
856
|
+
*
|
|
857
|
+
* @param mrb The mruby state.
|
|
858
|
+
* @param ary The array (mrb_value) from which to pop the element.
|
|
859
|
+
* @return The last element of the array, or `nil` if the array is empty.
|
|
860
|
+
*/
|
|
861
|
+
MRB_API mrb_value
|
|
862
|
+
mrb_ary_pop(mrb_state *mrb, mrb_value ary)
|
|
863
|
+
{
|
|
864
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
865
|
+
mrb_int len = ARY_LEN(a);
|
|
866
|
+
|
|
867
|
+
ary_modify_check(mrb, a);
|
|
868
|
+
if (len == 0) return mrb_nil_value();
|
|
869
|
+
ARY_SET_LEN(a, len-1);
|
|
870
|
+
return ARY_PTR(a)[len-1];
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
#define ARY_SHIFT_SHARED_MIN 10
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Removes and returns the first element from an array.
|
|
877
|
+
*
|
|
878
|
+
* If the array is empty, returns `nil`.
|
|
879
|
+
* All other elements are shifted down by one index.
|
|
880
|
+
* This function modifies the array in place.
|
|
881
|
+
*
|
|
882
|
+
* @param mrb The mruby state.
|
|
883
|
+
* @param self The array (mrb_value) from which to shift the element.
|
|
884
|
+
* @return The first element of the array, or `nil` if the array is empty.
|
|
885
|
+
*/
|
|
886
|
+
MRB_API mrb_value
|
|
887
|
+
mrb_ary_shift(mrb_state *mrb, mrb_value self)
|
|
888
|
+
{
|
|
889
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
890
|
+
mrb_int len = ARY_LEN(a);
|
|
891
|
+
|
|
892
|
+
ary_modify_check(mrb, a);
|
|
893
|
+
if (len == 0) return mrb_nil_value();
|
|
894
|
+
if (ARY_SHARED_P(a)) {
|
|
895
|
+
L_SHIFT:
|
|
896
|
+
a->as.heap.ptr++;
|
|
897
|
+
a->as.heap.len--;
|
|
898
|
+
return a->as.heap.ptr[-1];
|
|
899
|
+
}
|
|
900
|
+
else if (len > ARY_SHIFT_SHARED_MIN) {
|
|
901
|
+
ary_make_shared(mrb, a);
|
|
902
|
+
goto L_SHIFT;
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
mrb_value *ptr = ARY_PTR(a);
|
|
906
|
+
mrb_int size = len;
|
|
907
|
+
mrb_value val = *ptr;
|
|
908
|
+
|
|
909
|
+
while (--size) {
|
|
910
|
+
*ptr = *(ptr+1);
|
|
911
|
+
ptr++;
|
|
912
|
+
}
|
|
913
|
+
ARY_SET_LEN(a, len-1);
|
|
914
|
+
return val;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/*
|
|
919
|
+
* call-seq:
|
|
920
|
+
* array.shift -> object or nil
|
|
921
|
+
* array.shift(n) -> new_array
|
|
922
|
+
*
|
|
923
|
+
* Removes and returns leading elements.
|
|
924
|
+
*
|
|
925
|
+
* When no argument is given, removes and returns the first element:
|
|
926
|
+
*
|
|
927
|
+
* a = [:foo, 'bar', 2]
|
|
928
|
+
* a.shift # => :foo
|
|
929
|
+
* a # => ["bar", 2]
|
|
930
|
+
*
|
|
931
|
+
* Returns `nil` if `self` is empty.
|
|
932
|
+
*
|
|
933
|
+
* When argument `n` is given, removes and returns the first `n` elements in a new Array:
|
|
934
|
+
*
|
|
935
|
+
* a = [:foo, 'bar', 2]
|
|
936
|
+
* a.shift(2) # => [:foo, "bar"]
|
|
937
|
+
* a # => [2]
|
|
938
|
+
*/
|
|
939
|
+
static mrb_value
|
|
940
|
+
mrb_ary_shift_m(mrb_state *mrb, mrb_value self)
|
|
941
|
+
{
|
|
942
|
+
|
|
943
|
+
if (mrb_get_argc(mrb) == 0) {
|
|
944
|
+
return mrb_ary_shift(mrb, self);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
mrb_int n = mrb_as_int(mrb, mrb_get_arg1(mrb));
|
|
948
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
949
|
+
mrb_int len = ARY_LEN(a);
|
|
950
|
+
|
|
951
|
+
ary_modify_check(mrb, a);
|
|
952
|
+
if (len == 0 || n == 0) return mrb_ary_new(mrb);
|
|
953
|
+
if (n < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array shift");
|
|
954
|
+
if (n > len) n = len;
|
|
955
|
+
mrb_value val = mrb_ary_new_from_values(mrb, n, ARY_PTR(a));
|
|
956
|
+
if (ARY_SHARED_P(a)) {
|
|
957
|
+
L_SHIFT:
|
|
958
|
+
a->as.heap.ptr+=n;
|
|
959
|
+
a->as.heap.len-=n;
|
|
960
|
+
return val;
|
|
961
|
+
}
|
|
962
|
+
if (len > ARY_SHIFT_SHARED_MIN) {
|
|
963
|
+
ary_make_shared(mrb, a);
|
|
964
|
+
goto L_SHIFT;
|
|
965
|
+
}
|
|
966
|
+
else if (len == n) {
|
|
967
|
+
ARY_SET_LEN(a, 0);
|
|
968
|
+
}
|
|
969
|
+
else {
|
|
970
|
+
mrb_value *ptr = ARY_PTR(a);
|
|
971
|
+
mrb_int size = len-n;
|
|
972
|
+
|
|
973
|
+
while (size--) {
|
|
974
|
+
*ptr = *(ptr+n);
|
|
975
|
+
ptr++;
|
|
976
|
+
}
|
|
977
|
+
ARY_SET_LEN(a, len-n);
|
|
978
|
+
}
|
|
979
|
+
return val;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/* self = [1,2,3]
|
|
983
|
+
item = 0
|
|
984
|
+
self.unshift item
|
|
985
|
+
p self #=> [0, 1, 2, 3] */
|
|
986
|
+
/**
|
|
987
|
+
* Prepends an element to the beginning of an array.
|
|
988
|
+
*
|
|
989
|
+
* This function adds `item` to the front of the `self` array,
|
|
990
|
+
* shifting all existing elements up by one index.
|
|
991
|
+
* The array capacity may be expanded if necessary.
|
|
992
|
+
* This function modifies the array in place.
|
|
993
|
+
*
|
|
994
|
+
* @param mrb The mruby state.
|
|
995
|
+
* @param self The array (mrb_value) to unshift the element onto.
|
|
996
|
+
* @param item The mrb_value to prepend to the array.
|
|
997
|
+
* @return The modified array (the same mrb_value as `self`).
|
|
998
|
+
*/
|
|
999
|
+
MRB_API mrb_value
|
|
1000
|
+
mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item)
|
|
1001
|
+
{
|
|
1002
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1003
|
+
mrb_int len = ARY_LEN(a);
|
|
1004
|
+
|
|
1005
|
+
if (ARY_SHARED_P(a)
|
|
1006
|
+
&& a->as.heap.aux.shared->refcnt == 1 /* shared only referenced from this array */
|
|
1007
|
+
&& a->as.heap.ptr - a->as.heap.aux.shared->ptr >= 1) /* there's room for unshifted item */ {
|
|
1008
|
+
a->as.heap.ptr--;
|
|
1009
|
+
a->as.heap.ptr[0] = item;
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
mrb_value *ptr;
|
|
1013
|
+
|
|
1014
|
+
ary_modify(mrb, a);
|
|
1015
|
+
if (ARY_CAPA(a) < len + 1)
|
|
1016
|
+
ary_expand_capa(mrb, a, len + 1);
|
|
1017
|
+
ptr = ARY_PTR(a);
|
|
1018
|
+
value_move(ptr + 1, ptr, len);
|
|
1019
|
+
ptr[0] = item;
|
|
1020
|
+
}
|
|
1021
|
+
ARY_SET_LEN(a, len+1);
|
|
1022
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, item);
|
|
1023
|
+
|
|
1024
|
+
return self;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/*
|
|
1028
|
+
* call-seq:
|
|
1029
|
+
* array.unshift(*objects) -> self
|
|
1030
|
+
*
|
|
1031
|
+
* Prepends the given `objects` to `self`:
|
|
1032
|
+
*
|
|
1033
|
+
* a = [:foo, 'bar', 2]
|
|
1034
|
+
* a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
|
|
1035
|
+
*
|
|
1036
|
+
* Array#prepend is an alias for Array#unshift.
|
|
1037
|
+
*
|
|
1038
|
+
* Related: #push, #pop, #shift.
|
|
1039
|
+
*/
|
|
1040
|
+
|
|
1041
|
+
static mrb_value
|
|
1042
|
+
mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
|
|
1043
|
+
{
|
|
1044
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1045
|
+
mrb_value *ptr;
|
|
1046
|
+
|
|
1047
|
+
mrb_int alen = mrb_get_argc(mrb);
|
|
1048
|
+
|
|
1049
|
+
if (alen == 0) {
|
|
1050
|
+
ary_modify_check(mrb, a);
|
|
1051
|
+
return self;
|
|
1052
|
+
}
|
|
1053
|
+
const mrb_value *vals = mrb_get_argv(mrb);
|
|
1054
|
+
mrb_int len = ARY_LEN(a);
|
|
1055
|
+
if (alen > ARY_MAX_SIZE - len) {
|
|
1056
|
+
ary_too_big(mrb);
|
|
1057
|
+
}
|
|
1058
|
+
if (ARY_SHARED_P(a)
|
|
1059
|
+
&& a->as.heap.aux.shared->refcnt == 1 /* shared only referenced from this array */
|
|
1060
|
+
&& a->as.heap.ptr - a->as.heap.aux.shared->ptr >= alen) /* there's room for unshifted item */ {
|
|
1061
|
+
ary_modify_check(mrb, a);
|
|
1062
|
+
a->as.heap.ptr -= alen;
|
|
1063
|
+
ptr = a->as.heap.ptr;
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
mrb_bool same = vals == ARY_PTR(a);
|
|
1067
|
+
ary_modify(mrb, a);
|
|
1068
|
+
if (ARY_CAPA(a) < len + alen)
|
|
1069
|
+
ary_expand_capa(mrb, a, len + alen);
|
|
1070
|
+
ptr = ARY_PTR(a);
|
|
1071
|
+
value_move(ptr + alen, ptr, len);
|
|
1072
|
+
if (same) vals = ptr;
|
|
1073
|
+
}
|
|
1074
|
+
array_copy(ptr, vals, alen);
|
|
1075
|
+
ARY_SET_LEN(a, len+alen);
|
|
1076
|
+
while (alen--) {
|
|
1077
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, vals[alen]);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
return self;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Sets the element at a given index in an array.
|
|
1085
|
+
*
|
|
1086
|
+
* If `n` is within the current bounds of the array, the element at that index
|
|
1087
|
+
* is replaced with `val`.
|
|
1088
|
+
* If `n` is beyond the current bounds, the array is expanded to accommodate
|
|
1089
|
+
* the new element, and any intermediate elements are filled with `nil`.
|
|
1090
|
+
* If `n` is negative, it counts from the end of the array.
|
|
1091
|
+
* An IndexError is raised if a negative index points past the beginning of the array.
|
|
1092
|
+
* This function modifies the array in place.
|
|
1093
|
+
*
|
|
1094
|
+
* @param mrb The mruby state.
|
|
1095
|
+
* @param ary The array (mrb_value) to modify.
|
|
1096
|
+
* @param n The index at which to set the element.
|
|
1097
|
+
* @param val The mrb_value to set at the specified index.
|
|
1098
|
+
*/
|
|
1099
|
+
MRB_API void
|
|
1100
|
+
mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val)
|
|
1101
|
+
{
|
|
1102
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
1103
|
+
mrb_int len = ARY_LEN(a);
|
|
1104
|
+
|
|
1105
|
+
ary_modify(mrb, a);
|
|
1106
|
+
/* range check */
|
|
1107
|
+
if (n < 0) {
|
|
1108
|
+
n += len;
|
|
1109
|
+
if (n < 0) {
|
|
1110
|
+
mrb_raisef(mrb, E_INDEX_ERROR, "index %i out of array", n - len);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (n >= ARY_MAX_SIZE) {
|
|
1114
|
+
mrb_raise(mrb, E_INDEX_ERROR, "index too big");
|
|
1115
|
+
}
|
|
1116
|
+
if (len <= n) {
|
|
1117
|
+
if (ARY_CAPA(a) <= n)
|
|
1118
|
+
ary_expand_capa(mrb, a, n + 1);
|
|
1119
|
+
ary_fill_with_nil(ARY_PTR(a) + len, n + 1 - len);
|
|
1120
|
+
ARY_SET_LEN(a, n+1);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
ARY_PTR(a)[n] = val;
|
|
1124
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic*)a, val);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/* Creates a duplicate of an array */
|
|
1128
|
+
static struct RArray*
|
|
1129
|
+
ary_dup(mrb_state *mrb, struct RArray *a)
|
|
1130
|
+
{
|
|
1131
|
+
return ary_new_from_values(mrb, ARY_LEN(a), ARY_PTR(a));
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
MRB_API mrb_value
|
|
1135
|
+
mrb_ary_dup(mrb_state *mrb, mrb_value ary)
|
|
1136
|
+
{
|
|
1137
|
+
return mrb_obj_value(ary_dup(mrb, mrb_ary_ptr(ary)));
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Replaces a portion of an array with elements from another array or a single value.
|
|
1142
|
+
*
|
|
1143
|
+
* Removes `len` elements from `ary` starting at `head` index, and inserts
|
|
1144
|
+
* the elements from `rpl` (if `rpl` is an array) or `rpl` itself (if it's not an array)
|
|
1145
|
+
* at that position.
|
|
1146
|
+
* If `head` is negative, it counts from the end of the array.
|
|
1147
|
+
* If `len` is negative, an IndexError is raised.
|
|
1148
|
+
* If `rpl` is `mrb_undef_p()`, then the elements are removed without replacement.
|
|
1149
|
+
* This function modifies the `ary` array in place.
|
|
1150
|
+
*
|
|
1151
|
+
* @param mrb The mruby state.
|
|
1152
|
+
* @param ary The array (mrb_value) to modify.
|
|
1153
|
+
* @param head The starting index for the splice operation.
|
|
1154
|
+
* @param len The number of elements to remove.
|
|
1155
|
+
* @param rpl The mrb_value to insert (can be an array or a single value, or mrb_undef_p()).
|
|
1156
|
+
* @return The modified array (the same mrb_value as `ary`).
|
|
1157
|
+
*/
|
|
1158
|
+
MRB_API mrb_value
|
|
1159
|
+
mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_value rpl)
|
|
1160
|
+
{
|
|
1161
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
1162
|
+
mrb_int alen = ARY_LEN(a);
|
|
1163
|
+
const mrb_value *argv;
|
|
1164
|
+
mrb_int argc;
|
|
1165
|
+
|
|
1166
|
+
ary_modify(mrb, a);
|
|
1167
|
+
|
|
1168
|
+
/* len check */
|
|
1169
|
+
if (len < 0) mrb_raisef(mrb, E_INDEX_ERROR, "negative length (%i)", len);
|
|
1170
|
+
|
|
1171
|
+
/* range check */
|
|
1172
|
+
if (head < 0) {
|
|
1173
|
+
head += alen;
|
|
1174
|
+
if (head < 0) goto out_of_range;
|
|
1175
|
+
}
|
|
1176
|
+
if (head > ARY_MAX_SIZE - len) {
|
|
1177
|
+
out_of_range:
|
|
1178
|
+
mrb_raisef(mrb, E_INDEX_ERROR, "index %i is out of array", head);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
mrb_int tail = head + len;
|
|
1182
|
+
if (alen < len || alen < tail) {
|
|
1183
|
+
len = alen - head;
|
|
1184
|
+
tail = head + len;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/* size check */
|
|
1188
|
+
if (mrb_array_p(rpl)) {
|
|
1189
|
+
argc = RARRAY_LEN(rpl);
|
|
1190
|
+
argv = RARRAY_PTR(rpl);
|
|
1191
|
+
if (argv == ARY_PTR(a)) {
|
|
1192
|
+
struct RArray *r;
|
|
1193
|
+
|
|
1194
|
+
if (argc > 32767) {
|
|
1195
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "too big recursive splice");
|
|
1196
|
+
}
|
|
1197
|
+
r = ary_dup(mrb, a);
|
|
1198
|
+
argv = ARY_PTR(r);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
else if (mrb_undef_p(rpl)) {
|
|
1202
|
+
argc = 0;
|
|
1203
|
+
argv = NULL;
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
argc = 1;
|
|
1207
|
+
argv = &rpl;
|
|
1208
|
+
}
|
|
1209
|
+
if (head >= alen) {
|
|
1210
|
+
if (head > ARY_MAX_SIZE - argc) goto out_of_range;
|
|
1211
|
+
len = head + argc;
|
|
1212
|
+
if (len > ARY_CAPA(a)) {
|
|
1213
|
+
ary_expand_capa(mrb, a, len);
|
|
1214
|
+
}
|
|
1215
|
+
ary_fill_with_nil(ARY_PTR(a) + alen, head - alen);
|
|
1216
|
+
if (argc > 0) {
|
|
1217
|
+
array_copy(ARY_PTR(a) + head, argv, argc);
|
|
1218
|
+
}
|
|
1219
|
+
ARY_SET_LEN(a, len);
|
|
1220
|
+
}
|
|
1221
|
+
else {
|
|
1222
|
+
if (alen - len > ARY_MAX_SIZE - argc) {
|
|
1223
|
+
head = alen + argc - len;
|
|
1224
|
+
goto out_of_range;
|
|
1225
|
+
}
|
|
1226
|
+
mrb_int newlen = alen + argc - len;
|
|
1227
|
+
if (newlen > ARY_CAPA(a)) {
|
|
1228
|
+
ary_expand_capa(mrb, a, newlen);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if (len != argc) {
|
|
1232
|
+
mrb_value *ptr = ARY_PTR(a);
|
|
1233
|
+
value_move(ptr + head + argc, ptr + tail, alen - tail);
|
|
1234
|
+
ARY_SET_LEN(a, newlen);
|
|
1235
|
+
}
|
|
1236
|
+
if (argc > 0) {
|
|
1237
|
+
value_move(ARY_PTR(a) + head, argv, argc);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
mrb_write_barrier(mrb, (struct RBasic*)a);
|
|
1241
|
+
return ary;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
void
|
|
1245
|
+
mrb_ary_decref(mrb_state *mrb, mrb_shared_array *shared)
|
|
1246
|
+
{
|
|
1247
|
+
shared->refcnt--;
|
|
1248
|
+
if (shared->refcnt == 0) {
|
|
1249
|
+
mrb_free(mrb, shared->ptr);
|
|
1250
|
+
mrb_free(mrb, shared);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/* Creates a subsequence array, using shared storage when appropriate */
|
|
1255
|
+
static mrb_value
|
|
1256
|
+
ary_subseq(mrb_state *mrb, struct RArray *a, mrb_int beg, mrb_int len)
|
|
1257
|
+
{
|
|
1258
|
+
struct RArray *b;
|
|
1259
|
+
|
|
1260
|
+
if (!ARY_SHARED_P(a) && len <= ARY_SHIFT_SHARED_MIN) {
|
|
1261
|
+
return mrb_ary_new_from_values(mrb, len, ARY_PTR(a)+beg);
|
|
1262
|
+
}
|
|
1263
|
+
ary_make_shared(mrb, a);
|
|
1264
|
+
b = MRB_OBJ_ALLOC(mrb, MRB_TT_ARRAY, mrb->array_class);
|
|
1265
|
+
b->as.heap.ptr = a->as.heap.ptr + beg;
|
|
1266
|
+
b->as.heap.len = len;
|
|
1267
|
+
b->as.heap.aux.shared = a->as.heap.aux.shared;
|
|
1268
|
+
b->as.heap.aux.shared->refcnt++;
|
|
1269
|
+
ARY_SET_SHARED_FLAG(b);
|
|
1270
|
+
|
|
1271
|
+
return mrb_obj_value(b);
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates a new array that is a subsequence of an existing array.
|
|
1276
|
+
*
|
|
1277
|
+
* The new array contains `len` elements, starting from index `beg` of the
|
|
1278
|
+
* original `ary`.
|
|
1279
|
+
* This function attempts to create a shared array if appropriate for efficiency.
|
|
1280
|
+
*
|
|
1281
|
+
* @param mrb The mruby state.
|
|
1282
|
+
* @param ary The original array (mrb_value).
|
|
1283
|
+
* @param beg The starting index of the subsequence.
|
|
1284
|
+
* @param len The length of the subsequence.
|
|
1285
|
+
* @return A new mrb_value representing the subsequence array.
|
|
1286
|
+
*/
|
|
1287
|
+
mrb_value
|
|
1288
|
+
mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len)
|
|
1289
|
+
{
|
|
1290
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
1291
|
+
return ary_subseq(mrb, a, beg, len);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/* Converts various types to array index integer */
|
|
1295
|
+
static mrb_int
|
|
1296
|
+
aget_index(mrb_state *mrb, mrb_value index)
|
|
1297
|
+
{
|
|
1298
|
+
if (mrb_integer_p(index)) {
|
|
1299
|
+
return mrb_integer(index);
|
|
1300
|
+
}
|
|
1301
|
+
#ifndef MRB_NO_FLOAT
|
|
1302
|
+
else if (mrb_float_p(index)) {
|
|
1303
|
+
return (mrb_int)mrb_float(index);
|
|
1304
|
+
}
|
|
1305
|
+
#endif
|
|
1306
|
+
else {
|
|
1307
|
+
mrb_int i, argc;
|
|
1308
|
+
const mrb_value *argv;
|
|
1309
|
+
|
|
1310
|
+
mrb_get_args(mrb, "i*!", &i, &argv, &argc);
|
|
1311
|
+
return i;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/*
|
|
1316
|
+
* call-seq:
|
|
1317
|
+
* ary[index] -> obj or nil
|
|
1318
|
+
* ary[start, length] -> new_ary or nil
|
|
1319
|
+
* ary[range] -> new_ary or nil
|
|
1320
|
+
* ary.slice(index) -> obj or nil
|
|
1321
|
+
* ary.slice(start, length) -> new_ary or nil
|
|
1322
|
+
* ary.slice(range) -> new_ary or nil
|
|
1323
|
+
*
|
|
1324
|
+
* Element Reference --- Returns the element at `index`, or returns a
|
|
1325
|
+
* subarray starting at the `start` index and continuing for `length`
|
|
1326
|
+
* elements, or returns a subarray specified by `range` of indices.
|
|
1327
|
+
*
|
|
1328
|
+
* Negative indices count backward from the end of the array (-1 is the last
|
|
1329
|
+
* element). For `start` and `range` cases the starting index is just before
|
|
1330
|
+
* an element. Additionally, an empty array is returned when the starting
|
|
1331
|
+
* index for an element range is at the end of the array.
|
|
1332
|
+
*
|
|
1333
|
+
* Returns `nil` if the index (or starting index) are out of range.
|
|
1334
|
+
*
|
|
1335
|
+
* a = [ "a", "b", "c", "d", "e" ]
|
|
1336
|
+
* a[1] => "b"
|
|
1337
|
+
* a[1,2] => ["b", "c"]
|
|
1338
|
+
* a[1..-2] => ["b", "c", "d"]
|
|
1339
|
+
*
|
|
1340
|
+
*/
|
|
1341
|
+
|
|
1342
|
+
static mrb_value
|
|
1343
|
+
mrb_ary_aget(mrb_state *mrb, mrb_value self)
|
|
1344
|
+
{
|
|
1345
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1346
|
+
mrb_int i, len;
|
|
1347
|
+
mrb_value index;
|
|
1348
|
+
|
|
1349
|
+
if (mrb_get_argc(mrb) == 1) {
|
|
1350
|
+
index = mrb_get_arg1(mrb);
|
|
1351
|
+
switch (mrb_type(index)) {
|
|
1352
|
+
/* a[n..m] */
|
|
1353
|
+
case MRB_TT_RANGE:
|
|
1354
|
+
if (mrb_range_beg_len(mrb, index, &i, &len, ARY_LEN(a), TRUE) == MRB_RANGE_OK) {
|
|
1355
|
+
return ary_subseq(mrb, a, i, len);
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
return mrb_nil_value();
|
|
1359
|
+
}
|
|
1360
|
+
case MRB_TT_INTEGER:
|
|
1361
|
+
return mrb_ary_ref(mrb, self, mrb_integer(index));
|
|
1362
|
+
default:
|
|
1363
|
+
return mrb_ary_ref(mrb, self, aget_index(mrb, index));
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
mrb_get_args(mrb, "oi", &index, &len);
|
|
1368
|
+
i = aget_index(mrb, index);
|
|
1369
|
+
mrb_int alen = ARY_LEN(a);
|
|
1370
|
+
if (i < 0) i += alen;
|
|
1371
|
+
if (i < 0 || alen < i) return mrb_nil_value();
|
|
1372
|
+
if (len < 0) return mrb_nil_value();
|
|
1373
|
+
if (alen == i) return mrb_ary_new(mrb);
|
|
1374
|
+
if (len > alen - i) len = alen - i;
|
|
1375
|
+
|
|
1376
|
+
return ary_subseq(mrb, a, i, len);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/*
|
|
1380
|
+
* call-seq:
|
|
1381
|
+
* ary[index] = obj -> obj
|
|
1382
|
+
* ary[start, length] = obj or other_ary or nil -> obj or other_ary or nil
|
|
1383
|
+
* ary[range] = obj or other_ary or nil -> obj or other_ary or nil
|
|
1384
|
+
*
|
|
1385
|
+
* Element Assignment --- Sets the element at `index`, or replaces a subarray
|
|
1386
|
+
* from the `start` index for `length` elements, or replaces a subarray
|
|
1387
|
+
* specified by the `range` of indices.
|
|
1388
|
+
*
|
|
1389
|
+
* If indices are greater than the current capacity of the array, the array
|
|
1390
|
+
* grows automatically. Elements are inserted into the array at `start` if
|
|
1391
|
+
* `length` is zero.
|
|
1392
|
+
*
|
|
1393
|
+
* Negative indices will count backward from the end of the array. For
|
|
1394
|
+
* `start` and `range` cases the starting index is just before an element.
|
|
1395
|
+
*
|
|
1396
|
+
* An IndexError is raised if a negative index points past the beginning of
|
|
1397
|
+
* the array.
|
|
1398
|
+
*
|
|
1399
|
+
* See also Array#push, and Array#unshift.
|
|
1400
|
+
*
|
|
1401
|
+
* a = Array.new
|
|
1402
|
+
* a[4] = "4"; #=> [nil, nil, nil, nil, "4"]
|
|
1403
|
+
* a[0, 3] = [ 'a', 'b', 'c' ] #=> ["a", "b", "c", nil, "4"]
|
|
1404
|
+
* a[1..2] = [ 1, 2 ] #=> ["a", 1, 2, nil, "4"]
|
|
1405
|
+
* a[0, 2] = "?" #=> ["?", 2, nil, "4"]
|
|
1406
|
+
* a[0..2] = "A" #=> ["A", "4"]
|
|
1407
|
+
* a[-1] = "Z" #=> ["A", "Z"]
|
|
1408
|
+
* a[1..-1] = nil #=> ["A", nil]
|
|
1409
|
+
* a[1..-1] = [] #=> ["A"]
|
|
1410
|
+
* a[0, 0] = [ 1, 2 ] #=> [1, 2, "A"]
|
|
1411
|
+
* a[3, 0] = "B" #=> [1, 2, "A", "B"]
|
|
1412
|
+
*/
|
|
1413
|
+
|
|
1414
|
+
static mrb_value
|
|
1415
|
+
mrb_ary_aset(mrb_state *mrb, mrb_value self)
|
|
1416
|
+
{
|
|
1417
|
+
mrb_value v1, v2, v3;
|
|
1418
|
+
|
|
1419
|
+
if (mrb_get_argc(mrb) == 2) {
|
|
1420
|
+
mrb_int i, len;
|
|
1421
|
+
const mrb_value *vs = mrb_get_argv(mrb);
|
|
1422
|
+
v1 = vs[0]; v2 = vs[1];
|
|
1423
|
+
|
|
1424
|
+
/* a[n..m] = v */
|
|
1425
|
+
switch (mrb_range_beg_len(mrb, v1, &i, &len, RARRAY_LEN(self), FALSE)) {
|
|
1426
|
+
case MRB_RANGE_TYPE_MISMATCH:
|
|
1427
|
+
mrb_ary_set(mrb, self, aget_index(mrb, v1), v2);
|
|
1428
|
+
break;
|
|
1429
|
+
case MRB_RANGE_OK:
|
|
1430
|
+
mrb_ary_splice(mrb, self, i, len, v2);
|
|
1431
|
+
break;
|
|
1432
|
+
case MRB_RANGE_OUT:
|
|
1433
|
+
mrb_raisef(mrb, E_RANGE_ERROR, "%v out of range", v1);
|
|
1434
|
+
break;
|
|
1435
|
+
}
|
|
1436
|
+
return v2;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
mrb_get_args(mrb, "ooo", &v1, &v2, &v3);
|
|
1440
|
+
/* a[n,m] = v */
|
|
1441
|
+
mrb_ary_splice(mrb, self, aget_index(mrb, v1), aget_index(mrb, v2), v3);
|
|
1442
|
+
return v3;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
mrb_value
|
|
1446
|
+
mrb_ary_delete_at(mrb_state *mrb, mrb_value self)
|
|
1447
|
+
{
|
|
1448
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1449
|
+
|
|
1450
|
+
mrb_int index = mrb_as_int(mrb, mrb_get_arg1(mrb));
|
|
1451
|
+
mrb_int alen = ARY_LEN(a);
|
|
1452
|
+
if (index < 0) index += alen;
|
|
1453
|
+
if (index < 0 || alen <= index) return mrb_nil_value();
|
|
1454
|
+
|
|
1455
|
+
ary_modify(mrb, a);
|
|
1456
|
+
mrb_value *ptr = ARY_PTR(a);
|
|
1457
|
+
mrb_value val = ptr[index];
|
|
1458
|
+
|
|
1459
|
+
ptr += index;
|
|
1460
|
+
mrb_int len = alen - index;
|
|
1461
|
+
while (--len) {
|
|
1462
|
+
*ptr = *(ptr+1);
|
|
1463
|
+
ptr++;
|
|
1464
|
+
}
|
|
1465
|
+
ARY_SET_LEN(a, alen-1);
|
|
1466
|
+
|
|
1467
|
+
ary_shrink_capa(mrb, a);
|
|
1468
|
+
|
|
1469
|
+
return val;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/*
|
|
1473
|
+
* call-seq:
|
|
1474
|
+
* array.first -> object or nil
|
|
1475
|
+
* array.first(n) -> new_array
|
|
1476
|
+
*
|
|
1477
|
+
* Returns elements from the beginning of `self`.
|
|
1478
|
+
*
|
|
1479
|
+
* When no argument is given, returns the first element:
|
|
1480
|
+
*
|
|
1481
|
+
* a = [:foo, 'bar', 2]
|
|
1482
|
+
* a.first # => :foo
|
|
1483
|
+
* a # => [:foo, "bar", 2]
|
|
1484
|
+
*
|
|
1485
|
+
* If `self` is empty, returns `nil`.
|
|
1486
|
+
*
|
|
1487
|
+
* When non-negative Integer argument `n` is given,
|
|
1488
|
+
* returns the first `n` elements in a new Array:
|
|
1489
|
+
*
|
|
1490
|
+
* a = [:foo, 'bar', 2]
|
|
1491
|
+
* a.first(2) # => [:foo, "bar"]
|
|
1492
|
+
*/
|
|
1493
|
+
static mrb_value
|
|
1494
|
+
mrb_ary_first(mrb_state *mrb, mrb_value self)
|
|
1495
|
+
{
|
|
1496
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1497
|
+
mrb_int size;
|
|
1498
|
+
|
|
1499
|
+
if (mrb_get_argc(mrb) == 0) {
|
|
1500
|
+
if (ARY_LEN(a) > 0) return ARY_PTR(a)[0];
|
|
1501
|
+
return mrb_nil_value();
|
|
1502
|
+
}
|
|
1503
|
+
mrb_get_args(mrb, "|i", &size);
|
|
1504
|
+
if (size < 0) {
|
|
1505
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size");
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
mrb_int alen = ARY_LEN(a);
|
|
1509
|
+
if (size > alen) size = alen;
|
|
1510
|
+
if (ARY_SHARED_P(a)) {
|
|
1511
|
+
return ary_subseq(mrb, a, 0, size);
|
|
1512
|
+
}
|
|
1513
|
+
return mrb_ary_new_from_values(mrb, size, ARY_PTR(a));
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
/*
|
|
1517
|
+
* call-seq:
|
|
1518
|
+
* array.last -> object or nil
|
|
1519
|
+
* array.last(n) -> new_array
|
|
1520
|
+
*
|
|
1521
|
+
* Returns elements from the end of `self`.
|
|
1522
|
+
*
|
|
1523
|
+
* When no argument is given, returns the last element:
|
|
1524
|
+
*
|
|
1525
|
+
* a = [:foo, 'bar', 2]
|
|
1526
|
+
* a.last # => 2
|
|
1527
|
+
* a # => [:foo, "bar", 2]
|
|
1528
|
+
*
|
|
1529
|
+
* If `self` is empty, returns `nil`.
|
|
1530
|
+
*
|
|
1531
|
+
* When non-negative Integer argument `n` is given,
|
|
1532
|
+
* returns the last `n` elements in a new Array:
|
|
1533
|
+
*
|
|
1534
|
+
* a = [:foo, 'bar', 2]
|
|
1535
|
+
* a.last(2) # => ["bar", 2]
|
|
1536
|
+
*/
|
|
1537
|
+
static mrb_value
|
|
1538
|
+
mrb_ary_last(mrb_state *mrb, mrb_value self)
|
|
1539
|
+
{
|
|
1540
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1541
|
+
mrb_int alen = ARY_LEN(a);
|
|
1542
|
+
|
|
1543
|
+
if (mrb_get_argc(mrb) == 0) {
|
|
1544
|
+
if (alen > 0) return ARY_PTR(a)[alen - 1];
|
|
1545
|
+
return mrb_nil_value();
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
mrb_int size = mrb_integer(mrb_get_arg1(mrb));
|
|
1549
|
+
if (size < 0) {
|
|
1550
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size");
|
|
1551
|
+
}
|
|
1552
|
+
if (size > alen) size = alen;
|
|
1553
|
+
if (ARY_SHARED_P(a) || size > ARY_DEFAULT_LEN) {
|
|
1554
|
+
return ary_subseq(mrb, a, alen - size, size);
|
|
1555
|
+
}
|
|
1556
|
+
return mrb_ary_new_from_values(mrb, size, ARY_PTR(a) + alen - size);
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
/*
|
|
1560
|
+
* call-seq:
|
|
1561
|
+
* ary.index(val) -> int or nil
|
|
1562
|
+
* ary.index {|item| block } -> int or nil
|
|
1563
|
+
* array.index -> enumerator
|
|
1564
|
+
*
|
|
1565
|
+
* Returns the _index_ of the first object in `ary` such that the object is
|
|
1566
|
+
* `==` to `obj`.
|
|
1567
|
+
*
|
|
1568
|
+
* If a block is given instead of an argument, returns the _index_ of the
|
|
1569
|
+
* first object for which the block returns `true`. Returns `nil` if no
|
|
1570
|
+
* match is found.
|
|
1571
|
+
*
|
|
1572
|
+
* ISO 15.2.12.5.14
|
|
1573
|
+
*/
|
|
1574
|
+
static mrb_value
|
|
1575
|
+
mrb_ary_index_m(mrb_state *mrb, mrb_value self)
|
|
1576
|
+
{
|
|
1577
|
+
mrb_value obj, blk;
|
|
1578
|
+
|
|
1579
|
+
if (mrb_get_args(mrb, "|o&", &obj, &blk) == 0 && mrb_nil_p(blk)) {
|
|
1580
|
+
return mrb_funcall_id(mrb, self, MRB_SYM(to_enum), 1, mrb_symbol_value(MRB_SYM(index)));
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
if (mrb_nil_p(blk)) {
|
|
1584
|
+
for (mrb_int i = 0; i < RARRAY_LEN(self); i++) {
|
|
1585
|
+
if (mrb_equal(mrb, RARRAY_PTR(self)[i], obj)) {
|
|
1586
|
+
return mrb_int_value(mrb, i);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
else {
|
|
1591
|
+
for (mrb_int i = 0; i < RARRAY_LEN(self); i++) {
|
|
1592
|
+
mrb_value eq = mrb_yield(mrb, blk, RARRAY_PTR(self)[i]);
|
|
1593
|
+
if (mrb_test(eq)) {
|
|
1594
|
+
return mrb_int_value(mrb, i);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return mrb_nil_value();
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/*
|
|
1602
|
+
* call-seq:
|
|
1603
|
+
* ary.rindex(val) -> int or nil
|
|
1604
|
+
* ary.rindex {|item| block } -> int or nil
|
|
1605
|
+
* array.rindex -> enumerator
|
|
1606
|
+
*
|
|
1607
|
+
* Returns the _index_ of the first object in `ary` such that the object is
|
|
1608
|
+
* `==` to `obj`.
|
|
1609
|
+
*
|
|
1610
|
+
* If a block is given instead of an argument, returns the _index_ of the
|
|
1611
|
+
* first object for which the block returns `true`. Returns `nil` if no
|
|
1612
|
+
* match is found.
|
|
1613
|
+
*
|
|
1614
|
+
* ISO 15.2.12.5.26
|
|
1615
|
+
*/
|
|
1616
|
+
static mrb_value
|
|
1617
|
+
mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
|
|
1618
|
+
{
|
|
1619
|
+
mrb_value obj, blk;
|
|
1620
|
+
|
|
1621
|
+
if (mrb_get_args(mrb, "|o&", &obj, &blk) == 0 && mrb_nil_p(blk)) {
|
|
1622
|
+
return mrb_funcall_id(mrb, self, MRB_SYM(to_enum), 1, mrb_symbol_value(MRB_SYM(rindex)));
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
for (mrb_int i = RARRAY_LEN(self) - 1; i >= 0; i--) {
|
|
1626
|
+
if (mrb_nil_p(blk)) {
|
|
1627
|
+
if (mrb_equal(mrb, RARRAY_PTR(self)[i], obj)) {
|
|
1628
|
+
return mrb_int_value(mrb, i);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
mrb_value eq = mrb_yield(mrb, blk, RARRAY_PTR(self)[i]);
|
|
1633
|
+
if (mrb_test(eq)) return mrb_int_value(mrb, i);
|
|
1634
|
+
}
|
|
1635
|
+
mrb_int len = RARRAY_LEN(self);
|
|
1636
|
+
if (i > len) {
|
|
1637
|
+
i = len;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return mrb_nil_value();
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* Creates a new array from a given value, performing a "splat" operation.
|
|
1645
|
+
*
|
|
1646
|
+
* If `v` is already an array, a duplicate of `v` is returned.
|
|
1647
|
+
* If `v` responds to `to_a`, it is called, and if the result is an array,
|
|
1648
|
+
* a duplicate of that result is returned. If `to_a` returns `nil` or something
|
|
1649
|
+
* other than an array, `v` itself is wrapped in a new, single-element array.
|
|
1650
|
+
* Otherwise (if `v` is not an array and does not respond to `to_a`),
|
|
1651
|
+
* `v` itself is wrapped in a new, single-element array.
|
|
1652
|
+
*
|
|
1653
|
+
* @param mrb The mruby state.
|
|
1654
|
+
* @param v The mrb_value to convert into an array.
|
|
1655
|
+
* @return A new mrb_value representing the "splatted" array.
|
|
1656
|
+
*/
|
|
1657
|
+
MRB_API mrb_value
|
|
1658
|
+
mrb_ary_splat(mrb_state *mrb, mrb_value v)
|
|
1659
|
+
{
|
|
1660
|
+
struct RArray *a;
|
|
1661
|
+
|
|
1662
|
+
if (mrb_array_p(v)) {
|
|
1663
|
+
a = ary_dup(mrb, mrb_ary_ptr(v));
|
|
1664
|
+
return mrb_obj_value(a);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
if (!mrb_respond_to(mrb, v, MRB_SYM(to_a))) {
|
|
1668
|
+
return mrb_ary_new_from_values(mrb, 1, &v);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
mrb_value ary = mrb_funcall_argv(mrb, v, MRB_SYM(to_a), 0, NULL);
|
|
1672
|
+
if (mrb_nil_p(ary)) {
|
|
1673
|
+
return mrb_ary_new_from_values(mrb, 1, &v);
|
|
1674
|
+
}
|
|
1675
|
+
mrb_ensure_array_type(mrb, ary);
|
|
1676
|
+
a = mrb_ary_ptr(ary);
|
|
1677
|
+
a = ary_dup(mrb, a);
|
|
1678
|
+
return mrb_obj_value(a);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
/*
|
|
1682
|
+
* call-seq:
|
|
1683
|
+
* array.size -> integer
|
|
1684
|
+
* array.length -> integer
|
|
1685
|
+
*
|
|
1686
|
+
* Returns the count of elements in `self`:
|
|
1687
|
+
*
|
|
1688
|
+
* [0, 1, 2].size # => 3
|
|
1689
|
+
* [].size # => 0
|
|
1690
|
+
*/
|
|
1691
|
+
static mrb_value
|
|
1692
|
+
mrb_ary_size(mrb_state *mrb, mrb_value self)
|
|
1693
|
+
{
|
|
1694
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1695
|
+
|
|
1696
|
+
return mrb_int_value(mrb, ARY_LEN(a));
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* Removes all elements from an array, making it empty.
|
|
1701
|
+
*
|
|
1702
|
+
* This function modifies the array in place.
|
|
1703
|
+
*
|
|
1704
|
+
* @param mrb The mruby state.
|
|
1705
|
+
* @param self The array (mrb_value) to clear.
|
|
1706
|
+
* @return The cleared (now empty) array (the same mrb_value as `self`).
|
|
1707
|
+
*/
|
|
1708
|
+
MRB_API mrb_value
|
|
1709
|
+
mrb_ary_clear(mrb_state *mrb, mrb_value self)
|
|
1710
|
+
{
|
|
1711
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1712
|
+
|
|
1713
|
+
ary_modify(mrb, a);
|
|
1714
|
+
if (ARY_SHARED_P(a)) {
|
|
1715
|
+
mrb_ary_decref(mrb, a->as.heap.aux.shared);
|
|
1716
|
+
ARY_UNSET_SHARED_FLAG(a);
|
|
1717
|
+
}
|
|
1718
|
+
else if (!ARY_EMBED_P(a)){
|
|
1719
|
+
mrb_free(mrb, a->as.heap.ptr);
|
|
1720
|
+
}
|
|
1721
|
+
if (MRB_ARY_EMBED_LEN_MAX > 0) {
|
|
1722
|
+
ARY_SET_EMBED_LEN(a, 0);
|
|
1723
|
+
}
|
|
1724
|
+
else {
|
|
1725
|
+
a->as.heap.ptr = NULL;
|
|
1726
|
+
a->as.heap.aux.capa = 0;
|
|
1727
|
+
ARY_SET_LEN(a, 0);
|
|
1728
|
+
}
|
|
1729
|
+
return self;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/*
|
|
1733
|
+
* call-seq:
|
|
1734
|
+
* array.empty? -> true or false
|
|
1735
|
+
*
|
|
1736
|
+
* Returns `true` if the count of elements in `self` is zero,
|
|
1737
|
+
* `false` otherwise:
|
|
1738
|
+
*
|
|
1739
|
+
* [].empty? # => true
|
|
1740
|
+
* [0].empty? # => false
|
|
1741
|
+
*/
|
|
1742
|
+
static mrb_value
|
|
1743
|
+
mrb_ary_empty_p(mrb_state *mrb, mrb_value self)
|
|
1744
|
+
{
|
|
1745
|
+
struct RArray *a = mrb_ary_ptr(self);
|
|
1746
|
+
|
|
1747
|
+
return mrb_bool_value(ARY_LEN(a) == 0);
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* Retrieves an element from an array at a specific index.
|
|
1752
|
+
* This is a direct (unsafe) equivalent of `RARRAY_PTR(ary)[n]`.
|
|
1753
|
+
*
|
|
1754
|
+
* If `n` is negative, it counts from the end of the array.
|
|
1755
|
+
* Returns `nil` if the index is out of bounds.
|
|
1756
|
+
* This function does not perform a bounds check before accessing the element if the index is positive.
|
|
1757
|
+
* Prefer using `mrb_ary_ref` for safe access or ensure `n` is within bounds.
|
|
1758
|
+
*
|
|
1759
|
+
* @param ary The array (mrb_value) from which to retrieve the element.
|
|
1760
|
+
* @param n The index of the element to retrieve.
|
|
1761
|
+
* @return The mrb_value at the specified index, or `nil` if out of bounds.
|
|
1762
|
+
*/
|
|
1763
|
+
MRB_API mrb_value
|
|
1764
|
+
mrb_ary_entry(mrb_value ary, mrb_int n)
|
|
1765
|
+
{
|
|
1766
|
+
struct RArray *a = mrb_ary_ptr(ary);
|
|
1767
|
+
mrb_int len = ARY_LEN(a);
|
|
1768
|
+
|
|
1769
|
+
/* range check */
|
|
1770
|
+
if (n < 0) n += len;
|
|
1771
|
+
if (n < 0 || len <= n) return mrb_nil_value();
|
|
1772
|
+
|
|
1773
|
+
return ARY_PTR(a)[n];
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
static mrb_value
|
|
1777
|
+
join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list)
|
|
1778
|
+
{
|
|
1779
|
+
/* check recursive */
|
|
1780
|
+
for (mrb_int i=0; i<RARRAY_LEN(list); i++) {
|
|
1781
|
+
if (mrb_obj_equal(mrb, ary, RARRAY_PTR(list)[i])) {
|
|
1782
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "recursive array join");
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
mrb_ary_push(mrb, list, ary);
|
|
1787
|
+
|
|
1788
|
+
mrb_value result = mrb_str_new_capa(mrb, 64);
|
|
1789
|
+
|
|
1790
|
+
for (mrb_int i=0; i<RARRAY_LEN(ary); i++) {
|
|
1791
|
+
if (i > 0 && !mrb_nil_p(sep)) {
|
|
1792
|
+
mrb_str_cat_str(mrb, result, sep);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
mrb_value val = RARRAY_PTR(ary)[i];
|
|
1796
|
+
|
|
1797
|
+
switch (mrb_type(val)) {
|
|
1798
|
+
case MRB_TT_ARRAY:
|
|
1799
|
+
ary_join:
|
|
1800
|
+
val = join_ary(mrb, val, sep, list);
|
|
1801
|
+
/* fall through */
|
|
1802
|
+
|
|
1803
|
+
case MRB_TT_STRING:
|
|
1804
|
+
str_join:
|
|
1805
|
+
mrb_str_cat_str(mrb, result, val);
|
|
1806
|
+
break;
|
|
1807
|
+
|
|
1808
|
+
default:
|
|
1809
|
+
if (!mrb_immediate_p(val)) {
|
|
1810
|
+
mrb_value tmp = mrb_check_string_type(mrb, val);
|
|
1811
|
+
if (!mrb_nil_p(tmp)) {
|
|
1812
|
+
val = tmp;
|
|
1813
|
+
goto str_join;
|
|
1814
|
+
}
|
|
1815
|
+
tmp = mrb_check_array_type(mrb, val);
|
|
1816
|
+
if (!mrb_nil_p(tmp)) {
|
|
1817
|
+
val = tmp;
|
|
1818
|
+
goto ary_join;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
val = mrb_obj_as_string(mrb, val);
|
|
1822
|
+
goto str_join;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
mrb_ary_pop(mrb, list);
|
|
1827
|
+
|
|
1828
|
+
return result;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
/**
|
|
1832
|
+
* Joins the elements of an array into a string, separated by a given separator.
|
|
1833
|
+
*
|
|
1834
|
+
* Each element of `ary` is converted to a string. These strings are then
|
|
1835
|
+
* concatenated, with the string representation of `sep` inserted between
|
|
1836
|
+
* adjacent elements.
|
|
1837
|
+
* If `sep` is `nil`, no separator is used.
|
|
1838
|
+
* This function handles recursive array joins by raising an E_ARGUMENT_ERROR.
|
|
1839
|
+
*
|
|
1840
|
+
* @param mrb The mruby state.
|
|
1841
|
+
* @param ary The array (mrb_value) whose elements are to be joined.
|
|
1842
|
+
* @param sep The separator (mrb_value) to use between elements. Can be `nil`.
|
|
1843
|
+
* @return A new mrb_value string representing the joined array elements.
|
|
1844
|
+
*/
|
|
1845
|
+
MRB_API mrb_value
|
|
1846
|
+
mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
|
|
1847
|
+
{
|
|
1848
|
+
if (!mrb_nil_p(sep)) {
|
|
1849
|
+
sep = mrb_obj_as_string(mrb, sep);
|
|
1850
|
+
}
|
|
1851
|
+
return join_ary(mrb, ary, sep, mrb_ary_new(mrb));
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
/*
|
|
1855
|
+
* call-seq:
|
|
1856
|
+
* ary.join(sep="") -> str
|
|
1857
|
+
*
|
|
1858
|
+
* Returns a string created by converting each element of the array to
|
|
1859
|
+
* a string, separated by *sep*.
|
|
1860
|
+
*
|
|
1861
|
+
* [ "a", "b", "c" ].join #=> "abc"
|
|
1862
|
+
* [ "a", "b", "c" ].join("-") #=> "a-b-c"
|
|
1863
|
+
*/
|
|
1864
|
+
|
|
1865
|
+
static mrb_value
|
|
1866
|
+
mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
|
|
1867
|
+
{
|
|
1868
|
+
mrb_value sep = mrb_nil_value();
|
|
1869
|
+
|
|
1870
|
+
mrb_get_args(mrb, "|S!", &sep);
|
|
1871
|
+
return mrb_ary_join(mrb, ary, sep);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/*
|
|
1875
|
+
* call-seq:
|
|
1876
|
+
* ary.to_s -> string
|
|
1877
|
+
* ary.inspect -> string
|
|
1878
|
+
*
|
|
1879
|
+
* Return the contents of this array as a string.
|
|
1880
|
+
*/
|
|
1881
|
+
static mrb_value
|
|
1882
|
+
mrb_ary_to_s(mrb_state *mrb, mrb_value self)
|
|
1883
|
+
{
|
|
1884
|
+
mrb->c->ci->mid = MRB_SYM(inspect);
|
|
1885
|
+
mrb_value ret = mrb_str_new_lit(mrb, "[");
|
|
1886
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
1887
|
+
if (MRB_RECURSIVE_UNARY_P(mrb, MRB_SYM(inspect), self)) {
|
|
1888
|
+
mrb_str_cat_lit(mrb, ret, "...]");
|
|
1889
|
+
return ret;
|
|
1890
|
+
}
|
|
1891
|
+
for (mrb_int i=0; i<RARRAY_LEN(self); i++) {
|
|
1892
|
+
if (i>0) mrb_str_cat_lit(mrb, ret, ", ");
|
|
1893
|
+
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, RARRAY_PTR(self)[i]));
|
|
1894
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
1895
|
+
}
|
|
1896
|
+
mrb_str_cat_lit(mrb, ret, "]");
|
|
1897
|
+
|
|
1898
|
+
return ret;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
/* check array equality: 1=equal,0=not_equal,-1=need_elements_check */
|
|
1902
|
+
static mrb_int
|
|
1903
|
+
ary_eq(mrb_state *mrb, mrb_value ary1, mrb_value ary2)
|
|
1904
|
+
{
|
|
1905
|
+
if (mrb_obj_equal(mrb, ary1, ary2)) return 1;
|
|
1906
|
+
if (!mrb_array_p(ary2)) return 0;
|
|
1907
|
+
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return 0;
|
|
1908
|
+
|
|
1909
|
+
return -1;
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
/*
|
|
1913
|
+
* call-seq:
|
|
1914
|
+
* array == other -> true or false
|
|
1915
|
+
*
|
|
1916
|
+
* Equality---Two arrays are equal if they contain the same number
|
|
1917
|
+
* of elements and if each element is equal to (according to
|
|
1918
|
+
* Object.==) the corresponding element in the other array.
|
|
1919
|
+
*
|
|
1920
|
+
*/
|
|
1921
|
+
static mrb_value
|
|
1922
|
+
mrb_ary_eq(mrb_state *mrb, mrb_value ary1)
|
|
1923
|
+
{
|
|
1924
|
+
mrb_value ary2 = mrb_get_arg1(mrb);
|
|
1925
|
+
mrb_int n = ary_eq(mrb, ary1, ary2);
|
|
1926
|
+
|
|
1927
|
+
if (n == 1) return mrb_true_value();
|
|
1928
|
+
if (n == 0) return mrb_false_value();
|
|
1929
|
+
|
|
1930
|
+
/* Check for recursion */
|
|
1931
|
+
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_OPSYM(eq), ary1, ary2)) {
|
|
1932
|
+
return mrb_false_value();
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
1936
|
+
for (mrb_int i=0; i<RARRAY_LEN(ary1); i++) {
|
|
1937
|
+
mrb_value eq = mrb_funcall_id(mrb, mrb_ary_entry(ary1, i), MRB_OPSYM(eq), 1, mrb_ary_entry(ary2, i));
|
|
1938
|
+
if (!mrb_test(eq)) return mrb_false_value();
|
|
1939
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
1940
|
+
}
|
|
1941
|
+
return mrb_true_value();
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
/*
|
|
1945
|
+
* call-seq:
|
|
1946
|
+
* array.eql? other_array -> true or false
|
|
1947
|
+
*
|
|
1948
|
+
* Returns `true` if `self` and _other_ are the same object,
|
|
1949
|
+
* or are both arrays with the same content.
|
|
1950
|
+
*
|
|
1951
|
+
*/
|
|
1952
|
+
static mrb_value
|
|
1953
|
+
mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
|
|
1954
|
+
{
|
|
1955
|
+
mrb_value ary2 = mrb_get_arg1(mrb);
|
|
1956
|
+
mrb_int n = ary_eq(mrb, ary1, ary2);
|
|
1957
|
+
|
|
1958
|
+
if (n == 1) return mrb_true_value();
|
|
1959
|
+
if (n == 0) return mrb_false_value();
|
|
1960
|
+
|
|
1961
|
+
/* Check for recursion */
|
|
1962
|
+
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_SYM_Q(eql), ary1, ary2)) {
|
|
1963
|
+
return mrb_false_value();
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
1967
|
+
for (mrb_int i=0; i<RARRAY_LEN(ary1); i++) {
|
|
1968
|
+
mrb_value eq = mrb_funcall_id(mrb, mrb_ary_entry(ary1, i), MRB_SYM_Q(eql), 1, mrb_ary_entry(ary2, i));
|
|
1969
|
+
if (!mrb_test(eq)) return mrb_false_value();
|
|
1970
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
1971
|
+
}
|
|
1972
|
+
return mrb_true_value();
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
/*
|
|
1976
|
+
* call-seq:
|
|
1977
|
+
* array <=> other_array -> -1, 0, or 1
|
|
1978
|
+
*
|
|
1979
|
+
* Comparison---Returns an integer (-1, 0, or +1)
|
|
1980
|
+
* if this array is less than, equal to, or greater than *other_ary*.
|
|
1981
|
+
* Each object in each array is compared (using <=>). If any value isn't
|
|
1982
|
+
* equal, then that inequality is the return value. If all the
|
|
1983
|
+
* values found are equal, then the return is based on a
|
|
1984
|
+
* comparison of the array lengths. Thus, two arrays are
|
|
1985
|
+
* "equal" according to `Array#<=>` if and only if they have
|
|
1986
|
+
* the same length and the value of each element is equal to the
|
|
1987
|
+
* value of the corresponding element in the other array.
|
|
1988
|
+
*/
|
|
1989
|
+
static mrb_value
|
|
1990
|
+
mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
|
|
1991
|
+
{
|
|
1992
|
+
mrb_value ary2 = mrb_get_arg1(mrb);
|
|
1993
|
+
|
|
1994
|
+
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_fixnum_value(0);
|
|
1995
|
+
if (!mrb_array_p(ary2)) return mrb_nil_value();
|
|
1996
|
+
|
|
1997
|
+
for (mrb_int i=0; i<RARRAY_LEN(ary1) && i<RARRAY_LEN(ary2); i++) {
|
|
1998
|
+
mrb_int n = mrb_cmp(mrb, RARRAY_PTR(ary1)[i], RARRAY_PTR(ary2)[i]);
|
|
1999
|
+
if (n == -2) return mrb_nil_value();
|
|
2000
|
+
if (n != 0) return mrb_fixnum_value(n);
|
|
2001
|
+
}
|
|
2002
|
+
mrb_int len = RARRAY_LEN(ary1) - RARRAY_LEN(ary2);
|
|
2003
|
+
if (len == 0) return mrb_fixnum_value(0);
|
|
2004
|
+
else if (len > 0) return mrb_fixnum_value(1);
|
|
2005
|
+
else return mrb_fixnum_value(-1);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
/* internal method to convert multi-value to single value */
|
|
2009
|
+
static mrb_value
|
|
2010
|
+
mrb_ary_svalue(mrb_state *mrb, mrb_value ary)
|
|
2011
|
+
{
|
|
2012
|
+
switch (RARRAY_LEN(ary)) {
|
|
2013
|
+
case 0:
|
|
2014
|
+
return mrb_nil_value();
|
|
2015
|
+
case 1:
|
|
2016
|
+
return RARRAY_PTR(ary)[0];
|
|
2017
|
+
default:
|
|
2018
|
+
return ary;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
/*
|
|
2023
|
+
* call-seq:
|
|
2024
|
+
* array.delete(obj) -> deleted_object
|
|
2025
|
+
* array.delete(obj) {|nosuch| ... } -> deleted_object or block_return
|
|
2026
|
+
*
|
|
2027
|
+
* Removes zero or more elements from self; returns self.
|
|
2028
|
+
*
|
|
2029
|
+
* When no block is given, removes from self each element e such
|
|
2030
|
+
* that e == obj; returns the last deleted element
|
|
2031
|
+
*
|
|
2032
|
+
* Returns nil if no elements removed.
|
|
2033
|
+
*
|
|
2034
|
+
* When a block is given, removes from self each element e such
|
|
2035
|
+
* that e == obj. If any such elements are found, ignores the block and
|
|
2036
|
+
* returns the last. Otherwise, returns the block's return value.
|
|
2037
|
+
*/
|
|
2038
|
+
static mrb_value
|
|
2039
|
+
mrb_ary_delete(mrb_state *mrb, mrb_value self)
|
|
2040
|
+
{
|
|
2041
|
+
mrb_value obj, blk;
|
|
2042
|
+
|
|
2043
|
+
mrb_get_args(mrb, "o&", &obj, &blk);
|
|
2044
|
+
|
|
2045
|
+
struct RArray *ary = RARRAY(self);
|
|
2046
|
+
mrb_value ret = obj;
|
|
2047
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
2048
|
+
mrb_int i = 0;
|
|
2049
|
+
mrb_int j = 0;
|
|
2050
|
+
for (; i < ARY_LEN(ary); i++) {
|
|
2051
|
+
mrb_value elem = ARY_PTR(ary)[i];
|
|
2052
|
+
|
|
2053
|
+
if (mrb_equal(mrb, elem, obj)) {
|
|
2054
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
2055
|
+
mrb_gc_protect(mrb, elem);
|
|
2056
|
+
ret = elem;
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
if (i != j) {
|
|
2061
|
+
if (j >= ARY_LEN(ary)) {
|
|
2062
|
+
// Since breaking here will further change the array length,
|
|
2063
|
+
// there is no choice but to raise an exception or return.
|
|
2064
|
+
mrb_raise(mrb, E_RUNTIME_ERROR, "array modified during delete");
|
|
2065
|
+
}
|
|
2066
|
+
ary_modify(mrb, ary);
|
|
2067
|
+
ARY_PTR(ary)[j] = elem;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
j++;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
if (i == j) {
|
|
2074
|
+
if (mrb_nil_p(blk)) return mrb_nil_value();
|
|
2075
|
+
return mrb_yield(mrb, blk, obj);
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
ARY_SET_LEN(ary, j);
|
|
2079
|
+
return ret;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
|
|
2083
|
+
#define SMALL_ARRAY_SORT_THRESHOLD 16
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
static mrb_bool
|
|
2087
|
+
sort_cmp(mrb_state *mrb, mrb_value ary, mrb_value a_val, mrb_value b_val, mrb_value blk)
|
|
2088
|
+
{
|
|
2089
|
+
mrb_value *p = RARRAY_PTR(ary);
|
|
2090
|
+
mrb_int n = RARRAY_LEN(ary);
|
|
2091
|
+
|
|
2092
|
+
mrb_int cmp;
|
|
2093
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
2094
|
+
|
|
2095
|
+
if (mrb_nil_p(blk)) {
|
|
2096
|
+
enum mrb_vtype type_a = mrb_type(a_val);
|
|
2097
|
+
enum mrb_vtype type_b = mrb_type(b_val);
|
|
2098
|
+
|
|
2099
|
+
if (type_a == type_b) {
|
|
2100
|
+
switch (type_a) {
|
|
2101
|
+
case MRB_TT_FIXNUM:
|
|
2102
|
+
cmp = (mrb_fixnum(a_val) > mrb_fixnum(b_val)) ? 1 : (mrb_fixnum(a_val) < mrb_fixnum(b_val)) ? -1 : 0;
|
|
2103
|
+
break;
|
|
2104
|
+
#ifndef MRB_NO_FLOAT
|
|
2105
|
+
case MRB_TT_FLOAT:
|
|
2106
|
+
cmp = (mrb_float(a_val) > mrb_float(b_val)) ? 1 : (mrb_float(a_val) < mrb_float(b_val)) ? -1 : 0;
|
|
2107
|
+
break;
|
|
2108
|
+
#endif
|
|
2109
|
+
case MRB_TT_STRING:
|
|
2110
|
+
cmp = mrb_str_cmp(mrb, a_val, b_val);
|
|
2111
|
+
break;
|
|
2112
|
+
default:
|
|
2113
|
+
cmp = mrb_cmp(mrb, a_val, b_val);
|
|
2114
|
+
break;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
else {
|
|
2118
|
+
cmp = mrb_cmp(mrb, a_val, b_val);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
else {
|
|
2122
|
+
mrb_value args[2] = {a_val, b_val};
|
|
2123
|
+
mrb_value c = mrb_yield_argv(mrb, blk, 2, args);
|
|
2124
|
+
if (mrb_nil_p(c) || !mrb_fixnum_p(c)) {
|
|
2125
|
+
cmp = -2;
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
cmp = mrb_fixnum(c);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
2132
|
+
if (cmp == -2) {
|
|
2133
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "comparison failed");
|
|
2134
|
+
}
|
|
2135
|
+
if (RARRAY_PTR(ary) != p || RARRAY_LEN(ary) != n) {
|
|
2136
|
+
mrb_raise(mrb, E_RUNTIME_ERROR, "array modified during sort");
|
|
2137
|
+
}
|
|
2138
|
+
return cmp > 0;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
static void
|
|
2142
|
+
heapify(mrb_state *mrb, mrb_value ary, mrb_value *a, mrb_int index, mrb_int size, mrb_value blk)
|
|
2143
|
+
{
|
|
2144
|
+
/* Iterative heapify to avoid stack overflow on memory-constrained devices */
|
|
2145
|
+
while (1) {
|
|
2146
|
+
mrb_int max = index;
|
|
2147
|
+
mrb_int left_index = 2 * index + 1;
|
|
2148
|
+
mrb_int right_index = left_index + 1;
|
|
2149
|
+
|
|
2150
|
+
if (left_index < size && sort_cmp(mrb, ary, a[left_index], a[max], blk)) {
|
|
2151
|
+
max = left_index;
|
|
2152
|
+
}
|
|
2153
|
+
if (right_index < size && sort_cmp(mrb, ary, a[right_index], a[max], blk)) {
|
|
2154
|
+
max = right_index;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
if (max == index) {
|
|
2158
|
+
/* Heap property satisfied, no more swaps needed */
|
|
2159
|
+
break;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
/* Swap elements and continue heapifying down the affected subtree */
|
|
2163
|
+
mrb_value tmp = a[max];
|
|
2164
|
+
a[max] = a[index];
|
|
2165
|
+
a[index] = tmp;
|
|
2166
|
+
|
|
2167
|
+
/* Continue with the affected child subtree */
|
|
2168
|
+
index = max;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
static void
|
|
2173
|
+
insertion_sort(mrb_state *mrb, mrb_value ary, mrb_value *a, mrb_int size, mrb_value blk)
|
|
2174
|
+
{
|
|
2175
|
+
int ai = mrb_gc_arena_save(mrb);
|
|
2176
|
+
for (mrb_int i = 1; i < size; i++) {
|
|
2177
|
+
mrb_value key = a[i];
|
|
2178
|
+
mrb_int j = i - 1;
|
|
2179
|
+
|
|
2180
|
+
/* Protect key from GC - it's temporarily out of the array during sort */
|
|
2181
|
+
mrb_gc_protect(mrb, key);
|
|
2182
|
+
|
|
2183
|
+
/* Move elements that are greater than key to one position ahead */
|
|
2184
|
+
while (j >= 0 && sort_cmp(mrb, ary, a[j], key, blk)) {
|
|
2185
|
+
a[j + 1] = a[j];
|
|
2186
|
+
j--;
|
|
2187
|
+
}
|
|
2188
|
+
a[j + 1] = key;
|
|
2189
|
+
mrb_gc_arena_restore(mrb, ai);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
/*
|
|
2194
|
+
* call-seq:
|
|
2195
|
+
* array.sort! -> self
|
|
2196
|
+
* array.sort! {|a, b| ... } -> self
|
|
2197
|
+
*
|
|
2198
|
+
* Sort all elements and replace `self` with these
|
|
2199
|
+
* elements.
|
|
2200
|
+
*/
|
|
2201
|
+
static mrb_value
|
|
2202
|
+
mrb_ary_sort_bang(mrb_state *mrb, mrb_value ary)
|
|
2203
|
+
{
|
|
2204
|
+
mrb_value blk;
|
|
2205
|
+
|
|
2206
|
+
mrb_int n = RARRAY_LEN(ary);
|
|
2207
|
+
if (n < 2) return ary;
|
|
2208
|
+
|
|
2209
|
+
ary_modify(mrb, mrb_ary_ptr(ary));
|
|
2210
|
+
mrb_get_args(mrb, "&", &blk);
|
|
2211
|
+
|
|
2212
|
+
mrb_value *a = RARRAY_PTR(ary);
|
|
2213
|
+
|
|
2214
|
+
/* Algorithm selection based on array size */
|
|
2215
|
+
if (n <= SMALL_ARRAY_SORT_THRESHOLD) {
|
|
2216
|
+
/* Use insertion sort for small arrays */
|
|
2217
|
+
insertion_sort(mrb, ary, a, n, blk);
|
|
2218
|
+
}
|
|
2219
|
+
else {
|
|
2220
|
+
/* Use heap sort for larger arrays */
|
|
2221
|
+
for (mrb_int i = n / 2 - 1; i >= 0; i--) {
|
|
2222
|
+
heapify(mrb, ary, a, i, n, blk);
|
|
2223
|
+
}
|
|
2224
|
+
for (mrb_int i = n - 1; i > 0; i--) {
|
|
2225
|
+
mrb_value tmp = a[0];
|
|
2226
|
+
a[0] = a[i];
|
|
2227
|
+
a[i] = tmp;
|
|
2228
|
+
heapify(mrb, ary, a, 0, i, blk);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
return ary;
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
/*
|
|
2235
|
+
* call-seq:
|
|
2236
|
+
* array.to_a -> self
|
|
2237
|
+
*
|
|
2238
|
+
* Returns self. If called on a subclass of Array, converts
|
|
2239
|
+
* the receiver to an Array object.
|
|
2240
|
+
*/
|
|
2241
|
+
static mrb_value
|
|
2242
|
+
mrb_ary_to_a(mrb_state *mrb, mrb_value self)
|
|
2243
|
+
{
|
|
2244
|
+
if (mrb_obj_class(mrb, self) != mrb->array_class) {
|
|
2245
|
+
/* Convert subclass to Array */
|
|
2246
|
+
return mrb_ary_dup(mrb, self);
|
|
2247
|
+
}
|
|
2248
|
+
return self;
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
/* ---------------------------*/
|
|
2252
|
+
static const mrb_mt_entry array_rom_entries[] = {
|
|
2253
|
+
MRB_MT_ENTRY(mrb_ary_plus, MRB_OPSYM(add), MRB_ARGS_REQ(1)), /* 15.2.12.5.1 */
|
|
2254
|
+
MRB_MT_ENTRY(mrb_ary_times, MRB_OPSYM(mul), MRB_ARGS_REQ(1)), /* 15.2.12.5.2 */
|
|
2255
|
+
MRB_MT_ENTRY(mrb_ary_push_m, MRB_OPSYM(lshift), MRB_ARGS_REQ(1)), /* 15.2.12.5.3 */
|
|
2256
|
+
MRB_MT_ENTRY(mrb_ary_aget, MRB_OPSYM(aref), MRB_ARGS_ARG(1,1)), /* 15.2.12.5.4 */
|
|
2257
|
+
MRB_MT_ENTRY(mrb_ary_aset, MRB_OPSYM(aset), MRB_ARGS_ARG(2,1)), /* 15.2.12.5.5 */
|
|
2258
|
+
MRB_MT_ENTRY(mrb_ary_clear, MRB_SYM(clear), MRB_ARGS_NONE()), /* 15.2.12.5.6 */
|
|
2259
|
+
MRB_MT_ENTRY(mrb_ary_cmp, MRB_OPSYM(cmp), MRB_ARGS_REQ(1)),
|
|
2260
|
+
MRB_MT_ENTRY(mrb_ary_concat_m, MRB_SYM(concat), MRB_ARGS_REQ(1)), /* 15.2.12.5.8 */
|
|
2261
|
+
MRB_MT_ENTRY(mrb_ary_delete, MRB_SYM(delete), MRB_ARGS_REQ(1)),
|
|
2262
|
+
MRB_MT_ENTRY(mrb_ary_delete_at, MRB_SYM(delete_at), MRB_ARGS_REQ(1)), /* 15.2.12.5.9 */
|
|
2263
|
+
MRB_MT_ENTRY(mrb_ary_empty_p, MRB_SYM_Q(empty), MRB_ARGS_NONE()), /* 15.2.12.5.12 */
|
|
2264
|
+
MRB_MT_ENTRY(mrb_ary_eq, MRB_OPSYM(eq), MRB_ARGS_REQ(1)),
|
|
2265
|
+
MRB_MT_ENTRY(mrb_ary_eql, MRB_SYM_Q(eql), MRB_ARGS_REQ(1)),
|
|
2266
|
+
MRB_MT_ENTRY(mrb_ary_first, MRB_SYM(first), MRB_ARGS_OPT(1)), /* 15.2.12.5.13 */
|
|
2267
|
+
MRB_MT_ENTRY(mrb_ary_index_m, MRB_SYM(index), MRB_ARGS_OPT(1)), /* 15.2.12.5.14 */
|
|
2268
|
+
MRB_MT_ENTRY(mrb_ary_init, MRB_SYM(initialize), MRB_ARGS_OPT(2) | MRB_MT_PRIVATE), /* 15.2.12.5.15 */
|
|
2269
|
+
MRB_MT_ENTRY(mrb_ary_replace_m, MRB_SYM(initialize_copy), MRB_ARGS_REQ(1) | MRB_MT_PRIVATE), /* 15.2.12.5.16 */
|
|
2270
|
+
MRB_MT_ENTRY(mrb_ary_join_m, MRB_SYM(join), MRB_ARGS_OPT(1)), /* 15.2.12.5.17 */
|
|
2271
|
+
MRB_MT_ENTRY(mrb_ary_last, MRB_SYM(last), MRB_ARGS_OPT(1)), /* 15.2.12.5.18 */
|
|
2272
|
+
MRB_MT_ENTRY(mrb_ary_size, MRB_SYM(length), MRB_ARGS_NONE()), /* 15.2.12.5.19 */
|
|
2273
|
+
MRB_MT_ENTRY(mrb_ary_pop, MRB_SYM(pop), MRB_ARGS_NONE()), /* 15.2.12.5.21 */
|
|
2274
|
+
MRB_MT_ENTRY(mrb_ary_push_m, MRB_SYM(push), MRB_ARGS_ANY()), /* 15.2.12.5.22 */
|
|
2275
|
+
MRB_MT_ENTRY(mrb_ary_replace_m, MRB_SYM(replace), MRB_ARGS_REQ(1)), /* 15.2.12.5.23 */
|
|
2276
|
+
MRB_MT_ENTRY(mrb_ary_reverse, MRB_SYM(reverse), MRB_ARGS_NONE()), /* 15.2.12.5.24 */
|
|
2277
|
+
MRB_MT_ENTRY(mrb_ary_reverse_bang, MRB_SYM_B(reverse), MRB_ARGS_NONE()), /* 15.2.12.5.25 */
|
|
2278
|
+
MRB_MT_ENTRY(mrb_ary_rindex_m, MRB_SYM(rindex), MRB_ARGS_OPT(1)), /* 15.2.12.5.26 */
|
|
2279
|
+
MRB_MT_ENTRY(mrb_ary_shift_m, MRB_SYM(shift), MRB_ARGS_OPT(1)), /* 15.2.12.5.27 */
|
|
2280
|
+
MRB_MT_ENTRY(mrb_ary_size, MRB_SYM(size), MRB_ARGS_NONE()), /* 15.2.12.5.28 */
|
|
2281
|
+
MRB_MT_ENTRY(mrb_ary_aget, MRB_SYM(slice), MRB_ARGS_ARG(1,1)), /* 15.2.12.5.29 */
|
|
2282
|
+
MRB_MT_ENTRY(mrb_ary_unshift_m, MRB_SYM(unshift), MRB_ARGS_ANY()), /* 15.2.12.5.30 */
|
|
2283
|
+
MRB_MT_ENTRY(mrb_ary_to_a, MRB_SYM(to_a), MRB_ARGS_NONE()),
|
|
2284
|
+
MRB_MT_ENTRY(mrb_ary_to_a, MRB_SYM(entries), MRB_ARGS_NONE()),
|
|
2285
|
+
MRB_MT_ENTRY(mrb_ary_to_s, MRB_SYM(to_s), MRB_ARGS_NONE()),
|
|
2286
|
+
MRB_MT_ENTRY(mrb_ary_to_s, MRB_SYM(inspect), MRB_ARGS_NONE()),
|
|
2287
|
+
MRB_MT_ENTRY(mrb_ary_sort_bang, MRB_SYM_B(sort), MRB_ARGS_NONE()),
|
|
2288
|
+
MRB_MT_ENTRY(mrb_ary_svalue, MRB_SYM(__svalue), MRB_ARGS_NONE()),
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
void
|
|
2292
|
+
mrb_init_array(mrb_state *mrb)
|
|
2293
|
+
{
|
|
2294
|
+
struct RClass *a;
|
|
2295
|
+
|
|
2296
|
+
mrb->array_class = a = mrb_define_class_id(mrb, MRB_SYM(Array), mrb->object_class); /* 15.2.12 */
|
|
2297
|
+
MRB_SET_INSTANCE_TT(a, MRB_TT_ARRAY);
|
|
2298
|
+
|
|
2299
|
+
mrb_define_class_method_id(mrb, a, MRB_OPSYM(aref), mrb_ary_s_create, MRB_ARGS_ANY()); /* 15.2.12.4.1 */
|
|
2300
|
+
|
|
2301
|
+
MRB_MT_INIT_ROM(mrb, a, array_rom_entries);
|
|
2302
|
+
}
|