mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
Merge branch 'feature/abnf-grammar' into feature/abnf-grammar-converter
This commit is contained in:
commit
9403dd45d1
114
Cargo.lock
generated
114
Cargo.lock
generated
@ -32,9 +32,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
checksum = "bedc89c5c7b5550ffb9372eb5c5ffc7f9f705cc3f4a128bd4669b9745f555093"
|
||||
|
||||
[[package]]
|
||||
name = "adler32"
|
||||
@ -219,7 +219,7 @@ dependencies = [
|
||||
"block-padding",
|
||||
"byte-tools",
|
||||
"byteorder",
|
||||
"generic-array 0.12.4",
|
||||
"generic-array 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -608,7 +608,7 @@ version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
|
||||
dependencies = [
|
||||
"generic-array 0.12.4",
|
||||
"generic-array 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -819,10 +819,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "1.1.0"
|
||||
name = "futf"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
||||
checksum = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
|
||||
dependencies = [
|
||||
"mac",
|
||||
"new_debug_unreachable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
@ -883,9 +887,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.12.4"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
|
||||
checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
@ -945,9 +949,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.1"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78"
|
||||
checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@ -960,6 +964,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"tracing-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1199,9 +1204,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.48"
|
||||
version = "0.3.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78"
|
||||
checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
@ -1247,6 +1252,7 @@ dependencies = [
|
||||
"num-bigint",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tendril",
|
||||
"thiserror",
|
||||
"typed-arena",
|
||||
]
|
||||
@ -1262,12 +1268,14 @@ dependencies = [
|
||||
name = "leo-ast"
|
||||
version = "1.2.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"criterion",
|
||||
"indexmap",
|
||||
"leo-input",
|
||||
"pest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tendril",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@ -1394,6 +1402,7 @@ dependencies = [
|
||||
"leo-ast",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tendril",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
]
|
||||
@ -1500,6 +1509,12 @@ dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
@ -1666,6 +1681,12 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
||||
|
||||
[[package]]
|
||||
name = "nias"
|
||||
version = "0.5.0"
|
||||
@ -1946,9 +1967,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.6"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
|
||||
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
@ -2459,9 +2480,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.64"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||
checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@ -2846,6 +2867,17 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tendril"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9ef557cb397a4f0a5a3a628f06515f78563f2209e64d47055d9dc6052bf5e33"
|
||||
dependencies = [
|
||||
"futf",
|
||||
"mac",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
@ -3024,6 +3056,16 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-futures"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
|
||||
dependencies = [
|
||||
"pin-project",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.2"
|
||||
@ -3154,6 +3196,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf-8"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.11"
|
||||
@ -3213,9 +3261,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.71"
|
||||
version = "0.2.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7"
|
||||
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"serde",
|
||||
@ -3225,9 +3273,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.71"
|
||||
version = "0.2.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8"
|
||||
checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
@ -3240,9 +3288,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.21"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab"
|
||||
checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"js-sys",
|
||||
@ -3252,9 +3300,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.71"
|
||||
version = "0.2.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b"
|
||||
checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c"
|
||||
dependencies = [
|
||||
"quote 1.0.9",
|
||||
"wasm-bindgen-macro-support",
|
||||
@ -3262,9 +3310,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.71"
|
||||
version = "0.2.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e"
|
||||
checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.9",
|
||||
@ -3275,15 +3323,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.71"
|
||||
version = "0.2.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1"
|
||||
checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.48"
|
||||
version = "0.3.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b"
|
||||
checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@ -3368,9 +3416,9 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "0.5.11"
|
||||
version = "0.5.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8264fcea9b7a036a4a5103d7153e988dbc2ebbafb34f68a3c2d404b6b82d74b6"
|
||||
checksum = "5a8977234acab718eb2820494b2f96cbb16004c19dddf88b7445b27381450997"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"bzip2",
|
||||
|
@ -43,5 +43,8 @@ version = "0.4"
|
||||
[dependencies.typed-arena]
|
||||
version = "2.0"
|
||||
|
||||
[dependencies.tendril]
|
||||
version = "0.4"
|
||||
|
||||
[dev-dependencies.criterion]
|
||||
version = "0.3"
|
||||
|
@ -18,6 +18,7 @@ use crate::{AsgConvertError, IntegerType, Span, Type};
|
||||
|
||||
use num_bigint::BigInt;
|
||||
use std::{convert::TryInto, fmt};
|
||||
use tendril::StrTendril;
|
||||
|
||||
/// Constant integer values in a program.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@ -38,7 +39,7 @@ pub enum ConstInt {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum GroupCoordinate {
|
||||
/// Explicit field element number string.
|
||||
Number(String),
|
||||
Number(StrTendril),
|
||||
|
||||
/// Attempt to recover with a sign high bit.
|
||||
SignHigh,
|
||||
@ -87,7 +88,7 @@ impl Into<leo_ast::GroupCoordinate> for &GroupCoordinate {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum GroupValue {
|
||||
Single(String),
|
||||
Single(StrTendril),
|
||||
Tuple(GroupCoordinate, GroupCoordinate),
|
||||
}
|
||||
|
||||
@ -106,7 +107,7 @@ pub enum ConstValue {
|
||||
Int(ConstInt),
|
||||
Group(GroupValue),
|
||||
Field(BigInt),
|
||||
Address(String),
|
||||
Address(StrTendril),
|
||||
Boolean(bool),
|
||||
|
||||
// compounds
|
||||
|
@ -35,25 +35,7 @@ pub enum AsgConvertError {
|
||||
SyntaxError(#[from] SyntaxError),
|
||||
}
|
||||
|
||||
impl LeoError for AsgConvertError {
|
||||
fn get_path(&self) -> Option<&str> {
|
||||
match self {
|
||||
AsgConvertError::Error(error) => error.get_path(),
|
||||
AsgConvertError::SyntaxError(error) => error.get_path(),
|
||||
AsgConvertError::ImportError(error) => error.get_path(),
|
||||
AsgConvertError::InternalError(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_path(&mut self, path: &str, contents: &[String]) {
|
||||
match self {
|
||||
AsgConvertError::Error(error) => error.set_path(path, contents),
|
||||
AsgConvertError::SyntaxError(error) => error.set_path(path, contents),
|
||||
AsgConvertError::ImportError(error) => error.set_path(path, contents),
|
||||
AsgConvertError::InternalError(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl LeoError for AsgConvertError {}
|
||||
|
||||
impl AsgConvertError {
|
||||
fn new_from_span(message: String, span: &Span) -> Self {
|
||||
|
@ -152,7 +152,7 @@ impl<'a> Into<leo_ast::ArrayInitExpression> for &ArrayInitExpression<'a> {
|
||||
leo_ast::ArrayInitExpression {
|
||||
element: Box::new(self.element.get().into()),
|
||||
dimensions: leo_ast::ArrayDimensions(vec![leo_ast::PositiveNumber {
|
||||
value: self.len.to_string(),
|
||||
value: self.len.to_string().into(),
|
||||
}]),
|
||||
span: self.span.clone().unwrap_or_default(),
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
||||
let circuit_name = circuit.name.borrow().name.clone();
|
||||
let member = circuit.members.borrow();
|
||||
let member = member
|
||||
.get(&name.name)
|
||||
.get(name.name.as_ref())
|
||||
.ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
||||
match member {
|
||||
CircuitMember::Function(body) => {
|
||||
@ -156,7 +156,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
|
||||
|
||||
let member = circuit.members.borrow();
|
||||
let member = member
|
||||
.get(&name.name)
|
||||
.get(name.name.as_ref())
|
||||
.ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
|
||||
match member {
|
||||
CircuitMember::Function(body) => {
|
||||
|
@ -67,7 +67,7 @@ impl<'a> ExpressionNode<'a> for CircuitAccessExpression<'a> {
|
||||
None // function target only for static
|
||||
} else {
|
||||
let members = self.circuit.get().members.borrow();
|
||||
let member = members.get(&self.member.name)?;
|
||||
let member = members.get(self.member.name.as_ref())?;
|
||||
match member {
|
||||
CircuitMember::Variable(type_) => Some(type_.clone()),
|
||||
CircuitMember::Function(_) => None,
|
||||
@ -112,7 +112,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
|
||||
|
||||
// scoping refcell reference
|
||||
let found_member = {
|
||||
if let Some(member) = circuit.members.borrow().get(&value.name.name) {
|
||||
if let Some(member) = circuit.members.borrow().get(value.name.name.as_ref()) {
|
||||
if let Some(expected_type) = &expected_type {
|
||||
if let CircuitMember::Variable(type_) = &member {
|
||||
let type_: Type = type_.clone();
|
||||
@ -136,10 +136,10 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
|
||||
} else if circuit.is_input_pseudo_circuit() {
|
||||
// add new member to implicit input
|
||||
if let Some(expected_type) = expected_type.map(PartialType::full).flatten() {
|
||||
circuit
|
||||
.members
|
||||
.borrow_mut()
|
||||
.insert(value.name.name.clone(), CircuitMember::Variable(expected_type.clone()));
|
||||
circuit.members.borrow_mut().insert(
|
||||
value.name.name.to_string(),
|
||||
CircuitMember::Variable(expected_type.clone()),
|
||||
);
|
||||
} else {
|
||||
return Err(AsgConvertError::input_ref_needs_type(
|
||||
&circuit.name.borrow().name,
|
||||
@ -192,7 +192,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(&value.name.name) {
|
||||
if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) {
|
||||
// okay
|
||||
} else {
|
||||
return Err(AsgConvertError::unresolved_circuit_member(
|
||||
|
@ -99,10 +99,10 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
|
||||
));
|
||||
}
|
||||
}
|
||||
let members: IndexMap<&String, (&Identifier, Option<&leo_ast::Expression>)> = value
|
||||
let members: IndexMap<&str, (&Identifier, Option<&leo_ast::Expression>)> = value
|
||||
.members
|
||||
.iter()
|
||||
.map(|x| (&x.identifier.name, (&x.identifier, x.expression.as_ref())))
|
||||
.map(|x| (x.identifier.name.as_ref(), (&x.identifier, x.expression.as_ref())))
|
||||
.collect();
|
||||
|
||||
let mut values: Vec<(Identifier, Cell<&'a Expression<'a>>)> = vec![];
|
||||
@ -124,7 +124,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
if let Some((identifier, receiver)) = members.get(&name) {
|
||||
if let Some((identifier, receiver)) = members.get(&**name) {
|
||||
let received = if let Some(receiver) = *receiver {
|
||||
<&Expression<'a>>::from_ast(scope, receiver, Some(type_.partial()))?
|
||||
} else {
|
||||
|
@ -174,12 +174,12 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
||||
Some(PartialType::Type(Type::Group)) => Constant {
|
||||
parent: Cell::new(None),
|
||||
span: Some(span.clone()),
|
||||
value: ConstValue::Group(GroupValue::Single(value.to_string())),
|
||||
value: ConstValue::Group(GroupValue::Single(value.clone())),
|
||||
},
|
||||
Some(PartialType::Type(Type::Address)) => Constant {
|
||||
parent: Cell::new(None),
|
||||
span: Some(span.clone()),
|
||||
value: ConstValue::Address(value.to_string()),
|
||||
value: ConstValue::Address(value.clone()),
|
||||
},
|
||||
Some(x) => return Err(AsgConvertError::unexpected_type(&x.to_string(), Some("unknown"), span)),
|
||||
},
|
||||
@ -213,10 +213,10 @@ impl<'a> Into<leo_ast::ValueExpression> for &Constant<'a> {
|
||||
leo_ast::ValueExpression::Address(value.clone(), self.span.clone().unwrap_or_default())
|
||||
}
|
||||
ConstValue::Boolean(value) => {
|
||||
leo_ast::ValueExpression::Boolean(value.to_string(), self.span.clone().unwrap_or_default())
|
||||
leo_ast::ValueExpression::Boolean(value.to_string().into(), self.span.clone().unwrap_or_default())
|
||||
}
|
||||
ConstValue::Field(value) => {
|
||||
leo_ast::ValueExpression::Field(value.to_string(), self.span.clone().unwrap_or_default())
|
||||
leo_ast::ValueExpression::Field(value.to_string().into(), self.span.clone().unwrap_or_default())
|
||||
}
|
||||
ConstValue::Group(value) => leo_ast::ValueExpression::Group(Box::new(match value {
|
||||
GroupValue::Single(single) => {
|
||||
@ -230,7 +230,7 @@ impl<'a> Into<leo_ast::ValueExpression> for &Constant<'a> {
|
||||
})),
|
||||
ConstValue::Int(int) => leo_ast::ValueExpression::Integer(
|
||||
int.get_int_type(),
|
||||
int.raw_value(),
|
||||
int.raw_value().into(),
|
||||
self.span.clone().unwrap_or_default(),
|
||||
),
|
||||
ConstValue::Tuple(_) => unimplemented!(),
|
||||
|
@ -109,7 +109,7 @@ impl<'a> Into<leo_ast::TupleAccessExpression> for &TupleAccessExpression<'a> {
|
||||
leo_ast::TupleAccessExpression {
|
||||
tuple: Box::new(self.tuple_ref.get().into()),
|
||||
index: leo_ast::PositiveNumber {
|
||||
value: self.index.to_string(),
|
||||
value: self.index.to_string().into(),
|
||||
},
|
||||
span: self.span.clone().unwrap_or_default(),
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
|
||||
value: &leo_ast::Identifier,
|
||||
expected_type: Option<PartialType<'a>>,
|
||||
) -> Result<&'a Expression<'a>, AsgConvertError> {
|
||||
let variable = if value.name == "input" {
|
||||
let variable = if value.name.as_ref() == "input" {
|
||||
if let Some(function) = scope.resolve_current_function() {
|
||||
if !function.has_input {
|
||||
return Err(AsgConvertError::unresolved_reference(&value.name, &value.span));
|
||||
|
@ -40,7 +40,7 @@ impl<'a> Input<'a> {
|
||||
fn make_header(scope: &'a Scope<'a>, name: &str) -> &'a Circuit<'a> {
|
||||
scope.context.alloc_circuit(Circuit {
|
||||
id: scope.context.get_id(),
|
||||
name: RefCell::new(Identifier::new(name.to_string())),
|
||||
name: RefCell::new(Identifier::new(name.into())),
|
||||
members: RefCell::new(IndexMap::new()),
|
||||
core_mapping: RefCell::new(None),
|
||||
scope,
|
||||
@ -69,7 +69,7 @@ impl<'a> Input<'a> {
|
||||
|
||||
let container_circuit = input_scope.context.alloc_circuit(Circuit {
|
||||
id: scope.context.get_id(),
|
||||
name: RefCell::new(Identifier::new(CONTAINER_PSEUDO_CIRCUIT.to_string())),
|
||||
name: RefCell::new(Identifier::new(CONTAINER_PSEUDO_CIRCUIT.into())),
|
||||
members: RefCell::new(container_members),
|
||||
core_mapping: RefCell::new(None),
|
||||
scope: input_scope,
|
||||
@ -84,7 +84,7 @@ impl<'a> Input<'a> {
|
||||
container_circuit,
|
||||
container: input_scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||
id: scope.context.get_id(),
|
||||
name: Identifier::new("input".to_string()),
|
||||
name: Identifier::new("input".into()),
|
||||
type_: Type::Circuit(container_circuit),
|
||||
mutable: false,
|
||||
const_: false,
|
||||
|
@ -22,6 +22,9 @@
|
||||
//! A new [`Asg`] type can be created from an [`Ast`].
|
||||
//! Converting to an [`Asg`] provides greater type safety by canonicalizing and checking program types.
|
||||
|
||||
#![allow(clippy::from_over_into)]
|
||||
#![allow(clippy::result_unit_err)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate thiserror;
|
||||
|
||||
|
@ -68,35 +68,53 @@ impl<'a> Circuit<'a> {
|
||||
|
||||
let mut members = circuit.members.borrow_mut();
|
||||
for member in value.members.iter() {
|
||||
match member {
|
||||
leo_ast::CircuitMember::CircuitVariable(name, type_) => {
|
||||
if members.contains_key(&name.name) {
|
||||
return Err(AsgConvertError::redefined_circuit_member(
|
||||
&value.circuit_name.name,
|
||||
&name.name,
|
||||
&name.span,
|
||||
));
|
||||
}
|
||||
members.insert(
|
||||
name.name.clone(),
|
||||
CircuitMember::Variable(new_scope.resolve_ast_type(type_)?),
|
||||
);
|
||||
if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member {
|
||||
if members.contains_key(name.name.as_ref()) {
|
||||
return Err(AsgConvertError::redefined_circuit_member(
|
||||
&value.circuit_name.name,
|
||||
&name.name,
|
||||
&name.span,
|
||||
));
|
||||
}
|
||||
leo_ast::CircuitMember::CircuitFunction(function) => {
|
||||
if members.contains_key(&function.identifier.name) {
|
||||
return Err(AsgConvertError::redefined_circuit_member(
|
||||
&value.circuit_name.name,
|
||||
&function.identifier.name,
|
||||
&function.identifier.span,
|
||||
));
|
||||
}
|
||||
let asg_function = Function::init(new_scope, function)?;
|
||||
asg_function.circuit.replace(Some(circuit));
|
||||
if asg_function.is_test() {
|
||||
return Err(AsgConvertError::circuit_test_function(&function.identifier.span));
|
||||
}
|
||||
members.insert(function.identifier.name.clone(), CircuitMember::Function(asg_function));
|
||||
members.insert(
|
||||
name.name.to_string(),
|
||||
CircuitMember::Variable(new_scope.resolve_ast_type(type_)?),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(circuit)
|
||||
}
|
||||
|
||||
pub(super) fn init_member(
|
||||
scope: &'a Scope<'a>,
|
||||
value: &leo_ast::Circuit,
|
||||
) -> Result<&'a Circuit<'a>, AsgConvertError> {
|
||||
let new_scope = scope.make_subscope();
|
||||
let circuits = scope.circuits.borrow();
|
||||
|
||||
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();
|
||||
for member in value.members.iter() {
|
||||
if let leo_ast::CircuitMember::CircuitFunction(function) = member {
|
||||
if members.contains_key(function.identifier.name.as_ref()) {
|
||||
return Err(AsgConvertError::redefined_circuit_member(
|
||||
&value.circuit_name.name,
|
||||
&function.identifier.name,
|
||||
&function.identifier.span,
|
||||
));
|
||||
}
|
||||
let asg_function = Function::init(new_scope, function)?;
|
||||
asg_function.circuit.replace(Some(circuit));
|
||||
if asg_function.is_test() {
|
||||
return Err(AsgConvertError::circuit_test_function(&function.identifier.span));
|
||||
}
|
||||
members.insert(
|
||||
function.identifier.name.to_string(),
|
||||
CircuitMember::Function(asg_function),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +129,7 @@ impl<'a> Circuit<'a> {
|
||||
let asg_function = match *self
|
||||
.members
|
||||
.borrow()
|
||||
.get(&function.identifier.name)
|
||||
.get(function.identifier.name.as_ref())
|
||||
.expect("missing header for defined circuit function")
|
||||
{
|
||||
CircuitMember::Function(f) => f,
|
||||
@ -133,7 +151,7 @@ impl<'a> Into<leo_ast::Circuit> for &Circuit<'a> {
|
||||
.iter()
|
||||
.map(|(name, member)| match &member {
|
||||
CircuitMember::Variable(type_) => {
|
||||
leo_ast::CircuitMember::CircuitVariable(Identifier::new(name.clone()), type_.into())
|
||||
leo_ast::CircuitMember::CircuitVariable(Identifier::new((&**name).into()), type_.into())
|
||||
}
|
||||
CircuitMember::Function(func) => leo_ast::CircuitMember::CircuitFunction((*func).into()),
|
||||
})
|
||||
|
@ -37,6 +37,7 @@ use std::cell::{Cell, RefCell};
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum FunctionQualifier {
|
||||
SelfRef,
|
||||
ConstSelfRef,
|
||||
MutSelfRef,
|
||||
Static,
|
||||
}
|
||||
@ -89,6 +90,9 @@ impl<'a> Function<'a> {
|
||||
FunctionInput::SelfKeyword(_) => {
|
||||
qualifier = FunctionQualifier::SelfRef;
|
||||
}
|
||||
FunctionInput::ConstSelfKeyword(_) => {
|
||||
qualifier = FunctionQualifier::ConstSelfRef;
|
||||
}
|
||||
FunctionInput::MutSelfKeyword(_) => {
|
||||
qualifier = FunctionQualifier::MutSelfRef;
|
||||
}
|
||||
@ -109,7 +113,7 @@ impl<'a> Function<'a> {
|
||||
references: vec![],
|
||||
assignments: vec![],
|
||||
}));
|
||||
arguments.insert(identifier.name.clone(), Cell::new(&*variable));
|
||||
arguments.insert(identifier.name.to_string(), Cell::new(&*variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,7 +144,7 @@ impl<'a> Function<'a> {
|
||||
let circuit = self.circuit.get();
|
||||
let self_variable = self.scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||
id: self.scope.context.get_id(),
|
||||
name: Identifier::new("self".to_string()),
|
||||
name: Identifier::new("self".into()),
|
||||
type_: Type::Circuit(circuit.as_ref().unwrap()),
|
||||
mutable: self.qualifier == FunctionQualifier::MutSelfRef,
|
||||
const_: false,
|
||||
@ -182,7 +186,7 @@ impl<'a> Function<'a> {
|
||||
}
|
||||
|
||||
pub fn is_test(&self) -> bool {
|
||||
self.annotations.iter().any(|x| x.name.name == "test")
|
||||
self.annotations.iter().any(|x| x.name.name.as_ref() == "test")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,11 +75,11 @@ fn resolve_import_package(
|
||||
) {
|
||||
match package_or_packages {
|
||||
PackageOrPackages::Package(package) => {
|
||||
package_segments.push(package.name.name.clone());
|
||||
package_segments.push(package.name.name.to_string());
|
||||
resolve_import_package_access(output, package_segments, &package.access);
|
||||
}
|
||||
PackageOrPackages::Packages(packages) => {
|
||||
package_segments.push(packages.name.name.clone());
|
||||
package_segments.push(packages.name.name.to_string());
|
||||
for access in packages.accesses.clone() {
|
||||
resolve_import_package_access(output, package_segments.clone(), &access);
|
||||
}
|
||||
@ -106,14 +106,14 @@ fn resolve_import_package_access(
|
||||
PackageAccess::Symbol(symbol) => {
|
||||
let span = symbol.symbol.span.clone();
|
||||
let symbol = if let Some(alias) = symbol.alias.as_ref() {
|
||||
ImportSymbol::Alias(symbol.symbol.name.clone(), alias.name.clone())
|
||||
ImportSymbol::Alias(symbol.symbol.name.to_string(), alias.name.to_string())
|
||||
} else {
|
||||
ImportSymbol::Direct(symbol.symbol.name.clone())
|
||||
ImportSymbol::Direct(symbol.symbol.name.to_string())
|
||||
};
|
||||
output.push((package_segments, symbol, span));
|
||||
}
|
||||
PackageAccess::Multiple(packages) => {
|
||||
package_segments.push(packages.name.name.clone());
|
||||
package_segments.push(packages.name.name.to_string());
|
||||
for subaccess in packages.accesses.iter() {
|
||||
resolve_import_package_access(output, package_segments.clone(), &subaccess);
|
||||
}
|
||||
@ -240,35 +240,43 @@ impl<'a> Program<'a> {
|
||||
assert_eq!(name.name, circuit.circuit_name.name);
|
||||
let asg_circuit = Circuit::init(scope, circuit)?;
|
||||
|
||||
scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit);
|
||||
scope.circuits.borrow_mut().insert(name.name.to_string(), asg_circuit);
|
||||
}
|
||||
|
||||
// Second pass for circuit members.
|
||||
for (name, circuit) in program.circuits.iter() {
|
||||
assert_eq!(name.name, circuit.circuit_name.name);
|
||||
let asg_circuit = Circuit::init_member(scope, circuit)?;
|
||||
|
||||
scope.circuits.borrow_mut().insert(name.name.to_string(), asg_circuit);
|
||||
}
|
||||
|
||||
for (name, function) in program.functions.iter() {
|
||||
assert_eq!(name.name, function.identifier.name);
|
||||
let function = Function::init(scope, function)?;
|
||||
|
||||
scope.functions.borrow_mut().insert(name.name.clone(), function);
|
||||
scope.functions.borrow_mut().insert(name.name.to_string(), function);
|
||||
}
|
||||
|
||||
// Load concrete definitions.
|
||||
let mut functions = IndexMap::new();
|
||||
for (name, function) in program.functions.iter() {
|
||||
assert_eq!(name.name, function.identifier.name);
|
||||
let asg_function = *scope.functions.borrow().get(&name.name).unwrap();
|
||||
let asg_function = *scope.functions.borrow().get(name.name.as_ref()).unwrap();
|
||||
|
||||
asg_function.fill_from_ast(function)?;
|
||||
|
||||
functions.insert(name.name.clone(), asg_function);
|
||||
functions.insert(name.name.to_string(), asg_function);
|
||||
}
|
||||
|
||||
let mut circuits = IndexMap::new();
|
||||
for (name, circuit) in program.circuits.iter() {
|
||||
assert_eq!(name.name, circuit.circuit_name.name);
|
||||
let asg_circuit = *scope.circuits.borrow().get(&name.name).unwrap();
|
||||
let asg_circuit = *scope.circuits.borrow().get(name.name.as_ref()).unwrap();
|
||||
|
||||
asg_circuit.fill_from_ast(circuit)?;
|
||||
|
||||
circuits.insert(name.name.clone(), asg_circuit);
|
||||
circuits.insert(name.name.to_string(), asg_circuit);
|
||||
}
|
||||
|
||||
Ok(Program {
|
||||
@ -330,7 +338,7 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program {
|
||||
for (_, program) in all_programs.into_iter() {
|
||||
for (name, circuit) in program.circuits.iter() {
|
||||
let identifier = format!("{}{}", identifiers.next().unwrap(), name);
|
||||
circuit.name.borrow_mut().name = identifier.clone();
|
||||
circuit.name.borrow_mut().name = identifier.clone().into();
|
||||
all_circuits.insert(identifier, *circuit);
|
||||
}
|
||||
for (name, function) in program.functions.iter() {
|
||||
@ -339,7 +347,7 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program {
|
||||
} else {
|
||||
format!("{}{}", identifiers.next().unwrap(), name)
|
||||
};
|
||||
function.name.borrow_mut().name = identifier.clone();
|
||||
function.name.borrow_mut().name = identifier.clone().into();
|
||||
all_functions.insert(identifier, *function);
|
||||
}
|
||||
}
|
||||
@ -350,7 +358,7 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program {
|
||||
.iter()
|
||||
.map(|(module, _)| leo_ast::ImportStatement {
|
||||
package_or_packages: leo_ast::PackageOrPackages::Package(leo_ast::Package {
|
||||
name: Identifier::new(module.clone()),
|
||||
name: Identifier::new(module.clone().into()),
|
||||
access: leo_ast::PackageAccess::Star(Span::default()),
|
||||
span: Default::default(),
|
||||
}),
|
||||
|
@ -194,7 +194,7 @@ impl<'a> Scope<'a> {
|
||||
.map(|x| self.resolve_ast_type(x))
|
||||
.collect::<Result<Vec<_>, AsgConvertError>>()?,
|
||||
),
|
||||
Circuit(name) if name.name == "Self" => Type::Circuit(
|
||||
Circuit(name) if name.name.as_ref() == "Self" => Type::Circuit(
|
||||
self.resolve_circuit_self()
|
||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
||||
),
|
||||
|
@ -69,7 +69,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
) -> Result<Self, AsgConvertError> {
|
||||
let (name, span) = (&statement.assignee.identifier.name, &statement.assignee.identifier.span);
|
||||
|
||||
let variable = if name == "input" {
|
||||
let variable = if name.as_ref() == "input" {
|
||||
if let Some(function) = scope.resolve_current_function() {
|
||||
if !function.has_input {
|
||||
return Err(AsgConvertError::unresolved_reference(name, &span));
|
||||
@ -188,7 +188,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
let circuit = circuit;
|
||||
|
||||
let members = circuit.members.borrow();
|
||||
let member = members.get(&name.name).ok_or_else(|| {
|
||||
let member = members.get(name.name.as_ref()).ok_or_else(|| {
|
||||
AsgConvertError::unresolved_circuit_member(
|
||||
&circuit.name.borrow().name,
|
||||
&name.name,
|
||||
@ -251,7 +251,7 @@ impl<'a> Into<leo_ast::AssignStatement> for &AssignStatement<'a> {
|
||||
AssignAccess::ArrayIndex(index) => AstAssigneeAccess::ArrayIndex(index.get().into()),
|
||||
AssignAccess::Tuple(index) => AstAssigneeAccess::Tuple(
|
||||
leo_ast::PositiveNumber {
|
||||
value: index.to_string(),
|
||||
value: index.to_string().into(),
|
||||
},
|
||||
self.span.clone().unwrap_or_default(),
|
||||
),
|
||||
|
@ -106,7 +106,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
||||
scope
|
||||
.variables
|
||||
.borrow_mut()
|
||||
.insert(variable.borrow().name.name.clone(), *variable);
|
||||
.insert(variable.borrow().name.name.to_string(), *variable);
|
||||
}
|
||||
|
||||
let statement = scope
|
||||
|
@ -85,7 +85,7 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
|
||||
scope
|
||||
.variables
|
||||
.borrow_mut()
|
||||
.insert(statement.variable.name.clone(), variable);
|
||||
.insert(statement.variable.name.to_string(), variable);
|
||||
|
||||
let statement = scope.context.alloc_statement(Statement::Iteration(IterationStatement {
|
||||
parent: Cell::new(None),
|
||||
|
@ -204,7 +204,9 @@ impl<'a> Into<leo_ast::Type> for &Type<'a> {
|
||||
Integer(int_type) => leo_ast::Type::IntegerType(int_type.clone()),
|
||||
Array(type_, len) => leo_ast::Type::Array(
|
||||
Box::new(type_.as_ref().into()),
|
||||
leo_ast::ArrayDimensions(vec![leo_ast::PositiveNumber { value: len.to_string() }]),
|
||||
leo_ast::ArrayDimensions(vec![leo_ast::PositiveNumber {
|
||||
value: len.to_string().into(),
|
||||
}]),
|
||||
),
|
||||
Tuple(subtypes) => leo_ast::Type::Tuple(subtypes.iter().map(Into::into).collect()),
|
||||
Circuit(circuit) => leo_ast::Type::Circuit(circuit.name.borrow().clone()),
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
const public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions
|
||||
const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let arr: [u8; (2, 2)] = [[1u8, 1u8],
|
||||
const arr: [u8; (2, 2)] = [[1u8, 1u8],
|
||||
[1u8]]; // incorrect dimensions
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions
|
||||
const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: [u8; -2] = [0u32; 2];
|
||||
const a: [u8; -2] = [0u32; 2];
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
const b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
const b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
const b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
|
||||
const b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering)
|
||||
const b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
let b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer
|
||||
const b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
const b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering)
|
||||
const b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
let b: [u8; (2, 3)] = [0; (2, 3)]; // initializer
|
||||
const b: [u8; (2, 3)] = [0; (2, 3)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order)
|
||||
const b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a = true && 1u32;
|
||||
const a = true && 1u32;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a = true || 1u32;
|
||||
const a = true || 1u32;
|
||||
}
|
@ -3,5 +3,5 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { y: 0u32 };
|
||||
const a = Foo { y: 0u32 };
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a = Foo { };
|
||||
const a = Foo { };
|
||||
}
|
@ -5,6 +5,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { };
|
||||
let err = a.echoed(1u32);
|
||||
const a = Foo { };
|
||||
const err = a.echoed(1u32);
|
||||
}
|
@ -5,6 +5,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { };
|
||||
let err = a.echo(1u32); // echo is a static function and must be accessed using `::`
|
||||
const a = Foo { };
|
||||
const err = a.echo(1u32); // echo is a static function and must be accessed using `::`
|
||||
}
|
@ -5,5 +5,5 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::`
|
||||
const err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::`
|
||||
}
|
@ -5,5 +5,5 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let err = Foo::echoed(1u32);
|
||||
const err = Foo::echoed(1u32);
|
||||
}
|
@ -3,7 +3,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { x: 1u32 };
|
||||
const a = Foo { x: 1u32 };
|
||||
|
||||
let err = a.y;
|
||||
const err = a.y;
|
||||
}
|
@ -60,7 +60,7 @@ fn test_mut_member_function_fail() {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { };
|
||||
const a = Foo { };
|
||||
|
||||
console.assert(a.echo(1u32) == 1u32);
|
||||
}"#;
|
||||
|
@ -5,7 +5,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u8 };
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
f.bar = 1u8;
|
||||
}
|
@ -9,7 +9,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u8 };
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
f.set_a(1u8);
|
||||
}
|
@ -9,7 +9,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u8 };
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
f.set_a(1u8);
|
||||
}
|
@ -7,7 +7,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u8 };
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
f.set_a(1u8);
|
||||
}
|
@ -3,7 +3,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut f = Foo { a: 0u8 };
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
f.bar = 1u8;
|
||||
}
|
@ -3,7 +3,7 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let f = Foo { a: 0u8 };
|
||||
const f = Foo { a: 0u8 };
|
||||
|
||||
f.a = 1u8;
|
||||
}
|
@ -7,6 +7,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() -> u32 {
|
||||
let foo = Foo { f: 1u32 };
|
||||
let err = foo.bar();
|
||||
const foo = Foo { f: 1u32 };
|
||||
const err = foo.bar();
|
||||
}
|
@ -5,6 +5,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let foo = Foo { };
|
||||
let err = foo.bar();
|
||||
const foo = Foo { };
|
||||
const err = foo.bar();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
function foo(a: [u8; 1]) {}
|
||||
|
||||
function main() {
|
||||
let a: [u16; 1] = [1; 1];
|
||||
const a: [u16; 1] = [1; 1];
|
||||
foo(a);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main () -> u16 {
|
||||
if false {
|
||||
let a = 1u16;
|
||||
let b = a + 1u16;
|
||||
const a = 1u16;
|
||||
const b = a + 1u16;
|
||||
return b
|
||||
} else if false {
|
||||
return 0u16
|
||||
|
@ -3,5 +3,5 @@ function array_3x2_tuple() -> [[u8; 2]; 3] {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let b = array_3x2_tuple();
|
||||
const b = array_3x2_tuple();
|
||||
}
|
@ -3,5 +3,5 @@ function array_3x2_nested() -> [u8; (3, 2)] {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = array_3x2_nested();
|
||||
const a = array_3x2_nested();
|
||||
}
|
@ -3,6 +3,6 @@ function foo() -> field {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let myGlobal = 42field;
|
||||
let err = foo();
|
||||
const myGlobal = 42field;
|
||||
const err = foo();
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let element = (+, +)group;
|
||||
const element = (+, +)group;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let element = (_, _)group;
|
||||
const element = (_, _)group;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let element = (-, -)group;
|
||||
const element = (-, -)group;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i128 = 170141183460469231731687303715884105728;
|
||||
const a: i128 = 170141183460469231731687303715884105728;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i128 = -170141183460469231731687303715884105729;
|
||||
const a: i128 = -170141183460469231731687303715884105729;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let a: i128 = -170141183460469231731687303715884105728;
|
||||
let b = -a;
|
||||
const a: i128 = -170141183460469231731687303715884105728;
|
||||
const b = -a;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i16 = 32768;
|
||||
const a: i16 = 32768;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i16 = -32769;
|
||||
const a: i16 = -32769;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let a = -32768i16;
|
||||
let b = -a;
|
||||
const a = -32768i16;
|
||||
const b = -a;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i32 = 2147483648;
|
||||
const a: i32 = 2147483648;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i32 = -2147483649;
|
||||
const a: i32 = -2147483649;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let a = -2147483648i32;
|
||||
let b = -a;
|
||||
const a = -2147483648i32;
|
||||
const b = -a;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i64 = 9223372036854775808;
|
||||
const a: i64 = 9223372036854775808;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i64 = -9223372036854775809;
|
||||
const a: i64 = -9223372036854775809;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let a: i64 = -9223372036854775808;
|
||||
let b = -a;
|
||||
const a: i64 = -9223372036854775808;
|
||||
const b = -a;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i8 = 128;
|
||||
const a: i8 = 128;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: i8 = -129;
|
||||
const a: i8 = -129;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function main() {
|
||||
let a = -128i8;
|
||||
let b = -a;
|
||||
const a = -128i8;
|
||||
const b = -a;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u128 = 340282366920938463463374607431768211456;
|
||||
const a: u128 = 340282366920938463463374607431768211456;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u128 = -1;
|
||||
const a: u128 = -1;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u16 = 65536;
|
||||
const a: u16 = 65536;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u16 = -1;
|
||||
const a: u16 = -1;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u32 = 4294967296;
|
||||
const a: u32 = 4294967296;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u32 = -1;
|
||||
const a: u32 = -1;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u64 = 18446744073709551616;
|
||||
const a: u64 = 18446744073709551616;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u64 = -1;
|
||||
const a: u64 = -1;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u8 = 256;
|
||||
const a: u8 = 256;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u8 = -1;
|
||||
const a: u8 = -1;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Arrays are immutable by default.
|
||||
function main() {
|
||||
let a = [1u32];
|
||||
const a = [1u32];
|
||||
a[0] = 0;
|
||||
}
|
@ -4,6 +4,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let a = Foo { x: 1 };
|
||||
const a = Foo { x: 1 };
|
||||
a.x = 0;
|
||||
}
|
@ -4,6 +4,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut a = Foo { x: 1 };
|
||||
let a = Foo { x: 1 };
|
||||
a.bar = 0;
|
||||
}
|
@ -4,6 +4,6 @@ circuit Foo {
|
||||
}
|
||||
|
||||
function main() {
|
||||
let mut a = Foo { x: 1 };
|
||||
let a = Foo { x: 1 };
|
||||
a.bar = 0;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Let variables are immutable by default.
|
||||
function main() {
|
||||
let a = 1u32;
|
||||
const a = 1u32;
|
||||
a = 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Function input are immutable by default.
|
||||
function main(a: bool) {
|
||||
// Const function input are immutable.
|
||||
function main(const a: bool) {
|
||||
a = false;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Variables are immutable by default.
|
||||
function main() {
|
||||
let a = 1u32;
|
||||
const a = 1u32;
|
||||
a = 0;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const x = 1u32;
|
||||
}
|
3
asg/tests/fail/statements/let_mut_declaration_fail.leo
Normal file
3
asg/tests/fail/statements/let_mut_declaration_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let mut x = 1u32;
|
||||
}
|
@ -23,7 +23,7 @@ fn test_num_returns_fail() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_declaration_fail() {
|
||||
let program_string = include_str!("const_declaration_fail.leo");
|
||||
fn test_let_mut_declaration_fail() {
|
||||
let program_string = include_str!("let_mut_declaration_fail.leo");
|
||||
load_asg(program_string).err().unwrap();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
function main() {
|
||||
let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8);
|
||||
let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8);
|
||||
const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8);
|
||||
const address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8);
|
||||
|
||||
console.assert(address_1 == address_2);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user