script_core 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -6
- data/.ruby-version +1 -1
- data/Gemfile +2 -1
- data/bin/sandbox +1 -1
- data/ext/enterprise_script_service/Rakefile +1 -1
- data/ext/enterprise_script_service/flags.rb +5 -0
- data/ext/enterprise_script_service/libseccomp/CHANGELOG +15 -0
- data/ext/enterprise_script_service/libseccomp/CREDITS +3 -0
- data/ext/enterprise_script_service/libseccomp/Makefile.am +1 -1
- data/ext/enterprise_script_service/libseccomp/README.md +1 -1
- data/ext/enterprise_script_service/libseccomp/SECURITY.md +45 -0
- data/ext/enterprise_script_service/libseccomp/configure.ac +3 -3
- data/ext/enterprise_script_service/libseccomp/doc/admin/MAINTAINER_PROCESS.md +95 -0
- data/ext/enterprise_script_service/libseccomp/{RELEASE_PROCESS.md → doc/admin/RELEASE_PROCESS.md} +9 -1
- data/ext/enterprise_script_service/libseccomp/include/Makefile.am +1 -1
- data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +2292 -0
- data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +3 -1065
- data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +35 -3
- data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +35 -3
- data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +43 -11
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +33 -1
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +33 -1
- data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +34 -2
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +43 -11
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +44 -12
- data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +46 -14
- data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +142 -18
- data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +47 -15
- data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +143 -17
- data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +33 -1
- data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +94 -12
- data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +142 -19
- data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +33 -1
- data/ext/enterprise_script_service/libseccomp/src/db.c +1 -0
- data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +10 -3
- data/ext/enterprise_script_service/libseccomp/src/python/Makefile.am +4 -4
- data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +2 -0
- data/ext/enterprise_script_service/libseccomp/tests/.gitignore +1 -0
- data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.c +98 -0
- data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.py +61 -0
- data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.tests +18 -0
- data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +6 -3
- data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -2
- data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -0
- data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +2 -0
- data/ext/enterprise_script_service/mruby-mpdecimal/src/ext.c +1 -1
- data/ext/enterprise_script_service/mruby/.gitignore +2 -2
- data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +10 -3
- data/ext/enterprise_script_service/mruby/Doxyfile +2408 -0
- data/ext/enterprise_script_service/mruby/README.md +21 -8
- data/ext/enterprise_script_service/mruby/Rakefile +4 -13
- data/ext/enterprise_script_service/mruby/appveyor_config.rb +1 -1
- data/ext/enterprise_script_service/mruby/build_config.rb +3 -3
- data/ext/enterprise_script_service/mruby/doc/guides/compile.md +42 -42
- data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +1 -1
- data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +45 -6
- data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +5 -0
- data/ext/enterprise_script_service/mruby/doc/limitations.md +88 -38
- data/ext/enterprise_script_service/mruby/doc/mruby_logo_red_icon.png +0 -0
- data/ext/enterprise_script_service/mruby/doc/opcode.md +94 -94
- data/ext/enterprise_script_service/mruby/include/mrbconf.h +74 -11
- data/ext/enterprise_script_service/mruby/include/mruby.h +242 -146
- data/ext/enterprise_script_service/mruby/include/mruby/array.h +7 -7
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +2 -9
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +11 -10
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +104 -69
- data/ext/enterprise_script_service/mruby/include/mruby/class.h +7 -5
- data/ext/enterprise_script_service/mruby/include/mruby/common.h +9 -7
- data/ext/enterprise_script_service/mruby/include/mruby/compile.h +6 -6
- data/ext/enterprise_script_service/mruby/include/mruby/data.h +5 -5
- data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/dump.h +3 -7
- data/ext/enterprise_script_service/mruby/include/mruby/error.h +34 -6
- data/ext/enterprise_script_service/mruby/include/mruby/gc.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/hash.h +4 -11
- data/ext/enterprise_script_service/mruby/include/mruby/irep.h +16 -4
- data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -4
- data/ext/enterprise_script_service/mruby/include/mruby/khash.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +41 -7
- data/ext/enterprise_script_service/mruby/include/mruby/object.h +8 -9
- data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/ops.h +6 -6
- data/ext/enterprise_script_service/mruby/include/mruby/proc.h +19 -13
- data/ext/enterprise_script_service/mruby/include/mruby/range.h +10 -4
- data/ext/enterprise_script_service/mruby/include/mruby/re.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/string.h +130 -107
- data/ext/enterprise_script_service/mruby/include/mruby/throw.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/value.h +137 -49
- data/ext/enterprise_script_service/mruby/include/mruby/variable.h +3 -5
- data/ext/enterprise_script_service/mruby/include/mruby/version.h +24 -10
- data/ext/enterprise_script_service/mruby/lib/mruby-core-ext.rb +2 -39
- data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +32 -15
- data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +63 -17
- data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +24 -10
- data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +11 -7
- data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +81 -0
- data/ext/enterprise_script_service/mruby/minirake +27 -11
- data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +3 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrbgem.rake +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +47 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +3 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +50 -29
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +3 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c +3 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +28 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +1 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +75 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +134 -90
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +69 -46
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +0 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +51 -59
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +430 -241
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrbgem.rake +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +122 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +249 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +153 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/mrblib/chain.rb +19 -17
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/test/enum_chain.rb +41 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb +30 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/test/enum.rb +8 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrbgem.rake +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +46 -14
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +51 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +47 -44
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-exit/src/mruby-exit.c +9 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +16 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/test/fiber.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +0 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +3 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +3 -7
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +1 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +0 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +24 -38
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/kernel.rb +16 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +19 -18
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +5 -16
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +54 -42
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +24 -20
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file_test.rb +4 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +41 -35
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +9 -36
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrbgem.rake +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +9 -27
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb +2 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +5 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +39 -24
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +48 -17
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/method.rb +0 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +134 -101
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +9 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb +1 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +17 -37
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +0 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrbgem.rake +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrblib/object.rb +15 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +35 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/test/nil.rb +4 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +1 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +28 -23
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/test/pack.rb +43 -49
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +3 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +6 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.rb +21 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +157 -124
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +72 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +38 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +26 -11
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +111 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrbgem.rake +5 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +117 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +209 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +308 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +10 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +22 -24
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrbgem.rake +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +8 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +116 -117
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/numeric.rb +29 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/range.rb +26 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/string.rb +32 -50
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +5 -7
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +43 -57
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/test/struct.rb +16 -11
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +152 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +4 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +200 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/include/mruby/time.h +2 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +199 -68
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/test/time.rb +81 -46
- data/ext/enterprise_script_service/mruby/mrblib/array.rb +14 -16
- data/ext/enterprise_script_service/mruby/mrblib/enum.rb +13 -9
- data/ext/enterprise_script_service/mruby/mrblib/hash.rb +5 -7
- data/ext/enterprise_script_service/mruby/mrblib/kernel.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrblib/range.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrblib/string.rb +55 -112
- data/ext/enterprise_script_service/mruby/mruby-source.gemspec +1 -1
- data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby.dict +105 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_fuzzer.options +5 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_proto_fuzzer.options +4 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_fuzzer.c +18 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +44 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.cpp +455 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +55 -0
- data/ext/enterprise_script_service/mruby/oss-fuzz/ruby.proto +201 -0
- data/ext/enterprise_script_service/mruby/src/array.c +95 -46
- data/ext/enterprise_script_service/mruby/src/backtrace.c +6 -8
- data/ext/enterprise_script_service/mruby/src/class.c +370 -278
- data/ext/enterprise_script_service/mruby/src/codedump.c +34 -34
- data/ext/enterprise_script_service/mruby/src/debug.c +2 -2
- data/ext/enterprise_script_service/mruby/src/dump.c +8 -6
- data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
- data/ext/enterprise_script_service/mruby/src/error.c +157 -55
- data/ext/enterprise_script_service/mruby/src/etc.c +13 -46
- data/ext/enterprise_script_service/mruby/src/fmt_fp.c +2 -2
- data/ext/enterprise_script_service/mruby/src/gc.c +30 -11
- data/ext/enterprise_script_service/mruby/src/hash.c +23 -14
- data/ext/enterprise_script_service/mruby/src/kernel.c +16 -54
- data/ext/enterprise_script_service/mruby/src/load.c +40 -76
- data/ext/enterprise_script_service/mruby/src/numeric.c +164 -94
- data/ext/enterprise_script_service/mruby/src/object.c +16 -39
- data/ext/enterprise_script_service/mruby/src/pool.c +0 -2
- data/ext/enterprise_script_service/mruby/src/proc.c +47 -48
- data/ext/enterprise_script_service/mruby/src/range.c +22 -35
- data/ext/enterprise_script_service/mruby/src/state.c +5 -94
- data/ext/enterprise_script_service/mruby/src/string.c +874 -710
- data/ext/enterprise_script_service/mruby/src/symbol.c +73 -48
- data/ext/enterprise_script_service/mruby/src/variable.c +58 -38
- data/ext/enterprise_script_service/mruby/src/vm.c +133 -304
- data/ext/enterprise_script_service/mruby/tasks/doc.rake +48 -0
- data/ext/enterprise_script_service/mruby/tasks/toolchains/clang.rake +3 -4
- data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +20 -19
- data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +0 -12
- data/ext/enterprise_script_service/mruby/test/assert.rb +186 -25
- data/ext/enterprise_script_service/mruby/test/t/array.rb +34 -6
- data/ext/enterprise_script_service/mruby/test/t/class.rb +26 -0
- data/ext/enterprise_script_service/mruby/test/t/enumerable.rb +2 -2
- data/ext/enterprise_script_service/mruby/test/t/float.rb +17 -17
- data/ext/enterprise_script_service/mruby/test/t/hash.rb +2 -0
- data/ext/enterprise_script_service/mruby/test/t/integer.rb +14 -6
- data/ext/enterprise_script_service/mruby/test/t/kernel.rb +38 -19
- data/ext/enterprise_script_service/mruby/test/t/module.rb +87 -14
- data/ext/enterprise_script_service/mruby/test/t/numeric.rb +65 -23
- data/ext/enterprise_script_service/mruby/test/t/range.rb +4 -4
- data/ext/enterprise_script_service/mruby/test/t/string.rb +211 -49
- data/ext/enterprise_script_service/mruby/test/t/syntax.rb +19 -2
- data/ext/enterprise_script_service/mruby/test/t/vformat.rb +92 -0
- data/ext/enterprise_script_service/mruby/travis_config.rb +2 -2
- data/ext/enterprise_script_service/mruby_config.rb +10 -0
- data/ext/enterprise_script_service/mruby_engine.cpp +2 -2
- data/ext/enterprise_script_service/mruby_engine.gembox +1 -0
- data/ext/enterprise_script_service/msgpack/CHANGELOG.md +14 -0
- data/ext/enterprise_script_service/msgpack/Files.cmake +4 -0
- data/ext/enterprise_script_service/msgpack/README.md +1 -1
- data/ext/enterprise_script_service/msgpack/appveyor.yml +1 -1
- data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple.hpp.erb +1 -1
- data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb +1 -1
- data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_zone.hpp.erb +3 -3
- data/ext/enterprise_script_service/msgpack/example/boost/asio_send_recv.cpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/cpp11/timespec.hpp +16 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/wstring.hpp +15 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/object.h +2 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/pack_template.h +17 -9
- data/ext/enterprise_script_service/msgpack/include/msgpack/sysdep.h +27 -16
- data/ext/enterprise_script_service/msgpack/include/msgpack/type.hpp +2 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/unpack_template.h +5 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +0 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/check_container_size.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/chrono.hpp +5 -5
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/timespec.hpp +140 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple.hpp +32 -32
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple_decl.hpp +32 -32
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple.hpp +6 -6
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple_decl.hpp +10 -10
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/ext.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/fixint.hpp +5 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int.hpp +40 -13
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int_decl.hpp +3 -2
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +121 -0
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp03_zone.hpp +3 -3
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp11_zone.hpp +3 -3
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object.hpp +6 -6
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object_fwd.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/pack.hpp +40 -5
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/unpack.hpp +11 -11
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/vrefbuffer.hpp +7 -7
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/zbuffer.hpp +5 -5
- data/ext/enterprise_script_service/msgpack/include/msgpack/v2/adaptor/int_decl.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v2/create_object_visitor.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v2/parse.hpp +13 -13
- data/ext/enterprise_script_service/msgpack/include/msgpack/v2/x3_parse.hpp +28 -26
- data/ext/enterprise_script_service/msgpack/include/msgpack/v3/adaptor/int_decl.hpp +1 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v3/parse.hpp +13 -13
- data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
- data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +6 -6
- data/ext/enterprise_script_service/msgpack/include/msgpack/zone.h +1 -1
- data/ext/enterprise_script_service/msgpack/src/objectc.c +83 -148
- data/ext/enterprise_script_service/msgpack/src/unpack.c +73 -47
- data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +1 -1
- data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +15 -9
- data/ext/enterprise_script_service/msgpack/test/buffer.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/carray.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/cases.cpp +7 -1
- data/ext/enterprise_script_service/msgpack/test/convert.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/fixint.cpp +7 -1
- data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +6 -1
- data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +8 -2
- data/ext/enterprise_script_service/msgpack/test/json.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/limit.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +128 -6
- data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +7 -2
- data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +20 -3
- data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +159 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +8 -3
- data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +23 -18
- data/ext/enterprise_script_service/msgpack/test/object.cpp +77 -45
- data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +28 -10
- data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +25 -18
- data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/raw.cpp +17 -12
- data/ext/enterprise_script_service/msgpack/test/reference.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +6 -2
- data/ext/enterprise_script_service/msgpack/test/streaming.cpp +10 -3
- data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/user_class.cpp +5 -0
- data/ext/enterprise_script_service/msgpack/test/version.cpp +6 -0
- data/ext/enterprise_script_service/msgpack/test/visitor.cpp +7 -0
- data/ext/enterprise_script_service/msgpack/test/zone.cpp +6 -0
- data/lib/script_core/version.rb +1 -1
- data/lib/tasks/mruby/engine.gembox.example +1 -0
- data/lib/tasks/script_core.rake +21 -3
- data/spec/dummy/app/helpers/fields_helper.rb +2 -2
- data/spec/dummy/mruby/engine.gembox +1 -0
- data/spec/script_core_spec.rb +1 -1
- metadata +38 -22
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.gitignore +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.travis.yml +0 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/run_test.rb +0 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrblib/kernel.rb +0 -15
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/unbound_method.rb +0 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.gitignore +0 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.travis.yml +0 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/packtest.rb +0 -157
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/run_test.rb +0 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.c +0 -224
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.h +0 -80
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.h +0 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.gitignore +0 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis.yml +0 -29
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis_build_config.rb +0 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/Rakefile +0 -29
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/.travis.yml +0 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/run_test.rb +0 -28
@@ -0,0 +1,10 @@
|
|
1
|
+
MRuby::Gem::Specification.new('mruby-complex') do |spec|
|
2
|
+
spec.license = 'MIT'
|
3
|
+
spec.author = 'mruby developers'
|
4
|
+
spec.summary = 'Complex class'
|
5
|
+
|
6
|
+
spec.add_dependency 'mruby-metaprog', core: 'mruby-metaprog'
|
7
|
+
spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext'
|
8
|
+
spec.add_dependency 'mruby-numeric-ext', core: 'mruby-numeric-ext'
|
9
|
+
spec.add_dependency 'mruby-math', core: 'mruby-math'
|
10
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
class Complex < Numeric
|
2
|
+
def self.polar(abs, arg = 0)
|
3
|
+
Complex(abs * Math.cos(arg), abs * Math.sin(arg))
|
4
|
+
end
|
5
|
+
|
6
|
+
def inspect
|
7
|
+
"(#{to_s})"
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"#{real}#{'+' unless imaginary.negative?}#{imaginary}i"
|
12
|
+
end
|
13
|
+
|
14
|
+
def +@
|
15
|
+
Complex(real, imaginary)
|
16
|
+
end
|
17
|
+
|
18
|
+
def -@
|
19
|
+
Complex(-real, -imaginary)
|
20
|
+
end
|
21
|
+
|
22
|
+
def +(rhs)
|
23
|
+
if rhs.is_a? Complex
|
24
|
+
Complex(real + rhs.real, imaginary + rhs.imaginary)
|
25
|
+
elsif rhs.is_a? Numeric
|
26
|
+
Complex(real + rhs, imaginary)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def -(rhs)
|
31
|
+
if rhs.is_a? Complex
|
32
|
+
Complex(real - rhs.real, imaginary - rhs.imaginary)
|
33
|
+
elsif rhs.is_a? Numeric
|
34
|
+
Complex(real - rhs, imaginary)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def *(rhs)
|
39
|
+
if rhs.is_a? Complex
|
40
|
+
Complex(real * rhs.real - imaginary * rhs.imaginary, real * rhs.imaginary + rhs.real * imaginary)
|
41
|
+
elsif rhs.is_a? Numeric
|
42
|
+
Complex(real * rhs, imaginary * rhs)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def /(rhs)
|
47
|
+
if rhs.is_a? Complex
|
48
|
+
__div__(rhs)
|
49
|
+
elsif rhs.is_a? Numeric
|
50
|
+
Complex(real / rhs, imaginary / rhs)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
alias_method :quo, :/
|
54
|
+
|
55
|
+
def ==(rhs)
|
56
|
+
if rhs.is_a? Complex
|
57
|
+
real == rhs.real && imaginary == rhs.imaginary
|
58
|
+
elsif rhs.is_a? Numeric
|
59
|
+
imaginary.zero? && real == rhs
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def abs
|
64
|
+
Math.hypot imaginary, real
|
65
|
+
end
|
66
|
+
alias_method :magnitude, :abs
|
67
|
+
|
68
|
+
def abs2
|
69
|
+
real * real + imaginary * imaginary
|
70
|
+
end
|
71
|
+
|
72
|
+
def arg
|
73
|
+
Math.atan2 imaginary, real
|
74
|
+
end
|
75
|
+
alias_method :angle, :arg
|
76
|
+
alias_method :phase, :arg
|
77
|
+
|
78
|
+
def conjugate
|
79
|
+
Complex(real, -imaginary)
|
80
|
+
end
|
81
|
+
alias_method :conj, :conjugate
|
82
|
+
|
83
|
+
def fdiv(numeric)
|
84
|
+
Complex(real.to_f / numeric, imaginary.to_f / numeric)
|
85
|
+
end
|
86
|
+
|
87
|
+
def polar
|
88
|
+
[abs, arg]
|
89
|
+
end
|
90
|
+
|
91
|
+
def real?
|
92
|
+
false
|
93
|
+
end
|
94
|
+
|
95
|
+
def rectangular
|
96
|
+
[real, imaginary]
|
97
|
+
end
|
98
|
+
alias_method :rect, :rectangular
|
99
|
+
|
100
|
+
def to_r
|
101
|
+
raise RangeError.new "can't convert #{to_s} into Rational" unless imaginary.zero?
|
102
|
+
Rational(real, 1)
|
103
|
+
end
|
104
|
+
|
105
|
+
alias_method :imag, :imaginary
|
106
|
+
|
107
|
+
[Fixnum, Float].each do |cls|
|
108
|
+
[:+, :-, :*, :/, :==].each do |op|
|
109
|
+
cls.instance_exec do
|
110
|
+
original_operator_name = "__original_operator_#{op}_complex"
|
111
|
+
alias_method original_operator_name, op
|
112
|
+
define_method op do |rhs|
|
113
|
+
if rhs.is_a? Complex
|
114
|
+
Complex(self).send(op, rhs)
|
115
|
+
else
|
116
|
+
send(original_operator_name, rhs)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
#include <mruby.h>
|
2
|
+
#include <mruby/class.h>
|
3
|
+
#include <mruby/numeric.h>
|
4
|
+
#include <math.h>
|
5
|
+
|
6
|
+
#ifdef MRB_WITHOUT_FLOAT
|
7
|
+
# error Complex conflicts 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
|
8
|
+
#endif
|
9
|
+
|
10
|
+
struct mrb_complex {
|
11
|
+
mrb_float real;
|
12
|
+
mrb_float imaginary;
|
13
|
+
};
|
14
|
+
|
15
|
+
#ifdef MRB_USE_FLOAT
|
16
|
+
#define F(x) x##f
|
17
|
+
#else
|
18
|
+
#define F(x) x
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT)
|
22
|
+
|
23
|
+
#define COMPLEX_USE_ISTRUCT
|
24
|
+
/* use TT_ISTRUCT */
|
25
|
+
#include <mruby/istruct.h>
|
26
|
+
|
27
|
+
#define complex_ptr(mrb, v) (struct mrb_complex*)mrb_istruct_ptr(v)
|
28
|
+
|
29
|
+
static struct RBasic*
|
30
|
+
complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p)
|
31
|
+
{
|
32
|
+
struct RIStruct *s;
|
33
|
+
|
34
|
+
s = (struct RIStruct*)mrb_obj_alloc(mrb, MRB_TT_ISTRUCT, c);
|
35
|
+
*p = (struct mrb_complex*)s->inline_data;
|
36
|
+
|
37
|
+
return (struct RBasic*)s;
|
38
|
+
}
|
39
|
+
|
40
|
+
#else
|
41
|
+
/* use TT_DATA */
|
42
|
+
#include <mruby/data.h>
|
43
|
+
|
44
|
+
static const struct mrb_data_type mrb_complex_type = {"Complex", mrb_free};
|
45
|
+
|
46
|
+
static struct RBasic*
|
47
|
+
complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p)
|
48
|
+
{
|
49
|
+
struct RData *d;
|
50
|
+
|
51
|
+
Data_Make_Struct(mrb, c, struct mrb_complex, &mrb_complex_type, *p, d);
|
52
|
+
|
53
|
+
return (struct RBasic*)d;
|
54
|
+
}
|
55
|
+
|
56
|
+
static struct mrb_complex*
|
57
|
+
complex_ptr(mrb_state *mrb, mrb_value v)
|
58
|
+
{
|
59
|
+
struct mrb_complex *p;
|
60
|
+
|
61
|
+
p = DATA_GET_PTR(mrb, v, &mrb_complex_type, struct mrb_complex);
|
62
|
+
if (!p) {
|
63
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized complex");
|
64
|
+
}
|
65
|
+
return p;
|
66
|
+
}
|
67
|
+
#endif
|
68
|
+
|
69
|
+
static mrb_value
|
70
|
+
complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
|
71
|
+
{
|
72
|
+
struct RClass *c = mrb_class_get(mrb, "Complex");
|
73
|
+
struct mrb_complex *p;
|
74
|
+
struct RBasic *comp = complex_alloc(mrb, c, &p);
|
75
|
+
p->real = real;
|
76
|
+
p->imaginary = imaginary;
|
77
|
+
MRB_SET_FROZEN_FLAG(comp);
|
78
|
+
|
79
|
+
return mrb_obj_value(comp);
|
80
|
+
}
|
81
|
+
|
82
|
+
static mrb_value
|
83
|
+
complex_real(mrb_state *mrb, mrb_value self)
|
84
|
+
{
|
85
|
+
struct mrb_complex *p = complex_ptr(mrb, self);
|
86
|
+
return mrb_float_value(mrb, p->real);
|
87
|
+
}
|
88
|
+
|
89
|
+
static mrb_value
|
90
|
+
complex_imaginary(mrb_state *mrb, mrb_value self)
|
91
|
+
{
|
92
|
+
struct mrb_complex *p = complex_ptr(mrb, self);
|
93
|
+
return mrb_float_value(mrb, p->imaginary);
|
94
|
+
}
|
95
|
+
|
96
|
+
static mrb_value
|
97
|
+
complex_s_rect(mrb_state *mrb, mrb_value self)
|
98
|
+
{
|
99
|
+
mrb_float real, imaginary = 0.0;
|
100
|
+
|
101
|
+
mrb_get_args(mrb, "f|f", &real, &imaginary);
|
102
|
+
return complex_new(mrb, real, imaginary);
|
103
|
+
}
|
104
|
+
|
105
|
+
static mrb_value
|
106
|
+
complex_to_f(mrb_state *mrb, mrb_value self)
|
107
|
+
{
|
108
|
+
struct mrb_complex *p = complex_ptr(mrb, self);
|
109
|
+
|
110
|
+
if (p->imaginary != 0) {
|
111
|
+
mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self);
|
112
|
+
}
|
113
|
+
|
114
|
+
return mrb_float_value(mrb, p->real);
|
115
|
+
}
|
116
|
+
|
117
|
+
static mrb_value
|
118
|
+
complex_to_i(mrb_state *mrb, mrb_value self)
|
119
|
+
{
|
120
|
+
struct mrb_complex *p = complex_ptr(mrb, self);
|
121
|
+
|
122
|
+
if (p->imaginary != 0) {
|
123
|
+
mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self);
|
124
|
+
}
|
125
|
+
return mrb_int_value(mrb, p->real);
|
126
|
+
}
|
127
|
+
|
128
|
+
static mrb_value
|
129
|
+
complex_to_c(mrb_state *mrb, mrb_value self)
|
130
|
+
{
|
131
|
+
return self;
|
132
|
+
}
|
133
|
+
|
134
|
+
/* Arithmetic on (significand, exponent) pairs avoids premature overflow in
|
135
|
+
complex division */
|
136
|
+
struct float_pair {
|
137
|
+
mrb_float s;
|
138
|
+
int x;
|
139
|
+
};
|
140
|
+
|
141
|
+
static void
|
142
|
+
add_pair(struct float_pair *s, struct float_pair const *a,
|
143
|
+
struct float_pair const *b)
|
144
|
+
{
|
145
|
+
if (b->s == 0.0F) {
|
146
|
+
*s = *a;
|
147
|
+
} else if (a->s == 0.0F) {
|
148
|
+
*s = *b;
|
149
|
+
} else if (a->x >= b->x) {
|
150
|
+
s->s = a->s + F(ldexp)(b->s, b->x - a->x);
|
151
|
+
s->x = a->x;
|
152
|
+
} else {
|
153
|
+
s->s = F(ldexp)(a->s, a->x - b->x) + b->s;
|
154
|
+
s->x = b->x;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
static void
|
159
|
+
mul_pair(struct float_pair *p, struct float_pair const *a,
|
160
|
+
struct float_pair const *b)
|
161
|
+
{
|
162
|
+
p->s = a->s * b->s;
|
163
|
+
p->x = a->x + b->x;
|
164
|
+
}
|
165
|
+
|
166
|
+
static void
|
167
|
+
div_pair(struct float_pair *q, struct float_pair const *a,
|
168
|
+
struct float_pair const *b)
|
169
|
+
{
|
170
|
+
q->s = a->s / b->s;
|
171
|
+
q->x = a->x - b->x;
|
172
|
+
}
|
173
|
+
|
174
|
+
static mrb_value
|
175
|
+
complex_div(mrb_state *mrb, mrb_value self)
|
176
|
+
{
|
177
|
+
mrb_value rhs;
|
178
|
+
struct mrb_complex *a, *b;
|
179
|
+
struct float_pair ar, ai, br, bi;
|
180
|
+
struct float_pair br2, bi2;
|
181
|
+
struct float_pair div;
|
182
|
+
struct float_pair ar_br, ai_bi;
|
183
|
+
struct float_pair ai_br, ar_bi;
|
184
|
+
struct float_pair zr, zi;
|
185
|
+
|
186
|
+
mrb_get_args(mrb, "o", &rhs);
|
187
|
+
a = complex_ptr(mrb, self);
|
188
|
+
b = complex_ptr(mrb, rhs);
|
189
|
+
|
190
|
+
/* Split floating point components into significand and exponent */
|
191
|
+
ar.s = F(frexp)(a->real, &ar.x);
|
192
|
+
ai.s = F(frexp)(a->imaginary, &ai.x);
|
193
|
+
br.s = F(frexp)(b->real, &br.x);
|
194
|
+
bi.s = F(frexp)(b->imaginary, &bi.x);
|
195
|
+
|
196
|
+
/* Perform arithmetic on (significand, exponent) pairs to produce
|
197
|
+
the result: */
|
198
|
+
|
199
|
+
/* the divisor */
|
200
|
+
mul_pair(&br2, &br, &br);
|
201
|
+
mul_pair(&bi2, &bi, &bi);
|
202
|
+
add_pair(&div, &br2, &bi2);
|
203
|
+
|
204
|
+
/* real component */
|
205
|
+
mul_pair(&ar_br, &ar, &br);
|
206
|
+
mul_pair(&ai_bi, &ai, &bi);
|
207
|
+
add_pair(&zr, &ar_br, &ai_bi);
|
208
|
+
div_pair(&zr, &zr, &div);
|
209
|
+
|
210
|
+
/* imaginary component */
|
211
|
+
mul_pair(&ai_br, &ai, &br);
|
212
|
+
mul_pair(&ar_bi, &ar, &bi);
|
213
|
+
ar_bi.s = -ar_bi.s;
|
214
|
+
add_pair(&zi, &ai_br, &ar_bi);
|
215
|
+
div_pair(&zi, &zi, &div);
|
216
|
+
|
217
|
+
/* assemble the result */
|
218
|
+
return complex_new(mrb, F(ldexp)(zr.s, zr.x), F(ldexp)(zi.s, zi.x));
|
219
|
+
}
|
220
|
+
|
221
|
+
void mrb_mruby_complex_gem_init(mrb_state *mrb)
|
222
|
+
{
|
223
|
+
struct RClass *comp;
|
224
|
+
|
225
|
+
#ifdef COMPLEX_USE_ISTRUCT
|
226
|
+
mrb_assert(sizeof(struct mrb_complex) < ISTRUCT_DATA_SIZE);
|
227
|
+
#endif
|
228
|
+
comp = mrb_define_class(mrb, "Complex", mrb_class_get(mrb, "Numeric"));
|
229
|
+
#ifdef COMPLEX_USE_ISTRUCT
|
230
|
+
MRB_SET_INSTANCE_TT(comp, MRB_TT_ISTRUCT);
|
231
|
+
#else
|
232
|
+
MRB_SET_INSTANCE_TT(comp, MRB_TT_DATA);
|
233
|
+
#endif
|
234
|
+
mrb_undef_class_method(mrb, comp, "new");
|
235
|
+
mrb_define_class_method(mrb, comp, "rectangular", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
|
236
|
+
mrb_define_class_method(mrb, comp, "rect", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
|
237
|
+
mrb_define_method(mrb, mrb->kernel_module, "Complex", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
|
238
|
+
mrb_define_method(mrb, comp, "real", complex_real, MRB_ARGS_NONE());
|
239
|
+
mrb_define_method(mrb, comp, "imaginary", complex_imaginary, MRB_ARGS_NONE());
|
240
|
+
mrb_define_method(mrb, comp, "to_f", complex_to_f, MRB_ARGS_NONE());
|
241
|
+
mrb_define_method(mrb, comp, "to_i", complex_to_i, MRB_ARGS_NONE());
|
242
|
+
mrb_define_method(mrb, comp, "to_c", complex_to_c, MRB_ARGS_NONE());
|
243
|
+
mrb_define_method(mrb, comp, "__div__", complex_div, MRB_ARGS_REQ(1));
|
244
|
+
}
|
245
|
+
|
246
|
+
void
|
247
|
+
mrb_mruby_complex_gem_final(mrb_state* mrb)
|
248
|
+
{
|
249
|
+
}
|
@@ -0,0 +1,153 @@
|
|
1
|
+
def assert_complex(real, exp)
|
2
|
+
assert "assert_complex" do
|
3
|
+
assert_float real.real, exp.real
|
4
|
+
assert_float real.imaginary, exp.imaginary
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
assert 'Complex' do
|
9
|
+
c = 123i
|
10
|
+
assert_equal Complex, c.class
|
11
|
+
assert_equal [c.real, c.imaginary], [0, 123]
|
12
|
+
c = 123 + -1.23i
|
13
|
+
assert_equal Complex, c.class
|
14
|
+
assert_equal [c.real, c.imaginary], [123, -1.23]
|
15
|
+
end
|
16
|
+
|
17
|
+
assert 'Complex::polar' do
|
18
|
+
assert_complex Complex.polar(3, 0), (3 + 0i)
|
19
|
+
assert_complex Complex.polar(3, Math::PI/2), (0 + 3i)
|
20
|
+
assert_complex Complex.polar(3, Math::PI), (-3 + 0i)
|
21
|
+
assert_complex Complex.polar(3, -Math::PI/2), (0 + -3i)
|
22
|
+
end
|
23
|
+
|
24
|
+
assert 'Complex::rectangular' do
|
25
|
+
assert_complex Complex.rectangular(1, 2), (1 + 2i)
|
26
|
+
end
|
27
|
+
|
28
|
+
assert 'Complex#*' do
|
29
|
+
assert_complex Complex(2, 3) * Complex(2, 3), (-5 + 12i)
|
30
|
+
assert_complex Complex(900) * Complex(1), (900 + 0i)
|
31
|
+
assert_complex Complex(-2, 9) * Complex(-9, 2), (0 - 85i)
|
32
|
+
assert_complex Complex(9, 8) * 4, (36 + 32i)
|
33
|
+
assert_complex Complex(20, 9) * 9.8, (196.0 + 88.2i)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert 'Complex#+' do
|
37
|
+
assert_complex Complex(2, 3) + Complex(2, 3) , (4 + 6i)
|
38
|
+
assert_complex Complex(900) + Complex(1) , (901 + 0i)
|
39
|
+
assert_complex Complex(-2, 9) + Complex(-9, 2), (-11 + 11i)
|
40
|
+
assert_complex Complex(9, 8) + 4 , (13 + 8i)
|
41
|
+
assert_complex Complex(20, 9) + 9.8 , (29.8 + 9i)
|
42
|
+
end
|
43
|
+
|
44
|
+
assert 'Complex#-' do
|
45
|
+
assert_complex Complex(2, 3) - Complex(2, 3) , (0 + 0i)
|
46
|
+
assert_complex Complex(900) - Complex(1) , (899 + 0i)
|
47
|
+
assert_complex Complex(-2, 9) - Complex(-9, 2), (7 + 7i)
|
48
|
+
assert_complex Complex(9, 8) - 4 , (5 + 8i)
|
49
|
+
assert_complex Complex(20, 9) - 9.8 , (10.2 + 9i)
|
50
|
+
end
|
51
|
+
|
52
|
+
assert 'Complex#-@' do
|
53
|
+
assert_complex(-Complex(1, 2), (-1 - 2i))
|
54
|
+
end
|
55
|
+
|
56
|
+
assert 'Complex#/' do
|
57
|
+
assert_complex Complex(2, 3) / Complex(2, 3) , (1 + 0i)
|
58
|
+
assert_complex Complex(900) / Complex(1) , (900 + 0i)
|
59
|
+
assert_complex Complex(-2, 9) / Complex(-9, 2), ((36 / 85) - (77i / 85))
|
60
|
+
assert_complex Complex(9, 8) / 4 , ((9 / 4) + 2i)
|
61
|
+
assert_complex Complex(20, 9) / 9.8 , (2.0408163265306123 + 0.9183673469387754i)
|
62
|
+
if 1e39.infinite? then
|
63
|
+
# MRB_USE_FLOAT in effect
|
64
|
+
ten = 1e21
|
65
|
+
one = 1e20
|
66
|
+
else
|
67
|
+
ten = 1e201
|
68
|
+
one = 1e200
|
69
|
+
end
|
70
|
+
assert_complex Complex(ten, ten) / Complex(one, one), Complex(10.0, 0.0)
|
71
|
+
end
|
72
|
+
|
73
|
+
assert 'Complex#==' do
|
74
|
+
assert_true Complex(2, 3) == Complex(2, 3)
|
75
|
+
assert_true Complex(5) == 5
|
76
|
+
assert_true Complex(0) == 0.0
|
77
|
+
end
|
78
|
+
|
79
|
+
assert 'Complex#abs' do
|
80
|
+
assert_float Complex(-1).abs, 1
|
81
|
+
assert_float Complex(3.0, -4.0).abs, 5.0
|
82
|
+
if 1e39.infinite? then
|
83
|
+
# MRB_USE_FLOAT in effect
|
84
|
+
exp = 125
|
85
|
+
else
|
86
|
+
exp = 1021
|
87
|
+
end
|
88
|
+
assert_true Complex(3.0*2.0**exp, 4.0*2.0**exp).abs.finite?
|
89
|
+
assert_float Complex(3.0*2.0**exp, 4.0*2.0**exp).abs, 5.0*2.0**exp
|
90
|
+
end
|
91
|
+
|
92
|
+
assert 'Complex#abs2' do
|
93
|
+
assert_float Complex(-1).abs2, 1
|
94
|
+
assert_float Complex(3.0, -4.0).abs2, 25.0
|
95
|
+
end
|
96
|
+
|
97
|
+
assert 'Complex#arg' do
|
98
|
+
assert_float Complex.polar(3, Math::PI/2).arg, 1.5707963267948966
|
99
|
+
end
|
100
|
+
|
101
|
+
assert 'Complex#conjugate' do
|
102
|
+
assert_complex Complex(1, 2).conjugate, (1 - 2i)
|
103
|
+
end
|
104
|
+
|
105
|
+
assert 'Complex#fdiv' do
|
106
|
+
assert_complex Complex(11, 22).fdiv(3), (3.6666666666666665 + 7.333333333333333i)
|
107
|
+
end
|
108
|
+
|
109
|
+
assert 'Complex#imaginary' do
|
110
|
+
assert_float Complex(7).imaginary , 0
|
111
|
+
assert_float Complex(9, -4).imaginary, -4
|
112
|
+
end
|
113
|
+
|
114
|
+
assert 'Complex#polar' do
|
115
|
+
assert_equal Complex(1, 2).polar, [2.23606797749979, 1.1071487177940904]
|
116
|
+
end
|
117
|
+
|
118
|
+
assert 'Complex#real' do
|
119
|
+
assert_float Complex(7).real, 7
|
120
|
+
assert_float Complex(9, -4).real, 9
|
121
|
+
end
|
122
|
+
|
123
|
+
assert 'Complex#real?' do
|
124
|
+
assert_false Complex(1).real?
|
125
|
+
end
|
126
|
+
|
127
|
+
assert 'Complex::rectangular' do
|
128
|
+
assert_equal Complex(1, 2).rectangular, [1, 2]
|
129
|
+
end
|
130
|
+
|
131
|
+
assert 'Complex::to_c' do
|
132
|
+
assert_equal Complex(1, 2).to_c, Complex(1, 2)
|
133
|
+
end
|
134
|
+
|
135
|
+
assert 'Complex::to_f' do
|
136
|
+
assert_float Complex(1, 0).to_f, 1.0
|
137
|
+
assert_raise(RangeError) do
|
138
|
+
Complex(1, 2).to_f
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
assert 'Complex::to_i' do
|
143
|
+
assert_equal Complex(1, 0).to_i, 1
|
144
|
+
assert_raise(RangeError) do
|
145
|
+
Complex(1, 2).to_i
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
assert 'Complex#frozen?' do
|
150
|
+
assert_predicate(1i, :frozen?)
|
151
|
+
assert_predicate(Complex(2,3), :frozen?)
|
152
|
+
assert_predicate(4+5i, :frozen?)
|
153
|
+
end
|