diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24fb4b81..2361dcec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,13 @@ jobs: strategy: matrix: include: - - { os: windows-latest, rust-version: stable, shell: 'msys2 {0}' } - - { os: macos-11, rust-version: stable, shell: bash } - - { os: ubuntu-20.04, rust-version: stable, shell: bash, extra: true } - - { os: ubuntu-20.04, rust-version: 1.65, shell: bash } - - { os: ubuntu-20.04, rust-version: beta, shell: bash } - - { os: ubuntu-20.04, rust-version: nightly, shell: bash } + - { os: windows-latest, rust-version: stable, shell: 'msys2 {0}', target: 'x86_64-pc-windows-gnu'} + - { os: macos-11, rust-version: stable, shell: bash, target: 'x86_64-apple-darwin' } + - { os: ubuntu-20.04, rust-version: stable, shell: bash, extra: true, target: 'x86_64-unknown-linux-gnu' } + - { os: ubuntu-20.04, rust-version: stable, shell: bash, target: 'i686-unknown-linux-gnu' } + - { os: ubuntu-20.04, rust-version: 1.65, shell: bash, target: 'x86_64-unknown-linux-gnu'} + - { os: ubuntu-20.04, rust-version: beta, shell: bash, target: 'x86_64-unknown-linux-gnu'} + - { os: ubuntu-20.04, rust-version: nightly, shell: bash, target: 'x86_64-unknown-linux-gnu'} defaults: run: shell: ${{ matrix.shell }} @@ -32,7 +33,11 @@ jobs: id: toolchain with: toolchain: ${{ matrix.rust-version }} + targets: ${{ matrix.target }} components: clippy, rustfmt + - name: Install i686 dependencies + if: "contains(matrix.target,'i686')" + run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install libssl-dev:i386 gcc-multilib clang -y && echo "CC=clang" >> $GITHUB_ENV && echo "PKG_CONFIG_SYSROOT_DIR=/" >> $GITHUB_ENV - uses: msys2/setup-msys2@v2 if: contains(matrix.os,'windows') with: @@ -48,14 +53,14 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ matrix.os }}_rustc-${{ steps.toolchain.outputs.cachekey }}_cargo-${{ hashFiles('**/Cargo.lock') }} + key: ${{ matrix.os }}_${{ matrix.target }}_rustc-${{ steps.toolchain.outputs.cachekey }}_cargo-${{ hashFiles('**/Cargo.lock') }} # Build and test. - name: Build library - run: cargo rustc --verbose --lib -- -D warnings + run: cargo rustc --target ${{ matrix.target }} --verbose --lib -- -D warnings - name: Test if: "!matrix.extra" - run: cargo test --all --verbose + run: cargo test --target ${{ matrix.target }} --all --verbose # Extra steps only run once to avoid duplication, when matrix.extra is true - name: Test and report @@ -90,14 +95,14 @@ jobs: - name: Build release binary if: contains(matrix.rust-version,'stable') run: | - cargo rustc --verbose --bin scryer-prolog --release -- -D warnings + cargo rustc --target ${{ matrix.target }} --verbose --bin scryer-prolog --release -- -D warnings echo "$PWD/target/release" >> $GITHUB_PATH - name: Publish release binary artifact if: contains(matrix.rust-version,'stable') uses: actions/upload-artifact@v3 with: - path: target/release/scryer-prolog* - name: scryer-prolog_${{ matrix.os }} + path: target/${{ matrix.target }}/release/scryer-prolog* + name: scryer-prolog_${{ matrix.os }}_${{ matrix.target }} logtalk-test: runs-on: ubuntu-20.04 @@ -106,7 +111,7 @@ jobs: # Download prebuilt ubuntu binary from build-test job, setup logtalk - uses: actions/download-artifact@v3 with: - name: scryer-prolog_ubuntu-20.04 + name: scryer-prolog_ubuntu-20.04_x86_64-unknown-linux-gnu - run: | chmod +x scryer-prolog echo "$PWD" >> "$GITHUB_PATH" @@ -154,9 +159,9 @@ jobs: - uses: actions/download-artifact@v3 - name: Zip binaries for release run: | - zip scryer-prolog_macos-11.zip ./scryer-prolog_macos-11/scryer-prolog - zip scryer-prolog_ubuntu-20.04.zip ./scryer-prolog_ubuntu-20.04/scryer-prolog - zip scryer-prolog_windows-latest.zip ./scryer-prolog_windows-latest/scryer-prolog.exe + zip scryer-prolog_macos-11.zip ./scryer-prolog_macos-11_x86_64-apple-darwin/scryer-prolog + zip scryer-prolog_ubuntu-20.04.zip ./scryer-prolog_ubuntu-20.04_x86_64-unknown-linux-gnu/scryer-prolog + zip scryer-prolog_windows-latest.zip ./scryer-prolog_windows-latest_x86_64-pc-windows-gnu/scryer-prolog.exe - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/Cargo.lock b/Cargo.lock index a53f32ce..76d60f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -69,9 +69,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -90,9 +90,9 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" [[package]] name = "bit-set" @@ -117,9 +117,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "bitvec" @@ -221,9 +221,12 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -285,9 +288,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -319,13 +322,14 @@ dependencies = [ [[package]] name = "crrl" -version = "0.2.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db40892a506901e4e8281f00e42687df82d1d3448cb0289ae9183a60cb42ec1" +checksum = "b083214486dae00f49a2f21f32fc8bbc333d6048601bc89203a8ab92bfa691f0" dependencies = [ "blake2 0.10.6", "rand_core", "sha2", + "sha3 0.10.8", ] [[package]] @@ -355,14 +359,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a011bbe2c35ce9c1f143b7af6f94f29a167beb4cd1d29e6740ce836f723120e" dependencies = [ "nix", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "dashmap" -version = "5.5.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" +checksum = "edd72493923899c6f10c641bdbdeddc7183d6396641d99c1a0d1597f37f92e28" dependencies = [ "cfg-if", "hashbrown 0.14.0", @@ -374,7 +378,7 @@ dependencies = [ [[package]] name = "dashu" version = "0.3.1" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" dependencies = [ "dashu-base", "dashu-float", @@ -386,12 +390,12 @@ dependencies = [ [[package]] name = "dashu-base" version = "0.3.1" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" [[package]] name = "dashu-float" version = "0.3.2" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" dependencies = [ "dashu-base", "dashu-int", @@ -403,11 +407,11 @@ dependencies = [ [[package]] name = "dashu-int" version = "0.3.1" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" dependencies = [ "cfg-if", "dashu-base", - "num-modular 0.6.0", + "num-modular 0.5.2", "num-order", "num-traits", "static_assertions", @@ -416,7 +420,7 @@ dependencies = [ [[package]] name = "dashu-macros" version = "0.3.1" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" dependencies = [ "dashu-base", "dashu-float", @@ -429,7 +433,7 @@ dependencies = [ [[package]] name = "dashu-ratio" version = "0.3.2" -source = "git+https://github.com/coasys/dashu.git#ae7ee53fad213e09da5fe4b30e9e9e8bce96aedd" +source = "git+https://github.com/coasys/dashu.git#f9342190be9062630124e666b001077bb5f02f23" dependencies = [ "dashu-base", "dashu-float", @@ -508,26 +512,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" -[[package]] -name = "ed25519" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" -dependencies = [ - "signature", -] - [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] @@ -540,13 +535,13 @@ checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] name = "errno" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -571,12 +566,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" [[package]] name = "fd-lock" @@ -585,8 +577,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" dependencies = [ "cfg-if", - "rustix 0.38.1", - "windows-sys 0.48.0", + "rustix", + "windows-sys", ] [[package]] @@ -691,7 +683,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", ] [[package]] @@ -759,15 +751,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "git-version" @@ -793,9 +787,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -833,9 +827,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "home" @@ -843,7 +837,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -924,9 +918,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" @@ -945,7 +939,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -954,12 +948,13 @@ dependencies = [ [[package]] name = "hyper" -version = "1.0.0-rc.4" +version = "1.0.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d280a71f348bcc670fc55b02b63c53a04ac0bf2daff2980795aeaf53edae10e6" +checksum = "7b75264b2003a3913f118d35c586e535293b3e22e41f074930762929d071e092" dependencies = [ "bytes", "futures-channel", + "futures-core", "futures-util", "h2", "http", @@ -986,24 +981,6 @@ dependencies = [ "tokio-native-tls", ] -[[package]] -name = "hyper-util" -version = "0.0.0" -source = "git+https://github.com/hyperium/hyper-util.git#f898015fc9eca9f459ddac521db278d904099e89" -dependencies = [ - "futures-channel", - "futures-util", - "http", - "hyper 1.0.0-rc.4", - "once_cell", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - [[package]] name = "iana-time-zone" version = "0.1.57" @@ -1056,17 +1033,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.8.0" @@ -1084,9 +1050,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" @@ -1168,29 +1134,11 @@ dependencies = [ "winapi", ] -[[package]] -name = "libsodium-sys" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b779387cd56adfbc02ea4a668e704f729be8d6a6abd2c27ca5ee537849a92fd" -dependencies = [ - "cc", - "libc", - "pkg-config", - "walkdir", -] - [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "linux-raw-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -1204,9 +1152,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "mac" @@ -1266,9 +1214,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] @@ -1294,7 +1242,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1360,14 +1308,13 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "abbbc55ad7b13aac85f9401c796dcda1b864e07fcad40ad47792eaa8932ea502" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "libc", - "static_assertions", ] [[package]] @@ -1401,8 +1348,8 @@ dependencies = [ [[package]] name = "num-modular" -version = "0.6.0" -source = "git+https://github.com/coasys/num-modular.git#87d6dc30600207445e07c2cc84e0a47ff58f0aca" +version = "0.5.2" +source = "git+https://github.com/coasys/num-modular.git#1ae06248ec69390370def3a229b3bf4c209aa6c7" [[package]] name = "num-order" @@ -1416,9 +1363,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] @@ -1435,9 +1382,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.4" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" dependencies = [ "memchr", ] @@ -1456,11 +1403,11 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.55" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -1477,7 +1424,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", ] [[package]] @@ -1488,9 +1435,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.90" +version = "0.9.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" +checksum = "db7e971c2c2bba161b2d2fdf37080177eff520b3bc044787c7f1f5f9e78d869b" dependencies = [ "cc", "libc", @@ -1643,31 +1590,11 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1728,18 +1655,18 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1862,11 +1789,11 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "encoding_rs", "futures-core", @@ -1912,6 +1839,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "ring-wasi" +version = "0.16.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db1418b2535ed5e71a9fc73d3fede8596792fd7cb4b4a0f8ecf412cfddaaedd4" +dependencies = [ + "cc", + "getrandom", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "ripemd160" version = "0.8.0" @@ -1940,36 +1883,22 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.37.21" +version = "0.38.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25693a73057a1b4cb56179dd3c7ea21a7c6c5ee7d85781f5749b46f34b79c" +checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - -[[package]] -name = "rustix" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc6396159432b5c8490d4e301d8c705f61860b8b6c863bf79942ce5401968f3" -dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.3", - "windows-sys 0.48.0", + "linux-raw-sys", + "windows-sys", ] [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "rustyline" @@ -1977,7 +1906,7 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "994eca4bca05c87e86e15d90fc7a91d1be64b4482b38cb2d27474568fe7c9db9" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "cfg-if", "clipboard-win", "fd-lock", @@ -1996,9 +1925,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "same-file" @@ -2011,22 +1940,22 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys 0.42.0", + "windows-sys", ] [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scryer-prolog" -version = "0.9.1" +version = "0.9.2" dependencies = [ "assert_cmd", "base64 0.12.3", @@ -2045,11 +1974,11 @@ dependencies = [ "divrem", "futures", "fxhash", + "getrandom", "git-version", "hostname", "http-body-util", - "hyper 1.0.0-rc.4", - "hyper-util", + "hyper 1.0.0-rc.3", "indexmap", "lazy_static", "lexical", @@ -2069,15 +1998,15 @@ dependencies = [ "regex", "reqwest", "ring", + "ring-wasi", "ripemd160", "roxmltree", "rustyline", "ryu", "select", "serial_test", - "sha3", + "sha3 0.8.2", "smallvec", - "sodiumoxide", "static_assertions", "strum", "strum_macros", @@ -2090,9 +2019,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -2103,9 +2032,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -2124,15 +2053,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.174" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b88756493a5bd5e5395d53baa70b194b05764ab85b59e43e4b8f4e1192fa9b1" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", +] [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" dependencies = [ "itoa", "ryu", @@ -2173,7 +2116,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", ] [[package]] @@ -2201,10 +2144,20 @@ dependencies = [ ] [[package]] -name = "signal-hook" -version = "0.3.15" +name = "sha3" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" dependencies = [ "libc", "signal-hook-registry", @@ -2230,32 +2183,26 @@ dependencies = [ "libc", ] -[[package]] -name = "signature" -version = "1.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" - [[package]] name = "siphasher" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -2268,15 +2215,13 @@ dependencies = [ ] [[package]] -name = "sodiumoxide" -version = "0.2.7" +name = "socket2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e26be3acb6c2d9a7aac28482586a7856436af4cfe7100031d219de2d2ecb0028" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" dependencies = [ - "ed25519", "libc", - "libsodium-sys", - "serde", + "windows-sys", ] [[package]] @@ -2367,9 +2312,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" dependencies = [ "proc-macro2", "quote", @@ -2384,16 +2329,15 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.6.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "autocfg", "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.21", - "windows-sys 0.48.0", + "rustix", + "windows-sys", ] [[package]] @@ -2415,22 +2359,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", ] [[package]] @@ -2482,11 +2426,10 @@ dependencies = [ [[package]] name = "tokio" -version = "1.29.0" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374442f06ee49c3a28a8fc9f01a2596fed7559c6b99b31279c3261778e77d84f" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -2495,9 +2438,9 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.3", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2508,7 +2451,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", ] [[package]] @@ -2535,28 +2478,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - [[package]] name = "tower-service" version = "0.3.2" @@ -2570,7 +2491,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", - "log", "pin-project-lite", "tracing-core", ] @@ -2604,9 +2524,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-normalization" @@ -2731,7 +2651,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", "wasm-bindgen-shared", ] @@ -2765,7 +2685,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.29", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2826,21 +2746,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -2852,110 +2757,69 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f594f3f4..47a412f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.9.1" +version = "0.9.2" authors = ["Mark Thom "] edition = "2021" description = "A modern Prolog implementation written mostly in Rust." @@ -14,6 +14,12 @@ rust-version = "1.63" [features] multi_thread = [] +default = ["ffi", "repl", "hostname", "tls", "http"] +ffi = ["dep:libffi"] +repl = ["dep:crossterm", "dep:ctrlc", "dep:rustyline"] +hostname = ["dep:hostname"] +tls = ["dep:native-tls"] +http = ["dep:hyper", "dep:reqwest"] [build-dependencies] indexmap = "1.0.2" @@ -30,50 +36,59 @@ walkdir = "2" bit-set = "0.5.3" bitvec = "1" cpu-time = "1.0.0" -crossterm = "0.20.0" dirs-next = "2.0.0" divrem = "0.1.0" fxhash = "0.2.1" git-version = "0.3.4" -hostname = "0.3.1" indexmap = "1.0.2" lazy_static = "1.4.0" lexical = "5.2.2" libc = "0.2.62" modular-bitfield = "0.11.2" -ctrlc = "3.2.2" ordered-float = "2.6.0" phf = { version = "0.9", features = ["macros"] } ref_thread_local = "0.0.0" -rustyline = "12.0.0" -ring = "0.16.13" ripemd160 = "0.8.0" sha3 = "0.8.2" blake2 = "0.8.1" -crrl = "0.2.0" -native-tls = "0.2.4" +crrl = "0.6.0" chrono = "0.4.11" select = "0.6.0" roxmltree = "0.11.0" base64 = "0.12.3" smallvec = "1.8.0" -sodiumoxide = "0.2.6" static_assertions = "1.1.0" ryu = "1.0.9" -hyper = { version = "1.0.0-rc.4", features = ["full"] } -hyper-util = { git = "https://github.com/hyperium/hyper-util.git" } -tokio = { version = "1.28.2", features = ["full"] } futures = "0.3" regex = "1.9.1" libloading = "0.7" derive_deref = "1.1.1" http-body-util = "0.1.0-rc.2" bytes = "1" -reqwest = { version = "0.11.18", features = ["blocking"] } -dashu = { git = "https://github.com/coasys/dashu.git" } -libffi = { git = "https://github.com/coasys/libffi-rs.git", branch = "windows-space" } +dashu = { git = "https://github.com/coasys/dashu.git", version = "0.3.1" } rand = "0.8.5" +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +libffi = { git = "https://github.com/coasys/libffi-rs.git", branch = "windows-space", optional = true, version = "3.2.0" } +hostname = { version = "0.3.1", optional = true } +crossterm = { version = "0.20.0", optional = true } +ctrlc = { version = "3.2.2", optional = true } +rustyline = { version = "12.0.0", optional = true } +native-tls = { version = "0.2.4", optional = true } +hyper = { version = "=1.0.0-rc.3", features = ["full"], optional = true } +reqwest = { version = "0.11.18", features = ["blocking"], optional = true } +tokio = { version = "1.28.2", features = ["full"] } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2.10", features = ["js"] } +tokio = { version = "1.28.2", features = ["sync", "macros", "io-util", "rt", "time"] } + +[target.'cfg(target_os = "wasi")'.dependencies] +ring-wasi = { version = "0.16.25" } + +[target.'cfg(not(target_os = "wasi"))'.dependencies] +ring = { version = "0.16.13" } + [dev-dependencies] assert_cmd = "1.0.3" predicates-core = "1.0.2" diff --git a/build/instructions_template.rs b/build/instructions_template.rs index 3ac76eff..52fcd8b7 100644 --- a/build/instructions_template.rs +++ b/build/instructions_template.rs @@ -99,6 +99,8 @@ enum BuiltInClauseType { Ground, #[strum_discriminants(strum(props(Arity = "2", Name = "is")))] Is(RegType, ArithmeticTerm), + #[strum_discriminants(strum(props(Arity = "1", Name = "$get_number")))] + GetNumber(ArithmeticTerm), #[strum_discriminants(strum(props(Arity = "2", Name = "keysort")))] KeySort, #[strum_discriminants(strum(props(Arity = "2", Name = "sort")))] @@ -1553,7 +1555,8 @@ fn generate_instruction_preface() -> TokenStream { &Instruction::CallFunctor | &Instruction::CallGround | &Instruction::CallKeySort | - &Instruction::CallSort => { + &Instruction::CallSort | + &Instruction::CallGetNumber(_) => { let (name, arity) = self.to_name_and_arity(); functor!(atom!("call"), [atom(name), fixnum(arity)]) } @@ -1578,7 +1581,8 @@ fn generate_instruction_preface() -> TokenStream { &Instruction::ExecuteGround | &Instruction::ExecuteIs(..) | &Instruction::ExecuteKeySort | - &Instruction::ExecuteSort => { + &Instruction::ExecuteSort | + &Instruction::ExecuteGetNumber(_) => { let (name, arity) = self.to_name_and_arity(); functor!(atom!("execute"), [atom(name), fixnum(arity)]) } @@ -1603,7 +1607,8 @@ fn generate_instruction_preface() -> TokenStream { &Instruction::DefaultCallGround | &Instruction::DefaultCallIs(..) | &Instruction::DefaultCallKeySort | - &Instruction::DefaultCallSort => { + &Instruction::DefaultCallSort | + &Instruction::DefaultCallGetNumber(_) => { let (name, arity) = self.to_name_and_arity(); functor!(atom!("call_default"), [atom(name), fixnum(arity)]) } @@ -1628,7 +1633,8 @@ fn generate_instruction_preface() -> TokenStream { &Instruction::DefaultExecuteGround | &Instruction::DefaultExecuteIs(..) | &Instruction::DefaultExecuteKeySort | - &Instruction::DefaultExecuteSort => { + &Instruction::DefaultExecuteSort | + &Instruction::DefaultExecuteGetNumber(_) => { let (name, arity) = self.to_name_and_arity(); functor!(atom!("execute_default"), [atom(name), fixnum(arity)]) } diff --git a/build/static_string_indexing.rs b/build/static_string_indexing.rs index ca5ac765..15f0441f 100644 --- a/build/static_string_indexing.rs +++ b/build/static_string_indexing.rs @@ -150,7 +150,7 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea Err(_) => {} } - let indices = (0..visitor.static_strs.len()).map(|i| i << 3); + let indices = (0..visitor.static_strs.len()).map(|i| (i << 3) as u64); let indices_iter = indices.clone(); let static_strs_len = visitor.static_strs.len(); diff --git a/src/arena.rs b/src/arena.rs index 66b5c27b..9434b28d 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "http")] use crate::http::{HttpListener, HttpResponse}; use crate::machine::loader::LiveLoadState; use crate::machine::machine_indices::*; @@ -306,12 +307,16 @@ pub trait ArenaAllocated: Sized { fn copy_to_arena(self, dst: *mut Self) -> Self::PtrToAllocated; fn header_offset_from_payload() -> usize { - mem::size_of::<*const ArenaHeader>() + mem::size_of::() } unsafe fn alloc(arena: &mut Arena, value: Self) -> Self::PtrToAllocated { let size = value.size() + mem::size_of::(); + #[cfg(target_pointer_width="32")] + let align = mem::align_of::() * 2; + + #[cfg(target_pointer_width="64")] let align = mem::align_of::(); let layout = alloc::Layout::from_size_align_unchecked(size, align); @@ -566,6 +571,7 @@ impl ArenaAllocated for TcpListener { } } +#[cfg(feature = "http")] impl ArenaAllocated for HttpListener { type PtrToAllocated = TypedArenaPtr; @@ -588,6 +594,7 @@ impl ArenaAllocated for HttpListener { } } +#[cfg(feature = "http")] impl ArenaAllocated for HttpResponse { type PtrToAllocated = TypedArenaPtr; @@ -653,9 +660,12 @@ impl ArenaAllocated for IndexPtr { } } +#[repr(C)] #[derive(Clone, Copy, Debug)] struct AllocSlab { next: *mut AllocSlab, + #[cfg(target_pointer_width="32")] + _padding: u32, header: ArenaHeader, } @@ -695,12 +705,15 @@ unsafe fn drop_slab_in_place(value: &mut AllocSlab) { ptr::drop_in_place(value.payload_offset::>>()); } ArenaHeaderTag::NamedTlsStream => { + #[cfg(feature = "tls")] ptr::drop_in_place(value.payload_offset::>>()); } ArenaHeaderTag::HttpReadStream => { + #[cfg(feature = "http")] ptr::drop_in_place(value.payload_offset::>>()); } ArenaHeaderTag::HttpWriteStream => { + #[cfg(feature = "http")] ptr::drop_in_place(value.payload_offset::>>()); } ArenaHeaderTag::ReadlineStream => { @@ -724,9 +737,11 @@ unsafe fn drop_slab_in_place(value: &mut AllocSlab) { ptr::drop_in_place(value.payload_offset::()); } ArenaHeaderTag::HttpListener => { + #[cfg(feature = "http")] ptr::drop_in_place(value.payload_offset::()); } ArenaHeaderTag::HttpResponse => { + #[cfg(feature = "http")] ptr::drop_in_place(value.payload_offset::()); } ArenaHeaderTag::StandardOutputStream => { @@ -819,6 +834,12 @@ mod tests { #[test] fn heap_cell_value_const_cast() { let mut wam = MockWAM::new(); + #[cfg(target_pointer_width="32")] + let const_value = HeapCellValue::from(ConsPtr::build_with( + 0x0000_0431 as *const _, + ConsPtrMaskTag::Cons, + )); + #[cfg(target_pointer_width="64")] let const_value = HeapCellValue::from(ConsPtr::build_with( 0x0000_5555_ff00_0431 as *const _, ConsPtrMaskTag::Cons, @@ -826,7 +847,7 @@ mod tests { match const_value.to_untyped_arena_ptr() { Some(arena_ptr) => { - assert_eq!(arena_ptr.into_bytes(), const_value.into_bytes()); + assert_eq!(arena_ptr.into_bytes(), const_value.to_untyped_arena_ptr_bytes()); } None => { assert!(false); @@ -839,7 +860,7 @@ mod tests { match stream_cell.to_untyped_arena_ptr() { Some(arena_ptr) => { - assert_eq!(arena_ptr.into_bytes(), stream_cell.into_bytes()); + assert_eq!(arena_ptr.into_bytes(), stream_cell.to_untyped_arena_ptr_bytes()); } None => { assert!(false); @@ -1093,7 +1114,7 @@ mod tests { read_heap_cell!(cell, (HeapCellValueTag::Atom, (el, _arity)) => { - assert_eq!(el.flat_index() as usize, empty_list_as_cell!().get_value()); + assert_eq!(el.flat_index(), empty_list_as_cell!().get_value()); assert_eq!(el.as_str(), "[]"); } _ => { unreachable!() } diff --git a/src/atom_table.rs b/src/atom_table.rs index bb7b56cf..087a9e20 100644 --- a/src/atom_table.rs +++ b/src/atom_table.rs @@ -16,7 +16,7 @@ use modular_bitfield::prelude::*; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Atom { - pub index: usize, + pub index: u64, } const_assert!(mem::size_of::() == 8); @@ -156,7 +156,7 @@ impl Atom { #[inline(always)] pub fn is_static(self) -> bool { - self.index < STRINGS.len() << 3 + (self.index as usize) < STRINGS.len() << 3 } #[inline(always)] @@ -164,19 +164,19 @@ impl Atom { if self.is_static() { ptr::null() } else { - (get_atom_tbl_buf_base() as usize + self.index - (STRINGS.len() << 3)) as *const u8 + (get_atom_tbl_buf_base() as usize + (self.index as usize) - (STRINGS.len() << 3)) as *const u8 } } #[inline(always)] - pub fn from(index: usize) -> Self { + pub fn from(index: u64) -> Self { Self { index } } #[inline(always)] pub fn len(self) -> usize { if self.is_static() { - STRINGS[self.index >> 3].len() + STRINGS[(self.index >> 3) as usize].len() } else { unsafe { ptr::read(self.as_ptr() as *const AtomHeader).len() as _ } } @@ -208,7 +208,7 @@ impl Atom { let ptr = self.as_ptr(); if ptr.is_null() { - return STRINGS[self.index >> 3]; + return STRINGS[(self.index >> 3) as usize]; } let header = ptr::read::(ptr as *const _); @@ -339,7 +339,7 @@ impl AtomTable { write_to_ptr(string, len_ptr); let atom = Atom { - index: (STRINGS.len() << 3) + len_ptr as usize - ptr_base, + index: ((STRINGS.len() << 3) + len_ptr as usize - ptr_base) as u64, }; self.table.insert(atom); @@ -386,7 +386,7 @@ impl AtomCell { #[inline] pub fn get_name(self) -> Atom { - Atom::from(self.get_index() << 3) + Atom::from((self.get_index() as u64) << 3) } #[inline] @@ -396,6 +396,6 @@ impl AtomCell { #[inline] pub fn get_name_and_arity(self) -> (Atom, usize) { - (Atom::from(self.get_index() << 3), self.get_arity()) + (Atom::from((self.get_index() as u64) << 3), self.get_arity()) } } diff --git a/src/bin/scryer-prolog.rs b/src/bin/scryer-prolog.rs index da462526..01291652 100644 --- a/src/bin/scryer-prolog.rs +++ b/src/bin/scryer-prolog.rs @@ -3,10 +3,18 @@ fn main() -> std::process::ExitCode { use scryer_prolog::*; use scryer_prolog::atom_table::Atom; + #[cfg(feature = "repl")] ctrlc::set_handler(move || { scryer_prolog::machine::INTERRUPT.store(true, Ordering::Relaxed); }).unwrap(); + #[cfg(target_os = "wasi")] + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + + #[cfg(not(target_os = "wasi"))] let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() .build() diff --git a/src/codegen.rs b/src/codegen.rs index 7d4b92d3..4902a618 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -804,17 +804,44 @@ impl<'b> CodeGenerator<'b> { &Term::Var(ref vr, ref name) => { let var_num = name.to_var_num().unwrap(); - self.marker.mark_var::( - var_num, - Level::Shallow, - vr, - term_loc, - code, - ); + if self.marker.var_data.records[var_num].num_occurrences > 1 { + self.marker.mark_var::( + var_num, + Level::Shallow, + vr, + term_loc, + code, + ); - self.marker.mark_safe_var_unconditionally(var_num); + self.marker.mark_safe_var_unconditionally(var_num); + compile_expr!(self, &terms[1], term_loc, code) + } else { + if let Term::Var(ref vr, ref var) = &terms[1] { + let var_num = var.to_var_num().unwrap(); - compile_expr!(self, &terms[1], term_loc, code) + // if var is an anonymous variable, insert + // is/2 call so that an instantiation error is + // thrown when the predicate is run. + if self.marker.var_data.records[var_num].num_occurrences > 1 { + self.marker.mark_var::( + var_num, + Level::Shallow, + vr, + term_loc, + code, + ); + + self.marker.mark_safe_var_unconditionally(var_num); + + let at = ArithmeticTerm::Reg(vr.get().norm()); + self.add_call(code, instr!("$get_number", at), call_policy); + + return Ok(()); + } + } + + compile_expr!(self, &terms[1], term_loc, code) + } } &Term::Literal(_, c @ Literal::Integer(_) | c @ Literal::Float(_) | diff --git a/src/lib.rs b/src/lib.rs index 81d8d56e..abd9d873 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,11 +17,13 @@ mod allocator; mod arithmetic; pub mod codegen; mod debray_allocator; +#[cfg(feature = "ffi")] mod ffi; mod variable_records; mod forms; mod heap_iter; pub mod heap_print; +#[cfg(feature = "http")] mod http; mod indexing; #[macro_use] @@ -32,6 +34,7 @@ mod iterators; pub mod machine; mod raw_block; pub mod read; +#[cfg(feature = "repl")] mod repl_helper; mod targets; pub mod types; diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index ed01f079..d560f675 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -119,7 +119,7 @@ :- use_module(library(iso_ext)). :- use_module(library(dcgs)). :- use_module(library(terms)). -:- use_module(library(error), [domain_error/3, type_error/3]). +:- use_module(library(error), [domain_error/3, type_error/3, can_be/2]). :- use_module(library(si)). :- use_module(library(freeze)). :- use_module(library(arithmetic)). @@ -838,12 +838,12 @@ Using suitable labeling strategies, we can easily find solutions with ``` ?- n_queens(80, Qs), labeling([ff], Qs). - Qs = [1,3,5,44,42,4,50,7,68,57,76,61,6,39,30,40,8,54,36,41,...] + Qs = [1,3,5,44,42,4,50,7,68,57,76,61,6,39,30,40,8,54,36,41|...] ; ... . ?- time((n_queens(90, Qs), labeling([ff], Qs))). - % CPU time: 31.351s - Qs = [1,3,5,50,42,4,49,7,59,48,46,63,6,55,47,64,8,70,58,67,...] + % CPU time: 2.382s + Qs = [1,3,5,50,42,4,49,7,59,48,46,63,6,55,47,64,8,70,58,67|...] ; ... . ``` @@ -1745,11 +1745,7 @@ clpz_in(V, D) :- drep_to_domain(D, Dom), domain(V, Dom). -fd_variable(V) :- - ( var(V) -> true - ; integer(V) -> true - ; type_error(integer, V) - ). +fd_variable(V) :- can_be(integer, V). %% ins(+Vars, +Domain) % @@ -2219,14 +2215,14 @@ all_different(Ls) :- fd_must_be_list(Ls, all_different(Ls)-1), maplist(fd_variable, Ls), Orig = original_goal(_, all_different(Ls)), - all_different(Ls, [], Orig), - do_queue. + new_queue(Q0), + phrase((all_different(Ls, [], Orig),do_queue), [Q0], _). -all_different([], _, _). -all_different([X|Right], Left, Orig) :- - ( var(X) -> - make_propagator(pdifferent(Left,Right,X,Orig), Prop), - init_propagator(X, Prop), +all_different([], _, _) --> []. +all_different([X|Right], Left, Orig) --> + ( { var(X) } -> + { make_propagator(pdifferent(Left,Right,X,Orig), Prop) }, + init_propagator_([X], Prop), trigger_prop(Prop) ; exclude_fire(Left, Right, X) ), @@ -2250,7 +2246,8 @@ all_distinct(Ls) :- maplist(fd_variable, Ls), make_propagator(pdistinct(Ls), Prop), new_queue(Q0), - phrase((distinct_attach(Ls, Prop, []),trigger_prop(Prop),do_queue), [Q0], _). + phrase((distinct_attach(Ls, Prop, []),trigger_prop(Prop),do_queue), [Q0], _), + variables_same_queue(Ls). %% nvalue(?N, +Vars). % @@ -2639,22 +2636,28 @@ parse_goals([G|Gs]) --> parse_goal(G), parse_goals(Gs). parse_goal(g(Goal)) --> [Goal]. parse_goal(p(Prop)) --> - [make_propagator(Prop, P)], { term_variables(Prop, Vs) }, - parse_init(Vs, P), - [trigger_once(P)]. + [make_propagator(Prop, P), + new_queue(Q0), + phrase(init_propagator_(Vs, P), [Q0], [Q]), + variables_same_queue(Vs), + trigger_once_(P, Q)]. -parse_init([], _) --> []. -parse_init([V|Vs], P) --> [init_propagator(V, P)], parse_init(Vs, P). - -%?- set_prolog_flag(answer_write_options, [portray(true)]), -% clpz:parse_clpz_clauses(Clauses), maplist(portray_clause, Clauses). +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +?- use_module(library(lists)), + use_module(library(format)), + clpz:parse_clpz_clauses(Clauses), + maplist(portray_clause, Clauses). +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% trigger_once(Prop) :- new_queue(Q), + trigger_once_(Prop, Q). + +trigger_once_(Prop, Q) :- phrase((trigger_prop(Prop),do_queue), [Q], _). neq(A, B) :- propagator_init_trigger(pneq(A, B)). @@ -2666,19 +2669,41 @@ propagator_init_trigger(P) --> propagator_init_trigger(Vs, P) --> [p(Prop)], { make_propagator(P, Prop), - maplist(prop_init(Prop), Vs), + new_queue(Q0), + phrase(init_propagator_(Vs, Prop), [Q0], [Q]), variables_same_queue(Vs), - trigger_once(Prop) }. + trigger_once_(Prop, Q) }. variables_same_queue(Vs0) :- include(var, Vs0, Vs), - new_queue(Q), - maplist(variable_queue, Vs, Qs), - phrase((collect_goal(Qs), - collect_fast(Qs), - collect_slow(Qs)), [Q], [Q]), - maplist(clear_queue, Qs), - maplist(=(Q), Qs). + ( Vs == [] -> true + ; maplist(variable_queue, Vs, Qs0), + sort(Qs0, [Q|Qs]), + Q =.. [_|Args], + append_queues_(Qs, Args, [append,append,append,ignore]), + maplist(clear_queue, Qs), + maplist(=(Q), Qs) + ). + +append_queues_([], _, _). +append_queues_([Q|Qs], Args0, Is) :- + Q =.. [_|Args], + maplist(append_queue, Is, Args0, Args), + append_queues_(Qs, Args, Is). + +append_queue(ignore, _, _). +append_queue(append, Q0, Q) :- + ( get_atts(Q0, queue(Ls0,Ls)) -> + ( get_atts(Q, queue(Ms0,Ms)) -> + Ls = Ms0, + put_atts(Q0, queue(Ls0,Ms)) + ; true + ) + ; ( get_atts(Q, queue(Ms0,Ms)) -> + put_atts(Q0, queue(Ms0,Ms)) + ; true + ) + ). clear_queue(queue(Goals,Fast,Slow,Aux)) :- put_atts(Goals, -queue(_,_)), @@ -2686,22 +2711,6 @@ clear_queue(queue(Goals,Fast,Slow,Aux)) :- put_atts(Slow, -queue(_,_)), put_atts(Aux, -disabled). -collect_goal(Qs) --> collect_arg(Qs, 1). -collect_fast(Qs) --> collect_arg(Qs, 2). -collect_slow(Qs) --> collect_arg(Qs, 3). - -collect_arg([], _) --> []. -collect_arg([Q|Qs], Which) --> - collect_all_(Q, Which), - collect_arg(Qs, Which). - -collect_all_(Q, Which) --> - ( { queue_get_arg_(Q, Which, Element) } -> - insert_queue(Element, Which), - collect_all_(Q, Which) - ; [] - ). - variable_queue(Var, Q) :- get_attr(Var, clpz, Attr), Attr = clpz_attr(_Left,_Right,_Spread,_Dom,_Ps,Q). @@ -2813,7 +2822,7 @@ matches([ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% m(var(X) #\= integer(Y)) => [g(neq_num(X, Y))], - m(var(X) #\= var(Y)) => [g(neq(X,Y))], + m(var(X) #\= var(Y)) => [p(pneq(X,Y))], m(var(X) #\= var(Y) + var(Z)) => [p(x_neq_y_plus_z(X, Y, Z))], m(var(X) #\= var(Y) - var(Z)) => [p(x_neq_y_plus_z(Y, X, Z))], m(var(X) #\= var(Y)*var(Z)) => [p(ptimes(Y,Z,P)), g(neq(X,P))], @@ -2898,10 +2907,12 @@ match_goal(r(X,Y), F) --> { G =.. [F,X,Y] }, [G]. match_goal(d(X,Y), _) --> [parse_clpz(X, Y)]. match_goal(g(Goal), _) --> [Goal]. match_goal(p(Prop), _) --> - [make_propagator(Prop, P)], { term_variables(Prop, Vs) }, - parse_init(Vs, P), - [trigger_once(P)]. + [make_propagator(Prop, P), + new_queue(Q0), + phrase(init_propagator_(Vs, P), [Q0], [Q]), + variables_same_queue(Vs), + trigger_once_(P, Q)]. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -3753,8 +3764,10 @@ kill_reified_tuples([B|Bs], Ps, All) --> relation_tuple_b_prop(Relation, Tuple, B, p(Prop)) :- put_attr(R, clpz_relation, Relation), make_propagator(reified_tuple_in(Tuple, R, B), Prop), - tuple_freeze_(Tuple, Prop), - init_propagator(B, Prop). + new_queue(Q0), + phrase((tuple_freeze_(Tuple, Prop), + init_propagator_([B], Prop), + do_queue), [Q0], _). tuples_in_conjunction(Tuples, Relation, Conj) :- @@ -3960,7 +3973,7 @@ insert_queue(Element, Which) --> Tail0 = [Element|Tail] ; Head = [Element|Tail] ), - put_atts(Arg, +queue(Head,Tail)) }. + put_atts(Arg, queue(Head,Tail)) }. domain_spread(Dom, Spread) :- @@ -4192,9 +4205,9 @@ ignore(Goal) :- ( Goal -> true ; true ). print_queue --> state(queue(Goal,Fast,Slow,_)), - { ignore(get_atts(Goal, +queue(GHs,_))), - ignore(get_atts(Fast, +queue(FHs,_))), - ignore(get_atts(Slow, +queue(SHs,_))), + { ignore(get_atts(Goal, queue(GHs,_))), + ignore(get_atts(Fast, queue(FHs,_))), + ignore(get_atts(Slow, queue(SHs,_))), format("Current queue:~n goal: ~q~n fast: ~q~n slow: ~q~n~n", [GHs,FHs,SHs]) }. @@ -4209,18 +4222,27 @@ queue_get_arg(Which, Element) --> queue_get_arg_(Queue, Which, Element) :- arg(Which, Queue, Arg), - get_atts(Arg, +queue([Element|Elements],Tail)), + get_atts(Arg, queue([Element|Elements],Tail)), ( var(Elements) -> put_atts(Arg, -queue(_,_)) - ; put_atts(Arg, +queue(Elements,Tail)) + ; put_atts(Arg, queue(Elements,Tail)) ). queue_enabled --> state(queue(_,_,_,Aux)), { \+ get_atts(Aux, disabled) }. -disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, +disabled) }. +disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, disabled) }. enable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, -disabled) }. portray_propagator(propagator(P,_), F) :- functor(P, F, _). +init_propagator_([], _) --> []. +init_propagator_([V|Vs], Prop) --> + ( { fd_get(V, Dom, Ps0) } -> + { insert_propagator(Prop, Ps0, Ps) }, + fd_put(V, Dom, Ps) + ; [] + ), + init_propagator_(Vs, Prop). + init_propagator(Var, Prop) :- ( fd_get(Var, Dom, Ps0) -> insert_propagator(Prop, Ps0, Ps), @@ -4343,17 +4365,22 @@ tuples_in(Tuples, Relation) :- must_be(list(list), Tuples), maplist(maplist(fd_variable), Tuples), must_be(list(list(integer)), Relation), - maplist(relation_tuple(Relation), Tuples). + new_queue(Q0), + phrase(tuples_relation(Tuples, Relation), [Q0], [Q]), + append(Tuples, Vs), + variables_same_queue(Vs), + phrase(do_queue, [Q], _). -relation_tuple(Relation, Tuple) :- - relation_unifiable(Relation, Tuple, Us, _, _), - ( ground(Tuple) -> memberchk(Tuple, Relation) - ; new_queue(Q), - phrase((tuple_domain(Tuple, Us),do_queue), [Q], _), +tuples_relation([], _) --> []. +tuples_relation([Tuple|Tuples], Relation) --> + { relation_unifiable(Relation, Tuple, Us, _, _) }, + ( ground(Tuple) -> { memberchk(Tuple, Relation) } + ; tuple_domain(Tuple, Us), ( Tuple = [_,_|_] -> tuple_freeze(Tuple, Us) - ; true + ; [] ) - ). + ), + tuples_relation(Tuples, Relation). list_first_rest([L|Ls], L, Ls). @@ -4371,19 +4398,19 @@ tuple_domain([T|Ts], Relation0) --> ), tuple_domain(Ts, Relation1). -tuple_freeze(Tuple, Relation) :- - ( ground(Tuple) -> memberchk(Tuple, Relation) - ; put_attr(R, clpz_relation, Relation), - make_propagator(rel_tuple(R, Tuple), Prop), +tuple_freeze(Tuple, Relation) --> + ( ground(Tuple) -> { memberchk(Tuple, Relation) } + ; { put_attr(R, clpz_relation, Relation), + make_propagator(rel_tuple(R, Tuple), Prop) }, tuple_freeze_(Tuple, Prop) ). -tuple_freeze_([], _). -tuple_freeze_([T|Ts], Prop) :- +tuple_freeze_([], _) --> []. +tuple_freeze_([T|Ts], Prop) --> ( var(T) -> - init_propagator(T, Prop), + init_propagator_([T], Prop), trigger_prop(Prop) - ; true + ; [] ), tuple_freeze_(Ts, Prop). @@ -5993,9 +6020,9 @@ max_factor(L1, U1, L2, U2, Max) :- distinct_attach([], _, _) --> []. distinct_attach([X|Xs], Prop, Right) --> ( var(X) -> - { init_propagator(X, Prop), - make_propagator(pexclude(Xs,Right,X), P1), - init_propagator(X, P1) }, + init_propagator_([X], Prop), + { make_propagator(pexclude(Xs,Right,X), P1) }, + init_propagator_([X], P1), trigger_prop(P1) ; exclude_fire(Xs, Right, X) ), @@ -7488,9 +7515,15 @@ zcompare(Order, A, B) :- propagator_init_trigger([A,B], pzcompare(Order, A, B)) ). -zcompare_(=, A, B) :- #A #= #B. -zcompare_(<, A, B) :- #A #< #B. -zcompare_(>, A, B) :- #A #> #B. +zcompare_(O, A, B) :- + ( member(O, "<=>") -> true + ; domain_error(order, O, zcompare/3) + ), + zcompare__(O, A, B). + +zcompare__(=, A, B) :- #A #= #B. +zcompare__(<, A, B) :- #A #< #B. +zcompare__(>, A, B) :- #A #> #B. %% chain(+Relation, +Zs) % diff --git a/src/lib/crypto.pl b/src/lib/crypto.pl index 71c0420e..bec12d51 100644 --- a/src/lib/crypto.pl +++ b/src/lib/crypto.pl @@ -711,6 +711,8 @@ curve25519_scalar_mult(Scalar, Point, Result) :- must_be_bytes(ScalarBytes, curve25519_scalar_mult/3), length(ScalarBytes, 32) ), + must_be(chars, Point), + length(Point, 32), maplist(char_code, Point, PointBytes), '$curve25519_scalar_mult'(ScalarBytes, PointBytes, Result). diff --git a/src/lib/format.pl b/src/lib/format.pl index 32ad2ff9..9280156f 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -526,7 +526,7 @@ var_name(V, Name=V, Num0, Num) :- Num is Num0 + 1. literal(Lit, VNs) --> - { write_term_to_chars(Lit, [quoted(true),variable_names(VNs)], Ls) }, + { write_term_to_chars(Lit, [quoted(true),variable_names(VNs),double_quotes(true)], Ls) }, seq(Ls). portray_(Var, VNs) --> { var(Var) }, !, literal(Var, VNs). diff --git a/src/lib/iso_ext.pl b/src/lib/iso_ext.pl index afc28969..0a5798ae 100644 --- a/src/lib/iso_ext.pl +++ b/src/lib/iso_ext.pl @@ -14,6 +14,7 @@ but they're not part of the ISO Prolog standard at the moment. partial_string/3, partial_string_tail/2, setup_call_cleanup/3, + succ/2, call_nth/2, countall/2, copy_term_nat/2, @@ -112,6 +113,23 @@ bb_get(Key, Value) :- ). +%% succ(?I, ?S). +% +% True iff S is the successor of the non-negative integer I. +% At least one of the arguments must be instantiated. + +succ(I, S) :- + can_be(not_less_than_zero, I), + can_be(not_less_than_zero, S), + ( integer(S) -> + S > 0, + I is S-1 + ; integer(I) -> + S is I+1 + ; instantiation_error(succ/2) + ). + + % setup_call_cleanup. :- meta_predicate(call_cleanup(0, 0)). diff --git a/src/lib/xpath.pl b/src/lib/xpath.pl index a871f78d..10f0fdef 100644 --- a/src/lib/xpath.pl +++ b/src/lib/xpath.pl @@ -95,7 +95,8 @@ op(200, fy, @) ]). -:- use_module(library(lists),[member/2,memberchk/2]). +:- use_module(library(lists),[member/2,memberchk/2,reverse/2]). +:- use_module(library(charsio)). :- use_module(library(error)). :- use_module(library(dcgs)). :- use_module(library(si)). @@ -636,5 +637,27 @@ text_of_1([C|Cs]) --> seq([C|Cs]). xsd_number_chars(Number, Chars) :- number_chars(Number, Chars). -normalize_space(Text0, Text) :- - Text0 = Text. % no conversion for the moment. +normalize_space(Cs0, Cs) :- + must_be(chars, Cs0), + no_leading_whitespace(Cs0, Cs1), + reverse(Cs1, Cs2), + no_leading_whitespace(Cs2, Cs3), + reverse(Cs3, Cs4), + single_intermediate_space(Cs4, Cs). + +no_leading_whitespace([], []). +no_leading_whitespace([C0|Cs0], Cs) :- + ( char_type(C0, whitespace) -> + no_leading_whitespace(Cs0, Cs) + ; Cs = [C0|Cs0] + ). + +single_intermediate_space([], []). +single_intermediate_space([C0|Cs0], [C|Cs]) :- + ( char_type(C0, whitespace) -> + no_leading_whitespace(Cs0, Cs1), + C = ' ', + single_intermediate_space(Cs1, Cs) + ; C = C0, + single_intermediate_space(Cs0, Cs) + ). diff --git a/src/machine/copier.rs b/src/machine/copier.rs index 0d091468..23330fd5 100644 --- a/src/machine/copier.rs +++ b/src/machine/copier.rs @@ -187,8 +187,8 @@ impl CopyTermState { fn copy_attr_var_list(&mut self, mut list_addr: HeapCellValue) { while let HeapCellValueTag::Lis = list_addr.get_tag() { let threshold = self.target.threshold(); - let heap_loc = list_addr.get_value(); - let str_loc = self.target[heap_loc].get_value(); + let heap_loc = list_addr.get_value() as usize; + let str_loc = self.target[heap_loc].get_value() as usize; self.target.push(heap_loc_as_cell!(threshold+2)); self.target.push(heap_loc_as_cell!(threshold+1)); diff --git a/src/machine/disjuncts.rs b/src/machine/disjuncts.rs index a17240f1..96da0a8d 100644 --- a/src/machine/disjuncts.rs +++ b/src/machine/disjuncts.rs @@ -27,7 +27,7 @@ pub struct BranchNumber { impl Default for BranchNumber { fn default() -> Self { Self { - branch_num: Rational::from(1usize << 63), + branch_num: Rational::from(1u64 << 63), delta: Rational::from(1), } } diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 6eeedb63..dc55ed86 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -1497,6 +1497,14 @@ impl Machine { try_or_throw!(self.machine_st, self.machine_st.is(r, at)); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } + Instruction::DefaultCallGetNumber(at) => { + try_or_throw!(self.machine_st, self.machine_st.get_number(at)); + step_or_fail!(self, self.machine_st.p += 1); + } + Instruction::DefaultExecuteGetNumber(at) => { + try_or_throw!(self.machine_st, self.machine_st.get_number(at)); + step_or_fail!(self, self.machine_st.p = self.machine_st.cp); + } &Instruction::CallAcyclicTerm => { let addr = self.machine_st.registers[1]; @@ -1965,6 +1973,34 @@ impl Machine { self.machine_st.p = self.machine_st.cp; } } + Instruction::CallGetNumber(at) => { + try_or_throw!(self.machine_st, self.machine_st.get_number(at)); + + if self.machine_st.fail { + self.machine_st.backtrack(); + } else { + try_or_throw!( + self.machine_st, + (self.machine_st.increment_call_count_fn)(&mut self.machine_st) + ); + + self.machine_st.p += 1; + } + } + Instruction::ExecuteGetNumber(at) => { + try_or_throw!(self.machine_st, self.machine_st.get_number(at)); + + if self.machine_st.fail { + self.machine_st.backtrack(); + } else { + try_or_throw!( + self.machine_st, + (self.machine_st.increment_call_count_fn)(&mut self.machine_st) + ); + + self.machine_st.p = self.machine_st.cp; + } + } &Instruction::CallN(arity) => { let pred = self.machine_st.registers[1]; @@ -4242,58 +4278,72 @@ impl Machine { step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallHttpOpen => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_open()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteHttpOpen => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_open()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallHttpListen => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_listen()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteHttpListen => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_listen()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallHttpAccept => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_accept()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteHttpAccept => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_accept()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallHttpAnswer => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_answer()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteHttpAnswer => { + #[cfg(feature = "http")] try_or_throw!(self.machine_st, self.http_answer()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallLoadForeignLib => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.load_foreign_lib()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteLoadForeignLib => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.load_foreign_lib()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallForeignCall => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.foreign_call()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteForeignCall => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.foreign_call()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallDefineForeignStruct => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.define_foreign_struct()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteDefineForeignStruct => { + #[cfg(feature = "ffi")] try_or_throw!(self.machine_st, self.define_foreign_struct()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } @@ -4462,18 +4512,22 @@ impl Machine { self.machine_st.p = self.machine_st.cp; } &Instruction::CallTLSAcceptClient => { + #[cfg(feature = "tls")] try_or_throw!(self.machine_st, self.tls_accept_client()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteTLSAcceptClient => { + #[cfg(feature = "tls")] try_or_throw!(self.machine_st, self.tls_accept_client()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } &Instruction::CallTLSClientConnect => { + #[cfg(feature = "tls")] try_or_throw!(self.machine_st, self.tls_client_connect()); step_or_fail!(self, self.machine_st.p += 1); } &Instruction::ExecuteTLSClientConnect => { + #[cfg(feature = "tls")] try_or_throw!(self.machine_st, self.tls_client_connect()); step_or_fail!(self, self.machine_st.p = self.machine_st.cp); } diff --git a/src/machine/gc.rs b/src/machine/gc.rs index 1de28ffe..ad42b1d5 100644 --- a/src/machine/gc.rs +++ b/src/machine/gc.rs @@ -68,7 +68,7 @@ pub(crate) struct StacklessPreOrderHeapIter<'a, UMP: UnmarkPolicy> { orig_heap_len: usize, start: usize, current: usize, - next: usize, + next: u64, _marker: PhantomData, } @@ -153,14 +153,14 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { } fn forward_var(&mut self) -> Option { - if self.heap[self.next].get_forwarding_bit() { + if self.heap[self.next as usize].get_forwarding_bit() { return self.backward_and_return(); } - let temp = self.heap[self.next].get_value(); + let temp = self.heap[self.next as usize].get_value(); - self.heap[self.next].set_value(self.current); - self.current = self.next; + self.heap[self.next as usize].set_value(self.current as u64); + self.current = self.next as usize; self.next = temp; None @@ -175,23 +175,23 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { HeapCellValueTag::AttrVar => { if let Some(cell) = UMP::forward_attr_var(self) { return Some(cell); } - if self.heap[self.next].get_mark_bit() { + if self.heap[self.next as usize].get_mark_bit() { return Some(attr_var_as_cell!(self.current)); } } HeapCellValueTag::Var => { if let Some(cell) = self.forward_var() { return Some(cell); } - if self.heap[self.next].get_mark_bit() { + if self.heap[self.next as usize].get_mark_bit() { return Some(heap_loc_as_cell!(self.current)); } } HeapCellValueTag::Str => { - if self.heap[self.next + 1].get_forwarding_bit() { + if self.heap[self.next as usize + 1].get_forwarding_bit() { return self.backward_and_return(); } - let h = self.next; + let h = self.next as usize; let cell = self.heap[h]; let arity = cell_as_atom_cell!(self.heap[h]).get_arity(); @@ -203,13 +203,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { let last_cell_loc = h + arity; self.next = self.heap[last_cell_loc].get_value(); - self.heap[last_cell_loc].set_value(self.current); + self.heap[last_cell_loc].set_value(self.current as u64); self.current = last_cell_loc; return Some(cell); } HeapCellValueTag::Lis => { - let last_cell_loc = self.next + 1; + let last_cell_loc = self.next as usize + 1; if self.heap[last_cell_loc].get_forwarding_bit() { return self.backward_and_return(); @@ -218,13 +218,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { self.heap[last_cell_loc].set_forwarding_bit(true); self.next = self.heap[last_cell_loc].get_value(); - self.heap[last_cell_loc].set_value(self.current); + self.heap[last_cell_loc].set_value(self.current as u64); self.current = last_cell_loc; return Some(list_loc_as_cell!(last_cell_loc - 1)); } HeapCellValueTag::PStrLoc => { - let h = self.next; + let h = self.next as usize; let cell = self.heap[h]; if self.heap[h+1].get_forwarding_bit() { @@ -236,13 +236,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { self.heap[last_cell_loc].set_forwarding_bit(true); self.next = self.heap[last_cell_loc].get_value(); - self.heap[last_cell_loc].set_value(self.current); + self.heap[last_cell_loc].set_value(self.current as u64); self.current = last_cell_loc; } else { debug_assert!(self.heap[h].get_tag() == HeapCellValueTag::PStrOffset); self.next = self.heap[h].get_value(); - self.heap[h].set_value(self.current); + self.heap[h].set_value(self.current as u64); self.current = h; if self.heap[h].get_mark_bit() { @@ -253,7 +253,7 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { return Some(cell); } HeapCellValueTag::PStrOffset => { - let h = self.next; + let h = self.next as usize; let cell = self.heap[h]; // mark the Fixnum offset. @@ -269,20 +269,20 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { self.heap[last_cell_loc].set_forwarding_bit(true); self.next = self.heap[last_cell_loc].get_value(); - self.heap[last_cell_loc].set_value(self.current); + self.heap[last_cell_loc].set_value(self.current as u64); self.current = last_cell_loc; } else { debug_assert!(self.heap[h].get_tag() == HeapCellValueTag::CStr); self.next = self.heap[h].get_value(); - self.heap[h].set_value(self.current); + self.heap[h].set_value(self.current as u64); self.current = h; } return Some(cell); } tag @ HeapCellValueTag::Atom => { - let cell = HeapCellValue::build_with(tag, self.next as u64); + let cell = HeapCellValue::build_with(tag, self.next); let arity = AtomCell::from_bytes(cell.into_bytes()).get_arity(); if arity == 0 { @@ -315,8 +315,8 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { UMP::unmark(self.heap, self.current); self.heap[self.current].set_value(self.next); - self.next = self.current; - self.current = temp; + self.next = self.current as u64; + self.current = temp as usize; } self.heap[self.current].set_forwarding_bit(false); diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index 936200f0..46c4be20 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -2,6 +2,7 @@ use crate::arena::*; use crate::atom_table::*; use crate::parser::ast::*; +#[cfg(feature = "ffi")] use crate::ffi::FFIError; use crate::forms::*; use crate::machine::heap::*; @@ -538,6 +539,7 @@ impl MachineState { } } + #[cfg(feature = "ffi")] pub(super) fn ffi_error(&mut self, err: FFIError) -> MachineError { let error_atom = match err { FFIError::ValueCast => atom!("value_cast"), diff --git a/src/machine/machine_indices.rs b/src/machine/machine_indices.rs index 7389caca..c040743f 100644 --- a/src/machine/machine_indices.rs +++ b/src/machine/machine_indices.rs @@ -143,6 +143,10 @@ impl IndexPtr { #[derive(Debug, Clone, Copy, Ord, Hash, PartialOrd, Eq, PartialEq)] pub struct CodeIndex(TypedArenaPtr); +#[cfg(target_pointer_width="32")] +const_assert!(std::mem::align_of::() == 4); + +#[cfg(target_pointer_width="64")] const_assert!(std::mem::align_of::() == 8); impl Deref for CodeIndex { @@ -164,7 +168,7 @@ impl DerefMut for CodeIndex { impl From for UntypedArenaPtr { #[inline(always)] fn from(ptr: CodeIndex) -> UntypedArenaPtr { - unsafe { std::mem::transmute(ptr.0.as_ptr()) } + UntypedArenaPtr::build_with(ptr.0.as_ptr() as usize) } } diff --git a/src/machine/mod.rs b/src/machine/mod.rs index a170abd4..e56e72bb 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -31,6 +31,7 @@ use crate::arena::*; use crate::arithmetic::*; use crate::atom_table::*; use crate::forms::*; +#[cfg(feature = "ffi")] use crate::ffi::ForeignFunctionTable; use crate::instructions::*; use crate::machine::args::*; @@ -73,6 +74,7 @@ pub struct Machine { pub(super) user_output: Stream, pub(super) user_error: Stream, pub(super) load_contexts: Vec, + #[cfg(feature = "ffi")] pub(super) foreign_function_table: ForeignFunctionTable, } @@ -452,6 +454,7 @@ impl Machine { user_output, user_error, load_contexts: vec![], + #[cfg(feature = "ffi")] foreign_function_table: Default::default(), }; @@ -1253,7 +1256,7 @@ impl Machine { } } TrailEntryTag::TrailedBlackboardEntry => { - let key = Atom::from(h); + let key = Atom::from(h as u64); match self.indices.global_variables.get_mut(&key) { Some((_, ref mut loc)) => *loc = None, @@ -1261,7 +1264,7 @@ impl Machine { } } TrailEntryTag::TrailedBlackboardOffset => { - let key = Atom::from(h); + let key = Atom::from(h as u64); let value_cell = HeapCellValue::from(u64::from(self.machine_st.trail[i + 1])); match self.indices.global_variables.get_mut(&key) { diff --git a/src/machine/streams.rs b/src/machine/streams.rs index 0ea8591d..f4ce6cbd 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -9,6 +9,7 @@ use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; use crate::machine::machine_state::*; use crate::types::*; +#[cfg(feature = "http")] use crate::http::HttpResponse; pub use modular_bitfield::prelude::*; @@ -26,6 +27,7 @@ use std::net::{TcpStream, Shutdown}; use std::ops::{Deref, DerefMut}; use std::ptr; +#[cfg(feature = "tls")] use native_tls::TlsStream; #[derive(Debug, BitfieldSpecifier, Clone, Copy, PartialEq, Eq, Hash)] @@ -232,12 +234,14 @@ impl Write for NamedTcpStream { } } +#[cfg(feature = "tls")] #[derive(Debug)] pub struct NamedTlsStream { address: Atom, tls_stream: TlsStream, } +#[cfg(feature = "tls")] impl Read for NamedTlsStream { #[inline] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { @@ -245,6 +249,7 @@ impl Read for NamedTlsStream { } } +#[cfg(feature = "tls")] impl Write for NamedTlsStream { #[inline] fn write(&mut self, buf: &[u8]) -> std::io::Result { @@ -257,17 +262,20 @@ impl Write for NamedTlsStream { } } +#[cfg(feature = "http")] pub struct HttpReadStream { url: Atom, body_reader: Box, } +#[cfg(feature = "http")] impl Debug for HttpReadStream { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Http Read Stream [{}]", self.url.as_str()) } } +#[cfg(feature = "http")] impl Read for HttpReadStream { #[inline] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { @@ -275,6 +283,7 @@ impl Read for HttpReadStream { } } +#[cfg(feature = "http")] pub struct HttpWriteStream { status_code: u16, headers: hyper::HeaderMap, @@ -282,12 +291,14 @@ pub struct HttpWriteStream { buffer: Vec, } +#[cfg(feature = "http")] impl Debug for HttpWriteStream { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Http Write Stream") } } +#[cfg(feature = "http")] impl Write for HttpWriteStream { #[inline] fn write(&mut self, buf: &[u8]) -> std::io::Result { @@ -361,7 +372,7 @@ impl StreamOptions { #[inline] pub fn get_alias(self) -> Option { if self.has_alias() { - Some(Atom::from((self.alias() << 3) as usize)) + Some(Atom::from((self.alias() as u64) << 3)) } else { None } @@ -453,8 +464,11 @@ arena_allocated_impl_for_stream!(CharReader, ByteStream); arena_allocated_impl_for_stream!(CharReader, InputFileStream); arena_allocated_impl_for_stream!(OutputFileStream, OutputFileStream); arena_allocated_impl_for_stream!(CharReader, NamedTcpStream); +#[cfg(feature = "tls")] arena_allocated_impl_for_stream!(CharReader, NamedTlsStream); +#[cfg(feature = "http")] arena_allocated_impl_for_stream!(CharReader, HttpReadStream); +#[cfg(feature = "http")] arena_allocated_impl_for_stream!(CharReader, HttpWriteStream); arena_allocated_impl_for_stream!(ReadlineStream, ReadlineStream); arena_allocated_impl_for_stream!(StaticStringStream, StaticStringStream); @@ -468,8 +482,11 @@ pub enum Stream { OutputFile(TypedArenaPtr>), StaticString(TypedArenaPtr>), NamedTcp(TypedArenaPtr>>), + #[cfg(feature = "tls")] NamedTls(TypedArenaPtr>>), + #[cfg(feature = "http")] HttpRead(TypedArenaPtr>>), + #[cfg(feature = "http")] HttpWrite(TypedArenaPtr>>), Null(StreamOptions), Readline(TypedArenaPtr>), @@ -524,8 +541,11 @@ impl Stream { Stream::OutputFile(TypedArenaPtr::new(ptr as *mut _)) } ArenaHeaderTag::NamedTcpStream => Stream::NamedTcp(TypedArenaPtr::new(ptr as *mut _)), + #[cfg(feature = "tls")] ArenaHeaderTag::NamedTlsStream => Stream::NamedTls(TypedArenaPtr::new(ptr as *mut _)), + #[cfg(feature = "http")] ArenaHeaderTag::HttpReadStream => Stream::HttpRead(TypedArenaPtr::new(ptr as *mut _)), + #[cfg(feature = "http")] ArenaHeaderTag::HttpWriteStream => Stream::HttpWrite(TypedArenaPtr::new(ptr as *mut _)), ArenaHeaderTag::ReadlineStream => Stream::Readline(TypedArenaPtr::new(ptr as *mut _)), ArenaHeaderTag::StaticStringStream => { @@ -578,8 +598,11 @@ impl Stream { Stream::OutputFile(ptr) => ptr.header_ptr(), Stream::StaticString(ptr) => ptr.header_ptr(), Stream::NamedTcp(ptr) => ptr.header_ptr(), + #[cfg(feature = "tls")] Stream::NamedTls(ptr) => ptr.header_ptr(), + #[cfg(feature = "http")] Stream::HttpRead(ptr) => ptr.header_ptr(), + #[cfg(feature = "http")] Stream::HttpWrite(ptr) => ptr.header_ptr(), Stream::Null(_) => ptr::null(), Stream::Readline(ptr) => ptr.header_ptr(), @@ -595,9 +618,12 @@ impl Stream { Stream::OutputFile(ref ptr) => &ptr.options, Stream::StaticString(ref ptr) => &ptr.options, Stream::NamedTcp(ref ptr) => &ptr.options, + #[cfg(feature = "tls")] Stream::NamedTls(ref ptr) => &ptr.options, + #[cfg(feature = "http")] Stream::HttpRead(ref ptr) => &ptr.options, - Stream::HttpWrite(ref ptr) => &ptr.options, + #[cfg(feature = "http")] + Stream::HttpWrite(ref ptr) => &ptr.options, Stream::Null(ref options) => options, Stream::Readline(ref ptr) => &ptr.options, Stream::StandardOutput(ref ptr) => &ptr.options, @@ -612,8 +638,11 @@ impl Stream { Stream::OutputFile(ref mut ptr) => &mut ptr.options, Stream::StaticString(ref mut ptr) => &mut ptr.options, Stream::NamedTcp(ref mut ptr) => &mut ptr.options, + #[cfg(feature = "tls")] Stream::NamedTls(ref mut ptr) => &mut ptr.options, + #[cfg(feature = "http")] Stream::HttpRead(ref mut ptr) => &mut ptr.options, + #[cfg(feature = "http")] Stream::HttpWrite(ref mut ptr) => &mut ptr.options, Stream::Null(ref mut options) => options, Stream::Readline(ref mut ptr) => &mut ptr.options, @@ -630,8 +659,11 @@ impl Stream { Stream::OutputFile(ptr) => ptr.lines_read += incr_num_lines_read, Stream::StaticString(ptr) => ptr.lines_read += incr_num_lines_read, Stream::NamedTcp(ptr) => ptr.lines_read += incr_num_lines_read, + #[cfg(feature = "tls")] Stream::NamedTls(ptr) => ptr.lines_read += incr_num_lines_read, + #[cfg(feature = "http")] Stream::HttpRead(ptr) => ptr.lines_read += incr_num_lines_read, + #[cfg(feature = "http")] Stream::HttpWrite(_) => {} Stream::Null(_) => {} Stream::Readline(ptr) => ptr.lines_read += incr_num_lines_read, @@ -648,8 +680,11 @@ impl Stream { Stream::OutputFile(ptr) => ptr.lines_read = value, Stream::StaticString(ptr) => ptr.lines_read = value, Stream::NamedTcp(ptr) => ptr.lines_read = value, + #[cfg(feature = "tls")] Stream::NamedTls(ptr) => ptr.lines_read = value, + #[cfg(feature = "http")] Stream::HttpRead(ptr) => ptr.lines_read = value, + #[cfg(feature = "http")] Stream::HttpWrite(_) => {} Stream::Null(_) => {} Stream::Readline(ptr) => ptr.lines_read = value, @@ -666,8 +701,11 @@ impl Stream { Stream::OutputFile(ptr) => ptr.lines_read, Stream::StaticString(ptr) => ptr.lines_read, Stream::NamedTcp(ptr) => ptr.lines_read, + #[cfg(feature = "tls")] Stream::NamedTls(ptr) => ptr.lines_read, + #[cfg(feature = "http")] Stream::HttpRead(ptr) => ptr.lines_read, + #[cfg(feature = "http")] Stream::HttpWrite(_) => 0, Stream::Null(_) => 0, Stream::Readline(ptr) => ptr.lines_read, @@ -682,15 +720,21 @@ impl CharRead for Stream { match self { Stream::InputFile(file) => (*file).peek_char(), Stream::NamedTcp(tcp_stream) => (*tcp_stream).peek_char(), + #[cfg(feature = "tls")] Stream::NamedTls(tls_stream) => (*tls_stream).peek_char(), + #[cfg(feature = "http")] Stream::HttpRead(http_stream) => (*http_stream).peek_char(), Stream::Readline(rl_stream) => (*rl_stream).peek_char(), Stream::StaticString(src) => (*src).peek_char(), Stream::Byte(cursor) => (*cursor).peek_char(), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => Some(Err(std::io::Error::new( + ErrorKind::PermissionDenied, + StreamError::ReadFromOutputStream, + ))), Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | - Stream::HttpWrite(_) | Stream::Null(_) => Some(Err(std::io::Error::new( ErrorKind::PermissionDenied, StreamError::ReadFromOutputStream, @@ -702,15 +746,21 @@ impl CharRead for Stream { match self { Stream::InputFile(file) => (*file).read_char(), Stream::NamedTcp(tcp_stream) => (*tcp_stream).read_char(), + #[cfg(feature = "tls")] Stream::NamedTls(tls_stream) => (*tls_stream).read_char(), + #[cfg(feature = "http")] Stream::HttpRead(http_stream) => (*http_stream).read_char(), Stream::Readline(rl_stream) => (*rl_stream).read_char(), Stream::StaticString(src) => (*src).read_char(), Stream::Byte(cursor) => (*cursor).read_char(), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => Some(Err(std::io::Error::new( + ErrorKind::PermissionDenied, + StreamError::ReadFromOutputStream, + ))), Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | - Stream::HttpWrite(_) | Stream::Null(_) => Some(Err(std::io::Error::new( ErrorKind::PermissionDenied, StreamError::ReadFromOutputStream, @@ -722,15 +772,18 @@ impl CharRead for Stream { match self { Stream::InputFile(file) => file.put_back_char(c), Stream::NamedTcp(tcp_stream) => tcp_stream.put_back_char(c), + #[cfg(feature = "tls")] Stream::NamedTls(tls_stream) => tls_stream.put_back_char(c), + #[cfg(feature = "http")] Stream::HttpRead(http_stream) => http_stream.put_back_char(c), Stream::Readline(rl_stream) => rl_stream.put_back_char(c), Stream::StaticString(src) => src.put_back_char(c), Stream::Byte(cursor) => cursor.put_back_char(c), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => {} Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | - Stream::HttpWrite(_) | Stream::Null(_) => {} } } @@ -739,15 +792,18 @@ impl CharRead for Stream { match self { Stream::InputFile(ref mut file) => file.consume(nread), Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.consume(nread), + #[cfg(feature = "tls")] Stream::NamedTls(ref mut tls_stream) => tls_stream.consume(nread), + #[cfg(feature = "http")] Stream::HttpRead(ref mut http_stream) => http_stream.consume(nread), Stream::Readline(ref mut rl_stream) => rl_stream.consume(nread), Stream::StaticString(ref mut src) => src.consume(nread), Stream::Byte(ref mut cursor) => cursor.consume(nread), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => {} Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | - Stream::HttpWrite(_) | Stream::Null(_) => {} } } @@ -759,15 +815,21 @@ impl Read for Stream { let bytes_read = match self { Stream::InputFile(file) => (*file).read(buf), Stream::NamedTcp(tcp_stream) => (*tcp_stream).read(buf), + #[cfg(feature = "tls")] Stream::NamedTls(tls_stream) => (*tls_stream).read(buf), + #[cfg(feature = "http")] Stream::HttpRead(http_stream) => (*http_stream).read(buf), Stream::Readline(rl_stream) => (*rl_stream).read(buf), Stream::StaticString(src) => (*src).read(buf), Stream::Byte(cursor) => (*cursor).read(buf), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => Err(std::io::Error::new( + ErrorKind::PermissionDenied, + StreamError::ReadFromOutputStream, + )), Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) - | Stream::HttpWrite(_) | Stream::Null(_) => Err(std::io::Error::new( ErrorKind::PermissionDenied, StreamError::ReadFromOutputStream, @@ -783,12 +845,18 @@ impl Write for Stream { match self { Stream::OutputFile(ref mut file) => file.write(buf), Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.get_mut().write(buf), + #[cfg(feature = "tls")] Stream::NamedTls(ref mut tls_stream) => tls_stream.get_mut().write(buf), Stream::Byte(ref mut cursor) => cursor.get_mut().write(buf), Stream::StandardOutput(stream) => stream.write(buf), Stream::StandardError(stream) => stream.write(buf), + #[cfg(feature = "http")] Stream::HttpWrite(ref mut stream) => stream.get_mut().write(buf), - Stream::HttpRead(_) | + #[cfg(feature = "http")] + Stream::HttpRead(_) => Err(std::io::Error::new( + ErrorKind::PermissionDenied, + StreamError::WriteToInputStream, + )), Stream::StaticString(_) | Stream::Readline(_) | Stream::InputFile(..) | @@ -803,12 +871,18 @@ impl Write for Stream { match self { Stream::OutputFile(ref mut file) => file.stream.flush(), Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.stream.get_mut().flush(), + #[cfg(feature = "tls")] Stream::NamedTls(ref mut tls_stream) => tls_stream.stream.get_mut().flush(), Stream::Byte(ref mut cursor) => cursor.stream.get_mut().flush(), Stream::StandardError(stream) => stream.stream.flush(), Stream::StandardOutput(stream) => stream.stream.flush(), + #[cfg(feature = "http")] Stream::HttpWrite(ref mut stream) => stream.stream.get_mut().flush(), - Stream::HttpRead(_) | + #[cfg(feature = "http")] + Stream::HttpRead(_) => Err(std::io::Error::new( + ErrorKind::PermissionDenied, + StreamError::FlushToInputStream, + )), Stream::StaticString(_) | Stream::Readline(_) | Stream::InputFile(_) | @@ -913,7 +987,12 @@ impl Stream { Stream::InputFile(file_stream) => { file_stream.position() } - Stream::NamedTcp(..) | Stream::NamedTls(..) | Stream::Readline(..) => { + #[cfg(feature = "tls")] + Stream::NamedTls(..) => { + Some(0) + } + Stream::NamedTcp(..) + | Stream::Readline(..) => { Some(0) } _ => None, @@ -951,8 +1030,11 @@ impl Stream { Stream::OutputFile(stream) => stream.past_end_of_stream, Stream::StaticString(stream) => stream.past_end_of_stream, Stream::NamedTcp(stream) => stream.past_end_of_stream, + #[cfg(feature = "tls")] Stream::NamedTls(stream) => stream.past_end_of_stream, + #[cfg(feature = "http")] Stream::HttpRead(stream) => stream.past_end_of_stream, + #[cfg(feature = "http")] Stream::HttpWrite(stream) => stream.past_end_of_stream, Stream::Null(_) => false, Stream::Readline(stream) => stream.past_end_of_stream, @@ -974,8 +1056,11 @@ impl Stream { Stream::OutputFile(stream) => stream.past_end_of_stream = value, Stream::StaticString(stream) => stream.past_end_of_stream = value, Stream::NamedTcp(stream) => stream.past_end_of_stream = value, + #[cfg(feature = "tls")] Stream::NamedTls(stream) => stream.past_end_of_stream = value, + #[cfg(feature = "http")] Stream::HttpRead(stream) => stream.past_end_of_stream = value, + #[cfg(feature = "http")] Stream::HttpWrite(stream) => stream.past_end_of_stream = value, Stream::Null(_) => {} Stream::Readline(stream) => stream.past_end_of_stream = value, @@ -1054,6 +1139,7 @@ impl Stream { Stream::InputFile(file) => Some(file.stream.get_ref().file_name), Stream::OutputFile(file) => Some(file.stream.file_name), Stream::NamedTcp(tcp) => Some(tcp.stream.get_ref().address), + #[cfg(feature = "tls")] Stream::NamedTls(tls) => Some(tls.stream.get_ref().address), _ => None, } @@ -1062,14 +1148,19 @@ impl Stream { #[inline] pub(crate) fn mode(&self) -> Atom { match self { + #[cfg(feature = "http")] + Stream::HttpRead(_) => atom!("read"), + #[cfg(feature = "tls")] + Stream::NamedTls(..) => atom!("read_append"), Stream::Byte(_) | Stream::Readline(_) | Stream::StaticString(_) - | Stream::HttpRead(_) | Stream::InputFile(..) => atom!("read"), - Stream::NamedTcp(..) | Stream::NamedTls(..) => atom!("read_append"), + Stream::NamedTcp(..) => atom!("read_append"), Stream::OutputFile(file) if file.is_append => atom!("append"), - Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | Stream::HttpWrite(_) => atom!("write"), + #[cfg(feature = "http")] + Stream::HttpWrite(_) => atom!("write"), + Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) => atom!("write"), Stream::Null(_) => atom!(""), } } @@ -1108,6 +1199,7 @@ impl Stream { )) } + #[cfg(feature = "tls")] #[inline] pub(crate) fn from_tls_stream( address: Atom, @@ -1123,6 +1215,7 @@ impl Stream { )) } + #[cfg(feature = "http")] #[inline] pub(crate) fn from_http_stream( url: Atom, @@ -1138,6 +1231,7 @@ impl Stream { )) } + #[cfg(feature = "http")] #[inline] pub(crate) fn from_http_sender( response: TypedArenaPtr, @@ -1189,9 +1283,11 @@ impl Stream { Stream::NamedTcp(ref mut tcp_stream) => { tcp_stream.inner_mut().tcp_stream.shutdown(Shutdown::Both) }, + #[cfg(feature = "tls")] Stream::NamedTls(ref mut tls_stream) => { tls_stream.inner_mut().tls_stream.shutdown() } + #[cfg(feature = "http")] Stream::HttpRead(ref mut http_stream) => { unsafe { http_stream.set_tag(ArenaHeaderTag::Dropped); @@ -1200,7 +1296,8 @@ impl Stream { Ok(()) } - Stream::HttpWrite(ref mut http_stream) => { + #[cfg(feature = "http")] + Stream::HttpWrite(ref mut http_stream) => { unsafe { http_stream.set_tag(ArenaHeaderTag::Dropped); std::ptr::drop_in_place(&mut http_stream.inner_mut().buffer as *mut _); @@ -1242,9 +1339,11 @@ impl Stream { #[inline] pub(crate) fn is_input_stream(&self) -> bool { match self { + #[cfg(feature = "tls")] + Stream::NamedTls(..) => true, + #[cfg(feature = "http")] + Stream::HttpRead(..) => true, Stream::NamedTcp(..) - | Stream::NamedTls(..) - | Stream::HttpRead(..) | Stream::Byte(_) | Stream::Readline(_) | Stream::StaticString(_) @@ -1256,11 +1355,13 @@ impl Stream { #[inline] pub(crate) fn is_output_stream(&self) -> bool { match self { + #[cfg(feature = "tls")] + Stream::NamedTls(..) => true, + #[cfg(feature = "http")] + Stream::HttpWrite(..) => true, Stream::StandardError(_) | Stream::StandardOutput(_) | Stream::NamedTcp(..) - | Stream::NamedTls(..) - | Stream::HttpWrite(..) | Stream::Byte(_) | Stream::OutputFile(..) => true, _ => false, diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index f025306c..bd38455b 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -7,9 +7,11 @@ use lazy_static::lazy_static; use crate::arena::*; use crate::atom_table::*; use crate::forms::*; +#[cfg(feature = "ffi")] use crate::ffi::*; use crate::heap_iter::*; use crate::heap_print::*; +#[cfg(feature = "http")] use crate::http::{HttpService, HttpListener, HttpResponse}; use crate::instructions::*; use crate::machine; @@ -44,6 +46,7 @@ use std::cmp::Ordering; use std::collections::BTreeSet; use std::convert::TryFrom; use std::env; +#[cfg(feature = "ffi")] use std::ffi::CString; use std::fs; use std::hash::{BuildHasher, BuildHasherDefault}; @@ -57,10 +60,13 @@ use std::process; use std::str::FromStr; use chrono::{offset::Local, DateTime}; +#[cfg(not(target_os = "wasi"))] use cpu_time::ProcessTime; use std::time::{Duration, SystemTime}; +#[cfg(feature = "repl")] use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +#[cfg(feature = "repl")] use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use blake2::{Blake2b, Blake2s}; @@ -72,24 +78,28 @@ use ring::{ use ripemd160::{Digest, Ripemd160}; use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; -use crrl::secp256k1; - -use sodiumoxide::crypto::scalarmult::curve25519::*; +use crrl::{secp256k1, x25519}; +#[cfg(feature = "tls")] use native_tls::{TlsConnector,TlsAcceptor,Identity}; use base64; use roxmltree; use select; +#[cfg(feature = "http")] use hyper::server::conn::http1; +#[cfg(feature = "http")] use hyper::header::{HeaderValue, HeaderName}; +#[cfg(feature = "http")] use hyper::{HeaderMap, Method}; use http_body_util::BodyExt; use bytes::Buf; +#[cfg(feature = "http")] use reqwest::Url; use hyper_util::rt::TokioIo; +#[cfg(feature = "repl")] pub(crate) fn get_key() -> KeyEvent { let key; enable_raw_mode().expect("failed to enable raw mode"); @@ -744,7 +754,7 @@ impl MachineState { }; if let Some(max_steps) = max_steps_n { - if max_steps.abs() as usize <= 1 << 63 { + if max_steps.abs() as u64 <= 1 << 63 { if max_steps >= 0 { max_old = max_steps; } else { @@ -979,7 +989,7 @@ impl MachineState { pub(crate) fn call_continuation_chunk(&mut self, chunk: HeapCellValue, return_p: usize) -> usize { let chunk = self.store(self.deref(chunk)); - let s = chunk.get_value(); + let s = chunk.get_value() as usize; let arity = cell_as_atom_cell!(self.heap[s]).get_arity(); let num_cells = arity - 1; @@ -1160,7 +1170,7 @@ impl Machine { let attr_var = self.deref_register(1); if let HeapCellValueTag::AttrVar = attr_var.get_tag() { - let attr_var_loc = attr_var.get_value(); + let attr_var_loc = attr_var.get_value() as usize; self.machine_st.heap[attr_var_loc] = heap_loc_as_cell!(attr_var_loc); self.machine_st.trail(TrailRef::Ref(Ref::attr_var(attr_var_loc))); } @@ -1346,7 +1356,7 @@ impl Machine { } else { if is_internal_call { debug_assert_eq!(goal.get_tag(), HeapCellValueTag::Str); - goal = self.machine_st.heap[goal.get_value()+1]; + goal = self.machine_st.heap[goal.get_value() as usize+1]; (module_name, goal) = self.machine_st.strip_module(goal, module_name); if let Some((inner_name, inner_arity)) = self.machine_st.name_and_arity_from_heap(goal) { @@ -1576,7 +1586,7 @@ impl Machine { ); if HeapCellValueTag::Str == qualified_goal.get_tag() { - let s = qualified_goal.get_value(); + let s = qualified_goal.get_value() as usize; let (name, arity) = cell_as_atom_cell!(self.machine_st.heap[s]) .get_name_and_arity(); @@ -1767,6 +1777,7 @@ impl Machine { #[inline(always)] pub(crate) fn current_hostname(&mut self) { + #[cfg(feature = "hostname")] match hostname::get().ok() { Some(host) => match host.to_str() { Some(host) => { @@ -3682,6 +3693,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "repl")] #[inline(always)] pub(crate) fn get_single_char(&mut self) -> CallResult { let ctrl_c = KeyEvent { @@ -3705,7 +3717,28 @@ impl Machine { KeyCode::Char(c) => c, _ => unreachable!(), }; + let a1 = self.deref_register(1); + self.machine_st.unify_char( + c, + a1, + ); + Ok(()) + } + + #[cfg(not(feature = "repl"))] + #[inline(always)] + pub(crate) fn get_single_char(&mut self) -> CallResult { + let mut buffer = [0; 1]; + // is there a better way? + if std::io::stdin().read(&mut buffer).is_err() { + let stub = functor_stub(atom!("get_single_char"), 1); + let err = self.machine_st.interrupt_error(); + let err = self.machine_st.error_form(err, stub); + + return Err(err); + } + let c = buffer[0] as char; let a1 = self.deref_register(1); self.machine_st.unify_char( c, @@ -4161,6 +4194,7 @@ impl Machine { self.machine_st.fail = result; } + #[cfg(not(target_os = "wasi"))] #[inline(always)] pub(crate) fn cpu_now(&mut self) { let secs = ProcessTime::now().as_duration().as_secs_f64(); @@ -4169,6 +4203,12 @@ impl Machine { self.machine_st.unify_f64(secs, self.machine_st.registers[1]); } + #[cfg(target_os = "wasi")] + #[inline(always)] + pub(crate) fn cpu_now(&mut self) { + // TODO + } + #[inline(always)] pub(crate) fn det_length_rundown(&mut self) -> CallResult { let stub_gen = || functor_stub(atom!("length"), 2); @@ -4201,6 +4241,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "http")] #[inline(always)] pub(crate) fn http_open(&mut self) -> CallResult { let address_sink = self.deref_register(1); @@ -4319,6 +4360,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "http")] #[inline(always)] pub(crate) fn http_listen(&mut self) -> CallResult { let address_sink = self.deref_register(1); @@ -4371,6 +4413,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "http")] #[inline(always)] pub(crate) fn http_accept(&mut self) -> CallResult { let culprit = self.deref_register(1); @@ -4455,6 +4498,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "http")] #[inline(always)] pub(crate) fn http_answer(&mut self) -> CallResult { let culprit = self.deref_register(1); @@ -4521,6 +4565,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "ffi")] #[inline(always)] pub(crate) fn load_foreign_lib(&mut self) -> CallResult { let library_name = self.deref_register(1); @@ -4567,6 +4612,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "ffi")] #[inline(always)] pub(crate) fn foreign_call(&mut self) -> CallResult { let function_name = self.deref_register(1); @@ -4642,6 +4688,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "ffi")] fn build_struct(&mut self, name: &str, mut args: Vec) -> HeapCellValue { args.insert(0, Value::CString(CString::new(name).unwrap())); let cells: Vec<_> = args.into_iter() @@ -4662,6 +4709,7 @@ impl Machine { ) } + #[cfg(feature = "ffi")] #[inline(always)] pub(crate) fn define_foreign_struct(&mut self) -> CallResult { let struct_name = self.deref_register(1); @@ -4854,7 +4902,7 @@ impl Machine { Some(AttrListMatch { match_site: MatchSite::Match(match_site), .. }) => { let list_head = self.machine_st.heap[match_site]; - if list_head.get_value() == match_site { + if list_head.get_value() as usize == match_site { // at the end of the list, no match found in this case. self.machine_st.fail = true; } else { @@ -4927,7 +4975,7 @@ impl Machine { prev_tail } else { if self.machine_st.heap[match_site + 1].is_var() { - let h = attr_var.get_value(); + let h = attr_var.get_value() as usize; self.machine_st.heap[h] = heap_loc_as_cell!(h); self.machine_st.trail(TrailRef::Ref(Ref::attr_var(h))); @@ -5002,13 +5050,13 @@ impl Machine { } MatchSite::Match(match_site) => { let l = self.machine_st.heap[match_site].get_value(); - self.machine_st.heap[match_site].set_value(h); + self.machine_st.heap[match_site].set_value(h as u64); (match_site, l) } }; - self.machine_st.trail(TrailRef::AttrVarListLink(match_site, l)); + self.machine_st.trail(TrailRef::AttrVarListLink(match_site, l as usize)); } None => { // the list is empty. @@ -5038,7 +5086,7 @@ impl Machine { let mut prev_tail = None; while let HeapCellValueTag::Lis = attrs_list.get_tag() { - let mut list_head = self.machine_st.heap[attrs_list.get_value()]; + let mut list_head = self.machine_st.heap[attrs_list.get_value() as usize]; loop { read_heap_cell!(list_head, @@ -5058,7 +5106,7 @@ impl Machine { if module == module_loc && name == t_name && arity == t_arity { return Some(AttrListMatch { - match_site: MatchSite::Match(attrs_list.get_value()), + match_site: MatchSite::Match(attrs_list.get_value() as usize), prev_tail, }); } @@ -5071,7 +5119,7 @@ impl Machine { ); } - let tail_loc = attrs_list.get_value() + 1; + let tail_loc = attrs_list.get_value() as usize + 1; prev_tail = Some(tail_loc); // do the work of self.store(self.deref(...)) but inline it @@ -5416,7 +5464,7 @@ impl Machine { let value = self.deref_register(2); debug_assert_eq!(HeapCellValueTag::AttrVar, var.get_tag()); - self.machine_st.heap[var.get_value()] = value; + self.machine_st.heap[var.get_value() as usize] = value; } #[inline(always)] @@ -6241,6 +6289,7 @@ impl Machine { Ok(()) } + #[cfg(feature = "tls")] #[inline(always)] pub(crate) fn tls_client_connect(&mut self) -> CallResult { if let Some(hostname) = self.machine_st.value_to_str_like(self.machine_st.registers[1]) { @@ -6278,6 +6327,7 @@ impl Machine { } } + #[cfg(feature = "tls")] #[inline(always)] pub(crate) fn tls_accept_client(&mut self) -> CallResult { let pkcs12 = self.string_encoding_bytes(self.machine_st.registers[1], atom!("octet")); @@ -7304,13 +7354,11 @@ impl Machine { pub(crate) fn curve25519_scalar_mult(&mut self) { let stub1_gen = || functor_stub(atom!("curve25519_scalar_mult"), 3); let scalar_bytes = self.machine_st.integers_to_bytevec(self.machine_st.registers[1], stub1_gen); - let scalar = Scalar(<[u8; 32]>::try_from(&scalar_bytes[..]).unwrap()); - let stub2_gen = || functor_stub(atom!("curve25519_scalar_mult"), 3); let point_bytes = self.machine_st.integers_to_bytevec(self.machine_st.registers[2], stub2_gen); - let point = GroupElement(<[u8; 32]>::try_from(&point_bytes[..]).unwrap()); - let result = scalarmult(&scalar, &point).unwrap(); + let result = x25519::x25519(&<[u8; 32]>::try_from(&point_bytes[..]).unwrap(), + &<[u8; 32]>::try_from(&scalar_bytes[..]).unwrap()); let string = self.u8s_to_string(&result[..]); diff --git a/src/macros.rs b/src/macros.rs index 9bd89ab7..ef47ff27 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -73,9 +73,9 @@ macro_rules! cell_as_string { macro_rules! cell_as_atom { ($cell:expr) => {{ let cell = AtomCell::from_bytes($cell.into_bytes()); - let name = cell.get_index() << 3; + let name = (cell.get_index() as u64) << 3; - Atom::from(name as usize) + Atom::from(name) }}; } @@ -87,14 +87,14 @@ macro_rules! cell_as_atom_cell { macro_rules! cell_as_f64_ptr { ($cell:expr) => {{ - let offset = $cell.get_value(); + let offset = $cell.get_value() as usize; F64Ptr::from_offset(offset) }}; } macro_rules! cell_as_untyped_arena_ptr { ($cell:expr) => { - UntypedArenaPtr::from(u64::from($cell) as *const ArenaHeader) + UntypedArenaPtr::from_bytes($cell.to_untyped_arena_ptr_bytes()) }; } @@ -173,7 +173,14 @@ macro_rules! attr_var_loc_as_cell { macro_rules! typed_arena_ptr_as_cell { ($ptr:expr) => { - untyped_arena_ptr_as_cell!($ptr.header_ptr()) + raw_ptr_as_cell!($ptr.header_ptr()) + }; +} + +macro_rules! raw_ptr_as_cell { + ($ptr:expr) => { + // Cell is 64-bit, but raw ptr is 32-bit in 32-bit systems + HeapCellValue::from_raw_ptr_bytes(unsafe { std::mem::transmute($ptr) }) }; } @@ -217,7 +224,7 @@ macro_rules! string_as_pstr_cell { macro_rules! stream_as_cell { ($ptr:expr) => { - untyped_arena_ptr_as_cell!($ptr.as_ptr()) + raw_ptr_as_cell!($ptr.as_ptr()) }; } @@ -250,13 +257,15 @@ macro_rules! match_untyped_arena_ptr_pat_body { #[allow(unused_braces)] $code }}; - ($cell:ident, OssifiedOpDir, $n:ident, $code:expr) => {{ - let $n = cell_as_ossified_op_dir!($cell); + ($ptr:ident, OssifiedOpDir, $n:ident, $code:expr) => {{ + let payload_ptr = unsafe { std::mem::transmute::<_, *mut OssifiedOpDir>($ptr.payload_offset()) }; + let $n = TypedArenaPtr::new(payload_ptr); #[allow(unused_braces)] $code }}; - ($cell:ident, LiveLoadState, $n:ident, $code:expr) => {{ - let $n = cell_as_load_state_payload!($cell); + ($ptr:ident, LiveLoadState, $n:ident, $code:expr) => {{ + let payload_ptr = unsafe { std::mem::transmute::<_, *mut LiveLoadState>($ptr.payload_offset()) }; + let $n = TypedArenaPtr::new(payload_ptr); #[allow(unused_braces)] $code }}; diff --git a/src/read.rs b/src/read.rs index e23dc302..40b50e03 100644 --- a/src/read.rs +++ b/src/read.rs @@ -10,14 +10,19 @@ use crate::machine::machine_indices::*; use crate::machine::machine_state::MachineState; use crate::machine::streams::*; use crate::parser::char_reader::*; +#[cfg(feature = "repl")] use crate::repl_helper::Helper; use crate::types::*; use fxhash::FxBuildHasher; use indexmap::IndexSet; + +#[cfg(feature = "repl")] use rustyline::error::ReadlineError; +#[cfg(feature = "repl")] use rustyline::history::DefaultHistory; +#[cfg(feature = "repl")] use rustyline::{Config, Editor}; use std::collections::VecDeque; @@ -102,12 +107,14 @@ fn get_prompt() -> &'static str { #[derive(Debug)] pub struct ReadlineStream { + #[cfg(feature = "repl")] rl: Editor, pending_input: CharReader>, add_history: bool, } impl ReadlineStream { + #[cfg(feature = "repl")] #[inline] pub fn new(pending_input: &str, add_history: bool) -> Self { let config = Config::builder() @@ -133,11 +140,25 @@ impl ReadlineStream { } } + #[cfg(not(feature = "repl"))] + #[inline] + pub fn new(pending_input: &str, add_history: bool) -> Self { + ReadlineStream { + pending_input: CharReader::new(Cursor::new(pending_input.to_owned())), + add_history: add_history, + } + } + + #[cfg(feature = "repl")] pub fn set_atoms_for_completion(&mut self, atoms: *const IndexSet) { let helper = self.rl.helper_mut().unwrap(); helper.atoms = atoms; } + #[cfg(not(feature = "repl"))] + pub fn set_atoms_for_completion(&mut self, atoms: *const IndexSet) { + } + #[inline] pub fn reset(&mut self) { self.pending_input.reset_buffer(); @@ -148,6 +169,7 @@ impl ReadlineStream { pending_input.set_position(0); } + #[cfg(feature = "repl")] fn call_readline(&mut self) -> std::io::Result { match self.rl.readline(get_prompt()) { Ok(text) => { @@ -175,6 +197,12 @@ impl ReadlineStream { } } + #[cfg(not(feature = "repl"))] + fn call_readline(&mut self) -> std::io::Result { + Ok(0) + } + + #[cfg(feature = "repl")] fn save_history(&mut self) { if !self.add_history { return; @@ -191,6 +219,10 @@ impl ReadlineStream { } } + #[cfg(not(feature = "repl"))] + fn save_history(&mut self) { + } + #[inline] pub(crate) fn peek_byte(&mut self) -> std::io::Result { let bytes = self.pending_input.refresh_buffer()?; diff --git a/src/types.rs b/src/types.rs index 12add4ef..350a76dd 100644 --- a/src/types.rs +++ b/src/types.rs @@ -88,6 +88,15 @@ impl ConsPtr { .with_tag(tag) } + #[cfg(target_pointer_width="32")] + #[inline(always)] + pub fn as_ptr(self) -> *mut u8 { + let bytes = self.into_bytes(); + let raw_ptr_bytes = [bytes[1], bytes[2], bytes[3], bytes[4]]; + unsafe { mem::transmute(raw_ptr_bytes) } + } + + #[cfg(target_pointer_width="64")] #[inline(always)] pub fn as_ptr(self) -> *mut u8 { self.ptr() as *mut _ @@ -444,7 +453,7 @@ impl HeapCellValue { pub fn is_compound(self, heap: &[HeapCellValue]) -> bool { match self.get_tag() { HeapCellValueTag::Str => { - cell_as_atom_cell!(heap[self.get_value()]).get_arity() > 0 + cell_as_atom_cell!(heap[self.get_value() as usize]).get_arity() > 0 } HeapCellValueTag::Lis | HeapCellValueTag::CStr | @@ -491,13 +500,13 @@ impl HeapCellValue { } #[inline] - pub fn get_value(self) -> usize { - self.val() as usize + pub fn get_value(self) -> u64 { + self.val() as u64 } #[inline] - pub fn set_value(&mut self, val: usize) { - self.set_val(val as u64); + pub fn set_value(&mut self, val: u64) { + self.set_val(val); } #[inline] @@ -513,7 +522,7 @@ impl HeapCellValue { #[inline] pub fn to_atom(self) -> Option { match self.tag() { - HeapCellValueTag::Atom => Some(Atom::from((self.val() << 3) as usize)), + HeapCellValueTag::Atom => Some(Atom::from(self.val() << 3)), _ => None, } } @@ -522,7 +531,7 @@ impl HeapCellValue { pub fn to_pstr(self) -> Option { match self.tag() { HeapCellValueTag::PStr => { - Some(PartialString::from(Atom::from((self.val() as usize) << 3))) + Some(PartialString::from(Atom::from(self.val() << 3))) } _ => None, } @@ -536,10 +545,39 @@ impl HeapCellValue { } } + #[cfg(target_pointer_width="32")] + #[inline] + pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 4]) -> Self { + HeapCellValue::from_bytes([ptr_bytes[0], ptr_bytes[1], ptr_bytes[2], ptr_bytes[3], 0, 0, 0, 0]) + } + #[cfg(target_pointer_width="64")] + #[inline] + pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 8]) -> Self { + HeapCellValue::from_bytes(ptr_bytes) + } + + #[inline] + #[cfg(target_pointer_width="32")] + pub fn to_raw_ptr_bytes(self) -> [u8; 4] { + let bytes = self.into_bytes(); + [bytes[0], bytes[1], bytes[2], bytes[3]] + } + + #[inline] + #[cfg(target_pointer_width="64")] + pub fn to_raw_ptr_bytes(self) -> [u8; 8] { + self.into_bytes() + } + + #[inline] + pub fn to_untyped_arena_ptr_bytes(self) -> [u8; 8] { + self.into_bytes() + } + #[inline] pub fn to_untyped_arena_ptr(self) -> Option { - match self.tag() { - HeapCellValueTag::Cons => Some(UntypedArenaPtr::from_bytes(self.into_bytes())), + match self.get_tag() { + HeapCellValueTag::Cons => Some(UntypedArenaPtr::from_bytes(self.to_untyped_arena_ptr_bytes())), _ => None, } } @@ -607,7 +645,7 @@ impl HeapCellValue { Some(TermOrderCategory::Compound) } HeapCellValueTag::Str => { - let value = heap[self.get_value()]; + let value = heap[self.get_value() as usize]; let arity = cell_as_atom_cell!(value).get_arity(); if arity == 0 { @@ -642,31 +680,39 @@ const_assert!(mem::size_of::() == 8); #[repr(u64)] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub struct UntypedArenaPtr { - ptr: B61, + #[allow(unused)] ptr: B61, m: bool, #[allow(unused)] padding: B2, } +impl UntypedArenaPtr { + #[inline(always)] + pub fn build_with(ptr: usize) -> Self { + UntypedArenaPtr::new() + .with_ptr(ptr as u64) + } +} + const_assert!(mem::size_of::() == 8); impl From<*const ArenaHeader> for UntypedArenaPtr { #[inline] fn from(ptr: *const ArenaHeader) -> UntypedArenaPtr { - unsafe { mem::transmute(ptr) } + UntypedArenaPtr::build_with(ptr as usize) } } impl From<*const IndexPtr> for UntypedArenaPtr { #[inline] fn from(ptr: *const IndexPtr) -> UntypedArenaPtr { - unsafe { mem::transmute(ptr) } + UntypedArenaPtr::build_with(ptr as usize) } } impl From for *const ArenaHeader { #[inline] fn from(ptr: UntypedArenaPtr) -> *const ArenaHeader { - unsafe { mem::transmute(ptr) } + ptr.get_ptr() as *const ArenaHeader } } @@ -676,15 +722,24 @@ impl UntypedArenaPtr { self.set_m(m); } + #[cfg(target_pointer_width="32")] #[inline] pub fn get_ptr(self) -> *const u8 { - self.ptr() as *const u8 + let bytes = self.into_bytes(); + let raw_ptr_bytes = [bytes[0], bytes[1], bytes[2], bytes[3]]; + unsafe { mem::transmute(raw_ptr_bytes) } + } + + #[cfg(target_pointer_width="64")] + #[inline] + pub fn get_ptr(self) -> *const u8 { + self.ptr() as *const u8 } #[inline] pub fn get_tag(self) -> ArenaHeaderTag { unsafe { - let header = *(self.ptr() as *const ArenaHeader); + let header = *(self.get_ptr() as *const ArenaHeader); header.get_tag() } } @@ -714,7 +769,7 @@ impl Add for HeapCellValue { tag @ HeapCellValueTag::PStrLoc | tag @ HeapCellValueTag::Var | tag @ HeapCellValueTag::AttrVar => { - HeapCellValue::build_with(tag, (self.get_value() + rhs) as u64) + HeapCellValue::build_with(tag, (self.get_value() as usize + rhs) as u64) } _ => { self @@ -734,7 +789,7 @@ impl Sub for HeapCellValue { tag @ HeapCellValueTag::PStrLoc | tag @ HeapCellValueTag::Var | tag @ HeapCellValueTag::AttrVar => { - HeapCellValue::build_with(tag, (self.get_value() - rhs) as u64) + HeapCellValue::build_with(tag, (self.get_value() as usize - rhs) as u64) } _ => { self @@ -762,7 +817,7 @@ impl Sub for HeapCellValue { tag @ HeapCellValueTag::PStrLoc | tag @ HeapCellValueTag::Var | tag @ HeapCellValueTag::AttrVar => { - HeapCellValue::build_with(tag, (self.get_value() + rhs.abs() as usize) as u64) + HeapCellValue::build_with(tag, self.get_value() + rhs.abs() as u64) } _ => { self