mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-26 08:30:59 +03:00
Merge branch 'master' into leo-manifest-dependencies
This commit is contained in:
commit
a04249976e
@ -46,7 +46,7 @@ commands:
|
|||||||
jobs:
|
jobs:
|
||||||
check-style:
|
check-style:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
@ -61,7 +61,7 @@ jobs:
|
|||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
@ -76,7 +76,7 @@ jobs:
|
|||||||
|
|
||||||
# code-cov:
|
# code-cov:
|
||||||
# docker:
|
# docker:
|
||||||
# - image: cimg/rust:1.53.0
|
# - image: cimg/rust:1.54.0
|
||||||
# resource_class: xlarge
|
# resource_class: xlarge
|
||||||
# environment:
|
# environment:
|
||||||
# RUSTC_BOOTSTRAP: 1
|
# RUSTC_BOOTSTRAP: 1
|
||||||
@ -118,7 +118,7 @@ jobs:
|
|||||||
|
|
||||||
leo-executable:
|
leo-executable:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
@ -136,7 +136,7 @@ jobs:
|
|||||||
|
|
||||||
leo-new:
|
leo-new:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -149,7 +149,7 @@ jobs:
|
|||||||
|
|
||||||
leo-init:
|
leo-init:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -162,7 +162,7 @@ jobs:
|
|||||||
|
|
||||||
leo-clean:
|
leo-clean:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -175,7 +175,7 @@ jobs:
|
|||||||
|
|
||||||
leo-setup:
|
leo-setup:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -188,7 +188,7 @@ jobs:
|
|||||||
|
|
||||||
# leo-add-remove:
|
# leo-add-remove:
|
||||||
# docker:
|
# docker:
|
||||||
# - image: cimg/rust:1.53
|
# - image: cimg/rust:1.54.0
|
||||||
# resource_class: xlarge
|
# resource_class: xlarge
|
||||||
# steps:
|
# steps:
|
||||||
# - attach_workspace:
|
# - attach_workspace:
|
||||||
@ -201,7 +201,7 @@ jobs:
|
|||||||
|
|
||||||
leo-check-constraints:
|
leo-check-constraints:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -214,7 +214,7 @@ jobs:
|
|||||||
|
|
||||||
leo-login-logout:
|
leo-login-logout:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -227,7 +227,7 @@ jobs:
|
|||||||
|
|
||||||
leo-clone:
|
leo-clone:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
@ -240,7 +240,7 @@ jobs:
|
|||||||
|
|
||||||
leo-publish:
|
leo-publish:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/rust:1.53
|
- image: cimg/rust:1.54.0
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Force certain files to be LF
|
||||||
|
*.leo text eol=lf
|
||||||
|
*.out text eol=lf
|
||||||
|
*.rs text eol=lf
|
87
.github/workflows/ci.yml
vendored
87
.github/workflows/ci.yml
vendored
@ -93,14 +93,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
sccache --start-server
|
sccache --start-server
|
||||||
|
|
||||||
- name: Install cargo-all-features
|
|
||||||
run: |
|
|
||||||
cargo install cargo-all-features
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
uses: actions-rs/cargo@v1
|
||||||
cd package
|
with:
|
||||||
cargo test-all-features
|
command: test
|
||||||
|
args: --all --features ci_skip
|
||||||
|
|
||||||
- name: Print sccache stats
|
- name: Print sccache stats
|
||||||
run: sccache --show-stats
|
run: sccache --show-stats
|
||||||
@ -160,17 +157,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
sccache --start-server
|
sccache --start-server
|
||||||
|
|
||||||
- name: Install cargo-all-features
|
|
||||||
run: |
|
|
||||||
SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) \
|
|
||||||
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) \
|
|
||||||
cargo install cargo-all-features
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) \
|
SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) \
|
||||||
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) \
|
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) \
|
||||||
cd package && cargo test-all-features
|
cargo test --all --features ci_skip
|
||||||
|
|
||||||
- name: Print sccache stats
|
- name: Print sccache stats
|
||||||
run: sccache --show-stats
|
run: sccache --show-stats
|
||||||
@ -178,6 +169,74 @@ jobs:
|
|||||||
- name: Stop sccache server
|
- name: Stop sccache server
|
||||||
run: sccache --stop-server || true
|
run: sccache --stop-server || true
|
||||||
|
|
||||||
|
test-docs:
|
||||||
|
name: Test Docs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUSTC_WRAPPER: sccache
|
||||||
|
SCCACHE_CACHE_SIZE: 2G
|
||||||
|
SCCACHE_DIR: /home/runner/.cache/sccache
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: master
|
||||||
|
|
||||||
|
- name: Install sccache
|
||||||
|
env:
|
||||||
|
LINK: https://github.com/mozilla/sccache/releases/download
|
||||||
|
SCCACHE_VERSION: v0.2.15
|
||||||
|
run: |
|
||||||
|
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
|
||||||
|
mkdir -p $HOME/.local/bin
|
||||||
|
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
|
||||||
|
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
|
||||||
|
chmod +x $HOME/.local/bin/sccache
|
||||||
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Cache cargo registry
|
||||||
|
uses: actions/cache@v2
|
||||||
|
continue-on-error: false
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: Install Rust Stable
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Save sccache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
continue-on-error: false
|
||||||
|
with:
|
||||||
|
path: /home/runner/.cache/sccache
|
||||||
|
key: ubuntu-sccache-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: ubuntu-sccache-
|
||||||
|
|
||||||
|
- name: Start sccache server
|
||||||
|
run: sccache --start-server
|
||||||
|
|
||||||
|
- name: Build Cargo Docs
|
||||||
|
env:
|
||||||
|
RUSTDOCFLAGS: "--enable-index-page -Zunstable-options"
|
||||||
|
RUSTC_BOOTSTRAP: "1"
|
||||||
|
run: |
|
||||||
|
cargo doc --no-deps --document-private-items --workspace
|
||||||
|
rm -rf ./tests
|
||||||
|
|
||||||
|
- name: Print sccache stats
|
||||||
|
run: sccache --show-stats
|
||||||
|
|
||||||
|
- name: Stop sccache server
|
||||||
|
run: sccache --stop-server || true
|
||||||
|
|
||||||
codecov:
|
codecov:
|
||||||
name: Code Coverage
|
name: Code Coverage
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
69
.github/workflows/docs.yml
vendored
Normal file
69
.github/workflows/docs.yml
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
name: Master Crates Docs
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-crates-docs:
|
||||||
|
name: Build Crates Docs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUSTC_WRAPPER: sccache
|
||||||
|
SCCACHE_CACHE_SIZE: 2G
|
||||||
|
SCCACHE_DIR: /home/runner/.cache/sccache
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: master
|
||||||
|
|
||||||
|
- name: Install sccache
|
||||||
|
env:
|
||||||
|
LINK: https://github.com/mozilla/sccache/releases/download
|
||||||
|
SCCACHE_VERSION: v0.2.15
|
||||||
|
run: |
|
||||||
|
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
|
||||||
|
mkdir -p $HOME/.local/bin
|
||||||
|
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
|
||||||
|
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
|
||||||
|
chmod +x $HOME/.local/bin/sccache
|
||||||
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Install Rust Stable
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Save sccache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
continue-on-error: false
|
||||||
|
with:
|
||||||
|
path: /home/runner/.cache/sccache
|
||||||
|
key: ubuntu-sccache-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: ubuntu-sccache-
|
||||||
|
|
||||||
|
- name: Start sccache server
|
||||||
|
run: sccache --start-server
|
||||||
|
|
||||||
|
- name: Build Cargo Docs
|
||||||
|
env:
|
||||||
|
RUSTDOCFLAGS: "--enable-index-page -Zunstable-options"
|
||||||
|
RUSTC_BOOTSTRAP: "1"
|
||||||
|
run: |
|
||||||
|
cargo doc --no-deps --document-private-items --workspace
|
||||||
|
rm -rf ./tests
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./target/doc/
|
||||||
|
|
||||||
|
- name: Print sccache stats
|
||||||
|
run: sccache --show-stats
|
||||||
|
|
||||||
|
- name: Stop sccache server
|
||||||
|
run: sccache --stop-server || true
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,6 +9,9 @@
|
|||||||
**/.crates2.json
|
**/.crates2.json
|
||||||
**/bin/
|
**/bin/
|
||||||
|
|
||||||
|
# sccache from pipeline
|
||||||
|
sccache*/
|
||||||
|
|
||||||
# Emacs gitignore files
|
# Emacs gitignore files
|
||||||
*~
|
*~
|
||||||
\#*\#
|
\#*\#
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[hooks]
|
[hooks]
|
||||||
pre-commit = "cargo clippy && cargo +nightly fmt --all -- --check"
|
pre-commit = "cargo clippy && cargo fmt --all -- --check"
|
||||||
|
|
||||||
[logging]
|
[logging]
|
||||||
verbose = true
|
verbose = true
|
||||||
|
126
Cargo.lock
generated
126
Cargo.lock
generated
@ -23,9 +23,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
version = "0.15.2"
|
version = "0.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e7a2e47a1fbe209ee101dd6d61285226744c6c8d3c21c8dc878ba6cb9f467f3a"
|
checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gimli",
|
"gimli",
|
||||||
]
|
]
|
||||||
@ -119,9 +119,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.60"
|
version = "0.3.61"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7815ea54e4d821e791162e078acbebfd6d8c8939cd559c9335dceb1c8ca7282"
|
checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"addr2line",
|
"addr2line",
|
||||||
"cc",
|
"cc",
|
||||||
@ -340,6 +340,17 @@ dependencies = [
|
|||||||
"vec_map",
|
"vec_map",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "color-backtrace"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cd6c04463c99389fff045d2b90ce84f5131332712c7ffbede020f5e9ad1ed685"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"backtrace",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colored"
|
name = "colored"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -640,6 +651,16 @@ dependencies = [
|
|||||||
"indexmap",
|
"indexmap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "eyre"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "221239d1d5ea86bf5d6f91c9d6bc3646ffe471b08ff9b0f91c44f115ac969d2b"
|
||||||
|
dependencies = [
|
||||||
|
"indenter",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "failure"
|
name = "failure"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
@ -900,9 +921,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gimli"
|
name = "gimli"
|
||||||
version = "0.24.0"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189"
|
checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
@ -1044,6 +1065,12 @@ dependencies = [
|
|||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indenter"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
@ -1172,12 +1199,12 @@ dependencies = [
|
|||||||
"criterion",
|
"criterion",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
|
"leo-errors",
|
||||||
"leo-parser",
|
"leo-parser",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tendril",
|
"tendril",
|
||||||
"thiserror",
|
|
||||||
"typed-arena",
|
"typed-arena",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1186,21 +1213,21 @@ name = "leo-asg-passes"
|
|||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"leo-asg",
|
"leo-asg",
|
||||||
|
"leo-errors",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "leo-ast"
|
name = "leo-ast"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
|
||||||
"criterion",
|
"criterion",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
"leo-errors",
|
||||||
"leo-input",
|
"leo-input",
|
||||||
"pest",
|
"pest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tendril",
|
"tendril",
|
||||||
"thiserror",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1213,6 +1240,7 @@ dependencies = [
|
|||||||
"leo-asg",
|
"leo-asg",
|
||||||
"leo-asg-passes",
|
"leo-asg-passes",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
|
"leo-errors",
|
||||||
"leo-imports",
|
"leo-imports",
|
||||||
"leo-input",
|
"leo-input",
|
||||||
"leo-package",
|
"leo-package",
|
||||||
@ -1237,10 +1265,25 @@ dependencies = [
|
|||||||
"snarkvm-utilities",
|
"snarkvm-utilities",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tendril",
|
"tendril",
|
||||||
"thiserror",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "leo-errors"
|
||||||
|
version = "1.5.3"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
"color-backtrace",
|
||||||
|
"colored",
|
||||||
|
"derivative",
|
||||||
|
"eyre",
|
||||||
|
"leo-input",
|
||||||
|
"pest",
|
||||||
|
"serde",
|
||||||
|
"tendril",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "leo-imports"
|
name = "leo-imports"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
@ -1248,8 +1291,8 @@ dependencies = [
|
|||||||
"indexmap",
|
"indexmap",
|
||||||
"leo-asg",
|
"leo-asg",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
|
"leo-errors",
|
||||||
"leo-parser",
|
"leo-parser",
|
||||||
"thiserror",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1270,9 +1313,9 @@ name = "leo-lang"
|
|||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.12.1",
|
"ansi_term 0.12.1",
|
||||||
"anyhow",
|
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"clap",
|
"clap",
|
||||||
|
"color-backtrace",
|
||||||
"colored",
|
"colored",
|
||||||
"console",
|
"console",
|
||||||
"dirs",
|
"dirs",
|
||||||
@ -1281,6 +1324,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
"leo-compiler",
|
"leo-compiler",
|
||||||
|
"leo-errors",
|
||||||
"leo-imports",
|
"leo-imports",
|
||||||
"leo-input",
|
"leo-input",
|
||||||
"leo-package",
|
"leo-package",
|
||||||
@ -1302,7 +1346,6 @@ dependencies = [
|
|||||||
"snarkvm-utilities",
|
"snarkvm-utilities",
|
||||||
"structopt",
|
"structopt",
|
||||||
"test_dir",
|
"test_dir",
|
||||||
"thiserror",
|
|
||||||
"toml",
|
"toml",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
@ -1319,8 +1362,8 @@ version = "1.5.3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"leo-errors",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
|
||||||
"toml",
|
"toml",
|
||||||
"tracing",
|
"tracing",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
@ -1335,12 +1378,12 @@ dependencies = [
|
|||||||
"indexmap",
|
"indexmap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
|
"leo-errors",
|
||||||
"leo-test-framework",
|
"leo-test-framework",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"tendril",
|
"tendril",
|
||||||
"thiserror",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1350,6 +1393,7 @@ version = "1.5.3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"leo-ast",
|
"leo-ast",
|
||||||
|
"leo-errors",
|
||||||
"leo-input",
|
"leo-input",
|
||||||
"rand 0.8.4",
|
"rand 0.8.4",
|
||||||
"rand_core 0.6.3",
|
"rand_core 0.6.3",
|
||||||
@ -1358,14 +1402,15 @@ dependencies = [
|
|||||||
"snarkvm-curves",
|
"snarkvm-curves",
|
||||||
"snarkvm-dpc",
|
"snarkvm-dpc",
|
||||||
"snarkvm-utilities",
|
"snarkvm-utilities",
|
||||||
"thiserror",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "leo-synthesizer"
|
name = "leo-synthesizer"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"eyre",
|
||||||
"hex",
|
"hex",
|
||||||
|
"leo-errors",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -1691,9 +1736,9 @@ checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.25.3"
|
version = "0.26.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7"
|
checksum = "c55827317fb4c08822499848a14237d2874d6f139828893017237e7ab93eb386"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
@ -2363,9 +2408,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml"
|
name = "serde_yaml"
|
||||||
version = "0.8.17"
|
version = "0.8.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23"
|
checksum = "039ba818c784248423789eec090aab9fb566c7b94d6ebbfa1814a9fd52c8afb2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dtoa",
|
"dtoa",
|
||||||
"linked-hash-map",
|
"linked-hash-map",
|
||||||
@ -2430,9 +2475,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-algorithms"
|
name = "snarkvm-algorithms"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "40caa98abd0a874a003d844d6a73562020fb5fa976daa14055f030d9803430b7"
|
checksum = "3534da2cfa71894e4d28c5dcaf9f9c5c94315904c4ace6c86419a8f2ff8b1641"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bitvec",
|
"bitvec",
|
||||||
@ -2487,9 +2532,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-dpc"
|
name = "snarkvm-dpc"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1588a3d2f38307bd64838cf1761d8cef485461e5224831c9b9df11a1fa9864e7"
|
checksum = "c922bb690fbe9c5919f67f2d887452376339a36bf5ffb50dc6b00d58a5650284"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base58",
|
"base58",
|
||||||
@ -2535,9 +2580,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-gadgets"
|
name = "snarkvm-gadgets"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3b0cd11387a572f9a1c318c1d446dd46e0522c9be7681b8d6af6882d20880fd"
|
checksum = "3138cfcaaa27e53cabc7a4fc596b3b0abb47c3cb46fee496e3ac7ce2cd07df9d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derivative",
|
"derivative",
|
||||||
"digest 0.9.0",
|
"digest 0.9.0",
|
||||||
@ -2555,9 +2600,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-marlin"
|
name = "snarkvm-marlin"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "206d633d6299dfb4f52640a3188567462dbf1f207de70cbb829707c07858c7e6"
|
checksum = "12e6987cde7b734415afc7afe58a038d224393842ad5dfaba728a601c5c5473d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2",
|
"blake2",
|
||||||
"derivative",
|
"derivative",
|
||||||
@ -2579,9 +2624,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-parameters"
|
name = "snarkvm-parameters"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f5c4d4233a623c46c483296aa24bf4d95a5f3344c669ce4f2956467fe6ea904"
|
checksum = "506cbbbfe27acb4d4e8dd15e49b430dbfb920fd680cfe1c69ab87542083d0422"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"curl",
|
"curl",
|
||||||
"hex",
|
"hex",
|
||||||
@ -2592,9 +2637,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-polycommit"
|
name = "snarkvm-polycommit"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b5ca8d560cb6f49d9de9b4a955778cc14563b0a381c56db48ea6171788f30d4"
|
checksum = "c23a7fa2aab25aa6fc3b7fb27b3d639936725a5c29b29936d1530b64bd011e67"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derivative",
|
"derivative",
|
||||||
"digest 0.9.0",
|
"digest 0.9.0",
|
||||||
@ -2611,15 +2656,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-profiler"
|
name = "snarkvm-profiler"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "29cb28d79c59db77774484dbc0f4e876dc8604085d8d7f43eee1b813ec0614b4"
|
checksum = "f7d80cc343b9e19e0f38582fa7e17e6263c4c7449122cf9a606279567ff33d71"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snarkvm-r1cs"
|
name = "snarkvm-r1cs"
|
||||||
version = "0.7.8"
|
version = "0.7.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a12e3b7acea34af74dbe5dea056714a9f3c9b1029a9ac888595c96a6e3c676e6"
|
checksum = "537f2123c7da8a9d3482523156318479790c41e390d33f6936b89a3ed9eee0a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"fxhash",
|
"fxhash",
|
||||||
@ -2761,6 +2806,15 @@ dependencies = [
|
|||||||
"utf-8",
|
"utf-8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "terminal_size"
|
name = "terminal_size"
|
||||||
version = "0.1.17"
|
version = "0.1.17"
|
||||||
|
14
Cargo.toml
14
Cargo.toml
@ -30,6 +30,7 @@ members = [
|
|||||||
"asg-passes",
|
"asg-passes",
|
||||||
"ast",
|
"ast",
|
||||||
"compiler",
|
"compiler",
|
||||||
|
"errors",
|
||||||
"grammar",
|
"grammar",
|
||||||
"imports",
|
"imports",
|
||||||
"input",
|
"input",
|
||||||
@ -49,6 +50,10 @@ version = "1.5.3"
|
|||||||
path = "./compiler"
|
path = "./compiler"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
|
|
||||||
|
[dependencies.leo-errors]
|
||||||
|
path = "./errors"
|
||||||
|
version = "1.5.3"
|
||||||
|
|
||||||
[dependencies.leo-imports]
|
[dependencies.leo-imports]
|
||||||
path = "./imports"
|
path = "./imports"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
@ -91,15 +96,15 @@ default-features = false
|
|||||||
[dependencies.snarkvm-utilities]
|
[dependencies.snarkvm-utilities]
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
|
||||||
[dependencies.anyhow]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dependencies.structopt]
|
[dependencies.structopt]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "2.33.3"
|
version = "2.33.3"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
color-backtrace = "0.5.1"
|
||||||
|
|
||||||
[dependencies.colored]
|
[dependencies.colored]
|
||||||
version = "2.0"
|
version = "2.0"
|
||||||
|
|
||||||
@ -143,9 +148,6 @@ features = [ "derive" ]
|
|||||||
[dependencies.serde_json]
|
[dependencies.serde_json]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
[dependencies.thiserror]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dependencies.toml]
|
[dependencies.toml]
|
||||||
version = "0.5"
|
version = "0.5"
|
||||||
|
|
||||||
|
@ -23,3 +23,7 @@ path = "src/lib.rs"
|
|||||||
[dependencies.leo-asg]
|
[dependencies.leo-asg]
|
||||||
path = "../asg"
|
path = "../asg"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
|
|
||||||
|
[dependencies.leo-errors]
|
||||||
|
path = "../errors"
|
||||||
|
version = "1.5.3"
|
||||||
|
0
asg-passes/README.md
Normal file
0
asg-passes/README.md
Normal file
@ -17,6 +17,7 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
use leo_asg::*;
|
use leo_asg::*;
|
||||||
|
use leo_errors::LeoError;
|
||||||
|
|
||||||
pub struct ConstantFolding<'a, 'b> {
|
pub struct ConstantFolding<'a, 'b> {
|
||||||
program: &'b Program<'a>,
|
program: &'b Program<'a>,
|
||||||
@ -45,7 +46,7 @@ impl<'a, 'b> StatementVisitor<'a> for ConstantFolding<'a, 'b> {}
|
|||||||
impl<'a, 'b> ProgramVisitor<'a> for ConstantFolding<'a, 'b> {}
|
impl<'a, 'b> ProgramVisitor<'a> for ConstantFolding<'a, 'b> {}
|
||||||
|
|
||||||
impl<'a, 'b> AsgPass<'a> for ConstantFolding<'a, 'b> {
|
impl<'a, 'b> AsgPass<'a> for ConstantFolding<'a, 'b> {
|
||||||
fn do_pass(asg: Program<'a>) -> Result<Program<'a>, FormattedError> {
|
fn do_pass(asg: Program<'a>) -> Result<Program<'a>, LeoError> {
|
||||||
let pass = ConstantFolding { program: &asg };
|
let pass = ConstantFolding { program: &asg };
|
||||||
let mut director = VisitorDirector::new(pass);
|
let mut director = VisitorDirector::new(pass);
|
||||||
director.visit_program(&asg).ok();
|
director.visit_program(&asg).ok();
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
use leo_asg::*;
|
use leo_asg::*;
|
||||||
|
use leo_errors::LeoError;
|
||||||
|
|
||||||
pub struct DeadCodeElimination {}
|
pub struct DeadCodeElimination {}
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ impl<'a> ReconstructingReducerStatement<'a> for DeadCodeElimination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsgPass<'a> for DeadCodeElimination {
|
impl<'a> AsgPass<'a> for DeadCodeElimination {
|
||||||
fn do_pass(asg: Program<'a>) -> Result<Program<'a>, FormattedError> {
|
fn do_pass(asg: Program<'a>) -> Result<Program<'a>, LeoError> {
|
||||||
let pass = DeadCodeElimination {};
|
let pass = DeadCodeElimination {};
|
||||||
let mut director = ReconstructingDirector::new(asg.context, pass);
|
let mut director = ReconstructingDirector::new(asg.context, pass);
|
||||||
Ok(director.reduce_program(asg))
|
Ok(director.reduce_program(asg))
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
pub mod constant_folding;
|
pub mod constant_folding;
|
||||||
pub use constant_folding::*;
|
pub use constant_folding::*;
|
||||||
|
|
||||||
|
@ -26,13 +26,14 @@ version = "1.0"
|
|||||||
[dependencies.indexmap]
|
[dependencies.indexmap]
|
||||||
version = "1.7"
|
version = "1.7"
|
||||||
|
|
||||||
[dependencies.thiserror]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dependencies.leo-ast]
|
[dependencies.leo-ast]
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
path = "../ast"
|
path = "../ast"
|
||||||
|
|
||||||
|
[dependencies.leo-errors]
|
||||||
|
path = "../errors"
|
||||||
|
version = "1.5.3"
|
||||||
|
|
||||||
[dependencies.leo-parser]
|
[dependencies.leo-parser]
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
path = "../parser"
|
path = "../parser"
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{statement::*, BoolAnd, Expression, Monoid, MonoidalReducerExpression, MonoidalReducerStatement, Node};
|
||||||
statement::*, BoolAnd, Expression, Monoid, MonoidalReducerExpression, MonoidalReducerStatement, Node, Span,
|
|
||||||
};
|
use leo_errors::Span;
|
||||||
|
|
||||||
pub struct ReturnPathReducer {
|
pub struct ReturnPathReducer {
|
||||||
pub errors: Vec<(Span, String)>,
|
pub errors: Vec<(Span, String)>,
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, Circuit, Identifier, IntegerType, Span, Type};
|
use crate::{Circuit, Identifier, IntegerType, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
@ -313,18 +314,18 @@ impl ConstInt {
|
|||||||
Type::Integer(self.get_int_type())
|
Type::Integer(self.get_int_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result<ConstInt, AsgConvertError> {
|
pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result<ConstInt> {
|
||||||
Ok(match int_type {
|
Ok(match int_type {
|
||||||
IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,329 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//! Errors encountered when attempting to convert to an asg from an ast.
|
|
||||||
|
|
||||||
use crate::Span;
|
|
||||||
use leo_ast::{AstError, FormattedError, LeoError};
|
|
||||||
use leo_parser::SyntaxError;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum AsgConvertError {
|
|
||||||
#[error("{}", _0)]
|
|
||||||
Error(#[from] FormattedError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
ImportError(FormattedError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
AstError(#[from] AstError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
InternalError(String),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
SyntaxError(#[from] SyntaxError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LeoError for AsgConvertError {}
|
|
||||||
|
|
||||||
impl AsgConvertError {
|
|
||||||
fn new_from_span(message: String, span: &Span) -> Self {
|
|
||||||
AsgConvertError::Error(FormattedError::new_from_span(message, span))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_circuit(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to resolve circuit: '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_import(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to resolve import: '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_circuit_member(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"illegal reference to non-existant member '{}' of circuit '{}'",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn missing_circuit_member(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"missing circuit member '{}' for initialization of circuit '{}'",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn overridden_circuit_member(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot declare circuit member '{}' more than once for initialization of circuit '{}'",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn redefined_circuit_member(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot declare circuit member '{}' multiple times in circuit '{}'",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn extra_circuit_member(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"extra circuit member '{}' for initialization of circuit '{}' is not allowed",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn illegal_function_assign(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("attempt to assign to function '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_variable_call(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("cannot call variable member '{}' of circuit '{}'", name, circuit_name),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_static_call_invalid(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot call static function '{}' of circuit '{}' from target",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_member_mut_call_invalid(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot call mutable member function '{}' of circuit '{}' from immutable context",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_member_call_invalid(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot call member function '{}' of circuit '{}' from static context",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_function_ref(circuit_name: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"cannot reference function member '{}' of circuit '{}' as value",
|
|
||||||
name, circuit_name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn index_into_non_array(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to index into non-array '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_assign_index(name: &str, num: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("failed to index array with invalid integer '{}'[{}]", name, num),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_backwards_assignment(name: &str, left: usize, right: usize, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"failed to index array range for assignment with left > right '{}'[{}..{}]",
|
|
||||||
name, left, right
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_const_assign(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"failed to create const variable(s) '{}' with non constant values.",
|
|
||||||
name
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn duplicate_function_definition(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("a function named \"{}\" already exists in this scope", name),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn duplicate_variable_definition(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("a variable named \"{}\" already exists in this scope", name),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn index_into_non_tuple(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to index into non-tuple '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tuple_index_out_of_bounds(index: usize, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("tuple index out of bounds: '{}'", index), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn array_index_out_of_bounds(index: usize, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("array index out of bounds: '{}'", index), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ternary_different_types(left: &str, right: &str, span: &Span) -> Self {
|
|
||||||
let message = format!("ternary sides had different types: left {}, right {}", left, right);
|
|
||||||
|
|
||||||
Self::new_from_span(message, span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unknown_array_size(span: &Span) -> Self {
|
|
||||||
Self::new_from_span("array size cannot be inferred, add explicit types".to_string(), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unexpected_call_argument_count(expected: usize, got: usize, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("function call expected {} arguments, got {}", expected, got),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_function(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to resolve function: '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_type(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("failed to resolve type for variable definition '{}'", name),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unexpected_type(expected: &str, received: Option<&str>, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!(
|
|
||||||
"unexpected type, expected: '{}', received: '{}'",
|
|
||||||
expected,
|
|
||||||
received.unwrap_or("unknown")
|
|
||||||
),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unexpected_nonconst(span: &Span) -> Self {
|
|
||||||
Self::new_from_span("expected const, found non-const value".to_string(), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unresolved_reference(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to resolve variable reference '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_boolean(value: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to parse boolean value '{}'", value), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_char(value: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to parse char value '{}'", value), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_int(value: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("failed to parse int value '{}'", value), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unsigned_negation(span: &Span) -> Self {
|
|
||||||
Self::new_from_span("cannot negate unsigned integer".to_string(), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn immutable_assignment(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("illegal assignment to immutable variable '{}'", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn function_missing_return(name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(format!("function '{}' missing return for all paths", name), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn function_return_validation(name: &str, description: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("function '{}' failed to validate return path: '{}'", name, description),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn input_ref_needs_type(category: &str, name: &str, span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
format!("could not infer type for input in '{}': '{}'", category, name),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_self_in_global(span: &Span) -> Self {
|
|
||||||
Self::new_from_span(
|
|
||||||
"cannot have `mut self` or `self` arguments in global functions".to_string(),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn call_test_function(span: &Span) -> Self {
|
|
||||||
Self::new_from_span("cannot call test function".to_string(), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn circuit_test_function(span: &Span) -> Self {
|
|
||||||
Self::new_from_span("cannot have test function as member of circuit".to_string(), span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_index_error() -> Self {
|
|
||||||
AsgConvertError::InternalError("failed to parse index".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_dimension_error() -> Self {
|
|
||||||
AsgConvertError::InternalError("failed to parse dimension".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reference_self_outside_circuit() -> Self {
|
|
||||||
AsgConvertError::InternalError("referenced self outside of circuit function".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn illegal_ast_structure(details: &str) -> Self {
|
|
||||||
AsgConvertError::InternalError(format!("illegal ast structure: {}", details))
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
use leo_ast::IntegerType;
|
use leo_ast::IntegerType;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<'
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ArrayAccessExpression,
|
value: &leo_ast::ArrayAccessExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<ArrayAccessExpression<'a>, AsgConvertError> {
|
) -> Result<ArrayAccessExpression<'a>> {
|
||||||
let array = <&Expression<'a>>::from_ast(
|
let array = <&Expression<'a>>::from_ast(
|
||||||
scope,
|
scope,
|
||||||
&*value.array,
|
&*value.array,
|
||||||
@ -92,11 +93,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<'
|
|||||||
let array_len = match array.get_type() {
|
let array_len = match array.get_type() {
|
||||||
Some(Type::Array(_, len)) => len,
|
Some(Type::Array(_, len)) => len,
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"array",
|
"array",
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,10 +114,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<'
|
|||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if index >= array_len {
|
if index >= array_len {
|
||||||
return Err(AsgConvertError::array_index_out_of_bounds(
|
return Err(
|
||||||
index,
|
AsgError::array_index_out_of_bounds(index, &array.span().cloned().unwrap_or_default()).into(),
|
||||||
&array.span().cloned().unwrap_or_default(),
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -68,16 +69,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ArrayInitExpression,
|
value: &leo_ast::ArrayInitExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<ArrayInitExpression<'a>, AsgConvertError> {
|
) -> Result<ArrayInitExpression<'a>> {
|
||||||
let (mut expected_item, expected_len) = match expected_type {
|
let (mut expected_item, expected_len) = match expected_type {
|
||||||
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
|
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(type_, "array", &value.span).into());
|
||||||
&type_.to_string(),
|
|
||||||
Some("array"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let dimensions = value
|
let dimensions = value
|
||||||
@ -85,20 +82,23 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
|
|||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
x.value
|
Ok(x.value
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.map_err(|_| AsgConvertError::parse_dimension_error())
|
.map_err(|_| AsgError::parse_dimension_error(&value.span))?)
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
let len = *dimensions.get(0).ok_or_else(AsgConvertError::parse_dimension_error)?;
|
let len = *dimensions
|
||||||
|
.get(0)
|
||||||
|
.ok_or_else(|| AsgError::parse_dimension_error(&value.span))?;
|
||||||
if let Some(expected_len) = expected_len {
|
if let Some(expected_len) = expected_len {
|
||||||
if expected_len != len {
|
if expected_len != len {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
&*format!("array of length {}", expected_len),
|
format!("array of length {}", expected_len),
|
||||||
Some(&*format!("array of length {}", len)),
|
format!("array of length {}", len),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,11 +107,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
|
|||||||
Some(PartialType::Array(item, len)) => {
|
Some(PartialType::Array(item, len)) => {
|
||||||
if let Some(len) = len {
|
if let Some(len) = len {
|
||||||
if len != dimension {
|
if len != dimension {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
&*format!("array of length {}", dimension),
|
format!("array of length {}", dimension),
|
||||||
Some(&*format!("array of length {}", len)),
|
format!("array of length {}", len),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +120,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
|
|||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type("array", type_, &value.span).into());
|
||||||
"array",
|
|
||||||
Some(&type_.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
use leo_ast::SpreadOrExpression;
|
use leo_ast::SpreadOrExpression;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -103,16 +104,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ArrayInlineExpression,
|
value: &leo_ast::ArrayInlineExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<ArrayInlineExpression<'a>, AsgConvertError> {
|
) -> Result<ArrayInlineExpression<'a>> {
|
||||||
let (mut expected_item, expected_len) = match expected_type {
|
let (mut expected_item, expected_len) = match expected_type {
|
||||||
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
|
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(type_, "array", &value.span).into());
|
||||||
&type_.to_string(),
|
|
||||||
Some("array"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -169,29 +166,31 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
|
|||||||
len += spread_len;
|
len += spread_len;
|
||||||
}
|
}
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
expected_item
|
expected_item
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.unwrap_or("unknown"),
|
.unwrap_or("unknown"),
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok((Cell::new(expr), true))
|
Ok((Cell::new(expr), true))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?,
|
.collect::<Result<Vec<_>>>()?,
|
||||||
};
|
};
|
||||||
if let Some(expected_len) = expected_len {
|
if let Some(expected_len) = expected_len {
|
||||||
if len != expected_len {
|
if len != expected_len {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
&*format!("array of length {}", expected_len),
|
format!("array of length {}", expected_len),
|
||||||
Some(&*format!("array of length {}", len)),
|
format!("array of length {}", len),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
use leo_ast::IntegerType;
|
use leo_ast::IntegerType;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -102,16 +103,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ArrayRangeAccessExpression,
|
value: &leo_ast::ArrayRangeAccessExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<ArrayRangeAccessExpression<'a>, AsgConvertError> {
|
) -> Result<ArrayRangeAccessExpression<'a>> {
|
||||||
let (expected_array, expected_len) = match expected_type.clone() {
|
let (expected_array, expected_len) = match expected_type.clone() {
|
||||||
Some(PartialType::Array(element, len)) => (Some(PartialType::Array(element, None)), len),
|
Some(PartialType::Array(element, len)) => (Some(PartialType::Array(element, None)), len),
|
||||||
None => (None, None),
|
None => (None, None),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, "array", &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some("array"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?;
|
let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?;
|
||||||
@ -119,11 +116,12 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
let (parent_element, parent_size) = match array_type {
|
let (parent_element, parent_size) = match array_type {
|
||||||
Some(Type::Array(inner, size)) => (inner, size),
|
Some(Type::Array(inner, size)) => (inner, size),
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"array",
|
"array",
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
} else {
|
} else {
|
||||||
value.span.clone()
|
value.span.clone()
|
||||||
};
|
};
|
||||||
return Err(AsgConvertError::array_index_out_of_bounds(inner_value, &error_span));
|
return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into());
|
||||||
} else if let Some(left) = const_left {
|
} else if let Some(left) = const_left {
|
||||||
if left > inner_value {
|
if left > inner_value {
|
||||||
let error_span = if let Some(right) = right {
|
let error_span = if let Some(right) = right {
|
||||||
@ -165,7 +163,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
} else {
|
} else {
|
||||||
value.span.clone()
|
value.span.clone()
|
||||||
};
|
};
|
||||||
return Err(AsgConvertError::array_index_out_of_bounds(inner_value, &error_span));
|
return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,11 +183,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
if let Some(length) = length {
|
if let Some(length) = length {
|
||||||
if length != expected_len {
|
if length != expected_len {
|
||||||
let concrete_type = Type::Array(parent_element, length);
|
let concrete_type = Type::Array(parent_element, length);
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(
|
||||||
&expected_type.as_ref().unwrap().to_string(),
|
AsgError::unexpected_type(expected_type.as_ref().unwrap(), concrete_type, &value.span).into(),
|
||||||
Some(&concrete_type.to_string()),
|
);
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(left_value) = const_left {
|
if let Some(left_value) = const_left {
|
||||||
@ -199,13 +195,13 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
|
|||||||
} else {
|
} else {
|
||||||
value.span.clone()
|
value.span.clone()
|
||||||
};
|
};
|
||||||
return Err(AsgConvertError::array_index_out_of_bounds(left_value, &error_span));
|
return Err(AsgError::array_index_out_of_bounds(left_value, &error_span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
length = Some(expected_len);
|
length = Some(expected_len);
|
||||||
}
|
}
|
||||||
if length.is_none() {
|
if length.is_none() {
|
||||||
return Err(AsgConvertError::unknown_array_size(&value.span));
|
return Err(AsgError::unknown_array_size(&value.span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ArrayRangeAccessExpression {
|
Ok(ArrayRangeAccessExpression {
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
pub use leo_ast::{BinaryOperation, BinaryOperationClass};
|
pub use leo_ast::{BinaryOperation, BinaryOperationClass};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -116,17 +117,13 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::BinaryExpression,
|
value: &leo_ast::BinaryExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<BinaryExpression<'a>, AsgConvertError> {
|
) -> Result<BinaryExpression<'a>> {
|
||||||
let class = value.op.class();
|
let class = value.op.class();
|
||||||
let expected_type = match class {
|
let expected_type = match class {
|
||||||
BinaryOperationClass::Boolean => match expected_type {
|
BinaryOperationClass::Boolean => match expected_type {
|
||||||
Some(PartialType::Type(Type::Boolean)) | None => None,
|
Some(PartialType::Type(Type::Boolean)) | None => None,
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Boolean.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BinaryOperationClass::Numeric => match expected_type {
|
BinaryOperationClass::Numeric => match expected_type {
|
||||||
@ -134,11 +131,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
|
|||||||
Some(x @ PartialType::Type(Type::Field)) => Some(x),
|
Some(x @ PartialType::Type(Type::Field)) => Some(x),
|
||||||
Some(x @ PartialType::Type(Type::Group)) => Some(x),
|
Some(x @ PartialType::Type(Type::Group)) => Some(x),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, "integer, field, or group", &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some("integer, field, or group"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
@ -187,33 +180,26 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
|
|||||||
}
|
}
|
||||||
Some(Type::Field) if value.op == BinaryOperation::Mul || value.op == BinaryOperation::Div => (),
|
Some(Type::Field) if value.op == BinaryOperation::Mul || value.op == BinaryOperation::Div => (),
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"integer",
|
"integer",
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BinaryOperationClass::Boolean => match &value.op {
|
BinaryOperationClass::Boolean => match &value.op {
|
||||||
BinaryOperation::And | BinaryOperation::Or => match left_type {
|
BinaryOperation::And | BinaryOperation::Or => match left_type {
|
||||||
Some(Type::Boolean) | None => (),
|
Some(Type::Boolean) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Boolean.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BinaryOperation::Eq | BinaryOperation::Ne => (), // all types allowed
|
BinaryOperation::Eq | BinaryOperation::Ne => (), // all types allowed
|
||||||
_ => match left_type {
|
_ => match left_type {
|
||||||
Some(Type::Integer(_)) | None => (),
|
Some(Type::Integer(_)) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, "integer", &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some("integer"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -224,19 +210,11 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
|
|||||||
match (left_type, right_type) {
|
match (left_type, right_type) {
|
||||||
(Some(left_type), Some(right_type)) => {
|
(Some(left_type), Some(right_type)) => {
|
||||||
if !left_type.is_assignable_from(&right_type) {
|
if !left_type.is_assignable_from(&right_type) {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(left_type, right_type, &value.span).into());
|
||||||
&left_type.to_string(),
|
|
||||||
Some(&*right_type.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type("any type", "unknown type", &value.span).into());
|
||||||
"any type",
|
|
||||||
Some("unknown type"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
(_, _) => (),
|
(_, _) => (),
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Function, FunctionQualifier, Node,
|
CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Function, FunctionQualifier, Node, PartialType,
|
||||||
PartialType, Scope, Span, Type,
|
Scope, Type,
|
||||||
};
|
};
|
||||||
pub use leo_ast::{BinaryOperation, Node as AstNode};
|
pub use leo_ast::{BinaryOperation, Node as AstNode};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -78,13 +79,13 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::CallExpression,
|
value: &leo_ast::CallExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<CallExpression<'a>, AsgConvertError> {
|
) -> Result<CallExpression<'a>> {
|
||||||
let (target, function) = match &*value.function {
|
let (target, function) = match &*value.function {
|
||||||
leo_ast::Expression::Identifier(name) => (
|
leo_ast::Expression::Identifier(name) => (
|
||||||
None,
|
None,
|
||||||
scope
|
scope
|
||||||
.resolve_function(&name.name)
|
.resolve_function(&name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_function(&name.name, &name.span))?,
|
.ok_or_else(|| AsgError::unresolved_function(&name.name, &name.span))?,
|
||||||
),
|
),
|
||||||
leo_ast::Expression::CircuitMemberAccess(leo_ast::CircuitMemberAccessExpression {
|
leo_ast::Expression::CircuitMemberAccess(leo_ast::CircuitMemberAccessExpression {
|
||||||
circuit: ast_circuit,
|
circuit: ast_circuit,
|
||||||
@ -95,37 +96,32 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
|||||||
let circuit = match target.get_type() {
|
let circuit = match target.get_type() {
|
||||||
Some(Type::Circuit(circuit)) => circuit,
|
Some(Type::Circuit(circuit)) => circuit,
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"circuit",
|
"circuit",
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
span,
|
span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let circuit_name = circuit.name.borrow().name.clone();
|
let circuit_name = circuit.name.borrow().name.clone();
|
||||||
let member = circuit.members.borrow();
|
let member = circuit.members.borrow();
|
||||||
let member = member
|
let member = member
|
||||||
.get(name.name.as_ref())
|
.get(name.name.as_ref())
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
.ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
||||||
match member {
|
match member {
|
||||||
CircuitMember::Function(body) => {
|
CircuitMember::Function(body) => {
|
||||||
if body.qualifier == FunctionQualifier::Static {
|
if body.qualifier == FunctionQualifier::Static {
|
||||||
return Err(AsgConvertError::circuit_static_call_invalid(
|
return Err(AsgError::circuit_static_call_invalid(&circuit_name, &name.name, span).into());
|
||||||
&circuit_name,
|
|
||||||
&name.name,
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
} else if body.qualifier == FunctionQualifier::MutSelfRef && !target.is_mut_ref() {
|
} else if body.qualifier == FunctionQualifier::MutSelfRef && !target.is_mut_ref() {
|
||||||
return Err(AsgConvertError::circuit_member_mut_call_invalid(
|
return Err(
|
||||||
&circuit_name,
|
AsgError::circuit_member_mut_call_invalid(circuit_name, &name.name, span).into(),
|
||||||
&name.name,
|
);
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
(Some(target), *body)
|
(Some(target), *body)
|
||||||
}
|
}
|
||||||
CircuitMember::Variable(_) => {
|
CircuitMember::Variable(_) => {
|
||||||
return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, span));
|
return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,54 +133,49 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
|||||||
let circuit = if let leo_ast::Expression::Identifier(circuit_name) = &**ast_circuit {
|
let circuit = if let leo_ast::Expression::Identifier(circuit_name) = &**ast_circuit {
|
||||||
scope
|
scope
|
||||||
.resolve_circuit(&circuit_name.name)
|
.resolve_circuit(&circuit_name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&circuit_name.name, &circuit_name.span))?
|
.ok_or_else(|| AsgError::unresolved_circuit(&circuit_name.name, &circuit_name.span))?
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unexpected_type("circuit", None, span));
|
return Err(AsgError::unexpected_type("circuit", "unknown", span).into());
|
||||||
};
|
};
|
||||||
let circuit_name = circuit.name.borrow().name.clone();
|
let circuit_name = circuit.name.borrow().name.clone();
|
||||||
|
|
||||||
let member = circuit.members.borrow();
|
let member = circuit.members.borrow();
|
||||||
let member = member
|
let member = member
|
||||||
.get(name.name.as_ref())
|
.get(name.name.as_ref())
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
.ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
||||||
match member {
|
match member {
|
||||||
CircuitMember::Function(body) => {
|
CircuitMember::Function(body) => {
|
||||||
if body.qualifier != FunctionQualifier::Static {
|
if body.qualifier != FunctionQualifier::Static {
|
||||||
return Err(AsgConvertError::circuit_member_call_invalid(
|
return Err(AsgError::circuit_member_call_invalid(circuit_name, &name.name, span).into());
|
||||||
&circuit_name,
|
|
||||||
&name.name,
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
(None, *body)
|
(None, *body)
|
||||||
}
|
}
|
||||||
CircuitMember::Variable(_) => {
|
CircuitMember::Variable(_) => {
|
||||||
return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, span));
|
return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AsgConvertError::illegal_ast_structure(
|
return Err(AsgError::illegal_ast_structure(
|
||||||
"non Identifier/CircuitMemberAccess/CircuitStaticFunctionAccess as call target",
|
"non Identifier/CircuitMemberAccess/CircuitStaticFunctionAccess as call target",
|
||||||
));
|
&value.span,
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(expected) = expected_type {
|
if let Some(expected) = expected_type {
|
||||||
let output: Type = function.output.clone();
|
let output: Type = function.output.clone();
|
||||||
if !expected.matches(&output) {
|
if !expected.matches(&output) {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(expected, output, &value.span).into());
|
||||||
&expected.to_string(),
|
|
||||||
Some(&*output.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if value.arguments.len() != function.arguments.len() {
|
if value.arguments.len() != function.arguments.len() {
|
||||||
return Err(AsgConvertError::unexpected_call_argument_count(
|
return Err(AsgError::unexpected_call_argument_count(
|
||||||
function.arguments.len(),
|
function.arguments.len(),
|
||||||
value.arguments.len(),
|
value.arguments.len(),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let arguments = value
|
let arguments = value
|
||||||
@ -195,14 +186,14 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
|||||||
let argument = argument.get().borrow();
|
let argument = argument.get().borrow();
|
||||||
let converted = <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()))?;
|
let converted = <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()))?;
|
||||||
if argument.const_ && !converted.is_consty() {
|
if argument.const_ && !converted.is_consty() {
|
||||||
return Err(AsgConvertError::unexpected_nonconst(expr.span()));
|
return Err(AsgError::unexpected_nonconst(expr.span()).into());
|
||||||
}
|
}
|
||||||
Ok(Cell::new(converted))
|
Ok(Cell::new(converted))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
if function.is_test() {
|
if function.is_test() {
|
||||||
return Err(AsgConvertError::call_test_function(&value.span));
|
return Err(AsgError::call_test_function(&value.span).into());
|
||||||
}
|
}
|
||||||
Ok(CallExpression {
|
Ok(CallExpression {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
pub use leo_ast::UnaryOperation;
|
pub use leo_ast::UnaryOperation;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -75,15 +76,11 @@ impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::CastExpression,
|
value: &leo_ast::CastExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<CastExpression<'a>, AsgConvertError> {
|
) -> Result<CastExpression<'a>> {
|
||||||
let target_type = scope.resolve_ast_type(&value.target_type)?;
|
let target_type = scope.resolve_ast_type(&value.target_type, &value.span)?;
|
||||||
if let Some(expected_type) = &expected_type {
|
if let Some(expected_type) = &expected_type {
|
||||||
if !expected_type.matches(&target_type) {
|
if !expected_type.matches(&target_type) {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(expected_type, target_type, &value.span).into());
|
||||||
&expected_type.to_string(),
|
|
||||||
Some(&target_type.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, Circuit, CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Identifier, Node,
|
Circuit, CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Identifier, Node, PartialType, Scope, Type,
|
||||||
PartialType, Scope, Span, Type,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -92,16 +92,17 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::CircuitMemberAccessExpression,
|
value: &leo_ast::CircuitMemberAccessExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<CircuitAccessExpression<'a>, AsgConvertError> {
|
) -> Result<CircuitAccessExpression<'a>> {
|
||||||
let target = <&'a Expression<'a>>::from_ast(scope, &*value.circuit, None)?;
|
let target = <&'a Expression<'a>>::from_ast(scope, &*value.circuit, None)?;
|
||||||
let circuit = match target.get_type() {
|
let circuit = match target.get_type() {
|
||||||
Some(Type::Circuit(circuit)) => circuit,
|
Some(Type::Circuit(circuit)) => circuit,
|
||||||
x => {
|
x => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"circuit",
|
"circuit",
|
||||||
x.map(|x| x.to_string()).as_deref(),
|
x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,11 +113,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
|
|||||||
if let CircuitMember::Variable(type_) = &member {
|
if let CircuitMember::Variable(type_) = &member {
|
||||||
let type_: Type = type_.clone();
|
let type_: Type = type_.clone();
|
||||||
if !expected_type.matches(&type_) {
|
if !expected_type.matches(&type_) {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into());
|
||||||
&expected_type.to_string(),
|
|
||||||
Some(&type_.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} // used by call expression
|
} // used by call expression
|
||||||
}
|
}
|
||||||
@ -136,18 +133,17 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
|
|||||||
CircuitMember::Variable(expected_type.clone()),
|
CircuitMember::Variable(expected_type.clone()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::input_ref_needs_type(
|
return Err(
|
||||||
&circuit.name.borrow().name,
|
AsgError::input_ref_needs_type(&circuit.name.borrow().name, &value.name.name, &value.span).into(),
|
||||||
&value.name.name,
|
);
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unresolved_circuit_member(
|
return Err(AsgError::unresolved_circuit_member(
|
||||||
&circuit.name.borrow().name,
|
&circuit.name.borrow().name,
|
||||||
&value.name.name,
|
&value.name.name,
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CircuitAccessExpression {
|
Ok(CircuitAccessExpression {
|
||||||
@ -165,36 +161,29 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit
|
|||||||
scope: &Scope<'a>,
|
scope: &Scope<'a>,
|
||||||
value: &leo_ast::CircuitStaticFunctionAccessExpression,
|
value: &leo_ast::CircuitStaticFunctionAccessExpression,
|
||||||
expected_type: Option<PartialType>,
|
expected_type: Option<PartialType>,
|
||||||
) -> Result<CircuitAccessExpression<'a>, AsgConvertError> {
|
) -> Result<CircuitAccessExpression<'a>> {
|
||||||
let circuit = match &*value.circuit {
|
let circuit = match &*value.circuit {
|
||||||
leo_ast::Expression::Identifier(name) => scope
|
leo_ast::Expression::Identifier(name) => scope
|
||||||
.resolve_circuit(&name.name)
|
.resolve_circuit(&name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type("circuit", "unknown", &value.span).into());
|
||||||
"circuit",
|
|
||||||
Some("unknown"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(expected_type) = expected_type {
|
if let Some(expected_type) = expected_type {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(expected_type, "none", &value.span).into());
|
||||||
&expected_type.to_string(),
|
|
||||||
Some("none"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) {
|
if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) {
|
||||||
// okay
|
// okay
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unresolved_circuit_member(
|
return Err(AsgError::unresolved_circuit_member(
|
||||||
&circuit.name.borrow().name,
|
&circuit.name.borrow().name,
|
||||||
&value.name.name,
|
&value.name.name,
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CircuitAccessExpression {
|
Ok(CircuitAccessExpression {
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, Circuit, CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Identifier, Node,
|
Circuit, CircuitMember, ConstValue, Expression, ExpressionNode, FromAst, Identifier, Node, PartialType, Scope, Type,
|
||||||
PartialType, Scope, Span, Type,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use indexmap::{IndexMap, IndexSet};
|
use indexmap::{IndexMap, IndexSet};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -82,19 +83,15 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::CircuitInitExpression,
|
value: &leo_ast::CircuitInitExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<CircuitInitExpression<'a>, AsgConvertError> {
|
) -> Result<CircuitInitExpression<'a>> {
|
||||||
let circuit = scope
|
let circuit = scope
|
||||||
.resolve_circuit(&value.name.name)
|
.resolve_circuit(&value.name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&value.name.name, &value.name.span))?;
|
.ok_or_else(|| AsgError::unresolved_circuit(&value.name.name, &value.name.span))?;
|
||||||
match expected_type {
|
match expected_type {
|
||||||
Some(PartialType::Type(Type::Circuit(expected_circuit))) if expected_circuit == circuit => (),
|
Some(PartialType::Type(Type::Circuit(expected_circuit))) if expected_circuit == circuit => (),
|
||||||
None => (),
|
None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, circuit.name.borrow().name.to_string(), &value.span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&circuit.name.borrow().name),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let members: IndexMap<&str, (&Identifier, Option<&leo_ast::Expression>)> = value
|
let members: IndexMap<&str, (&Identifier, Option<&leo_ast::Expression>)> = value
|
||||||
@ -110,11 +107,9 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
|
|||||||
let circuit_members = circuit.members.borrow();
|
let circuit_members = circuit.members.borrow();
|
||||||
for (name, member) in circuit_members.iter() {
|
for (name, member) in circuit_members.iter() {
|
||||||
if defined_variables.contains(name) {
|
if defined_variables.contains(name) {
|
||||||
return Err(AsgConvertError::overridden_circuit_member(
|
return Err(
|
||||||
&circuit.name.borrow().name,
|
AsgError::overridden_circuit_member(&circuit.name.borrow().name, name, &value.span).into(),
|
||||||
name,
|
);
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
defined_variables.insert(name.clone());
|
defined_variables.insert(name.clone());
|
||||||
let type_: Type = if let CircuitMember::Variable(type_) = &member {
|
let type_: Type = if let CircuitMember::Variable(type_) = &member {
|
||||||
@ -134,21 +129,17 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
|
|||||||
};
|
};
|
||||||
values.push(((*identifier).clone(), Cell::new(received)));
|
values.push(((*identifier).clone(), Cell::new(received)));
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::missing_circuit_member(
|
return Err(
|
||||||
&circuit.name.borrow().name,
|
AsgError::missing_circuit_member(&circuit.name.borrow().name, name, &value.span).into(),
|
||||||
name,
|
);
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, (identifier, _expression)) in members.iter() {
|
for (name, (identifier, _expression)) in members.iter() {
|
||||||
if circuit_members.get(*name).is_none() {
|
if circuit_members.get(*name).is_none() {
|
||||||
return Err(AsgConvertError::extra_circuit_member(
|
return Err(
|
||||||
&circuit.name.borrow().name,
|
AsgError::extra_circuit_member(&circuit.name.borrow().name, name, &identifier.span).into(),
|
||||||
*name,
|
);
|
||||||
&identifier.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, CharValue, ConstInt, ConstValue, Expression, ExpressionNode, FromAst, GroupValue, Node,
|
CharValue, ConstInt, ConstValue, Expression, ExpressionNode, FromAst, GroupValue, Node, PartialType, Scope, Type,
|
||||||
PartialType, Scope, Span, Type,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -67,18 +68,14 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
_scope: &'a Scope<'a>,
|
_scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ValueExpression,
|
value: &leo_ast::ValueExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Constant<'a>, AsgConvertError> {
|
) -> Result<Constant<'a>> {
|
||||||
use leo_ast::ValueExpression::*;
|
use leo_ast::ValueExpression::*;
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
Address(value, span) => {
|
Address(value, span) => {
|
||||||
match expected_type.map(PartialType::full).flatten() {
|
match expected_type.map(PartialType::full).flatten() {
|
||||||
Some(Type::Address) | None => (),
|
Some(Type::Address) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Address, span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Address.to_string()),
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
@ -91,11 +88,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
match expected_type.map(PartialType::full).flatten() {
|
match expected_type.map(PartialType::full).flatten() {
|
||||||
Some(Type::Boolean) | None => (),
|
Some(Type::Boolean) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Boolean, span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Boolean.to_string()),
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
@ -104,7 +97,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
value: ConstValue::Boolean(
|
value: ConstValue::Boolean(
|
||||||
value
|
value
|
||||||
.parse::<bool>()
|
.parse::<bool>()
|
||||||
.map_err(|_| AsgConvertError::invalid_boolean(value, span))?,
|
.map_err(|_| AsgError::invalid_boolean(value, span))?,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,11 +105,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
match expected_type.map(PartialType::full).flatten() {
|
match expected_type.map(PartialType::full).flatten() {
|
||||||
Some(Type::Char) | None => (),
|
Some(Type::Char) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Char, value.span()).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Char.to_string()),
|
|
||||||
value.span(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,28 +119,20 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
match expected_type.map(PartialType::full).flatten() {
|
match expected_type.map(PartialType::full).flatten() {
|
||||||
Some(Type::Field) | None => (),
|
Some(Type::Field) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Field, span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Field.to_string()),
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
span: Some(span.clone()),
|
span: Some(span.clone()),
|
||||||
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Group(value) => {
|
Group(value) => {
|
||||||
match expected_type.map(PartialType::full).flatten() {
|
match expected_type.map(PartialType::full).flatten() {
|
||||||
Some(Type::Group) | None => (),
|
Some(Type::Group) | None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, Type::Group, value.span()).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*Type::Group.to_string()),
|
|
||||||
value.span(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
@ -166,7 +147,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Implicit(value, span) => match expected_type {
|
Implicit(value, span) => match expected_type {
|
||||||
None => return Err(AsgConvertError::unresolved_type("unknown", span)),
|
None => return Err(AsgError::unresolved_type("unknown", span).into()),
|
||||||
Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => {
|
Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => {
|
||||||
Constant {
|
Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
@ -177,7 +158,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
Some(PartialType::Type(Type::Field)) => Constant {
|
Some(PartialType::Type(Type::Field)) => Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
span: Some(span.clone()),
|
span: Some(span.clone()),
|
||||||
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
|
||||||
},
|
},
|
||||||
Some(PartialType::Type(Type::Group)) => Constant {
|
Some(PartialType::Type(Type::Group)) => Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
@ -189,7 +170,9 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
span: Some(span.clone()),
|
span: Some(span.clone()),
|
||||||
value: ConstValue::Address(value.clone()),
|
value: ConstValue::Address(value.clone()),
|
||||||
},
|
},
|
||||||
Some(x) => return Err(AsgConvertError::unexpected_type(&x.to_string(), Some("unknown"), span)),
|
Some(x) => {
|
||||||
|
return Err(AsgError::unexpected_type(x, "unknown", span).into());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Integer(int_type, value, span) => {
|
Integer(int_type, value, span) => {
|
||||||
match expected_type {
|
match expected_type {
|
||||||
@ -197,11 +180,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
Some(PartialType::Integer(None, Some(_))) => (),
|
Some(PartialType::Integer(None, Some(_))) => (),
|
||||||
None => (),
|
None => (),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(x, int_type, span).into());
|
||||||
&x.to_string(),
|
|
||||||
Some(&*int_type.to_string()),
|
|
||||||
span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
|
@ -65,7 +65,8 @@ pub use variable_ref::*;
|
|||||||
mod cast;
|
mod cast;
|
||||||
pub use cast::*;
|
pub use cast::*;
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, FromAst, Node, PartialType, Scope, Type};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Expression<'a> {
|
pub enum Expression<'a> {
|
||||||
@ -284,7 +285,7 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::Expression,
|
value: &leo_ast::Expression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
use leo_ast::Expression::*;
|
use leo_ast::Expression::*;
|
||||||
let expression = match value {
|
let expression = match value {
|
||||||
Identifier(identifier) => Self::from_ast(scope, identifier, expected_type)?,
|
Identifier(identifier) => Self::from_ast(scope, identifier, expected_type)?,
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::TernaryExpression,
|
value: &leo_ast::TernaryExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<TernaryExpression<'a>, AsgConvertError> {
|
) -> Result<TernaryExpression<'a>> {
|
||||||
let if_true = Cell::new(<&Expression<'a>>::from_ast(
|
let if_true = Cell::new(<&Expression<'a>>::from_ast(
|
||||||
scope,
|
scope,
|
||||||
&*value.if_true,
|
&*value.if_true,
|
||||||
@ -90,11 +91,7 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> {
|
|||||||
let right = if_false.get().get_type().unwrap().into();
|
let right = if_false.get().get_type().unwrap().into();
|
||||||
|
|
||||||
if left != right {
|
if left != right {
|
||||||
return Err(AsgConvertError::ternary_different_types(
|
return Err(AsgError::ternary_different_types(left, right, &value.span).into());
|
||||||
&left.to_string(),
|
|
||||||
&right.to_string(),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(TernaryExpression {
|
Ok(TernaryExpression {
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -74,12 +75,12 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<'
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::TupleAccessExpression,
|
value: &leo_ast::TupleAccessExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<TupleAccessExpression<'a>, AsgConvertError> {
|
) -> Result<TupleAccessExpression<'a>> {
|
||||||
let index = value
|
let index = value
|
||||||
.index
|
.index
|
||||||
.value
|
.value
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.map_err(|_| AsgConvertError::parse_index_error())?;
|
.map_err(|_| AsgError::parse_index_error(&value.span))?;
|
||||||
|
|
||||||
let mut expected_tuple = vec![None; index + 1];
|
let mut expected_tuple = vec![None; index + 1];
|
||||||
expected_tuple[index] = expected_type;
|
expected_tuple[index] = expected_type;
|
||||||
@ -88,11 +89,14 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<'
|
|||||||
let tuple_type = tuple.get_type();
|
let tuple_type = tuple.get_type();
|
||||||
if let Some(Type::Tuple(_items)) = tuple_type {
|
if let Some(Type::Tuple(_items)) = tuple_type {
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"a tuple",
|
"a tuple",
|
||||||
tuple_type.map(|x| x.to_string()).as_deref(),
|
tuple_type
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(TupleAccessExpression {
|
Ok(TupleAccessExpression {
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -80,16 +81,17 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::TupleInitExpression,
|
value: &leo_ast::TupleInitExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<TupleInitExpression<'a>, AsgConvertError> {
|
) -> Result<TupleInitExpression<'a>> {
|
||||||
let tuple_types = match expected_type {
|
let tuple_types = match expected_type {
|
||||||
Some(PartialType::Tuple(sub_types)) => Some(sub_types),
|
Some(PartialType::Tuple(sub_types)) => Some(sub_types),
|
||||||
None => None,
|
None => None,
|
||||||
x => {
|
x => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
"tuple",
|
"tuple",
|
||||||
x.map(|x| x.to_string()).as_deref(),
|
x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,11 +99,12 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> {
|
|||||||
// Expected type can be equal or less than actual size of a tuple.
|
// Expected type can be equal or less than actual size of a tuple.
|
||||||
// Size of expected tuple can be based on accessed index.
|
// Size of expected tuple can be based on accessed index.
|
||||||
if tuple_types.len() > value.elements.len() {
|
if tuple_types.len() > value.elements.len() {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
&*format!("tuple of length {}", tuple_types.len()),
|
format!("tuple of length {}", tuple_types.len()),
|
||||||
Some(&*format!("tuple of length {}", value.elements.len())),
|
format!("tuple of length {}", value.elements.len()),
|
||||||
&value.span,
|
&value.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +120,7 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> {
|
|||||||
)
|
)
|
||||||
.map(Cell::new)
|
.map(Cell::new)
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
Ok(TupleInitExpression {
|
Ok(TupleInitExpression {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type};
|
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
|
||||||
pub use leo_ast::UnaryOperation;
|
pub use leo_ast::UnaryOperation;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -89,16 +90,12 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::UnaryExpression,
|
value: &leo_ast::UnaryExpression,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<UnaryExpression<'a>, AsgConvertError> {
|
) -> Result<UnaryExpression<'a>> {
|
||||||
let expected_type = match value.op {
|
let expected_type = match value.op {
|
||||||
UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() {
|
UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() {
|
||||||
Some(Type::Boolean) | None => Some(Type::Boolean),
|
Some(Type::Boolean) | None => Some(Type::Boolean),
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span).into());
|
||||||
&type_.to_string(),
|
|
||||||
Some(&*Type::Boolean.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UnaryOperation::Negate => match expected_type.map(|x| x.full()).flatten() {
|
UnaryOperation::Negate => match expected_type.map(|x| x.full()).flatten() {
|
||||||
@ -107,22 +104,14 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
|
|||||||
Some(Type::Field) => Some(Type::Field),
|
Some(Type::Field) => Some(Type::Field),
|
||||||
None => None,
|
None => None,
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(type_, "integer, group, field", &value.span).into());
|
||||||
&type_.to_string(),
|
|
||||||
Some("integer, group, field"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() {
|
UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() {
|
||||||
Some(type_ @ Type::Integer(_)) => Some(type_),
|
Some(type_ @ Type::Integer(_)) => Some(type_),
|
||||||
None => None,
|
None => None,
|
||||||
Some(type_) => {
|
Some(type_) => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(type_, "integer", &value.span).into());
|
||||||
&type_.to_string(),
|
|
||||||
Some("integer"),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -137,7 +126,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
|
|||||||
})
|
})
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if is_expr_unsigned {
|
if is_expr_unsigned {
|
||||||
return Err(AsgConvertError::unsigned_negation(&value.span));
|
return Err(AsgError::unsigned_negation(&value.span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(UnaryExpression {
|
Ok(UnaryExpression {
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, ConstValue, Constant, DefinitionStatement, Expression, ExpressionNode, FromAst, Node, PartialType,
|
ConstValue, Constant, DefinitionStatement, Expression, ExpressionNode, FromAst, Node, PartialType, Scope,
|
||||||
Scope, Span, Statement, Type, Variable,
|
Statement, Type, Variable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -123,14 +125,12 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::Identifier,
|
value: &leo_ast::Identifier,
|
||||||
expected_type: Option<PartialType<'a>>,
|
expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<&'a Expression<'a>, AsgConvertError> {
|
) -> Result<&'a Expression<'a>> {
|
||||||
let variable = if value.name.as_ref() == "input" {
|
let variable = if value.name.as_ref() == "input" {
|
||||||
if let Some(input) = scope.resolve_input() {
|
if let Some(input) = scope.resolve_input() {
|
||||||
input.container
|
input.container
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::InternalError(
|
return Err(AsgError::illegal_input_variable_reference(&value.span).into());
|
||||||
"attempted to reference input when none is in scope".to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match scope.resolve_variable(&value.name) {
|
match scope.resolve_variable(&value.name) {
|
||||||
@ -143,7 +143,7 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
|
|||||||
value: ConstValue::Address(value.name.clone()),
|
value: ConstValue::Address(value.name.clone()),
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
return Err(AsgConvertError::unresolved_reference(&value.name, &value.span));
|
return Err(AsgError::unresolved_reference(&value.name, &value.span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -158,13 +158,9 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
|
|||||||
if let Some(expected_type) = expected_type {
|
if let Some(expected_type) = expected_type {
|
||||||
let type_ = expression
|
let type_ = expression
|
||||||
.get_type()
|
.get_type()
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_reference(&value.name, &value.span))?;
|
.ok_or_else(|| AsgError::unresolved_reference(&value.name, &value.span))?;
|
||||||
if !expected_type.matches(&type_) {
|
if !expected_type.matches(&type_) {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into());
|
||||||
&expected_type.to_string(),
|
|
||||||
Some(&*type_.to_string()),
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::{AsgContext, AsgConvertError, Program, Span};
|
use crate::{AsgContext, Program};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ pub trait ImportResolver<'a> {
|
|||||||
context: AsgContext<'a>,
|
context: AsgContext<'a>,
|
||||||
package_segments: &[&str],
|
package_segments: &[&str],
|
||||||
span: &Span,
|
span: &Span,
|
||||||
) -> Result<Option<Program<'a>>, AsgConvertError>;
|
) -> Result<Option<Program<'a>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NullImportResolver;
|
pub struct NullImportResolver;
|
||||||
@ -39,7 +40,7 @@ impl<'a> ImportResolver<'a> for NullImportResolver {
|
|||||||
_context: AsgContext<'a>,
|
_context: AsgContext<'a>,
|
||||||
_package_segments: &[&str],
|
_package_segments: &[&str],
|
||||||
_span: &Span,
|
_span: &Span,
|
||||||
) -> Result<Option<Program<'a>>, AsgConvertError> {
|
) -> Result<Option<Program<'a>>> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ impl<'a, 'b, T: ImportResolver<'b>> ImportResolver<'b> for CoreImportResolver<'a
|
|||||||
context: AsgContext<'b>,
|
context: AsgContext<'b>,
|
||||||
package_segments: &[&str],
|
package_segments: &[&str],
|
||||||
span: &Span,
|
span: &Span,
|
||||||
) -> Result<Option<Program<'b>>, AsgConvertError> {
|
) -> Result<Option<Program<'b>>> {
|
||||||
if !package_segments.is_empty() && package_segments.get(0).unwrap() == &"core" {
|
if !package_segments.is_empty() && package_segments.get(0).unwrap() == &"core" {
|
||||||
Ok(crate::resolve_core_module(context, &*package_segments[1..].join("."))?)
|
Ok(crate::resolve_core_module(context, &*package_segments[1..].join("."))?)
|
||||||
} else {
|
} else {
|
||||||
@ -83,7 +84,7 @@ impl<'a> ImportResolver<'a> for MockedImportResolver<'a> {
|
|||||||
_context: AsgContext<'a>,
|
_context: AsgContext<'a>,
|
||||||
package_segments: &[&str],
|
package_segments: &[&str],
|
||||||
_span: &Span,
|
_span: &Span,
|
||||||
) -> Result<Option<Program<'a>>, AsgConvertError> {
|
) -> Result<Option<Program<'a>>> {
|
||||||
Ok(self.packages.get(&package_segments.join(".")).cloned())
|
Ok(self.packages.get(&package_segments.join(".")).cloned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Circuit, CircuitMember, Identifier, Scope, Type, Variable};
|
use crate::{Circuit, CircuitMember, Identifier, Scope, Type, Variable};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@ -44,7 +45,7 @@ impl<'a> Input<'a> {
|
|||||||
members: RefCell::new(IndexMap::new()),
|
members: RefCell::new(IndexMap::new()),
|
||||||
core_mapping: RefCell::new(None),
|
core_mapping: RefCell::new(None),
|
||||||
scope,
|
scope,
|
||||||
span: Default::default(),
|
span: Some(Span::default()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ impl<'a> Input<'a> {
|
|||||||
members: RefCell::new(container_members),
|
members: RefCell::new(container_members),
|
||||||
core_mapping: RefCell::new(None),
|
core_mapping: RefCell::new(None),
|
||||||
scope: input_scope,
|
scope: input_scope,
|
||||||
span: Default::default(),
|
span: Some(Span::default()),
|
||||||
});
|
});
|
||||||
|
|
||||||
Input {
|
Input {
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
|
|
||||||
#![allow(clippy::from_over_into)]
|
#![allow(clippy::from_over_into)]
|
||||||
#![allow(clippy::result_unit_err)]
|
#![allow(clippy::result_unit_err)]
|
||||||
|
#![doc = include_str!("../README.md")]
|
||||||
#[macro_use]
|
|
||||||
extern crate thiserror;
|
|
||||||
|
|
||||||
pub mod checks;
|
pub mod checks;
|
||||||
pub use checks::*;
|
pub use checks::*;
|
||||||
@ -34,9 +32,6 @@ pub use checks::*;
|
|||||||
pub mod const_value;
|
pub mod const_value;
|
||||||
pub use const_value::*;
|
pub use const_value::*;
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub use error::*;
|
|
||||||
|
|
||||||
pub mod expression;
|
pub mod expression;
|
||||||
pub use expression::*;
|
pub use expression::*;
|
||||||
|
|
||||||
@ -77,7 +72,8 @@ pub use pass::*;
|
|||||||
pub mod context;
|
pub mod context;
|
||||||
pub use context::*;
|
pub use context::*;
|
||||||
|
|
||||||
pub use leo_ast::{Ast, Identifier, Span};
|
pub use leo_ast::{Ast, Identifier};
|
||||||
|
use leo_errors::Result;
|
||||||
|
|
||||||
/// The abstract semantic graph (ASG) for a Leo program.
|
/// The abstract semantic graph (ASG) for a Leo program.
|
||||||
///
|
///
|
||||||
@ -97,7 +93,7 @@ impl<'a> Asg<'a> {
|
|||||||
context: AsgContext<'a>,
|
context: AsgContext<'a>,
|
||||||
ast: Y,
|
ast: Y,
|
||||||
resolver: &mut T,
|
resolver: &mut T,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
context,
|
context,
|
||||||
asg: Program::new(context, ast.as_ref(), resolver)?,
|
asg: Program::new(context, ast.as_ref(), resolver)?,
|
||||||
@ -130,7 +126,7 @@ pub fn load_asg<'a, T: ImportResolver<'a>>(
|
|||||||
context: AsgContext<'a>,
|
context: AsgContext<'a>,
|
||||||
content: &str,
|
content: &str,
|
||||||
resolver: &mut T,
|
resolver: &mut T,
|
||||||
) -> Result<Program<'a>, AsgConvertError> {
|
) -> Result<Program<'a>> {
|
||||||
// Parses the Leo file and constructs a grammar ast.
|
// Parses the Leo file and constructs a grammar ast.
|
||||||
let ast = leo_parser::parse_ast("input.leo", content)?;
|
let ast = leo_parser::parse_ast("input.leo", content)?;
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{AsgContextInner, Circuit, Expression, Function, PartialType, Scope, Statement, Variable};
|
||||||
AsgContextInner, AsgConvertError, Circuit, Expression, Function, PartialType, Scope, Span, Statement, Variable,
|
|
||||||
};
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
/// A node in the abstract semantic graph.
|
/// A node in the abstract semantic graph.
|
||||||
pub trait Node {
|
pub trait Node {
|
||||||
@ -26,11 +26,7 @@ pub trait Node {
|
|||||||
pub(super) trait FromAst<'a, T: leo_ast::Node + 'static>: Sized {
|
pub(super) trait FromAst<'a, T: leo_ast::Node + 'static>: Sized {
|
||||||
// expected_type contract: if present, output expression must be of type expected_type.
|
// expected_type contract: if present, output expression must be of type expected_type.
|
||||||
// type of an element may NEVER be None unless it is functionally a non-expression. (static call targets, function ref call targets are not expressions)
|
// type of an element may NEVER be None unless it is functionally a non-expression. (static call targets, function ref call targets are not expressions)
|
||||||
fn from_ast(
|
fn from_ast(scope: &'a Scope<'a>, value: &T, expected_type: Option<PartialType<'a>>) -> Result<Self>;
|
||||||
scope: &'a Scope<'a>,
|
|
||||||
value: &T,
|
|
||||||
expected_type: Option<PartialType<'a>>,
|
|
||||||
) -> Result<Self, AsgConvertError>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ArenaNode<'a> {
|
pub enum ArenaNode<'a> {
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::Program;
|
use crate::Program;
|
||||||
pub use leo_ast::FormattedError;
|
use leo_errors::Result;
|
||||||
|
|
||||||
pub trait AsgPass<'a> {
|
pub trait AsgPass<'a> {
|
||||||
fn do_pass(asg: Program<'a>) -> Result<Program<'a>, FormattedError>;
|
fn do_pass(asg: Program<'a>) -> Result<Program<'a>>;
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
// TODO (protryon): We should merge this with core
|
// TODO (protryon): We should merge this with core
|
||||||
|
|
||||||
use crate::{AsgContext, AsgConvertError, Program};
|
use crate::{AsgContext, Program};
|
||||||
|
use leo_errors::Result;
|
||||||
|
|
||||||
// TODO (protryon): Make asg deep copy so we can cache resolved core modules
|
// TODO (protryon): Make asg deep copy so we can cache resolved core modules
|
||||||
// TODO (protryon): Figure out how to do headers without bogus returns
|
// TODO (protryon): Figure out how to do headers without bogus returns
|
||||||
|
|
||||||
pub fn resolve_core_module<'a>(context: AsgContext<'a>, module: &str) -> Result<Option<Program<'a>>, AsgConvertError> {
|
pub fn resolve_core_module<'a>(context: AsgContext<'a>, module: &str) -> Result<Option<Program<'a>>> {
|
||||||
match module {
|
match module {
|
||||||
"unstable.blake2s" => {
|
"unstable.blake2s" => {
|
||||||
let asg = crate::load_asg(
|
let asg = crate::load_asg(
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, Function, Identifier, Node, Scope, Span, Type};
|
use crate::{Function, Identifier, Node, Scope, Type};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@ -53,7 +54,7 @@ impl<'a> Node for Circuit<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Circuit<'a> {
|
impl<'a> Circuit<'a> {
|
||||||
pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>, AsgConvertError> {
|
pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>> {
|
||||||
let new_scope = scope.make_subscope();
|
let new_scope = scope.make_subscope();
|
||||||
|
|
||||||
let circuit = scope.context.alloc_circuit(Circuit {
|
let circuit = scope.context.alloc_circuit(Circuit {
|
||||||
@ -64,21 +65,18 @@ impl<'a> Circuit<'a> {
|
|||||||
span: Some(value.circuit_name.span.clone()),
|
span: Some(value.circuit_name.span.clone()),
|
||||||
scope: new_scope,
|
scope: new_scope,
|
||||||
});
|
});
|
||||||
new_scope.circuit_self.replace(Some(circuit));
|
|
||||||
|
|
||||||
let mut members = circuit.members.borrow_mut();
|
let mut members = circuit.members.borrow_mut();
|
||||||
for member in value.members.iter() {
|
for member in value.members.iter() {
|
||||||
if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member {
|
if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member {
|
||||||
if members.contains_key(name.name.as_ref()) {
|
if members.contains_key(name.name.as_ref()) {
|
||||||
return Err(AsgConvertError::redefined_circuit_member(
|
return Err(
|
||||||
&value.circuit_name.name,
|
AsgError::redefined_circuit_member(&value.circuit_name.name, &name.name, &name.span).into(),
|
||||||
&name.name,
|
);
|
||||||
&name.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
members.insert(
|
members.insert(
|
||||||
name.name.to_string(),
|
name.name.to_string(),
|
||||||
CircuitMember::Variable(new_scope.resolve_ast_type(type_)?),
|
CircuitMember::Variable(new_scope.resolve_ast_type(type_, &name.span)?),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,30 +84,27 @@ impl<'a> Circuit<'a> {
|
|||||||
Ok(circuit)
|
Ok(circuit)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn init_member(
|
pub(super) fn init_member(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>> {
|
||||||
scope: &'a Scope<'a>,
|
|
||||||
value: &leo_ast::Circuit,
|
|
||||||
) -> Result<&'a Circuit<'a>, AsgConvertError> {
|
|
||||||
let new_scope = scope.make_subscope();
|
let new_scope = scope.make_subscope();
|
||||||
let circuits = scope.circuits.borrow();
|
let circuits = scope.circuits.borrow();
|
||||||
|
|
||||||
let circuit = circuits.get(value.circuit_name.name.as_ref()).unwrap();
|
let circuit = circuits.get(value.circuit_name.name.as_ref()).unwrap();
|
||||||
new_scope.circuit_self.replace(Some(circuit));
|
|
||||||
|
|
||||||
let mut members = circuit.members.borrow_mut();
|
let mut members = circuit.members.borrow_mut();
|
||||||
for member in value.members.iter() {
|
for member in value.members.iter() {
|
||||||
if let leo_ast::CircuitMember::CircuitFunction(function) = member {
|
if let leo_ast::CircuitMember::CircuitFunction(function) = member {
|
||||||
if members.contains_key(function.identifier.name.as_ref()) {
|
if members.contains_key(function.identifier.name.as_ref()) {
|
||||||
return Err(AsgConvertError::redefined_circuit_member(
|
return Err(AsgError::redefined_circuit_member(
|
||||||
&value.circuit_name.name,
|
&value.circuit_name.name,
|
||||||
&function.identifier.name,
|
&function.identifier.name,
|
||||||
&function.identifier.span,
|
&function.identifier.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
let asg_function = Function::init(new_scope, function)?;
|
let asg_function = Function::init(new_scope, function)?;
|
||||||
asg_function.circuit.replace(Some(circuit));
|
asg_function.circuit.replace(Some(circuit));
|
||||||
if asg_function.is_test() {
|
if asg_function.is_test() {
|
||||||
return Err(AsgConvertError::circuit_test_function(&function.identifier.span));
|
return Err(AsgError::circuit_test_function(&function.identifier.span).into());
|
||||||
}
|
}
|
||||||
members.insert(
|
members.insert(
|
||||||
function.identifier.name.to_string(),
|
function.identifier.name.to_string(),
|
||||||
@ -121,7 +116,7 @@ impl<'a> Circuit<'a> {
|
|||||||
Ok(circuit)
|
Ok(circuit)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn fill_from_ast(self: &'a Circuit<'a>, value: &leo_ast::Circuit) -> Result<(), AsgConvertError> {
|
pub(super) fn fill_from_ast(self: &'a Circuit<'a>, value: &leo_ast::Circuit) -> Result<()> {
|
||||||
for member in value.members.iter() {
|
for member in value.members.iter() {
|
||||||
match member {
|
match member {
|
||||||
leo_ast::CircuitMember::CircuitVariable(..) => {}
|
leo_ast::CircuitMember::CircuitVariable(..) => {}
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, BlockStatement, Circuit, FromAst, Identifier, MonoidalDirector, ReturnPathReducer, Scope, Span,
|
BlockStatement, Circuit, FromAst, Identifier, MonoidalDirector, ReturnPathReducer, Scope, Statement, Type, Variable,
|
||||||
Statement, Type, Variable,
|
|
||||||
};
|
};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
pub use leo_ast::Annotation;
|
pub use leo_ast::Annotation;
|
||||||
use leo_ast::FunctionInput;
|
use leo_ast::FunctionInput;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
||||||
@ -58,11 +58,11 @@ impl<'a> PartialEq for Function<'a> {
|
|||||||
impl<'a> Eq for Function<'a> {}
|
impl<'a> Eq for Function<'a> {}
|
||||||
|
|
||||||
impl<'a> Function<'a> {
|
impl<'a> Function<'a> {
|
||||||
pub(crate) fn init(scope: &'a Scope<'a>, value: &leo_ast::Function) -> Result<&'a Function<'a>, AsgConvertError> {
|
pub(crate) fn init(scope: &'a Scope<'a>, value: &leo_ast::Function) -> Result<&'a Function<'a>> {
|
||||||
let output: Type<'a> = value
|
let output: Type<'a> = value
|
||||||
.output
|
.output
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|t| scope.resolve_ast_type(t))
|
.map(|t| scope.resolve_ast_type(t, &value.span))
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or_else(|| Type::Tuple(vec![]));
|
.unwrap_or_else(|| Type::Tuple(vec![]));
|
||||||
let mut qualifier = FunctionQualifier::Static;
|
let mut qualifier = FunctionQualifier::Static;
|
||||||
@ -81,31 +81,22 @@ impl<'a> Function<'a> {
|
|||||||
FunctionInput::MutSelfKeyword(_) => {
|
FunctionInput::MutSelfKeyword(_) => {
|
||||||
qualifier = FunctionQualifier::MutSelfRef;
|
qualifier = FunctionQualifier::MutSelfRef;
|
||||||
}
|
}
|
||||||
FunctionInput::Variable(leo_ast::FunctionInputVariable {
|
FunctionInput::Variable(input_variable) => {
|
||||||
type_,
|
|
||||||
identifier,
|
|
||||||
const_,
|
|
||||||
mutable,
|
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||||
id: scope.context.get_id(),
|
id: scope.context.get_id(),
|
||||||
name: identifier.clone(),
|
name: input_variable.identifier.clone(),
|
||||||
type_: scope.resolve_ast_type(type_)?,
|
type_: scope.resolve_ast_type(&input_variable.type_, &value.span)?,
|
||||||
mutable: *mutable,
|
mutable: input_variable.mutable,
|
||||||
const_: *const_,
|
const_: input_variable.const_,
|
||||||
declaration: crate::VariableDeclaration::Parameter,
|
declaration: crate::VariableDeclaration::Parameter,
|
||||||
references: vec![],
|
references: vec![],
|
||||||
assignments: vec![],
|
assignments: vec![],
|
||||||
}));
|
}));
|
||||||
arguments.insert(identifier.name.to_string(), Cell::new(&*variable));
|
arguments.insert(input_variable.identifier.name.to_string(), Cell::new(&*variable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if qualifier != FunctionQualifier::Static && scope.circuit_self.get().is_none() {
|
|
||||||
return Err(AsgConvertError::invalid_self_in_global(&value.span));
|
|
||||||
}
|
|
||||||
let function = scope.context.alloc_function(Function {
|
let function = scope.context.alloc_function(Function {
|
||||||
id: scope.context.get_id(),
|
id: scope.context.get_id(),
|
||||||
name: RefCell::new(value.identifier.clone()),
|
name: RefCell::new(value.identifier.clone()),
|
||||||
@ -123,7 +114,7 @@ impl<'a> Function<'a> {
|
|||||||
Ok(function)
|
Ok(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn fill_from_ast(self: &'a Function<'a>, value: &leo_ast::Function) -> Result<(), AsgConvertError> {
|
pub(super) fn fill_from_ast(self: &'a Function<'a>, value: &leo_ast::Function) -> Result<()> {
|
||||||
if self.qualifier != FunctionQualifier::Static {
|
if self.qualifier != FunctionQualifier::Static {
|
||||||
let circuit = self.circuit.get();
|
let circuit = self.circuit.get();
|
||||||
let self_variable = self.scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
let self_variable = self.scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||||
@ -148,19 +139,12 @@ impl<'a> Function<'a> {
|
|||||||
let main_block = BlockStatement::from_ast(self.scope, &value.block, None)?;
|
let main_block = BlockStatement::from_ast(self.scope, &value.block, None)?;
|
||||||
let mut director = MonoidalDirector::new(ReturnPathReducer::new());
|
let mut director = MonoidalDirector::new(ReturnPathReducer::new());
|
||||||
if !director.reduce_block(&main_block).0 && !self.output.is_unit() {
|
if !director.reduce_block(&main_block).0 && !self.output.is_unit() {
|
||||||
return Err(AsgConvertError::function_missing_return(
|
return Err(AsgError::function_missing_return(&self.name.borrow().name, &value.span).into());
|
||||||
&self.name.borrow().name,
|
|
||||||
&value.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::never_loop)] // TODO @Protryon: How should we return multiple errors?
|
#[allow(clippy::never_loop)] // TODO @Protryon: How should we return multiple errors?
|
||||||
for (span, error) in director.reducer().errors {
|
for (span, error) in director.reducer().errors {
|
||||||
return Err(AsgConvertError::function_return_validation(
|
return Err(AsgError::function_return_validation(&self.name.borrow().name, error, &span).into());
|
||||||
&self.name.borrow().name,
|
|
||||||
&error,
|
|
||||||
&span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.body
|
self.body
|
||||||
|
@ -24,10 +24,9 @@ pub use circuit::*;
|
|||||||
mod function;
|
mod function;
|
||||||
pub use function::*;
|
pub use function::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{node::FromAst, ArenaNode, AsgContext, DefinitionStatement, ImportResolver, Input, Scope, Statement};
|
||||||
node::FromAst, ArenaNode, AsgContext, AsgConvertError, DefinitionStatement, ImportResolver, Input, Scope, Statement,
|
use leo_ast::{Identifier, PackageAccess, PackageOrPackages};
|
||||||
};
|
use leo_errors::{AsgError, Result, Span};
|
||||||
use leo_ast::{Identifier, PackageAccess, PackageOrPackages, Span};
|
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
@ -138,7 +137,7 @@ impl<'a> Program<'a> {
|
|||||||
context: AsgContext<'a>,
|
context: AsgContext<'a>,
|
||||||
program: &leo_ast::Program,
|
program: &leo_ast::Program,
|
||||||
import_resolver: &mut T,
|
import_resolver: &mut T,
|
||||||
) -> Result<Program<'a>, AsgConvertError> {
|
) -> Result<Program<'a>> {
|
||||||
// Recursively extract imported symbols.
|
// Recursively extract imported symbols.
|
||||||
let mut imported_symbols: Vec<(Vec<String>, ImportSymbol, Span)> = vec![];
|
let mut imported_symbols: Vec<(Vec<String>, ImportSymbol, Span)> = vec![];
|
||||||
for import in program.imports.iter() {
|
for import in program.imports.iter() {
|
||||||
@ -164,7 +163,9 @@ impl<'a> Program<'a> {
|
|||||||
span,
|
span,
|
||||||
)? {
|
)? {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return Err(AsgConvertError::unresolved_import(&*pretty_package, &Span::default())),
|
None => {
|
||||||
|
return Err(AsgError::unresolved_import(pretty_package, &Span::default()).into());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
resolved_packages.insert(package.clone(), resolved_package);
|
resolved_packages.insert(package.clone(), resolved_package);
|
||||||
@ -195,10 +196,7 @@ impl<'a> Program<'a> {
|
|||||||
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
|
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
|
||||||
imported_global_consts.insert(name.clone(), *global_const);
|
imported_global_consts.insert(name.clone(), *global_const);
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unresolved_import(
|
return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into());
|
||||||
&*format!("{}.{}", pretty_package, name),
|
|
||||||
&span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImportSymbol::Alias(name, alias) => {
|
ImportSymbol::Alias(name, alias) => {
|
||||||
@ -209,10 +207,7 @@ impl<'a> Program<'a> {
|
|||||||
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
|
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
|
||||||
imported_global_consts.insert(alias.clone(), *global_const);
|
imported_global_consts.insert(alias.clone(), *global_const);
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::unresolved_import(
|
return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into());
|
||||||
&*format!("{}.{}", pretty_package, name),
|
|
||||||
&span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +217,6 @@ impl<'a> Program<'a> {
|
|||||||
context,
|
context,
|
||||||
id: context.get_id(),
|
id: context.get_id(),
|
||||||
parent_scope: Cell::new(None),
|
parent_scope: Cell::new(None),
|
||||||
circuit_self: Cell::new(None),
|
|
||||||
variables: RefCell::new(IndexMap::new()),
|
variables: RefCell::new(IndexMap::new()),
|
||||||
functions: RefCell::new(imported_functions),
|
functions: RefCell::new(imported_functions),
|
||||||
global_consts: RefCell::new(imported_global_consts),
|
global_consts: RefCell::new(imported_global_consts),
|
||||||
@ -239,7 +233,6 @@ impl<'a> Program<'a> {
|
|||||||
input: Cell::new(Some(Input::new(import_scope))), // we use import_scope to avoid recursive scope ref here
|
input: Cell::new(Some(Input::new(import_scope))), // we use import_scope to avoid recursive scope ref here
|
||||||
id: context.get_id(),
|
id: context.get_id(),
|
||||||
parent_scope: Cell::new(Some(import_scope)),
|
parent_scope: Cell::new(Some(import_scope)),
|
||||||
circuit_self: Cell::new(None),
|
|
||||||
variables: RefCell::new(IndexMap::new()),
|
variables: RefCell::new(IndexMap::new()),
|
||||||
functions: RefCell::new(IndexMap::new()),
|
functions: RefCell::new(IndexMap::new()),
|
||||||
global_consts: RefCell::new(IndexMap::new()),
|
global_consts: RefCell::new(IndexMap::new()),
|
||||||
@ -303,7 +296,7 @@ impl<'a> Program<'a> {
|
|||||||
let name = name.name.to_string();
|
let name = name.name.to_string();
|
||||||
|
|
||||||
if functions.contains_key(&name) {
|
if functions.contains_key(&name) {
|
||||||
return Err(AsgConvertError::duplicate_function_definition(&name, &function.span));
|
return Err(AsgError::duplicate_function_definition(name, &function.span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
functions.insert(name, asg_function);
|
functions.insert(name, asg_function);
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgContext, AsgConvertError, Circuit, DefinitionStatement, Function, Input, Type, Variable};
|
use crate::{AsgContext, Circuit, DefinitionStatement, Function, Input, Type, Variable};
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
@ -33,9 +34,6 @@ pub struct Scope<'a> {
|
|||||||
/// The function definition that this scope occurs in.
|
/// The function definition that this scope occurs in.
|
||||||
pub function: Cell<Option<&'a Function<'a>>>,
|
pub function: Cell<Option<&'a Function<'a>>>,
|
||||||
|
|
||||||
/// The circuit definition that this scope occurs in.
|
|
||||||
pub circuit_self: Cell<Option<&'a Circuit<'a>>>,
|
|
||||||
|
|
||||||
/// Maps variable name => variable.
|
/// Maps variable name => variable.
|
||||||
pub variables: RefCell<IndexMap<String, &'a Variable<'a>>>,
|
pub variables: RefCell<IndexMap<String, &'a Variable<'a>>>,
|
||||||
|
|
||||||
@ -127,8 +125,6 @@ impl<'a> Scope<'a> {
|
|||||||
pub fn resolve_circuit(&self, name: &str) -> Option<&'a Circuit<'a>> {
|
pub fn resolve_circuit(&self, name: &str) -> Option<&'a Circuit<'a>> {
|
||||||
if let Some(resolved) = self.circuits.borrow().get(name) {
|
if let Some(resolved) = self.circuits.borrow().get(name) {
|
||||||
Some(*resolved)
|
Some(*resolved)
|
||||||
} else if name == "Self" && self.circuit_self.get().is_some() {
|
|
||||||
self.circuit_self.get()
|
|
||||||
} else if let Some(resolved) = self.parent_scope.get() {
|
} else if let Some(resolved) = self.parent_scope.get() {
|
||||||
resolved.resolve_circuit(name)
|
resolved.resolve_circuit(name)
|
||||||
} else {
|
} else {
|
||||||
@ -136,22 +132,6 @@ impl<'a> Scope<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Returns a reference to the current circuit.
|
|
||||||
///
|
|
||||||
/// If the current scope did not have a circuit self present, then the parent scope is checked.
|
|
||||||
/// If there is no parent scope, then `None` is returned.
|
|
||||||
///
|
|
||||||
pub fn resolve_circuit_self(&self) -> Option<&'a Circuit<'a>> {
|
|
||||||
if let Some(resolved) = self.circuit_self.get() {
|
|
||||||
Some(resolved)
|
|
||||||
} else if let Some(resolved) = self.parent_scope.get() {
|
|
||||||
resolved.resolve_circuit_self()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Returns a new scope given a parent scope.
|
/// Returns a new scope given a parent scope.
|
||||||
///
|
///
|
||||||
@ -160,7 +140,6 @@ impl<'a> Scope<'a> {
|
|||||||
context: self.context,
|
context: self.context,
|
||||||
id: self.context.get_id(),
|
id: self.context.get_id(),
|
||||||
parent_scope: Cell::new(Some(self)),
|
parent_scope: Cell::new(Some(self)),
|
||||||
circuit_self: Cell::new(None),
|
|
||||||
variables: RefCell::new(IndexMap::new()),
|
variables: RefCell::new(IndexMap::new()),
|
||||||
functions: RefCell::new(IndexMap::new()),
|
functions: RefCell::new(IndexMap::new()),
|
||||||
circuits: RefCell::new(IndexMap::new()),
|
circuits: RefCell::new(IndexMap::new()),
|
||||||
@ -173,7 +152,7 @@ impl<'a> Scope<'a> {
|
|||||||
///
|
///
|
||||||
/// Returns the type returned by the current scope.
|
/// Returns the type returned by the current scope.
|
||||||
///
|
///
|
||||||
pub fn resolve_ast_type(&self, type_: &leo_ast::Type) -> Result<Type<'a>, AsgConvertError> {
|
pub fn resolve_ast_type(&self, type_: &leo_ast::Type, span: &Span) -> Result<Type<'a>> {
|
||||||
use leo_ast::Type::*;
|
use leo_ast::Type::*;
|
||||||
Ok(match type_ {
|
Ok(match type_ {
|
||||||
Address => Type::Address,
|
Address => Type::Address,
|
||||||
@ -183,12 +162,12 @@ impl<'a> Scope<'a> {
|
|||||||
Group => Type::Group,
|
Group => Type::Group,
|
||||||
IntegerType(int_type) => Type::Integer(int_type.clone()),
|
IntegerType(int_type) => Type::Integer(int_type.clone()),
|
||||||
Array(sub_type, dimensions) => {
|
Array(sub_type, dimensions) => {
|
||||||
let mut item = Box::new(self.resolve_ast_type(&*sub_type)?);
|
let mut item = Box::new(self.resolve_ast_type(&*sub_type, span)?);
|
||||||
for dimension in dimensions.0.iter().rev() {
|
for dimension in dimensions.0.iter().rev() {
|
||||||
let dimension = dimension
|
let dimension = dimension
|
||||||
.value
|
.value
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.map_err(|_| AsgConvertError::parse_index_error())?;
|
.map_err(|_| AsgError::parse_index_error(span))?;
|
||||||
item = Box::new(Type::Array(item, dimension));
|
item = Box::new(Type::Array(item, dimension));
|
||||||
}
|
}
|
||||||
*item
|
*item
|
||||||
@ -196,20 +175,13 @@ impl<'a> Scope<'a> {
|
|||||||
Tuple(sub_types) => Type::Tuple(
|
Tuple(sub_types) => Type::Tuple(
|
||||||
sub_types
|
sub_types
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| self.resolve_ast_type(x))
|
.map(|x| self.resolve_ast_type(x, span))
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?,
|
.collect::<Result<Vec<_>>>()?,
|
||||||
),
|
|
||||||
Circuit(name) if name.name.as_ref() == "Self" => Type::Circuit(
|
|
||||||
self.resolve_circuit_self()
|
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
|
||||||
),
|
|
||||||
SelfType => Type::Circuit(
|
|
||||||
self.resolve_circuit_self()
|
|
||||||
.ok_or_else(AsgConvertError::reference_self_outside_circuit)?,
|
|
||||||
),
|
),
|
||||||
|
SelfType => return Err(AsgError::unexpected_big_self(span).into()),
|
||||||
Circuit(name) => Type::Circuit(
|
Circuit(name) => Type::Circuit(
|
||||||
self.resolve_circuit(&name.name)
|
self.resolve_circuit(&name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?,
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,12 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AsgConvertError, CircuitMember, ConstInt, ConstValue, Expression, ExpressionNode, FromAst, Identifier, IntegerType,
|
CircuitMember, ConstInt, ConstValue, Expression, ExpressionNode, FromAst, Identifier, IntegerType, Node,
|
||||||
Node, PartialType, Scope, Span, Statement, Type, Variable,
|
PartialType, Scope, Statement, Type, Variable,
|
||||||
};
|
};
|
||||||
pub use leo_ast::AssignOperation;
|
pub use leo_ast::AssignOperation;
|
||||||
use leo_ast::AssigneeAccess as AstAssigneeAccess;
|
use leo_ast::AssigneeAccess as AstAssigneeAccess;
|
||||||
|
use leo_errors::{AsgError, Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -52,25 +53,26 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::AssignStatement,
|
statement: &leo_ast::AssignStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let (name, span) = (&statement.assignee.identifier.name, &statement.assignee.identifier.span);
|
let (name, span) = (
|
||||||
|
&statement.assignee.identifier.name.clone(),
|
||||||
|
&statement.assignee.identifier.span,
|
||||||
|
);
|
||||||
|
|
||||||
let variable = if name.as_ref() == "input" {
|
let variable = if name.as_ref() == "input" {
|
||||||
if let Some(input) = scope.resolve_input() {
|
if let Some(input) = scope.resolve_input() {
|
||||||
input.container
|
input.container
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::InternalError(
|
return Err(AsgError::illegal_input_variable_reference(&statement.span).into());
|
||||||
"attempted to reference input when none is in scope".to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scope
|
scope
|
||||||
.resolve_variable(name)
|
.resolve_variable(name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_reference(name, span))?
|
.ok_or_else(|| AsgError::unresolved_reference(name, span))?
|
||||||
};
|
};
|
||||||
|
|
||||||
if !variable.borrow().mutable {
|
if !variable.borrow().mutable {
|
||||||
return Err(AsgConvertError::immutable_assignment(name, &statement.span));
|
return Err(AsgError::immutable_assignment(name, &statement.span).into());
|
||||||
}
|
}
|
||||||
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
|
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
|
||||||
|
|
||||||
@ -81,19 +83,15 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
let index_type = Some(PartialType::Integer(None, Some(IntegerType::U32)));
|
let index_type = Some(PartialType::Integer(None, Some(IntegerType::U32)));
|
||||||
let left = left
|
let left = left
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(
|
.map(|left: &leo_ast::Expression| -> Result<&'a Expression<'a>> {
|
||||||
|left: &leo_ast::Expression| -> Result<&'a Expression<'a>, AsgConvertError> {
|
<&Expression<'a>>::from_ast(scope, left, index_type.clone())
|
||||||
<&Expression<'a>>::from_ast(scope, left, index_type.clone())
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
let right = right
|
let right = right
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(
|
.map(|right: &leo_ast::Expression| -> Result<&'a Expression<'a>> {
|
||||||
|right: &leo_ast::Expression| -> Result<&'a Expression<'a>, AsgConvertError> {
|
<&Expression<'a>>::from_ast(scope, right, index_type)
|
||||||
<&Expression<'a>>::from_ast(scope, right, index_type)
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
match &target_type {
|
match &target_type {
|
||||||
@ -109,29 +107,30 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
) {
|
) {
|
||||||
let left = match left {
|
let left = match left {
|
||||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||||
AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span)
|
AsgError::invalid_assign_index(name, x.to_string(), &statement.span)
|
||||||
})?,
|
})?,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
let right = match right {
|
let right = match right {
|
||||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||||
AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span)
|
AsgError::invalid_assign_index(name, x.to_string(), &statement.span)
|
||||||
})?,
|
})?,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
if right >= left {
|
if right >= left {
|
||||||
target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize)))
|
target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize)))
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::invalid_backwards_assignment(
|
return Err(AsgError::invalid_backwards_assignment(
|
||||||
name,
|
name,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
&statement.span,
|
&statement.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)),
|
_ => return Err(AsgError::index_into_non_array(name, &statement.span).into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
|
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
|
||||||
@ -139,7 +138,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
AstAssigneeAccess::ArrayIndex(index) => {
|
AstAssigneeAccess::ArrayIndex(index) => {
|
||||||
target_type = match target_type.clone() {
|
target_type = match target_type.clone() {
|
||||||
Some(PartialType::Array(item, _)) => item.map(|x| *x),
|
Some(PartialType::Array(item, _)) => item.map(|x| *x),
|
||||||
_ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)),
|
_ => return Err(AsgError::index_into_non_array(name, &statement.span).into()),
|
||||||
};
|
};
|
||||||
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
|
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
|
||||||
scope,
|
scope,
|
||||||
@ -147,17 +146,17 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
Some(PartialType::Integer(None, Some(IntegerType::U32))),
|
Some(PartialType::Integer(None, Some(IntegerType::U32))),
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
AstAssigneeAccess::Tuple(index, _) => {
|
AstAssigneeAccess::Tuple(index, span) => {
|
||||||
let index = index
|
let index = index
|
||||||
.value
|
.value
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.map_err(|_| AsgConvertError::parse_index_error())?;
|
.map_err(|_| AsgError::parse_index_error(span))?;
|
||||||
target_type = match target_type {
|
target_type = match target_type {
|
||||||
Some(PartialType::Tuple(types)) => types
|
Some(PartialType::Tuple(types)) => types
|
||||||
.get(index)
|
.get(index)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| AsgConvertError::tuple_index_out_of_bounds(index, &statement.span))?,
|
.ok_or_else(|| AsgError::tuple_index_out_of_bounds(index, &statement.span))?,
|
||||||
_ => return Err(AsgConvertError::index_into_non_tuple(name, &statement.span)),
|
_ => return Err(AsgError::index_into_non_tuple(name, &statement.span).into()),
|
||||||
};
|
};
|
||||||
AssignAccess::Tuple(index)
|
AssignAccess::Tuple(index)
|
||||||
}
|
}
|
||||||
@ -168,7 +167,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
|
|
||||||
let members = circuit.members.borrow();
|
let members = circuit.members.borrow();
|
||||||
let member = members.get(name.name.as_ref()).ok_or_else(|| {
|
let member = members.get(name.name.as_ref()).ok_or_else(|| {
|
||||||
AsgConvertError::unresolved_circuit_member(
|
AsgError::unresolved_circuit_member(
|
||||||
&circuit.name.borrow().name,
|
&circuit.name.borrow().name,
|
||||||
&name.name,
|
&name.name,
|
||||||
&statement.span,
|
&statement.span,
|
||||||
@ -178,16 +177,17 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
let x = match &member {
|
let x = match &member {
|
||||||
CircuitMember::Variable(type_) => type_.clone(),
|
CircuitMember::Variable(type_) => type_.clone(),
|
||||||
CircuitMember::Function(_) => {
|
CircuitMember::Function(_) => {
|
||||||
return Err(AsgConvertError::illegal_function_assign(&name.name, &statement.span));
|
return Err(AsgError::illegal_function_assign(&name.name, &statement.span).into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Some(x.partial())
|
Some(x.partial())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AsgConvertError::index_into_non_tuple(
|
return Err(AsgError::index_into_non_tuple(
|
||||||
&statement.assignee.identifier.name,
|
&statement.assignee.identifier.name,
|
||||||
&statement.span,
|
&statement.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AssignAccess::Member(name.clone())
|
AssignAccess::Member(name.clone())
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span, Statement};
|
use crate::{FromAst, Node, PartialType, Scope, Statement};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ impl<'a> FromAst<'a, leo_ast::Block> for BlockStatement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::Block,
|
statement: &leo_ast::Block,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let new_scope = scope.make_subscope();
|
let new_scope = scope.make_subscope();
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, BlockStatement, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type};
|
use crate::{BlockStatement, Expression, FromAst, Node, PartialType, Scope, Statement, Type};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ impl<'a> FromAst<'a, leo_ast::ConditionalStatement> for ConditionalStatement<'a>
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::ConditionalStatement,
|
statement: &leo_ast::ConditionalStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let condition = <&Expression<'a>>::from_ast(scope, &statement.condition, Some(Type::Boolean.into()))?;
|
let condition = <&Expression<'a>>::from_ast(scope, &statement.condition, Some(Type::Boolean.into()))?;
|
||||||
let result = scope.context.alloc_statement(Statement::Block(BlockStatement::from_ast(
|
let result = scope.context.alloc_statement(Statement::Block(BlockStatement::from_ast(
|
||||||
scope,
|
scope,
|
||||||
@ -48,9 +49,7 @@ impl<'a> FromAst<'a, leo_ast::ConditionalStatement> for ConditionalStatement<'a>
|
|||||||
let next = statement
|
let next = statement
|
||||||
.next
|
.next
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|next| -> Result<&'a Statement<'a>, AsgConvertError> {
|
.map(|next| -> Result<&'a Statement<'a>> { <&'a Statement<'a>>::from_ast(scope, next, None) })
|
||||||
<&'a Statement<'a>>::from_ast(scope, next, None)
|
|
||||||
})
|
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
Ok(ConditionalStatement {
|
Ok(ConditionalStatement {
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, CharValue, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type};
|
use crate::{CharValue, Expression, FromAst, Node, PartialType, Scope, Statement, Type};
|
||||||
use leo_ast::ConsoleFunction as AstConsoleFunction;
|
use leo_ast::ConsoleFunction as AstConsoleFunction;
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ impl<'a> FromAst<'a, leo_ast::ConsoleArgs> for ConsoleArgs<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::ConsoleArgs,
|
value: &leo_ast::ConsoleArgs,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let mut parameters = vec![];
|
let mut parameters = vec![];
|
||||||
for parameter in value.parameters.iter() {
|
for parameter in value.parameters.iter() {
|
||||||
parameters.push(Cell::new(<&Expression<'a>>::from_ast(scope, parameter, None)?));
|
parameters.push(Cell::new(<&Expression<'a>>::from_ast(scope, parameter, None)?));
|
||||||
@ -80,7 +81,7 @@ impl<'a> FromAst<'a, leo_ast::ConsoleStatement> for ConsoleStatement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::ConsoleStatement,
|
statement: &leo_ast::ConsoleStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
Ok(ConsoleStatement {
|
Ok(ConsoleStatement {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
span: Some(statement.span.clone()),
|
span: Some(statement.span.clone()),
|
||||||
|
@ -14,10 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Type, Variable};
|
||||||
AsgConvertError, Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Span, Statement,
|
use leo_errors::{AsgError, Result, Span};
|
||||||
Type, Variable,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
||||||
@ -59,11 +57,11 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::DefinitionStatement,
|
statement: &leo_ast::DefinitionStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let type_ = statement
|
let type_ = statement
|
||||||
.type_
|
.type_
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|x| scope.resolve_ast_type(x))
|
.map(|x| scope.resolve_ast_type(x, &statement.span))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
|
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
|
||||||
@ -76,7 +74,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(" ,");
|
.join(" ,");
|
||||||
|
|
||||||
return Err(AsgConvertError::invalid_const_assign(&var_names, &statement.span));
|
return Err(AsgError::invalid_const_assign(var_names, &statement.span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let type_ = type_.or_else(|| value.get_type());
|
let type_ = type_.or_else(|| value.get_type());
|
||||||
@ -85,9 +83,11 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
|
|
||||||
let mut variables = vec![];
|
let mut variables = vec![];
|
||||||
if statement.variable_names.is_empty() {
|
if statement.variable_names.is_empty() {
|
||||||
return Err(AsgConvertError::illegal_ast_structure(
|
return Err(AsgError::illegal_ast_structure(
|
||||||
"cannot have 0 variable names in destructuring tuple",
|
"cannot have 0 variable names in destructuring tuple",
|
||||||
));
|
&statement.span,
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
if statement.variable_names.len() == 1 {
|
if statement.variable_names.len() == 1 {
|
||||||
// any return type is fine
|
// any return type is fine
|
||||||
@ -99,11 +99,12 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
output_types.extend(sub_types.clone().into_iter().map(Some).collect::<Vec<_>>());
|
output_types.extend(sub_types.clone().into_iter().map(Some).collect::<Vec<_>>());
|
||||||
}
|
}
|
||||||
type_ => {
|
type_ => {
|
||||||
return Err(AsgConvertError::unexpected_type(
|
return Err(AsgError::unexpected_type(
|
||||||
&*format!("{}-ary tuple", statement.variable_names.len()),
|
format!("{}-ary tuple", statement.variable_names.len()),
|
||||||
type_.map(|x| x.to_string()).as_deref(),
|
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
|
||||||
&statement.span,
|
&statement.span,
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +113,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable {
|
variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable {
|
||||||
id: scope.context.get_id(),
|
id: scope.context.get_id(),
|
||||||
name: variable.identifier.clone(),
|
name: variable.identifier.clone(),
|
||||||
type_:
|
type_: type_.ok_or_else(|| AsgError::unresolved_type(&variable.identifier.name, &statement.span))?,
|
||||||
type_.ok_or_else(|| AsgConvertError::unresolved_type(&variable.identifier.name, &statement.span))?,
|
|
||||||
mutable: variable.mutable,
|
mutable: variable.mutable,
|
||||||
const_: false,
|
const_: false,
|
||||||
declaration: crate::VariableDeclaration::Definition,
|
declaration: crate::VariableDeclaration::Definition,
|
||||||
@ -126,10 +126,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
let mut variables = scope.variables.borrow_mut();
|
let mut variables = scope.variables.borrow_mut();
|
||||||
let var_name = variable.borrow().name.name.to_string();
|
let var_name = variable.borrow().name.name.to_string();
|
||||||
if variables.contains_key(&var_name) {
|
if variables.contains_key(&var_name) {
|
||||||
return Err(AsgConvertError::duplicate_variable_definition(
|
return Err(AsgError::duplicate_variable_definition(var_name, &statement.span).into());
|
||||||
&var_name,
|
|
||||||
&statement.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variables.insert(var_name, *variable);
|
variables.insert(var_name, *variable);
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement};
|
use crate::{Expression, FromAst, Node, PartialType, Scope, Statement};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ impl<'a> FromAst<'a, leo_ast::ExpressionStatement> for ExpressionStatement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::ExpressionStatement,
|
statement: &leo_ast::ExpressionStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let expression = <&Expression<'a>>::from_ast(scope, &statement.expression, None)?;
|
let expression = <&Expression<'a>>::from_ast(scope, &statement.expression, None)?;
|
||||||
|
|
||||||
Ok(ExpressionStatement {
|
Ok(ExpressionStatement {
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
use leo_ast::IntegerType;
|
use leo_ast::IntegerType;
|
||||||
|
|
||||||
use crate::{
|
use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Variable};
|
||||||
AsgConvertError, Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Span, Statement,
|
use leo_errors::{AsgError, Result, Span};
|
||||||
Variable,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
||||||
@ -45,21 +43,17 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::IterationStatement,
|
statement: &leo_ast::IterationStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let expected_index_type = Some(PartialType::Integer(Some(IntegerType::U32), None));
|
let expected_index_type = Some(PartialType::Integer(Some(IntegerType::U32), None));
|
||||||
let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?;
|
let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?;
|
||||||
let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?;
|
let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?;
|
||||||
|
|
||||||
// Return an error if start or stop is not constant.
|
// Return an error if start or stop is not constant.
|
||||||
if !start.is_consty() {
|
if !start.is_consty() {
|
||||||
return Err(AsgConvertError::unexpected_nonconst(
|
return Err(AsgError::unexpected_nonconst(&start.span().cloned().unwrap_or_default()).into());
|
||||||
&start.span().cloned().unwrap_or_default(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if !stop.is_consty() {
|
if !stop.is_consty() {
|
||||||
return Err(AsgConvertError::unexpected_nonconst(
|
return Err(AsgError::unexpected_nonconst(&stop.span().cloned().unwrap_or_default()).into());
|
||||||
&stop.span().cloned().unwrap_or_default(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let variable = scope.context.alloc_variable(RefCell::new(InnerVariable {
|
let variable = scope.context.alloc_variable(RefCell::new(InnerVariable {
|
||||||
@ -67,7 +61,7 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
|
|||||||
name: statement.variable.clone(),
|
name: statement.variable.clone(),
|
||||||
type_: start
|
type_: start
|
||||||
.get_type()
|
.get_type()
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_type(&statement.variable.name, &statement.span))?,
|
.ok_or_else(|| AsgError::unresolved_type(&statement.variable.name, &statement.span))?,
|
||||||
mutable: false,
|
mutable: false,
|
||||||
const_: true,
|
const_: true,
|
||||||
declaration: crate::VariableDeclaration::IterationDefinition,
|
declaration: crate::VariableDeclaration::IterationDefinition,
|
||||||
|
@ -42,7 +42,8 @@ pub use iteration::*;
|
|||||||
mod return_;
|
mod return_;
|
||||||
pub use return_::*;
|
pub use return_::*;
|
||||||
|
|
||||||
use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span};
|
use crate::{FromAst, Node, PartialType, Scope};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Statement<'a> {
|
pub enum Statement<'a> {
|
||||||
@ -79,14 +80,14 @@ impl<'a> FromAst<'a, leo_ast::Statement> for &'a Statement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
value: &leo_ast::Statement,
|
value: &leo_ast::Statement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<&'a Statement<'a>, AsgConvertError> {
|
) -> Result<&'a Statement<'a>> {
|
||||||
use leo_ast::Statement::*;
|
use leo_ast::Statement::*;
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
Return(statement) => scope
|
Return(statement) => scope
|
||||||
.context
|
.context
|
||||||
.alloc_statement(Statement::Return(ReturnStatement::from_ast(scope, statement, None)?)),
|
.alloc_statement(Statement::Return(ReturnStatement::from_ast(scope, statement, None)?)),
|
||||||
Definition(statement) => Self::from_ast(scope, statement, None)?,
|
Definition(statement) => Self::from_ast(scope, statement, None)?,
|
||||||
Assign(statement) => Self::from_ast(scope, statement, None)?,
|
Assign(statement) => Self::from_ast(scope, &**statement, None)?,
|
||||||
Conditional(statement) => {
|
Conditional(statement) => {
|
||||||
scope
|
scope
|
||||||
.context
|
.context
|
||||||
@ -94,7 +95,7 @@ impl<'a> FromAst<'a, leo_ast::Statement> for &'a Statement<'a> {
|
|||||||
scope, statement, None,
|
scope, statement, None,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
Iteration(statement) => Self::from_ast(scope, statement, None)?,
|
Iteration(statement) => Self::from_ast(scope, &**statement, None)?,
|
||||||
Console(statement) => scope
|
Console(statement) => scope
|
||||||
.context
|
.context
|
||||||
.alloc_statement(Statement::Console(ConsoleStatement::from_ast(scope, statement, None)?)),
|
.alloc_statement(Statement::Console(ConsoleStatement::from_ast(scope, statement, None)?)),
|
||||||
@ -118,9 +119,9 @@ impl<'a> Into<leo_ast::Statement> for &Statement<'a> {
|
|||||||
match self {
|
match self {
|
||||||
Return(statement) => leo_ast::Statement::Return(statement.into()),
|
Return(statement) => leo_ast::Statement::Return(statement.into()),
|
||||||
Definition(statement) => leo_ast::Statement::Definition(statement.into()),
|
Definition(statement) => leo_ast::Statement::Definition(statement.into()),
|
||||||
Assign(statement) => leo_ast::Statement::Assign(statement.into()),
|
Assign(statement) => leo_ast::Statement::Assign(Box::new(statement.into())),
|
||||||
Conditional(statement) => leo_ast::Statement::Conditional(statement.into()),
|
Conditional(statement) => leo_ast::Statement::Conditional(statement.into()),
|
||||||
Iteration(statement) => leo_ast::Statement::Iteration(statement.into()),
|
Iteration(statement) => leo_ast::Statement::Iteration(Box::new(statement.into())),
|
||||||
Console(statement) => leo_ast::Statement::Console(statement.into()),
|
Console(statement) => leo_ast::Statement::Console(statement.into()),
|
||||||
Expression(statement) => leo_ast::Statement::Expression(statement.into()),
|
Expression(statement) => leo_ast::Statement::Expression(statement.into()),
|
||||||
Block(statement) => leo_ast::Statement::Block(statement.into()),
|
Block(statement) => leo_ast::Statement::Block(statement.into()),
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type};
|
use crate::{Expression, FromAst, Node, PartialType, Scope, Statement, Type};
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -35,7 +36,7 @@ impl<'a> FromAst<'a, leo_ast::ReturnStatement> for ReturnStatement<'a> {
|
|||||||
scope: &'a Scope<'a>,
|
scope: &'a Scope<'a>,
|
||||||
statement: &leo_ast::ReturnStatement,
|
statement: &leo_ast::ReturnStatement,
|
||||||
_expected_type: Option<PartialType<'a>>,
|
_expected_type: Option<PartialType<'a>>,
|
||||||
) -> Result<Self, AsgConvertError> {
|
) -> Result<Self> {
|
||||||
let return_type: Option<Type> = scope
|
let return_type: Option<Type> = scope
|
||||||
.resolve_current_function()
|
.resolve_current_function()
|
||||||
.map(|x| x.output.clone())
|
.map(|x| x.output.clone())
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use leo_asg::*;
|
use leo_asg::*;
|
||||||
|
use leo_errors::LeoError;
|
||||||
use leo_parser::parse_ast;
|
use leo_parser::parse_ast;
|
||||||
|
|
||||||
mod fail;
|
mod fail;
|
||||||
@ -22,7 +23,7 @@ mod pass;
|
|||||||
|
|
||||||
const TESTING_FILEPATH: &str = "input.leo";
|
const TESTING_FILEPATH: &str = "input.leo";
|
||||||
|
|
||||||
fn load_asg(program_string: &str) -> Result<Program<'static>, AsgConvertError> {
|
fn load_asg(program_string: &str) -> Result<Program<'static>, LeoError> {
|
||||||
load_asg_imports(make_test_context(), program_string, &mut NullImportResolver)
|
load_asg_imports(make_test_context(), program_string, &mut NullImportResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,8 +31,9 @@ fn load_asg_imports<'a, T: ImportResolver<'a>>(
|
|||||||
context: AsgContext<'a>,
|
context: AsgContext<'a>,
|
||||||
program_string: &str,
|
program_string: &str,
|
||||||
imports: &mut T,
|
imports: &mut T,
|
||||||
) -> Result<Program<'a>, AsgConvertError> {
|
) -> Result<Program<'a>, LeoError> {
|
||||||
let ast = parse_ast(&TESTING_FILEPATH, program_string)?;
|
let mut ast = parse_ast(&TESTING_FILEPATH, program_string)?;
|
||||||
|
ast.canonicalize()?;
|
||||||
Program::new(context, &ast.as_repr(), imports)
|
Program::new(context, &ast.as_repr(), imports)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,10 @@ edition = "2018"
|
|||||||
path = "../input"
|
path = "../input"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
|
|
||||||
|
[dependencies.leo-errors]
|
||||||
|
path = "../errors"
|
||||||
|
version = "1.5.3"
|
||||||
|
|
||||||
[dependencies.indexmap]
|
[dependencies.indexmap]
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
features = [ "serde-1" ]
|
features = [ "serde-1" ]
|
||||||
@ -35,12 +39,6 @@ features = [ "derive", "rc" ]
|
|||||||
[dependencies.serde_json]
|
[dependencies.serde_json]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
[dependencies.anyhow]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dependencies.thiserror]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dependencies.tendril]
|
[dependencies.tendril]
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# leo-ast
|
# leo-ast
|
||||||
|
|
||||||
[![Crates.io](https://img.shields.io/crates/v/leo-ast.svg?color=neon)](https://crates.io/crates/leo-ast)
|
[![Crates.io](https://img.shields.io/crates/v/leo-ast.svg?color=neon)](https://crates.io/crates/leo-ast)
|
||||||
[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS)
|
[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS)
|
||||||
[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md)
|
[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md)
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Span};
|
use crate::Identifier;
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tendril::StrTendril;
|
use tendril::StrTendril;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::common::span::Span;
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
// use serde::de::{Deserialize as SerDeserialize, Deserializer};
|
// use serde::de::{Deserialize as SerDeserialize, Deserializer};
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Node, Span};
|
use crate::{Identifier, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::Span;
|
use leo_errors::Span;
|
||||||
use leo_input::common::Identifier as InputIdentifier;
|
use leo_input::common::Identifier as InputIdentifier;
|
||||||
use tendril::StrTendril;
|
use tendril::StrTendril;
|
||||||
|
|
||||||
|
@ -32,12 +32,7 @@ pub use positive_number::*;
|
|||||||
pub mod self_keyword;
|
pub mod self_keyword;
|
||||||
pub use self_keyword::*;
|
pub use self_keyword::*;
|
||||||
|
|
||||||
pub mod span;
|
|
||||||
pub use span::*;
|
|
||||||
|
|
||||||
pub mod spread_or_expression;
|
pub mod spread_or_expression;
|
||||||
pub use spread_or_expression::*;
|
pub use spread_or_expression::*;
|
||||||
|
|
||||||
pub mod tendril_json;
|
|
||||||
|
|
||||||
pub mod vec_tendril_json;
|
pub mod vec_tendril_json;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Node, Span};
|
use crate::{Identifier, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -23,7 +23,7 @@ use tendril::StrTendril;
|
|||||||
/// A number string guaranteed to be positive by the pest grammar.
|
/// A number string guaranteed to be positive by the pest grammar.
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct PositiveNumber {
|
pub struct PositiveNumber {
|
||||||
#[serde(with = "crate::common::tendril_json")]
|
#[serde(with = "leo_errors::common::tendril_json")]
|
||||||
pub value: StrTendril,
|
pub value: StrTendril,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Node, Span};
|
use crate::{Identifier, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Expression, Node, Span};
|
use crate::{Expression, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use crate::{FormattedError, LeoError, ReducerError, Span};
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum AstError {
|
|
||||||
#[error("{}", _0)]
|
|
||||||
Error(#[from] FormattedError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
IOError(#[from] std::io::Error),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
ReducerError(#[from] ReducerError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
SerdeJsonError(#[from] ::serde_json::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LeoError for AstError {}
|
|
||||||
|
|
||||||
impl AstError {
|
|
||||||
fn _new_from_span(message: String, span: &Span) -> Self {
|
|
||||||
AstError::Error(FormattedError::new_from_span(message, span))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use crate::{FormattedError, LeoError, Span};
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum CanonicalizeError {
|
|
||||||
#[error("{}", _0)]
|
|
||||||
Error(#[from] FormattedError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LeoError for CanonicalizeError {}
|
|
||||||
|
|
||||||
impl CanonicalizeError {
|
|
||||||
fn new_from_span(message: String, span: &Span) -> Self {
|
|
||||||
CanonicalizeError::Error(FormattedError::new_from_span(message, span))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn big_self_outside_of_circuit(span: &Span) -> Self {
|
|
||||||
let message = "cannot call keyword `Self` outside of a circuit function".to_string();
|
|
||||||
|
|
||||||
Self::new_from_span(message, span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalid_array_dimension_size(span: &Span) -> Self {
|
|
||||||
let message = "received dimension size of 0, expected it to be 1 or larger.".to_string();
|
|
||||||
|
|
||||||
Self::new_from_span(message, span)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use crate::{LeoError, Span};
|
|
||||||
use std::{fmt, sync::Arc};
|
|
||||||
|
|
||||||
pub const INDENT: &str = " ";
|
|
||||||
|
|
||||||
/// Formatted compiler error type
|
|
||||||
/// --> file.leo: 2:8
|
|
||||||
/// |
|
|
||||||
/// 2 | let a = x;
|
|
||||||
/// | ^
|
|
||||||
/// |
|
|
||||||
/// = undefined value `x`
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
||||||
pub struct FormattedError {
|
|
||||||
pub line_start: usize,
|
|
||||||
pub line_stop: usize,
|
|
||||||
pub col_start: usize,
|
|
||||||
pub col_stop: usize,
|
|
||||||
pub path: Arc<String>,
|
|
||||||
pub content: String,
|
|
||||||
pub message: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FormattedError {
|
|
||||||
pub fn new_from_span(message: String, span: &Span) -> Self {
|
|
||||||
Self {
|
|
||||||
line_start: span.line_start,
|
|
||||||
line_stop: span.line_stop,
|
|
||||||
col_start: span.col_start,
|
|
||||||
col_stop: span.col_stop,
|
|
||||||
path: span.path.clone(),
|
|
||||||
content: span.content.to_string(),
|
|
||||||
message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LeoError for FormattedError {}
|
|
||||||
|
|
||||||
fn underline(mut start: usize, mut end: usize) -> String {
|
|
||||||
if start > end {
|
|
||||||
std::mem::swap(&mut start, &mut end)
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut underline = String::new();
|
|
||||||
|
|
||||||
for _ in 0..start {
|
|
||||||
underline.push(' ');
|
|
||||||
end -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for _ in 0..end {
|
|
||||||
underline.push('^');
|
|
||||||
}
|
|
||||||
|
|
||||||
underline
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for FormattedError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
let underline = underline(self.col_start, self.col_stop);
|
|
||||||
|
|
||||||
let error_message = format!(
|
|
||||||
"{indent }--> {path}:{line_start}:{start}\n\
|
|
||||||
{indent } ",
|
|
||||||
indent = INDENT,
|
|
||||||
path = &*self.path,
|
|
||||||
line_start = self.line_start,
|
|
||||||
start = self.col_start,
|
|
||||||
);
|
|
||||||
|
|
||||||
write!(f, "{}", error_message)?;
|
|
||||||
|
|
||||||
for (line_no, line) in self.content.lines().enumerate() {
|
|
||||||
writeln!(
|
|
||||||
f,
|
|
||||||
"|\n{line_no:width$} | {text}",
|
|
||||||
width = INDENT.len(),
|
|
||||||
line_no = self.line_start + line_no,
|
|
||||||
text = line,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{indent } |{underline}\n\
|
|
||||||
{indent } |\n\
|
|
||||||
{indent } = {message}",
|
|
||||||
indent = INDENT,
|
|
||||||
underline = underline,
|
|
||||||
message = self.message,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for FormattedError {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
&self.message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_error() {
|
|
||||||
let err = FormattedError {
|
|
||||||
path: std::sync::Arc::new("file.leo".to_string()),
|
|
||||||
line_start: 2,
|
|
||||||
line_stop: 2,
|
|
||||||
col_start: 9,
|
|
||||||
col_stop: 10,
|
|
||||||
content: "let a = x;".into(),
|
|
||||||
message: "undefined value `x`".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
err.to_string(),
|
|
||||||
vec![
|
|
||||||
" --> file.leo:2:9",
|
|
||||||
" |",
|
|
||||||
" 2 | let a = x;",
|
|
||||||
" | ^",
|
|
||||||
" |",
|
|
||||||
" = undefined value `x`",
|
|
||||||
]
|
|
||||||
.join("\n")
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
pub mod ast;
|
|
||||||
pub use ast::*;
|
|
||||||
|
|
||||||
pub mod canonicalization;
|
|
||||||
pub use canonicalization::*;
|
|
||||||
|
|
||||||
pub mod combiner;
|
|
||||||
pub use combiner::*;
|
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub use error::*;
|
|
||||||
|
|
||||||
pub mod reducer;
|
|
||||||
pub use reducer::*;
|
|
||||||
|
|
||||||
pub trait LeoError {}
|
|
@ -1,50 +0,0 @@
|
|||||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
|
||||||
// This file is part of the Leo library.
|
|
||||||
|
|
||||||
// The Leo library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// The Leo library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use crate::{CanonicalizeError, CombinerError, FormattedError, LeoError, Span};
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum ReducerError {
|
|
||||||
#[error("{}", _0)]
|
|
||||||
Error(#[from] FormattedError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
CanonicalizeError(#[from] CanonicalizeError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
CombinerError(#[from] CombinerError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LeoError for ReducerError {}
|
|
||||||
|
|
||||||
impl ReducerError {
|
|
||||||
fn new_from_span(message: String, span: &Span) -> Self {
|
|
||||||
ReducerError::Error(FormattedError::new_from_span(message, span))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn empty_string(span: &Span) -> Self {
|
|
||||||
let message =
|
|
||||||
"Cannot constrcut an empty string: it has the type of [char; 0] which is not possible.".to_string();
|
|
||||||
|
|
||||||
Self::new_from_span(message, span)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn impossible_console_assert_call(span: &Span) -> Self {
|
|
||||||
let message = "Console::Assert cannot be matched here, its handled in another case.".to_string();
|
|
||||||
|
|
||||||
Self::new_from_span(message, span)
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,15 +15,15 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ArrayDimensions, CircuitImpliedVariableDefinition, GroupValue, Identifier, IntegerType, PositiveNumber, Span,
|
ArrayDimensions, CircuitImpliedVariableDefinition, GroupValue, Identifier, IntegerType, Node, PositiveNumber,
|
||||||
SpreadOrExpression,
|
SpreadOrExpression,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::Node;
|
|
||||||
|
|
||||||
mod binary;
|
mod binary;
|
||||||
pub use binary::*;
|
pub use binary::*;
|
||||||
mod unary;
|
mod unary;
|
||||||
|
@ -17,20 +17,20 @@
|
|||||||
use tendril::StrTendril;
|
use tendril::StrTendril;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{Char, CharValue, GroupTuple};
|
use crate::{Char, CharValue};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum ValueExpression {
|
pub enum ValueExpression {
|
||||||
// todo: deserialize values here
|
// todo: deserialize values here
|
||||||
Address(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Address(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
Boolean(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Boolean(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
Char(CharValue),
|
Char(CharValue),
|
||||||
Field(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Field(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
Group(Box<GroupValue>),
|
Group(Box<GroupValue>),
|
||||||
Implicit(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Implicit(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
Integer(
|
Integer(
|
||||||
IntegerType,
|
IntegerType,
|
||||||
#[serde(with = "crate::common::tendril_json")] StrTendril,
|
#[serde(with = "leo_errors::common::tendril_json")] StrTendril,
|
||||||
Span,
|
Span,
|
||||||
),
|
),
|
||||||
String(Vec<Char>, Span),
|
String(Vec<Char>, Span),
|
||||||
@ -69,7 +69,8 @@ impl Node for ValueExpression {
|
|||||||
| String(_, span) => span,
|
| String(_, span) => span,
|
||||||
Char(character) => &character.span,
|
Char(character) => &character.span,
|
||||||
Group(group) => match &**group {
|
Group(group) => match &**group {
|
||||||
GroupValue::Single(_, span) | GroupValue::Tuple(GroupTuple { span, .. }) => span,
|
GroupValue::Single(_, span) => span,
|
||||||
|
GroupValue::Tuple(tuple) => &tuple.span,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +86,8 @@ impl Node for ValueExpression {
|
|||||||
| String(_, span) => *span = new_span,
|
| String(_, span) => *span = new_span,
|
||||||
Char(character) => character.span = new_span,
|
Char(character) => character.span = new_span,
|
||||||
Group(group) => match &mut **group {
|
Group(group) => match &mut **group {
|
||||||
GroupValue::Single(_, span) | GroupValue::Tuple(GroupTuple { span, .. }) => *span = new_span,
|
GroupValue::Single(_, span) => *span = new_span,
|
||||||
|
GroupValue::Tuple(tuple) => tuple.span = new_span,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Annotation, Block, FunctionInput, Identifier, Node, Span, Type};
|
use crate::{Annotation, Block, FunctionInput, Identifier, Node, Type};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Node, Span, Type};
|
use crate::{Identifier, Node, Type};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ConstSelfKeyword, FunctionInputVariable, MutSelfKeyword, Node, SelfKeyword, Span};
|
use crate::{ConstSelfKeyword, FunctionInputVariable, MutSelfKeyword, Node, SelfKeyword};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::common::span::Span;
|
use leo_errors::Span;
|
||||||
use leo_input::values::{
|
use leo_input::values::{
|
||||||
GroupCoordinate as InputGroupCoordinate, Inferred as InputInferred, NumberValue as InputNumberValue,
|
GroupCoordinate as InputGroupCoordinate, Inferred as InputInferred, NumberValue as InputNumberValue,
|
||||||
SignHigh as InputSignHigh, SignLow as InputSignLow,
|
SignHigh as InputSignHigh, SignLow as InputSignLow,
|
||||||
@ -26,7 +26,7 @@ use tendril::StrTendril;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum GroupCoordinate {
|
pub enum GroupCoordinate {
|
||||||
Number(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Number(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
SignHigh,
|
SignHigh,
|
||||||
SignLow,
|
SignLow,
|
||||||
Inferred,
|
Inferred,
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{common::span::Span, groups::GroupCoordinate};
|
use crate::groups::GroupCoordinate;
|
||||||
|
use leo_errors::Span;
|
||||||
use leo_input::values::{
|
use leo_input::values::{
|
||||||
GroupRepresentation as InputGroupRepresentation, GroupTuple as InputGroupTuple, GroupValue as InputGroupValue,
|
GroupRepresentation as InputGroupRepresentation, GroupTuple as InputGroupTuple, GroupValue as InputGroupValue,
|
||||||
};
|
};
|
||||||
@ -25,7 +26,7 @@ use tendril::StrTendril;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum GroupValue {
|
pub enum GroupValue {
|
||||||
Single(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
Single(#[serde(with = "leo_errors::common::tendril_json")] StrTendril, Span),
|
||||||
Tuple(GroupTuple),
|
Tuple(GroupTuple),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{PackageOrPackages, Span};
|
use crate::PackageOrPackages;
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Span};
|
use crate::Identifier;
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{common::Identifier, PackageAccess, Span};
|
use crate::{common::Identifier, PackageAccess};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ImportSymbol, Node, Package, Packages, Span};
|
use crate::{ImportSymbol, Node, Package, Packages};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Node, Package, Packages, Span};
|
use crate::{Node, Package, Packages};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{common::Identifier, PackageAccess, Span};
|
use crate::{common::Identifier, PackageAccess};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ArrayDimensions, Char, CharValue, GroupValue, Span as AstSpan};
|
use crate::{ArrayDimensions, Char, CharValue, GroupValue};
|
||||||
|
use leo_errors::Span as AstSpan;
|
||||||
use leo_input::{
|
use leo_input::{
|
||||||
errors::InputParserError,
|
errors::InputParserError,
|
||||||
expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression, StringExpression, TupleExpression},
|
expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression, StringExpression, TupleExpression},
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Span, Type};
|
use crate::{Identifier, Type};
|
||||||
|
use leo_errors::Span;
|
||||||
use leo_input::parameters::Parameter as GrammarParameter;
|
use leo_input::parameters::Parameter as GrammarParameter;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
//! The [`Ast`] type is intended to be parsed and modified by different passes
|
//! The [`Ast`] type is intended to be parsed and modified by different passes
|
||||||
//! of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any [`Ast`].
|
//! of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any [`Ast`].
|
||||||
|
|
||||||
#[macro_use]
|
#![doc = include_str!("../README.md")]
|
||||||
extern crate thiserror;
|
|
||||||
|
|
||||||
pub mod annotation;
|
pub mod annotation;
|
||||||
pub use self::annotation::*;
|
pub use self::annotation::*;
|
||||||
@ -35,9 +34,6 @@ pub use self::chars::*;
|
|||||||
pub mod common;
|
pub mod common;
|
||||||
pub use self::common::*;
|
pub use self::common::*;
|
||||||
|
|
||||||
pub mod errors;
|
|
||||||
pub use self::errors::*;
|
|
||||||
|
|
||||||
pub mod expression;
|
pub mod expression;
|
||||||
pub use self::expression::*;
|
pub use self::expression::*;
|
||||||
|
|
||||||
@ -68,6 +64,8 @@ pub use self::types::*;
|
|||||||
mod node;
|
mod node;
|
||||||
pub use node::*;
|
pub use node::*;
|
||||||
|
|
||||||
|
use leo_errors::{AstError, Result};
|
||||||
|
|
||||||
/// The abstract syntax tree (AST) for a Leo program.
|
/// The abstract syntax tree (AST) for a Leo program.
|
||||||
///
|
///
|
||||||
/// The [`Ast`] type represents a Leo program as a series of recursive data types.
|
/// The [`Ast`] type represents a Leo program as a series of recursive data types.
|
||||||
@ -86,7 +84,7 @@ impl Ast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Mutates the program ast by preforming canonicalization on it.
|
/// Mutates the program ast by preforming canonicalization on it.
|
||||||
pub fn canonicalize(&mut self) -> Result<(), AstError> {
|
pub fn canonicalize(&mut self) -> Result<()> {
|
||||||
self.ast = ReconstructingDirector::new(Canonicalizer::default()).reduce_program(self.as_repr())?;
|
self.ast = ReconstructingDirector::new(Canonicalizer::default()).reduce_program(self.as_repr())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -101,26 +99,28 @@ impl Ast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes the ast into a JSON string.
|
/// Serializes the ast into a JSON string.
|
||||||
pub fn to_json_string(&self) -> Result<String, AstError> {
|
pub fn to_json_string(&self) -> Result<String> {
|
||||||
Ok(serde_json::to_string_pretty(&self.ast)?)
|
Ok(serde_json::to_string_pretty(&self.ast).map_err(|e| AstError::failed_to_convert_ast_to_json_string(&e))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_json_file(&self, mut path: std::path::PathBuf, file_name: &str) -> Result<(), AstError> {
|
/// Serializes the ast into a JSON file.
|
||||||
|
pub fn to_json_file(&self, mut path: std::path::PathBuf, file_name: &str) -> Result<()> {
|
||||||
path.push(file_name);
|
path.push(file_name);
|
||||||
let file = std::fs::File::create(path)?;
|
let file = std::fs::File::create(&path).map_err(|e| AstError::failed_to_create_ast_json_file(&path, &e))?;
|
||||||
let writer = std::io::BufWriter::new(file);
|
let writer = std::io::BufWriter::new(file);
|
||||||
serde_json::to_writer_pretty(writer, &self.ast)?;
|
Ok(serde_json::to_writer_pretty(writer, &self.ast)
|
||||||
Ok(())
|
.map_err(|e| AstError::failed_to_write_ast_to_json_file(&path, &e))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserializes the JSON string into a ast.
|
/// Deserializes the JSON string into a ast.
|
||||||
pub fn from_json_string(json: &str) -> Result<Self, AstError> {
|
pub fn from_json_string(json: &str) -> Result<Self> {
|
||||||
let ast: Program = serde_json::from_str(json)?;
|
let ast: Program = serde_json::from_str(json).map_err(|e| AstError::failed_to_read_json_string_to_ast(&e))?;
|
||||||
Ok(Self { ast })
|
Ok(Self { ast })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_json_file(path: std::path::PathBuf) -> Result<Self, AstError> {
|
/// Deserializes the JSON string into a ast from a file.
|
||||||
let data = std::fs::read_to_string(path)?;
|
pub fn from_json_file(path: std::path::PathBuf) -> Result<Self> {
|
||||||
|
let data = std::fs::read_to_string(&path).map_err(|e| AstError::failed_to_read_json_file(&path, &e))?;
|
||||||
Self::from_json_string(&data)
|
Self::from_json_string(&data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::Span;
|
use leo_errors::Span;
|
||||||
|
|
||||||
pub trait Node:
|
pub trait Node:
|
||||||
std::fmt::Debug + std::fmt::Display + Clone + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned
|
std::fmt::Debug + std::fmt::Display + Clone + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned
|
||||||
|
@ -15,11 +15,12 @@
|
|||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
use leo_errors::{AstError, Result, Span};
|
||||||
|
|
||||||
/// Replace Self when it is in a enclosing circuit type.
|
/// Replace Self when it is in a enclosing circuit type.
|
||||||
/// Error when Self is outside an enclosing circuit type.
|
/// Error when Self is outside an enclosing circuit type.
|
||||||
/// Tuple array types and expressions expand to nested arrays.
|
/// Tuple array types and expressions expand to nested arrays.
|
||||||
/// Tuple array types and expressions error if a size of 0 is given.anyhow
|
/// Tuple array types and expressions error if a size of 0 is given.
|
||||||
/// Compound operators become simple assignments.
|
/// Compound operators become simple assignments.
|
||||||
/// Functions missing output type return a empty tuple.
|
/// Functions missing output type return a empty tuple.
|
||||||
pub struct Canonicalizer {
|
pub struct Canonicalizer {
|
||||||
@ -43,7 +44,7 @@ impl Canonicalizer {
|
|||||||
start: Expression,
|
start: Expression,
|
||||||
accesses: &[AssigneeAccess],
|
accesses: &[AssigneeAccess],
|
||||||
span: &Span,
|
span: &Span,
|
||||||
) -> Result<Box<Expression>, ReducerError> {
|
) -> Result<Box<Expression>> {
|
||||||
let mut left = Box::new(start);
|
let mut left = Box::new(start);
|
||||||
|
|
||||||
for access in accesses.iter() {
|
for access in accesses.iter() {
|
||||||
@ -83,10 +84,7 @@ impl Canonicalizer {
|
|||||||
Ok(left)
|
Ok(left)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compound_operation_converstion(
|
pub fn compound_operation_converstion(&mut self, operation: &AssignOperation) -> Result<BinaryOperation> {
|
||||||
&mut self,
|
|
||||||
operation: &AssignOperation,
|
|
||||||
) -> Result<BinaryOperation, ReducerError> {
|
|
||||||
match operation {
|
match operation {
|
||||||
AssignOperation::Assign => unreachable!(),
|
AssignOperation::Assign => unreachable!(),
|
||||||
AssignOperation::Add => Ok(BinaryOperation::Add),
|
AssignOperation::Add => Ok(BinaryOperation::Add),
|
||||||
@ -106,8 +104,24 @@ impl Canonicalizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_type(&mut self, type_option: Option<&Type>) -> bool {
|
fn canonicalize_self_type(&self, type_option: Option<&Type>) -> Option<Type> {
|
||||||
matches!(type_option, Some(Type::SelfType))
|
match type_option {
|
||||||
|
Some(type_) => match type_ {
|
||||||
|
Type::SelfType => Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone())),
|
||||||
|
Type::Array(type_, dimensions) => Some(Type::Array(
|
||||||
|
Box::new(self.canonicalize_self_type(Some(type_)).unwrap()),
|
||||||
|
dimensions.clone(),
|
||||||
|
)),
|
||||||
|
Type::Tuple(types) => Some(Type::Tuple(
|
||||||
|
types
|
||||||
|
.iter()
|
||||||
|
.map(|type_| self.canonicalize_self_type(Some(type_)).unwrap())
|
||||||
|
.collect(),
|
||||||
|
)),
|
||||||
|
_ => Some(type_.clone()),
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn canonicalize_expression(&mut self, expression: &Expression) -> Expression {
|
fn canonicalize_expression(&mut self, expression: &Expression) -> Expression {
|
||||||
@ -147,11 +161,7 @@ impl Canonicalizer {
|
|||||||
|
|
||||||
Expression::Cast(cast) => {
|
Expression::Cast(cast) => {
|
||||||
let inner = Box::new(self.canonicalize_expression(&cast.inner));
|
let inner = Box::new(self.canonicalize_expression(&cast.inner));
|
||||||
let mut target_type = cast.target_type.clone();
|
let target_type = self.canonicalize_self_type(Some(&cast.target_type)).unwrap();
|
||||||
|
|
||||||
if matches!(target_type, Type::SelfType) {
|
|
||||||
target_type = Type::Circuit(self.circuit_name.as_ref().unwrap().clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Expression::Cast(CastExpression {
|
return Expression::Cast(CastExpression {
|
||||||
inner,
|
inner,
|
||||||
@ -338,11 +348,7 @@ impl Canonicalizer {
|
|||||||
}
|
}
|
||||||
Statement::Definition(definition) => {
|
Statement::Definition(definition) => {
|
||||||
let value = self.canonicalize_expression(&definition.value);
|
let value = self.canonicalize_expression(&definition.value);
|
||||||
let mut type_ = definition.type_.clone();
|
let type_ = self.canonicalize_self_type(definition.type_.as_ref());
|
||||||
|
|
||||||
if self.is_self_type(type_.as_ref()) {
|
|
||||||
type_ = Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::Definition(DefinitionStatement {
|
Statement::Definition(DefinitionStatement {
|
||||||
declaration_type: definition.declaration_type.clone(),
|
declaration_type: definition.declaration_type.clone(),
|
||||||
@ -356,12 +362,12 @@ impl Canonicalizer {
|
|||||||
let assignee = self.canonicalize_assignee(&assign.assignee);
|
let assignee = self.canonicalize_assignee(&assign.assignee);
|
||||||
let value = self.canonicalize_expression(&assign.value);
|
let value = self.canonicalize_expression(&assign.value);
|
||||||
|
|
||||||
Statement::Assign(AssignStatement {
|
Statement::Assign(Box::new(AssignStatement {
|
||||||
assignee,
|
assignee,
|
||||||
value,
|
value,
|
||||||
operation: assign.operation,
|
operation: assign.operation,
|
||||||
span: assign.span.clone(),
|
span: assign.span.clone(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
Statement::Conditional(conditional) => {
|
Statement::Conditional(conditional) => {
|
||||||
let condition = self.canonicalize_expression(&conditional.condition);
|
let condition = self.canonicalize_expression(&conditional.condition);
|
||||||
@ -383,14 +389,14 @@ impl Canonicalizer {
|
|||||||
let stop = self.canonicalize_expression(&iteration.stop);
|
let stop = self.canonicalize_expression(&iteration.stop);
|
||||||
let block = self.canonicalize_block(&iteration.block);
|
let block = self.canonicalize_block(&iteration.block);
|
||||||
|
|
||||||
Statement::Iteration(IterationStatement {
|
Statement::Iteration(Box::new(IterationStatement {
|
||||||
variable: iteration.variable.clone(),
|
variable: iteration.variable.clone(),
|
||||||
start,
|
start,
|
||||||
stop,
|
stop,
|
||||||
inclusive: iteration.inclusive,
|
inclusive: iteration.inclusive,
|
||||||
block,
|
block,
|
||||||
span: iteration.span.clone(),
|
span: iteration.span.clone(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
Statement::Console(console_function_call) => {
|
Statement::Console(console_function_call) => {
|
||||||
let function = match &console_function_call.function {
|
let function = match &console_function_call.function {
|
||||||
@ -436,13 +442,9 @@ impl Canonicalizer {
|
|||||||
CircuitMember::CircuitVariable(_, _) => {}
|
CircuitMember::CircuitVariable(_, _) => {}
|
||||||
CircuitMember::CircuitFunction(function) => {
|
CircuitMember::CircuitFunction(function) => {
|
||||||
let input = function.input.clone();
|
let input = function.input.clone();
|
||||||
let mut output = function.output.clone();
|
let output = self.canonicalize_self_type(function.output.as_ref());
|
||||||
let block = self.canonicalize_block(&function.block);
|
let block = self.canonicalize_block(&function.block);
|
||||||
|
|
||||||
if self.is_self_type(output.as_ref()) {
|
|
||||||
output = Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return CircuitMember::CircuitFunction(Function {
|
return CircuitMember::CircuitFunction(Function {
|
||||||
annotations: function.annotations.clone(),
|
annotations: function.annotations.clone(),
|
||||||
identifier: function.identifier.clone(),
|
identifier: function.identifier.clone(),
|
||||||
@ -467,13 +469,11 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
self.in_circuit = !self.in_circuit;
|
self.in_circuit = !self.in_circuit;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result<Type, ReducerError> {
|
fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result<Type> {
|
||||||
match new {
|
match new {
|
||||||
Type::Array(type_, mut dimensions) => {
|
Type::Array(type_, mut dimensions) => {
|
||||||
if dimensions.is_zero() {
|
if dimensions.is_zero() {
|
||||||
return Err(ReducerError::from(CanonicalizeError::invalid_array_dimension_size(
|
return Err(AstError::invalid_array_dimension_size(span).into());
|
||||||
span,
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()]));
|
let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()]));
|
||||||
@ -490,16 +490,14 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
|
|
||||||
Ok(array)
|
Ok(array)
|
||||||
}
|
}
|
||||||
Type::SelfType if !self.in_circuit => {
|
Type::SelfType if !self.in_circuit => Err(AstError::big_self_outside_of_circuit(span).into()),
|
||||||
Err(ReducerError::from(CanonicalizeError::big_self_outside_of_circuit(span)))
|
|
||||||
}
|
|
||||||
_ => Ok(new.clone()),
|
_ => Ok(new.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression, ReducerError> {
|
fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression> {
|
||||||
if string.is_empty() {
|
if string.is_empty() {
|
||||||
return Err(ReducerError::empty_string(span));
|
return Err(AstError::empty_string(span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut elements = Vec::new();
|
let mut elements = Vec::new();
|
||||||
@ -534,14 +532,14 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
elements.push(SpreadOrExpression::Expression(Expression::Value(
|
elements.push(SpreadOrExpression::Expression(Expression::Value(
|
||||||
ValueExpression::Char(CharValue {
|
ValueExpression::Char(CharValue {
|
||||||
character: character.clone(),
|
character: character.clone(),
|
||||||
span: Span {
|
span: Span::new(
|
||||||
line_start: span.line_start,
|
span.line_start,
|
||||||
line_stop: span.line_stop,
|
span.line_stop,
|
||||||
col_start,
|
col_start,
|
||||||
col_stop,
|
col_stop,
|
||||||
path: span.path.clone(),
|
span.path.clone(),
|
||||||
content: span.content.clone(),
|
span.content.clone(),
|
||||||
},
|
),
|
||||||
}),
|
}),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -556,11 +554,9 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
array_init: &ArrayInitExpression,
|
array_init: &ArrayInitExpression,
|
||||||
element: Expression,
|
element: Expression,
|
||||||
) -> Result<ArrayInitExpression, ReducerError> {
|
) -> Result<ArrayInitExpression> {
|
||||||
if array_init.dimensions.is_zero() {
|
if array_init.dimensions.is_zero() {
|
||||||
return Err(ReducerError::from(CanonicalizeError::invalid_array_dimension_size(
|
return Err(AstError::invalid_array_dimension_size(&array_init.span).into());
|
||||||
&array_init.span,
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let element = Box::new(element);
|
let element = Box::new(element);
|
||||||
@ -607,7 +603,7 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
assign: &AssignStatement,
|
assign: &AssignStatement,
|
||||||
assignee: Assignee,
|
assignee: Assignee,
|
||||||
value: Expression,
|
value: Expression,
|
||||||
) -> Result<AssignStatement, ReducerError> {
|
) -> Result<AssignStatement> {
|
||||||
match value {
|
match value {
|
||||||
value if assign.operation != AssignOperation::Assign => {
|
value if assign.operation != AssignOperation::Assign => {
|
||||||
let left = self.canonicalize_accesses(
|
let left = self.canonicalize_accesses(
|
||||||
@ -649,7 +645,7 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
input: Vec<FunctionInput>,
|
input: Vec<FunctionInput>,
|
||||||
output: Option<Type>,
|
output: Option<Type>,
|
||||||
block: Block,
|
block: Block,
|
||||||
) -> Result<Function, ReducerError> {
|
) -> Result<Function> {
|
||||||
let new_output = match output {
|
let new_output = match output {
|
||||||
None => Some(Type::Tuple(vec![])),
|
None => Some(Type::Tuple(vec![])),
|
||||||
_ => output,
|
_ => output,
|
||||||
@ -670,7 +666,7 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
_circuit: &Circuit,
|
_circuit: &Circuit,
|
||||||
circuit_name: Identifier,
|
circuit_name: Identifier,
|
||||||
members: Vec<CircuitMember>,
|
members: Vec<CircuitMember>,
|
||||||
) -> Result<Circuit, ReducerError> {
|
) -> Result<Circuit> {
|
||||||
self.circuit_name = Some(circuit_name.clone());
|
self.circuit_name = Some(circuit_name.clone());
|
||||||
let circ = Circuit {
|
let circ = Circuit {
|
||||||
circuit_name,
|
circuit_name,
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use leo_errors::{AstError, Result, Span};
|
||||||
|
|
||||||
pub struct ReconstructingDirector<R: ReconstructingReducer> {
|
pub struct ReconstructingDirector<R: ReconstructingReducer> {
|
||||||
reducer: R,
|
reducer: R,
|
||||||
@ -29,7 +30,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
Self { reducer }
|
Self { reducer }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result<Type, ReducerError> {
|
pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result<Type> {
|
||||||
let new = match type_ {
|
let new = match type_ {
|
||||||
Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_, span)?), dimensions.clone()),
|
Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_, span)?), dimensions.clone()),
|
||||||
Type::Tuple(types) => {
|
Type::Tuple(types) => {
|
||||||
@ -48,7 +49,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
pub fn reduce_expression(&mut self, expression: &Expression) -> Result<Expression, ReducerError> {
|
pub fn reduce_expression(&mut self, expression: &Expression) -> Result<Expression> {
|
||||||
let new = match expression {
|
let new = match expression {
|
||||||
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)?),
|
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)?),
|
||||||
Expression::Value(value) => self.reduce_value(value)?,
|
Expression::Value(value) => self.reduce_value(value)?,
|
||||||
@ -81,15 +82,15 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_expression(expression, new)
|
self.reducer.reduce_expression(expression, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result<Identifier, ReducerError> {
|
pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result<Identifier> {
|
||||||
self.reducer.reduce_identifier(identifier)
|
self.reducer.reduce_identifier(identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result<GroupTuple, ReducerError> {
|
pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result<GroupTuple> {
|
||||||
self.reducer.reduce_group_tuple(group_tuple)
|
self.reducer.reduce_group_tuple(group_tuple)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result<GroupValue, ReducerError> {
|
pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result<GroupValue> {
|
||||||
let new = match group_value {
|
let new = match group_value {
|
||||||
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(group_tuple)?),
|
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(group_tuple)?),
|
||||||
_ => group_value.clone(),
|
_ => group_value.clone(),
|
||||||
@ -98,11 +99,11 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_group_value(group_value, new)
|
self.reducer.reduce_group_value(group_value, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression, ReducerError> {
|
pub fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression> {
|
||||||
self.reducer.reduce_string(string, span)
|
self.reducer.reduce_string(string, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_value(&mut self, value: &ValueExpression) -> Result<Expression, ReducerError> {
|
pub fn reduce_value(&mut self, value: &ValueExpression) -> Result<Expression> {
|
||||||
let new = match value {
|
let new = match value {
|
||||||
ValueExpression::Group(group_value) => {
|
ValueExpression::Group(group_value) => {
|
||||||
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(group_value)?)))
|
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(group_value)?)))
|
||||||
@ -114,20 +115,20 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_value(value, new)
|
self.reducer.reduce_value(value, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> Result<BinaryExpression, ReducerError> {
|
pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> Result<BinaryExpression> {
|
||||||
let left = self.reduce_expression(&binary.left)?;
|
let left = self.reduce_expression(&binary.left)?;
|
||||||
let right = self.reduce_expression(&binary.right)?;
|
let right = self.reduce_expression(&binary.right)?;
|
||||||
|
|
||||||
self.reducer.reduce_binary(binary, left, right, binary.op.clone())
|
self.reducer.reduce_binary(binary, left, right, binary.op.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> Result<UnaryExpression, ReducerError> {
|
pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> Result<UnaryExpression> {
|
||||||
let inner = self.reduce_expression(&unary.inner)?;
|
let inner = self.reduce_expression(&unary.inner)?;
|
||||||
|
|
||||||
self.reducer.reduce_unary(unary, inner, unary.op.clone())
|
self.reducer.reduce_unary(unary, inner, unary.op.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> Result<TernaryExpression, ReducerError> {
|
pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> Result<TernaryExpression> {
|
||||||
let condition = self.reduce_expression(&ternary.condition)?;
|
let condition = self.reduce_expression(&ternary.condition)?;
|
||||||
let if_true = self.reduce_expression(&ternary.if_true)?;
|
let if_true = self.reduce_expression(&ternary.if_true)?;
|
||||||
let if_false = self.reduce_expression(&ternary.if_false)?;
|
let if_false = self.reduce_expression(&ternary.if_false)?;
|
||||||
@ -135,17 +136,14 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_ternary(ternary, condition, if_true, if_false)
|
self.reducer.reduce_ternary(ternary, condition, if_true, if_false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_cast(&mut self, cast: &CastExpression) -> Result<CastExpression, ReducerError> {
|
pub fn reduce_cast(&mut self, cast: &CastExpression) -> Result<CastExpression> {
|
||||||
let inner = self.reduce_expression(&cast.inner)?;
|
let inner = self.reduce_expression(&cast.inner)?;
|
||||||
let target_type = self.reduce_type(&cast.target_type, &cast.span)?;
|
let target_type = self.reduce_type(&cast.target_type, &cast.span)?;
|
||||||
|
|
||||||
self.reducer.reduce_cast(cast, inner, target_type)
|
self.reducer.reduce_cast(cast, inner, target_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_array_inline(
|
pub fn reduce_array_inline(&mut self, array_inline: &ArrayInlineExpression) -> Result<ArrayInlineExpression> {
|
||||||
&mut self,
|
|
||||||
array_inline: &ArrayInlineExpression,
|
|
||||||
) -> Result<ArrayInlineExpression, ReducerError> {
|
|
||||||
let mut elements = vec![];
|
let mut elements = vec![];
|
||||||
for element in array_inline.elements.iter() {
|
for element in array_inline.elements.iter() {
|
||||||
let reduced_element = match element {
|
let reduced_element = match element {
|
||||||
@ -163,16 +161,13 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_array_inline(array_inline, elements)
|
self.reducer.reduce_array_inline(array_inline, elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> Result<ArrayInitExpression, ReducerError> {
|
pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> Result<ArrayInitExpression> {
|
||||||
let element = self.reduce_expression(&array_init.element)?;
|
let element = self.reduce_expression(&array_init.element)?;
|
||||||
|
|
||||||
self.reducer.reduce_array_init(array_init, element)
|
self.reducer.reduce_array_init(array_init, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_array_access(
|
pub fn reduce_array_access(&mut self, array_access: &ArrayAccessExpression) -> Result<ArrayAccessExpression> {
|
||||||
&mut self,
|
|
||||||
array_access: &ArrayAccessExpression,
|
|
||||||
) -> Result<ArrayAccessExpression, ReducerError> {
|
|
||||||
let array = self.reduce_expression(&array_access.array)?;
|
let array = self.reduce_expression(&array_access.array)?;
|
||||||
let index = self.reduce_expression(&array_access.index)?;
|
let index = self.reduce_expression(&array_access.index)?;
|
||||||
|
|
||||||
@ -182,7 +177,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_array_range_access(
|
pub fn reduce_array_range_access(
|
||||||
&mut self,
|
&mut self,
|
||||||
array_range_access: &ArrayRangeAccessExpression,
|
array_range_access: &ArrayRangeAccessExpression,
|
||||||
) -> Result<ArrayRangeAccessExpression, ReducerError> {
|
) -> Result<ArrayRangeAccessExpression> {
|
||||||
let array = self.reduce_expression(&array_range_access.array)?;
|
let array = self.reduce_expression(&array_range_access.array)?;
|
||||||
let left = array_range_access
|
let left = array_range_access
|
||||||
.left
|
.left
|
||||||
@ -199,7 +194,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
.reduce_array_range_access(array_range_access, array, left, right)
|
.reduce_array_range_access(array_range_access, array, left, right)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> Result<TupleInitExpression, ReducerError> {
|
pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> Result<TupleInitExpression> {
|
||||||
let mut elements = vec![];
|
let mut elements = vec![];
|
||||||
for element in tuple_init.elements.iter() {
|
for element in tuple_init.elements.iter() {
|
||||||
elements.push(self.reduce_expression(element)?);
|
elements.push(self.reduce_expression(element)?);
|
||||||
@ -208,10 +203,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_tuple_init(tuple_init, elements)
|
self.reducer.reduce_tuple_init(tuple_init, elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_tuple_access(
|
pub fn reduce_tuple_access(&mut self, tuple_access: &TupleAccessExpression) -> Result<TupleAccessExpression> {
|
||||||
&mut self,
|
|
||||||
tuple_access: &TupleAccessExpression,
|
|
||||||
) -> Result<TupleAccessExpression, ReducerError> {
|
|
||||||
let tuple = self.reduce_expression(&tuple_access.tuple)?;
|
let tuple = self.reduce_expression(&tuple_access.tuple)?;
|
||||||
|
|
||||||
self.reducer.reduce_tuple_access(tuple_access, tuple)
|
self.reducer.reduce_tuple_access(tuple_access, tuple)
|
||||||
@ -220,7 +212,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_circuit_implied_variable_definition(
|
pub fn reduce_circuit_implied_variable_definition(
|
||||||
&mut self,
|
&mut self,
|
||||||
variable: &CircuitImpliedVariableDefinition,
|
variable: &CircuitImpliedVariableDefinition,
|
||||||
) -> Result<CircuitImpliedVariableDefinition, ReducerError> {
|
) -> Result<CircuitImpliedVariableDefinition> {
|
||||||
let identifier = self.reduce_identifier(&variable.identifier)?;
|
let identifier = self.reduce_identifier(&variable.identifier)?;
|
||||||
let expression = variable
|
let expression = variable
|
||||||
.expression
|
.expression
|
||||||
@ -232,10 +224,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
.reduce_circuit_implied_variable_definition(variable, identifier, expression)
|
.reduce_circuit_implied_variable_definition(variable, identifier, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_circuit_init(
|
pub fn reduce_circuit_init(&mut self, circuit_init: &CircuitInitExpression) -> Result<CircuitInitExpression> {
|
||||||
&mut self,
|
|
||||||
circuit_init: &CircuitInitExpression,
|
|
||||||
) -> Result<CircuitInitExpression, ReducerError> {
|
|
||||||
let name = self.reduce_identifier(&circuit_init.name)?;
|
let name = self.reduce_identifier(&circuit_init.name)?;
|
||||||
|
|
||||||
let mut members = vec![];
|
let mut members = vec![];
|
||||||
@ -249,7 +238,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_circuit_member_access(
|
pub fn reduce_circuit_member_access(
|
||||||
&mut self,
|
&mut self,
|
||||||
circuit_member_access: &CircuitMemberAccessExpression,
|
circuit_member_access: &CircuitMemberAccessExpression,
|
||||||
) -> Result<CircuitMemberAccessExpression, ReducerError> {
|
) -> Result<CircuitMemberAccessExpression> {
|
||||||
let circuit = self.reduce_expression(&circuit_member_access.circuit)?;
|
let circuit = self.reduce_expression(&circuit_member_access.circuit)?;
|
||||||
let name = self.reduce_identifier(&circuit_member_access.name)?;
|
let name = self.reduce_identifier(&circuit_member_access.name)?;
|
||||||
|
|
||||||
@ -260,7 +249,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_circuit_static_fn_access(
|
pub fn reduce_circuit_static_fn_access(
|
||||||
&mut self,
|
&mut self,
|
||||||
circuit_static_fn_access: &CircuitStaticFunctionAccessExpression,
|
circuit_static_fn_access: &CircuitStaticFunctionAccessExpression,
|
||||||
) -> Result<CircuitStaticFunctionAccessExpression, ReducerError> {
|
) -> Result<CircuitStaticFunctionAccessExpression> {
|
||||||
let circuit = self.reduce_expression(&circuit_static_fn_access.circuit)?;
|
let circuit = self.reduce_expression(&circuit_static_fn_access.circuit)?;
|
||||||
let name = self.reduce_identifier(&circuit_static_fn_access.name)?;
|
let name = self.reduce_identifier(&circuit_static_fn_access.name)?;
|
||||||
|
|
||||||
@ -268,7 +257,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
.reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name)
|
.reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_call(&mut self, call: &CallExpression) -> Result<CallExpression, ReducerError> {
|
pub fn reduce_call(&mut self, call: &CallExpression) -> Result<CallExpression> {
|
||||||
let function = self.reduce_expression(&call.function)?;
|
let function = self.reduce_expression(&call.function)?;
|
||||||
|
|
||||||
let mut arguments = vec![];
|
let mut arguments = vec![];
|
||||||
@ -280,13 +269,13 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Statements
|
// Statements
|
||||||
pub fn reduce_statement(&mut self, statement: &Statement) -> Result<Statement, ReducerError> {
|
pub fn reduce_statement(&mut self, statement: &Statement) -> Result<Statement> {
|
||||||
let new = match statement {
|
let new = match statement {
|
||||||
Statement::Return(return_statement) => Statement::Return(self.reduce_return(return_statement)?),
|
Statement::Return(return_statement) => Statement::Return(self.reduce_return(return_statement)?),
|
||||||
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(definition)?),
|
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(definition)?),
|
||||||
Statement::Assign(assign) => Statement::Assign(self.reduce_assign(assign)?),
|
Statement::Assign(assign) => Statement::Assign(Box::new(self.reduce_assign(assign)?)),
|
||||||
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?),
|
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?),
|
||||||
Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(iteration)?),
|
Statement::Iteration(iteration) => Statement::Iteration(Box::new(self.reduce_iteration(iteration)?)),
|
||||||
Statement::Console(console) => Statement::Console(self.reduce_console(console)?),
|
Statement::Console(console) => Statement::Console(self.reduce_console(console)?),
|
||||||
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?),
|
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?),
|
||||||
Statement::Block(block) => Statement::Block(self.reduce_block(block)?),
|
Statement::Block(block) => Statement::Block(self.reduce_block(block)?),
|
||||||
@ -295,19 +284,19 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_statement(statement, new)
|
self.reducer.reduce_statement(statement, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> Result<ReturnStatement, ReducerError> {
|
pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> Result<ReturnStatement> {
|
||||||
let expression = self.reduce_expression(&return_statement.expression)?;
|
let expression = self.reduce_expression(&return_statement.expression)?;
|
||||||
|
|
||||||
self.reducer.reduce_return(return_statement, expression)
|
self.reducer.reduce_return(return_statement, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result<VariableName, ReducerError> {
|
pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result<VariableName> {
|
||||||
let identifier = self.reduce_identifier(&variable_name.identifier)?;
|
let identifier = self.reduce_identifier(&variable_name.identifier)?;
|
||||||
|
|
||||||
self.reducer.reduce_variable_name(variable_name, identifier)
|
self.reducer.reduce_variable_name(variable_name, identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> Result<DefinitionStatement, ReducerError> {
|
pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> Result<DefinitionStatement> {
|
||||||
let mut variable_names = vec![];
|
let mut variable_names = vec![];
|
||||||
for variable_name in definition.variable_names.iter() {
|
for variable_name in definition.variable_names.iter() {
|
||||||
variable_names.push(self.reduce_variable_name(variable_name)?);
|
variable_names.push(self.reduce_variable_name(variable_name)?);
|
||||||
@ -324,7 +313,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_definition(definition, variable_names, type_, value)
|
self.reducer.reduce_definition(definition, variable_names, type_, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result<AssigneeAccess, ReducerError> {
|
pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result<AssigneeAccess> {
|
||||||
let new = match access {
|
let new = match access {
|
||||||
AssigneeAccess::ArrayRange(left, right) => {
|
AssigneeAccess::ArrayRange(left, right) => {
|
||||||
let left = left.as_ref().map(|left| self.reduce_expression(left)).transpose()?;
|
let left = left.as_ref().map(|left| self.reduce_expression(left)).transpose()?;
|
||||||
@ -340,7 +329,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_assignee_access(access, new)
|
self.reducer.reduce_assignee_access(access, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Result<Assignee, ReducerError> {
|
pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Result<Assignee> {
|
||||||
let identifier = self.reduce_identifier(&assignee.identifier)?;
|
let identifier = self.reduce_identifier(&assignee.identifier)?;
|
||||||
|
|
||||||
let mut accesses = vec![];
|
let mut accesses = vec![];
|
||||||
@ -351,17 +340,14 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_assignee(assignee, identifier, accesses)
|
self.reducer.reduce_assignee(assignee, identifier, accesses)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_assign(&mut self, assign: &AssignStatement) -> Result<AssignStatement, ReducerError> {
|
pub fn reduce_assign(&mut self, assign: &AssignStatement) -> Result<AssignStatement> {
|
||||||
let assignee = self.reduce_assignee(&assign.assignee)?;
|
let assignee = self.reduce_assignee(&assign.assignee)?;
|
||||||
let value = self.reduce_expression(&assign.value)?;
|
let value = self.reduce_expression(&assign.value)?;
|
||||||
|
|
||||||
self.reducer.reduce_assign(assign, assignee, value)
|
self.reducer.reduce_assign(assign, assignee, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_conditional(
|
pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement) -> Result<ConditionalStatement> {
|
||||||
&mut self,
|
|
||||||
conditional: &ConditionalStatement,
|
|
||||||
) -> Result<ConditionalStatement, ReducerError> {
|
|
||||||
let condition = self.reduce_expression(&conditional.condition)?;
|
let condition = self.reduce_expression(&conditional.condition)?;
|
||||||
let block = self.reduce_block(&conditional.block)?;
|
let block = self.reduce_block(&conditional.block)?;
|
||||||
let next = conditional
|
let next = conditional
|
||||||
@ -373,7 +359,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_conditional(conditional, condition, block, next)
|
self.reducer.reduce_conditional(conditional, condition, block, next)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> Result<IterationStatement, ReducerError> {
|
pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> Result<IterationStatement> {
|
||||||
let variable = self.reduce_identifier(&iteration.variable)?;
|
let variable = self.reduce_identifier(&iteration.variable)?;
|
||||||
let start = self.reduce_expression(&iteration.start)?;
|
let start = self.reduce_expression(&iteration.start)?;
|
||||||
let stop = self.reduce_expression(&iteration.stop)?;
|
let stop = self.reduce_expression(&iteration.stop)?;
|
||||||
@ -382,10 +368,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_iteration(iteration, variable, start, stop, block)
|
self.reducer.reduce_iteration(iteration, variable, start, stop, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_console(
|
pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> Result<ConsoleStatement> {
|
||||||
&mut self,
|
|
||||||
console_function_call: &ConsoleStatement,
|
|
||||||
) -> Result<ConsoleStatement, ReducerError> {
|
|
||||||
let function = match &console_function_call.function {
|
let function = match &console_function_call.function {
|
||||||
ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?),
|
ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?),
|
||||||
ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
ConsoleFunction::Error(args) | ConsoleFunction::Log(args) => {
|
||||||
@ -403,7 +386,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
match &console_function_call.function {
|
match &console_function_call.function {
|
||||||
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
||||||
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
||||||
_ => return Err(ReducerError::impossible_console_assert_call(&args.span)),
|
_ => return Err(AstError::impossible_console_assert_call(&args.span).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -411,15 +394,12 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_console(console_function_call, function)
|
self.reducer.reduce_console(console_function_call, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_expression_statement(
|
pub fn reduce_expression_statement(&mut self, expression: &ExpressionStatement) -> Result<ExpressionStatement> {
|
||||||
&mut self,
|
|
||||||
expression: &ExpressionStatement,
|
|
||||||
) -> Result<ExpressionStatement, ReducerError> {
|
|
||||||
let inner_expression = self.reduce_expression(&expression.expression)?;
|
let inner_expression = self.reduce_expression(&expression.expression)?;
|
||||||
self.reducer.reduce_expression_statement(expression, inner_expression)
|
self.reducer.reduce_expression_statement(expression, inner_expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_block(&mut self, block: &Block) -> Result<Block, ReducerError> {
|
pub fn reduce_block(&mut self, block: &Block) -> Result<Block> {
|
||||||
let mut statements = vec![];
|
let mut statements = vec![];
|
||||||
for statement in block.statements.iter() {
|
for statement in block.statements.iter() {
|
||||||
statements.push(self.reduce_statement(statement)?);
|
statements.push(self.reduce_statement(statement)?);
|
||||||
@ -429,7 +409,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Program
|
// Program
|
||||||
pub fn reduce_program(&mut self, program: &Program) -> Result<Program, ReducerError> {
|
pub fn reduce_program(&mut self, program: &Program) -> Result<Program> {
|
||||||
let mut inputs = vec![];
|
let mut inputs = vec![];
|
||||||
for input in program.expected_input.iter() {
|
for input in program.expected_input.iter() {
|
||||||
inputs.push(self.reduce_function_input(input)?);
|
inputs.push(self.reduce_function_input(input)?);
|
||||||
@ -464,14 +444,14 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_function_input_variable(
|
pub fn reduce_function_input_variable(
|
||||||
&mut self,
|
&mut self,
|
||||||
variable: &FunctionInputVariable,
|
variable: &FunctionInputVariable,
|
||||||
) -> Result<FunctionInputVariable, ReducerError> {
|
) -> Result<FunctionInputVariable> {
|
||||||
let identifier = self.reduce_identifier(&variable.identifier)?;
|
let identifier = self.reduce_identifier(&variable.identifier)?;
|
||||||
let type_ = self.reduce_type(&variable.type_, &variable.span)?;
|
let type_ = self.reduce_type(&variable.type_, &variable.span)?;
|
||||||
|
|
||||||
self.reducer.reduce_function_input_variable(variable, identifier, type_)
|
self.reducer.reduce_function_input_variable(variable, identifier, type_)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result<FunctionInput, ReducerError> {
|
pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result<FunctionInput> {
|
||||||
let new = match input {
|
let new = match input {
|
||||||
FunctionInput::Variable(function_input_variable) => {
|
FunctionInput::Variable(function_input_variable) => {
|
||||||
FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)?)
|
FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)?)
|
||||||
@ -482,10 +462,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_function_input(input, new)
|
self.reducer.reduce_function_input(input, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_package_or_packages(
|
pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> Result<PackageOrPackages> {
|
||||||
&mut self,
|
|
||||||
package_or_packages: &PackageOrPackages,
|
|
||||||
) -> Result<PackageOrPackages, ReducerError> {
|
|
||||||
let new = match package_or_packages {
|
let new = match package_or_packages {
|
||||||
PackageOrPackages::Package(package) => PackageOrPackages::Package(Package {
|
PackageOrPackages::Package(package) => PackageOrPackages::Package(Package {
|
||||||
name: self.reduce_identifier(&package.name)?,
|
name: self.reduce_identifier(&package.name)?,
|
||||||
@ -502,13 +479,13 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_package_or_packages(package_or_packages, new)
|
self.reducer.reduce_package_or_packages(package_or_packages, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_import(&mut self, import: &ImportStatement) -> Result<ImportStatement, ReducerError> {
|
pub fn reduce_import(&mut self, import: &ImportStatement) -> Result<ImportStatement> {
|
||||||
let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?;
|
let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?;
|
||||||
|
|
||||||
self.reducer.reduce_import(import, package_or_packages)
|
self.reducer.reduce_import(import, package_or_packages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result<CircuitMember, ReducerError> {
|
pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result<CircuitMember> {
|
||||||
let new = match circuit_member {
|
let new = match circuit_member {
|
||||||
CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable(
|
CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable(
|
||||||
self.reduce_identifier(identifier)?,
|
self.reduce_identifier(identifier)?,
|
||||||
@ -520,7 +497,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_circuit_member(circuit_member, new)
|
self.reducer.reduce_circuit_member(circuit_member, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result<Circuit, ReducerError> {
|
pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result<Circuit> {
|
||||||
let circuit_name = self.reduce_identifier(&circuit.circuit_name)?;
|
let circuit_name = self.reduce_identifier(&circuit.circuit_name)?;
|
||||||
|
|
||||||
let mut members = vec![];
|
let mut members = vec![];
|
||||||
@ -531,13 +508,13 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
self.reducer.reduce_circuit(circuit, circuit_name, members)
|
self.reducer.reduce_circuit(circuit, circuit_name, members)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_annotation(&mut self, annotation: &Annotation) -> Result<Annotation, ReducerError> {
|
fn reduce_annotation(&mut self, annotation: &Annotation) -> Result<Annotation> {
|
||||||
let name = self.reduce_identifier(&annotation.name)?;
|
let name = self.reduce_identifier(&annotation.name)?;
|
||||||
|
|
||||||
self.reducer.reduce_annotation(annotation, name)
|
self.reducer.reduce_annotation(annotation, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reduce_function(&mut self, function: &Function) -> Result<Function, ReducerError> {
|
pub fn reduce_function(&mut self, function: &Function) -> Result<Function> {
|
||||||
let identifier = self.reduce_identifier(&function.identifier)?;
|
let identifier = self.reduce_identifier(&function.identifier)?;
|
||||||
|
|
||||||
let mut annotations = vec![];
|
let mut annotations = vec![];
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use leo_errors::{Result, Span};
|
||||||
|
|
||||||
// Needed to fix clippy bug.
|
// Needed to fix clippy bug.
|
||||||
#[allow(clippy::redundant_closure)]
|
#[allow(clippy::redundant_closure)]
|
||||||
@ -23,23 +24,23 @@ pub trait ReconstructingReducer {
|
|||||||
fn in_circuit(&self) -> bool;
|
fn in_circuit(&self) -> bool;
|
||||||
fn swap_in_circuit(&mut self);
|
fn swap_in_circuit(&mut self);
|
||||||
|
|
||||||
fn reduce_type(&mut self, _type_: &Type, new: Type, _span: &Span) -> Result<Type, ReducerError> {
|
fn reduce_type(&mut self, _type_: &Type, new: Type, _span: &Span) -> Result<Type> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
fn reduce_expression(&mut self, _expression: &Expression, new: Expression) -> Result<Expression, ReducerError> {
|
fn reduce_expression(&mut self, _expression: &Expression, new: Expression) -> Result<Expression> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_identifier(&mut self, identifier: &Identifier) -> Result<Identifier, ReducerError> {
|
fn reduce_identifier(&mut self, identifier: &Identifier) -> Result<Identifier> {
|
||||||
Ok(Identifier {
|
Ok(Identifier {
|
||||||
name: identifier.name.clone(),
|
name: identifier.name.clone(),
|
||||||
span: identifier.span.clone(),
|
span: identifier.span.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result<GroupTuple, ReducerError> {
|
fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result<GroupTuple> {
|
||||||
Ok(GroupTuple {
|
Ok(GroupTuple {
|
||||||
x: group_tuple.x.clone(),
|
x: group_tuple.x.clone(),
|
||||||
y: group_tuple.y.clone(),
|
y: group_tuple.y.clone(),
|
||||||
@ -47,18 +48,18 @@ pub trait ReconstructingReducer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> Result<GroupValue, ReducerError> {
|
fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> Result<GroupValue> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression, ReducerError> {
|
fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression> {
|
||||||
Ok(Expression::Value(ValueExpression::String(
|
Ok(Expression::Value(ValueExpression::String(
|
||||||
string.to_vec(),
|
string.to_vec(),
|
||||||
span.clone(),
|
span.clone(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_value(&mut self, _value: &ValueExpression, new: Expression) -> Result<Expression, ReducerError> {
|
fn reduce_value(&mut self, _value: &ValueExpression, new: Expression) -> Result<Expression> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ pub trait ReconstructingReducer {
|
|||||||
left: Expression,
|
left: Expression,
|
||||||
right: Expression,
|
right: Expression,
|
||||||
op: BinaryOperation,
|
op: BinaryOperation,
|
||||||
) -> Result<BinaryExpression, ReducerError> {
|
) -> Result<BinaryExpression> {
|
||||||
Ok(BinaryExpression {
|
Ok(BinaryExpression {
|
||||||
left: Box::new(left),
|
left: Box::new(left),
|
||||||
right: Box::new(right),
|
right: Box::new(right),
|
||||||
@ -82,7 +83,7 @@ pub trait ReconstructingReducer {
|
|||||||
unary: &UnaryExpression,
|
unary: &UnaryExpression,
|
||||||
inner: Expression,
|
inner: Expression,
|
||||||
op: UnaryOperation,
|
op: UnaryOperation,
|
||||||
) -> Result<UnaryExpression, ReducerError> {
|
) -> Result<UnaryExpression> {
|
||||||
Ok(UnaryExpression {
|
Ok(UnaryExpression {
|
||||||
inner: Box::new(inner),
|
inner: Box::new(inner),
|
||||||
op,
|
op,
|
||||||
@ -96,7 +97,7 @@ pub trait ReconstructingReducer {
|
|||||||
condition: Expression,
|
condition: Expression,
|
||||||
if_true: Expression,
|
if_true: Expression,
|
||||||
if_false: Expression,
|
if_false: Expression,
|
||||||
) -> Result<TernaryExpression, ReducerError> {
|
) -> Result<TernaryExpression> {
|
||||||
Ok(TernaryExpression {
|
Ok(TernaryExpression {
|
||||||
condition: Box::new(condition),
|
condition: Box::new(condition),
|
||||||
if_true: Box::new(if_true),
|
if_true: Box::new(if_true),
|
||||||
@ -105,12 +106,7 @@ pub trait ReconstructingReducer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_cast(
|
fn reduce_cast(&mut self, cast: &CastExpression, inner: Expression, target_type: Type) -> Result<CastExpression> {
|
||||||
&mut self,
|
|
||||||
cast: &CastExpression,
|
|
||||||
inner: Expression,
|
|
||||||
target_type: Type,
|
|
||||||
) -> Result<CastExpression, ReducerError> {
|
|
||||||
Ok(CastExpression {
|
Ok(CastExpression {
|
||||||
inner: Box::new(inner),
|
inner: Box::new(inner),
|
||||||
target_type,
|
target_type,
|
||||||
@ -122,7 +118,7 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
array_inline: &ArrayInlineExpression,
|
array_inline: &ArrayInlineExpression,
|
||||||
elements: Vec<SpreadOrExpression>,
|
elements: Vec<SpreadOrExpression>,
|
||||||
) -> Result<ArrayInlineExpression, ReducerError> {
|
) -> Result<ArrayInlineExpression> {
|
||||||
Ok(ArrayInlineExpression {
|
Ok(ArrayInlineExpression {
|
||||||
elements,
|
elements,
|
||||||
span: array_inline.span.clone(),
|
span: array_inline.span.clone(),
|
||||||
@ -133,7 +129,7 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
array_init: &ArrayInitExpression,
|
array_init: &ArrayInitExpression,
|
||||||
element: Expression,
|
element: Expression,
|
||||||
) -> Result<ArrayInitExpression, ReducerError> {
|
) -> Result<ArrayInitExpression> {
|
||||||
Ok(ArrayInitExpression {
|
Ok(ArrayInitExpression {
|
||||||
element: Box::new(element),
|
element: Box::new(element),
|
||||||
dimensions: array_init.dimensions.clone(),
|
dimensions: array_init.dimensions.clone(),
|
||||||
@ -146,7 +142,7 @@ pub trait ReconstructingReducer {
|
|||||||
array_access: &ArrayAccessExpression,
|
array_access: &ArrayAccessExpression,
|
||||||
array: Expression,
|
array: Expression,
|
||||||
index: Expression,
|
index: Expression,
|
||||||
) -> Result<ArrayAccessExpression, ReducerError> {
|
) -> Result<ArrayAccessExpression> {
|
||||||
Ok(ArrayAccessExpression {
|
Ok(ArrayAccessExpression {
|
||||||
array: Box::new(array),
|
array: Box::new(array),
|
||||||
index: Box::new(index),
|
index: Box::new(index),
|
||||||
@ -160,7 +156,7 @@ pub trait ReconstructingReducer {
|
|||||||
array: Expression,
|
array: Expression,
|
||||||
left: Option<Expression>,
|
left: Option<Expression>,
|
||||||
right: Option<Expression>,
|
right: Option<Expression>,
|
||||||
) -> Result<ArrayRangeAccessExpression, ReducerError> {
|
) -> Result<ArrayRangeAccessExpression> {
|
||||||
Ok(ArrayRangeAccessExpression {
|
Ok(ArrayRangeAccessExpression {
|
||||||
array: Box::new(array),
|
array: Box::new(array),
|
||||||
left: left.map(|expr| Box::new(expr)),
|
left: left.map(|expr| Box::new(expr)),
|
||||||
@ -173,7 +169,7 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
tuple_init: &TupleInitExpression,
|
tuple_init: &TupleInitExpression,
|
||||||
elements: Vec<Expression>,
|
elements: Vec<Expression>,
|
||||||
) -> Result<TupleInitExpression, ReducerError> {
|
) -> Result<TupleInitExpression> {
|
||||||
Ok(TupleInitExpression {
|
Ok(TupleInitExpression {
|
||||||
elements,
|
elements,
|
||||||
span: tuple_init.span.clone(),
|
span: tuple_init.span.clone(),
|
||||||
@ -184,7 +180,7 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
tuple_access: &TupleAccessExpression,
|
tuple_access: &TupleAccessExpression,
|
||||||
tuple: Expression,
|
tuple: Expression,
|
||||||
) -> Result<TupleAccessExpression, ReducerError> {
|
) -> Result<TupleAccessExpression> {
|
||||||
Ok(TupleAccessExpression {
|
Ok(TupleAccessExpression {
|
||||||
tuple: Box::new(tuple),
|
tuple: Box::new(tuple),
|
||||||
index: tuple_access.index.clone(),
|
index: tuple_access.index.clone(),
|
||||||
@ -197,7 +193,7 @@ pub trait ReconstructingReducer {
|
|||||||
_variable: &CircuitImpliedVariableDefinition,
|
_variable: &CircuitImpliedVariableDefinition,
|
||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
expression: Option<Expression>,
|
expression: Option<Expression>,
|
||||||
) -> Result<CircuitImpliedVariableDefinition, ReducerError> {
|
) -> Result<CircuitImpliedVariableDefinition> {
|
||||||
Ok(CircuitImpliedVariableDefinition { identifier, expression })
|
Ok(CircuitImpliedVariableDefinition { identifier, expression })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +202,7 @@ pub trait ReconstructingReducer {
|
|||||||
circuit_init: &CircuitInitExpression,
|
circuit_init: &CircuitInitExpression,
|
||||||
name: Identifier,
|
name: Identifier,
|
||||||
members: Vec<CircuitImpliedVariableDefinition>,
|
members: Vec<CircuitImpliedVariableDefinition>,
|
||||||
) -> Result<CircuitInitExpression, ReducerError> {
|
) -> Result<CircuitInitExpression> {
|
||||||
Ok(CircuitInitExpression {
|
Ok(CircuitInitExpression {
|
||||||
name,
|
name,
|
||||||
members,
|
members,
|
||||||
@ -219,7 +215,7 @@ pub trait ReconstructingReducer {
|
|||||||
circuit_member_access: &CircuitMemberAccessExpression,
|
circuit_member_access: &CircuitMemberAccessExpression,
|
||||||
circuit: Expression,
|
circuit: Expression,
|
||||||
name: Identifier,
|
name: Identifier,
|
||||||
) -> Result<CircuitMemberAccessExpression, ReducerError> {
|
) -> Result<CircuitMemberAccessExpression> {
|
||||||
Ok(CircuitMemberAccessExpression {
|
Ok(CircuitMemberAccessExpression {
|
||||||
circuit: Box::new(circuit),
|
circuit: Box::new(circuit),
|
||||||
name,
|
name,
|
||||||
@ -232,7 +228,7 @@ pub trait ReconstructingReducer {
|
|||||||
circuit_static_fn_access: &CircuitStaticFunctionAccessExpression,
|
circuit_static_fn_access: &CircuitStaticFunctionAccessExpression,
|
||||||
circuit: Expression,
|
circuit: Expression,
|
||||||
name: Identifier,
|
name: Identifier,
|
||||||
) -> Result<CircuitStaticFunctionAccessExpression, ReducerError> {
|
) -> Result<CircuitStaticFunctionAccessExpression> {
|
||||||
Ok(CircuitStaticFunctionAccessExpression {
|
Ok(CircuitStaticFunctionAccessExpression {
|
||||||
circuit: Box::new(circuit),
|
circuit: Box::new(circuit),
|
||||||
name,
|
name,
|
||||||
@ -245,7 +241,7 @@ pub trait ReconstructingReducer {
|
|||||||
call: &CallExpression,
|
call: &CallExpression,
|
||||||
function: Expression,
|
function: Expression,
|
||||||
arguments: Vec<Expression>,
|
arguments: Vec<Expression>,
|
||||||
) -> Result<CallExpression, ReducerError> {
|
) -> Result<CallExpression> {
|
||||||
Ok(CallExpression {
|
Ok(CallExpression {
|
||||||
function: Box::new(function),
|
function: Box::new(function),
|
||||||
arguments,
|
arguments,
|
||||||
@ -254,26 +250,18 @@ pub trait ReconstructingReducer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Statements
|
// Statements
|
||||||
fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Result<Statement, ReducerError> {
|
fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Result<Statement> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_return(
|
fn reduce_return(&mut self, return_statement: &ReturnStatement, expression: Expression) -> Result<ReturnStatement> {
|
||||||
&mut self,
|
|
||||||
return_statement: &ReturnStatement,
|
|
||||||
expression: Expression,
|
|
||||||
) -> Result<ReturnStatement, ReducerError> {
|
|
||||||
Ok(ReturnStatement {
|
Ok(ReturnStatement {
|
||||||
expression,
|
expression,
|
||||||
span: return_statement.span.clone(),
|
span: return_statement.span.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_variable_name(
|
fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> Result<VariableName> {
|
||||||
&mut self,
|
|
||||||
variable_name: &VariableName,
|
|
||||||
identifier: Identifier,
|
|
||||||
) -> Result<VariableName, ReducerError> {
|
|
||||||
Ok(VariableName {
|
Ok(VariableName {
|
||||||
mutable: variable_name.mutable,
|
mutable: variable_name.mutable,
|
||||||
identifier,
|
identifier,
|
||||||
@ -287,7 +275,7 @@ pub trait ReconstructingReducer {
|
|||||||
variable_names: Vec<VariableName>,
|
variable_names: Vec<VariableName>,
|
||||||
type_: Option<Type>,
|
type_: Option<Type>,
|
||||||
value: Expression,
|
value: Expression,
|
||||||
) -> Result<DefinitionStatement, ReducerError> {
|
) -> Result<DefinitionStatement> {
|
||||||
Ok(DefinitionStatement {
|
Ok(DefinitionStatement {
|
||||||
declaration_type: definition.declaration_type.clone(),
|
declaration_type: definition.declaration_type.clone(),
|
||||||
variable_names,
|
variable_names,
|
||||||
@ -297,11 +285,7 @@ pub trait ReconstructingReducer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_assignee_access(
|
fn reduce_assignee_access(&mut self, _access: &AssigneeAccess, new: AssigneeAccess) -> Result<AssigneeAccess> {
|
||||||
&mut self,
|
|
||||||
_access: &AssigneeAccess,
|
|
||||||
new: AssigneeAccess,
|
|
||||||
) -> Result<AssigneeAccess, ReducerError> {
|
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +294,7 @@ pub trait ReconstructingReducer {
|
|||||||
assignee: &Assignee,
|
assignee: &Assignee,
|
||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
accesses: Vec<AssigneeAccess>,
|
accesses: Vec<AssigneeAccess>,
|
||||||
) -> Result<Assignee, ReducerError> {
|
) -> Result<Assignee> {
|
||||||
Ok(Assignee {
|
Ok(Assignee {
|
||||||
identifier,
|
identifier,
|
||||||
accesses,
|
accesses,
|
||||||
@ -323,7 +307,7 @@ pub trait ReconstructingReducer {
|
|||||||
assign: &AssignStatement,
|
assign: &AssignStatement,
|
||||||
assignee: Assignee,
|
assignee: Assignee,
|
||||||
value: Expression,
|
value: Expression,
|
||||||
) -> Result<AssignStatement, ReducerError> {
|
) -> Result<AssignStatement> {
|
||||||
Ok(AssignStatement {
|
Ok(AssignStatement {
|
||||||
operation: assign.operation,
|
operation: assign.operation,
|
||||||
assignee,
|
assignee,
|
||||||
@ -338,7 +322,7 @@ pub trait ReconstructingReducer {
|
|||||||
condition: Expression,
|
condition: Expression,
|
||||||
block: Block,
|
block: Block,
|
||||||
statement: Option<Statement>,
|
statement: Option<Statement>,
|
||||||
) -> Result<ConditionalStatement, ReducerError> {
|
) -> Result<ConditionalStatement> {
|
||||||
Ok(ConditionalStatement {
|
Ok(ConditionalStatement {
|
||||||
condition,
|
condition,
|
||||||
block,
|
block,
|
||||||
@ -354,7 +338,7 @@ pub trait ReconstructingReducer {
|
|||||||
start: Expression,
|
start: Expression,
|
||||||
stop: Expression,
|
stop: Expression,
|
||||||
block: Block,
|
block: Block,
|
||||||
) -> Result<IterationStatement, ReducerError> {
|
) -> Result<IterationStatement> {
|
||||||
Ok(IterationStatement {
|
Ok(IterationStatement {
|
||||||
variable,
|
variable,
|
||||||
start,
|
start,
|
||||||
@ -365,11 +349,7 @@ pub trait ReconstructingReducer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_console(
|
fn reduce_console(&mut self, console: &ConsoleStatement, function: ConsoleFunction) -> Result<ConsoleStatement> {
|
||||||
&mut self,
|
|
||||||
console: &ConsoleStatement,
|
|
||||||
function: ConsoleFunction,
|
|
||||||
) -> Result<ConsoleStatement, ReducerError> {
|
|
||||||
Ok(ConsoleStatement {
|
Ok(ConsoleStatement {
|
||||||
function,
|
function,
|
||||||
span: console.span.clone(),
|
span: console.span.clone(),
|
||||||
@ -380,14 +360,14 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
expression_statement: &ExpressionStatement,
|
expression_statement: &ExpressionStatement,
|
||||||
expression: Expression,
|
expression: Expression,
|
||||||
) -> Result<ExpressionStatement, ReducerError> {
|
) -> Result<ExpressionStatement> {
|
||||||
Ok(ExpressionStatement {
|
Ok(ExpressionStatement {
|
||||||
expression,
|
expression,
|
||||||
span: expression_statement.span.clone(),
|
span: expression_statement.span.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_block(&mut self, block: &Block, statements: Vec<Statement>) -> Result<Block, ReducerError> {
|
fn reduce_block(&mut self, block: &Block, statements: Vec<Statement>) -> Result<Block> {
|
||||||
Ok(Block {
|
Ok(Block {
|
||||||
statements,
|
statements,
|
||||||
span: block.span.clone(),
|
span: block.span.clone(),
|
||||||
@ -403,7 +383,7 @@ pub trait ReconstructingReducer {
|
|||||||
circuits: IndexMap<Identifier, Circuit>,
|
circuits: IndexMap<Identifier, Circuit>,
|
||||||
functions: IndexMap<Identifier, Function>,
|
functions: IndexMap<Identifier, Function>,
|
||||||
global_consts: IndexMap<String, DefinitionStatement>,
|
global_consts: IndexMap<String, DefinitionStatement>,
|
||||||
) -> Result<Program, ReducerError> {
|
) -> Result<Program> {
|
||||||
Ok(Program {
|
Ok(Program {
|
||||||
name: program.name.clone(),
|
name: program.name.clone(),
|
||||||
expected_input,
|
expected_input,
|
||||||
@ -419,7 +399,7 @@ pub trait ReconstructingReducer {
|
|||||||
variable: &FunctionInputVariable,
|
variable: &FunctionInputVariable,
|
||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
type_: Type,
|
type_: Type,
|
||||||
) -> Result<FunctionInputVariable, ReducerError> {
|
) -> Result<FunctionInputVariable> {
|
||||||
Ok(FunctionInputVariable {
|
Ok(FunctionInputVariable {
|
||||||
identifier,
|
identifier,
|
||||||
const_: variable.const_,
|
const_: variable.const_,
|
||||||
@ -429,11 +409,7 @@ pub trait ReconstructingReducer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_function_input(
|
fn reduce_function_input(&mut self, _input: &FunctionInput, new: FunctionInput) -> Result<FunctionInput> {
|
||||||
&mut self,
|
|
||||||
_input: &FunctionInput,
|
|
||||||
new: FunctionInput,
|
|
||||||
) -> Result<FunctionInput, ReducerError> {
|
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,7 +417,7 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
_package_or_packages: &PackageOrPackages,
|
_package_or_packages: &PackageOrPackages,
|
||||||
new: PackageOrPackages,
|
new: PackageOrPackages,
|
||||||
) -> Result<PackageOrPackages, ReducerError> {
|
) -> Result<PackageOrPackages> {
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,18 +425,14 @@ pub trait ReconstructingReducer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
import: &ImportStatement,
|
import: &ImportStatement,
|
||||||
package_or_packages: PackageOrPackages,
|
package_or_packages: PackageOrPackages,
|
||||||
) -> Result<ImportStatement, ReducerError> {
|
) -> Result<ImportStatement> {
|
||||||
Ok(ImportStatement {
|
Ok(ImportStatement {
|
||||||
package_or_packages,
|
package_or_packages,
|
||||||
span: import.span.clone(),
|
span: import.span.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_circuit_member(
|
fn reduce_circuit_member(&mut self, _circuit_member: &CircuitMember, new: CircuitMember) -> Result<CircuitMember> {
|
||||||
&mut self,
|
|
||||||
_circuit_member: &CircuitMember,
|
|
||||||
new: CircuitMember,
|
|
||||||
) -> Result<CircuitMember, ReducerError> {
|
|
||||||
Ok(new)
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,11 +441,11 @@ pub trait ReconstructingReducer {
|
|||||||
_circuit: &Circuit,
|
_circuit: &Circuit,
|
||||||
circuit_name: Identifier,
|
circuit_name: Identifier,
|
||||||
members: Vec<CircuitMember>,
|
members: Vec<CircuitMember>,
|
||||||
) -> Result<Circuit, ReducerError> {
|
) -> Result<Circuit> {
|
||||||
Ok(Circuit { circuit_name, members })
|
Ok(Circuit { circuit_name, members })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Result<Annotation, ReducerError> {
|
fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Result<Annotation> {
|
||||||
Ok(Annotation {
|
Ok(Annotation {
|
||||||
span: annotation.span.clone(),
|
span: annotation.span.clone(),
|
||||||
name,
|
name,
|
||||||
@ -490,7 +462,7 @@ pub trait ReconstructingReducer {
|
|||||||
input: Vec<FunctionInput>,
|
input: Vec<FunctionInput>,
|
||||||
output: Option<Type>,
|
output: Option<Type>,
|
||||||
block: Block,
|
block: Block,
|
||||||
) -> Result<Function, ReducerError> {
|
) -> Result<Function> {
|
||||||
Ok(Function {
|
Ok(Function {
|
||||||
identifier,
|
identifier,
|
||||||
annotations,
|
annotations,
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Expression, Identifier, PositiveNumber, Span};
|
use crate::{Expression, Identifier, PositiveNumber};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Expression, Node, Span};
|
use crate::{Expression, Node};
|
||||||
|
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Node, Span, Statement};
|
use crate::{Node, Statement};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Block, Expression, Node, Span, Statement};
|
use crate::{Block, Expression, Node, Statement};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Char, Expression, Node, Span};
|
use crate::{Char, Expression, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ConsoleArgs, Expression, Node, Span};
|
use crate::{ConsoleArgs, Expression, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ConsoleFunction, Node, Span};
|
use crate::{ConsoleFunction, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Expression, Node, Span, Type};
|
use crate::{Expression, Node, Type};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Identifier, Node, Span};
|
use crate::{Identifier, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Expression, Node, Span};
|
use crate::{Expression, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Block, Expression, Identifier, Node, Span};
|
use crate::{Block, Expression, Identifier, Node};
|
||||||
|
use leo_errors::Span;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user