merge develop
This commit is contained in:
commit
60c63c1aef
22 changed files with 386 additions and 251 deletions
98
Cargo.lock
generated
98
Cargo.lock
generated
|
@ -23,7 +23,7 @@ dependencies = [
|
|||
"difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"skeptic 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -42,8 +42,8 @@ name = "backtrace"
|
|||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -51,7 +51,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "backtrace-sys"
|
||||
version = "0.1.23"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -97,7 +97,7 @@ dependencies = [
|
|||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -107,7 +107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -126,7 +126,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.32"
|
||||
version = "0.1.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -145,11 +145,6 @@ name = "difference"
|
|||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "environment"
|
||||
version = "0.1.1"
|
||||
|
@ -223,11 +218,8 @@ name = "num"
|
|||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-complex 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -238,17 +230,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -268,17 +249,6 @@ dependencies = [
|
|||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.43"
|
||||
|
@ -294,7 +264,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.9"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -310,10 +280,10 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.5"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -378,8 +348,8 @@ version = "0.1.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-serialize"
|
||||
version = "0.3.24"
|
||||
name = "ryu"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -414,18 +384,18 @@ name = "serde_derive"
|
|||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.14.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.14.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.24"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -439,7 +409,7 @@ dependencies = [
|
|||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -451,11 +421,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.14.7"
|
||||
version = "0.14.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -575,7 +545,7 @@ dependencies = [
|
|||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zokrates_core 0.2.0",
|
||||
"zokrates_fs_resolver 0.1.0",
|
||||
]
|
||||
|
@ -587,17 +557,18 @@ dependencies = [
|
|||
"assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cmake 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reduce 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -610,7 +581,7 @@ version = "0.1.0"
|
|||
"checksum assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "72342c21057a3cb5f7c2d849bf7999a83795434dd36d74fa8c24680581bd1930"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
|
||||
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
|
||||
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
|
||||
"checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e"
|
||||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
|
||||
|
@ -618,12 +589,11 @@ version = "0.1.0"
|
|||
"checksum byteorder 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8389c509ec62b9fe8eca58c502a0acaf017737355615243496cde4994f8fa4f9"
|
||||
"checksum cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1efca0b863ca03ed4c109fb1c55e0bc4bbeb221d3e103d86251046b06a526bd0"
|
||||
"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
|
||||
"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e"
|
||||
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
|
||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||
"checksum cmake 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "b56821938fa1a3aaf4f0c4f49504928c5a7fcc56cbc9855be8fc2e98567e750c"
|
||||
"checksum cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "704fbf3bb5149daab0afb255dbea24a1f08d2f4099cedb9baab6d470d4c5eefb"
|
||||
"checksum colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc0a60679001b62fb628c4da80e574b9645ab4646056d7c9018885efffe45533"
|
||||
"checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8"
|
||||
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
|
||||
"checksum environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee"
|
||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
|
@ -637,15 +607,13 @@ version = "0.1.0"
|
|||
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
||||
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
|
||||
"checksum num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1"
|
||||
"checksum num-complex 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
|
||||
"checksum num-rational 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e"
|
||||
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
|
||||
"checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe"
|
||||
"checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6"
|
||||
"checksum proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "7a17a4d77bc20d344179de803a34694c0ac7a0b3fb4384bee99783215a8e0410"
|
||||
"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
|
||||
"checksum quote 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3372dc35766b36a99ce2352bd1b6ea0137c38d215cc0c8780bf6de6df7842ba9"
|
||||
"checksum quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ed7d650913520df631972f21e104a4fa2f9c82a14afc65d17b388a2e29731e7c"
|
||||
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
|
||||
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
|
||||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
|
@ -654,16 +622,16 @@ version = "0.1.0"
|
|||
"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7"
|
||||
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
|
||||
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
||||
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||
"checksum ryu 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "16aa12da69951804cddf5f74d96abcc414a31b064e610dc81e37c1536082f491"
|
||||
"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)" = "6dfad05c8854584e5f72fb859385ecdfa03af69c3fd0572f0da2d4c95f060bdb"
|
||||
"checksum serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)" = "b719c6d5e9f73fbc37892246d5852333f040caa617b8873c6aced84bcb28e7bb"
|
||||
"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2"
|
||||
"checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae"
|
||||
"checksum skeptic 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c4474d6da9593171bcb086890fc344a3a12783cb24e5b141f8a5d0e43561f4b6"
|
||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||
"checksum syn 0.14.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e13df71f29f9440b50261a5882c86eac334f1badb3134ec26f0de2f1418e44"
|
||||
"checksum syn 0.14.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b7bfcbb0c068d0f642a0ffbd5c604965a360a61f99e8add013cef23a838614f3"
|
||||
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
|
|
7
zokrates_cli/examples/taxation.code
Normal file
7
zokrates_cli/examples/taxation.code
Normal file
|
@ -0,0 +1,7 @@
|
|||
def wtax(debt,wealth):
|
||||
x = if wealth < debt then 0 else (wealth-debt) fi
|
||||
return x
|
||||
|
||||
def main(debt, wealth):
|
||||
tax = wtax(debt,wealth)
|
||||
return tax
|
|
@ -62,6 +62,10 @@ fn main() {
|
|||
.long("optimized")
|
||||
.help("perform optimization.")
|
||||
.required(false)
|
||||
).arg(Arg::with_name("light")
|
||||
.long("light")
|
||||
.help("Skip logs and human readable output")
|
||||
.required(false)
|
||||
).arg(Arg::with_name("gadgets")
|
||||
.long("gadgets")
|
||||
.help("include libsnark gadgets such as sha256")
|
||||
|
@ -73,7 +77,7 @@ fn main() {
|
|||
.arg(Arg::with_name("input")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.help("path of comiled code.")
|
||||
.help("path of compiled code.")
|
||||
.value_name("FILE")
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
|
@ -195,17 +199,23 @@ fn main() {
|
|||
|
||||
let path = PathBuf::from(sub_matches.value_of("input").unwrap());
|
||||
|
||||
let location = path.parent().unwrap().to_path_buf();
|
||||
let location = path.parent().unwrap().to_path_buf().into_os_string().into_string().unwrap();
|
||||
|
||||
let should_optimize = sub_matches.occurrences_of("optimized") > 0;
|
||||
|
||||
let should_include_gadgets = sub_matches.occurrences_of("gadgets") > 0;
|
||||
|
||||
let light = sub_matches.occurrences_of("light") > 0;
|
||||
|
||||
let bin_output_path = Path::new(sub_matches.value_of("output").unwrap());
|
||||
|
||||
let hr_output_path = bin_output_path.to_path_buf().with_extension("code");
|
||||
|
||||
let file = File::open(path.clone()).unwrap();
|
||||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let program_flattened: FlatProg<FieldPrime> = match compile(&mut reader, location, Some(fs_resolve), should_optimize, should_include_gadgets) {
|
||||
let program_flattened: FlatProg<FieldPrime> = match compile(&mut reader, Some(location), Some(fs_resolve), should_optimize, should_include_gadgets) {
|
||||
Ok(p) => p,
|
||||
Err(why) => panic!("Compilation failed: {}", why)
|
||||
};
|
||||
|
@ -217,7 +227,6 @@ fn main() {
|
|||
.unwrap().statements.len();
|
||||
|
||||
// serialize flattened program and write to binary file
|
||||
let bin_output_path = Path::new(sub_matches.value_of("output").unwrap());
|
||||
let mut bin_output_file = match File::create(&bin_output_path) {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("couldn't create {}: {}", bin_output_path.display(), why),
|
||||
|
@ -225,27 +234,30 @@ fn main() {
|
|||
|
||||
serialize_into(&mut bin_output_file, &program_flattened, Infinite).expect("Unable to write data to file.");
|
||||
|
||||
// write human-readable output file
|
||||
let hr_output_path = bin_output_path.to_path_buf().with_extension("code");
|
||||
if !light {
|
||||
// write human-readable output file
|
||||
let hr_output_file = match File::create(&hr_output_path) {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("couldn't create {}: {}", hr_output_path.display(), why),
|
||||
};
|
||||
|
||||
let hr_output_file = match File::create(&hr_output_path) {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("couldn't create {}: {}", hr_output_path.display(), why),
|
||||
};
|
||||
let mut hrofb = BufWriter::new(hr_output_file);
|
||||
write!(&mut hrofb, "{}\n", program_flattened).expect("Unable to write data to file.");
|
||||
hrofb.flush().expect("Unable to flush buffer.");
|
||||
}
|
||||
|
||||
let mut hrofb = BufWriter::new(hr_output_file);
|
||||
write!(&mut hrofb, "{}\n", program_flattened).expect("Unable to write data to file.");
|
||||
hrofb.flush().expect("Unable to flush buffer.");
|
||||
if !light {
|
||||
// debugging output
|
||||
println!("Compiled program:\n{}", program_flattened);
|
||||
}
|
||||
|
||||
// debugging output
|
||||
println!("Compiled program:\n{}", program_flattened);
|
||||
println!("Compiled code written to '{}'", bin_output_path.display());
|
||||
|
||||
println!(
|
||||
"Compiled code written to '{}', \nHuman readable code to '{}'. \nNumber of constraints: {}",
|
||||
bin_output_path.display(),
|
||||
hr_output_path.display(),
|
||||
num_constraints
|
||||
);
|
||||
if !light {
|
||||
println!("Human readable code to '{}'", hr_output_path.display());
|
||||
}
|
||||
|
||||
println!("Number of constraints: {}", num_constraints);
|
||||
}
|
||||
("compute-witness", Some(sub_matches)) => {
|
||||
println!("Computing witness for:");
|
||||
|
@ -555,9 +567,10 @@ mod tests {
|
|||
// let file = File::open(path.clone()).unwrap();
|
||||
|
||||
// let mut reader = BufReader::new(file);
|
||||
// let location = path.parent().unwrap().to_path_buf().into_os_string().into_string().unwrap();
|
||||
|
||||
// let program_flattened: FlatProg<FieldPrime> =
|
||||
// compile(&mut reader, path.parent().unwrap().to_path_buf(), Some(fs_resolve), true, false).unwrap();
|
||||
// let program_flattened: FlatProg<FieldPrime> =
|
||||
// compile(&mut reader, Some(location), Some(fs_resolve), true, false).unwrap();
|
||||
|
||||
// let (..) = r1cs_program(&program_flattened);
|
||||
// }
|
||||
|
@ -575,10 +588,13 @@ mod tests {
|
|||
|
||||
let file = File::open(path.clone()).unwrap();
|
||||
|
||||
let location = path.parent().unwrap().to_path_buf().into_os_string().into_string().unwrap();
|
||||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let program_flattened: FlatProg<FieldPrime> =
|
||||
compile(&mut reader, path.parent().unwrap().to_path_buf(), Some(fs_resolve), true, false).unwrap();
|
||||
|
||||
compile(&mut reader, Some(location), Some(fs_resolve), true, false).unwrap();
|
||||
|
||||
let (..) = r1cs_program(&program_flattened);
|
||||
let _ = program_flattened.get_witness(vec![FieldPrime::from(0)]).unwrap();
|
||||
|
@ -597,10 +613,13 @@ mod tests {
|
|||
|
||||
let file = File::open(path.clone()).unwrap();
|
||||
|
||||
let location = path.parent().unwrap().to_path_buf().into_os_string().into_string().unwrap();
|
||||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let program_flattened: FlatProg<FieldPrime> =
|
||||
compile(&mut reader, path.parent().unwrap().to_path_buf(), Some(fs_resolve), true, false).unwrap();
|
||||
|
||||
compile(&mut reader, Some(location), Some(fs_resolve), true, false).unwrap();
|
||||
|
||||
let (..) = r1cs_program(&program_flattened);
|
||||
|
||||
|
|
1
zokrates_cli/tests/code/taxation.arguments.json
Normal file
1
zokrates_cli/tests/code/taxation.arguments.json
Normal file
|
@ -0,0 +1 @@
|
|||
[15, 12]
|
7
zokrates_cli/tests/code/taxation.code
Normal file
7
zokrates_cli/tests/code/taxation.code
Normal file
|
@ -0,0 +1,7 @@
|
|||
def wtax(debt,wealth):
|
||||
x = if wealth < debt then 0 else (wealth-debt) fi
|
||||
return x
|
||||
|
||||
def main(debt, wealth):
|
||||
tax = wtax(debt,wealth)
|
||||
return tax
|
1
zokrates_cli/tests/code/taxation.expected.witness
Normal file
1
zokrates_cli/tests/code/taxation.expected.witness
Normal file
|
@ -0,0 +1 @@
|
|||
~out_0 0
|
|
@ -72,7 +72,7 @@ mod integration {
|
|||
compile.push("--optimized");
|
||||
|
||||
// we don't want to test libsnark integrations if libsnark is not available
|
||||
#[cfg(feature = "nolibsnark")]
|
||||
#[cfg(not(feature = "libsnark"))]
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,42 @@ mod integration {
|
|||
.succeeds()
|
||||
.unwrap();
|
||||
|
||||
#[cfg(not(feature = "nolibsnark"))]
|
||||
// COMPUTE_WITNESS
|
||||
let arguments: Value = serde_json::from_reader(File::open(arguments_path).unwrap()).unwrap();
|
||||
|
||||
let arguments_str_list: Vec<String> = arguments.as_array().unwrap().iter().map(|i| match *i {
|
||||
Value::Number(ref n) => n.to_string(),
|
||||
_ => panic!(format!("Cannot read arguments. Check {}", arguments_path.to_str().unwrap()))
|
||||
}).collect();
|
||||
|
||||
let mut compute = vec!["../target/debug/zokrates", "compute-witness",
|
||||
"-i", flattened_path.to_str().unwrap(),
|
||||
"-o", witness_path.to_str().unwrap(),
|
||||
"-a"];
|
||||
|
||||
for arg in arguments_str_list.iter() {
|
||||
compute.push(arg);
|
||||
}
|
||||
|
||||
assert_cli::Assert::command(&compute)
|
||||
.succeeds()
|
||||
.unwrap();
|
||||
|
||||
// load the expected witness
|
||||
let mut expected_witness_file = File::open(&expected_witness_path).unwrap();
|
||||
let mut expected_witness = String::new();
|
||||
expected_witness_file.read_to_string(&mut expected_witness).unwrap();
|
||||
|
||||
// load the actual witness
|
||||
let mut witness_file = File::open(&witness_path).unwrap();
|
||||
let mut witness = String::new();
|
||||
witness_file.read_to_string(&mut witness).unwrap();
|
||||
|
||||
for line in expected_witness.as_str().split("\n") {
|
||||
assert!(witness.contains(line), "Witness generation failed for {}\n\nLine \"{}\" not found in witness", program_path.to_str().unwrap(), line);
|
||||
}
|
||||
|
||||
#[cfg(feature = "libsnark")]
|
||||
{
|
||||
// SETUP
|
||||
assert_cli::Assert::command(&["../target/debug/zokrates", "setup",
|
||||
|
@ -99,40 +134,6 @@ mod integration {
|
|||
.succeeds()
|
||||
.unwrap();
|
||||
|
||||
// COMPUTE_WITNESS
|
||||
let arguments: Value = serde_json::from_reader(File::open(arguments_path).unwrap()).unwrap();
|
||||
|
||||
let arguments_str_list: Vec<String> = arguments.as_array().unwrap().iter().map(|i| match *i {
|
||||
Value::Number(ref n) => n.to_string(),
|
||||
_ => panic!(format!("Cannot read arguments. Check {}", arguments_path.to_str().unwrap()))
|
||||
}).collect();
|
||||
|
||||
let mut compute = vec!["../target/debug/zokrates", "compute-witness",
|
||||
"-i", flattened_path.to_str().unwrap(),
|
||||
"-o", witness_path.to_str().unwrap(),
|
||||
"-a"];
|
||||
|
||||
for arg in arguments_str_list.iter() {
|
||||
compute.push(arg);
|
||||
}
|
||||
|
||||
assert_cli::Assert::command(&compute)
|
||||
.succeeds()
|
||||
.unwrap();
|
||||
|
||||
// load the expected witness
|
||||
let mut expected_witness_file = File::open(&expected_witness_path).unwrap();
|
||||
let mut expected_witness = String::new();
|
||||
expected_witness_file.read_to_string(&mut expected_witness).unwrap();
|
||||
|
||||
// load the actual witness
|
||||
let mut witness_file = File::open(&witness_path).unwrap();
|
||||
let mut witness = String::new();
|
||||
witness_file.read_to_string(&mut witness).unwrap();
|
||||
|
||||
for line in expected_witness.as_str().split("\n") {
|
||||
assert!(witness.contains(line), "Witness generation failed for {}\n\nLine \"{}\" not found in witness", program_path.to_str().unwrap(), line);
|
||||
}
|
||||
// GENERATE-PROOF
|
||||
assert_cli::Assert::command(&["../target/debug/zokrates", "generate-proof",
|
||||
"-w", witness_path.to_str().unwrap(),
|
||||
|
|
|
@ -12,7 +12,8 @@ libsnark = []
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.0"
|
||||
num = "0.1.36"
|
||||
num = {version = "0.1.36", default-features = false}
|
||||
num-bigint = {version = "0.1.36", default-features = false}
|
||||
lazy_static = "0.1.*"
|
||||
reduce = "0.1.1"
|
||||
# cli
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//! @date 2018
|
||||
use std::io::{BufRead};
|
||||
use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
use field::{Field};
|
||||
use absy::{Prog};
|
||||
use flat_absy::{FlatProg};
|
||||
|
@ -60,7 +59,7 @@ impl<T: Field> fmt::Display for CompileError<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compile<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(reader: &mut R, location: PathBuf, resolve_option: Option<fn(&PathBuf) -> Result<S, E>>, should_optimize: bool, should_include_gadgets: bool) -> Result<FlatProg<T>, CompileError<T>> {
|
||||
pub fn compile<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(reader: &mut R, location: Option<String>, resolve_option: Option<fn(&Option<String>, &String) -> Result<(S, String, String), E>>, should_optimize: bool, should_include_gadgets: bool) -> Result<FlatProg<T>, CompileError<T>> {
|
||||
|
||||
let compiled = compile_aux(reader, location, resolve_option, should_include_gadgets);
|
||||
|
||||
|
@ -73,9 +72,51 @@ pub fn compile<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(reader
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compile_aux<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(reader: &mut R, location: PathBuf, resolve_option: Option<fn(&PathBuf) -> Result<S, E>>, should_include_gadgets: bool) -> Result<FlatProg<T>, CompileError<T>> {
|
||||
pub fn compile_aux<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(reader: &mut R, location: Option<String>, resolve_option: Option<fn(&Option<String>, &String) -> Result<(S, String, String), E>>, should_include_gadgets: bool) -> Result<FlatProg<T>, CompileError<T>> {
|
||||
let program_ast_without_imports: Prog<T> = parse_program(reader)?;
|
||||
|
||||
// let mut compiled_imports: Vec<(FlatProg<T>, String)> = vec![];
|
||||
|
||||
// // to resolve imports, we need a resolver
|
||||
// match resolve_option {
|
||||
// Some(resolve) => {
|
||||
// // we have a resolver, pass each import through it
|
||||
// for import in program_ast_without_imports.imports.iter() {
|
||||
// match resolve(&location, import.get_source()) {
|
||||
// Ok((mut res, file_location, default_alias)) => {
|
||||
// let compiled = compile_aux(&mut res, Some(file_location), resolve_option, should_include_gadgets)?;
|
||||
// let alias = match import.get_alias() {
|
||||
// &Some(ref custom_alias) => custom_alias.clone(),
|
||||
// &None => default_alias
|
||||
// };
|
||||
// compiled_imports.push((compiled, alias));
|
||||
// },
|
||||
// Err(err) => return Err(CompileError::ImportError(err.into()))
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// None => {
|
||||
// if program_ast_without_imports.imports.len() > 0 {
|
||||
// return Err(imports::Error::new("Can't resolve import without a resolver").into())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// #[cfg(feature = "libsnark")]
|
||||
// {
|
||||
// use libsnark::{get_sha256_constraints};
|
||||
// use standard::R1CS;
|
||||
// use serde_json::from_str;
|
||||
|
||||
// if should_include_gadgets {
|
||||
// // inject globals
|
||||
// let r1cs: R1CS = from_str(&get_sha256_constraints()).unwrap();
|
||||
|
||||
// compiled_imports.push((FlatProg::from(r1cs), "sha256libsnark".to_string()));
|
||||
// }
|
||||
// }
|
||||
// >>>>>>> b89d5306914cfaec45f0c98c7ea8b1366ffdb7d0
|
||||
|
||||
let program_ast = Importer::new().apply_imports(program_ast_without_imports, location, resolve_option, should_include_gadgets)?;
|
||||
|
||||
// check semantics
|
||||
|
@ -101,7 +142,7 @@ mod test {
|
|||
def main() -> (field):
|
||||
return foo()
|
||||
"#.as_bytes());
|
||||
let res: Result<FlatProg<FieldPrime>, CompileError<FieldPrime>> = compile(&mut r, PathBuf::from("./path/to/file"), None::<fn(&PathBuf) -> Result<BufReader<Empty>, io::Error>>, false, false);
|
||||
let res: Result<FlatProg<FieldPrime>, CompileError<FieldPrime>> = compile(&mut r, Some(String::from("./path/to/file")), None::<fn(&Option<String>, &String) -> Result<(BufReader<Empty>, String, String), io::Error>>, false, false);
|
||||
assert_eq!(format!("{}", res.unwrap_err()), "Import error: Can't resolve import without a resolver".to_string());
|
||||
}
|
||||
|
||||
|
@ -111,7 +152,7 @@ mod test {
|
|||
def main() -> (field):
|
||||
return 1
|
||||
"#.as_bytes());
|
||||
let res: Result<FlatProg<FieldPrime>, CompileError<FieldPrime>> = compile(&mut r, PathBuf::from("./path/to/file"), None::<fn(&PathBuf) -> Result<BufReader<Empty>, io::Error>>, false, false);
|
||||
let res: Result<FlatProg<FieldPrime>, CompileError<FieldPrime>> = compile(&mut r, Some(String::from("./path/to/file")), None::<fn(&Option<String>, &String) -> Result<(BufReader<Empty>, String, String), io::Error>>, false, false);
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
// @date 2017
|
||||
|
||||
use num::{Num, Integer, One, Zero};
|
||||
use num::bigint::{BigInt, BigUint, Sign, ToBigInt};
|
||||
use num_bigint::{BigInt, BigUint, Sign, ToBigInt};
|
||||
use std::convert::From;
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
use std::fmt;
|
||||
|
@ -345,7 +345,7 @@ impl<'de> Deserialize<'de> for FieldPrime {
|
|||
}
|
||||
}
|
||||
|
||||
/// Calculates the gcd using a iterative implementation of the extended euclidian algorithm.
|
||||
/// Calculates the gcd using an iterative implementation of the extended euclidian algorithm.
|
||||
/// Returning `(d, s, t)` so that `d = s * a + t * b`
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -21,7 +21,7 @@ impl fmt::Debug for FlatParameter {
|
|||
}
|
||||
|
||||
impl FlatParameter {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> FlatParameter {
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> FlatParameter {
|
||||
FlatParameter {
|
||||
id: substitution.get(&self.id).unwrap().to_string(),
|
||||
private: self.private
|
||||
|
|
|
@ -212,20 +212,20 @@ impl<T: Field> fmt::Debug for FlatStatement<T> {
|
|||
}
|
||||
|
||||
impl<T: Field> FlatStatement<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> FlatStatement<T> {
|
||||
match *self {
|
||||
FlatStatement::Definition(ref id, ref x) => FlatStatement::Definition(
|
||||
match substitution.get(id) {
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> FlatStatement<T> {
|
||||
match self {
|
||||
FlatStatement::Definition(id, x) => FlatStatement::Definition(
|
||||
match substitution.get(&id) {
|
||||
Some(z) => z.clone(),
|
||||
None => id.clone()
|
||||
},
|
||||
x.apply_substitution(substitution)
|
||||
),
|
||||
FlatStatement::Return(ref x) => FlatStatement::Return(x.apply_substitution(substitution)),
|
||||
FlatStatement::Condition(ref x, ref y) => {
|
||||
FlatStatement::Return(x) => FlatStatement::Return(x.apply_substitution(substitution)),
|
||||
FlatStatement::Condition(x, y) => {
|
||||
FlatStatement::Condition(x.apply_substitution(substitution), y.apply_substitution(substitution))
|
||||
},
|
||||
FlatStatement::Directive(ref d) => {
|
||||
FlatStatement::Directive(d) => {
|
||||
let new_outputs = d.outputs.iter().map(|o| match substitution.get(o) {
|
||||
Some(z) => z.clone(),
|
||||
None => o.clone()
|
||||
|
@ -235,7 +235,7 @@ impl<T: Field> FlatStatement<T> {
|
|||
DirectiveStatement {
|
||||
outputs: new_outputs,
|
||||
inputs: new_inputs,
|
||||
helper: d.helper.clone()
|
||||
helper: d.helper
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -254,10 +254,10 @@ pub enum FlatExpression<T: Field> {
|
|||
}
|
||||
|
||||
impl<T: Field> FlatExpression<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> FlatExpression<T> {
|
||||
match *self {
|
||||
ref e @ FlatExpression::Number(_) => e.clone(),
|
||||
FlatExpression::Identifier(ref v) => {
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> FlatExpression<T> {
|
||||
match self {
|
||||
e @ FlatExpression::Number(_) => e,
|
||||
FlatExpression::Identifier(v) => {
|
||||
let mut new_name = v.to_string();
|
||||
loop {
|
||||
match substitution.get(&new_name) {
|
||||
|
@ -266,19 +266,19 @@ impl<T: Field> FlatExpression<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
FlatExpression::Add(ref e1, ref e2) => FlatExpression::Add(
|
||||
FlatExpression::Add(e1, e2) => FlatExpression::Add(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FlatExpression::Sub(ref e1, ref e2) => FlatExpression::Sub(
|
||||
FlatExpression::Sub(e1, e2) => FlatExpression::Sub(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FlatExpression::Mult(ref e1, ref e2) => FlatExpression::Mult(
|
||||
FlatExpression::Mult(e1, e2) => FlatExpression::Mult(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FlatExpression::Div(ref e1, ref e2) => FlatExpression::Div(
|
||||
FlatExpression::Div(e1, e2) => FlatExpression::Div(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
)
|
||||
|
@ -383,10 +383,9 @@ impl<T: Field> fmt::Display for FlatExpressionList<T> {
|
|||
}
|
||||
|
||||
impl<T: Field> FlatExpressionList<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> FlatExpressionList<T> {
|
||||
let expressions: Vec<FlatExpression<T>> = self.expressions.iter().map(|e| e.apply_substitution(substitution)).collect();
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> FlatExpressionList<T> {
|
||||
FlatExpressionList {
|
||||
expressions: expressions
|
||||
expressions: self.expressions.into_iter().map(|e| e.apply_substitution(substitution)).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,8 +177,8 @@ impl Flattener {
|
|||
// bitness checks
|
||||
for i in 0..self.bits - 2 {
|
||||
let new_name = format!("{}{}{}", &lhs_name, BINARY_SEPARATOR, i);
|
||||
statements_flattened.push(FlatStatement::Condition(
|
||||
FlatExpression::Identifier(new_name.to_string()),
|
||||
statements_flattened.push(FlatStatement::Definition(
|
||||
new_name.to_string(),
|
||||
FlatExpression::Mult(
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
|
@ -212,8 +212,8 @@ impl Flattener {
|
|||
// bitness checks
|
||||
for i in 0..self.bits - 2 {
|
||||
let new_name = format!("{}{}{}", &rhs_name, BINARY_SEPARATOR, i);
|
||||
statements_flattened.push(FlatStatement::Condition(
|
||||
FlatExpression::Identifier(new_name.to_string()),
|
||||
statements_flattened.push(FlatStatement::Definition(
|
||||
new_name.to_string(),
|
||||
FlatExpression::Mult(
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
|
@ -257,8 +257,8 @@ impl Flattener {
|
|||
// sym_b{i} = sym_b{i}**2 (bitness checks)
|
||||
for i in 0..self.bits {
|
||||
let new_name = format!("{}{}{}", &subtraction_result, BINARY_SEPARATOR, i);
|
||||
statements_flattened.push(FlatStatement::Condition(
|
||||
FlatExpression::Identifier(new_name.to_string()),
|
||||
statements_flattened.push(FlatStatement::Definition(
|
||||
new_name.to_string(),
|
||||
FlatExpression::Mult(
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
box FlatExpression::Identifier(new_name.to_string()),
|
||||
|
@ -403,7 +403,7 @@ impl Flattener {
|
|||
|
||||
// Handle complex parameters and assign values:
|
||||
// Rename Parameters, assign them to values in call. Resolve complex expressions with definitions
|
||||
for (i, param_expr) in param_expressions.iter().enumerate() {
|
||||
for (i, param_expr) in param_expressions.clone().into_iter().enumerate() {
|
||||
let new_var;
|
||||
let param_expr = param_expr.apply_substitution(&self.substitution);
|
||||
|
||||
|
@ -727,12 +727,12 @@ impl Flattener {
|
|||
functions_flattened: &mut Vec<FlatFunction<T>>,
|
||||
arguments_flattened: &Vec<FlatParameter>,
|
||||
statements_flattened: &mut Vec<FlatStatement<T>>,
|
||||
stat: &TypedStatement<T>,
|
||||
stat: TypedStatement<T>,
|
||||
) {
|
||||
match *stat {
|
||||
TypedStatement::Return(ref exprs) => {
|
||||
match stat {
|
||||
TypedStatement::Return(exprs) => {
|
||||
|
||||
let flat_expressions = exprs.iter().map(|expr| {
|
||||
let flat_expressions = exprs.into_iter().map(|expr| {
|
||||
match expr {
|
||||
TypedExpression::FieldElement(e) => {
|
||||
let expr_subbed = e.apply_substitution(&self.substitution);
|
||||
|
@ -759,7 +759,7 @@ impl Flattener {
|
|||
// declarations have already been checked
|
||||
()
|
||||
}
|
||||
TypedStatement::Definition(ref v, ref expr) => {
|
||||
TypedStatement::Definition(v, expr) => {
|
||||
|
||||
// define n variables with n the number of primitive types for v_type
|
||||
// assign them to the n primitive types for expr
|
||||
|
@ -785,7 +785,7 @@ impl Flattener {
|
|||
_ => panic!("Definitions must have type FieldElement")
|
||||
}
|
||||
}
|
||||
TypedStatement::Condition(ref expr1, ref expr2) => {
|
||||
TypedStatement::Condition(expr1, expr2) => {
|
||||
|
||||
// flatten expr1 and expr2 to n flattened expressions with n the number of primitive types for expr1
|
||||
// add n conditions to check equality of the n expressions
|
||||
|
@ -834,14 +834,14 @@ impl Flattener {
|
|||
_ => panic!("Conditions (Assertions) must be applied to expressions of type FieldElement")
|
||||
}
|
||||
}
|
||||
TypedStatement::For(ref var, ref start, ref end, ref statements) => {
|
||||
let mut current = start.clone();
|
||||
while ¤t < end {
|
||||
TypedStatement::For(var, start, end, statements) => {
|
||||
let mut current = start;
|
||||
while current < end {
|
||||
statements_flattened.push(FlatStatement::Definition(
|
||||
self.use_variable(&var.id),
|
||||
FlatExpression::Number(current.clone()),
|
||||
));
|
||||
for s in statements {
|
||||
for s in statements.clone() {
|
||||
self.flatten_statement(
|
||||
functions_flattened,
|
||||
arguments_flattened,
|
||||
|
@ -852,24 +852,24 @@ impl Flattener {
|
|||
current = T::one() + ¤t;
|
||||
}
|
||||
}
|
||||
TypedStatement::MultipleDefinition(ref vars, ref rhs) => {
|
||||
TypedStatement::MultipleDefinition(vars, rhs) => {
|
||||
|
||||
// flatten the right side to p = sum(var_i.type.primitive_count) expressions
|
||||
// define p new variables to the right side expressions
|
||||
|
||||
let var_types = vars.iter().map(|v| v.get_type()).collect();
|
||||
|
||||
let rhs_subbed = rhs.apply_substitution(&self.substitution);
|
||||
|
||||
match rhs_subbed {
|
||||
TypedExpressionList::FunctionCall(ref fun_id, ref exprs, ref types) => {
|
||||
let var_types = vars.iter().map(|v| v.get_type()).collect();
|
||||
|
||||
TypedExpressionList::FunctionCall(fun_id, exprs, types) => {
|
||||
let rhs_flattened = self.flatten_function_call(
|
||||
functions_flattened,
|
||||
arguments_flattened,
|
||||
statements_flattened,
|
||||
fun_id,
|
||||
&fun_id,
|
||||
var_types,
|
||||
exprs,
|
||||
&exprs,
|
||||
);
|
||||
|
||||
for (i, v) in vars.into_iter().enumerate() {
|
||||
|
@ -930,12 +930,12 @@ impl Flattener {
|
|||
}
|
||||
}
|
||||
// flatten statements in functions and apply substitution
|
||||
for stat in &funct.statements {
|
||||
for stat in funct.statements {
|
||||
self.flatten_statement(
|
||||
functions_flattened,
|
||||
&arguments_flattened,
|
||||
&mut statements_flattened,
|
||||
&stat,
|
||||
stat,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1057,7 +1057,7 @@ mod multiple_definition {
|
|||
&mut functions_flattened,
|
||||
&arguments_flattened,
|
||||
&mut statements_flattened,
|
||||
&statement,
|
||||
statement,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -1108,7 +1108,7 @@ mod multiple_definition {
|
|||
&mut functions_flattened,
|
||||
&arguments_flattened,
|
||||
&mut statements_flattened,
|
||||
&statement,
|
||||
statement,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -1155,7 +1155,7 @@ mod multiple_definition {
|
|||
&mut functions_flattened,
|
||||
&arguments_flattened,
|
||||
&mut statements_flattened,
|
||||
&statement,
|
||||
statement,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
|
|
@ -11,7 +11,6 @@ use std::fmt;
|
|||
use absy::*;
|
||||
use flat_absy::*;
|
||||
use field::Field;
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
|
||||
pub struct CompiledImport<T: Field> {
|
||||
|
@ -60,44 +59,58 @@ impl From<io::Error> for Error {
|
|||
|
||||
#[derive(PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct Import {
|
||||
source: PathBuf,
|
||||
alias: String,
|
||||
source: String,
|
||||
alias: Option<String>,
|
||||
}
|
||||
|
||||
impl Import {
|
||||
pub fn new(source: String) -> Import {
|
||||
Import {
|
||||
source: PathBuf::from(source.clone()),
|
||||
alias: PathBuf::from(source).file_stem().unwrap().to_os_string().to_string_lossy().to_string(),
|
||||
source: source,
|
||||
alias: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alias(&self) -> String {
|
||||
self.alias.clone()
|
||||
pub fn get_alias(&self) -> &Option<String> {
|
||||
&self.alias
|
||||
}
|
||||
|
||||
pub fn new_with_alias(source: String, alias: &String) -> Import {
|
||||
Import {
|
||||
source: PathBuf::from(source.clone()),
|
||||
alias: alias.clone(),
|
||||
source: source,
|
||||
alias: Some(alias.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_source(&self) -> &PathBuf {
|
||||
pub fn get_source(&self) -> &String {
|
||||
&self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Import {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "import {} as {}", self.source.clone().into_os_string().into_string().unwrap(), self.alias)
|
||||
match self.alias {
|
||||
Some(ref alias) => {
|
||||
write!(f, "import {} as {}", self.source, alias)
|
||||
},
|
||||
None => {
|
||||
write!(f, "import {}", self.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Import {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "import(source: {}, alias: {})", self.source.clone().into_os_string().into_string().unwrap(), self.alias)
|
||||
}
|
||||
match self.alias {
|
||||
Some(ref alias) => {
|
||||
write!(f, "import(source: {}, alias: {})", self.source, alias)
|
||||
},
|
||||
None => {
|
||||
write!(f, "import(source: {})", self.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Importer {
|
||||
|
@ -111,7 +124,7 @@ impl Importer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn apply_imports<T: Field, S: BufRead, E: Into<Error>>(&self, destination: Prog<T>, location: PathBuf, resolve_option: Option<fn(&PathBuf) -> Result<S, E>>, should_include_gadgets: bool) -> Result<Prog<T>, CompileError<T>> {
|
||||
pub fn apply_imports<T: Field, S: BufRead, E: Into<Error>>(&self, destination: Prog<T>, location: Option<String>, resolve_option: Option<fn(&Option<String>, &String) -> Result<(S, String, String), E>>, should_include_gadgets: bool) -> Result<Prog<T>, CompileError<T>> {
|
||||
|
||||
let mut origins: Vec<CompiledImport<T>> = vec![];
|
||||
|
||||
|
@ -121,11 +134,14 @@ impl Importer {
|
|||
// we have a resolver, pass each import through it
|
||||
for import in destination.imports.iter() {
|
||||
// find the absolute path for the import, based on the path of the file which imports it
|
||||
let absolute_import_path = location.join(import.get_source());
|
||||
match resolve(&absolute_import_path) {
|
||||
Ok(mut res) => {
|
||||
let compiled = compile_aux(&mut res, absolute_import_path.parent().unwrap().to_path_buf(), resolve_option, should_include_gadgets)?;
|
||||
origins.push(CompiledImport::new(compiled, import.alias()));
|
||||
match resolve(&location, &import.source) {
|
||||
Ok((mut reader, location, auto_alias)) => {
|
||||
let compiled = compile_aux(&mut reader, Some(location), resolve_option, should_include_gadgets)?;
|
||||
let alias = match import.alias {
|
||||
Some(ref alias) => alias.clone(),
|
||||
None => auto_alias
|
||||
};
|
||||
origins.push(CompiledImport::new(compiled, alias));
|
||||
},
|
||||
Err(err) => return Err(CompileError::ImportError(err.into()))
|
||||
}
|
||||
|
@ -169,16 +185,16 @@ mod tests {
|
|||
#[test]
|
||||
fn create_with_no_alias() {
|
||||
assert_eq!(Import::new("./foo/bar/baz.code".to_string()), Import {
|
||||
source: PathBuf::from("./foo/bar/baz.code"),
|
||||
alias: "baz".to_string(),
|
||||
source: String::from("./foo/bar/baz.code"),
|
||||
alias: None,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_with_alias() {
|
||||
assert_eq!(Import::new_with_alias("./foo/bar/baz.code".to_string(), &"myalias".to_string()), Import {
|
||||
source: PathBuf::from("./foo/bar/baz.code"),
|
||||
alias: "myalias".to_string(),
|
||||
source: String::from("./foo/bar/baz.code"),
|
||||
alias: Some("myalias".to_string()),
|
||||
});
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate num;
|
||||
extern crate num_bigint;
|
||||
extern crate reduce; // better reduce function than Iter.fold
|
||||
extern crate serde; // serialization deserialization
|
||||
extern crate serde_json;
|
||||
|
|
|
@ -215,7 +215,7 @@ fn vec_as_u8_32_array(vec: &Vec<u8>) -> [u8; 32] {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use num::bigint::BigUint;
|
||||
use num_bigint::BigUint;
|
||||
use serde_json;
|
||||
use flat_absy::*;
|
||||
use standard;
|
||||
|
|
|
@ -93,8 +93,8 @@ impl Optimizer {
|
|||
}
|
||||
|
||||
// generate optimized statements by removing synonym declarations and renaming variables
|
||||
let optimized_statements = funct.statements.iter().filter_map(|statement| {
|
||||
match *statement {
|
||||
let optimized_statements = funct.statements.into_iter().filter_map(|statement| {
|
||||
match statement {
|
||||
// filter out synonyms definitions
|
||||
FlatStatement::Definition(_, FlatExpression::Identifier(_)) => {
|
||||
None
|
||||
|
@ -107,15 +107,13 @@ impl Optimizer {
|
|||
}).collect();
|
||||
|
||||
// generate optimized arguments by renaming them
|
||||
let optimized_arguments = funct.arguments.iter().map(|arg| arg.apply_substitution(&self.substitution)).collect();
|
||||
let optimized_arguments = funct.arguments.into_iter().map(|arg| arg.apply_substitution(&self.substitution)).collect();
|
||||
|
||||
// clone function
|
||||
let mut optimized_funct = funct.clone();
|
||||
// update statements with optimized ones
|
||||
optimized_funct.statements = optimized_statements;
|
||||
optimized_funct.arguments = optimized_arguments;
|
||||
|
||||
optimized_funct
|
||||
FlatFunction {
|
||||
arguments: optimized_arguments,
|
||||
statements: optimized_statements,
|
||||
..funct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ fn get_summands<T: Field>(expr: &FlatExpression<T>) -> Vec<&FlatExpression<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a `HashMap` containing variables and the number of occurences
|
||||
/// Returns a `HashMap` containing variables and the number of occurrences
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
|
|
@ -145,6 +145,7 @@ impl Checker {
|
|||
signature: func.signature
|
||||
});
|
||||
}
|
||||
|
||||
self.check_single_main()?;
|
||||
|
||||
Ok(TypedProg {
|
||||
|
@ -155,7 +156,7 @@ impl Checker {
|
|||
}
|
||||
|
||||
fn check_single_main(&mut self) -> Result<(), Error> {
|
||||
match self.functions.clone().into_iter().filter(|fun| fun.id == "main").count() {
|
||||
match self.functions.iter().filter(|fun| fun.id == "main").count() {
|
||||
1 => Ok(()),
|
||||
0 => Err(Error { message: format!("No main function found") }),
|
||||
n => Err(Error { message: format!("Only one main function allowed, found {}", n) })
|
||||
|
|
|
@ -7,7 +7,7 @@ use reduce::Reduce;
|
|||
use helpers::{DirectiveStatement, Helper, LibsnarkGadgetHelper};
|
||||
|
||||
// for r1cs import, can be moved.
|
||||
// r1cs data strucutre reflecting JSON standard format:
|
||||
// r1cs data structure reflecting JSON standard format:
|
||||
// {
|
||||
// input_count: count, // # of inputs to pass
|
||||
// outputs: [offset_42, offset_63, offset_55], // indices of the outputs in the witness
|
||||
|
|
|
@ -310,10 +310,10 @@ pub enum BooleanExpression<T: Field> {
|
|||
}
|
||||
|
||||
impl<T: Field> BooleanExpression<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> BooleanExpression<T> {
|
||||
match *self {
|
||||
BooleanExpression::Identifier(ref id) => {
|
||||
let mut new_name = id.clone();
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> BooleanExpression<T> {
|
||||
match self {
|
||||
BooleanExpression::Identifier(id) => {
|
||||
let mut new_name = id;
|
||||
loop {
|
||||
match substitution.get(&new_name) {
|
||||
Some(x) => new_name = x.to_string(),
|
||||
|
@ -321,23 +321,23 @@ impl<T: Field> BooleanExpression<T> {
|
|||
}
|
||||
}
|
||||
},
|
||||
BooleanExpression::Lt(ref lhs, ref rhs) => BooleanExpression::Lt(
|
||||
BooleanExpression::Lt(lhs, rhs) => BooleanExpression::Lt(
|
||||
box lhs.apply_substitution(substitution),
|
||||
box rhs.apply_substitution(substitution),
|
||||
),
|
||||
BooleanExpression::Le(ref lhs, ref rhs) => BooleanExpression::Le(
|
||||
BooleanExpression::Le(lhs, rhs) => BooleanExpression::Le(
|
||||
box lhs.apply_substitution(substitution),
|
||||
box rhs.apply_substitution(substitution),
|
||||
),
|
||||
BooleanExpression::Eq(ref lhs, ref rhs) => BooleanExpression::Eq(
|
||||
BooleanExpression::Eq(lhs, rhs) => BooleanExpression::Eq(
|
||||
box lhs.apply_substitution(substitution),
|
||||
box rhs.apply_substitution(substitution),
|
||||
),
|
||||
BooleanExpression::Ge(ref lhs, ref rhs) => BooleanExpression::Ge(
|
||||
BooleanExpression::Ge(lhs, rhs) => BooleanExpression::Ge(
|
||||
box lhs.apply_substitution(substitution),
|
||||
box rhs.apply_substitution(substitution),
|
||||
),
|
||||
BooleanExpression::Gt(ref lhs, ref rhs) => BooleanExpression::Gt(
|
||||
BooleanExpression::Gt(lhs, rhs) => BooleanExpression::Gt(
|
||||
box lhs.apply_substitution(substitution),
|
||||
box rhs.apply_substitution(substitution),
|
||||
),
|
||||
|
@ -351,10 +351,10 @@ impl<T: Field> BooleanExpression<T> {
|
|||
}
|
||||
|
||||
impl<T: Field> FieldElementExpression<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> FieldElementExpression<T> {
|
||||
match *self {
|
||||
ref e @ FieldElementExpression::Number(_) => e.clone(),
|
||||
FieldElementExpression::Identifier(ref id) => {
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> FieldElementExpression<T> {
|
||||
match self {
|
||||
e @ FieldElementExpression::Number(_) => e,
|
||||
FieldElementExpression::Identifier(id) => {
|
||||
let mut new_name = id.clone();
|
||||
loop {
|
||||
match substitution.get(&new_name) {
|
||||
|
@ -363,36 +363,33 @@ impl<T: Field> FieldElementExpression<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
FieldElementExpression::Add(ref e1, ref e2) => FieldElementExpression::Add(
|
||||
FieldElementExpression::Add(e1, e2) => FieldElementExpression::Add(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::Sub(ref e1, ref e2) => FieldElementExpression::Sub(
|
||||
FieldElementExpression::Sub(e1, e2) => FieldElementExpression::Sub(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::Mult(ref e1, ref e2) => FieldElementExpression::Mult(
|
||||
FieldElementExpression::Mult(e1, e2) => FieldElementExpression::Mult(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::Div(ref e1, ref e2) => FieldElementExpression::Div(
|
||||
FieldElementExpression::Div(e1, e2) => FieldElementExpression::Div(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::Pow(ref e1, ref e2) => FieldElementExpression::Pow(
|
||||
FieldElementExpression::Pow(e1, e2) => FieldElementExpression::Pow(
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::IfElse(ref c, ref e1, ref e2) => FieldElementExpression::IfElse(
|
||||
FieldElementExpression::IfElse(c, e1, e2) => FieldElementExpression::IfElse(
|
||||
box c.apply_substitution(substitution),
|
||||
box e1.apply_substitution(substitution),
|
||||
box e2.apply_substitution(substitution),
|
||||
),
|
||||
FieldElementExpression::FunctionCall(ref i, ref p) => {
|
||||
for param in p {
|
||||
param.apply_substitution(substitution);
|
||||
}
|
||||
FieldElementExpression::FunctionCall(i.clone(), p.clone())
|
||||
FieldElementExpression::FunctionCall(i, p) => {
|
||||
FieldElementExpression::FunctionCall(i, p.into_iter().map(|param| param.apply_substitution(substitution)).collect())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -495,7 +492,7 @@ impl<T: Field> fmt::Debug for FieldElementExpression<T> {
|
|||
|
||||
|
||||
impl<T: Field> TypedExpression<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> TypedExpression<T> {
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> TypedExpression<T> {
|
||||
match self {
|
||||
TypedExpression::Boolean(e) => e.apply_substitution(substitution).into(),
|
||||
TypedExpression::FieldElement(e) => e.apply_substitution(substitution).into(),
|
||||
|
@ -504,10 +501,10 @@ impl<T: Field> TypedExpression<T> {
|
|||
}
|
||||
|
||||
impl<T: Field> TypedExpressionList<T> {
|
||||
pub fn apply_substitution(&self, substitution: &Substitution) -> TypedExpressionList<T> {
|
||||
match *self {
|
||||
TypedExpressionList::FunctionCall(ref id, ref inputs, ref types) => {
|
||||
TypedExpressionList::FunctionCall(id.clone(), inputs.iter().map(|i| i.apply_substitution(substitution)).collect(), types.clone())
|
||||
pub fn apply_substitution(self, substitution: &Substitution) -> TypedExpressionList<T> {
|
||||
match self {
|
||||
TypedExpressionList::FunctionCall(id, inputs, types) => {
|
||||
TypedExpressionList::FunctionCall(id, inputs.into_iter().map(|i| i.apply_substitution(substitution)).collect(), types)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,83 @@ use std::path::PathBuf;
|
|||
use std::fs::File;
|
||||
use std::io;
|
||||
|
||||
pub fn resolve(source: &PathBuf) -> Result<BufReader<File>, io::Error> {
|
||||
File::open(source).and_then(|f| Ok(BufReader::new(f)))
|
||||
pub fn resolve(location: &Option<String>, source: &String) -> Result<(BufReader<File>, String, String), io::Error> {
|
||||
// the fs resolver has to be provided a location, as it supports relative paths
|
||||
match location {
|
||||
Some(location) => resolve_with_location(location, source),
|
||||
None => Err(io::Error::new(io::ErrorKind::Other, "No location provided"))
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_with_location(location: &String, source: &String) -> Result<(BufReader<File>, String, String), io::Error> {
|
||||
let path = PathBuf::from(location).join(PathBuf::from(source));
|
||||
let (next_location, alias) = generate_next_parameters(&path)?;
|
||||
|
||||
File::open(path).and_then(|f| Ok((BufReader::new(f), next_location, alias)))
|
||||
}
|
||||
|
||||
fn generate_next_parameters(path: &PathBuf) -> Result<(String, String), io::Error> {
|
||||
match (path.parent(), path.file_stem()) {
|
||||
(Some(parent), Some(stem)) => Ok(
|
||||
(
|
||||
parent.to_path_buf().into_os_string().into_string().unwrap(),
|
||||
stem.to_os_string().to_string_lossy().to_string()
|
||||
)
|
||||
),
|
||||
_ => Err(io::Error::new(io::ErrorKind::Other, "Invalid path"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn valid_path_with_location() {
|
||||
let (_, next_location, alias) = resolve(&Some(String::from("./src")), &String::from("lib.rs")).unwrap();
|
||||
assert_eq!(next_location, String::from("./src"));
|
||||
assert_eq!(alias, String::from("lib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_path_without_location() {
|
||||
let res = resolve(&None, &String::from("./src/lib.rs"));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_existing_file() {
|
||||
let res = resolve(&Some(String::from("./src")), &String::from("rubbish.rs"));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_location() {
|
||||
let res = resolve(&Some(String::from(",8!-$2abc")), &String::from("foo.code"));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_file() {
|
||||
let res = resolve(&Some(String::from("./src")), &String::from(",8!-$2abc"));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_a_file() {
|
||||
let res = resolve(&Some(String::from(".")), &String::from("/src/"));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_parent() {
|
||||
let res = resolve(&Some(String::from(".")), &String::from("."));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_file_name() {
|
||||
let res = resolve(&Some(String::from(".")), &String::from(""));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue